Пример #1
0
 /**
  * @param \Symfony\Component\HttpFoundation\Session\Session $session
  */
 public function handleSessionValidation(SymfonySession $session)
 {
     $ip_address = new IPAddress($this->request->getClientIp());
     $request_ip = $ip_address->getIp(IPAddress::FORMAT_IP_STRING);
     $invalidate = false;
     $ip = $session->get('CLIENT_REMOTE_ADDR');
     $agent = $session->get('CLIENT_HTTP_USER_AGENT');
     $request_agent = $this->request->server->get('HTTP_USER_AGENT');
     // Validate the request IP
     if ($this->shouldCompareIP() && $ip && $ip != $request_ip) {
         if ($this->logger) {
             $this->logger->debug('Session Invalidated. Session IP "{session}" did not match provided IP "{client}".', array('session' => $ip, 'client' => $request_ip));
         }
         $invalidate = true;
     }
     // Validate the request user agent
     if ($this->shouldCompareAgent() && $agent && $agent != $request_agent) {
         if ($this->logger) {
             $this->logger->debug('Session Invalidated. Session user agent "{session}" did not match provided agent "{client}"', array('session' => $agent, 'client' => $request_agent));
         }
         $invalidate = true;
     }
     if ($invalidate) {
         $session->invalidate();
     } else {
         if (!$ip && $request_ip) {
             $session->set('CLIENT_REMOTE_ADDR', $request_ip);
         }
         if (!$agent && $request_agent) {
             $session->set('CLIENT_HTTP_USER_AGENT', $request_agent);
         }
     }
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 public function shouldLogQueries(Request $request)
 {
     $th = Core::make('helper/text');
     foreach ($this->excludedPaths as $path) {
         if ($th->fnmatch($path, $request->getPath())) {
             return false;
         }
     }
     return true;
 }
Пример #4
0
 /**
  * Create a new symfony session object
  * This method MUST NOT start the session
  *
  * @return \Symfony\Component\HttpFoundation\Session\Session
  */
 public function createSession()
 {
     $config = $this->app['config'];
     $storage = $this->getSessionStorage($config);
     $session = new SymfonySession($storage);
     $session->setName($config->get('concrete.session.name'));
     /**
      * @todo Move this to somewhere else
      */
     $this->request->setSession($session);
     return $session;
 }
 /**
  * @param \Concrete\Core\Http\Request $req
  * @return Error
  */
 public function validateRequest(\Concrete\Core\Http\Request $req)
 {
     $e = new Error();
     $data = $req->get('fslType');
     $this->path = $data['path'];
     if (!$this->path) {
         $e->add(t("You must include a root path for this storage location."));
     } else {
         if (!is_dir($this->path)) {
             $e->add(t("The specified root path does not exist."));
         }
     }
     return $e;
 }
 /**
  * @param \Concrete\Core\Http\Request $req
  *
  * @return Error
  */
 public function validateRequest(\Concrete\Core\Http\Request $req)
 {
     $e = \Core::make('error');
     $data = $req->get('fslType');
     $this->path = $data['path'];
     if (!$this->path) {
         $e->add(t("You must include a root path for this storage location."));
     } elseif (!is_dir($this->path)) {
         $e->add(t("The specified root path does not exist."));
     } elseif ($this->path == '/') {
         $e->add(t('Invalid path to file storage location. You may not choose the root directory.'));
     }
     return $e;
 }
 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);
 }
Пример #8
0
 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);
 }
 /**
  * Create a service object given a ServiceFactory object
  *
  * @param \OAuth\ServiceFactory $factory
  * @return \OAuth\Common\Service\ServiceInterface
  */
 public function createService(ServiceFactory $factory)
 {
     $appId = $this->config->get('auth.community.appid');
     $appSecret = $this->config->get('auth.community.secret');
     // Get the callback url
     /** @var Url $callbackUrl */
     $callbackUrl = $this->urlResolver->resolve(['/ccm/system/authentication/oauth2/community/callback/']);
     if ($callbackUrl->getHost() == '') {
         $callbackUrl = $callbackUrl->setHost($this->request->getHost());
         $callbackUrl = $callbackUrl->setScheme($this->request->getScheme());
     }
     // Create a credential object with our ID, Secret, and callback url
     $credentials = new Credentials($appId, $appSecret, (string) $callbackUrl);
     // Create a new session storage object and pass it the active session
     $storage = new SymfonySession($this->session, false);
     // Create the service using the oauth service factory
     return $factory->createService('community', $credentials, $storage);
 }
Пример #10
0
 /**
  * Begin the runtime.
  */
 public function run()
 {
     $app = $this->app;
     include DIR_APPLICATION . '/bootstrap/app.php';
     if ($this->app->isInstalled()) {
         /*
          * ----------------------------------------------------------------------------
          * Now that we have languages out of the way, we can run our package on_start
          * methods
          * ----------------------------------------------------------------------------
          */
         $app->setupPackages();
         /*
          * ----------------------------------------------------------------------------
          * Legacy Definitions. This has to come after packages because this
          * essentially loads the entity manager, and the entity manager loads classes
          * found in its config, which may be classes that haven't been autoloaded by initialPackages. It also
          * has to come after setupPackages() in case an autoloader is configured in on_start()
          * ----------------------------------------------------------------------------
          */
         $this->initializeLegacyURLDefinitions($app);
         /*
          * Handle automatic updating. Must come after setupPackages() because some things setup autoloaders in on_start() of their package
          * controller
          */
         $app->handleAutomaticUpdates();
         // This is a crappy place for this, but it has to come AFTER the packages because sometimes packages
         // want to replace legacy "tools" URLs with the new MVC, and the tools paths are so greedy they don't
         // work unless they come at the end.
         $this->registerLegacyRoutes();
         /* ----------------------------------------------------------------------------
          * Register legacy routes
          * ----------------------------------------------------------------------------
          */
         $this->registerLegacyRoutes();
         /* ----------------------------------------------------------------------------
          * Register legacy config values
          * ----------------------------------------------------------------------------
          */
         $this->registerLegacyConfigValues();
         /*
          * ----------------------------------------------------------------------------
          * Load all permission keys into our local cache.
          * ----------------------------------------------------------------------------
          */
         Key::loadAll();
     }
     /*
      * ----------------------------------------------------------------------------
      * Fire an event for intercepting the dispatch
      * ----------------------------------------------------------------------------
      */
     Events::dispatch('on_before_dispatch');
     $request = Request::createFromGlobals();
     return $this->server->handleRequest($request);
 }
Пример #11
0
 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();
     });
 }
 /**
  * Create a service object given a ServiceFactory object
  *
  * @return \OAuth\Common\Service\ServiceInterface
  */
 public function createService()
 {
     $appId = $this->config->get('auth.twitter.appid');
     $appSecret = $this->config->get('auth.twitter.secret');
     $verifyPeer = $this->config->get('app.curl.verifyPeer');
     /** @var ServiceFactory $factory */
     $factory = $this->app->make('oauth/factory/service', array(CURLOPT_SSL_VERIFYPEER => $verifyPeer));
     // Get the callback url
     $callbackUrl = $this->urlResolver->resolve(['/ccm/system/authentication/oauth2/twitter/callback/']);
     if ($callbackUrl->getHost() == '') {
         $callbackUrl = $callbackUrl->setHost($this->request->getHost());
         $callbackUrl = $callbackUrl->setScheme($this->request->getScheme());
     }
     // Create a credential object with our ID, Secret, and callback url
     $credentials = new Credentials($appId, $appSecret, (string) $callbackUrl);
     // Create a new session storage object and pass it the active session
     $storage = new SymfonySession($this->session, false);
     // Create the service using the oauth service factory
     return $factory->createService('twitter', $credentials, $storage);
 }
Пример #13
0
 /**
  * @inheritdoc
  */
 public function forbidden($requestUrl, $code = Response::HTTP_FORBIDDEN, $headers = array())
 {
     // set page for redirection after successful login
     $this->session->set('rUri', $requestUrl);
     // load page forbidden
     $item = '/page_forbidden';
     $c = Page::getByPath($item);
     if (is_object($c) && !$c->isError()) {
         $this->request->setCurrentPage($c);
         return $this->controller($c->getPageController(), $code, $headers);
     }
     $cnt = $this->app->make(PageForbidden::class);
     $this->controller($cnt, $code, $headers);
 }
 /**
  * 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;
     }
     $config = $this->app['config'];
     // Determine trailing slash setting
     $trailing_slashes = $config->get('concrete.seo.trailing_slash') ? Url::TRAILING_SLASHES_ENABLED : Url::TRAILING_SLASHES_DISABLED;
     $url = Url::createFromUrl('', $trailing_slashes);
     $url->setHost(null);
     $url->setScheme(null);
     if ($config->get('concrete.seo.canonical_url')) {
         $canonical = UrlImmutable::createFromUrl($config->get('concrete.seo.canonical_url'), $trailing_slashes);
         // 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)->setPort($this->request->getPort());
         }
     }
     if ($relative_path = $this->app['app_relative_path']) {
         $url = $url->setPath($relative_path);
     }
     $this->cached = UrlImmutable::createFromUrl($url, $trailing_slashes);
     return $this->cached;
 }
Пример #15
0
 public function setUp()
 {
     $this->app = clone Application::getFacadeApplication();
     $this->app['config'] = clone $this->app['config'];
     $this->request = Request::create('http://url.com/');
     $this->validator = new SessionValidator($this->app, $this->app['config'], $this->request);
     $store = array();
     $mock = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\Session\\Session')->setMethods(array('has', 'get', 'set', 'invalidate', 'all'))->getMock();
     $mock->expects($this->any())->method('has')->willReturnCallback(function ($key) use(&$store) {
         return array_get($store, $key) !== null;
     });
     $mock->expects($this->any())->method('get')->willReturnCallback(function ($key, $default = null) use(&$store) {
         return array_get($store, $key, $default);
     });
     $mock->expects($this->any())->method('set')->willReturnCallback(function ($key, $value) use(&$store) {
         return $store[$key] = $value;
     });
     $mock->expects($this->any())->method('all')->willReturnCallback(function () use(&$store) {
         return $store;
     });
     $this->session = $mock;
 }
Пример #16
0
 /**
  * @param null $key
  * @param null $default_value
  * @return mixed|null
  */
 public function request($key = null, $default_value = null)
 {
     if ($key == null) {
         return $_REQUEST;
     }
     $req = Request::createFromGlobals();
     if ($req->query->has($key)) {
         return $req->query->get($key);
     } else {
         if ($req->request->has($key)) {
             return $req->request->get($key);
         }
     }
     return $default_value;
 }
Пример #17
0
 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;
     }
 }
Пример #18
0
 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;
 }
 /**
  * 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.
  *
  * If the first argument provided is a page object, we will use that object to determine the site tree
  * (and thus the canonical url) to use.
  *
  * @param array $arguments A list of the arguments
  * @param \League\URL\URLInterface $resolved
  *
  * @return \League\URL\URLInterface
  */
 public function resolve(array $arguments, $resolved = null)
 {
     $config = null;
     $page = null;
     // Canonical urls for pages can be different than for the entire site
     if (count($arguments) && head($arguments) instanceof Page) {
         /** @var Page $page */
         $page = head($arguments);
         $tree = $page->getSiteTreeObject();
         if ($tree instanceof SiteTree && ($site = $tree->getSite())) {
             $config = $site->getConfigRepository();
         }
     } elseif ($this->cached) {
         return $this->cached;
     }
     // Get the config from the current site tree
     if ($config === null && $this->app->isInstalled()) {
         $site = $this->app['site']->getSite();
         if (is_object($site)) {
             $config = $site->getConfigRepository();
         }
     }
     // Determine trailing slash setting
     $trailing_slashes = $config && $config->get('seo.trailing_slash') ? Url::TRAILING_SLASHES_ENABLED : Url::TRAILING_SLASHES_DISABLED;
     $url = UrlImmutable::createFromUrl('', $trailing_slashes);
     $url = $url->setHost(null);
     $url = $url->setScheme(null);
     if ($config && ($configUrl = $site->getSiteCanonicalURL())) {
         $canonical = UrlImmutable::createFromUrl($configUrl, $trailing_slashes);
         if ($configSslUrl = $config->get('seo.canonical_ssl_url')) {
             $canonical_ssl = UrlImmutable::createFromUrl($configSslUrl, $trailing_slashes);
         }
         $url = $url->setHost($canonical->getHost());
         $url = $url->setScheme($canonical->getScheme());
         // If the request is over https
         if (strtolower($this->request->getScheme()) == 'https') {
             // If the canonical ssl url is set, respect the canonical ssl url.
             if (isset($canonical_ssl)) {
                 $url = $url->setHost($canonical_ssl->getHost());
                 $url = $url->setScheme($canonical_ssl->getScheme());
                 if (intval($canonical_ssl->getPort()->get()) > 0) {
                     $url = $url->setPort($canonical_ssl->getPort());
                 }
             } else {
                 // If the canonical url is http, lets just say https for the canonical url.
                 if (strtolower($canonical->getScheme()) == 'http') {
                     $url = $url->setScheme('https');
                 }
                 if (intval($canonical->getPort()->get()) > 0) {
                     $url = $url->setPort($canonical->getPort());
                 }
             }
         } elseif (intval($canonical->getPort()->get()) > 0) {
             $url = $url->setPort($canonical->getPort());
         }
     }
     if ($relative_path = $this->app['app_relative_path']) {
         $url = $url->setPath($relative_path);
     }
     // Don't cache page specific canonical urls
     if (!$page) {
         $this->cached = $url;
     }
     return $url;
 }
Пример #20
0
 /**
  * This should be removed and moved into a request middleware layer, lets just make sure it happens here for now
  */
 public function testAddedToRequest()
 {
     $session = $this->factory->createSession();
     $this->assertEquals($session, $this->request->getSession());
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Session\\SessionInterface', $this->request->getSession());
 }
Пример #21
0
 private function collectionNotFound(Collection $collection, Request $request, array $headers)
 {
     // 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->notFound('', Response::HTTP_NOT_FOUND, $headers);
     }
     // 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);
     $response = $homeController->validateRequest();
     if ($response instanceof \Symfony\Component\HttpFoundation\Response) {
         return $response;
     } elseif ($response === true) {
         return $this->controller($homeController);
     } else {
         return $this->notFound('', Response::HTTP_NOT_FOUND, $headers);
     }
 }
Пример #22
0
 /**
  * {@inheritdoc}
  */
 public function prepare(Request $request)
 {
     $this->headers->set('Content-Length', $this->file->getSize());
     if (!$this->headers->has('Accept-Ranges')) {
         // Only accept ranges on safe HTTP methods
         $this->headers->set('Accept-Ranges', $request->isMethodSafe() ? 'bytes' : 'none');
     }
     if (!$this->headers->has('Content-Type')) {
         $this->headers->set('Content-Type', $this->file->getMimetype() ?: 'application/octet-stream');
     }
     if ('HTTP/1.0' != $request->server->get('SERVER_PROTOCOL')) {
         $this->setProtocolVersion('1.1');
     }
     $this->ensureIEOverSSLCompatibility($request);
     $this->offset = 0;
     $this->maxlen = -1;
     if ($request->headers->has('Range')) {
         // Process the range headers.
         if (!$request->headers->has('If-Range') || $this->getEtag() == $request->headers->get('If-Range')) {
             $range = $request->headers->get('Range');
             $fileSize = $this->file->getSize();
             list($start, $end) = explode('-', substr($range, 6), 2) + array(0);
             $end = '' === $end ? $fileSize - 1 : (int) $end;
             if ('' === $start) {
                 $start = $fileSize - $end;
                 $end = $fileSize - 1;
             } else {
                 $start = (int) $start;
             }
             if ($start <= $end) {
                 if ($start < 0 || $end > $fileSize - 1) {
                     $this->setStatusCode(416);
                 } elseif ($start !== 0 || $end !== $fileSize - 1) {
                     $this->maxlen = $end < $fileSize ? $end - $start + 1 : -1;
                     $this->offset = $start;
                     $this->setStatusCode(206);
                     $this->headers->set('Content-Range', sprintf('bytes %s-%s/%s', $start, $end, $fileSize));
                     $this->headers->set('Content-Length', $end - $start + 1);
                 }
             }
         }
     }
     return $this;
 }
Пример #23
0
 public function testPathSlashesRedirection()
 {
     $app = Core::make("app");
     $request = \Concrete\Core\Http\Request::create('http://xn--mgbh0fb.xn--kgbechtv/services');
     $response = $app->handleURLSlashes($request);
     $this->assertNull($response);
     $request = \Concrete\Core\Http\Request::create('http://xn--fsqu00a.xn--0zwm56d/services/');
     $response = $app->handleURLSlashes($request);
     $this->assertEquals('http://例子.测试/services', $response->getTargetUrl());
     $request = \Concrete\Core\Http\Request::create('http://concrete5.dev/derp');
     $response = $app->handleURLSlashes($request);
     $this->assertNull($response);
     $request = \Concrete\Core\Http\Request::create('http://concrete5.dev/index.php?cID=1');
     $response = $app->handleURLSlashes($request);
     $this->assertNull($response);
     $request = \Concrete\Core\Http\Request::create('http://www.awesome.com/about-us/now');
     $response = $app->handleURLSlashes($request);
     $this->assertNull($response);
     $request = \Concrete\Core\Http\Request::create('http://www.awesome.com/about-us/now/');
     $response = $app->handleURLSlashes($request);
     $this->assertInstanceOf('\\Concrete\\Core\\Routing\\RedirectResponse', $response);
     $this->assertEquals('http://www.awesome.com/about-us/now', $response->getTargetUrl());
     $request = \Concrete\Core\Http\Request::create('http://www.awesome.com/index.php/about-us/now/?bar=1&foo=2');
     $response = $app->handleURLSlashes($request);
     $this->assertInstanceOf('\\Concrete\\Core\\Routing\\RedirectResponse', $response);
     $this->assertEquals('http://www.awesome.com/index.php/about-us/now?bar=1&foo=2', $response->getTargetUrl());
     Config::set('concrete.seo.trailing_slash', true);
     $request = \Concrete\Core\Http\Request::create('http://www.awesome.com:8080/index.php/about-us/now/?bar=1&foo=2');
     $response = $app->handleURLSlashes($request);
     $this->assertNull($response);
     $request = \Concrete\Core\Http\Request::create('http://www.awesome.com:8080/index.php/about-us/now?bar=1&foo=2');
     $response = $app->handleURLSlashes($request);
     $this->assertEquals('http://www.awesome.com:8080/index.php/about-us/now/?bar=1&foo=2', $response->getTargetUrl());
     Config::set('concrete.seo.trailing_slash', false);
 }
Пример #24
0
 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;
 }
Пример #25
0
 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;
 }
Пример #26
0
 public function setupRequestActionAndParameters(Request $request)
 {
     $requestPath = $this->getCustomRequestPath();
     if ($requestPath === null) {
         $requestPath = $request->getPath();
     }
     $task = substr($requestPath, strlen($this->c->getCollectionPath()) + 1);
     $task = str_replace('-/', '', $task);
     $taskparts = explode('/', $task);
     if (isset($taskparts[0]) && $taskparts[0] !== '') {
         $method = $taskparts[0];
     } elseif (is_object($this->c) && is_callable(array($this, $this->c->getCollectionHandle()))) {
         $method = $this->c->getCollectionHandle();
     } else {
         $method = 'view';
     }
     $foundTask = false;
     $restrictedControllers = array('Concrete\\Core\\Controller\\Controller', 'Concrete\\Core\\Controller\\AbstractController', 'Concrete\\Core\\Page\\Controller\\PageController');
     try {
         $r = new \ReflectionMethod(get_class($this), $method);
         $cl = $r->getDeclaringClass();
         if (is_object($cl)) {
             if (!in_array($cl->getName(), $restrictedControllers) && strpos($method, 'on_') !== 0 && strpos($method, '__') !== 0 && $r->isPublic() && !$r->isConstructor() && (is_array($this->restrictedMethods) && !in_array($method, $this->restrictedMethods))) {
                 $foundTask = true;
             }
         }
     } catch (\Exception $e) {
     }
     if ($foundTask) {
         $this->action = $method;
         if (isset($taskparts[1])) {
             array_shift($taskparts);
             $this->parameters = $taskparts;
         }
     } else {
         $this->action = 'view';
         if ($taskparts[0] !== '') {
             $this->parameters = $taskparts;
         }
     }
 }
Пример #27
0
 /**
  * If we haven't installed and we're not looking at the install directory, redirect.
  *
  * @param Application $app
  * @param Request $request
  *
  * @return null|Response
  */
 private function checkInstall(Application $app, Request $request)
 {
     if (!$app->isInstalled()) {
         if (!$request->matches('/install/*') && $request->getPath() != '/install' && !$request->matches('/ccm/assets/localization/*')) {
             $manager = $app->make('Concrete\\Core\\Url\\Resolver\\Manager\\ResolverManager');
             $response = new RedirectResponse($manager->resolve(array('install')));
             return $response;
         }
     }
 }
Пример #28
0
 /**
  * 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);
 }
Пример #29
0
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__)));
require_once 'ConcreteDatabaseTestCase.php';
require_once 'BlockTypeTestCase.php';
require_once 'PageTestCase.php';
require_once 'AttributeTestCase.php';
require_once 'FileStorageTestCase.php';
require_once 'UserTestCase.php';
define('DIR_BASE', realpath(dirname(__FILE__) . '/../../web'));
$DIR_BASE_CORE = realpath(dirname(__FILE__) . '/../../web/concrete');
require $DIR_BASE_CORE . '/bootstrap/configure.php';
/**
 * Include all autoloaders
 */
require $DIR_BASE_CORE . '/bootstrap/autoload.php';
$r = new \Concrete\Core\Http\Request(array(), array(), array(), array(), array(), array('HTTP_HOST' => 'www.dummyco.com', 'SCRIPT_NAME' => '/path/to/server/index.php'));
\Concrete\Core\Http\Request::setInstance($r);
/**
 * Begin concrete5 startup.
 */
$cms = (require $DIR_BASE_CORE . '/bootstrap/start.php');
/**
 * Test more strictly than core settings
 */
error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED);
class TestConfigRepository extends Repository
{
    public function save($key, $value)
    {
        return true;
    }
}
 /**
  * @deprecated Use CollectionResponseFactory
  * @param Request $request
  * @param $currentPage
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function sendPageForbidden(Request $request, $currentPage)
 {
     return $this->factory->forbidden($request->getUri());
 }