*/
class PagesFunctionTemplatePlugin implements IFunctionTemplatePlugin {
const SHOW_LINKS = 11;
- const SHOW_SUB_LINKS = 20;
/**
* Inserts the page number into the link.
* @param string $link
* @param integer $pageNo
* @param integer $activePage
- * @param boolean $break
* @return string
*/
protected function makeLink($link, $pageNo, $activePage, $break = false) {
// first page
if ($activePage != $pageNo) {
- return '<li class="wcf-button '.($break ? 'break' : '').'"><a href="'.$this->insertPageNumber($link, $pageNo).'">'.StringUtil::formatInteger($pageNo).'</a></li>'."\n";
+ return '<li class="button"><a href="'.$this->insertPageNumber($link, $pageNo).'" title="'.WCF::getLanguage()->getDynamicVariable('wcf.page.pageNo', array('pageNo' => $pageNo)).'">'.StringUtil::formatInteger($pageNo).'</a></li>'."\n";
}
else {
- return '<li class="wcf-button '.($break ? 'break ' : '').'active"><span>'.StringUtil::formatInteger($pageNo).'</span></li>'."\n";
+ return '<li class="button active"><span>'.StringUtil::formatInteger($pageNo).'</span></li>'."\n";
+ }
+ }
+
+ protected function makePreviousLink($link, $pageNo) {
+ if ($pageNo > 1) {
+ return '<li class="button skip"><a href="'.$this->insertPageNumber($link, $pageNo - 1).'" title="'.WCF::getLanguage()->getDynamicVariable('wcf.global.page.previous').'" class="jsTooltip"><img src="'.self::getIconPath('previous1').'" alt="" /></a></li>'."\n";
+ }
+ else {
+ return '<li class="skip disabled"><img src="'.self::getIconPath('previous1D').'" alt="" /></li>'."\n";
+ }
+ }
+
+ protected function makeNextLink($link, $pageNo, $pages) {
+ if ($pageNo && $pageNo < $pages) {
+ return '<li class="button skip"><a href="'.$this->insertPageNumber($link, $pageNo + 1).'" title="'.WCF::getLanguage()->getDynamicVariable('wcf.global.page.next').'" class="jsTooltip"><img src="'.self::getIconPath('next1').'" alt="" /></a></li>'."\n";
+ }
+ else {
+ return '<li class="skip disabled"><img src="'.self::getIconPath('next1D').'" alt="" /></li>'."\n";
}
}
}
// open div and ul
- $html .= "<nav class=\"wcf-pageNavigation\" data-link=\"".$link."\">\n<ul>\n";
+ $html .= "<nav class=\"pageNavigation\" data-link=\"".$link."\" data-pages=\"".$tagArgs['pages']."\">\n<ul>\n";
// previous page
- $previousTitle = WCF::getLanguage()->getDynamicVariable('wcf.global.page.previous');
- if ($tagArgs['page'] > 1) {
- $html .= '<li class="wcf-button skip"><a href="'.$this->insertPageNumber($link, $tagArgs['page'] - 1).'" title="'.$previousTitle.'" class="jsTooltip"><img src="'.self::getIconPath('previous1').'" alt="" /></a></li>'."\n";
- }
- else {
- $html .= '<li class="skip disabled"><img src="'.self::getIconPath('previous1D').'" alt="" /></li>'."\n";
- }
+ $html .= $this->makePreviousLink($link, $tagArgs['page']);
// first page
$html .= $this->makeLink($link, 1, $tagArgs['page']);
// calculate page links
- $maxLinks = self::SHOW_LINKS - 4;
+ $maxLinks = static::SHOW_LINKS - 4;
$linksBeforePage = $tagArgs['page'] - 2;
if ($linksBeforePage < 0) $linksBeforePage = 0;
$linksAfterPage = $tagArgs['pages'] - ($tagArgs['page'] + 1);
$html .= $this->makeLink($link, 2, $tagArgs['page']);
}
else {
- $html .= '<li class="children"><a onclick="multiPagesLinks.startPageNumberInput(this)" class="wcf-dropdownCaption"><img src="'.self::getIconPath('dropdown1').'" alt="" /></a><input type="text" name="pageNo" placeholder="…" class="tiny" /><div class="wcf-dropdown"><span class="pointer"><span></span></span><ul>'."\n";
-
- $k = 0;
- $step = intval(ceil(($left - 2) / self::SHOW_SUB_LINKS));
- for ($i = 2; $i <= $left; $i += $step) {
- $html .= $this->makeLink($link, $i, $tagArgs['page'], $k != 0 && $k % 4 == 0);
- $k++;
- }
-
- $html .= "</ul></div></li>\n";
+ $html .= '<li class="button jumpTo"><a title="'.WCF::getLanguage()->getDynamicVariable('wcf.global.page.jumpTo').'" class="jsTooltip">...</a></li>'."\n";
}
}
$html .= $this->makeLink($link, $tagArgs['pages'] - 1, $tagArgs['page']);
}
else {
- $html .= '<li class="children"><a onclick="multiPagesLinks.startPageNumberInput(this)" class="wcf-dropdownCaption"><img src="'.self::getIconPath('dropdown1').'" alt="" /></a><input type="text" name="page" placeholder="…" class="tiny" /><div class="wcf-dropdown"><span class="pointer"><span></span></span><ul>'."\n";
-
- $k = 0;
- $step = intval(ceil(($tagArgs['pages'] - $right) / self::SHOW_SUB_LINKS));
- for ($i = $right; $i < $tagArgs['pages']; $i += $step) {
- $html .= $this->makeLink($link, $i, $tagArgs['page'], $k != 0 && $k % 4 == 0);
- $k++;
- }
-
- $html .= "</ul></div></li>\n";
+ $html .= '<li class="button jumpTo"><a title="'.WCF::getLanguage()->getDynamicVariable('wcf.global.page.jumpTo').'" class="jsTooltip">...</a></li>'."\n";
}
}
$html .= $this->makeLink($link, $tagArgs['pages'], $tagArgs['page']);
// next page
- $nextTitle = WCF::getLanguage()->getDynamicVariable('wcf.global.page.next');
- if ($tagArgs['page'] && $tagArgs['page'] < $tagArgs['pages']) {
- $html .= '<li class="wcf-button skip"><a href="'.$this->insertPageNumber($link, $tagArgs['page'] + 1).'" title="'.$nextTitle.'" class="jsTooltip"><img src="'.self::getIconPath('next1').'" alt="" /></a></li>'."\n";
- }
- else {
- $html .= '<li class="skip disabled"><img src="'.self::getIconPath('next1D').'" alt="" /></li>'."\n";
- }
+ $html .= $this->makeNextLink($link, $tagArgs['page'], $tagArgs['pages']);
// close div and ul
$html .= "</ul></nav>\n";
<?php
namespace wcf\system\template\plugin;
-use wcf\system\exception\SystemException;
-use wcf\system\request\LinkHandler;
use wcf\system\template\TemplateEngine;
-use wcf\system\WCF;
-use wcf\util\StringUtil;
/**
* The 'smallpages' template function is used to generate simple sliding pagers.
* @subpackage system.template.plugin
* @category Community Framework
*/
-class SmallpagesFunctionTemplatePlugin implements IFunctionTemplatePlugin {
- const SHOW_LINKS = 5;
+class SmallpagesFunctionTemplatePlugin extends PagesFunctionTemplatePlugin {
+ /**
+ * @see wcf\system\template\plugin\PagesFunctionTemplatePlugin::SHOW_LINKS
+ */
+ const SHOW_LINKS = 7;
/**
- * Inserts the page number into the link.
- *
- * @param string $link
- * @param integer $pageNo
- * @return string final link
+ * @see wcf\system\template\plugin\PagesFunctionTemplatePlugin::makePreviousLink()
*/
- protected static function insertPageNumber($link, $pageNo) {
- $startPos = StringUtil::indexOf($link, '%d');
- if ($startPos !== null) $link = StringUtil::substring($link, 0, $startPos) . $pageNo . StringUtil::substring($link, $startPos + 2);
- return $link;
+ protected function makePreviousLink($link, $pageNo) {
+ return '';
}
/**
- * Generates html code of a link.
- *
- * @param string $link
- * @param integer $pageNo
- * @return string
+ * @see wcf\system\template\plugin\PagesFunctionTemplatePlugin::makeNextLink()
*/
- protected function makeLink($link, $pageNo) {
- return '<li class="wcf-button"><a href="'.$this->insertPageNumber($link, $pageNo).'" title="' . WCF::getLanguage()->getDynamicVariable('wcf.page.pageNo', array('pageNo' => $pageNo)) . '">'.StringUtil::formatInteger($pageNo).'</a></li>'."\n";
+ protected function makeNextLink($link, $pageNo, $pages) {
+ return '';
}
/**
* @see wcf\system\template\IFunctionTemplatePlugin::execute()
*/
public function execute($tagArgs, TemplateEngine $tplObj) {
- // needed params: controller, link, pages
- if (!isset($tagArgs['link'])) throw new SystemException("missing 'link' argument in smallpages tag");
- if (!isset($tagArgs['controller'])) throw new SystemException("missing 'controller' argument in smallpages tag");
- if (!isset($tagArgs['pages'])) {
- if (($tagArgs['pages'] = $tplObj->get('pages')) === null) {
- throw new SystemException("missing 'pages' argument in smallpages tag");
- }
- }
-
- $html = '';
- if ($tagArgs['pages'] > 1) {
- // create and encode route link
- $parameters = array();
- if (isset($tagArgs['id'])) $parameters['id'] = $tagArgs['id'];
- if (isset($tagArgs['title'])) $parameters['title'] = $tagArgs['title'];
- if (isset($tagArgs['object'])) $parameters['object'] = $tagArgs['object'];
- if (isset($tagArgs['application'])) $parameters['application'] = $tagArgs['application'];
- $link = StringUtil::encodeHTML(LinkHandler::getInstance()->getLink($tagArgs['controller'], $parameters, $tagArgs['link']));
-
- // open div and ul
- $html .= "<nav class=\"wcf-pageNavigation\" data-link=\"".$link."\">\n<ul>\n";
-
- // generate simple links
- $simpleLinks = $tagArgs['pages'];
- if ($simpleLinks > self::SHOW_LINKS) {
- $simpleLinks = self::SHOW_LINKS - 2;
- }
-
- for ($i = 1; $i <= $simpleLinks; $i++) {
- $html .= $this->makeLink($link, $i);
- }
-
- if ($tagArgs['pages'] > self::SHOW_LINKS) {
- // jumper
- $html .= '<li class="wcf-button"><a onclick="var result = prompt(\''.WCF::getLanguage()->get('wcf.global.page.input').'\', \''.$tagArgs['pages'].'\'); if (typeof(result) != \'object\' && typeof(result) != \'undefined\') document.location.href = fixURL((\''.StringUtil::replace("'", "\'", $link).'\').replace(/%d/, result));">…</a></li>'."\n";
-
- // last page
- $html .= $this->makeLink($link, $tagArgs['pages']);
- }
-
- // close div and ul
- $html .= "</ul></nav>\n";
- }
-
- // assign html output to template var
- if (isset($tagArgs['assign'])) {
- $tplObj->assign($tagArgs['assign'], $html);
- if (!isset($tagArgs['print']) || !$tagArgs['print']) return '';
- }
+ $tagArgs['page'] = 0;
- return $html;
+ return parent::execute($tagArgs, $tplObj);
}
}