/** * @see wcf\system\template\IFunctionTemplatePlugin::execute() */ public function execute($tagArgs, TemplateEngine $tplObj) { if (!isset($tagArgs['name'])) { $tagArgs['name'] = 'default'; } if (!isset($this->counters[$tagArgs['name']])) { $this->counters[$tagArgs['name']] = array( 'skip' => isset($tagArgs['skip']) ? $tagArgs['skip'] : 1, 'direction' => isset($tagArgs['direction']) ? $tagArgs['direction'] : 'up', 'assign' => (isset($tagArgs['assign']) && !empty($tagArgs['assign'])) ? $tagArgs['assign'] : null, 'print' => isset($tagArgs['print']) ? $tagArgs['print'] : false, 'count' => isset($tagArgs['start']) ? $tagArgs['start'] : 1 ); } $counter =& $this->counters[$tagArgs['name']]; if ($counter['assign'] !== null) { $tplObj->assign($counter['assign'], $counter['count']); } $result = ''; if ($counter['print']) { $result = $counter['count']; } if ($counter['direction'] == 'down') { $counter['count'] -= $counter['skip']; } else { $counter['count'] += $counter['skip']; } return $result; }
/** * @see \wcf\system\template\IModifierTemplatePlugin::execute() */ public function execute($tagArgs, TemplateEngine $tplObj) { if (($lang = $tplObj->get('__language')) === null) { $lang = WCF::getLanguage(); } return $lang->getDynamicVariable($tagArgs[0]); }
/** * @see wcf\system\template\IFunctionTemplatePlugin::execute() */ public function execute($tagArgs, TemplateEngine $tplObj) { // get params $name = isset($tagArgs['name']) ? $tagArgs['name'] : 'default'; $print = isset($tagArgs['print']) ? $tagArgs['print'] : 1; $advance = isset($tagArgs['advance']) ? $tagArgs['advance'] : 1; $reset = isset($tagArgs['reset']) ? $tagArgs['reset'] : 0; // get values if (!isset($tagArgs['values'])) { if (!isset($this->cycles[$name]['values'])) { throw new SystemException("missing 'values' argument in cycle tag"); } } else { if (isset($this->cycles[$name]['values']) && $this->cycles[$name]['values'] != $tagArgs['values']) { $this->cycles[$name]['index'] = 0; } $this->cycles[$name]['values'] = $tagArgs['values']; } // get delimiter if (!isset($this->cycles[$name]['delimiter'])) { // set default delimiter $this->cycles[$name]['delimiter'] = ','; } if (isset($tagArgs['delimiter'])) { $this->cycles[$name]['delimiter'] = $tagArgs['delimiter']; } // split values if (is_array($this->cycles[$name]['values'])) { $cycleArray = $this->cycles[$name]['values']; } else { $cycleArray = explode($this->cycles[$name]['delimiter'], $this->cycles[$name]['values']); } // set index if (!isset($this->cycles[$name]['index']) || $reset) { $this->cycles[$name]['index'] = 0; } // get result $result = $cycleArray[$this->cycles[$name]['index']]; // assign result to template var if (isset($tagArgs['assign'])) { $print = false; $tplObj->assign($tagArgs['assign'], $result); } // update index if ($advance) { if ($this->cycles[$name]['index'] >= count($cycleArray) - 1) { $this->cycles[$name]['index'] = 0; } else { $this->cycles[$name]['index']++; } } // print var if ($print) { return $result; } }
/** * @see \wcf\system\template\TemplateEngine::getTemplateListenerCode() */ public function getTemplateListenerCode($templateName, $eventName) { // skip template listeners within WCF ACP if (defined('PACKAGE_ID') && PACKAGE_ID == 1) { return ''; } return parent::getTemplateListenerCode($templateName, $eventName); }
/** * Applies the prefilters to the given string. * * @param string $templateName * @param string $string * @return string */ public function applyPrefilters($templateName, $string) { foreach ($this->template->getPrefilters() as $prefilter) { if (!is_object($prefilter)) { $className = $this->template->getPluginClassName('prefilter', $prefilter); if (!class_exists($className)) { throw new SystemException($this->formatSyntaxError('unable to find prefilter class ' . $className, $this->currentIdentifier)); } $prefilter = new $className(); } if ($prefilter instanceof IPrefilterTemplatePlugin) { $string = $prefilter->execute($templateName, $string, $this); } else { throw new SystemException($this->formatSyntaxError("Prefilter '" . (is_object($prefilter) ? get_class($prefilter) : $prefilter) . "' does not implement the interface 'IPrefilterTemplatePlugin'", $this->currentIdentifier)); } } return $string; }
/** * Initialises the template engine. */ protected function initTPL() { self::$tplObj = TemplateEngine::getInstance(); self::getTPL()->setLanguageID(self::getLanguage()->languageID); $this->assignDefaultTemplateVariables(); $this->initStyle(); }
/** * @see wcf\system\template\IFunctionTemplatePlugin::execute() */ public function execute($tagArgs, TemplateEngine $tplObj) { // needed params: controller, link, page, pages if (!isset($tagArgs['link'])) throw new SystemException("missing 'link' argument in pages tag"); if (!isset($tagArgs['controller'])) throw new SystemException("missing 'controller' argument in pages tag"); if (!isset($tagArgs['pages'])) { if (($tagArgs['pages'] = $tplObj->get('pages')) === null) { throw new SystemException("missing 'pages' argument in pages 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'])); if (!isset($tagArgs['page'])) { if (($tagArgs['page'] = $tplObj->get('pageNo')) === null) { $tagArgs['page'] = 0; } } // open div and ul $html .= "<nav class=\"pageNavigation\" data-link=\"".$link."\" data-pages=\"".$tagArgs['pages']."\">\n<ul>\n"; // previous page $html .= $this->makePreviousLink($link, $tagArgs['page']); // first page $html .= $this->makeLink($link, 1, $tagArgs['page']); // calculate page links $maxLinks = static::SHOW_LINKS - 4; $linksBeforePage = $tagArgs['page'] - 2; if ($linksBeforePage < 0) $linksBeforePage = 0; $linksAfterPage = $tagArgs['pages'] - ($tagArgs['page'] + 1); if ($linksAfterPage < 0) $linksAfterPage = 0; if ($tagArgs['page'] > 1 && $tagArgs['page'] < $tagArgs['pages']) { $maxLinks--; } $half = $maxLinks / 2; $left = $right = $tagArgs['page']; if ($left < 1) $left = 1; if ($right < 1) $right = 1; if ($right > $tagArgs['pages'] - 1) $right = $tagArgs['pages'] - 1; if ($linksBeforePage >= $half) { $left -= $half; } else { $left -= $linksBeforePage; $right += $half - $linksBeforePage; } if ($linksAfterPage >= $half) { $right += $half; } else { $right += $linksAfterPage; $left -= $half - $linksAfterPage; } $right = intval(ceil($right)); $left = intval(ceil($left)); if ($left < 1) $left = 1; if ($right > $tagArgs['pages']) $right = $tagArgs['pages']; // left ... links if ($left > 1) { if ($left - 1 < 2) { $html .= $this->makeLink($link, 2, $tagArgs['page']); } else { $html .= '<li class="button jumpTo"><a title="'.WCF::getLanguage()->getDynamicVariable('wcf.global.page.jumpTo').'" class="jsTooltip">'.StringUtil::HELLIP.'</a></li>'."\n"; } } // visible links for ($i = $left + 1; $i < $right; $i++) { $html .= $this->makeLink($link, $i, $tagArgs['page']); } // right ... links if ($right < $tagArgs['pages']) { if ($tagArgs['pages'] - $right < 2) { $html .= $this->makeLink($link, $tagArgs['pages'] - 1, $tagArgs['page']); } else { $html .= '<li class="button jumpTo"><a title="'.WCF::getLanguage()->getDynamicVariable('wcf.global.page.jumpTo').'" class="jsTooltip">'.StringUtil::HELLIP.'</a></li>'."\n"; } } // last page $html .= $this->makeLink($link, $tagArgs['pages'], $tagArgs['page']); // next page $html .= $this->makeNextLink($link, $tagArgs['page'], $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 ''; } return $html; }