コード例 #1
0
 /**
  * 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);
 }
コード例 #2
0
 /**
  * Generate an array of every single documentation page installed on the system. 
  *
  * @return DataObjectSet
  */
 public static function get_all_documentation_pages()
 {
     DocumentationService::load_automatic_registration();
     $modules = DocumentationService::get_registered_entities();
     $output = new DataObjectSet();
     if ($modules) {
         foreach ($modules as $module) {
             foreach ($module->getVersions() as $version) {
                 try {
                     $pages = DocumentationService::get_pages_from_folder($module, false, true, $version);
                     if ($pages) {
                         foreach ($pages as $page) {
                             $output->push($page);
                         }
                     }
                 } catch (Exception $e) {
                     user_error($e, E_USER_WARNING);
                 }
             }
         }
     }
     return $output;
 }
コード例 #3
0
 /**
  * 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)
 {
     // if we submitted a form, let that pass
     if (!$request->isGET() || isset($_GET['action_results'])) {
         return parent::handleRequest($request);
     }
     $firstParam = $request->param('Action') ? $request->param('Action') : $request->shift();
     $secondParam = $request->shift();
     $thirdParam = $request->shift();
     $this->Remaining = $request->shift(10);
     DocumentationService::load_automatic_registration();
     // if no params passed at all then it's the homepage
     if (!$firstParam && !$secondParam && !$thirdParam) {
         return parent::handleRequest($request);
     }
     if ($firstParam) {
         // allow assets
         if ($firstParam == "assets") {
             return parent::handleRequest($request);
         }
         // check for permalinks
         if ($link = DocumentationPermalinks::map($firstParam)) {
             // the first param is a shortcode for a page so redirect the user to
             // the short code.
             $this->response = new SS_HTTPResponse();
             $this->redirect($link, 301);
             // 301 permanent redirect
             return $this->response;
         }
         // check to see if the module is a valid module. If it isn't, then we
         // need to throw a 404.
         if (!DocumentationService::is_registered_entity($firstParam)) {
             return $this->throw404();
         }
         $this->entity = $firstParam;
         $this->language = $secondParam;
         if (isset($thirdParam) && (is_numeric($thirdParam) || in_array($thirdParam, array('master', 'trunk')))) {
             $this->version = $thirdParam;
         } else {
             // current version so store one area para
             array_unshift($this->Remaining, $thirdParam);
             $this->version = false;
         }
     }
     // 'current' version mapping
     $entity = DocumentationService::is_registered_entity($this->entity, null, $this->getLang());
     if ($entity) {
         $current = $entity->getStableVersion();
         $version = $this->getVersion();
         if (!$version) {
             $this->version = $current;
         }
         // Check if page exists, otherwise return 404
         if (!$this->locationExists()) {
             return $this->throw404();
         }
         return parent::handleRequest($request);
     }
     return $this->throw404();
 }