/** * Resolve url's from any type of input. * * This method MUST either return a `\League\URL\URL` when a url is resolved * or null when a url cannot be resolved. * * @param array $arguments A list of the arguments * @param \League\URL\URLInterface $resolved * * @return \League\URL\URLInterface */ public function resolve(array $arguments, $resolved = null) { if ($this->cached) { return $this->cached; } $url = Url::createFromUrl(''); $url->setHost(null); $url->setScheme(null); if (\Config::get('concrete.seo.canonical_url')) { $canonical = UrlImmutable::createFromUrl(Config::get('concrete.seo.canonical_url')); // If the request is over https and the canonical url is http, lets just say https for the canonical url. if (strtolower($canonical->getScheme()) == 'http' && strtolower($this->request->getScheme()) == 'https') { $url->setScheme('https'); } else { $url->setScheme($canonical->getScheme()); } $url->setHost($canonical->getHost()); if (intval($canonical->getPort()->get()) > 0) { $url->setPort($canonical->getPort()); } } else { $host = $this->request->getHost(); $scheme = $this->request->getScheme(); if ($scheme && $host) { $url->setScheme($scheme)->setHost($host)->setPortIfNecessary(Request::getInstance()->getPort()); } } if ($relative_path = \Core::getApplicationRelativePath()) { $url = $url->setPath($relative_path); } $this->cached = UrlImmutable::createFromUrl($url); return $this->cached; }
public function register() { $singletons = array('helper/ajax' => '\\Concrete\\Core\\Http\\Service\\Ajax', 'helper/json' => '\\Concrete\\Core\\Http\\Service\\Json'); foreach ($singletons as $key => $value) { $this->app->singleton($key, $value); } $this->app->bind('Concrete\\Core\\Http\\Request', function ($app) { return Request::getInstance(); }); $this->app->bind(StackInterface::class, MiddlewareStack::class); $this->app->bind(DelegateInterface::class, MiddlewareDelegate::class); $this->app->bind(DispatcherInterface::class, DefaultDispatcher::class); $this->app->singleton(ServerInterface::class, function ($app) { $server = $app->build(DefaultServer::class); $config = $this->app['config']; foreach ($config->get('app.middleware') as $middleware) { if (is_array($middleware)) { $server->addMiddleware($app->make($middleware['class']), $middleware['priority']); } else { $server->addMiddleware($app->make($middleware)); } } return $server; }); // Response Factory $this->app->bind(ResponseFactoryInterface::class, ResponseFactory::class); }
public function setFavoriteTeam() { $leagueId = Request::getInstance()->get('favorite'); $th = Core::make('helper/text'); $leagueId = $th->sanitize($leagueId); $data = $this->getTeams($leagueId); $results = new Ajax(); $results->sendResult($data); }
public function register() { $singletons = array('helper/ajax' => '\\Concrete\\Core\\Http\\Service\\Ajax', 'helper/json' => '\\Concrete\\Core\\Http\\Service\\Json'); foreach ($singletons as $key => $value) { $this->app->singleton($key, $value); } $this->app->bind('Concrete\\Core\\Http\\Request', function ($app) { return Request::getInstance(); }); }
/** * Given either a path or a Page object, this is a shortcut to * 1. Grab the controller of THAT page. * 2. Grab the view of THAT controller * 3. Render that view. * 4. Exit – so we immediately stop all other output in the controller that * called render(). * * @param @string|\Concrete\Core\Page\Page $var */ public function replace($var) { if ($var instanceof Page) { $page = $var; $path = $var->getCollectionPath(); } else { $path = (string) $var; $page = Page::getByPath($path); } $request = Request::getInstance(); $controller = $page->getPageController(); $request->setCurrentPage($page); if (is_callable([$controller, 'setCustomRequestPath'])) { $controller->setCustomRequestPath($path); } $this->replacement = $controller; }
/** * @param \Illuminate\Config\Repository $config * * @return Request */ private function initializeRequest(Repository $config) { /* * ---------------------------------------------------------------------------- * Set trusted proxies and headers for the request * ---------------------------------------------------------------------------- */ if ($proxyHeaders = $config->get('concrete.security.trusted_proxies.headers')) { foreach ($proxyHeaders as $key => $value) { Request::setTrustedHeaderName($key, $value); } } if ($trustedProxiesIps = $config->get('concrete.security.trusted_proxies.ips')) { Request::setTrustedProxies($trustedProxiesIps); } /* * ---------------------------------------------------------------------------- * Obtain the Request object. * ---------------------------------------------------------------------------- */ $request = Request::getInstance(); return $request; }
protected function getPageFeedContent(Page $p) { switch ($this->pfContentToDisplay) { case 'S': return $p->getCollectionDescription(); case 'A': $a = new \Area($this->getAreaHandleToDisplay()); $blocks = $a->getAreaBlocksArray($p); $r = Request::getInstance(); $r->setCurrentPage($p); ob_start(); foreach ($blocks as $b) { $bv = new BlockView($b); $bv->render('view'); } $content = ob_get_contents(); ob_end_clean(); return $content; } }
public function _getUserGroups($disableLogin = false) { $app = Application::getFacadeApplication(); $req = Request::getInstance(); $session = $app['session']; if ($session->has('uGroups') && !$disableLogin && !$req->hasCustomRequestUser()) { $ug = $session->get('uGroups'); } else { $db = $app['database']->connection(); if ($this->uID) { $ug[REGISTERED_GROUP_ID] = REGISTERED_GROUP_ID; $uID = $this->uID; $q = "select gID from UserGroups where uID = ?"; $r = $db->query($q, array($uID)); while ($row = $r->fetch()) { $g = Group::getByID($row['gID']); if ($g->isUserExpired($this)) { $this->exitGroup($g); } else { $ug[$row['gID']] = $row['gID']; } } } // now we populate also with guest information, since presumably logged-in users // see the same stuff as guest $ug[GUEST_GROUP_ID] = GUEST_GROUP_ID; } return $ug; }
/** * Detect the application's current environment. * * @param array|string|Callable $environments * * @return string */ public function detectEnvironment($environments) { $r = Request::getInstance(); $pos = stripos($r->server->get('SCRIPT_NAME'), DISPATCHER_FILENAME); if ($pos > 0) { //we do this because in CLI circumstances (and some random ones) we would end up with index.ph instead of index.php $pos = $pos - 1; } $home = substr($r->server->get('SCRIPT_NAME'), 0, $pos); $this['app_relative_path'] = rtrim($home, '/'); $args = isset($_SERVER['argv']) ? $_SERVER['argv'] : null; $detector = new EnvironmentDetector(); return $this->environment = $detector->detect($environments, $args); }
protected function getPageFeedContent(Page $p) { $content = false; switch ($this->pfContentToDisplay) { case 'S': $content = $p->getCollectionDescription(); break; case 'A': $a = new \Area($this->getAreaHandleToDisplay()); $blocks = $a->getAreaBlocksArray($p); $r = Request::getInstance(); $r->setCurrentPage($p); ob_start(); foreach ($blocks as $b) { $bv = new BlockView($b); $bv->render('view'); } $content = ob_get_contents(); ob_end_clean(); break; } $f = $p->getAttribute('thumbnail'); if (is_object($f)) { $content = '<p><img src="' . $f->getURL() . '" /></p>' . $content; } return $content; }
public function preview($pThemeID) { $vl = $this->getValueListFromRequest($pThemeID); $pt = PageTheme::getByID($pThemeID); $pt->enablePreviewRequest(); $sheets = $pt->getThemeCustomizableStyleSheets(); // for each customizable stylesheet in the theme, we take the value list // and send its variables through the LESS parser. foreach ($sheets as $sheet) { $sheet->setValueList($vl); // we save each sheet to the preview location. $sheet->output(); } // and finally, we pass our modified theme into the updated view, which we send back in the iframe. $req = Request::getInstance(); $req->setCurrentPage($this->page); $controller = $this->page->getPageController(); $view = $controller->getViewObject(); $view->setCustomPageTheme($pt); $req->setCustomRequestUser(-1); $response = new Response(); $content = $view->render(); $response->setContent($content); return $response; }