Alpha Framework alpha--controller
[ class tree: alpha--controller ] [ index: alpha--controller ] [ all elements ]

Source for file ViewArticleFile.php

Documentation is available at ViewArticleFile.php

  1. <?php
  2.  
  3. // include the config file
  4. if(!isset($config)) {
  5.     require_once '../util/AlphaConfig.inc';
  6.     $config AlphaConfig::getInstance();
  7. }
  8.  
  9. require_once $config->get('sysRoot').'alpha/controller/ViewArticle.php';
  10. require_once $config->get('sysRoot').'alpha/exceptions/FileNotFoundException.inc';
  11.  
  12. /**
  13.  * 
  14.  * Controller used to display a Markdown version of a page article where the name of the
  15.  * .text file containing the Markdown/HTML content is provided
  16.  * 
  17.  * @package alpha::controller
  18.  * @since 1.0
  19.  * @author John Collins <dev@alphaframework.org>
  20.  * @version $Id: ViewArticleFile.php 1341 2011-03-17 15:02:02Z johnc $
  21.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  22.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  23.  *  All rights reserved.
  24.  * 
  25.  *  <pre>
  26.  *  Redistribution and use in source and binary forms, with or
  27.  *  without modification, are permitted provided that the
  28.  *  following conditions are met:
  29.  * 
  30.  *  * Redistributions of source code must retain the above
  31.  *    copyright notice, this list of conditions and the
  32.  *    following disclaimer.
  33.  *  * Redistributions in binary form must reproduce the above
  34.  *    copyright notice, this list of conditions and the
  35.  *    following disclaimer in the documentation and/or other
  36.  *    materials provided with the distribution.
  37.  *  * Neither the name of the Alpha Framework nor the names
  38.  *    of its contributors may be used to endorse or promote
  39.  *    products derived from this software without specific
  40.  *    prior written permission.
  41.  *   
  42.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  43.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  44.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  45.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  46.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  47.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  48.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  49.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  50.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  51.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  52.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  53.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  54.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  55.  *  </pre>
  56.  *  
  57.  */
  58. class ViewArticleFile extends ViewArticle {
  59.     /**
  60.      * Trace logger
  61.      * 
  62.      * @var Logger 
  63.      * @since 1.0
  64.      */
  65.     private static $logger null;
  66.                                     
  67.     /**
  68.      * Handle GET requests
  69.      * 
  70.      * @param array $params 
  71.      * @since 1.0
  72.      * @throws ResourceNotFoundException
  73.      */
  74.     public function doGET($params{
  75.         self::$logger new Logger('ViewArticleFile');
  76.             
  77.         global $config;
  78.         
  79.         try {
  80.             // ensure that a title is provided
  81.             if (isset($params['file'])) {
  82.                 $title basename($params['file']);
  83.                 $title str_replace('_'' '$title);
  84.                 $title str_replace('.text'''$title);
  85.             }else{
  86.                 throw new IllegalArguementException('Could not load the article as a file name was not supplied!');
  87.             }
  88.             
  89.             $this->BO = new ArticleObject();
  90.             $this->BO->set('title'$title);
  91.             // just checking to see if the file path is absolute or not
  92.             if(substr($params['file']01== '/')
  93.                 $this->BO->loadContentFromFile($params['file']);
  94.             else
  95.                 $this->BO->loadContentFromFile($config->get('sysRoot').'alpha/docs/'.$params['file']);
  96.             
  97.         }catch(IllegalArguementException $e{
  98.             self::$logger->error($e->getMessage());
  99.             throw new ResourceNotFoundException($e->getMessage());
  100.         }catch(FileNotFoundException $e{
  101.             self::$logger->warn($e->getMessage());
  102.             throw new ResourceNotFoundException('Failed to load the requested article from the file system!');
  103.         }
  104.  
  105.         $this->setTitle($this->BO->get('title'));
  106.         
  107.         $BOView AlphaView::getInstance($this->BO);
  108.         
  109.         echo AlphaView::displayPageHead($thisfalse);
  110.         
  111.         echo $BOView->markdownView();
  112.         
  113.         echo AlphaView::displayPageFoot($this);
  114.     }
  115.  
  116.     /**
  117.      * Overidding the parent here as we want an empty footer on file-based articles
  118.      * 
  119.      * @return string 
  120.      * @since 1.0
  121.      */
  122.     public function before_displayPageFoot_callback({
  123.         return '';
  124.     }
  125. }
  126.  
  127. // now build the new controller
  128. if(basename($_SERVER['PHP_SELF']== 'ViewArticleFile.php'{
  129.     $controller new ViewArticleFile();
  130.     
  131.     if(!empty($_POST)) {            
  132.         $controller->doPOST($_REQUEST);
  133.     }else{
  134.         $controller->doGET($_GET);
  135.     }
  136. }
  137.  
  138. ?>

Documentation generated on Thu, 17 Mar 2011 16:45:05 +0000 by phpDocumentor 1.4.3