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

Source for file ViewArticleTitle.php

Documentation is available at ViewArticleTitle.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.  
  11. /**
  12.  * 
  13.  * Controller used to display a Markdown version of a page article where the title is provided in GET vars
  14.  * 
  15.  * @package alpha::controller
  16.  * @since 1.0
  17.  * @author John Collins <dev@alphaframework.org>
  18.  * @version $Id: ViewArticleTitle.php 1343 2011-03-17 16:10:07Z johnc $
  19.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  20.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  21.  *  All rights reserved.
  22.  * 
  23.  *  <pre>
  24.  *  Redistribution and use in source and binary forms, with or
  25.  *  without modification, are permitted provided that the
  26.  *  following conditions are met:
  27.  * 
  28.  *  * Redistributions of source code must retain the above
  29.  *    copyright notice, this list of conditions and the
  30.  *    following disclaimer.
  31.  *  * Redistributions in binary form must reproduce the above
  32.  *    copyright notice, this list of conditions and the
  33.  *    following disclaimer in the documentation and/or other
  34.  *    materials provided with the distribution.
  35.  *  * Neither the name of the Alpha Framework nor the names
  36.  *    of its contributors may be used to endorse or promote
  37.  *    products derived from this software without specific
  38.  *    prior written permission.
  39.  *   
  40.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  41.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  42.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  43.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  44.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  45.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  46.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  47.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  48.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  49.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  50.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  51.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  52.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  53.  *  </pre>
  54.  *  
  55.  */
  56. class ViewArticleTitle extends ViewArticle {
  57.     /**
  58.      * Trace logger
  59.      * 
  60.      * @var Logger 
  61.      */
  62.     private static $logger null;
  63.     
  64.     /**
  65.      * Constructor to set up the object
  66.      * 
  67.      * @since 1.0
  68.      */
  69.     public function __construct({
  70.         self::$logger new Logger('ViewArticleTitle');
  71.         self::$logger->debug('>>__construct()');
  72.         
  73.         global $config;
  74.         
  75.         // ensure that the super class constructor is called, indicating the rights group
  76.         parent::__construct('Public');
  77.         
  78.         self::$logger->debug('<<__construct');
  79.     }
  80.                                     
  81.     /**
  82.      * Handle GET requests
  83.      * 
  84.      * @param array $params 
  85.      * @since 1.0
  86.      * @throws ResourceNotFoundException
  87.      */
  88.     public function doGET($params{
  89.         self::$logger->debug('>>doGET($params=['.var_export($paramstrue).'])');
  90.         
  91.         global $config;
  92.         
  93.         try {
  94.             // it may have already been loaded by a doPOST call
  95.             if($this->BO->isTransient()) {
  96.                 // ensure that a title is provided
  97.                 if (isset($params['title'])) {
  98.                     $title str_replace('_'' '$params['title']);
  99.                 }else{
  100.                     throw new IllegalArguementException('Could not load the article as a title was not supplied!');
  101.                 }
  102.                 
  103.                 $this->BO = new ArticleObject();
  104.                 $this->BO->set('title'$title);
  105.                 // this is effectively a lazy-load
  106.                 $this->BO->loadByAttribute('title'$titlefalsearray('OID''version_num''created_ts''updated_ts''author''published'));
  107.                 if(!$this->BO->get('published'))
  108.                     throw new BONotFoundException('Attempted to load an article which is not published yet');
  109.                 $this->BO->set('tags'$this->BO->getOID());
  110.             }
  111.                         
  112.         }catch(IllegalArguementException $e{
  113.             self::$logger->warn($e->getMessage());
  114.             throw new ResourceNotFoundException('The file that you have requested cannot be found!');
  115.         }catch(BONotFoundException $e{
  116.             self::$logger->warn($e->getMessage());
  117.             throw new ResourceNotFoundException('The article that you have requested cannot be found!');
  118.         }
  119.         
  120.         $this->setTitle($this->BO->get('title'));
  121.         $this->setDescription($this->BO->get('description'));
  122.         
  123.         $BOView AlphaView::getInstance($this->BO);
  124.         
  125.         echo AlphaView::displayPageHead($this);
  126.         
  127.         echo $BOView->markdownView();
  128.         
  129.         echo AlphaView::displayPageFoot($this);
  130.         
  131.         self::$logger->debug('<<doGET');
  132.     }    
  133. }
  134.  
  135. // now build the new controller
  136. if(basename($_SERVER['PHP_SELF']== 'ViewArticleTitle.php'{
  137.     $controller new ViewArticleTitle();
  138.     
  139.     if(!empty($_POST)) {            
  140.         $controller->doPOST($_REQUEST);
  141.     }else{
  142.         $controller->doGET($_GET);
  143.     }
  144. }
  145.  
  146. ?>

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