/** * Returns the instance of the dispatcher * * @return frontDispatcher the instance */ public static function getInstance() { if (!self::$_instance instanceof self) { self::$_instance = new self(); } return self::$_instance; }
/** * Authentication * * @param frontDispatcher $front * @param string $authUrl the Auth URL * @param string $from, if set to 'ajax', it will return a json with error = false instead of * routing. * @return boolean */ public function authenticate(frontDispatcher $front, $authUrl, $from) { $actions = $this->getActions(); $controller = explode('Controller', $front->getController()); $controller = $controller[0]; $action = $front->getAction(); if (!isset($actions[$controller]) || isset($actions[$controller]) && isset($actions[$controller][$action]) && '1' === $actions[$controller][$action]) { // add this for preserved areas if (false === AuthManager::check()) { if ('ajax' == $from) { header('content-type: application/json'); $params = array('error' => 'true', 'url' => $authUrl); echo json_encode($params); } else { header("location: {$authUrl}"); } exit; } } }
/** * Computes the pagination * */ public function computePagination() { $dispatcher = frontDispatcher::getInstance(); $controllerName = substr($dispatcher->getController(), 0, -10); if (!empty($this->itemsPerPage)) { $this->pagination = new stdClass(); $this->pagination->links = array(); $this->pagination->pages = ceil($this->totalCount / $this->itemsPerPage); $offset = 0; for ($i = 0; $i < $this->pagination->pages; $i++) { $page = new stdClass(); $page->title = $i + 1; $page->offset = $offset; $page->link = "/?controller={$controllerName}&action=list&offset={$offset}"; // render previous link if ($offset - $this->itemsPerPage >= 0) { $previous = $offset - $this->itemsPerPage; $page->previous = "/?controller={$controllerName}&action=list&offset={$previous}"; } // render next link if ($offset + $this->itemsPerPage < $this->pagination->pages * $this->itemsPerPage) { $next = $offset + $this->itemsPerPage; $page->next = "/?controller={$controllerName}&action=list&offset={$next}"; } $this->pagination->links[$offset] = $page; $offset += $this->itemsPerPage; } } }
{ throw new ErrorException($errstr, 0, $errno, $errfile, $errline); } //set_error_handler("exception_error_handler"); require_once dirname(__FILE__) . '/../conf/configuration_front.php'; require_once dirname(__FILE__) . '/../core/autoloadManager.php'; autoloadManager::setSaveFile(dirname(__FILE__) . '/../tmp/front.php'); autoloadManager::addFolder(CORE); autoloadManager::addFolder(BUSINESS); spl_autoload_register('autoloadManager::loadClass'); $_REQUEST['controller'] = Toolbox::getArrayParameter($_REQUEST, 'controller', 'Feed'); $_REQUEST['action'] = Toolbox::getArrayParameter($_REQUEST, 'action', 'index'); // jquery based ajax application $from = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && 'XMLHttpRequest' === $_SERVER['HTTP_X_REQUESTED_WITH'] ? 'ajax' : 'http'; try { $front = frontDispatcher::getInstance(); // Init Session // Save header for ajax call, so that we can either root or return false for ajax calls $actions = AccessHelper::getActions(); // authenticate $AuthManager = new AuthManager($actions); $AuthManager->authenticate($front, '/?controller=Feed&action=index', $from); // Inject Dynamically changing objects $Container = ContainerFactory::get('front'); $Container['Access'] = $actions; $Container['AuthManager'] = $AuthManager; $Container['Request'] = $_REQUEST; $Container['Session'] = SessionManager::getSession('front'); // Route $front->route($Container); } catch (Exception $e) {