/** * * @return vB5_Template_Stylevar */ public static function instance() { if (!isset(self::$instance)) { $c = __CLASS__; self::$instance = new $c(); } return self::$instance; }
public static function init($configFile) { parent::init($configFile); self::$instance = new vB5_Frontend_Application(); self::$instance->router = new vB5_Frontend_Routing(); self::$instance->router->setRoutes(); $styleid = vB5_Template_Stylevar::instance()->getPreferredStyleId(); if ($styleid) { vB::getCurrentSession()->set('styleid', $styleid); } self::ajaxCharsetConvert(); self::setHeaders(); return self::$instance; }
/** * Returns the cache key to be used by vB_Cache * @param type $nodeId * @return string */ protected function getCacheKey($nodeId, $bbCodeOptions, $preview = false, $canview) { $styleId = vB5_Template_Stylevar::instance()->getPreferredStyleId(); $languageId = vB5_User::getLanguageId(); $cacheKey = "vbNodeText" . ($preview ? "_pre_" : '') . "{$nodeId}_{$styleId}_{$languageId}"; if (!$canview) { $cacheKey .= '_pvo)'; } else { if (!empty($bbCodeOptions)) { ksort($bbCodeOptions); $cacheKey .= ':' . md5(json_encode($bbCodeOptions)); } } return strtolower($cacheKey); }
public function getCssFile($filename) { $options = vB5_Template_Options::instance(); $storecssasfile = $options->get('options.storecssasfile'); $user = vB5_User::instance(); $textdirection = $user['lang_options']['direction'] ? 'ltr' : 'rtl'; // we cannot query user directly for styleid, we need to consider other parameters $styleid = vB5_Template_Stylevar::instance()->getPreferredStyleId(); $vbcsspath = $this->getCssPath($storecssasfile, $textdirection, $styleid); if ($storecssasfile) { $cssfiledate = $this->getCssFileDate($options, $styleid); $file = htmlspecialchars($vbcsspath . $cssfiledate . '-' . $filename); } else { if (!($cssdate = intval($options->get('miscoptions.cssdate')))) { $cssdate = time(); // fallback so we get the latest css } $joinChar = strpos($vbcsspath, '?') === false ? '?' : '&'; $file = htmlspecialchars($vbcsspath . $filename . "{$joinChar}ts={$cssdate}"); } return $file; }
/** * Handle any delayed rendering. Currently delayed urls and node texts. * * @param string * @param boolean true if we are rendering for a call to /ajax/render/ and we want CSS <link>s separate * * @return string */ protected function renderDelayed(&$final_rendered_orig, $isAjaxTemplateRender = false) { $javascript = vB5_Template_Javascript::instance(); $javascript->insertJs($final_rendered_orig); $javascript->resetPending(); $stylesheet = vB5_Template_Stylesheet::instance(); $stylesheet->insertCss($final_rendered_orig, $isAjaxTemplateRender); $stylesheet->resetPending(); $link = vB5_Template_Headlink::instance(); $link->insertLinks($final_rendered_orig); $link->resetPending(); $phrase = vB5_Template_Phrase::instance(); $phrase->replacePlaceholders($final_rendered_orig); $phrase->resetPending(); // we do not reset pending urls, since they may be required by nodetext vB5_Template_Url::instance()->replacePlaceholders($final_rendered_orig); $nodeText = vB5_Template_NodeText::instance(); $nodeText->replacePlaceholders($final_rendered_orig); $nodeText->resetPending(); $templateCache = vB5_Template_Cache::instance(); $templateCache->replaceTextOnly($final_rendered_orig); //We should keep the debug info for truly last. if (vB5_Frontend_Controller_Bbcode::needDebug()) { $config = vB5_Config::instance(); if (!$config->debug) { return $final_rendered_orig; } self::$renderedTemplateNames[] = 'debug_info'; self::$renderedTemplates[] = array('templateName' => 'debug_info', 'isParentTemplate' => (bool) 0, 'indent' => str_repeat('|----', 2)); $user = vB5_User::instance(); $this->register('user', $user, true); extract(self::$globalRegistered, EXTR_SKIP | EXTR_REFS); extract($this->registered, EXTR_OVERWRITE | EXTR_REFS); $vboptions = vB5_Template_Options::instance()->getOptions(); $vboptions = $vboptions['options']; $renderedTemplates = array('count' => count(self::$renderedTemplates), 'countUnique' => count(array_unique(self::$renderedTemplateNames)), 'templates' => self::$renderedTemplates, 'styleid' => vB5_Template_Stylevar::instance()->getPreferredStyleId()); $cssDebugLog = vB5_Template_Stylesheet::getDebugLog(); $jsDebugLog = vB5_Template_Javascript::instance()->getDebugLog(); $templateCode = $templateCache->getTemplate('debug_info'); if ($templateCache->isTemplateText()) { @eval($templateCode); } else { @(include $templateCode); } $phrase->replacePlaceholders($final_rendered); $phrase->resetPending(); $final_rendered_orig = str_replace('<!-DebugInfo-->', $final_rendered, $final_rendered_orig); } }
/** * Any final processing, and then output the page */ protected function outputPage($html, $exit = true) { $styleid = vB5_Template_Stylevar::instance()->getPreferredStyleId(); if (!$styleid) { $styleid = $this->vboptions['styleid']; } $fullPage = Api_InterfaceAbstract::instance()->callApi('template', 'processReplacementVars', array($html, $styleid)); if ($exit) { echo $fullPage; exit; } return $fullPage; }
/** * Receives either a template name or an array of template names to be fetched from the API * @param mixed $templateName */ protected function fetchTemplate($templateName) { if (is_array($templateName)) { $method = 'fetchBulk'; $arguments = array('template_names' => $templateName); } else { $method = 'fetch'; $arguments = array('name' => $templateName); } if ($styleId = vB5_Template_Stylevar::instance()->getPreferredStyleId()) { $arguments['styleid'] = $styleId; } $response = Api_InterfaceAbstract::instance()->callApi('template', $method, $arguments); // this api call may return a bunch of subtemplates as well if (is_array($response) and isset($response['textonly'])) { $placeholder = $this->getPlaceholder($templateName, '_to'); $this->cache[$templateName] = "\$final_rendered = \"" . $placeholder . "\";"; $this->textOnlyReplace[$placeholder] = $response['template']; } else { if (is_array($response)) { foreach ($response as $id => $code) { if (is_array($code) and isset($code['textonly'])) { //We use a placeholder; $placeholder = $this->getPlaceholder($id, '_to'); $this->cache[$id] = "\$final_rendered = \"" . $placeholder . "\";"; $this->textOnlyReplace[$placeholder] = $code['template']; } else { // in this layer we need to use vB5_Template_Runtime instead of vB_Template_Runtime $code = str_replace('vB_Template_Runtime', 'vB5_Template_Runtime', $code); $this->cache[$id] = $code; } } } else { //This probably doesn't do what you think it does. The response is always going to be an //array of some kind unless its a value like false (which is shouldn't be) // in this layer we need to use vB5_Template_Runtime instead of vB_Template_Runtime $response = str_replace('vB_Template_Runtime', 'vB5_Template_Runtime', $response); $this->cache[$templateName] = $response; } } }
public static function fetchStyleVar($stylevar) { $parts = explode('.', $stylevar); return self::outputStyleVar(vB5_Template_Stylevar::instance()->get($parts[0]), $parts); }