/** * Setups all default routes for [bd] Api. Also fires the code event * `api_setup_routes` and let any other add-ons to setup extra * routes for the system. * * @param array $routes the target routes array */ public static function setupRoutes(array &$routes) { self::addRoute($routes, 'index', 'bdApi_Route_PrefixApi_Index'); self::addRoute($routes, 'oauth', 'bdApi_Route_PrefixApi_OAuth'); self::addRoute($routes, 'categories', 'bdApi_Route_PrefixApi_Categories', 'data_only'); self::addRoute($routes, 'conversations', 'bdApi_Route_PrefixApi_Conversations', 'data_only'); self::addRoute($routes, 'conversation-messages', 'bdApi_Route_PrefixApi_ConversationMessages', 'data_only'); self::addRoute($routes, 'forums', 'bdApi_Route_PrefixApi_Forums', 'data_only'); self::addRoute($routes, 'navigation', 'bdApi_Route_PrefixApi_Navigation'); self::addRoute($routes, 'notifications', 'bdApi_Route_PrefixApi_Notifications'); self::addRoute($routes, 'pages', 'bdApi_Route_PrefixApi_Pages', 'data_only'); self::addRoute($routes, 'posts', 'bdApi_Route_PrefixApi_Posts', 'data_only'); self::addRoute($routes, 'profile-posts', 'bdApi_Route_PrefixApi_ProfilePosts', 'data_only'); self::addRoute($routes, 'tags', 'bdApi_Route_PrefixApi_Tags'); self::addRoute($routes, 'threads', 'bdApi_Route_PrefixApi_Threads', 'data_only'); self::addRoute($routes, 'users', 'bdApi_Route_PrefixApi_Users', 'data_only'); self::addRoute($routes, 'search', 'bdApi_Route_PrefixApi_Search', 'data_only'); self::addRoute($routes, 'assets', 'bdApi_Route_PrefixApi_Assets'); self::addRoute($routes, 'batch', 'bdApi_Route_PrefixApi_Batch'); self::addRoute($routes, 'subscriptions', 'bdApi_Route_PrefixApi_Subscriptions'); self::addRoute($routes, 'tools', 'bdApi_Route_PrefixApi_Tools'); // backward compatibility self::addRoute($routes, 'all-threads', 'bdApi_Route_PrefixApi_Threads'); XenForo_CodeEvent::fire('api_setup_routes', array(&$routes)); }
/** * Internal method for doing the actual swapping/shifting of route prefixes. * * @param string $defaultRoutePrefix * @param array $routesPublic */ protected static function _setCustomRoutePrefixes($defaultRoutePrefix, array $routesPublic) { $routesPublic['index'] = array('build_link' => 'all', 'route_class' => 'WidgetPortal_Route_PrefixPublic_Index'); $routesPublic['forum'] = array('build_link' => 'none', 'route_class' => 'WidgetPortal_Route_PrefixPublic_Forum'); $routesPublic[$defaultRoutePrefix]['build_link'] = 'all'; XenForo_Link::setHandlerInfoForGroup('public', $routesPublic); XenForo_CodeEvent::addListener('load_class_route_prefix', array(__CLASS__, 'loadClassRoutePrefix')); }
public function __construct() { $renderers = array(); $this->_registerDefaultRenderers($renderers); XenForo_CodeEvent::fire('widget_framework_ready', array(&$renderers)); foreach ($renderers as $renderer) { $this->_renderers[] = $renderer; } }
protected function _postDelete() { parent::_postDelete(); $discordId = $this->getExisting('da_discord_id'); if ($discordId !== null) { XenForo_CodeEvent::addListener('controller_post_dispatch', function ($c, $r, $n, $a) use($discordId) { try { self::refreshDiscordId($discordId); } catch (Exception $e) { XenForo_Error::logException($e, false); } }); } }
public static function init_dependencies(XenForo_Dependencies_Abstract $dependencies, array $data) { if ($dependencies instanceof XenForo_Dependencies_Public and ChipXF_MobileSwitcher_Detecter::isMobile()) { foreach ($data['codeEventListeners'] as $event => &$callbackList) { foreach ($callbackList as $key => $callback) { if (in_array($callback[0], XenForo_Application::get('options')->ChipXF_MS_AddonsDisabled)) { unset($data['codeEventListeners'][$event][$key]); } } } XenForo_CodeEvent::removeListeners(); XenForo_CodeEvent::setListeners($data['codeEventListeners']); ChipXF_MobileSwitcher_Detecter::$isMobile = true; } }
public function renderTree(array $tree, array $extraStates = array()) { if (XenForo_Application::get('options')->get('Bbm_PreCache_Enable')) { if (!empty($extraStates['bbmPreCacheInit']) && !$this->_bbmPreCacheDone) { parent::renderTree($tree, $extraStates); unset($extraStates['bbmPreCacheInit']); XenForo_CodeEvent::fire('bbm_callback_precache', array(&$this->_bbmPreCache, &$extraStates, 'wysiwyg')); XenForo_Application::set('bbm_preCache_wysiwyg', array($this->_bbmPreCache, $extraStates)); $this->_bbmPreCacheDone = true; return ''; } if (XenForo_Application::isRegistered('bbm_preCache_wysiwyg')) { list($_bbmPreCache, $_extraStates) = XenForo_Application::get('bbm_preCache_wysiwyg'); $this->_bbmPreCache = $_bbmPreCache; $extraStates['bbmPreCacheComplete'] = true; $extraStates += $_extraStates; } } return parent::renderTree($tree, $extraStates); }
public static function navigationTabs(array &$extraTabs, $selectedTabId) { $xenOptions = XenForo_Application::get('options'); $listeners = XenForo_CodeEvent::getEventListeners('navigation_tabs'); foreach ($listeners['_'] as $key => $callback) { if ($callback[0] == __CLASS__) { $listeners['_'] = array_slice($listeners['_'], $key + 1); } } if (!$listeners) { return true; } foreach ($listeners as $callbacks) { foreach ($callbacks as $callback) { if (is_callable($callback)) { $return = call_user_func_array($callback, array(&$extraTabs, $selectedTabId)); foreach ($extraTabs as $key => $extraTab) { if (!isset($extraTab['priority']) && isset($xenOptions->th_navigationTabs_priority[$callback[0] . '::' . $callback[1]])) { $extraTabs[$key]['priority'] = $xenOptions->th_navigationTabs_priority[$callback[0] . '::' . $callback[1]]; } } if ($return === false) { return false; } } } } foreach ($extraTabs as $tabKey => $extraTab) { if (isset($extraTab['nodeTab']['nat_display_order'])) { $extraTabs[$tabKey]['priority'] = $extraTab['nodeTab']['nat_display_order']; } elseif (!isset($extraTab['priority'])) { $extraTabs[$tabKey]['priority'] = 10; } } uasort($extraTabs, array('self', 'comparePriority')); return false; }
/** * Get the data and determine if we need to change the response code to 410. * * @param XenForo_Controller $controller * @param XenForo_ControllerResponse_Abstract|false $controllerResponse * @param string $controllerName * @param string $action * * @throws XenForo_Exception */ public static final function controllerPostDispatch(XenForo_Controller $controller, $controllerResponse, $controllerName, $action) { if ($controller instanceof XenForo_ControllerPublic_Abstract && $controllerResponse instanceof XenForo_ControllerResponse_Error && $controllerResponse->responseCode == 404) { $data = array(); XenForo_CodeEvent::fire('410_gone_data', array(&$data, $controller, $controllerName, $action)); $table = $field = ''; foreach ($data as $_controllerName => $info) { if ($_controllerName == $controllerName) { list($table, $field) = $info; break; } } if (($id = $controller->getInput()->filterSingle($field, XenForo_Input::UINT)) && $table && $field) { $db = XenForo_Application::getDb(); try { if (!$db->fetchOne("SELECT {$field} FROM {$table} WHERE {$field} = ?", $id) && $db->fetchOne("SELECT COUNT(*) FROM {$table} WHERE {$field} > ?", $id) > 0) { $controllerResponse->responseCode = 410; } } catch (Throwable $e) { XenForo_Error::logException($e, false, "410 Query Failed (Field: {$field}, Table: {$table}): "); } } } }
/** * Determines if the given media matches the criteria. * * @param array|string $criteria List of criteria, format: [] with keys rule * and data; may be serialized * @param boolean $matchOnEmpty If true and there's no criteria, true is * returned; otherwise, false * @param array $media * * @return boolean */ public static function mediaMatchesCriteria($criteria, $matchOnEmpty = false, array $media) { if (!($criteria = XenForo_Helper_Criteria::unserializeCriteria($criteria))) { return (bool) $matchOnEmpty; } foreach ($criteria as $criterion) { $data = $criterion['data']; switch ($criterion['rule']) { case 'categories': if (!isset($media['category_id'])) { return false; } if (empty($data['category_ids'])) { return false; } if (!in_array($media['category_id'], $data['category_ids'])) { return false; } break; default: $eventReturnValue = false; XenForo_CodeEvent::fire('criteria_xengallery_media', array($criterion['rule'], $data, $media, &$eventReturnValue)); if ($eventReturnValue === false) { return false; } } } return true; }
protected function _rebuildLoadClassHintsCache() { if (XenForo_Application::$versionId < 1020000) { return; } $newLoadClassHints = array('XenForo_ControllerPublic_Misc' => array()); XenForo_Application::get('options')->set('waindigo_loadClassHints', $newLoadClassHints); XenForo_CodeEvent::addListener('load_class', 'Waindigo_Listener_LoadClass', 'XenForo_ControllerPublic_Misc'); }
/** * Setup the visitor singleton. * * @param integer $userId User ID to setup as * @param array $options * * @return XenForo_Visitor */ public static function setup($userId, array $options = array()) { $userId = intval($userId); $options = array_merge(array('languageId' => 0, 'permissionUserId' => 0), $options); /* @var $userModel XenForo_Model_User */ $userModel = XenForo_Model::create('XenForo_Model_User'); $class = XenForo_Application::resolveDynamicClass('XenForo_Visitor'); $object = new $class(); if ($userId && ($user = $userModel->getVisitingUserById($userId))) { if ($user['is_admin']) { if ($options['permissionUserId']) { // force permissions for testing $user = $userModel->setPermissionsFromUserId($user, $options['permissionUserId']); } if ($options['languageId']) { $user['admin_language_id'] = $user['language_id'] = $options['languageId']; } } $object->_user = $user; } else { $object->_user = $userModel->getVisitingGuestUser(); if ($options['languageId']) { $object->_user['language_id'] = $options['languageId']; } } $object->_user = $userModel->prepareUser($object->_user); $object->_user['referer'] = !empty($options['referer']) ? $options['referer'] : null; $object->_user['from_search'] = !empty($options['fromSearch']); if (!empty($object->_user['ignored'])) { $ignored = XenForo_Helper_Php::safeUnserialize($object->_user['ignored']); $object->_user['ignoredUsers'] = $ignored; } else { $object->_user['ignoredUsers'] = array(); } if (!$object->_user['global_permission_cache']) { // force a rebuild if we don't have the perm cache $perms = XenForo_Model::create('XenForo_Model_Permission')->rebuildPermissionCombinationById($object->_user['permission_combination_id']); $object->_user['permissions'] = $perms ? $perms : array(); } else { $object->_user['permissions'] = XenForo_Permission::unserializePermissions($object->_user['global_permission_cache']); } $object->setVisitorLanguage($object->_user['language_id']); XenForo_Locale::setDefaultTimeZone($object->_user['timezone']); self::$_instance = $object; self::$_setupOptions = $options; XenForo_CodeEvent::fire('visitor_setup', array(&self::$_instance)); return self::$_instance; }
/** * This is to ensure copyright notices don't display on every page if all * add-ons are newer than 15 September 2012 (unless explicitly set). * * This code is redundant if all add-ons are newer than 25 June 2013. */ protected function _removeUnwantedCopyrightNotice() { $thListeners = XenForo_CodeEvent::getEventListeners('template_hook'); $tprListeners = XenForo_CodeEvent::getEventListeners('template_post_render'); if (!empty($thListeners) || !empty($tprListeners)) { $this->_getLibraryListenerFileVersion('Template'); if (!empty($thListeners)) { $templateHookVersion = $this->_getLibraryListenerFileVersion('TemplateHook'); } if (!empty($tprListeners)) { $templatePostRenderVersion = $this->_getLibraryListenerFileVersion('TemplatePostRender'); } } $tcListeners = XenForo_CodeEvent::getEventListeners('template_create'); if (!empty($tcListeners)) { $this->_getLibraryListenerFileVersion('TemplateCreate'); } $lccListeners = XenForo_CodeEvent::getEventListeners('load_class_controller'); if (!empty($lccListeners)) { $loadClassVersion = $this->_getLibraryListenerFileVersion('LoadClass', false); } if (defined(Waindigo_Listener_InitDependencies::COPYRIGHT_MODIFICATION_SIMPLE_CACHE_KEY) && !XenForo_Application::getSimpleCacheData(self::COPYRIGHT_MODIFICATION_SIMPLE_CACHE_KEY)) { return; } if (XenForo_Application::$versionId < 1020000 && self::$_showCopyright) { return; } $className = get_class(self::$_controller); if (XenForo_Application::$versionId < 1020000 && strpos($className, 'Waindigo') === 0) { return; } if (XenForo_Application::get('options')->waindigo_loadClassHints) { $controllers = XenForo_Application::get('options')->waindigo_loadClassHints; } else { $controllers = array('XenForo_ControllerPublic_Misc' => array()); } $addOns = array(); if (XenForo_Application::$versionId < 1020000 || !array_key_exists($className, $controllers)) { if (XenForo_Application::$versionId >= 1020000) { if (!empty($thListeners['_'])) { $thListeners = $thListeners['_']; } else { $thListeners = array(); } } if (!empty($thListeners)) { foreach ($thListeners as $templateHook) { if (strlen($templateHook[0]) > strlen('Waindigo_') && substr($templateHook[0], 0, strlen('Waindigo_')) == 'Waindigo_') { if ($templateHookVersion < '20120715') { return; } $addOns[] = substr($templateHook[0], 0, strlen($templateHook[0]) - strlen('_Listener_TemplateHook')); } } } if (XenForo_Application::$versionId >= 1020000) { if (!empty($tprListeners['_'])) { $tprListeners = $tprListeners['_']; } else { $tprListeners = array(); } } if (!empty($tprListeners)) { foreach ($tprListeners as $templatePostRender) { if (strlen($templatePostRender[0]) > strlen('Waindigo_') && substr($templatePostRender[0], 0, strlen('Waindigo_')) == 'Waindigo_') { $addOnId = substr($templatePostRender[0], 0, strlen($templatePostRender[0]) - strlen('_Listener_TemplatePostRender')); if (in_array($addOnId, $addOns)) { continue; } if ($templatePostRenderVersion < '20120715') { return; } $addOns[] = $addOnId; } } } if (XenForo_Application::$versionId >= 1020000) { if (!empty($lccListeners['_'])) { $lccListeners = $lccListeners['_']; } else { $lccListeners = array(); } } if (!empty($lccListeners)) { foreach ($lccListeners as $loadClassController) { if (strlen($loadClassController[0]) > strlen('Waindigo_') && substr($loadClassController[0], 0, strlen('Waindigo_')) == 'Waindigo_') { if (strpos($loadClassController[0], '_Listener_LoadClassController') > 0) { $addOnId = substr($loadClassController[0], 0, strlen($loadClassController[0]) - strlen('_Listener_LoadClassController')); } else { $addOnId = substr($loadClassController[0], 0, strlen($loadClassController[0]) - strlen('_Listener_LoadClass')); } if ($loadClassVersion >= '20121018') { $loadClassController = Waindigo_Listener_LoadClass::create($loadClassController[0]); if (method_exists($loadClassController, 'getExtendedClass')) { $extendedClasses = $loadClassController->getExtendedClasses(); if (in_array(get_class(self::$_controller), $extendedClasses)) { return; } } } if (!in_array($addOnId, $addOns)) { $addOns[] = $addOnId; } } } } if (!empty($addOns) && XenForo_Application::$versionId >= 1020000) { $enabledAddOns = XenForo_Application::get('addOns'); foreach ($enabledAddOns as $addOnId => $addOn) { if ($addOn > 1372118400) { $addOnKey = array_search($addOnId, $addOns); if ($addOnKey !== FALSE) { unset($addOns[$addOnKey]); } } } } if (!empty($addOns)) { $cpdListeners = XenForo_CodeEvent::getEventListeners('controller_pre_dispatch'); if (XenForo_Application::$versionId >= 1020000) { $cpdListeners = $cpdListeners['_']; } foreach ($cpdListeners as $controllerPreDispatch) { if (strlen($controllerPreDispatch[0]) > strlen('Waindigo_') && substr($controllerPreDispatch[0], 0, strlen('Waindigo_')) == 'Waindigo_') { if ($controllerPreDispatch[0] != 'Waindigo_Listener_ControllerPreDispatch') { $addOnId = substr($controllerPreDispatch[0], 0, strlen($controllerPreDispatch[0]) - strlen('_Listener_ControllerPreDispatch')); $addOnKey = array_search($addOnId, $addOns); if ($addOnKey !== FALSE) { unset($addOns[$addOnKey]); } } } } } } if (self::$_showCopyright && !array_key_exists($className, $controllers) && strpos($className, 'Waindigo') !== 0) { return; } if (empty($addOns) && (!empty($thListeners) || !empty($tprListeners))) { if (class_exists('Waindigo_Listener_Template')) { if (method_exists('Waindigo_Listener_Template', 'setCopyrightNotice')) { Waindigo_Listener_Template::setCopyrightNotice(true); } else { $addOnId = reset($addOns); eval(' class ' . $addOnId . '_Listener_Template extends Waindigo_Listener_Template { public static function setCopyrightNotice($copyrightNotice) { self::$_copyrightNotice = $copyrightNotice; } }'); call_user_func(array($addOnId . '_Listener_Template', 'setCopyrightNotice'), true); } } } }
/** * Removes all listeners. */ public static function removeListeners() { self::$_listeners = false; }
public function export($overwrite = false) { if (!$this->_addOnId) { throw new XenForo_Exception('Please specify an add-on id.'); } $filename = str_replace('_', '/', $this->_className) . '.php'; $existingContents = ''; $fullFilename = XenForo_Autoloader::getInstance()->getRootDir() . '/' . $filename; if (file_exists($fullFilename)) { $existingContents = file_get_contents($fullFilename); $existingContentsArray = preg_split('/(\\r\\n|\\n|\\r)/', $existingContents); foreach ($existingContentsArray as $key => $value) { if (rtrim($value) != $value) { $existingContentsArray[$key] = rtrim($value); } } $existingContents = implode("\n", $existingContentsArray); $existingContents = str_replace("\t", ' ', $existingContents); file_put_contents($fullFilename, $existingContents); $existingPhpFile = self::createFromContents($this->_className, $existingContents); } else { if (!file_exists(dirname($fullFilename))) { XenForo_Helper_File::createDirectory(dirname($fullFilename)); } $existingPhpFile = self::createFromContents($this->_className); } $contents = $this->getHeader(); $this->mergeConstants($existingPhpFile->getConstants()); if (isset($this->_constants) && !empty($this->_constants)) { foreach ($this->_constants as $constantName => $constant) { $contents .= $constant->getPhpDocAsString(); $contents .= "\n\t"; $contents .= 'const ' . $constant->getConstantName() . ' = ' . $constant->getValue() . ';' . "\n"; } } $this->mergeVariables($existingPhpFile->getVariables()); if (isset($this->_variables) && !empty($this->_variables)) { /* @var $variable ThemeHouse_PhpFile_Variable */ foreach ($this->_variables as $variableName => $variable) { $contents .= $variable->getPhpDocAsString(); $contents .= "\n\t"; $contents .= $variable->getFullSignatureAsString() . ' = ' . $variable->getValue() . ';' . "\n"; } } $this->mergeFunctions($existingPhpFile->getFunctions()); if (isset($this->_functions) && !empty($this->_functions)) { /* @var $function ThemeHouse_PhpFile_Function */ foreach ($this->_functions as $functionName => $function) { $contents .= $function->getPhpDocAsString(); $contents .= "\n\t"; $contents .= $function->getFullSignatureAsString(); $contents .= "\n\t{"; $contents .= $function->getBodyAsString(); $contents .= "\n\t}\n"; } } $contents .= "}"; $export = XenForo_CodeEvent::fire('phpfile_export_th', array(&$filename, &$contents, $existingContents, $overwrite, $this->_addOnId)); if ($export) { if (!file_exists(dirname(XenForo_AutoLoader::getInstance()->getRootDir() . '/' . $filename))) { mkdir(dirname(XenForo_AutoLoader::getInstance()->getRootDir() . '/' . $filename), 0, true); } file_put_contents(XenForo_AutoLoader::getInstance()->getRootDir() . '/' . $filename, $contents); } }
/** * Resolves dynamic, run time inheritance for the specified class. * The classes to be loaded for this base class are grabbed via the event. * These classes must inherit from from XFCP_x, which is a non-existant * class that is dynamically created, inheriting from the correct class * as needed. * * If a fake base is needed when the base class doesn't exist, and there * are no classes extending it, false will still be returned! This prevents * an unnecessary eval. * * @param string $class Name of class * @param string $type Type of class (for determining event to fire) * @param string|false $fakeBase If the specified class doesn't exist, an alternative base can be specified * * @return false|string False or name of class to instantiate */ public static function resolveDynamicClass($class, $type, $fakeBase = false) { if (!XenForo_Application::autoload($class)) { if ($fakeBase) { $fakeNeeded = true; } else { return false; } } else { $fakeNeeded = false; } if (!empty(self::$_classCache[$class])) { return self::$_classCache[$class]; } $createClass = $class; $extend = array(); XenForo_CodeEvent::fire('load_class_' . $type, array($class, &$extend)); if ($fakeNeeded) { if (!$extend) { return false; } eval('class ' . $class . ' extends ' . $fakeBase . ' {}'); } if ($extend) { try { foreach ($extend as $dynamicClass) { // XenForo Class Proxy, in case you're wondering $proxyClass = 'XFCP_' . $dynamicClass; eval('class ' . $proxyClass . ' extends ' . $createClass . ' {}'); XenForo_Application::autoload($dynamicClass); $createClass = $dynamicClass; } } catch (Exception $e) { self::$_classCache[$class] = $class; throw $e; } } self::$_classCache[$class] = $createClass; return $createClass; }
/** * * @param array $addOns */ protected function _checkAddOnsNeedUpgrading(array $addOns, $checkDisabled = false) { if (empty($addOns)) { return false; } if (XenForo_Application::$versionId < 1020000 || $checkDisabled) { /* @var $addOnModel XenForo_Model_AddOn */ $addOnModel = XenForo_Model::create('XenForo_Model_AddOn'); $allAddOns = $addOnModel->getAllAddOns(); } else { $allAddOns = XenForo_Application::get('addOns'); } $lastXmlUploadDate = $this->_getLastXmlUploadDate(); foreach ($addOns as $addOnId) { if (isset($allAddOns[$addOnId])) { $addOn = $allAddOns[$addOnId]; try { $addOnXML = new SimpleXMLElement(file_get_contents(XenForo_Application::getInstance()->getRootDir() . '/install/data/addon-' . $addOnId . '.xml')); $versionId = (string) $addOnXML->attributes()->version_id; } catch (Exception $e) { $versionId = ''; } if (is_array($addOn) && $versionId > $addOn['version_id'] || !is_array($addOn) && $versionId > $addOn) { self::$_upgradeAddOns[$addOnId] = $addOn; } else { $xmlUploadDate = filemtime(XenForo_Application::getInstance()->getRootDir() . '/install/data/addon-' . $addOnId . '.xml'); if ($xmlUploadDate > $lastXmlUploadDate) { $lastXmlUploadDate = $xmlUploadDate; } } } } eval(' class Waindigo_Listener_ControllerPreDispatch_TemplatePostRender { public static function templatePostRender($templateName, &$content, array &$containerData, XenForo_Template_Abstract $template) { if ($templateName == "PAGE_CONTAINER") { $upgradeAddOns = Waindigo_Listener_ControllerPreDispatch::getUpgradeAddOns(); if (!empty($upgradeAddOns)) { $params = $template->getParams(); if (!$params[\'showUpgradePendingNotice\']) { $pattern = \'#<noscript><p class="importantMessage">.*</p></noscript>#U\'; $replacement = \'<p class="importantMessage"><a href="\'.XenForo_Link::buildAdminLink(\'add-ons/upgrade-all-from-xml\').\'">\' . new XenForo_Phrase(\'upgrade_add_on\') . \'</a></p>\'; $content = preg_replace($pattern, \'${1}\' . $replacement, $content); } } } } }'); $tprListeners = XenForo_CodeEvent::getEventListeners('template_post_render'); if (!$tprListeners || XenForo_Application::$versionId >= 1020052) { $tprListeners = array(); } $newListener = array('Waindigo_Listener_ControllerPreDispatch_TemplatePostRender', 'templatePostRender'); if (XenForo_Application::$versionId < 1020000) { $tprListeners[] = $newListener; } else { $tprListeners['_'][] = $newListener; } XenForo_CodeEvent::setListeners(array('template_post_render' => $tprListeners)); if (empty(self::$_upgradeAddOns)) { $this->_setLastXmlUploadDate($lastXmlUploadDate); return false; } return true; }
/** * Runs the request, handling from routing straight through to response output. * Primary method to be used by the external API. * * @return string|null Returns a string if {@link $_sendResponse} is false */ public function run() { ob_start(); XenForo_Application::set('fc', $this); $this->setup(); $this->setRequestPaths(); $showDebugOutput = $this->showDebugOutput(); $this->_dependencies->preLoadData(); XenForo_CodeEvent::fire('front_controller_pre_route', array($this)); $routeMatch = $this->route(); XenForo_CodeEvent::fire('front_controller_pre_dispatch', array($this, &$routeMatch)); $controllerResponse = $this->dispatch($routeMatch); if (!$controllerResponse) { XenForo_Error::noControllerResponse($routeMatch, $this->_request); exit; } $viewRenderer = $this->_getViewRenderer($routeMatch->getResponseType()); if (!$viewRenderer) { // note: should only happen if there's an error getting the default renderer, which should never happen :) XenForo_Error::noViewRenderer($this->_request); exit; } $containerParams = array('majorSection' => $routeMatch->getMajorSection(), 'minorSection' => $routeMatch->getMinorSection()); XenForo_CodeEvent::fire('front_controller_pre_view', array($this, &$controllerResponse, &$viewRenderer, &$containerParams)); $content = $this->renderView($controllerResponse, $viewRenderer, $containerParams); if ($showDebugOutput) { $content = $this->renderDebugOutput($content); } $bufferedContents = ob_get_contents(); ob_end_clean(); if ($bufferedContents !== '' && is_string($content)) { if (preg_match('#<body[^>]*>#sU', $content, $match)) { $content = str_replace($match[0], $match[0] . $bufferedContents, $content); } else { $content = $bufferedContents . $content; } } XenForo_CodeEvent::fire('front_controller_post_view', array($this, &$content)); if ($this->_sendResponse) { $headers = $this->_response->getHeaders(); $isText = false; foreach ($headers as $header) { if ($header['name'] == 'Content-Type') { if (strpos($header['value'], 'text/') === 0) { $isText = true; } break; } } if ($isText && is_string($content) && $content) { $extraHeaders = XenForo_Application::gzipContentIfSupported($content); foreach ($extraHeaders as $extraHeader) { $this->_response->setHeader($extraHeader[0], $extraHeader[1], $extraHeader[2]); } } if (is_string($content) && $content && !ob_get_level() && XenForo_Application::get('config')->enableContentLength) { if ($this->_response->getHttpResponseCode() >= 400 && strpos($this->_request->getServer('HTTP_USER_AGENT', ''), 'IEMobile') !== false) { // Windows mobile bug - 400+ errors cause the standard browser error // to be output if a content length is sent. ...Err, what? } else { $this->_response->setHeader('Content-Length', strlen($content), true); } } $this->_response->sendHeaders(); if ($content instanceof XenForo_FileOutput) { $content->output(); } else { echo $content; } } else { return $content; } }
/** * Pre-loads globally required data for the system. */ public function preLoadData() { $required = array_merge(array('options', 'languages', 'contentTypes', 'codeEventListeners', 'deferredRun', 'simpleCache', 'addOns', 'defaultStyleProperties', 'routeFiltersIn', 'routeFiltersOut'), $this->_dataPreLoadFromRegistry); $dr = new XenForo_Model_DataRegistry(); // this is a slight hack to prevent the class from being cached $data = $dr->getMulti($required); if (XenForo_Application::get('config')->enableListeners) { if (!is_array($data['codeEventListeners'])) { $data['codeEventListeners'] = XenForo_Model::create('XenForo_Model_CodeEvent')->rebuildEventListenerCache(); } XenForo_CodeEvent::setListeners($data['codeEventListeners']); } if (!is_array($data['options'])) { $data['options'] = XenForo_Model::create('XenForo_Model_Option')->rebuildOptionCache(); } $options = new XenForo_Options($data['options']); XenForo_Application::setDefaultsFromOptions($options); XenForo_Application::set('options', $options); if (!is_array($data['languages'])) { $data['languages'] = XenForo_Model::create('XenForo_Model_Language')->rebuildLanguageCache(); } XenForo_Application::set('languages', $data['languages']); if (!is_array($data['defaultStyleProperties'])) { $data['defaultStyleProperties'] = XenForo_Model::create('XenForo_Model_StyleProperty')->rebuildPropertyCacheInStyleAndChildren(0, true); } XenForo_Application::set('defaultStyleProperties', $data['defaultStyleProperties']); if (!is_array($data['contentTypes'])) { $data['contentTypes'] = XenForo_Model::create('XenForo_Model_ContentType')->rebuildContentTypeCache(); } XenForo_Application::set('contentTypes', $data['contentTypes']); if (!is_int($data['deferredRun'])) { $data['deferredRun'] = XenForo_Model::create('XenForo_Model_Deferred')->updateNextDeferredTime(); } XenForo_Application::set('deferredRun', $data['deferredRun']); if (!is_array($data['addOns'])) { $data['addOns'] = XenForo_Model::create('XenForo_Model_AddOn')->rebuildActiveAddOnCache(); } XenForo_Application::set('addOns', $data['addOns']); if (!is_array($data['simpleCache'])) { $data['simpleCache'] = array(); XenForo_Model::create('XenForo_Model_DataRegistry')->set('simpleCache', $data['simpleCache']); } XenForo_Application::set('simpleCache', $data['simpleCache']); if (!is_array($data['routeFiltersIn']) || !is_array($data['routeFiltersOut'])) { $filterCache = XenForo_Model::create('XenForo_Model_RouteFilter')->rebuildRouteFilterCache(); $data['routeFiltersIn'] = $filterCache['in']; $data['routeFiltersOut'] = $filterCache['out']; } XenForo_Application::set('routeFiltersIn', $data['routeFiltersIn']); XenForo_Application::set('routeFiltersOut', $data['routeFiltersOut']); XenForo_Link::setRouteFiltersOut($data['routeFiltersOut']); $this->_handleCustomPreloadedData($data); XenForo_CodeEvent::fire('init_dependencies', array($this, $data)); }
protected function _disableListeners() { if (isset($this->_data['addon_id'])) { $this->_db->query(' UPDATE xf_addon SET active = 0 WHERE addon_id = ? ', $this->_data['addon_id']); $cache = $this->getModelFromCache('XenForo_Model_CodeEvent')->rebuildEventListenerCache(); XenForo_CodeEvent::setListeners($cache, false); } }
/** * Resolves dynamic, run time inheritance for the specified class. * The classes to be loaded for this base class are grabbed via the event. * These classes must inherit from from XFCP_x, which is a non-existant * class that is dynamically created, inheriting from the correct class * as needed. * * If a fake base is needed when the base class doesn't exist, and there * are no classes extending it, false will still be returned! This prevents * an unnecessary eval. * * @param string $class Name of class * @param string $type Type of class (for determining event to fire) * @param string|false $fakeBase If the specified class doesn't exist, an alternative base can be specified * * @return false|string False or name of class to instantiate */ public static function resolveDynamicClass($class, $type = '', $fakeBase = false) { if (!$class) { return false; } if (!XenForo_Application::autoload($class)) { if ($fakeBase) { $fakeNeeded = true; } else { return false; } } else { $fakeNeeded = false; } if (!empty(self::$_classCache[$class])) { return self::$_classCache[$class]; } $createClass = $class; $extend = array(); XenForo_CodeEvent::fire('load_class', array($class, &$extend), $class); if ($type) { XenForo_CodeEvent::fire('load_class_' . $type, array($class, &$extend), $class); } if ($fakeNeeded) { if (!$extend) { return false; } eval('class ' . $class . ' extends ' . $fakeBase . ' {}'); } if ($extend) { try { foreach ($extend as $dynamicClass) { if (preg_match('/[;,$\\/#"\'\\.()]/', $dynamicClass)) { continue; } // XenForo Class Proxy, in case you're wondering $proxyClass = 'XFCP_' . $dynamicClass; $namespaceEval = ''; $nsSplit = strrpos($dynamicClass, '\\'); if ($nsSplit !== false && ($ns = substr($dynamicClass, 0, $nsSplit))) { $namespaceEval = "namespace {$ns}; "; $proxyClass = 'XFCP_' . substr($dynamicClass, $nsSplit + 1); $createClass = '\\' . $createClass; } eval($namespaceEval . 'class ' . $proxyClass . ' extends ' . $createClass . ' {}'); XenForo_Application::autoload($dynamicClass); $createClass = $dynamicClass; } } catch (Exception $e) { self::$_classCache[$class] = $class; throw $e; } } self::$_classCache[$class] = $createClass; return $createClass; }
/** * * @param string $hint */ protected static function _fetchDisabledInstallerWaindigoListeners($hint = '') { /* @var $codeEventModel XenForo_Model_CodeEvent */ $codeEventModel = XenForo_Model::create('XenForo_Model_CodeEvent'); $listeners = $codeEventModel->getAllEventListeners(); $installerWaindigoListeners = XenForo_CodeEvent::getEventListeners('load_class_installer_waindigo'); if (XenForo_Application::$versionId > 1020000) { if (isset($installerWaindigoListeners['_'])) { $installerWaindigoListeners = $installerWaindigoListeners['_']; } else { $installerWaindigoListeners = array(); } if ($hint) { if (isset($installerWaindigoListeners[$hint])) { $installerWaindigoListeners = array_merge($installerWaindigoListeners, $installerWaindigoListeners[$hint]); } } } foreach ($listeners as $listener) { if ($listener['event_id'] == 'load_class_installer_waindigo') { if ($installerWaindigoListeners) { foreach ($installerWaindigoListeners as $installerWaindigoListener) { list($callbackClass, $callbackMethod) = $installerWaindigoListener; if ($listener['callback_class'] == $callbackClass && $listener['callback_method'] == $callbackMethod) { continue 2; } } } if ($listener['active']) { XenForo_CodeEvent::addListener('load_class_installer_waindigo', array($listener['callback_class'], $listener['callback_method']), $hint); } } } $installerWaindigoListeners = XenForo_CodeEvent::getEventListeners('load_class_installer_waindigo'); }
public function __construct($directory) { static::$instance = $this; $this->loadConfig($directory); \XenForo_CodeEvent::addListener('load_class_datawriter', 'Robbo\\XfSync\\Listener::extendClass'); }
protected function _postTemplateChange($file, $action) { XenForo_CodeEvent::fire('template_file_change', array($file, $action), $file); }
/** * This function is called immediately after an action is dispatched. * * @param mixed The response from the controller. Generally, a XenForo_ControllerResponse_Abstract object. * @param string The name of the final controller that was invoked * @param string The name of the final action that was invoked */ public final function postDispatch($controllerResponse, $controllerName, $action) { $this->updateSession($controllerResponse, $controllerName, $action); $this->updateSessionActivity($controllerResponse, $controllerName, $action); $this->_postDispatchType($controllerResponse, $controllerName, $action); $this->_postDispatch($controllerResponse, $controllerName, $action); XenForo_CodeEvent::fire('controller_post_dispatch', array($this, $controllerResponse, $controllerName, $action), $controllerName); }
/** * Gets the default source handler. * * @return XenForo_Search_SourceHandler_Abstract */ public static function getDefaultSourceHandler() { $class = 'XenForo_Search_SourceHandler_MySqlFt'; XenForo_CodeEvent::fire('search_source_create', array(&$class)); $class = XenForo_Application::resolveDynamicClass($class); return new $class(); }
/** * Gets the editor template. The WYSIWYG editor will be used if supported by * the browser. * * @param XenForo_View $view * @param string $formCtrlName Name of the textarea. If using the WYSIWYG editor, this will have _html appended to it. * @param string $message Default message to put in editor. This should contain BB code * @param array $editorOptions Array of options for the editor. Defaults are provided for any unspecified * Currently supported: * editorId - (string) override normal {formCtrlName}_html id * templateName - (string) override normal 'editor' name * disable - (boolean) true to prevent WYSIWYG from activating * json - (array) JSON options to be passed to the JS * * @return XenForo_Template_Abstract */ public static function getEditorTemplate(XenForo_View $view, $formCtrlName, $message = '', array $editorOptions = array()) { $messageHtml = ''; if (!empty($editorOptions['disable'])) { $showWysiwyg = false; } else { if (!XenForo_Visitor::getInstance()->enable_rte) { $showWysiwyg = false; } else { $showWysiwyg = self::supportsRichTextEditor(); } } $draftOption = XenForo_Application::getOptions()->saveDrafts; if (empty($draftOption['enabled'])) { unset($editorOptions['autoSaveUrl']); } else { if (!empty($editorOptions['autoSaveUrl']) && !isset($editorOptions['json']['autoSaveFrequency'])) { $editorOptions['json']['autoSaveFrequency'] = $draftOption['saveFrequency']; } } if (empty($editorOptions['templateName'])) { $editorOptions['templateName'] = 'editor'; } if (!isset($editorOptions['height'])) { $editorOptions['height'] = '260px'; } if (!isset($editorOptions['json']['bbCodes'])) { if (XenForo_Application::isRegistered('bbCode')) { $bbCodeCache = XenForo_Application::get('bbCode'); } else { $bbCodeCache = XenForo_Model::create('XenForo_Model_BbCode')->getBbCodeCache(); XenForo_Application::set('bbCode', $bbCodeCache); } $bbCodes = array(); if (!empty($bbCodeCache['bbCodes'])) { foreach ($bbCodeCache['bbCodes'] as $bbCodeTag => $bbCode) { if (!$bbCode['editor_icon_url']) { continue; } $bbCodes[$bbCodeTag] = array('title' => new XenForo_Phrase('custom_bb_code_' . $bbCodeTag . '_title'), 'hasOption' => $bbCode['has_option']); } } $editorOptions['json']['bbCodes'] = $bbCodes; } XenForo_CodeEvent::fire('editor_setup', array($view, $formCtrlName, &$message, &$editorOptions, &$showWysiwyg)); if ($showWysiwyg) { if (substr($formCtrlName, -1) == ']') { $formCtrlNameHtml = substr($formCtrlName, 0, -1) . '_html]'; } else { $formCtrlNameHtml = $formCtrlName . '_html'; } if ($message !== '') { $bbCodeParser = XenForo_BbCode_Parser::create(XenForo_BbCode_Formatter_Base::create('Wysiwyg', array('view' => $view))); $messageHtml = $bbCodeParser->render($message, array('lightBox' => false)); } } else { $formCtrlNameHtml = $formCtrlName; } // get editor id if (isset($editorOptions['editorId'])) { $editorId = $editorOptions['editorId']; } else { $ctrlInc = 0; do { $editorId = 'ctrl_' . $formCtrlName . ($ctrlInc ? "_{$ctrlInc}" : ''); $ctrlInc++; } while (isset(self::$_editorIds[$editorId]) && $ctrlInc < 100); self::$_editorIds[$editorId] = true; } return $view->createTemplateObject($editorOptions['templateName'], array('showWysiwyg' => $showWysiwyg, 'height' => $editorOptions['height'], 'formCtrlNameHtml' => $formCtrlNameHtml, 'formCtrlName' => $formCtrlName, 'editorId' => $editorId, 'message' => $message, 'messageHtml' => $messageHtml, 'editorOptions' => $editorOptions)); }
public function runXenDynamic($html) { global $XenDynamic_indexFile, $XenDynamic_container; ob_start(); $this->setup(); $this->_request->setBasePath(XenForo_Link::convertUriToAbsoluteUri("{$XenDynamic_indexFile}")); $this->setRequestPaths(); $showDebugOutput = $this->showDebugOutput(); $this->_dependencies->preLoadData(); XenForo_CodeEvent::fire('front_controller_pre_route', array($this)); $routeMatch = $this->route(); XenForo_CodeEvent::fire('front_controller_pre_dispatch', array($this, &$routeMatch)); $controllerResponse = $this->dispatch($routeMatch); $controllerResponse = new XenForo_ControllerResponse_View(); $controllerResponse->templateName = "XenDynamic"; $controllerResponse->viewName = "XenDynamic_Index"; /* $title = ""; if(preg_match('/<title>(.*?)<\/title>/i', $html, $matches) && count($matches) == 2){ $title = $matches[1]; } $controllerResponse->params = array( 'title' => $title, 'html' => $html ); */ $viewRenderer = $this->_getViewRenderer('html'); if (!$viewRenderer) { XenForo_Error::noViewRenderer($this->_request); exit; } $viewRenderer->setNeedsContainer($XenDynamic_container); $containerParams = array(); XenForo_CodeEvent::fire('front_controller_pre_view', array($this, &$controllerResponse, &$viewRenderer, &$containerParams)); $content = $this->renderView($controllerResponse, $viewRenderer, $containerParams); if ($showDebugOutput) { $content = $this->renderDebugOutput($content); } $bufferedContents = ob_get_contents(); ob_end_clean(); if ($bufferedContents !== '') { $content = $bufferedContents . $content; } XenForo_CodeEvent::fire('front_controller_post_view', array($this, &$content)); /* if ($this->_sendResponse) { $headers = $this->_response->getHeaders(); $isText = false; foreach ($headers AS $header) { if ($header['name'] == 'Content-Type') { if (strpos($header['value'], 'text/') === 0) { $isText = true; } break; } } if ($isText && is_string($content) && $content) { $extraHeaders = XenForo_Application::gzipContentIfSupported($content); foreach ($extraHeaders AS $extraHeader) { $this->_response->setHeader($extraHeader[0], $extraHeader[1], $extraHeader[2]); } } if (is_string($content) && $content && !ob_get_level() && XenForo_Application::get('config')->enableContentLength) { $this->_response->setHeader('Content-Length', strlen($content), true); } $this->_response->sendHeaders(); if ($content instanceof XenForo_FileOutput) { $content->output(); } else { echo $content; } } else { */ return $content; // } }
/** * Runs the request, handling from routing straight through to response output. * Primary method to be used by the external API. * * @return string|null Returns a string if {@link $_sendResponse} is false */ public function run($innerContent = "", $newParams = array()) { ob_start(); $this->setup(); $this->setRequestPaths(); $showDebugOutput = $this->showDebugOutput(); $this->_dependencies->preLoadData(); XenForo_CodeEvent::fire('front_controller_pre_route', array($this)); $routeMatch = $this->route(); XenForo_CodeEvent::fire('front_controller_pre_dispatch', array($this, &$routeMatch)); $controllerResponse = $this->dispatch($routeMatch); if (!$controllerResponse) { XenForo_Error::noControllerResponse($routeMatch, $this->_request); exit; } $viewRenderer = $this->_getViewRenderer($routeMatch->getResponseType()); if (!$viewRenderer) { // note: should only happen if there's an error getting the default renderer, which should never happen :) XenForo_Error::noViewRenderer($this->_request); exit; } $containerParams = array('majorSection' => $routeMatch->getMajorSection(), 'minorSection' => $routeMatch->getMinorSection()); XenForo_CodeEvent::fire('front_controller_pre_view', array($this, &$controllerResponse, &$viewRenderer, &$containerParams)); $content = $this->renderView($controllerResponse, $viewRenderer, $containerParams, $innerContent, $newParams); if ($showDebugOutput) { $content = $this->renderDebugOutput($content); } $bufferedContents = ob_get_contents(); ob_end_clean(); if ($bufferedContents !== '') { $content = $bufferedContents . $content; } XenForo_CodeEvent::fire('front_controller_post_view', array($this, &$content)); if ($this->_sendResponse) { $headers = $this->_response->getHeaders(); $isText = false; foreach ($headers as $header) { if ($header['name'] == 'Content-Type') { if (strpos($header['value'], 'text/') === 0) { $isText = true; } break; } } if ($isText && is_string($content) && $content) { $extraHeaders = XenForo_Application::gzipContentIfSupported($content); foreach ($extraHeaders as $extraHeader) { $this->_response->setHeader($extraHeader[0], $extraHeader[1], $extraHeader[2]); } } if (is_string($content) && $content && !ob_get_level() && XenForo_Application::get('config')->enableContentLength) { $this->_response->setHeader('Content-Length', strlen($content), true); } $this->_response->sendHeaders(); if ($content instanceof XenForo_FileOutput) { $content->output(); } else { //$uncompressed = gzuncompress($content); //echo $uncompressed; echo $content; } } else { return $content; } }
/** * Gets the effective set of container params. This includes combining * and specific container params with any global ones. For example, a specific * container param may refer to the section the page is in, so this function * could load the other options that are specific to this section. * * @param array $params Container params from the controller/view * @param Zend_Controller_Request_Http $request * * @return array */ public function getEffectiveContainerParams(array $params, Zend_Controller_Request_Http $request) { $visitor = XenForo_Visitor::getInstance(); if (!$visitor['is_admin'] && !isset($params['containerTemplate'])) { $params['containerTemplate'] = 'LOGIN_PAGE'; } $options = XenForo_Application::get('options'); $params['homeLink'] = $options->homePageUrl ? $options->homePageUrl : XenForo_Link::buildPublicLink('index'); $params['jQuerySource'] = self::getJquerySource(); $params = XenForo_Application::mapMerge($params, parent::getEffectiveContainerParams($params, $request), $this->_getCronContainerParams(), $this->_getNavigationContainerParams(empty($params['majorSection']) ? '' : $params['majorSection'])); XenForo_CodeEvent::fire('container_admin_params', array(&$params, $this)); return $params; }
/** * Determines if the given page matches the criteria. The provided page data takes the form of * $params and $containerData from XenForo_ViewRenderer_HtmlPublic::_getNoticesContainerParams(). * * @param array|string $criteria List of criteria, format: [] with keys rule and data; may be serialized * @param boolean $matchOnEmpty If true and there's no criteria, true is returned; otherwise, false * @param array $params * @param array $containerData * * @return boolean */ public static function pageMatchesCriteria($criteria, $matchOnEmpty = false, array $params, array $containerData) { if (!($criteria = self::unserializeCriteria($criteria))) { return (bool) $matchOnEmpty; } foreach ($criteria as $criterion) { $data = $criterion['data']; switch ($criterion['rule']) { // browsing within one of the specified nodes case 'nodes': if (!isset($containerData['navigation']) || !is_array($containerData['navigation'])) { return false; } if (empty($data['node_ids'])) { return false; // no node ids specified } if (empty($data['node_only'])) { foreach ($containerData['navigation'] as $i => $navItem) { if (isset($navItem['node_id']) && in_array($navItem['node_id'], $data['node_ids'])) { break 2; // break out of case 'nodes'... } } } if (isset($containerData['quickNavSelected'])) { $quickNavSelected = $containerData['quickNavSelected']; } else { $quickNavSelected = false; foreach ($containerData['navigation'] as $i => $navItem) { if (isset($navItem['node_id'])) { $quickNavSelected = 'node-' . $navItem['node_id']; } } } if ($quickNavSelected && in_array(preg_replace('/^.+-(\\d+)$/', '$1', $quickNavSelected), $data['node_ids'])) { break 1; } return false; break; // browsing within the specified controller (and action) // browsing within the specified controller (and action) case 'controller': if (!isset($params['controllerName']) || strtolower($params['controllerName']) != strtolower($data['name'])) { return false; } if (!empty($data['action']) && isset($params['controllerAction'])) { if (strtolower($params['controllerAction']) != strtolower($data['action'])) { return false; } } break; // browsing within the specified view // browsing within the specified view case 'view': if (!isset($params['viewName']) || strtolower($params['viewName']) != strtolower($data['name'])) { return false; } break; // viewing the specified content template // viewing the specified content template case 'template': if (!isset($params['contentTemplate']) || strtolower($params['contentTemplate']) != strtolower($data['name'])) { return false; } break; // browsing within the specified tab // browsing within the specified tab case 'tab': if (!isset($params['selectedTabId']) || strtolower($params['selectedTabId']) != strtolower($data['id'])) { return false; } break; // unknown criteria, assume failed unless something from a code event takes it // unknown criteria, assume failed unless something from a code event takes it default: $eventReturnValue = false; XenForo_CodeEvent::fire('criteria_page', array($criterion['rule'], $data, $params, $containerData, &$eventReturnValue)); if ($eventReturnValue === false) { return false; } } } return true; }