      1: <?php
      2:
      3: // include the config file
      4: if(!isset($config)) {
      5:     require_once '../util/AlphaConfig.inc';
      6:     $config = AlphaConfig::getInstance();
      7:
      8:     require_once $config->get('app.root').'alpha/util/AlphaAutoLoader.inc';
      9: }
     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 1577 2012-10-24 22:21:51Z alphadevx $
     19:  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
     20:  * @copyright Copyright (c) 2012, 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($params, true).'])');
     90:
     91:         global $config;
     92:
     93:         $KDP = new AlphaKPI('viewarticle');
     94:
     95:         try {
     96:             // it may have already been loaded by a doPOST call
     97:             if($this->BO->isTransient()) {
     98:                 // ensure that a title is provided
     99:                 if (isset($params['title'])) {
    100:                     $title = str_replace($config->get('cms.url.title.separator'), ' ', $params['title']);
    101:                 }else{
    102:                     throw new IllegalArguementException('Could not load the article as a title was not supplied!');
    103:                 }
    104:
    105:                 $this->BO = new ArticleObject();
    106:                 $this->BO->set('title', $title);
    107:                 $this->BO->loadByAttribute('title', $title, false, array('OID', 'version_num', 'created_ts', 'updated_ts', 'author', 'published', 'content', 'headerContent'));
    108:                 if(!$this->BO->get('published'))
    109:                     throw new BONotFoundException('Attempted to load an article which is not published yet');
    110:                 $this->BO->set('tags', $this->BO->getOID());
    111:             }
    112:
    113:         }catch(IllegalArguementException $e) {
    114:             self::$logger->warn($e->getMessage());
    115:             throw new ResourceNotFoundException('The file that you have requested cannot be found!');
    116:         }catch(BONotFoundException $e) {
    117:             self::$logger->warn($e->getMessage());
    118:             throw new ResourceNotFoundException('The article that you have requested cannot be found!');
    119:         }
    120:
    121:         $this->setTitle($this->BO->get('title'));
    122:         $this->setDescription($this->BO->get('description'));
    123:
    124:         $BOView = AlphaView::getInstance($this->BO);
    125:
    126:         echo AlphaView::displayPageHead($this);
    127:
    128:         echo $BOView->markdownView();
    129:
    130:         echo AlphaView::displayPageFoot($this);
    131:
    132:         $KDP->log();
    133:
    134:         self::$logger->debug('<<doGET');
    135:     }
    136: }
    137:
    138: // now build the new controller
    139: if(basename($_SERVER['PHP_SELF']) == 'ViewArticleTitle.php') {
    140:     $controller = new ViewArticleTitle();
    141:
    142:     if(!empty($_POST)) {
    143:         $controller->doPOST($_REQUEST);
    144:     }else{
    145:         $controller->doGET($_GET);
    146:     }
    147: }
    148:
    149: ?>