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

Source for file PreviewArticle.php

Documentation is available at PreviewArticle.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/util/Logger.inc';
  10. require_once $config->get('sysRoot').'alpha/util/MarkdownFacade.inc';
  11. require_once $config->get('sysRoot').'alpha/controller/AlphaController.inc';
  12. require_once $config->get('sysRoot').'alpha/controller/AlphaControllerInterface.inc';
  13. require_once $config->get('sysRoot').'alpha/model/ArticleObject.inc';
  14.  
  15. /**
  16.  *
  17.  * Article for previewing Markdown content in the markItUp TextBox widget
  18.  * 
  19.  * @package alpha::controller
  20.  * @since 1.0
  21.  * @author John Collins <dev@alphaframework.org>
  22.  * @version $Id: PreviewArticle.php 1341 2011-03-17 15:02:02Z johnc $
  23.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  24.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  25.  *  All rights reserved.
  26.  * 
  27.  *  <pre>
  28.  *  Redistribution and use in source and binary forms, with or
  29.  *  without modification, are permitted provided that the
  30.  *  following conditions are met:
  31.  * 
  32.  *  * Redistributions of source code must retain the above
  33.  *    copyright notice, this list of conditions and the
  34.  *    following disclaimer.
  35.  *  * Redistributions in binary form must reproduce the above
  36.  *    copyright notice, this list of conditions and the
  37.  *    following disclaimer in the documentation and/or other
  38.  *    materials provided with the distribution.
  39.  *  * Neither the name of the Alpha Framework nor the names
  40.  *    of its contributors may be used to endorse or promote
  41.  *    products derived from this software without specific
  42.  *    prior written permission.
  43.  *   
  44.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  45.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  46.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  47.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  48.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  49.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  50.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  51.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  52.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  53.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  54.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  55.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  56.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  57.  *  </pre>
  58.  *  
  59.  */
  60.     /**
  61.      * Trace logger
  62.      * 
  63.      * @var Logger 
  64.      * @since 1.0
  65.      */
  66.     private static $logger null;
  67.     
  68.     /**
  69.      * Constructor to set up the object
  70.      * 
  71.      * @since 1.0
  72.      */
  73.     public function __construct({
  74.         self::$logger new Logger('PreviewArticle');
  75.         self::$logger->debug('>>__construct()');
  76.         
  77.         // ensure that the super class constructor is called, indicating the rights group
  78.         parent::__construct('Public');
  79.         
  80.         // set up the title and meta details
  81.         $this->setTitle('Preview');
  82.         $this->setDescription('Preview page.');
  83.         $this->setKeywords('Preview,page');
  84.         
  85.         self::$logger->debug('<<__construct');
  86.     }    
  87.         
  88.     /**
  89.      * Handle GET requests
  90.      * 
  91.      * @param array $params 
  92.      * @since 1.0
  93.      */
  94.     public function doGET($params{
  95.         self::$logger->debug('>>doGET($params=['.var_export($paramstrue).'])');
  96.         
  97.         self::$logger->debug('<<doGET');
  98.     }    
  99.     
  100.     /**
  101.      * Handle POST requests
  102.      * 
  103.      * @param array $params 
  104.      * @since 1.0
  105.      * @throws IllegalArguementException
  106.      */
  107.     public function doPOST($params{
  108.         self::$logger->debug('>>doPOST($params=['.var_export($paramstrue).'])');
  109.         
  110.         global $config;
  111.         
  112.         if(isset($params['data'])) {
  113.             // allow the consumer to optionally indicate another BO than ArticleObject
  114.             if(isset($params['bo'])) {
  115.                 AlphaDAO::loadClassDef($params['bo']);
  116.                 $temp new $params['bo'];
  117.             }else{
  118.                 $temp new ArticleObject();
  119.             }
  120.             
  121.             $temp->set('content'$params['data']);
  122.             
  123.             if(isset($params['oid']))
  124.                 $temp->set('OID'$params['oid']);
  125.             
  126.             $parser new MarkdownFacade($tempfalse);
  127.         
  128.             // render a simple HTML header
  129.             echo '<html>';
  130.             echo '<head>';                    
  131.             echo '<link rel="StyleSheet" type="text/css" href="'.$config->get('sysURL').'alpha/lib/jquery/ui/themes/'.$config->get('sysTheme').'/ui.all.css">';
  132.             echo '<link rel="StyleSheet" type="text/css" href="'.$config->get('sysURL').'alpha/css/alpha.css">';
  133.             echo '<link rel="StyleSheet" type="text/css" href="'.$config->get('sysURL').'config/css/overrides.css">';
  134.             echo '</head>';
  135.             echo '<body>';
  136.                 
  137.             // transform text using parser.
  138.             echo $parser->getContent();
  139.             
  140.             echo '</body>';
  141.             echo '</html>';
  142.         }else{
  143.             throw new IllegalArguementException('No Markdown data provided in the POST data!');
  144.         }
  145.         self::$logger->debug('<<doPOST');
  146.     }
  147. }
  148.  
  149. // now build the new controller if this file is called directly
  150. if ('PreviewArticle.php' == basename($_SERVER['PHP_SELF'])) {
  151.     $controller new PreviewArticle();
  152.     
  153.     if(!empty($_POST)) {            
  154.         $controller->doPOST($_REQUEST);
  155.     }else{
  156.         $controller->doGET($_GET);
  157.     }
  158. }
  159.  
  160. ?>

Documentation generated on Thu, 17 Mar 2011 16:44:38 +0000 by phpDocumentor 1.4.3