/** * Inserts tag links into an HTML-formatted text. * * @param string $html * @param array $tags * @param array $options * @return string */ public static function autoTag($html, array $tags, array &$options = array()) { if (empty($tags)) { return $html; } $html = strval($html); $htmlNullified = utf8_strtolower($html); $htmlNullified = preg_replace_callback('#<a[^>]+>.+?</a>#', array(__CLASS__, '_autoTag_nullifyHtmlCallback'), $htmlNullified); $htmlNullified = preg_replace_callback('#<[^>]+>#', array(__CLASS__, '_autoTag_nullifyHtmlCallback'), $htmlNullified); // prepare the options $onceOnly = empty($options['onceOnly']) ? false : true; $options['autoTagged'] = array(); // reset this // sort tags with the longest one first // since 1.0.3 usort($tags, array(__CLASS__, '_autoTag_sortTagsByLength')); foreach ($tags as $tag) { $offset = 0; $tagText = utf8_strtolower($tag['tag']); $tagLength = utf8_strlen($tagText); while (true) { $pos = utf8_strpos($htmlNullified, $tagText, $offset); if ($pos !== false) { // the tag has been found if (self::_autoTag_hasValidCharacterAround($html, $pos, $tagText)) { // and it has good surrounding characters // start replacing $displayText = utf8_substr($html, $pos, $tagLength); $template = new XenForo_Template_Public('tinhte_xentag_bb_code_tag_tag'); $template->setParam('tag', $tag); $template->setParam('displayText', $displayText); $replacement = $template->render(); if (strlen($replacement) === 0) { // in case template system hasn't been initialized $replacement = sprintf('<a href="%s">%s</a>', XenForo_Link::buildPublicLink('tags', $tag), $displayText); } $html = utf8_substr_replace($html, $replacement, $pos, $tagLength); $htmlNullified = utf8_substr_replace($htmlNullified, str_repeat('_', utf8_strlen($replacement)), $pos, $tagLength); // sondh@2012-09-20 // keep track of the auto tagged tags $options['autoTagged'][$tagText][$pos] = $replacement; $offset = $pos + utf8_strlen($replacement); if ($onceOnly) { // auto link only once per tag // break the loop now break; // while (true) } } else { $offset = $pos + $tagLength; } } else { // no match has been found, stop working with this tag break; // while (true) } } } return $html; }
public static function hook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template) { $model = XenForo_Model::create("AssociationMc_Model_AssociationEntry"); $entry = $model->getEntryById($hookParams['user']['user_id']); if ($entry != null) { $myTemplate = new XenForo_Template_Public("association_profile_sidebar", array("mcName" => $entry['last_username'])); $contents .= $myTemplate->render(); } }
public function __construct($templateName, array $params = array()) { if (self::$bdSocialShare_Helper_visitor !== null) { $params['visitor'] = self::$bdSocialShare_Helper_visitor; } $params['xenOptions'] = XenForo_Application::getOptions()->getOptions(); parent::__construct(sprintf('__%s_%d_%d', $templateName, self::$bdSocialShare_Helper_styleId, self::$bdSocialShare_Helper_languageId), $params); }
public static function template_hook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template) { $options = XenForo_Application::get('options'); $enableadvxenforo = $options->enableadvxenforo; $thread_id = $hookParams['thread']['thread_id']; if ($enableadvxenforo) { $PermissionEnable = XenForo_Visitor::getInstance()->hasPermission('adv_xenforo', 'adv_xenforo_enable_adv') ? TRUE : FALSE; if ($hookName == 'account_preferences_options' && $PermissionEnable) { $ourTemplate = $template->create('adv_xenforo_account_options', $template->getparams()); $rendered = $ourTemplate->render(); $contents = $contents . $rendered; } $hasPermission = XenForo_Visitor::getInstance()->hasPermission('adv_xenforo', 'adv_xenforo_show') ? TRUE : FALSE; $advs = XenForo_Application::getSimpleCacheData('adv_xenforo'); $user = XenForo_Visitor::getInstance()->toArray(); $enable_adv = $PermissionEnable === TRUE ? $user['enable_adv'] : TRUE; $containerData = self::$containerData; if (empty(self::$containerData)) { $containerData = XenForo_Template_Public::getExtraContainerData(); } if ($enable_adv) { if ($hasPermission === TRUE && $advs["AdvsHook"]) { $isMobile = XenForo_Visitor::isBrowsingWith('mobile'); switch (TRUE) { case $isMobile == TRUE: $adv_adv = 'adv_small'; break; default: $adv_adv = 'adv_large'; break; } foreach ($advs["AdvsHook"] as $_asv) { if ($_asv['active'] && XenForo_Helper_Criteria::userMatchesCriteria($_asv['user_criteria'], TRUE, $user) && XenForo_Helper_Criteria::pageMatchesCriteria($_asv['page_criteria'], TRUE, $template->getParams(), $containerData)) { $ourTemplate = $template->create('ads_xf_ar_xenforo', array('advanced' => $_asv[$adv_adv])); $rendered = $ourTemplate->render(); if ($hookName == 'message_content' && Turki_Adv_Helper_Criteria::postCriteria($_asv['post_criteria'], TRUE) === FALSE) { if ($hookParams['message']['thread_id']) { $decode = XenForo_Helper_Criteria::prepareCriteriaForSelection($_asv['post_criteria']); $position = $decode['active']['page'] ? $hookParams['message']['position'] % $options->messagesPerPage : $hookParams['message']['position']; if ($position == $decode['active']['post_id'] - 1) { $contents = $decode['active']['position'] ? Turki_Adv_Helper_Helpers::advhtml($contents, $rendered) : $contents . $rendered; } } } else { if ($hookName == $_asv['adv_hook_name'] && Turki_Adv_Helper_Criteria::postCriteria($_asv['post_criteria'], TRUE)) { $contents = $_asv['display'] == 'top' ? $rendered . $contents : $contents . $rendered; } } } } } } self::_templateHook($hookName, $contents, $hookParams, $template); } }
public static function WidgetFramework_mergeExtraContainerData(array $extraData) { if (empty($extraData)) { return; } if (self::$_WidgetFramework_pageContainerTemplate === null or self::$_WidgetFramework_pageContainerTemplate->getParam('contents') === null) { XenForo_Template_Public::$_extraData = XenForo_Application::mapMerge(XenForo_Template_Public::$_extraData, $extraData); } else { // these extra data came too late // page container has already started rendering... self::$_WidgetFramework_lateExtraData = XenForo_Application::mapMerge(self::$_WidgetFramework_lateExtraData, $extraData); } }
public function __construct($templateName, array $params = array()) { if (self::$bdApi_visitor !== null) { $params['visitor'] = self::$bdApi_visitor; } $languageId = 0; if (!empty($params['visitor']['language_id'])) { $languageId = $params['visitor']['language_id']; } if (empty($languageId)) { $languageId = XenForo_Application::getOptions()->get('defaultLanguageId'); } $params['xenOptions'] = XenForo_Application::getOptions()->getOptions(); parent::__construct(sprintf('__%s_%d', $templateName, $languageId), $params); }
public function renderTemplate($name, $params = array(), $styleId = null, $languageId = null) { // user $user = $this->getUser(); // Template $template = new XenForo_Template_Public($name, $params); $template->setStyleId($styleId !== null ? $styleId : $user['style_id']); $template->setLanguageId($languageId !== null ? $languageId : $user['language_id']); return $template->render(); }
public static function hookRight($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template) { $myTemplate = new XenForo_Template_Public("association_visitor_right", $hookParams); $contents .= $myTemplate->render(); }
/** * Inserts tag links into an HTML-formatted text. * * @param string $html * @param array $tags * @param array $options */ public static function autoTag($html, array $tagsOrTexts, array &$options = array()) { if (empty($tagsOrTexts)) { return $html; } $html = strval($html); $tagTexts = Tinhte_XenTag_Helper::getTextsFromTagsOrTexts($tagsOrTexts); // prepare the options $onceOnly = empty($options['onceOnly']) ? false : true; $options['autoTagged'] = array(); // reset this // sort tags with the longest one first // since 1.0.3 usort($tagTexts, array(__CLASS__, '_autoTag_sortTagsByLength')); foreach ($tagTexts as $tagText) { $offset = 0; $tagLength = utf8_strlen($tagText); while (true) { $pos = Tinhte_XenTag_Helper::utf8_stripos($html, $tagText, $offset); if ($pos !== false) { // the tag has been found if (!self::_autoTag_isBetweenHtmlTags($html, $pos) and self::_autoTag_hasValidCharacterAround($html, $pos, $tagText)) { // and it's not between HTML tags, // with good surrounding characters // start replacing $template = new XenForo_Template_Public('tinhte_xentag_bb_code_tag_tag'); $template->setParam('tag', $tagText); $template->setParam('displayText', utf8_substr($html, $pos, $tagLength)); $replacement = $template->render(); $html = utf8_substr_replace($html, $replacement, $pos, $tagLength); // sondh@2012-09-20 // keep track of the auto tagged tags $options['autoTagged'][$tagText][$pos] = $replacement; $offset = $pos + utf8_strlen($replacement); if ($onceOnly) { // auto link only once per tag // break the loop now break; // while (true) } } else { $offset = $pos + $tagLength; } } else { // no match has been found, stop working with this tag break; // while (true) } } } return $html; }
/** * Resets the template system state. */ public static function reset() { self::$_templateCache = array(); self::$_toLoad = array(); }
/** * Does any preparations necessary for outputting to be done. */ protected function _prepareForOutput() { $this->_displayStyles = XenForo_Application::get('displayStyles'); $styles = XenForo_Application::get('styles'); $smilieSprites = XenForo_Model::create('XenForo_Model_DataRegistry')->get('smilieSprites'); if (is_array($smilieSprites)) { $this->_smilieSprites = $smilieSprites; } if ($this->_styleId && isset($styles[$this->_styleId])) { $style = $styles[$this->_styleId]; } else { $style = reset($styles); } if ($style) { $properties = unserialize($style['properties']); $this->_styleId = $style['style_id']; $this->_styleModifiedDate = $style['last_modified_date']; } else { $properties = array(); $this->_styleId = 0; } $defaultProperties = XenForo_Application::get('defaultStyleProperties'); XenForo_Template_Helper_Core::setStyleProperties(XenForo_Application::mapMerge($defaultProperties, $properties), false); XenForo_Template_Public::setStyleId($this->_styleId); XenForo_Template_Abstract::setLanguageId(0); }
/** * Performs any pre-view rendering setup, such as getting style information and * ensuring the correct data is registered. * * @param XenForo_ControllerResponse_Abstract|null $controllerResponse */ public function preRenderView(XenForo_ControllerResponse_Abstract $controllerResponse = null) { parent::preRenderView($controllerResponse); if (!empty($this->_viewStateChanges['styleId'])) { $styleId = $this->_viewStateChanges['styleId']; $forceStyleId = true; } else { $user = XenForo_Visitor::getInstance(); $styleId = !empty($user['style_id']) ? $user['style_id'] : 0; $forceStyleId = $user['is_admin'] ? true : false; } XenForo_Template_Abstract::setLanguageId(XenForo_Phrase::getLanguageId()); $styles = XenForo_Application::isRegistered('styles') ? XenForo_Application::get('styles') : XenForo_Model::create('XenForo_Model_Style')->getAllStyles(); if ($styleId && isset($styles[$styleId]) && ($styles[$styleId]['user_selectable'] || $forceStyleId)) { $style = $styles[$styleId]; } else { $defaultStyleId = XenForo_Application::get('options')->defaultStyleId; $style = isset($styles[$defaultStyleId]) ? $styles[$defaultStyleId] : reset($styles); } $defaultProperties = XenForo_Application::get('defaultStyleProperties'); if ($style) { $properties = XenForo_Helper_Php::safeUnserialize($style['properties']); XenForo_Template_Helper_Core::setStyleProperties(XenForo_Application::mapMerge($defaultProperties, $properties)); XenForo_Template_Public::setStyleId($style['style_id']); } else { XenForo_Template_Helper_Core::setStyleProperties($defaultProperties); } // setup the default template params if ($style) { $this->_defaultTemplateParams['visitorStyle'] = $style; } // expose the user fields info array $this->_defaultTemplateParams['userFieldsInfo'] = XenForo_Application::get('userFieldsInfo'); }
/** * Does any preperations necessary for outputting to be done. */ protected function _prepareForOutput() { $cacheData = XenForo_Model::create('XenForo_Model_DataRegistry')->getMulti(array('styles', 'displayStyles', 'options')); if (is_array($cacheData['displayStyles'])) { $this->_displayStyles = $cacheData['displayStyles']; } $styles = $cacheData['styles']; if (!is_array($styles)) { $styles = XenForo_Model::create('XenForo_Model_Style')->rebuildStyleCache(); } if (!is_array($cacheData['options'])) { $cacheData['options'] = XenForo_Model::create('XenForo_Model_Option')->rebuildOptionCache(); } $options = new XenForo_Options($cacheData['options']); XenForo_Application::setDefaultsFromOptions($options); XenForo_Application::set('options', $options); if ($this->_styleId && isset($styles[$this->_styleId])) { $style = $styles[$this->_styleId]; } else { $style = reset($styles); } if ($style) { $properties = unserialize($style['properties']); $this->_styleId = $style['style_id']; $this->_styleModifiedDate = $style['last_modified_date']; } else { $properties = array(); $this->_styleId = 0; } XenForo_Template_Helper_Core::setStyleProperties($properties, false); XenForo_Template_Public::setStyleId($this->_styleId); XenForo_Template_Abstract::setLanguageId(0); }
/** * Does any preperations necessary for outputting to be done. */ protected function _prepareForOutput() { $styles = XenForo_Application::get('styles'); if ($this->_styleId && isset($styles[$this->_styleId])) { $style = $styles[$this->_styleId]; } else { $style = reset($styles); } if ($style) { $properties = unserialize($style['properties']); $this->_styleId = $style['style_id']; $this->_styleModifiedDate = $style['last_modified_date']; } else { $properties = array(); $this->_styleId = 0; } $languages = XenForo_Application::get('languages'); if ($this->_languageId && isset($languages[$this->_languageId])) { $language = $languages[$this->_languageId]; } else { $language = reset($languages); } if ($language) { $this->_textDirection = $language['text_direction']; $this->_languageId = $language['language_id']; } else { $this->_textDirection = 'LTR'; $this->_languageId = 0; } XenForo_Template_Helper_Core::setStyleProperties($properties, false); XenForo_Template_Public::setStyleId($this->_styleId); XenForo_Template_Abstract::setLanguageId($this->_languageId); }