Example #1
0
 /**
  * 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));
 }
Example #2
0
 public function __construct()
 {
     $renderers = array();
     $this->_registerDefaultRenderers($renderers);
     XenForo_CodeEvent::fire('widget_framework_ready', array(&$renderers));
     foreach ($renderers as $renderer) {
         $this->_renderers[] = $renderer;
     }
 }
Example #3
0
 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);
 }
Example #4
0
 /**
  * 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}): ");
             }
         }
     }
 }
Example #5
0
 /**
  * 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);
 }
Example #6
0
 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);
     }
 }
Example #7
0
 /**
  * This function is called immediately before an action is dispatched.
  *
  * @param string Action that is requested
  */
 public final function preDispatch($action)
 {
     $this->_preDispatchFirst($action);
     $this->_setupSession($action);
     $this->_checkCsrf($action);
     $this->_handlePost($action);
     $this->_preDispatchType($action);
     $this->_preDispatch($action);
     XenForo_CodeEvent::fire('controller_pre_dispatch', array($this, $action));
 }
Example #8
0
 /**
  * Pre-loads globally required data for the system.
  */
 public function preLoadData()
 {
     $required = array_merge(array('options', 'languages', 'contentTypes', 'codeEventListeners', 'cron', 'simpleCache'), $this->_dataPreLoadFromRegistry);
     $data = XenForo_Model::create('XenForo_Model_DataRegistry')->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['contentTypes'])) {
         $data['contentTypes'] = XenForo_Model::create('XenForo_Model_ContentType')->rebuildContentTypeCache();
     }
     XenForo_Application::set('contentTypes', $data['contentTypes']);
     if (!is_int($data['cron'])) {
         $data['cron'] = XenForo_Model::create('XenForo_Model_Cron')->updateMinimumNextRunTime();
     }
     XenForo_Application::set('cron', $data['cron']);
     if (!is_array($data['simpleCache'])) {
         $data['simpleCache'] = array();
         XenForo_Model::create('XenForo_Model_DataRegistry')->set('simpleCache', $data['simpleCache']);
     }
     XenForo_Application::set('simpleCache', $data['simpleCache']);
     $this->_handleCustomPreloadedData($data);
     XenForo_CodeEvent::fire('init_dependencies', array($this, $data));
 }
Example #9
0
 /**
  * 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;
 }
Example #10
0
 /**
  * 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;
 }
Example #11
0
 /**
  * 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));
 }
Example #12
0
 /**
  * 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');
     $object = new self();
     if ($userId && ($user = $userModel->getVisitingUserById($userId))) {
         if ($user['is_admin'] && $options['permissionUserId']) {
             // force permissions for testing
             $user = $userModel->setPermissionsFromUserId($user, $options['permissionUserId']);
         }
         $object->_user = $user;
     } else {
         $object->_user = $userModel->getVisitingGuestUser();
         if ($options['languageId']) {
             $object->_user['language_id'] = $options['languageId'];
         }
     }
     $object->_user['referer'] = !empty($options['referer']) ? $options['referer'] : null;
     $object->_user['from_search'] = !empty($options['fromSearch']);
     $object->_user['is_robot'] = !empty($options['isRobot']);
     $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;
     XenForo_CodeEvent::fire('visitor_setup', array(&self::$_instance));
     return self::$_instance;
 }
Example #13
0
 public function preLoadTemplates(XenForo_View $view)
 {
     //Preload Bbm Templates
     $bbmListenerTemplateCache = array();
     XenForo_CodeEvent::fire('bbm_callback_template_cache', array(&$bbmListenerTemplateCache));
     if (!empty($bbmListenerTemplateCache) && is_array($bbmListenerTemplateCache) && is_array($this->_preloadBbmTemplates)) {
         $this->_preloadBbmTemplates = array_unique(array_merge($this->_preloadBbmTemplates, $bbmListenerTemplateCache));
     }
     if ($this->_view && is_array($this->_preloadBbmTemplates)) {
         foreach ($this->_preloadBbmTemplates as $templateName) {
             $this->_view->preLoadTemplate($templateName);
         }
     }
     $this->_view->preLoadTemplate('bbm_viewer_content_protected');
     return parent::preLoadTemplates($view);
 }
Example #14
0
 /**
  * Renders the captcha option.
  *
  * @param XenForo_View $view View object
  * @param string $fieldPrefix Prefix for the HTML form field name
  * @param array $preparedOption Prepared option info
  * @param boolean $canEdit True if an "edit" link should appear
  *
  * @return XenForo_Template_Abstract Template object
  */
 public static function renderOption(XenForo_View $view, $fieldPrefix, array $preparedOption, $canEdit)
 {
     $preparedOption['extraChoices'] = array();
     XenForo_CodeEvent::fire('option_captcha_render', array(&$preparedOption['extraChoices'], $view, $preparedOption));
     return XenForo_ViewAdmin_Helper_Option::renderOptionTemplateInternal('option_template_captcha', $view, $fieldPrefix, $preparedOption, $canEdit);
 }
Example #15
0
 public function prepareField(array $field)
 {
     XenForo_CodeEvent::fire('prepare_user_change_log_field', array($this, &$field));
     $field = $this->_getHelper()->prepareField($field);
     return array('field' => $field['field'], 'name' => $field['name'], 'old_value' => $field['old_value'], 'new_value' => $field['new_value']);
 }
Example #16
0
 /**
  * Calls the specified template hook event.
  *
  * Params passed by template explicitly will respect mappings and greater context.
  * Raw params are still available via the template object.
  *
  * @param string $name Name of the hook
  * @param string $contents Contents of the hook; may be empty
  * @param array $params List of params to pass specifically; these will respect mappings.
  *
  * @return string New version of the contents (could be modified)
  */
 public function callTemplateHook($name, $contents, array $params)
 {
     XenForo_CodeEvent::fire('template_hook', array($name, &$contents, $params, $this), $name);
     return $contents;
 }
Example #17
0
 /**
  * Fetches all notices applicable to the visiting user
  *
  * @param XenForo_Template_Abstract $template
  * @param array $containerData
  *
  * @return array
  */
 protected function _getNoticesContainerParams(XenForo_Template_Abstract $template, array $containerData)
 {
     $notices = array();
     foreach ($this->_dependencies->notices as $param => $noticeKey) {
         if ($template->getParam($param)) {
             $notices[$noticeKey] = array('title' => new XenForo_Phrase($noticeKey), 'message' => $template->create($noticeKey, $template->getParams()), 'wrap' => true, 'dismissible' => false);
         }
     }
     if (XenForo_Application::get('options')->enableNotices) {
         if (XenForo_Application::isRegistered('notices')) {
             $user = XenForo_Visitor::getInstance()->toArray();
             if (XenForo_Application::isRegistered('session')) {
                 $dismissedNotices = XenForo_Application::getSession()->get('dismissedNotices');
             }
             if (!isset($dismissedNotices) || !is_array($dismissedNotices)) {
                 $dismissedNotices = array();
             }
             // handle style overrides
             $visitorStyle = $template->getParam('visitorStyle');
             if (!empty($visitorStyle)) {
                 $user['style_id'] = $visitorStyle['style_id'];
             }
             $noticeList = XenForo_Application::get('notices');
             foreach (XenForo_Application::get('notices') as $noticeId => $notice) {
                 if (!empty($notice['dismissible']) && in_array($noticeId, $dismissedNotices) || !XenForo_Helper_Criteria::userMatchesCriteria($notice['user_criteria'], true, $user) || !XenForo_Helper_Criteria::pageMatchesCriteria($notice['page_criteria'], true, $template->getParams(), $containerData)) {
                     unset($noticeList[$noticeId]);
                 }
             }
             $noticeTokens = array('{name}' => $user['username'] !== '' ? $user['username'] : new XenForo_Phrase('guest'), '{user_id}' => $user['user_id']);
             XenForo_CodeEvent::fire('notices_prepare', array(&$noticeList, &$noticeTokens, $template, $containerData));
             foreach ($noticeList as $noticeId => $notice) {
                 $notices[$noticeId] = array('title' => $notice['title'], 'message' => str_replace(array_keys($noticeTokens), $noticeTokens, $notice['message']), 'wrap' => $notice['wrap'], 'dismissible' => $notice['dismissible'] && XenForo_Visitor::getUserId());
             }
         }
     }
     return $notices;
 }
Example #18
0
 protected function _postTemplateChange($file, $action)
 {
     XenForo_CodeEvent::fire('template_file_change', array($file, $action), $file);
 }
 /**
  * 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;
 }
Example #20
0
 public function actionFileCheck()
 {
     if ($this->_request->isPost()) {
         $hashes = XenForo_Install_Data_FileSums::getHashes();
         XenForo_CodeEvent::fire('file_health_check', array($this, &$hashes));
         $errors = XenForo_Helper_Hash::compareHashes($hashes);
         $viewParams = array('errors' => $errors, 'hashes' => $hashes);
     } else {
         $viewParams = array('form' => true);
     }
     return $this->responseView('XenForo_ViewAdmin_Tools_FileCheck', 'tools_file_check', $viewParams);
 }
Example #21
0
 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;
     // 		}
 }
Example #22
0
 /**
  * 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;
 }
Example #23
0
 /**
  * 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));
 }
 /**
  * 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;
     }
 }
Example #25
0
 /**
  * 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;
 }
Example #26
0
 protected function _getNavigationContainerParams($selectedTabId)
 {
     $tabs = array('forums' => array('title' => new XenForo_Phrase('forums'), 'href' => XenForo_Link::buildPublicLink('full:forums')), 'members' => array('title' => new XenForo_Phrase('members'), 'href' => XenForo_Link::buildPublicLink('full:members')), 'help' => array('title' => new XenForo_Phrase('help'), 'href' => XenForo_Link::buildPublicLink('full:help')));
     if (XenForo_Visitor::getUserId()) {
         $tabs['account'] = array('title' => new XenForo_Phrase('your_account'), 'href' => XenForo_Link::buildPublicLink('full:account'));
         $tabs['inbox'] = array('title' => new XenForo_Phrase('conversations'), 'href' => XenForo_Link::buildPublicLink('full:conversations'));
     }
     if (!XenForo_Model::create('XenForo_Model_User')->canViewMemberList()) {
         unset($tabs['members']);
     }
     $extraTabs = array();
     XenForo_CodeEvent::fire('navigation_tabs', array(&$extraTabs, $selectedTabId));
     if (!empty($extraTabs[$selectedTabId])) {
         $selectedTab = $extraTabs[$selectedTabId];
         $extraTabs[$selectedTabId]['selected'] = true;
     } else {
         if (!empty($tabs[$selectedTabId])) {
             $selectedTab = $tabs[$selectedTabId];
             $tabs[$selectedTabId]['selected'] = true;
         } else {
             $selectedTabId = '';
             $selectedTab = false;
         }
     }
     $extraTabsGrouped = array();
     foreach ($extraTabs as $extraTabId => $extraTab) {
         if (empty($extraTab['position'])) {
             $extraTab['position'] = 'middle';
         }
         $extraTabsGrouped[$extraTab['position']][$extraTabId] = $extraTab;
     }
     if (!empty($extraTabsGrouped['home'])) {
         list($homeTabId, $homeTab) = each($extraTabsGrouped['home']);
     } else {
         $homeTabId = false;
         $homeTab = false;
     }
     $options = XenForo_Application::get('options');
     $showHomeLink = false;
     if ($options->homePageUrl) {
         $showHomeLink = true;
         $homeLink = $options->homePageUrl;
         $logoLink = $options->logoLink ? $homeLink : XenForo_Link::buildPublicLink('full:index');
     } else {
         if ($homeTab) {
             $homeLink = $homeTab['href'];
             $logoLink = $options->logoLink ? $homeTab['href'] : XenForo_Link::buildPublicLink('full:index');
         } else {
             $indexUrl = XenForo_Link::buildPublicLink('full:index');
             foreach ($tabs as $tabKey => $tab) {
                 if (!empty($tab['href']) && $tab['href'] == $indexUrl) {
                     $homeTabId = $tabKey;
                     $homeTab = $tab;
                     $homeLink = $homeTab['href'];
                     $logoLink = $homeLink;
                     break;
                 }
             }
             if (!$homeTab && $extraTabsGrouped) {
                 foreach ($extraTabsGrouped as $extraTabs) {
                     foreach ($extraTabs as $tabKey => $tab) {
                         if (!empty($tab['href']) && $tab['href'] == $indexUrl) {
                             $homeTabId = $tabKey;
                             $homeTab = $tab;
                             $homeLink = $homeTab['href'];
                             $logoLink = $homeLink;
                             break 2;
                         }
                     }
                 }
             }
             if (!$homeTab) {
                 $homeTabId = 'forums';
                 $homeTab = $tabs['forums'];
                 $homeLink = $homeTab['href'];
                 $logoLink = $indexUrl;
             }
         }
     }
     return array('tabs' => $tabs, 'extraTabs' => $extraTabsGrouped, 'selectedTab' => $selectedTab, 'selectedTabId' => $selectedTabId, 'homeTab' => $homeTab, 'homeTabId' => $homeTabId, 'showHomeLink' => $showHomeLink, 'homeLink' => $homeLink, 'logoLink' => $logoLink);
 }
Example #27
0
 /**
  * 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();
 }
 /**
  * Fetches all notices applicable to the visiting user
  *
  * @param XenForo_Template_Abstract $template
  * @param array $containerData
  *
  * @return array
  */
 protected function _getNoticesContainerParams(XenForo_Template_Abstract $template, array $containerData)
 {
     $notices = array();
     foreach ($this->_dependencies->notices as $param => $noticeKey) {
         if ($template->getParam($param)) {
             $notices['block'][$noticeKey] = array('title' => new XenForo_Phrase($noticeKey), 'message' => $template->create($noticeKey, $template->getParams()), 'wrap' => true, 'dismissible' => false);
         }
     }
     if (XenForo_Application::get('options')->enableNotices) {
         if (XenForo_Application::isRegistered('notices')) {
             $user = XenForo_Visitor::getInstance()->toArray();
             if (XenForo_Application::isRegistered('session')) {
                 $dismissedNotices = XenForo_Application::getSession()->get('dismissedNotices');
             }
             if (!isset($dismissedNotices) || !is_array($dismissedNotices)) {
                 $dismissedNotices = array();
             }
             // handle style overrides
             $visitorStyle = $template->getParam('visitorStyle');
             if (!empty($visitorStyle)) {
                 $user['style_id'] = $visitorStyle['style_id'];
             }
             $noticeList = XenForo_Application::get('notices');
             foreach (XenForo_Application::get('notices') as $noticeId => $notice) {
                 if (!empty($notice['dismissible']) && in_array($noticeId, $dismissedNotices) || !XenForo_Helper_Criteria::userMatchesCriteria($notice['user_criteria'], true, $user) || !XenForo_Helper_Criteria::pageMatchesCriteria($notice['page_criteria'], true, $template->getParams(), $containerData)) {
                     unset($noticeList[$noticeId]);
                 }
             }
             $noticeTokens = array('{name}' => $user['username'] !== '' ? htmlspecialchars($user['username']) : new XenForo_Phrase('guest'), '{user_id}' => $user['user_id']);
             XenForo_CodeEvent::fire('notices_prepare', array(&$noticeList, &$noticeTokens, $template, $containerData));
             foreach ($noticeList as $noticeId => $notice) {
                 $noticeTokens['{title}'] = $notice['title'];
                 $imageUrl = '';
                 if ($notice['display_image'] == 'avatar') {
                     $imageUrl = XenForo_Template_Helper_Core::callHelper('avatar', array($user, 's'));
                 } else {
                     if ($notice['display_image'] == 'image') {
                         $imageUrl = $notice['image_url'];
                     }
                 }
                 $notices[$notice['notice_type']][$noticeId] = array('title' => $notice['title'], 'message' => str_replace(array_keys($noticeTokens), $noticeTokens, $notice['message']), 'wrap' => $notice['wrap'], 'dismissible' => $notice['dismissible'], 'delay_duration' => $notice['delay_duration'], 'display_duration' => $notice['display_duration'], 'auto_dismiss' => $notice['auto_dismiss'], 'display_image' => $notice['display_image'], 'display_style' => $notice['display_style'], 'css_class' => $notice['css_class'], 'visibility' => $notice['visibility'], 'imageUrl' => $imageUrl);
             }
         }
     }
     return $notices;
 }
Example #29
0
 /**
  * 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;
 }
Example #30
0
 /**
  * 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;
     }
 }