Updated template plugins to match new structure
authorAlexander Ebert <ebert@woltlab.com>
Tue, 27 Mar 2012 14:02:21 +0000 (16:02 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 27 Mar 2012 14:02:21 +0000 (16:02 +0200)
wcfsetup/install/files/lib/system/template/plugin/PagesFunctionTemplatePlugin.class.php
wcfsetup/install/files/lib/system/template/plugin/SmallpagesFunctionTemplatePlugin.class.php

index f486ad2030d3b1f5bdd93da043201a979808181e..8a1f4bfdafa2f84131cae6794859b7d84370e30a 100644 (file)
@@ -30,7 +30,6 @@ use wcf\util\StringUtil;
  */
 class PagesFunctionTemplatePlugin implements IFunctionTemplatePlugin {
        const SHOW_LINKS = 11;
-       const SHOW_SUB_LINKS = 20;
        
        /**
         * Inserts the page number into the link.
@@ -51,16 +50,33 @@ class PagesFunctionTemplatePlugin implements IFunctionTemplatePlugin {
         * @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";
                }
        }
        
@@ -96,22 +112,16 @@ class PagesFunctionTemplatePlugin implements IFunctionTemplatePlugin {
                        }
                        
                        // 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);
@@ -153,16 +163,7 @@ class PagesFunctionTemplatePlugin implements IFunctionTemplatePlugin {
                                        $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";
                                }
                        }
                        
@@ -177,16 +178,7 @@ class PagesFunctionTemplatePlugin implements IFunctionTemplatePlugin {
                                        $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";
                                }
                        }
                        
@@ -194,13 +186,7 @@ class PagesFunctionTemplatePlugin implements IFunctionTemplatePlugin {
                        $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";
index 14aa08b8cc26b53b4c6b375f80a2a40cbec17750..64ffa12e46a24a441a15d5754462e9c4b0127ad3 100644 (file)
@@ -1,10 +1,6 @@
 <?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.
@@ -25,87 +21,32 @@ use wcf\util\StringUtil;
  * @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\' &amp;&amp; typeof(result) != \'undefined\') document.location.href = fixURL((\''.StringUtil::replace("'", "\'", $link).'\').replace(/%d/, result));">&hellip;</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);
        }
 }