/** * Get the session user or load the user bu the id passed the request query * * @return type */ public function getUser() { if ($this->_user) { return $this->_user; } if (App_Main::getRequest()->getParam('user') && App_Main::hasSingleton('stages/user')) { $user = App_Main::getSingleton('stages/user'); } else { if (App_Main::hasSingleton('stages/user')) { $user = App_Main::getSingleton('stages/user'); } } if (!empty($user)) { $this->_user = $user; return $this->_user; } //else load the user with the fbid or from the session if ($userId = App_Main::getRequest()->getParam('user')) { $user = App_Main::getSession()->getUser()->getId() == $userId ? App_Main::getSession()->getUser() : App_Main::getSingleton('stages/user')->load($userId); } else { if (App_Main::getSession()->getUser()) { $user = App_Main::getSession()->getUser(); } } if ($user->getId()) { $this->_user = $user; return $this->_user; } return false; }
/** * Generic method to get the page url for a paginated list * * @return string */ public function getPageUrl($p) { $request = App_Main::getRequest(); $params = $request->getQuery(); $params['page'] = $p; return $this->getUrl('*/*/*', array('_use_rewrite' => true, '_query' => $params)); }
/** * Get request object * * @return Zend_Controller_Request_Http */ protected function _getRequest() { if (!$this->_request) { $this->_request = App_Main::getRequest(); } return $this->_request; }
/** * Get the request object * * @return Core_Controller_Request_Http */ protected function _getRequest() { if (!empty($this->_request)) { return $this->_request; } $this->_request = App_Main::getRequest(); return $this->_request; }
/** * Logic of custom rewrites * * @param Zend_Controller_Request_Http $request * @param Zend_Controller_Response_Http $response * @return Core_Model_Url */ public function rewrite(Zend_Controller_Request_Http $request = null, Zend_Controller_Response_Http $response = null) { if (is_null($request)) { $request = App_Main::getRequest(); } if (is_null($response)) { $response = App_Main::getResponse(); } $requestCases = array(); $requestPath = trim($request->getPathInfo(), '/'); /** * We need try to find rewrites information for both cases * More priority has url with query params */ if ($queryString = $this->_getQueryString()) { $requestCases[] = $requestPath . '?' . $queryString; $requestCases[] = $requestPath; } else { $requestCases[] = $requestPath; } $this->loadByRequestPath($requestCases); /** * Try to find rewrite by request path at first, if no luck - try to find by id_path */ if (!$this->getId()) { return false; } $request->setAlias(self::REWRITE_REQUEST_PATH_ALIAS, $this->getRequestPath()); $external = substr($this->getTargetPath(), 0, 6); $isPermanentRedirectOption = $this->hasOption('RP'); if ($external === 'http:/' || $external === 'https:') { if ($isPermanentRedirectOption) { header('HTTP/1.1 301 Moved Permanently'); } header("Location: " . $this->getTargetPath()); exit; } else { $targetUrl = $request->getBaseUrl() . '/' . $this->getTargetPath(); } $isRedirectOption = $this->hasOption('R'); if ($isRedirectOption || $isPermanentRedirectOption) { $targetUrl = $request->getBaseUrl() . '/' . $this->getTargetPath(); if ($isPermanentRedirectOption) { header('HTTP/1.1 301 Moved Permanently'); } header('Location: ' . $targetUrl); exit; } $targetUrl = $request->getBaseUrl() . '/' . $this->getTargetPath(); if ($queryString = $this->_getQueryString()) { $targetUrl .= '?' . $queryString; } $request->setRequestUri($targetUrl); $request->setPathInfo($this->getTargetPath()); return true; }
/** * Retrive the body element css class * @return string body element class */ public function getBodyClass() { if (!$this->_getData('body_class')) { $action = App_Main::getRequest()->getActionName(); $controller = App_Main::getRequest()->getControllerName(); if ($action && $controller) { $this->addBodyClass($controller . '_' . $action); } } return $this->_getData('body_class'); }
/** * Load the website based on the http host, If the host is not found, the default website is loaded * * @return Core_Model_Website */ public function loadFromRequestUrl() { $request = App_Main::getRequest(); $httpHost = $request->getHttpHost(); if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { $websiteId = App_Main::getConfig()->getScopeFromPathValue('website', 'web-secure-base-url', 'https://' . $httpHost); } else { $websiteId = App_Main::getConfig()->getScopeFromPathValue('website', 'web-unsecure-base-url', 'http://' . $httpHost); } if (!empty($websiteId)) { return $this->load($websiteId); } else { return $this->loadDefaultWebsite(); } }
/** * Check for the module existance in the current added routes. * If not a page not found result will load the login page instead * * @return array|bool * */ private function validateRoute() { $request = App_Main::getRequest(); $p = explode('/', trim($request->getPathInfo(), '/')); if ($request->getModuleName()) { $module = $request->getModuleName(); } else { if (!empty($p[0])) { $module = $p[0]; } else { $module = $this->getFront()->getDefault('module'); $request->setAlias('rewrite_request_path', ''); } } return $this->getModuleByFrontName($module); }
/** * Get the action object for the served request * @return Core_Controller_Action */ public function getAction() { return App_Main::getRequest()->getAction(); }
/** * Zend request object * * @return Zend_Controller_Request_Http */ public function getRequest() { if (!$this->_request) { $this->_request = App_Main::getRequest(); } return $this->_request; }
/** * Get the global request object * * @return Core_Controller_Request_Http */ protected function _getRequest() { return App_Main::getRequest(); }