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

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