public function onBeforeHTTPError($statusCode, $request)
 {
     $response = ErrorPage::response_for($statusCode);
     if ($response) {
         throw new SS_HTTPResponse_Exception($response, $statusCode);
     }
 }
예제 #2
0
 public function httpError($code, $message = null)
 {
     if (!Permission::check("ADMIN")) {
         $response = ErrorPage::response_for($code);
     }
     if (empty($response)) {
         $response = $message;
     }
     throw new SS_HTTPResponse_Exception($response);
 }
 /**
  * Process IPN request from ClickBank. Only process POST request
  * 
  * @param	object	$_POST
  * @return	int		HTTP code 
  */
 public function ipn(SS_HTTPRequest $request)
 {
     if ($request->isPost()) {
         if (ClickBankManager::validate_ipn_request($request->postVars())) {
             ClickBankManager::process_ipn_request($request->postVars());
             return Director::get_status_code();
         }
     }
     return ErrorPage::response_for(404);
 }
 function onBeforeInit()
 {
     if (Config::inst()->get('IpAccess', 'enabled')) {
         $ipAccess = new IpAccess($this->owner->getRequest()->getIP(), Config::inst()->get('IpAccess', 'allowed_ips'));
         if (!$ipAccess->hasAccess()) {
             if (class_exists('ErrorPage', true)) {
                 $response = ErrorPage::response_for(403);
             }
             $response = $response ? $response : 'The requested page could not be found.';
             return $this->owner->httpError(403, $response);
         }
     }
 }
 public function init()
 {
     parent::init();
     if (Config::inst()->get('IpAccess', 'enabled')) {
         $ipAccess = new IpAccess($this->owner->getRequest()->getIP(), Config::inst()->get('IpAccess', 'allowed_ips'));
         if (!$ipAccess->hasAccess()) {
             $reponse = '';
             if (class_exists('ErrorPage', true)) {
                 $response = ErrorPage::response_for(404);
             }
             return $this->owner->httpError(404, $response ? $response : 'The requested page could not be found.');
         }
     }
     // this prevents loading frontend css and javscript files
     Requirements::clear();
     Requirements::css('adminlogin/css/style.css');
 }
 /**
  * Tries to find the lightbox based on the id given.
  *
  * @param $request
  * @return HTMLText
  * @throws SS_HTTPResponse_Exception
  */
 public function renderBox($request)
 {
     $url = $request->param('URLSegment');
     $id = (int) preg_replace('/lightbox\\-/', '', $url);
     $lightbox = DataObject::get_by_id('Lightbox', $id);
     if ($lightbox) {
         $callback = $request->getVar('callback');
         $content = $lightbox->renderWith(get_class($lightbox));
         if ($callback) {
             $jsonContent = array('content' => $content->getValue());
             return "{$callback}(" . json_encode($jsonContent) . ");";
         } else {
             return $content;
         }
     }
     $this->httpError(404, ErrorPage::response_for(404));
 }
 /**
  * Displays a list of all members on the site that belong to the selected
  * groups.
  *
  * @return string
  */
 public function handleList($request)
 {
     if (!$this->parent->AllowProfileViewing) {
         return ErrorPage::response_for(404);
     }
     $sort = $request->getVar('sort');
     if ($sort && singleton('Member')->hasDatabaseField($sort)) {
         $sort = sprintf('"%s"', Convert::raw2sql($sort));
     } else {
         $sort = '"ID"';
     }
     $groups = $this->parent->Groups();
     $fields = $this->parent->Fields('"MemberListVisible" = 1');
     // List all members that are in at least one of the groups on the
     // parent page.
     if (count($groups)) {
         $groups = implode(',', array_keys($groups->map()));
         $filter = "\"Group_Members\".\"GroupID\" IN ({$groups})";
         $join = 'LEFT JOIN "Group_Members" ' . 'ON "Member"."ID" = "Group_Members"."MemberID"';
     } else {
         $filter = $join = null;
     }
     $members = DataObject::get('Member', $filter, $sort, $join, array('start' => $this->getPaginationStart(), 'limit' => 25));
     if ($members && $fields) {
         foreach ($members as $member) {
             $data = new DataObjectSet();
             $public = $member->getPublicFields();
             foreach ($fields as $field) {
                 if ($field->PublicVisibility == 'MemberChoice' && !in_array($field->MemberField, $public)) {
                     $value = null;
                 } else {
                     $value = $member->{$field->MemberField};
                 }
                 $data->push(new ArrayData(array('MemberID' => $member->ID, 'Name' => $field->MemberField, 'Title' => $field->Title, 'Value' => $value, 'Sortable' => $member->hasDatabaseField($field->MemberField))));
             }
             $member->setField('Fields', $data);
         }
     }
     $this->data()->Title = _t('MemberProfiles.MEMBERLIST', 'Member List');
     $this->data()->Parent = $this->parent;
     $controller = $this->customise(array('Members' => $members));
     return $controller->renderWith(array('MemberProfileViewer_list', 'MemberProfileViewer', 'Page'));
 }
 public function init()
 {
     parent::init();
     if (Config::inst()->get('IpAccess', 'enabled')) {
         $ipAccess = new IpAccess($this->owner->getRequest()->getIP(), Config::inst()->get('IpAccess', 'allowed_ips'));
         if (!$ipAccess->hasAccess()) {
             $reponse = '';
             if (class_exists('ErrorPage', true)) {
                 $response = ErrorPage::response_for(404);
             }
             return $this->owner->httpError(404, $response ? $response : 'The requested page could not be found.');
         }
     }
     if (Config::inst()->get('AdminLogin', 'UseTheme') !== true) {
         // this prevents loading frontend css and javscript files
         Object::useCustomClass('Page_Controller', 'AdminLoginPage_Controller');
         Requirements::css('adminlogin/css/style.css');
     }
     Object::useCustomClass('MemberLoginForm', 'AdminLoginForm');
 }
 /**
  *	Attempt to redirect towards the highest priority link mapping that may have been defined.
  *
  *	@URLparameter direct <{BYPASS_LINK_MAPPINGS}> boolean
  */
 public function postRequest(SS_HTTPRequest $request, SS_HTTPResponse $response, DataModel $model)
 {
     // Bypass the request filter when requesting specific director rules such as "/admin" or "/dev".
     $requestURL = $request->getURL();
     $configuration = Config::inst();
     foreach ($configuration->get('Director', 'rules') as $segment => $controller) {
         // Retrieve the specific director rules.
         if (($position = strpos($segment, '$')) !== false) {
             $segment = rtrim(substr($segment, 0, $position), '/');
         }
         // Determine if the current request matches a specific director rule.
         if ($segment && strpos($requestURL, $segment) === 0) {
             // Continue processing the response.
             return true;
         }
     }
     // Bypass the request filter when using the direct GET parameter.
     if ($request->getVar('direct')) {
         // Continue processing the response.
         return true;
     }
     // Determine the default automated URL handling response status.
     $status = $response->getStatusCode();
     $success = $status >= 200 && $status < 300;
     $error = $status === 404;
     // Either hook into a page not found, or when enforced, replace the default automated URL handling.
     $enforce = $configuration->get('MisdirectionRequestFilter', 'enforce_misdirection');
     $replace = $configuration->get('MisdirectionRequestFilter', 'replace_default');
     if (($error || $enforce || $replace) && ($map = $this->service->getMappingByRequest($request))) {
         // Update the response code where appropriate.
         $responseCode = $map->ResponseCode;
         if ($responseCode == 0) {
             $responseCode = 303;
         } else {
             if ($responseCode == 301 && $map->ForwardPOSTRequest) {
                 $responseCode = 308;
             } else {
                 if ($responseCode == 303 && $map->ForwardPOSTRequest) {
                     $responseCode = 307;
                 }
             }
         }
         // Update the response using the link mapping redirection.
         $response->redirect($map->getLink(), $responseCode);
     } else {
         if ($error && ($fallback = $this->service->determineFallback($requestURL))) {
             // Update the response code where appropriate.
             $responseCode = $fallback['code'];
             if ($responseCode === 0) {
                 $responseCode = 303;
             }
             // Update the response using the fallback, enforcing no further redirection.
             $response->redirect(HTTP::setGetVar('direct', true, Controller::join_links(Director::absoluteBaseURL(), $fallback['link'])), $responseCode);
         } else {
             if (!$error && !$success && $replace) {
                 $response->setStatusCode(404);
                 // Retrieve the appropriate page not found response.
                 ClassInfo::exists('SiteTree') && ($page = ErrorPage::response_for(404)) ? $response->setBody($page->getBody()) : $response->setBody('No URL was matched!');
             }
         }
     }
     // Continue processing the response.
     return true;
 }
예제 #10
0
 /**
  * @return ContentController
  */
 public function getNestedController()
 {
     $request = $this->request;
     if (!($URLSegment = $request->param('URLSegment'))) {
         throw new Exception('ModelAsController->getNestedController(): was not passed a URLSegment value.');
     }
     // Find page by link, regardless of current locale settings
     if (class_exists('Translatable')) {
         Translatable::disable_locale_filter();
     }
     $sitetree = DataObject::get_one('SiteTree', sprintf('"URLSegment" = \'%s\' %s', Convert::raw2sql(rawurlencode($URLSegment)), SiteTree::nested_urls() ? 'AND "ParentID" = 0' : null));
     if (class_exists('Translatable')) {
         Translatable::enable_locale_filter();
     }
     if (!$sitetree) {
         // If a root page has been renamed, redirect to the new location.
         // See ContentController->handleRequest() for similiar logic.
         $redirect = self::find_old_page($URLSegment);
         if ($redirect) {
             $params = $request->getVars();
             if (isset($params['url'])) {
                 unset($params['url']);
             }
             $this->response = new SS_HTTPResponse();
             $this->response->redirect(Controller::join_links($redirect->Link(Controller::join_links($request->param('Action'), $request->param('ID'), $request->param('OtherID'))), $params ? '?' . http_build_query($params) : null), 301);
             return $this->response;
         }
         if ($response = ErrorPage::response_for(404)) {
             return $response;
         } else {
             $this->httpError(404, 'The requested page could not be found.');
         }
     }
     // Enforce current locale setting to the loaded SiteTree object
     if (class_exists('Translatable') && $sitetree->Locale) {
         Translatable::set_current_locale($sitetree->Locale);
     }
     if (isset($_REQUEST['debug'])) {
         Debug::message("Using record #{$sitetree->ID} of type {$sitetree->class} with link {$sitetree->Link()}");
     }
     return self::controller_for($sitetree, $this->request->param('Action'));
 }
 /**
  * Get information about the current movie to display.
  * Uses the OMDb API indirectly through the {@link MovieInformation->getInfo} function which
  * returns the XML body.
  *
  * Gets the rotten tomato information as well as the IMDb information. Also obtains both the
  * short and long version of the plot (at the expense of another query). In future this could
  * become configurable.
  *
  * @return ArrayData The information about the current pages movie
  */
 public function getInfo()
 {
     // This will get us XML body to play with as well as testing validity
     $body = $this->isValid();
     if ($body === false) {
         throw new SS_HTTPResponse_Exception(ErrorPage::response_for(404), 404);
     }
     $api = new RestfulService('http://www.omdbapi.com/');
     $results = $api->getAttributes($body, 'movie');
     $return = $results[0];
     // Get short plot as well
     $api->setQueryString(array('r' => 'xml', 'type' => 'movie', 't' => $this->Title, 'plot' => 'short', 'v' => 1));
     $results = $api->request();
     $results = $api->getAttributes($results->getBody(), 'movie');
     if ($results && !empty($results)) {
         $results = $results[0];
         $return->setField('shortPlot', $results->getField('plot'));
     }
     return $return;
 }
예제 #12
0
 /**
  * Handle index requests
  */
 public function index()
 {
     if ($cart = $this->Cart()) {
         $this->redirect($cart->CartLink);
         return;
     } elseif ($response = ErrorPage::response_for(404)) {
         return $response;
     }
     return $this->httpError(404, _t("ShoppingCart.NOCARTINITIALISED", "no cart initialised"));
 }
 /**
  * @uses ErrorPage::response_for()
  */
 public function httpError($code, $message = null)
 {
     if ($this->request->isMedia() || !($response = ErrorPage::response_for($code))) {
         parent::httpError($code, $message);
     } else {
         throw new SS_HTTPResponse_Exception($response);
     }
 }
 public function handleRequest(SS_HTTPRequest $request, DataModel $model = null)
 {
     self::$is_at_root = true;
     $this->setDataModel($model);
     $this->pushCurrent();
     $this->init();
     if ($language = $request->param('Language')) {
         if (Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL')) {
             if (Config::inst()->get('MultilingualRootURLController', 'UseDashLocale')) {
                 //Language is missing a dash 404
                 if (strpos($language, '-') === false) {
                     //Locale not found 404
                     if ($response = ErrorPage::response_for(404)) {
                         return $response;
                     } else {
                         $this->httpError(404, 'The requested page could not be found.');
                     }
                     return $this->response;
                 }
                 $locale = explode('-', $language);
                 $locale[1] = strtoupper($locale[1]);
                 //Make sure that the language is all lowercase
                 if ($language == implode('-', $locale)) {
                     //Locale not found 404
                     if ($response = ErrorPage::response_for(404)) {
                         return $response;
                     } else {
                         $this->httpError(404, 'The requested page could not be found.');
                     }
                     return $this->response;
                 }
                 $locale = implode('_', $locale);
             } else {
                 $locale = $language;
             }
         } else {
             if (strpos($request->param('Language'), '_') !== false) {
                 //Locale not found 404
                 if ($response = ErrorPage::response_for(404)) {
                     return $response;
                 } else {
                     $this->httpError(404, 'The requested page could not be found.');
                 }
                 return $this->response;
             } else {
                 $locale = i18n::get_locale_from_lang($language);
             }
         }
         if (in_array($locale, Translatable::get_allowed_locales())) {
             Cookie::set('language', $language);
             Translatable::set_current_locale($locale);
             i18n::set_locale($locale);
             if (!DB::isActive() || !ClassInfo::hasTable('SiteTree')) {
                 $this->response = new SS_HTTPResponse();
                 $this->response->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null));
                 return $this->response;
             }
             $request->setUrl($language . '/' . self::get_homepage_link() . '/');
             $request->match('$Language/$URLSegment//$Action', true);
             $controller = new MultilingualModelAsController();
             $result = $controller->handleRequest($request, $model);
             $this->popCurrent();
             return $result;
         } else {
             //URL Param Locale is not allowed so redirect to default
             $this->redirect(Controller::join_links(Director::baseURL(), Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL') ? Translatable::default_locale() : Translatable::default_lang()) . '/', 301);
             $this->popCurrent();
             return $this->response;
         }
     }
     //No Locale Param so detect browser language and redirect
     if ($locale = self::detect_browser_locale()) {
         if (Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL')) {
             if (Config::inst()->get('MultilingualRootURLController', 'UseDashLocale')) {
                 $language = str_replace('_', '-', strtolower($locale));
             } else {
                 $language = $locale;
             }
         } else {
             $language = i18n::get_lang_from_locale($locale);
         }
         Cookie::set('language', $language);
         $this->redirect(Controller::join_links(Director::baseURL(), $language) . '/', 301);
         $this->popCurrent();
         return $this->response;
     }
     if (Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL')) {
         if (Config::inst()->get('MultilingualRootURLController', 'UseDashLocale')) {
             $language = str_replace('_', '-', strtolower(Translatable::default_locale()));
         } else {
             $language = Translatable::default_locale();
         }
     } else {
         $language = Translatable::default_lang();
     }
     $this->redirect(Controller::join_links(Director::baseURL(), $language . '/'), 301);
     $this->popCurrent();
     return $this->response;
 }
 /**
  * Test fallback to file generation API with enable_static_file disabled
  */
 public function testGeneratedFile()
 {
     Config::inst()->update('ErrorPage', 'enable_static_file', false);
     $this->logInWithPermission('ADMIN');
     $page = new ErrorPage();
     $page->ErrorCode = 405;
     $page->Title = 'Method Not Allowed';
     $page->write();
     $page->doPublish();
     // Dynamic content is available
     $response = ErrorPage::response_for('405');
     $this->assertNotEmpty($response);
     $this->assertNotEmpty($response->getBody());
     $this->assertEquals(405, (int) $response->getStatusCode());
     // Static content is not available
     $this->assertEmpty(ErrorPage::get_content_for_errorcode('405'));
     $expectedErrorPagePath = AssetStoreTest_SpyStore::base_path() . '/error-405.html';
     $this->assertFileNotExists($expectedErrorPagePath, 'Error page is not cached in static location');
 }
예제 #16
0
 /**
  * @param Controller $controller
  *
  * @throws SS_HTTPResponse_Exception
  */
 public function respondNoAccess(Controller $controller)
 {
     $response = null;
     if (class_exists('ErrorPage', true)) {
         $response = ErrorPage::response_for(403);
     }
     $controller->httpError(403, $response ? $response : 'The requested page could not be found.');
 }
 function index()
 {
     if (self::order_started() && ($order = self::current_order())) {
         Director::redirect($order->Link());
         return;
     } elseif ($response = ErrorPage::response_for(404)) {
         return $response;
     }
     return $this->httpError(404, _t("ShoppingCart.NOCARTINITIALISED", "no cart initialised"));
 }
 /**
  * Handles rendering of the preview for an object
  * @return {string} Response to send to the object
  */
 public function preview()
 {
     $auth = $this->request->getVar('auth');
     $token = KapostPreviewToken::get()->filter('Code', Convert::raw2sql($auth))->first();
     //Verify the token exists and hasn't expired yet
     if (!empty($token) && $token !== false && $token->exists() && time() - strtotime($token->Created) < self::config()->preview_token_expiry * 60 && $token->KapostRefID == $this->urlParams['ID']) {
         $kapostObj = KapostObject::get()->filter('KapostRefID', Convert::raw2sql($this->urlParams['ID']))->sort('"Created" DESC')->first();
         if (!empty($kapostObj) && $kapostObj !== false && $kapostObj->exists()) {
             $previewController = $kapostObj->renderPreview();
             $this->extend('updatePreviewDisplay', $kapostObj, $previewController);
             return $previewController;
         }
     }
     //Token expired or object not found
     if (class_exists('ErrorPage')) {
         $response = ErrorPage::response_for(404);
         if (!empty($response)) {
             return $response;
         }
     }
     return parent::httpError(404);
 }
 /**
  *  try to show a proper 404 error page. If the locale doesn't exist or no errorpage
  *  exists for the current locale, show the 404 error page for the default locale
  *  this will not redirect! If this is the right approach is up for discussion...
  */
 protected function showPageNotFound()
 {
     if ($response = ErrorPage::response_for(404)) {
         return $response;
     }
     // if an errorpage is not defined for the current language
     // use the default language
     $locale = Translatable::default_locale();
     Translatable::set_current_locale($locale);
     if ($response = ErrorPage::response_for(404)) {
         return $response;
     }
     //return $this->httpError(404, 'The requested page could not be found!!');
 }
 /**
  * @uses ErrorPage::response_for()
  */
 public function httpError($code, $message = null)
 {
     // Don't use the HTML response for media requests
     $response = $this->getRequest()->isMedia() ? null : ErrorPage::response_for($code);
     // Failover to $message if the HTML response is unavailable / inappropriate
     parent::httpError($code, $response ? $response : $message);
 }
예제 #21
0
 /**
  * 404 redirect
  *
  * @since version 1.0.0
  *
  * @throws SS_HTTPResponse_Exception Return a 404 response
  * @return void
  **/
 private function redirect404()
 {
     Controller::curr()->response->removeHeader('Location');
     throw new SS_HTTPResponse_Exception(ErrorPage::response_for(404), 404);
 }
예제 #22
0
 /**
  * @return ContentController
  */
 public function getNestedController()
 {
     $request = $this->request;
     if (!($URLSegment = $request->param('URLSegment'))) {
         throw new Exception('ModelAsController->getNestedController(): was not passed a URLSegment value.');
     }
     // Find page by link, regardless of current locale settings
     if (class_exists('Translatable')) {
         Translatable::disable_locale_filter();
     }
     $sitetree = DataObject::get_one('SiteTree', sprintf('"SiteTree"."URLSegment" = \'%s\' %s', Convert::raw2sql(rawurlencode($URLSegment)), SiteTree::config()->nested_urls ? 'AND "SiteTree"."ParentID" = 0' : null));
     if (class_exists('Translatable')) {
         Translatable::enable_locale_filter();
     }
     if (!$sitetree) {
         $response = ErrorPage::response_for(404);
         $this->httpError(404, $response ? $response : 'The requested page could not be found.');
     }
     // Enforce current locale setting to the loaded SiteTree object
     if (class_exists('Translatable') && $sitetree->Locale) {
         Translatable::set_current_locale($sitetree->Locale);
     }
     if (isset($_REQUEST['debug'])) {
         Debug::message("Using record #{$sitetree->ID} of type {$sitetree->class} with link {$sitetree->Link()}");
     }
     return self::controller_for($sitetree, $this->request->param('Action'));
 }
 /**
  * @return ContentController
  * @throws Exception If URLSegment not passed in as a request parameter.
  */
 public function getNestedController()
 {
     $request = $this->getRequest();
     if (!($URLSegment = $request->param('URLSegment'))) {
         throw new Exception('ModelAsController->getNestedController(): was not passed a URLSegment value.');
     }
     // Find page by link, regardless of current locale settings
     if (class_exists('Translatable')) {
         Translatable::disable_locale_filter();
     }
     // Select child page
     $conditions = array('"SiteTree"."URLSegment"' => rawurlencode($URLSegment));
     if (SiteTree::config()->nested_urls) {
         $conditions[] = array('"SiteTree"."ParentID"' => 0);
     }
     $sitetree = DataObject::get_one('SiteTree', $conditions);
     // Check translation module
     // @todo Refactor out module specific code
     if (class_exists('Translatable')) {
         Translatable::enable_locale_filter();
     }
     if (!$sitetree) {
         $response = ErrorPage::response_for(404);
         $this->httpError(404, $response ? $response : 'The requested page could not be found.');
     }
     // Enforce current locale setting to the loaded SiteTree object
     if (class_exists('Translatable') && $sitetree->Locale) {
         Translatable::set_current_locale($sitetree->Locale);
     }
     if (isset($_REQUEST['debug'])) {
         Debug::message("Using record #{$sitetree->ID} of type {$sitetree->class} with link {$sitetree->Link()}");
     }
     return self::controller_for($sitetree, $this->getRequest()->param('Action'));
 }
 /**
  * Overrides the default getNestedController() to maintain the language restrictions
  * @return ContentController
  */
 public function getNestedController()
 {
     $request = $this->request;
     if (!($URLSegment = $request->param('URLSegment'))) {
         throw new Exception('ModelAsController->getNestedController(): was not passed a URLSegment value.');
     }
     // Find page by link
     $sitetree = DataObject::get_one('SiteTree', sprintf('"URLSegment" = \'%s\' %s', Convert::raw2sql(rawurlencode($URLSegment)), SiteTree::nested_urls() ? 'AND "ParentID" = 0' : null));
     if (!$sitetree) {
         $response = ErrorPage::response_for(404);
         $this->httpError(404, $response ? $response : 'The requested page could not be found.');
     }
     // Enforce current language setting to the loaded SiteTree object
     if (class_exists('Translatable') && $sitetree->Locale) {
         if (Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL')) {
             Cookie::set('language', $sitetree->Locale);
         } else {
             Cookie::set('language', i18n::get_lang_from_locale($sitetree->Locale));
         }
         Translatable::set_current_locale($sitetree->Locale);
     }
     if (isset($_REQUEST['debug'])) {
         Debug::message("Using record #{$sitetree->ID} of type {$sitetree->class} with link {$sitetree->Link()}");
     }
     return self::controller_for($sitetree, $this->request->param('Action'));
 }