/** * Ensures the application routes and actions are loaded. * * @todo vBulletin is not a registered product so if any future apps use it then * we should either register vBulletin or make the app query less strict. * @todo Check if we can use a collection here for routes if it isn't too early * in the application stack. It shouldn't be as routing is now optional. */ protected static function assertRoutes() { // Check if we've already loaded the route info if (sizeof(self::$routes)) { return true; } // Check datastore if (!sizeof($routecache = vB::$vbulletin->routes)) { if (vB::$vbulletin->datastore->fetch(array('routes'))) { $routecache = vB::$vbulletin->routes; } } if (sizeof($routecache)) { self::$routes = $routecache['routes']; self::$actions = $routecache['actions']; self::$route_actions = $routecache['route_actions']; return true; } // Add framework level routes self::$routes['vB_Route_Error'] = 'error'; self::$routes['vB_Route_HttpError'] = 'httperror'; // Get routes and action from db and cache in datastore $result = vB::$db->query_read("\r\n\t\t\tSELECT\troute.userrequest AS route_segment, route.class AS route_class, route.packageid AS route_package,\r\n\t\t\t\t\taction.packageid AS action_package, action.controller, action.useraction AS action_segment,\r\n\t\t\t\t\taction.classaction AS controller_action\r\n\t\t\tFROM " . TABLE_PREFIX . "route AS route\r\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "action AS action\r\n\t\t\t\tON action.routeid = route.routeid\r\n\t\t"); while ($route = vB::$db->fetch_array($result)) { // cache route if (vB_Types::instance()->packageEnabled($route['route_package'])) { $route_class = vB_Types::instance()->getPackageClass($route['route_package']) . '_Route_' . $route['route_class']; self::$routes[$route_class] = $route['route_segment']; } else { continue; } // cache action if ($route['action_segment']) { if (vB_Types::instance()->packageEnabled($route['action_package'])) { $controller = vB_Types::instance()->getPackageClass($route['action_package']) . '_Controller_' . $route['controller']; // add to actions if (!isset(self::$actions[$controller])) { self::$actions[$controller] = array(); } self::$actions[$controller][$route['controller_action']] = $route['action_segment']; // add to per route actions if (!isset(self::$route_actions[$route_class])) { self::$route_actions[$route_class] = array(); } self::$route_actions[$route_class][$route['action_segment']] = array('controller' => $controller, 'action' => $route['controller_action']); } } } // Cache results $routecache = array('routes' => self::$routes, 'actions' => self::$actions, 'route_actions' => self::$route_actions); build_datastore('routes', serialize($routecache), 1); }