public function action_switch_language($currentPageID, $sectionID, $bID = false) { $lang = Section::getByID(intval($sectionID)); if (is_object($lang)) { $page = \Page::getByID(intval($currentPageID)); if (!$page->isError()) { $relatedID = $lang->getTranslatedPageID($page); if ($relatedID) { $pc = \Page::getByID($relatedID); Redirect::page($pc)->send(); exit; } } Redirect::page($lang)->send(); exit; } Redirect::to('/'); exit; }
private function validateUser() { // check to see if this is a valid user account $user = new User(); if (!$user->checkLogin()) { $isActive = $user->isActive(); $user->logout(); if ($user->isError()) { switch ($user->getError()) { case USER_SESSION_EXPIRED: return Redirect::to('/login', 'session_invalidated')->send(); } } elseif (!$isActive) { return Redirect::to('/login', 'account_deactivated')->send(); } else { $v = new View('/frontend/user_error'); $v->setViewTheme('concrete'); $contents = $v->render(); return $this->app->make(ResponseFactoryInterface::class)->forbidden($contents); } } }
public function execute(Request $request, \Concrete\Core\Routing\Route $route = null, $parameters = array()) { // figure out where we need to go $c = Page::getFromRequest($request); if ($c->isError() && $c->getError() == COLLECTION_NOT_FOUND) { // if we don't have a path and we're doing cID, then this automatically fires a 404. if (!$request->getPath() && $request->get('cID')) { return $this->sendPageNotFound($request); } // let's test to see if this is, in fact, the home page, // and we're routing arguments onto it (which is screwing up the path.) $home = Page::getByID(HOME_CID); $request->setCurrentPage($home); $homeController = $home->getPageController(); $homeController->setupRequestActionAndParameters($request); if (!$homeController->validateRequest()) { return $this->sendPageNotFound($request); } else { $c = $home; $c->cPathFetchIsCanonical = true; } } if (!$c->cPathFetchIsCanonical) { // Handle redirect URL (additional page paths) /** @var Url $url */ $url = \Core::make('url/manager')->resolve(array($c)); $query = $url->getQuery(); $query->modify($request->getQueryString()); $url = $url->setQuery($query); $response = Redirect::to($url); $response->setStatusCode(301); return $response; } // maintenance mode if ($c->getCollectionPath() != '/login') { $smm = Config::get('concrete.maintenance_mode'); if ($smm == 1 && !PermissionKey::getByHandle('view_in_maintenance_mode')->validate() && ($_SERVER['REQUEST_METHOD'] != 'POST' || Loader::helper('validation/token')->validate() == false)) { $v = new View('/frontend/maintenance_mode'); $v->setViewTheme(VIEW_CORE_THEME); return $this->sendResponse($v); } } if ($c->getCollectionPointerExternalLink() != '') { return Redirect::url($c->getCollectionPointerExternalLink(), 301); } $cp = new Permissions($c); if ($cp->isError() && $cp->getError() == COLLECTION_FORBIDDEN) { return $this->sendPageForbidden($request, $c); } if (!$c->isActive() && !$cp->canViewPageVersions()) { return $this->sendPageNotFound($request); } if ($cp->canEditPageContents() || $cp->canEditPageProperties() || $cp->canViewPageVersions()) { $c->loadVersionObject('RECENT'); } $vp = new Permissions($c->getVersionObject()); // returns the $vp object, which we then check if (is_object($vp) && $vp->isError()) { switch ($vp->getError()) { case COLLECTION_NOT_FOUND: return $this->sendPageNotFound($request); break; case COLLECTION_FORBIDDEN: return $this->sendPageForbidden($request, $c); break; } } // Now that we've passed all permissions checks, and we have a page, we check to see if we // ought to redirect based on base url or trailing slash settings $cms = \Core::make("app"); $response = $cms->handleCanonicalURLRedirection($request); if (!$response) { $response = $cms->handleURLSlashes($request); } if (isset($response)) { $response->send(); exit; } // Now we check to see if we're on the home page, and if it multilingual is enabled, // and if so, whether we should redirect to the default language page. if (\Core::make('multilingual/detector')->isEnabled()) { $dl = Core::make('multilingual/detector'); if ($c->getCollectionID() == HOME_CID && Config::get('concrete.multilingual.redirect_home_to_default_locale')) { // Let's retrieve the default language $ms = $dl->getPreferredSection(); if (is_object($ms) && $ms->getCollectionID() != HOME_CID) { Redirect::page($ms)->send(); exit; } } $dl->setupSiteInterfaceLocalization($c); } $request->setCurrentPage($c); require DIR_BASE_CORE . '/bootstrap/process.php'; $u = new User(); // On page view event. $pe = new PageEvent($c); $pe->setUser($u); $pe->setRequest($request); Events::dispatch('on_page_view', $pe); $controller = $c->getPageController(); $controller->on_start(); $controller->setupRequestActionAndParameters($request); $response = $controller->validateRequest(); if ($response instanceof \Symfony\Component\HttpFoundation\Response) { return $response; } else { if ($response == false) { return $this->sendPageNotFound($request); } } $requestTask = $controller->getRequestAction(); $requestParameters = $controller->getRequestActionParameters(); $response = $controller->runAction($requestTask, $requestParameters); if ($response instanceof \Symfony\Component\HttpFoundation\Response) { return $response; } $c->setController($controller); $view = $controller->getViewObject(); // Mobile theme if (Config::get('concrete.misc.mobile_theme_id') > 0) { $md = new \Mobile_Detect(); if ($md->isMobile()) { $mobileTheme = Theme::getByID(Config::get('concrete.misc.mobile_theme_id')); if ($mobileTheme instanceof Theme) { $view->setViewTheme($mobileTheme); $controller->setTheme($mobileTheme); } } } // we update the current page with the one bound to this controller. $request->setCurrentPage($c); return $this->sendResponse($view); }
public function view() { $child = $this->getPageObject()->getFirstChild(); return Redirect::to($child); }
public function chooseRedirect() { $config = $this->app->make('config'); $session = $this->app->make('session'); if (!$this->error) { $this->error = $this->app->make('helper/validation/error'); } $nh = $this->app->make('helper/validation/numbers'); $navigation = $this->app->make('helper/navigation'); $rUrl = false; $u = new User(); // added for the required registration attribute change above. We recalc the user and make sure they're still logged in if ($u->isRegistered()) { if ($u->config('NEWSFLOW_LAST_VIEWED') == 'FIRSTRUN') { $u->saveConfig('NEWSFLOW_LAST_VIEWED', 0); } do { // redirect to original destination if ($session->has('rUri')) { $rUrl = $session->get('rUri'); $session->remove('rUri'); if ($rUrl) { break; } } if ($session->has('rcID')) { $rcID = $session->get('rcID'); if ($nh->integer($rcID)) { $rc = Page::getByID($rcID); } elseif (strlen($rcID)) { $rcID = trim($rcID, '/'); $rc = Page::getByPath('/' . $rcID); } if ($rc instanceof Page && !$rc->isError()) { $rUrl = $navigation->getLinkToCollection($rc); break; } } $login_redirect_mode = $config->get('concrete.misc.login_redirect'); //redirect to custom page $login_redirect_cid = intval($config->get('concrete.misc.login_redirect_cid')); if ($login_redirect_mode == 'CUSTOM' && $login_redirect_cid > 0) { $rc = Page::getByID($login_redirect_cid); if ($rc instanceof Page && !$rc->isError()) { $rUrl = $navigation->getLinkToCollection($rc); break; } } if ($login_redirect_mode == 'DESKTOP') { $desktop = DesktopList::getMyDesktop(); if (is_object($desktop)) { $rUrl = $navigation->getLinkToCollection($desktop); } } break; } while (false); if ($rUrl) { return new RedirectResponse($rUrl); } else { return Redirect::to('/'); } } else { $this->error->add(t('User is not registered. Check your authentication controller.')); $u->logout(); } }
public function action_submit($bID = null) { if ($this->bID == $bID) { $entityManager = \Core::make('database/orm')->entityManager(); $form = $this->getFormEntity(); if (is_object($form)) { $e = \Core::make('error'); $validator = new Validator($e, $this->request); $validator->validate($form); if ($this->displayCaptcha) { $captcha = \Core::make('helper/validation/captcha'); if (!$captcha->check()) { $e->add(t('Incorrect captcha code.')); } } $this->set('error', $e); } $entity = $form->getEntity(); $permissions = new \Permissions($entity); if (!$permissions->canAddExpressEntries()) { $e->add(t('You do not have access to submit this form.')); } if (isset($e) && !$e->has()) { $manager = new Manager($entityManager, $this->request); $entry = $manager->addEntry($entity); $entry = $manager->saveEntryAttributesForm($form, $entry); $values = $entity->getAttributeKeyCategory()->getAttributeValues($entry); // Check antispam $antispam = \Core::make('helper/validation/antispam'); $submittedData = ''; foreach ($values as $value) { $submittedData .= $value->getAttributeKey()->getAttributeKeyDisplayName() . ":\r\n"; $submittedData .= $value->getPlainTextValue() . "\r\n\r\n"; } if (!$antispam->check($submittedData, 'form_block')) { // Remove the entry and silently fail. $entityManager->refresh($entry); $entityManager->remove($entry); $entityManager->flush(); $c = \Page::getCurrentPage(); $r = Redirect::page($c); $r->setTargetUrl($r->getTargetUrl() . '#form' . $this->bID); return $r; } if ($this->addFilesToSet) { $set = Set::getByID($this->addFilesToSet); if (is_object($set)) { foreach ($values as $value) { $value = $value->getValueObject(); if ($value instanceof FileProviderInterface) { $files = $value->getFileObjects(); foreach ($files as $file) { $set->addFileToSet($file); } } } } } if ($this->notifyMeOnSubmission) { if (\Config::get('concrete.email.form_block.address') && strstr(\Config::get('concrete.email.form_block.address'), '@')) { $formFormEmailAddress = \Config::get('concrete.email.form_block.address'); } else { $adminUserInfo = \UserInfo::getByID(USER_SUPER_ID); $formFormEmailAddress = $adminUserInfo->getUserEmail(); } $replyToEmailAddress = $formFormEmailAddress; if ($this->replyToEmailControlID) { $control = $entityManager->getRepository('Concrete\\Core\\Entity\\Express\\Control\\Control')->findOneById($this->replyToEmailControlID); if (is_object($control)) { $email = $entry->getAttribute($control->getAttributeKey()); if ($email) { $replyToEmailAddress = $email; } } } $formName = $this->getFormEntity()->getEntity()->getName(); $mh = \Core::make('helper/mail'); $mh->to($this->recipientEmail); $mh->from($formFormEmailAddress); $mh->replyto($replyToEmailAddress); $mh->addParameter('entity', $entity); $mh->addParameter('formName', $formName); $mh->addParameter('attributes', $values); $mh->load('block_express_form_submission'); $mh->setSubject(t('Website Form Submission – %s', $formName)); $mh->sendMail(); } if ($this->redirectCID > 0) { $c = \Page::getByID($this->redirectCID); if (is_object($c) && !$c->isError()) { $r = Redirect::page($c); $r->setTargetUrl($r->getTargetUrl() . '?form_success=1'); return $r; } } $c = \Page::getCurrentPage(); $url = \URL::to($c, 'form_success', $this->bID); $r = Redirect::to($url); $r->setTargetUrl($r->getTargetUrl() . '#form' . $this->bID); return $r; } } $this->view(); }
public function validateRequest() { $valid = true; if (!$this->isValidControllerTask($this->action, $this->parameters)) { $valid = false; // we check the blocks on the page. $blocks = array_merge($this->getPageObject()->getBlocks(), $this->getPageObject()->getGlobalBlocks()); foreach ($blocks as $b) { $controller = $b->getController(); list($method, $parameters) = $controller->getPassThruActionAndParameters($this->parameters); if ($controller->isValidControllerTask($method, $parameters)) { $controller->on_start(); $response = $controller->runAction($method, $parameters); if ($response instanceof Response) { return $response; } // old school blocks have already terminated at this point. They are redirecting // or exiting. But new blocks like topics, etc... can actually rely on their $set // data persisting and being passed into the view. // so if we make it down here we have to return true –so that we don't fire a 404. $valid = true; // then, we need to save the persisted data that may have been set. $controller->setPassThruBlockController($this); } } if (!$valid) { // finally, we check additional page paths. $paths = $this->getPageObject()->getAdditionalPagePaths(); foreach ($paths as $path) { if ($path->getPagePath() == $this->request->getPath()) { // This is an additional page path to a page. We 301 redirect. return Redirect::page($this->getPageObject(), 301); } } } } return $valid; }
public function execute(Request $request, \Concrete\Core\Routing\Route $route = null, $parameters = array()) { // figure out where we need to go $c = Page::getFromRequest($request); if ($c->isError() && $c->getError() == COLLECTION_NOT_FOUND) { // if we don't have a path and we're doing cID, then this automatically fires a 404. if (!$request->getPath() && $request->get('cID')) { return $this->sendPageNotFound($request); } // let's test to see if this is, in fact, the home page, // and we're routing arguments onto it (which is screwing up the path.) $home = Page::getByID(HOME_CID); $homeController = $home->getPageController(); $homeController->setupRequestActionAndParameters($request); if (!$homeController->validateRequest()) { return $this->sendPageNotFound($request); } else { $c = $home; } } // maintenance mode if (!$c->isAdminArea() && $c->getCollectionPath() != '/login') { $smm = Config::get('concrete.maintenance_mode'); if ($smm == 1 && ($_SERVER['REQUEST_METHOD'] != 'POST' || Loader::helper('validation/token')->validate() == false)) { $v = new View('/frontend/maintenance_mode'); $v->setViewTheme(VIEW_CORE_THEME); return $this->sendResponse($v); } } if ($c->getCollectionPointerExternalLink() != '') { return Redirect::url($c->getCollectionPointerExternalLink(), 301)->send(); } $cp = new Permissions($c); if ($cp->isError() && $cp->getError() == COLLECTION_FORBIDDEN) { return $this->sendPageForbidden($request); } if (!$c->isActive() && !$cp->canViewPageVersions()) { return $this->sendPageNotFound($request); } if ($cp->canEditPageContents() || $cp->canEditPageProperties() || $cp->canViewPageVersions()) { $c->loadVersionObject('RECENT'); } $vp = new Permissions($c->getVersionObject()); // returns the $vp object, which we then check if (is_object($vp) && $vp->isError()) { switch ($vp->getError()) { case COLLECTION_NOT_FOUND: return $this->sendPageNotFound($request); break; case COLLECTION_FORBIDDEN: return $this->sendPageForbidden($request); break; } } $request->setCurrentPage($c); require DIR_BASE_CORE . '/bootstrap/process.php'; $u = new User(); ## Fire the on_page_view Eventclass $pe = new PageEvent($c); $pe->setUser($u); Events::dispatch('on_page_view', $pe); $controller = $c->getPageController(); $controller->on_start(); $controller->setupRequestActionAndParameters($request); $response = $controller->validateRequest(); if ($response instanceof \Concrete\Core\Http\Response) { return $response; } else { if ($response == false) { return $this->sendPageNotFound($request); } } $requestTask = $controller->getRequestAction(); $requestParameters = $controller->getRequestActionParameters(); $controller->runAction($requestTask, $requestParameters); $c->setController($controller); $view = $controller->getViewObject(); // we update the current page with the one bound to this controller. $request->setCurrentPage($c); return $this->sendResponse($view); }
/** * (non-PHPdoc) * @see \mithra62\Platforms\AbstractPlatform::redirect() */ public function redirect($url) { return \Concrete\Core\Routing\Redirect::url($url); }