MVCnPHP Sample Application - Blog
NOTE: blog posts are delete every 10 minutes
There are no blog entries.
NOTE: blog posts are delete every 10 minutes
There are no blog entries.
<?php
/* Reminder: always indent with 4 spaces (no tabs). */
/**
* This file is part of the Apteno MVCnPHP Sample Application
*
* MVCnPHP is free software: you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* MVCnPHP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with MVCnPHP. If not,
* see <http://www.gnu.org/licenses/>.
*
* @category Apteno
* @package Apteno_MVCnPHP_Sample
* @author Tony Bibbs <tony@apteno.net>
* @author Michael Tutty <michael.tutty@gmail.com>
* @copyright Copyright (c) 2008-2009 Apteno L.C. (http://www.apteno.net)
* @license http://www.apteno.net/GPL.html GNU General Public License
* @version $Revision: 373 $
*
*/
/**
* Abstract parent
*/
require getOption('path') . 'modules/kernel/views/SampleBaseView.php';
/**
* BlogPosting model
*/
require_once getOption('path') . 'modules/blog/models/BlogPosting.php';
/**
* Shows the main blog page
*
*/
class BlogMainView extends SampleBaseView {
/**
* Indicates if we show oldest blog entries first
* @accesss private
* @var boolean
*/
private $oldestFirst = true;
/**
* Posting per page
* @access private
* @var integer
*/
private $maxPostings = 5;
/**
* Locate of data directory
* @access private
* @var string
*/
private $baseDir;
/**
* Name of topic to filter on
* @access pubic
* @var string
*/
public $topic = null;
/**
* Postings to be displayed
* @access public
* @var <type>
*/
public $postings = array();
/**
* Registers the actions this view or command responds to.
*
* Views and commands are assigned names called actions. This method assigns the actions that
* this view or command will be called on. The way it works is simple, if the controller sees
* one of the names below it will call the execute() or getView() method. Thus, each action
* assigned to a view or command must be unique.
*
* @access public
* @static
* @return array Collection of action names for this view or command
*
*/
public static function getActions()
{
return array('show','Show');
}
/**
* Registers this view as the default action
*
* @access public
* @static
* @return boolean True as this is the default view
*/
public static function getIsDefaultAction()
{
return true;
}
/**
* Registers the forwards this view or command uses
*
* Forwards are classes that tell the controller what to do after a view or command is executed.
* Each forward is given a name that can then be returned in the execute() or getView() for that
* particular view or command. The controller then does as it is instructed by the data in the
* forward.
*
* @access public
* @static
* @return array Collection of \Apteno\MVCnPHP\Forward objects
*
*/
public static function getForwards()
{
return array();
}
/**
* We don't require a valid user object in the session and we initialize the data directory
*
* @access public
*
*/
public function __construct() {
parent::__construct();
$this->setPostingDir(getOption('path_data'));
$this->setUserRequired(FALSE);
}
/**
* Render the view
*
* @access public
*
*/
public function processView()
{
// Maps the URL args to names we understand.
$this->mapUrlArgs(array('controller','action','topic'));
$peer = new BlogPostingPeer();
$peer->setBaseDir($this->getPostingDir());
$this->postings = $peer->listPostings($this->maxPostings, 0, $this->getArg('topic'),
$this->oldestFirst);
$this->setPageTitle(getOption('site_name'));
$this->showHeader();
$this->compileAndOutput('BlogMainView.thtml');
$this->showFooter();
}
/**
* Returns the posting directory
*
* @return string directory where stuff is posted.
*/
protected function getPostingDir()
{
return $this->baseDir;
}
/**
* Sets the posting directory
*
* @param string $baseDir
*/
protected function setPostingDir($baseDir)
{
$this->baseDir = $baseDir;
}
/**
* Formats the given date/time
*
* Used in Flexy template
*
* @acces public
* @param integer $val time to format
* @return string Formatted date time
*
*/
public function getFormattedDate($val)
{
return date('g', $val);
}
/**
* Determines if we have any postings
*
* Used in Flexy template
*
* @return boolen True if we have postings otherwise false
*
*/
public function hasPostings()
{
return ($this->postings != null && count($this->postings) > 0);
}
/**
* Determines if the current user can make enw blog entries or not.
*
* Used in Flexy template
*
* @return boolean True if teh user is allowed to post, otherwise false.
*
*/
public function canPost()
{
return $this->haveUser();
}
/**
* Gets the ID for the given post
*
* @access public
* @param BlogPosting $posting Instance of a blog model object
* @return string ID of post
*
*/
public function getPostingID($posting)
{
$peer = new BlogPostingPeer();
return $peer->getFileName($posting);
}
/**
* Determines if user can edit the given posting.
*
* Used in Flexy template
*
* @access public
* @param BlogPosting $posting Post to check access on
* @return boolean True if they can edit it otherwise false
*
*/
public function canEdit($posting)
{
return $this->haveUser();
}
/**
* Sets if we should show oldest first
*
* @access public
* @param boolean $oldestFirst True to show oldest first otherwise false
*
*/
public function setOldestFirst($oldestFirst)
{
$this->oldestFirst = $oldestFirst;
}
/**
* Gets if we should oldest posts first
*
* @return boolean True to show oldest first otherwise false
*
*/
public function getOldestFirst()
{
return $this->oldestFirst;
}
/**
* Sets maximum number of posts per page.
*
* @access protected
* @param integer $maxPostings Number of posting per page.
*
*/
protected function setMaxPostings($maxPostings)
{
$this->maxPostings = $maxPostings;
}
/**
* Sets maximum number of posts per page.
*
* @access protected
* @return integer Number of posting per page.
*
*/
protected function getMaxPostings()
{
return $this->maxPostings;
}
}
?>
<h3>{pageTitle}{if:topic} - {topic}{else:} - Blog{end:}</h3>
<p>
<b>NOTE:</b> blog posts are delete every 10 minutes
{if:hasPostings()}
{foreach:postings,posting}
<h3><a href="{controllerUrl}/read/{getPostingID(posting)}/" title="Read {posting.getTitle()}">{posting.getTitle()}</a></h3>
<p style="font-size: smaller; color: darkgray;">Topic: <a href="{controllerUrl}/show/{posting.getTopic()}/" title="Read more in {posting.getTopic()}">{posting.getTopic()}</a><br />
Posted on {posting.getCreateDate(#l, F jS Y \a\t g:i A#)}</p>
<p>{posting.getIntroduction()}</p>
<p>
<a href="{controllerUrl}/read/{getPostingID(posting)}/" title="Read {posting.getTitle()}">read more...</a>
{if:canEdit(posting)}
<a href="{controllerUrl}/edit/{getPostingID(posting)}/" title="Edit {posting.getTitle()}">edit</a>
{end:}
</p>
<br />
<br />
{end:}
{else:}
<p>There are no blog entries{if:topic} in this topic{end:}.</p>
{end:}
</p>
{if:canPost()}
<p><a href="{controllerUrl}/edit/" title="Create a new blog entry">Add a blog entry</a></p>
{end:}