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

Source for file CreateArticle.php

Documentation is available at CreateArticle.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/AlphaController.inc';
  10. require_once $config->get('sysRoot').'alpha/controller/EditArticle.php';
  11. require_once $config->get('sysRoot').'alpha/view/AlphaView.inc';
  12. require_once $config->get('sysRoot').'alpha/model/ArticleObject.inc';
  13. require_once $config->get('sysRoot').'alpha/controller/AlphaControllerInterface.inc';
  14.  
  15. /**
  16.  * 
  17.  * Controller used to create a new article in the database
  18.  * 
  19.  * @package alpha::controller
  20.  * @since 1.0
  21.  * @author John Collins <dev@alphaframework.org>
  22.  * @version $Id: CreateArticle.php 1453 2011-12-04 15:12:54Z 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. class CreateArticle extends AlphaController implements AlphaControllerInterface {
  61.     /**
  62.      * The new article to be created
  63.      * 
  64.      * @var ArticleObject 
  65.      * @since 1.0
  66.      */
  67.     protected $BO;
  68.                                 
  69.     /**
  70.      * Trace logger
  71.      * 
  72.      * @var Logger 
  73.      * @since 1.0
  74.      */
  75.     private static $logger null;
  76.                                 
  77.     /**
  78.      * constructor to set up the object
  79.      * 
  80.      * @since 1.0
  81.      */
  82.     public function __construct({
  83.         self::$logger new Logger('CreateArticle');
  84.         self::$logger->debug('>>__construct()');
  85.         
  86.         global $config;
  87.         
  88.         // ensure that the super class constructor is called, indicating the rights group
  89.         parent::__construct('Standard');
  90.         
  91.         $this->BO = new ArticleObject();
  92.         
  93.         // set up the title and meta details
  94.         $this->setTitle('Create a new Article');
  95.         $this->setDescription('Page to create a new article.');
  96.         $this->setKeywords('create,new,article');
  97.         
  98.         self::$logger->debug('<<__construct');
  99.     }
  100.  
  101.     /**
  102.      * Handle GET requests
  103.      * 
  104.      * @param array $params 
  105.      * @since 1.0
  106.      */
  107.     public function doGET($params{
  108.         self::$logger->debug('>>doGET($params=['.var_export($paramstrue).'])');
  109.         
  110.         echo AlphaView::displayPageHead($this);
  111.         
  112.         $view AlphaView::getInstance($this->BO);
  113.         
  114.         echo $view->createView();        
  115.         
  116.         echo AlphaView::displayPageFoot($this);
  117.         
  118.         self::$logger->debug('<<doGET');
  119.     }
  120.     
  121.     /**
  122.      * Method to handle POST requests
  123.      * 
  124.      * @param array $params 
  125.      * @throws SecurityException
  126.      * @since 1.0
  127.      */
  128.     public function doPOST($params{
  129.         self::$logger->debug('>>doPOST($params=['.var_export($paramstrue).'])');
  130.         
  131.         global $config;
  132.         
  133.         try {
  134.             // check the hidden security fields before accepting the form POST data
  135.             if(!$this->checkSecurityFields())
  136.                 throw new SecurityException('This page cannot accept post data from remote servers!');
  137.             
  138.             $this->BO = new ArticleObject();
  139.         
  140.             if (isset($params['createBut'])) {            
  141.                 // populate the transient object from post data
  142.                 $this->BO->populateFromPost();
  143.                     
  144.                 $this->BO->save();
  145.  
  146.                 AlphaDAO::disconnect();
  147.     
  148.                 try {
  149.                     if ($this->getNextJob(!= '')                    
  150.                         header('Location: '.$this->getNextJob());
  151.                     else                    
  152.                         header('Location: '.FrontController::generateSecureURL('act=Detail&bo='.get_class($this->BO).'&oid='.$this->BO->getID()));
  153.                 }catch(AlphaException $e{
  154.                         self::$logger->error($e->getTraceAsString());
  155.                         echo '<p class="error"><br>Error creating the new article, check the log!</p>';
  156.                 }
  157.             }
  158.             
  159.             if (isset($params['cancelBut'])) {
  160.                 header('Location: '.FrontController::generateSecureURL('act=ListBusinessObjects'));
  161.             }
  162.         }catch(SecurityException $e{
  163.             echo AlphaView::displayPageHead($this);
  164.             echo '<p class="error"><br>'.$e->getMessage().'</p>';                                
  165.             self::$logger->warn($e->getMessage());
  166.         }
  167.         
  168.         self::$logger->debug('<<doPOST');
  169.     }
  170.     
  171.     /**
  172.      * Renders the Javascript required in the header by markItUp!
  173.      *
  174.      * @return string 
  175.      * @since 1.0
  176.      */
  177.     public function during_displayPageHead_callback({
  178.         global $config;
  179.         
  180.         $html '
  181.             <script type="text/javascript">
  182.             var previewURL = "'.FrontController::generateSecureURL('act=PreviewArticle&bo=ArticleObject').'";
  183.             </script>            
  184.             <script type="text/javascript" src="'.$config->get('sysURL').'alpha/lib/markitup/jquery.markitup.js"></script>
  185.             <script type="text/javascript" src="'.$config->get('sysURL').'alpha/lib/markitup/sets/markdown/set.js"></script>
  186.             <link rel="stylesheet" type="text/css" href="'.$config->get('sysURL').'alpha/lib/markitup/skins/simple/style.css" />
  187.             <link rel="stylesheet" type="text/css" href="'.$config->get('sysURL').'alpha/lib/markitup/sets/markdown/style.css" />
  188.             <script type="text/javascript">
  189.             $(document).ready(function() {
  190.                 $("#text_field_content_0").markItUp(mySettings);
  191.                 
  192.                 var dialogCoords = [(screen.width/2)-400, (screen.height/2)-300];
  193.                 
  194.                 var dialogOpts = {
  195.                     title: "Help Page",
  196.                     modal: true,
  197.                     resizable: false,
  198.                     draggable: false,
  199.                     autoOpen: false,
  200.                     height: 400,
  201.                     width: 800,
  202.                     position: dialogCoords,
  203.                     buttons: {},
  204.                     open: function() {
  205.                         //display correct dialog content
  206.                         $("#helpPage").load("'.FrontController::generateSecureURL('act=ViewArticleFile&file=Markdown_Help.text').'");
  207.                     },
  208.                     close: function() {
  209.                     
  210.                         $("#helpPage").dialog(dialogOpts);
  211.                         
  212.                         $(".markItUpButton15").click(
  213.                             function (){
  214.                                 $("#helpPage").dialog("open");
  215.                                 return false;
  216.                             }
  217.                         );
  218.                     }
  219.                 };
  220.                     
  221.                 $("#helpPage").dialog(dialogOpts);
  222.     
  223.                 $(".markItUpButton15").click(
  224.                     function (){
  225.                         $("#helpPage").dialog("open");
  226.                         return false;
  227.                     }
  228.                 );
  229.             });
  230.             </script>';
  231.         
  232.         return $html;
  233.     }
  234. }
  235.  
  236. // now build the new controller
  237. if(basename($_SERVER['PHP_SELF']== 'CreateArticle.php'{
  238.     $controller new CreateArticle();
  239.     
  240.     if(!empty($_POST)) {            
  241.         $controller->doPOST($_REQUEST);
  242.     }else{
  243.         $controller->doGET($_GET);
  244.     }
  245. }
  246.  
  247. ?>

Documentation generated on Tue, 13 Dec 2011 20:26:36 +0000 by phpDocumentor 1.4.3