public function render(array $widget, $positionCode, array $params, XenForo_Template_Abstract $template, &$output) { $html = false; $containerData = array(); $requiredExternals = array(); try { if (!$this->_testConditional($widget, $params)) { // expression failed, stop rendering... if (WidgetFramework_Option::get('layoutEditorEnabled')) { $html = new XenForo_Phrase('wf_layout_editor_widget_conditional_failed'); } else { $html = ''; } } } catch (Exception $e) { // problem while testing conditional, stop rendering... if (WidgetFramework_Core::debugMode() or WidgetFramework_Option::get('layoutEditorEnabled')) { $html = $e->getMessage(); } else { $html = ''; } } // add check for mobile (user agent spoofing) // since 2.2.2 if (!empty($widget['options']['deactivate_for_mobile'])) { if (XenForo_Visitor::isBrowsingWith('mobile')) { $html = ''; } } // check for cache // since 1.2.1 $cacheId = false; $useUserCache = false; $useLiveCache = false; $lockId = ''; if ($html === false and $this->useCache($widget)) { // sondh@2013-04-02 // please keep this block of code in-sync'd with its copycat // implemented in WidgetFramework_WidgetRenderer::prepare $cacheId = $this->_getCacheId($widget, $positionCode, $params); $useUserCache = $this->useUserCache($widget); $useLiveCache = $this->useLiveCache($widget); $cached = WidgetFramework_Core::loadCachedWidget($cacheId, $useUserCache, $useLiveCache); if (!empty($cached) and is_array($cached)) { if ($this->isCacheUsable($cached, $widget)) { // found fresh cached html, use it asap $this->_restoreFromCache($cached, $html, $containerData, $requiredExternals); } else { // cached html has expired: try to acquire lock $lockId = $this->_acquireLock($widget, $positionCode, $params); if ($lockId === false) { // a lock cannot be acquired, an expired cached html is the second best choice $this->_restoreFromCache($cached, $html, $containerData, $requiredExternals); } } } else { // no cache found $lockId = $this->_acquireLock($widget, $positionCode, $params); } } if ($html === false and $lockId === false) { // a lock is required but we failed to acquired it // also, a cached could not be found // stop rendering $html = ''; } // conditional executed just fine if ($html === false) { $renderTemplate = $this->_getRenderTemplate($widget, $positionCode, $params); if (!empty($renderTemplate)) { $renderTemplateObject = $template->create($renderTemplate, array_merge($params, array('widget' => $widget))); // reset required externals $existingRequiredExternals = WidgetFramework_Template_Extended::WidgetFramework_getRequiredExternals(); WidgetFramework_Template_Extended::WidgetFramework_setRequiredExternals(array()); $html = $this->_render($widget, $positionCode, $params, $renderTemplateObject); // get container data (using template_post_render listener) $containerData = self::_getContainerData($widget); // get widget required externals $requiredExternals = WidgetFramework_Template_Extended::WidgetFramework_getRequiredExternals(); WidgetFramework_Template_Extended::WidgetFramework_setRequiredExternals($existingRequiredExternals); } else { $html = $this->_render($widget, $positionCode, $params, $template); } $html = trim($html); if ($cacheId !== false) { $extraData = array(); if (!empty($containerData)) { $extraData[self::EXTRA_CONTAINER_DATA] = $containerData; } if (!empty($requiredExternals)) { $extraData[self::EXTRA_REQUIRED_EXTERNALS] = $requiredExternals; } WidgetFramework_Core::preSaveWidget($widget, $positionCode, $params, $html); WidgetFramework_Core::saveCachedWidget($cacheId, $html, $extraData, $useUserCache, $useLiveCache); } } $this->_releaseLock($lockId); if (!empty($containerData)) { // apply container data WidgetFramework_Template_Extended::WidgetFramework_mergeExtraContainerData($containerData); } if (!empty($requiredExternals)) { // register required external foreach ($requiredExternals as $type => $requirements) { foreach ($requirements as $requirement) { $template->addRequiredExternal($type, $requirement); } } } return $html; }