Source for file ViewArticle.php
Documentation is available at ViewArticle.php
// include the config file
require_once '../util/AlphaConfig.inc';
require_once $config->get('sysRoot'). 'alpha/view/AlphaView.inc';
require_once $config->get('sysRoot'). 'alpha/controller/AlphaController.inc';
require_once $config->get('sysRoot'). 'alpha/model/ArticleObject.inc';
require_once $config->get('sysRoot'). 'alpha/util/InputFilter.inc';
require_once $config->get('sysRoot'). 'alpha/util/helpers/AlphaValidator.inc';
require_once $config->get('sysRoot'). 'alpha/controller/AlphaControllerInterface.inc';
* Controller used to display a Markdown version of an article
* @package alpha::controller
* @author John Collins <dev@alphaframework.org>
* @version $Id: ViewArticle.php 1453 2011-12-04 15:12:54Z johnc $
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the
* following conditions are met:
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
* * Neither the name of the Alpha Framework nor the names
* of its contributors may be used to endorse or promote
* products derived from this software without specific
* prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* The article to be rendered
private static $logger = null;
* constructor to set up the object
self::$logger = new Logger('ViewArticle');
self::$logger->debug('>>__construct()');
// ensure that the super class constructor is called, indicating the rights group
parent::__construct('Public');
self::$logger->debug('<<__construct');
* @throws ResourceNotFoundException
public function doGET($params) {
// check to see if we need to force a re-direct to the mod_rewrite alias URL for the article
if($config->get('sysForceModRewriteURLs') && basename($_SERVER['PHP_SELF']) == 'ViewArticle.php') {
// set the correct HTTP header for the response
header('HTTP/1.1 301 Moved Permanently');
header('Location: '. $this->BO->get('URL'));
// load the business object (BO) definition
$this->BO->load($params['oid']);
// set up the title and meta details
echo $BOView->markdownView();
self::$logger->error($e->getMessage());
throw new ResourceNotFoundException($e->getMessage());
self::$logger->warn($e->getMessage());
throw new ResourceNotFoundException('The article that you have requested cannot be found!');
* Callback used to inject ArticleObject headerContent into the page
return $this->BO->get('headerContent');
* Callback that inserts the CMS level header
if($config->get('sysCMSDisplayStandardHeader')) {
$html.= '<p><a href="'. $config->get('sysURL'). '">'. $config->get('sysTitle'). '</a> ';
$html.= 'Date Added: <em>'. $this->BO->getCreateTS()->getDate(). '</em> ';
$html.= 'Last Updated: <em>'. $this->BO->getUpdateTS()->getDate(). '</em> ';
$html.= 'Revision: <em>'. $this->BO->getVersion(). '</em></p>';
$html.= $config->get('sysCMSHeader');
* Callback used to render footer content, including comments, votes and print/PDF buttons when
if($config->get('sysCMSDisplayComments'))
$html .= $this->renderComments();
if($config->get('sysCMSDisplayTags')) {
$tags = $this->BO->getPropObject('tags')->getRelatedObjects();
$html .= ' <a href="'. $config->get('sysURL'). 'search/q/'. $tag->get('content'). '">'. $tag->get('content'). '</a>';
if($config->get('sysCMSDisplayVotes')) {
$rating = $this->BO->getArticleScore();
$votes = $this->BO->getArticleVotes();
$html .= '<p>Average Article User Rating: <strong>'. $rating. '</strong> out of 10 (based on <strong>'. count($votes). '</strong> votes)</p>';
if(!$this->BO->checkUserVoted() && $config->get('sysCMSVotingAllowed')) {
$html .= '<form action="'. $_SERVER['REQUEST_URI']. '" method="post">';
$html .= '<p>Please rate this article from 1-10 (10 being the best):' .
'<select name="user_vote">' .
'<option value="10">10' .
'</select></p> ';
$temp = new Button('submit','Vote!','voteBut');
$html .= $temp->render();
$temp = new Button("window.open('". $this->BO->get('printURL'). "')",'Open Printer Version','printBut');
$html .= $temp->render();
if($config->get('sysAllowPDFVersions')) {
$html .= $temp->render();
// render edit button for admins only
if (isset ($_SESSION['currentUser']) && $_SESSION['currentUser']->inGroup('Admin')) {
$html .= $button->render();
if($config->get('sysCMSDisplayStandardFooter')) {
$html .= '<p>Article URL: <a href="'. $this->BO->get('URL'). '">'. $this->BO->get('URL'). '</a><br>';
$html .= 'Title: '. $this->BO->get('title'). '<br>';
$html .= 'Author: '. $this->BO->get('author'). '</p>';
$html .= $config->get('sysCMSFooter');
* Method to handle POST requests
public function doPOST($params) {
// check the hidden security fields before accepting the form POST data
throw new SecurityException('This page cannot accept post data from remote servers!');
if(isset ($params['voteBut']) && !$this->BO->checkUserVoted()) {
if(isset ($params['oid'])) {
$vote->set('articleOID', $params['oid']);
// load article by title?
if (isset ($params['title'])) {
$this->BO->loadByAttribute('title', $title);
$vote->set('articleOID', $this->BO->getOID());
$vote->set('personOID', $_SESSION['currentUser']->getID());
$vote->set('score', $params['user_vote']);
self::$logger->error($e->getMessage());
if(isset ($params['createBut'])) {
$comment = new ArticleCommentObject();
// populate the transient object from post data
$comment->populateFromPost();
// filter the comment before saving
$success = $comment->save();
self::$logger->error($e->getMessage());
if(isset ($params['saveBut'])) {
$comment = new ArticleCommentObject();
$comment->load($params['article_comment_id']);
// re-populates the old object from post data
$comment->populateFromPost();
$success = $comment->save();
self::$logger->error($e->getMessage());
}catch (SecurityException $e) {
self::$logger->warn($e->getMessage());
throw new ResourceNotAllowedException($e->getMessage());
* Method for displaying the user comments for the article.
private function renderComments() {
$comments = $this->BO->getArticleComments();
$comment_count = count($comments);
if($config->get('sysCMSDisplayComments') && $comment_count > 0) {
$html .= '<h2>There are ['. $comment_count. '] user comments for this article</h2>';
for($i = 0; $i < $comment_count; $i++ ) {
if(isset ($_SESSION['currentUser']) && $config->get('sysCMSCommentsAllowed')) {
$comment->set('articleOID', $this->BO->getID());
// now build the new controller
if(basename($_SERVER['PHP_SELF']) == 'ViewArticle.php') {
$controller->doPOST($_REQUEST);
$controller->doGET($_GET);
|