Overview

Packages

  • alpha::controller
  • alpha::controller::front
  • alpha::exceptions
  • alpha::model
  • alpha::model::types
  • alpha::tasks
  • alpha::tests
  • alpha::util
  • alpha::util::cache
  • alpha::util::codehighlight
  • alpha::util::convertors
  • alpha::util::feeds
  • alpha::util::filters
  • alpha::util::graphs
  • alpha::util::helpers
  • alpha::util::metrics
  • alpha::view
  • alpha::view::renderers
  • alpha::view::widgets

Classes

  • AlphaController
  • CacheManager
  • Create
  • CreateArticle
  • Detail
  • Edit
  • EditArticle
  • EditDEnum
  • EditTags
  • GenSecureQueryStrings
  • Install
  • ListAll
  • ListBusinessObjects
  • ListDEnums
  • ListSequences
  • Login
  • Logout
  • PreviewArticle
  • Search
  • TagManager
  • ViewArticle
  • ViewArticleFile
  • ViewArticlePDF
  • ViewArticlePrint
  • ViewArticleTitle
  • ViewAttachment
  • ViewExcel
  • ViewFeed
  • ViewImage
  • ViewLog
  • ViewMetrics
  • ViewRecordSelector
  • ViewTestResults

Interfaces

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