      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 printer-friendly version of an 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: ViewArticlePrint.php 1624 2012-12-21 12:17:55Z 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 ViewArticlePrint extends ViewArticle {
     57:     /**
     58:      * Trace logger
     59:      *
     60:      * @var Logger
     61:      * @since 1.0
     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('ViewArticlePrint');
     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($params, true).'])');
     91:
     92:         global $config;
     93:
     94:         try {
     95:             // ensure that a title is provided
     96:             if (isset($params['title'])) {
     97:                 $title = str_replace($config->get('cms.url.title.separator'), ' ', $params['title']);
     98:             }else{
     99:                 throw new IllegalArguementException('Could not load the article as a title was not supplied!');
    100:             }
    101:
    102:             $this->BO = new ArticleObject();
    103:             $this->BO->loadByAttribute('title', $title);
    104:
    105:             AlphaDAO::disconnect();
    106:
    107:         }catch(IllegalArguementException $e) {
    108:             self::$logger->error($e->getMessage());
    109:             throw new ResourceNotFoundException($e->getMessage());
    110:         }catch(BONotFoundException $e) {
    111:             self::$logger->error($e->getMessage());
    112:             throw new ResourceNotFoundException($e->getMessage());
    113:         }
    114:
    115:         $this->setTitle($this->BO->get('title'));
    116:
    117:         $BOView = AlphaView::getInstance($this->BO);
    118:
    119:         // disabling force-frames
    120:         $_GET['no-forceframe'] = true;
    121:
    122:         echo AlphaView::displayPageHead($this);
    123:
    124:         echo $BOView->markdownView();
    125:
    126:         echo AlphaView::displayPageFoot($this);
    127:
    128:         self::$logger->debug('<<doGET');
    129:     }
    130:
    131:     /**
    132:      * Handle POST requests
    133:      *
    134:      * @param array $params
    135:      * @since 1.0
    136:      */
    137:     public function doPOST($params) {
    138:         self::$logger->debug('>>doPOST($params=['.var_export($params, true).'])');
    139:
    140:         self::$logger->debug('<<doPOST');
    141:     }
    142:
    143:     /**
    144:      * Injects the print CSS into the page header
    145:      *
    146:      * @return string
    147:      * @since 1.0
    148:      */
    149:     public function during_displayPageHead_callback() {
    150:         global $config;
    151:
    152:         return '<link rel="StyleSheet" type="text/css" href="'.$config->get('app.url').'alpha/css/print.css">';
    153:     }
    154:
    155:     /**
    156:      * Callback used to render footer content, including comments, votes and print/PDF buttons when
    157:      * enabled to do so.
    158:      *
    159:      * @return string
    160:      * @since 1.0
    161:      */
    162:     public function before_displayPageFoot_callback() {
    163:         global $config;
    164:
    165:         $rating = $this->BO->getArticleScore();
    166:         $votes = $this->BO->getArticleVotes();
    167:
    168:         $html = '<p>Article URL: <a href="'.$this->BO->get('URL').'">'.$this->BO->get('URL').'</a><br>';
    169:         $html .= 'Title: '.$this->BO->get('title').'<br>';
    170:         $html .= 'Author: '.$this->BO->get('author').'<br>';
    171:         $html .= $config->get('cms.footer').'</p>';
    172:
    173:         return $html;
    174:     }
    175: }
    176:
    177: // now build the new controller
    178: if(basename($_SERVER['PHP_SELF']) == 'ViewArticlePrint.php') {
    179:     $controller = new ViewArticlePrint();
    180:
    181:     if(!empty($_POST)) {
    182:         $controller->doPOST($_REQUEST);
    183:     }else{
    184:         $controller->doGET($_GET);
    185:     }
    186: }
    187:
    188: ?>