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 1469 2011-12-13 20:20:32Z 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 file path is provided
  81.             if (!isset($params['file'])) {
  82.                 throw new IllegalArguementException('Could not load the article as a file name was not supplied!');
  83.             }
  84.             
  85.             $this->BO = new ArticleObject();
  86.  
  87.             // just checking to see if the file path is absolute or not
  88.             if(substr($params['file']01== '/')
  89.                 $this->BO->loadContentFromFile($params['file']);
  90.             else
  91.                 $this->BO->loadContentFromFile($config->get('sysRoot').'alpha/docs/'.$params['file']);
  92.             
  93.         }catch(IllegalArguementException $e{
  94.             self::$logger->error($e->getMessage());
  95.             throw new ResourceNotFoundException($e->getMessage());
  96.         }catch(FileNotFoundException $e{
  97.             self::$logger->warn($e->getMessage().' File path is ['.$params['file'].']');
  98.             throw new ResourceNotFoundException('Failed to load the requested article from the file system!');
  99.         }
  100.  
  101.         $this->setTitle($this->BO->get('title'));
  102.         
  103.         $BOView AlphaView::getInstance($this->BO);
  104.         
  105.         echo AlphaView::displayPageHead($thisfalse);
  106.         
  107.         echo $BOView->markdownView();
  108.         
  109.         echo AlphaView::displayPageFoot($this);
  110.     }
  111.  
  112.     /**
  113.      * Overidding the parent here as we want an empty footer on file-based articles
  114.      * 
  115.      * @return string 
  116.      * @since 1.0
  117.      */
  118.     public function before_displayPageFoot_callback({
  119.         return '';
  120.     }
  121. }
  122.  
  123. // now build the new controller
  124. if(basename($_SERVER['PHP_SELF']== 'ViewArticleFile.php'{
  125.     $controller new ViewArticleFile();
  126.     
  127.     if(!empty($_POST)) {            
  128.         $controller->doPOST($_REQUEST);
  129.     }else{
  130.         $controller->doGET($_GET);
  131.     }
  132. }
  133.  
  134. ?>

Documentation generated on Tue, 13 Dec 2011 20:27:47 +0000 by phpDocumentor 1.4.3