public function getEventsAction(SS_HTTPRequest $request)
 {
     // Search date
     $date = DBField::create_field("SS_Datetime", $request->param("SearchDate"));
     if (!$date->getValue()) {
         $date = SS_Datetime::now();
     }
     // Get event data
     $cache = SS_Cache::factory(self::EVENTS_CACHE_NAME);
     $cacheKey = $date->Format('Y_m_d');
     if ($result = $cache->load($cacheKey)) {
         $data = unserialize($result);
     } else {
         $data = EventsDataUtil::get_events_data_for_day($date);
         $cache->save(serialize($data), $cacheKey);
     }
     // Get init data
     if ($request->param("GetAppConfig")) {
         $cache = SS_Cache::factory(self::CONFIG_CACHE_NAME);
         $cacheKey = 'APP_CONFIG';
         if ($result = $cache->load($cacheKey)) {
             $configData = unserialize($result);
         } else {
             $configData = AppConfigDataUtil::get_config_data();
             $cache->save(serialize($configData), $cacheKey);
         }
         $data['appConfig'] = $configData;
     }
     return $this->sendResponse($data);
 }
 /**
  * Request nodes from the server
  *
  * @param SS_HTTPRequest $request
  * @return JSONString
  */
 public function childnodes($request)
 {
     $data = array();
     $rootObjectType = 'SiteTree';
     if ($request->param('ID')) {
         $rootObjectType = $request->param('ID');
     }
     if ($request->getVar('search')) {
         return $this->performSearch($request->getVar('search'), $rootObjectType);
     }
     $parentId = $request->getVar('id');
     if (!$parentId) {
         $parentId = $rootObjectType . '-0';
     }
     $selectable = null;
     if ($request->param('OtherID')) {
         $selectable = explode(',', $request->param('OtherID'));
     }
     list($type, $id) = explode('-', $parentId);
     if (!$type || $id < 0) {
         $data = array(0 => array('data' => 'An error has occurred'));
     } else {
         $children = null;
         if ($id == 0) {
             $children = DataObject::get($rootObjectType, 'ParentID = 0');
         } else {
             $object = DataObject::get_by_id($type, $id);
             $children = $this->childrenOfNode($object);
         }
         $data = array();
         if ($children && count($children)) {
             foreach ($children as $child) {
                 if ($child->ID < 0) {
                     continue;
                 }
                 $haskids = $child->numChildren() > 0;
                 $nodeData = array('title' => isset($child->MenuTitle) ? $child->MenuTitle : $child->Title);
                 if ($selectable && !in_array($child->ClassName, $selectable)) {
                     $nodeData['clickable'] = false;
                 }
                 $thumbs = null;
                 if ($child->ClassName == 'Image') {
                     $thumbs = $this->generateThumbnails($child);
                     $nodeData['icon'] = $thumbs['x16'];
                 } else {
                     if (!$haskids) {
                         $nodeData['icon'] = 'frontend-editing/images/page.png';
                     }
                 }
                 $nodeEntry = array('attributes' => array('id' => $child->ClassName . '-' . $child->ID, 'title' => Convert::raw2att($nodeData['title']), 'link' => $child->RelativeLink()), 'data' => $nodeData, 'state' => $haskids ? 'closed' : 'open');
                 if ($thumbs) {
                     $nodeEntry['thumbs'] = $thumbs;
                 }
                 $data[] = $nodeEntry;
             }
         }
     }
     return Convert::raw2json($data);
 }
 /**
  * All requests pass through here and are redirected depending on HTTP verb and params
  * 
  * @param  SS_HTTPRequest        $request    HTTP request
  * @return DataObjec|DataList                DataObject/DataList result or stdClass on error
  */
 public function handleQuery(SS_HTTPRequest $request)
 {
     //get requested model(s) details
     $model = $request->param('ClassName');
     $id = $request->param('ID');
     $response = false;
     $queryParams = $this->parseQueryParameters($request->getVars());
     //validate Model name + store
     if ($model) {
         $model = $this->deSerializer->unformatName($model);
         if (!class_exists($model)) {
             return new RESTfulAPI_Error(400, "Model does not exist. Received '{$model}'.");
         } else {
             //store requested model data and query data
             $this->requestedData['model'] = $model;
         }
     } else {
         //if model missing, stop + return blank object
         return new RESTfulAPI_Error(400, "Missing Model parameter.");
     }
     //check API access rules on model
     if (!RESTfulAPI::api_access_control($model, $request->httpMethod())) {
         return new RESTfulAPI_Error(403, "API access denied.");
     }
     //validate ID + store
     if (($request->isPUT() || $request->isDELETE()) && !is_numeric($id)) {
         return new RESTfulAPI_Error(400, "Invalid or missing ID. Received '{$id}'.");
     } else {
         if ($id !== NULL && !is_numeric($id)) {
             return new RESTfulAPI_Error(400, "Invalid ID. Received '{$id}'.");
         } else {
             $this->requestedData['id'] = $id;
         }
     }
     //store query parameters
     if ($queryParams) {
         $this->requestedData['params'] = $queryParams;
     }
     //map HTTP word to module method
     switch ($request->httpMethod()) {
         case 'GET':
             return $this->findModel($model, $id, $queryParams, $request);
             break;
         case 'POST':
             return $this->createModel($model, $request);
             break;
         case 'PUT':
             return $this->updateModel($model, $id, $request);
             break;
         case 'DELETE':
             return $this->deleteModel($model, $id, $request);
             break;
         default:
             return new RESTfulAPI_Error(403, "HTTP method mismatch.");
             break;
     }
 }
 /**
  * Handle the url parsing for the documentation. In order to make this
  * user friendly this does some tricky things..
  *
  * The urls which should work
  * / - index page
  * /en/sapphire - the index page of sapphire (shows versions)
  * /2.4/en/sapphire - the docs for 2.4 sapphire.
  * /2.4/en/sapphire/installation/
  *
  * @return SS_HTTPResponse
  */
 public function handleRequest(SS_HTTPRequest $request)
 {
     // Workaround for root routing, e.g. Director::addRules(10, array('$Action' => 'DocumentationViewer'))
     $this->Version = $request->param('Action') ? $request->param('Action') : $request->shift();
     $this->Lang = $request->shift();
     $this->ModuleName = $request->shift();
     $this->Remaining = $request->shift(10);
     DocumentationService::load_automatic_registration();
     if (isset($this->Version)) {
         // check to see if its a valid version. If its not a float then its not actually a version
         // its actually a language and it needs to change. So this means we support 2 structures
         // /2.4/en/sapphire/page and
         // /en/sapphire/page which is a link to the latest one
         if (!is_numeric($this->Version) && $this->Version != 'current') {
             array_unshift($this->Remaining, $this->ModuleName);
             // not numeric so /en/sapphire/folder/page
             if (isset($this->Lang) && $this->Lang) {
                 $this->ModuleName = $this->Lang;
             }
             $this->Lang = $this->Version;
             $this->Version = null;
         } else {
             // if(!DocumentationService::is_registered_version($this->Version)) {
             //	$this->httpError(404, 'The requested version could not be found.');
             // }
         }
     }
     if (isset($this->Lang)) {
         // check to see if its a valid language
         // if(!DocumentationService::is_registered_language($this->Lang)) {
         //	$this->httpError(404, 'The requested language could not be found.');
         // }
     } else {
         $this->Lang = 'en';
     }
     // 'current' version mapping
     $module = DocumentationService::is_registered_module($this->ModuleName, null, $this->Lang);
     if ($this->Version && $module) {
         $current = $module->getCurrentVersion();
         if ($this->Version == 'current') {
             $this->Version = $current;
         } else {
             if ($current == $this->Version) {
                 $this->Version = 'current';
                 $link = $this->Link($this->Remaining);
                 $this->response = new SS_HTTPResponse();
                 $this->redirect($link, 301);
                 // permanent redirect
                 return $this->response;
             }
         }
     }
     return parent::handleRequest($request);
 }
 /**
  * @param SS_HTTPRequest $request
  * @return array
  */
 public function compare($request)
 {
     $form = $this->CompareVersionsForm($request->param('VersionID'), $request->param('OtherVersionID'));
     $negotiator = $this->getResponseNegotiator();
     $controller = $this;
     $negotiator->setCallback('CurrentForm', function () use(&$controller, &$form) {
         return $form ? $form->forTemplate() : $controller->renderWith($controller->getTemplatesWithSuffix('_Content'));
     });
     $negotiator->setCallback('default', function () use(&$controller, &$form) {
         return $controller->customise(array('EditForm' => $form))->renderWith($controller->getViewer('show'));
     });
     return $negotiator->respond($request);
 }
 public function show(SS_HTTPRequest $request)
 {
     $root = $this->readFolder($this->Folder);
     $folderPath = "";
     if (is_null($request->param('Action'))) {
         $folder = $root;
     } else {
         foreach ($request->latestParams() as $param) {
             if (!is_null($param)) {
                 $folderPath .= "/" . $param;
             }
         }
         $folder = $this->readFolder($folderPath);
     }
     if (class_exists("BreadcrumbNavigation") && isset($folder)) {
         $parentFolders = explode("/", $folderPath);
         $parents = array_reverse($folder->parentStack());
         for ($i = 1; $i < count($parents); $i++) {
             $parents[$i]->markExpanded();
             $parents[$i]->markOpened();
             if ($i > 0) {
                 $do = new DataObject();
                 $do->Link = $parents[$i]->AbsoluteLink();
                 $do->MenuTitle = $parents[$i]->MenuTitle();
                 if ($i == count($parents) - 1) {
                     $do->isSelf = true;
                 }
                 $this->owner->AddBreadcrumbAfter($do);
             }
         }
         $this->MetaTitle = "Gallery: " . $parents[count($parents) - 1]->MenuTitle();
     }
     return $this->customise(array('Content' => $this->customise(array('RootFolder' => $root, 'CurrentFolder' => $folder))->renderWith('AssetsGalleryMain', 'Page'), 'Form' => ''));
 }
 public function getLocationsByDay(SS_HTTPRequest $request)
 {
     try {
         $query_string = $request->getVars();
         $summit_id = intval($request->param('SUMMIT_ID'));
         $day = strtolower(Convert::raw2sql($query_string['day']));
         $summit = $this->summit_repository->getById($summit_id);
         if (is_null($summit)) {
             throw new NotFoundEntityException('Summit', sprintf(' id %s', $summit_id));
         }
         if (!$summit->isDayBelongs($day)) {
             throw new EntityValidationException(sprintf('day %s does not belongs to summit id %s', $day, $summit_id));
         }
         $response = array('day' => $day, 'summit_id' => intval($summit_id), 'locations' => array());
         foreach ($summit->getTopVenues() as $venue) {
             $class_name = $venue->ClassName;
             if ($class_name != 'SummitVenue' && $class_name != 'SummitExternalLocation' && $class_name != 'SummitHotel') {
                 continue;
             }
             $count = $summit->getPublishedEventsCountByDateLocation($day, $venue);
             array_push($response['locations'], array('id' => intval($venue->ID), 'events_count' => intval($count)));
             if ($class_name == 'SummitVenue') {
                 foreach ($venue->Rooms() as $room) {
                     $count = $summit->getPublishedEventsCountByDateLocation($day, $room);
                     array_push($response['locations'], array('id' => intval($room->ID), 'events_count' => intval($count)));
                 }
             }
         }
         return $this->ok($response);
     } catch (Exception $ex) {
         SS_Log::log($ex->getMessage(), SS_Log::ERR);
         return $this->serverError();
     }
 }
 public function date(SS_HTTPRequest $r)
 {
     $year = $r->param('ID');
     $month = $r->param('OtherID');
     if (!$year) {
         return $this->httpError(404);
     }
     $startDate = $month ? "{$year}-{$month}-01" : "{$year}-01-01";
     if (strtotime($startDate) === false) {
         return $this->httpError(404, 'Invalid date');
     }
     $adder = $month ? '+1 month' : '+1 year';
     $endDate = date('Y-m-d', strtotime($adder, strtotime($startDate)));
     $this->articleList = $this->articleList->filter(array('Date:GreaterThanOrEqual' => $startDate, 'Date:LessThan' => $endDate));
     return array('StartDate' => DBField::create_field('SS_DateTime', $startDate), 'EndDate' => DBField::create_field('SS_DateTime', $endDate));
 }
 public function handleRequest(SS_HTTPRequest $request, DataModel $model)
 {
     $this->pushCurrent();
     $this->urlParams = $request->allParams();
     $this->request = $request;
     $this->response = new SS_HTTPResponse();
     $this->setDataModel($model);
     $urlsegment = $request->param('URLSegment');
     $this->extend('onBeforeInit');
     $this->init();
     $this->extend('onAfterInit');
     // First check products against URL segment
     if ($product = Product::get()->filter(array('URLSegment' => $urlsegment, 'Disabled' => 0))->first()) {
         $controller = Catalogue_Controller::create($product);
     } elseif ($category = ProductCategory::get()->filter('URLSegment', $urlsegment)->first()) {
         $controller = Catalogue_Controller::create($category);
     } else {
         // If CMS is installed
         if (class_exists('ModelAsController')) {
             $controller = ModelAsController::create();
         }
     }
     $result = $controller->handleRequest($request, $model);
     $this->popCurrent();
     return $result;
 }
 public function getMember(SS_HTTPRequest $request)
 {
     try {
         $summit_id = intval($request->param('SUMMIT_ID'));
         $summit = $this->summit_repository->getById($summit_id);
         if (is_null($summit)) {
             throw new NotFoundEntityException('Summit', sprintf(' id %s', $summit_id));
         }
         $member_id = intval($request->param('MEMBER_ID'));
         $member = Member::get_by_id('Member', $member_id);
         if (is_null($member)) {
             throw new NotFoundEntityException('Member', sprintf(' id %s', $member_id));
         }
         $speaker = $member->Speaker()->ID ? $member->Speaker()->toMap() : '';
         $affiliation = '';
         if ($affiliation_obj = $member->getCurrentAffiliation()) {
             $affiliation = $affiliation_obj->toMap();
             $affiliation['Company'] = array('id' => $affiliation_obj->Organization()->ID, 'name' => $affiliation_obj->Organization()->Name);
         }
         echo json_encode(array('speaker' => $speaker, 'affiliation' => $affiliation));
     } catch (NotFoundEntityException $ex2) {
         SS_Log::log($ex2->getMessage(), SS_Log::WARN);
         return $this->notFound($ex2->getMessage());
     } catch (Exception $ex) {
         SS_Log::log($ex->getMessage(), SS_Log::ERR);
         return $this->serverError();
     }
 }
 public function getGoogleMapPin(SS_HTTPRequest $request)
 {
     $color = Convert::raw2sql($request->param('Color'));
     $path = ASSETS_PATH . '/maps/pins';
     // create folder on assets if does not exists ....
     if (!is_dir($path)) {
         mkdir($path, $mode = 0775, $recursive = true);
     }
     // if not get it from google (default)
     $ping_url = "http://chart.apis.google.com/chart?cht=mm&chs=32x32&chco=FFFFFF,{$color},000000&ext=.png";
     $write_2_disk = true;
     if (file_exists($path . '/pin_' . $color . '.jpg')) {
         // if we have the file on assets use it
         $ping_url = $path . '/pin_' . $color . '.jpg';
         $write_2_disk = false;
     }
     $body = file_get_contents($ping_url);
     if ($write_2_disk) {
         file_put_contents($path . '/pin_' . $color . '.jpg', $body);
     }
     $ext = 'jpg';
     $response = new SS_HTTPResponse($body, 200);
     $response->addHeader('Content-Type', 'image/' . $ext);
     return $response;
 }
 /**
  * @uses ModelAsController::getNestedController()
  * @param SS_HTTPRequest $request
  * @param DataModel $model
  * @return SS_HTTPResponse
  */
 public function handleRequest(SS_HTTPRequest $request, DataModel $model)
 {
     // Check Translatable dependency
     if (!class_exists('Translatable') || !SiteTree::has_extension('Translatable') && !SiteTree::has_extension('LanguagePrefixTranslatable')) {
         throw new Exception('Dependency error: the LanguagePrefix module expects the Translatable module.');
     }
     $disablePrefixForDefaultLang = Config::inst()->get('prefixconfig', 'disable_prefix_for_default_lang');
     $firstSegment = $request->param('URLSegment');
     if ($firstSegment) {
         $prefixUsed = $this->setLocale($firstSegment);
         $defaultLocale = Translatable::default_locale();
         $isDefaultLocale = $this->locale == $defaultLocale;
         if ($prefixUsed) {
             if ($isDefaultLocale && $disablePrefixForDefaultLang) {
                 $url = substr($request->getURL(true), strlen($firstSegment));
                 return $this->redirect($url, 301);
             } else {
                 $request->shiftAllParams();
                 $request->shift(1);
             }
         } else {
             /*
              *  if no prefix is used but $disablePrefixForDefaultLang
              *  is set, we go on like nothing happened. Otherwise a
              *  404 is generated. @todo: maybe we should redirect
              *  pages that do actually exist, because this is a bit
              *  harsh?
              */
             //if (!$isDefaultLocale || !$disablePrefixForDefaultLang) {
             //	return $this->showPageNotFound();
             //}
         }
     }
     return parent::handleRequest($request, $model);
 }
 public function show(SS_HTTPRequest $request)
 {
     $shot = ModuleScreenshot::get()->byID($request->param('ID'));
     if (!$shot) {
         return $this->httpError(404, 'That Screen shot could not be found');
     }
     return array('ModuleScreenshot' => $shot);
 }
 public function show(SS_HTTPRequest $r)
 {
     $presentation = Sluggable::get_by_slug('SchedPresentation', $r->param('ID'));
     if (!$presentation) {
         return $this->httpError(404);
     }
     return array('Presentation' => $presentation);
 }
 /**
  * @param SS_HTTPRequest $request
  * @return SS_HTTPResponse
  */
 public function claim(SS_HTTPRequest $request)
 {
     /** @var Order $order */
     $order = Order::get()->byID($request->param('ID'));
     $hash = $request->param('OtherID');
     $realHash = FollowUpEmail::generate_hash($order);
     if (!$order || !$order->exists() || empty($hash) || $hash !== $realHash) {
         $this->httpError(404);
     }
     // Require a login if the order is attached to an account
     if ($order->MemberID && $order->MemberID != Member::currentUserID()) {
         return Security::permissionFailure($this->owner, _t('ShopEmail.NotYourOrder', 'You must log in to access this order.'));
     }
     // Otherwise if all is good, proceed to checkout
     ShoppingCart::singleton()->setCurrent($order);
     return $this->redirect(CheckoutPage::get()->first()->Link());
 }
 protected function getComment(SS_HTTPRequest $request)
 {
     $id = $request->param('ID');
     if ($id != (int) $id && $id > 0) {
         return false;
     }
     return Comment::get()->byId($id);
 }
 /**
  * The default implementation of the controller
  * is to call the serializeData method on its model.
  * JsonDataResponse, SS_HTTPResponse or a string
  * @param SS_HTTPRequest $request
  * @return string|JsonDataResponse|SS_HTTPResponse
  */
 public function getData(SS_HTTPRequest $request)
 {
     $id = (int) $request->param('ID');
     $record = $this->getDataRecord();
     if ($record->hasMethod('getSerializedData')) {
         return $record->getSerializedData($id, $request->getVars())->toJson();
     }
 }
 public function show(SS_HTTPRequest $request)
 {
     $region = Region::get()->byID($request->param('ID'));
     if (!$region) {
         return $this->httpError(404, 'That region could not be found');
     }
     return array('Region' => $region, 'Title' => $region->Title);
 }
Beispiel #19
0
 public function show(SS_HTTPRequest $request)
 {
     $product = Product::get()->byID($request->param('ID'));
     if (!$product) {
         return $this->httpError(404, 'That product could not be found');
     }
     return array('Product' => $product);
 }
 public function handleManagePresentation(SS_HTTPRequest $r)
 {
     if ($presentation = Presentation::get()->byID($r->param('ID'))) {
         $request = PresentationAPI_PresentationRequest::create($presentation, $this);
         return $request->handleRequest($r, DataModel::inst());
     }
     return $this->httpError(404, "Presentation " . $r->param('ID') . " not found");
 }
Beispiel #21
0
 public function viewClass(SS_HTTPRequest $request)
 {
     $class = $request->param('Class');
     if (!class_exists($class)) {
         throw new Exception('CodeViewer->viewClass(): not passed a valid class to view (does the class exist?)');
     }
     return $this->customise(array('Content' => $this->testAnalysis(getClassFile($class))))->renderWith('CodeViewer');
 }
Beispiel #22
0
 public function show(SS_HTTPRequest $request)
 {
     $author = Author::get()->byID($request->param('ID'));
     if (!$author) {
         return $this->httpError(404, 'That author could not be found');
     }
     return array('Author' => $author);
 }
 /**
  * Verify whether the given user/request has a valid HMAC header
  * 
  * HMAC should be calculated as a concatenation of 
  * 
  * service name
  * method called
  * gmdate in format YmdH
  * 
  * So an example before hashing would be
  * 
  * product-getPrice-20130225
  * 
  * The key used for signing should come from the user's "AuthPrivateKey" field
  * 
  * The validator will accept an hour either side of 'now'
  * 
  * @param type $user
  * @param SS_HTTPRequest $request
  * @return boolean
  */
 public function validateHmac($user, SS_HTTPRequest $request)
 {
     $service = $request->param('Service');
     $method = $request->param('Method');
     $hmac = $request->getHeader('X-Silverstripe-Hmac');
     $key = $user->AuthPrivateKey;
     if (!strlen($key)) {
         return false;
     }
     $times = array(gmdate('YmdH', strtotime('-1 hour')), gmdate('YmdH'), gmdate('YmdH', strtotime('+1 hour')));
     foreach ($times as $time) {
         $message = $this->generateHmac(array($service, $method, $time), $key);
         if ($message == $hmac) {
             return true;
         }
     }
     return false;
 }
 public function show(SS_HTTPRequest $request)
 {
     $article_ID = $request->param('ID');
     $article = Article::get()->byID($article_ID);
     if (!$article) {
         return $this->httpError(404, 'That article could not be found');
     }
     return array('Article' => $article, 'Title' => $article->Title);
 }
 /**
  * Method to determine how to handle the request.
  * Uses the currency service to set the active currency
  * @param  \SS_HTTPRequest $request
  * @return array
  */
 public function process(\SS_HTTPRequest $request)
 {
     if ($identifier = $request->param('ID')) {
         if ($this->currencyService->setActiveCurrency(new Identifier($identifier))) {
             return ['Success' => true];
         }
     }
     return ['Success' => false];
 }
 public function one(SS_HTTPRequest $request)
 {
     $this->header();
     $hash = $request->param('hash');
     $data = new ViewableData();
     $data->Error = Error::get()->filter('Hash', $hash)->limit(1)->first();
     $data->ErrorOccurances = ErrorOccurance::get()->filter('Hash', $hash)->sort('Created DESC');
     echo SSViewer::execute_template('ErrorDetail', $data);
 }
 /**
  * @param SS_HTTPRequest $request
  * @return $this
  * @throws SS_HTTPResponse_Exception
  */
 public function index(SS_HTTPRequest $request)
 {
     $action = $request->param('Action');
     if (in_array($action, $this->stat('allowed_actions'))) {
         return $this->{$action}($request);
     }
     $this->httpError(404);
     return $this;
 }
 public function show(SS_HTTPRequest $request)
 {
     $video = ModuleVideo::get()->byID($request->param('ID'));
     if (!$video) {
         return $this->httpError(404, 'That Video could not be found');
     }
     return array('Video' => $video);
     // Variable to use in template -> $Video
 }
 /**
  * Read ShortURL key from request and redirect to the full URL from the matching
  * CheckfrontShortenedURL record.
  *
  * @param SS_HTTPRequest $request
  *
  * @return SS_HTTPResponse
  */
 public function redirect(SS_HTTPRequest $request)
 {
     if ($shortURL = $request->param('ShortURL')) {
         if ($fullURL = CheckfrontShortenedURL::get_url_by_key($shortURL)) {
             return parent::redirect($fullURL);
         }
     }
     $this->httpError("Bad URL");
 }
 /**
  * @param SS_HTTPRequest $request
  *
  * @return string|HTMLText
  */
 public function preview(SS_HTTPRequest $request)
 {
     $key = $request->param('Key');
     $token = $request->param('Token');
     /**
      * @var ShareToken $shareToken
      */
     $shareToken = ShareToken::get()->filter('token', $token)->first();
     if (!$shareToken) {
         return $this->errorPage();
     }
     $page = Versioned::get_one_by_stage('SiteTree', 'Stage', sprintf('"SiteTree"."ID" = \'%d\'', $shareToken->PageID));
     $latest = Versioned::get_latest_version('SiteTree', $shareToken->PageID);
     $controller = $this->getControllerFor($page);
     if (!$shareToken->isExpired() && $page->generateKey($shareToken->Token) === $key) {
         Requirements::css(SHAREDRAFTCONTENT_DIR . '/css/top-bar.css');
         // Temporarily un-secure the draft site and switch to draft
         $oldSecured = Session::get('unsecuredDraftSite');
         $oldMode = Versioned::get_reading_mode();
         $restore = function () use($oldSecured, $oldMode) {
             Session::set('unsecuredDraftSite', $oldSecured);
             Versioned::set_reading_mode($oldMode);
         };
         // Process page inside an unsecured draft container
         try {
             Session::set('unsecuredDraftSite', true);
             Versioned::reading_stage('Stage');
             // Create mock request; Simplify request to single top level reqest
             $pageRequest = new SS_HTTPRequest('GET', $page->URLSegment);
             $pageRequest->match('$URLSegment//$Action/$ID/$OtherID', true);
             $rendered = $controller->handleRequest($pageRequest, $this->model);
             // Render draft heading
             $data = new ArrayData(array('Page' => $page, 'Latest' => $latest));
             $include = (string) $data->renderWith('Includes/TopBar');
         } catch (Exception $ex) {
             $restore();
             throw $ex;
         }
         $restore();
         return str_replace('</body>', $include . '</body>', (string) $rendered->getBody());
     } else {
         return $this->errorPage();
     }
 }