Example #1
0
 public function preview()
 {
     $request = \Request::getInstance();
     $c = \Page::getByID($this->request->get('cID'));
     $cp = new \Permissions($c);
     if ($cp->canViewPageVersions()) {
         $c->loadVersionObject(\Core::make('helper/security')->sanitizeInt($_REQUEST['cvID']));
         $spoofed_request = \Request::createFromGlobals();
         if ($device_handle = $request->headers->get('x-device-handle')) {
             if ($device = \Core::make('device/manager')->get($device_handle)) {
                 if ($agent = $device->getUserAgent()) {
                     $spoofed_request->headers->set('User-Agent', $agent);
                 }
             }
         }
         $spoofed_request->setCustomRequestUser(-1);
         $spoofed_request->setCurrentPage($c);
         \Request::setInstance($spoofed_request);
         $controller = $c->getPageController();
         $controller->runTask('view', array());
         $view = $controller->getViewObject();
         $response = new \Response();
         $content = $view->render();
         // Reset just in case.
         \Request::setInstance($request);
         $response->setContent($content);
         $response->send();
         exit;
     }
 }
 public function testFromRequest()
 {
     $mock = $this->getMock('\\Concrete\\Core\\Http\\RequestBase');
     $mock->expects($this->once())->method('getScheme')->willReturn('http');
     $mock->expects($this->once())->method('getHost')->willReturn('somehost');
     $old_instance = \Request::getInstance();
     \Request::setInstance($mock);
     $old_value = \Config::get('concrete.seo.canonical_url');
     \Config::set('concrete.seo.canonical_url', null);
     $this->assertEquals((string) \Concrete\Core\Url\Url::createFromUrl("http://somehost")->setPath(\Core::getApplicationRelativePath()), (string) $this->urlResolver->resolve(array()));
     \Config::set('concrete.seo.canonical_url', $old_value);
     \Request::setInstance($old_instance);
 }