import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
98
modules/news/controllers/EditController.php
Normal file
98
modules/news/controllers/EditController.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class News_EditController extends CommunityID_Controller_Action
|
||||
{
|
||||
protected $_numCols = 2;
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$appSession = Zend_Registry::get('appSession');
|
||||
if (isset($appSession->articleForm)) {
|
||||
$this->view->articleForm = $appSession->articleForm;
|
||||
unset($appSession->articleForm);
|
||||
} else {
|
||||
$this->view->articleForm = new News_Form_Article();
|
||||
$news = new News_Model_News();
|
||||
if ($this->_getParam('id') && ($article = $news->getRowInstance($this->_getParam('id')))) {
|
||||
$this->view->articleForm->populate(array(
|
||||
'title' => $article->title,
|
||||
'date' => $article->date,
|
||||
'excerpt' => $article->excerpt,
|
||||
'content' => $article->content,
|
||||
));
|
||||
$this->view->articleId = $article->id;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_helper->actionStack('index', 'login', 'users');
|
||||
}
|
||||
|
||||
public function addAction()
|
||||
{
|
||||
$this->_forward('index');
|
||||
}
|
||||
|
||||
public function saveAction()
|
||||
{
|
||||
$form = new News_Form_Article();
|
||||
$formData = $this->_request->getPost();
|
||||
$form->populate($formData);
|
||||
|
||||
if (!$form->isValid($formData)) {
|
||||
$appSession = Zend_Registry::get('appSession');
|
||||
$appSession->articleForm = $form;
|
||||
$this->_forward('index');
|
||||
return;
|
||||
}
|
||||
|
||||
$news = new News_Model_News();
|
||||
if ($this->_getParam('id')) {
|
||||
if (!$article = $news->getRowInstance($this->_getParam('id'))) {
|
||||
$this->_helper->FlashMessenger->addMessage('Article doesn\'t exist.');
|
||||
$this->_redirect('/news');
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$article = $news->createRow();
|
||||
}
|
||||
|
||||
|
||||
require_once 'htmlpurifier/library/HTMLPurifier.auto.php';
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$purifier = new HTMLPurifier($config);
|
||||
$cleanHtml = $purifier->purify($form->getValue('content'));
|
||||
|
||||
$article->title = $form->getValue('title');
|
||||
$article->date = $form->getValue('date');
|
||||
$article->excerpt = $form->getValue('excerpt');
|
||||
$article->content = $cleanHtml;
|
||||
$article->save();
|
||||
|
||||
$this->_helper->FlashMessenger->addMessage('The article has been saved.');
|
||||
|
||||
$this->_redirect('/news');
|
||||
}
|
||||
|
||||
public function deleteAction()
|
||||
{
|
||||
$news = new News_Model_News();
|
||||
if (!$article = $news->getRowInstance($this->_getParam('id'))) {
|
||||
$this->_helper->FlashMessenger->addMessage('The article doesn\'t exist.');
|
||||
} else {
|
||||
$article->delete();
|
||||
$this->_helper->FlashMessenger->addMessage('The article has been deleted.');
|
||||
}
|
||||
|
||||
$this->_redirect('/news');
|
||||
}
|
||||
}
|
23
modules/news/controllers/IndexController.php
Normal file
23
modules/news/controllers/IndexController.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class News_IndexController extends CommunityID_Controller_Action
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
$news = new News_Model_News();
|
||||
|
||||
$this->view->paginator = $news->getArticlesPaginator(News_Model_News::RECORDS_PER_PAGE,
|
||||
$this->_getParam('page', 0), $this->user);
|
||||
|
||||
$this->_helper->actionStack('index', 'login', 'users');
|
||||
}
|
||||
}
|
25
modules/news/controllers/ViewController.php
Normal file
25
modules/news/controllers/ViewController.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class News_ViewController extends CommunityID_Controller_Action
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
$news = new News_Model_News();
|
||||
$this->view->article = $news->getRowInstance($this->_getParam('id'));
|
||||
|
||||
if ($this->view->article->date > date('Y-m-d H:i:s') && $this->user->role != Users_Model_User::ROLE_ADMIN) {
|
||||
throw new Monkeys_AccessDeniedException();
|
||||
}
|
||||
|
||||
$this->_helper->actionStack('index', 'login', 'users');
|
||||
}
|
||||
}
|
44
modules/news/forms/Article.php
Normal file
44
modules/news/forms/Article.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
|
||||
class News_Form_Article extends Zend_Form
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$title = new Monkeys_Form_Element_Text('title');
|
||||
translate('Title');
|
||||
$title->setLabel('Title')
|
||||
->setRequired(true)
|
||||
->setAttrib('style', 'width:350px');
|
||||
|
||||
$date = new Monkeys_Form_Element_DateTime('date');
|
||||
translate('Publication date');
|
||||
$date->setLabel('Publication date')
|
||||
->setShowEmptyValues(false)
|
||||
->setStartEndYear(1900, date('Y') + 1)
|
||||
->setReverseYears(true)
|
||||
->setValue(date('Y-m-d H:i'));
|
||||
|
||||
$excerpt = new Monkeys_Form_Element_Textarea('excerpt');
|
||||
translate('Excerpt');
|
||||
$excerpt->setLabel('Excerpt')
|
||||
->setAttrib('style', 'width:350px')
|
||||
->setAttrib('rows', 4);
|
||||
|
||||
$content = new Monkeys_Form_Element_Richtextarea('content');
|
||||
$content->setDecoratorOptions(array('separateLine' => true))
|
||||
->setAttrib('width', '510px')
|
||||
->setRequired(true);
|
||||
|
||||
$this->addElements(array($title, $date, $excerpt, $content));
|
||||
}
|
||||
}
|
58
modules/news/models/News.php
Normal file
58
modules/news/models/News.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
|
||||
class News_Model_News extends Monkeys_Db_Table_Gateway
|
||||
{
|
||||
const RECORDS_PER_PAGE = 5;
|
||||
|
||||
protected $_name = 'news';
|
||||
protected $_primary = 'id';
|
||||
protected $_rowClass = 'News_Model_NewsArticle';
|
||||
|
||||
private $_sortFields = array(
|
||||
'date' => array('date', 'title'),
|
||||
'title' => array('title', 'date')
|
||||
);
|
||||
|
||||
public function getArticlesPaginator($limit = self::RECORDS_PER_PAGE, $page = 0, Users_Model_User $user)
|
||||
{
|
||||
$select = $this->select()->order('date DESC');
|
||||
|
||||
if ($user->role != Users_Model_User::ROLE_ADMIN) {
|
||||
$select = $select->where('date <= ?', date('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbTableSelect($select));
|
||||
$paginator->setItemCountPerPage($limit);
|
||||
$paginator->setCurrentPageNumber($page);
|
||||
|
||||
return $paginator;
|
||||
}
|
||||
|
||||
public function getLatest($numItems, Users_Model_User $user)
|
||||
{
|
||||
$select = $this->select()
|
||||
->order('date DESC')
|
||||
->limit($numItems);
|
||||
|
||||
if ($user->role != Users_Model_User::ROLE_ADMIN) {
|
||||
$select = $select->where('date <= ?', date('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
return $this->fetchAll($select);
|
||||
}
|
||||
|
||||
public function deleteTestEntries()
|
||||
{
|
||||
$this->delete('test=1');
|
||||
}
|
||||
}
|
14
modules/news/models/NewsArticle.php
Normal file
14
modules/news/models/NewsArticle.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class News_Model_NewsArticle extends Zend_Db_Table_Row_Abstract
|
||||
{
|
||||
}
|
28
modules/news/views/scripts/edit/index.phtml
Normal file
28
modules/news/views/scripts/edit/index.phtml
Normal file
@ -0,0 +1,28 @@
|
||||
<form method="post" action="<?php echo $this->base ?>/news/edit/save" class="formGrid">
|
||||
<input type="hidden" name="id" value="<?= $this->articleId ?>" />
|
||||
<?php echo $this->articleForm->title ?>
|
||||
<?php echo $this->articleForm->excerpt ?>
|
||||
<?php echo $this->articleForm->date ?>
|
||||
<?php echo $this->articleForm->content ?>
|
||||
<div>
|
||||
<input type="submit" id="save" value="<?php echo $this->translate('Save') ?>" />
|
||||
<input type="button" id="cancel" value="<?php echo $this->translate('Cancel') ?>" />
|
||||
<script type="text/javascript">
|
||||
YAHOO.util.Event.onDOMReady(function () {
|
||||
new YAHOO.widget.Button(
|
||||
"save",
|
||||
{
|
||||
type : "submit"
|
||||
}
|
||||
);
|
||||
new YAHOO.widget.Button(
|
||||
"cancel",
|
||||
{
|
||||
type : "push",
|
||||
onclick : {fn: function() {COMMID.editArticle.cancel(<?php echo $this->articleId ?>)}}
|
||||
}
|
||||
);
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
</form>
|
34
modules/news/views/scripts/index/index.phtml
Normal file
34
modules/news/views/scripts/index/index.phtml
Normal file
@ -0,0 +1,34 @@
|
||||
<?php if ($this->user->role == Users_Model_User::ROLE_ADMIN): ?>
|
||||
<div class="linksTopRightContainer">
|
||||
<h2><?php echo $this->translate('Latest News') ?></h2>
|
||||
<div class="linksTopRight">
|
||||
<a href="<?php echo $this->base ?>/news/edit/add"><?php echo $this->translate('Add New Article') ?></a>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<?php if (count($this->paginator) == 0): ?>
|
||||
<div><?= $this->translate('There are no news articles yet') ?></div>
|
||||
<?php else: ?>
|
||||
<?php foreach ($this->paginator as $article): ?>
|
||||
<div class="post">
|
||||
<h3><a href="<?php echo $this->base . '/news/' . $article->id ?>"><?php echo $article->title ?></a></h3>
|
||||
<div class="article_date">
|
||||
<?php echo $this->translate("Published on %s", $article->date) ?>
|
||||
</div>
|
||||
<p><?php echo $article->excerpt ?></p>
|
||||
<p class="more">
|
||||
<a href="<?php echo $this->base . '/news/' . $article->id ?>">
|
||||
<?php echo $this->translate('read more') ?>
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif ?>
|
||||
<?php if ($this->paginator->count() > 1): ?>
|
||||
<?php echo $this->paginationControl($this->paginator,
|
||||
'Sliding',
|
||||
'index/pagination.phtml',
|
||||
array(
|
||||
'base' => $this->base
|
||||
)) ?>
|
||||
<?php endif ?>
|
36
modules/news/views/scripts/index/pagination.phtml
Normal file
36
modules/news/views/scripts/index/pagination.phtml
Normal file
@ -0,0 +1,36 @@
|
||||
<!--
|
||||
See http://developer.yahoo.com/ypatterns/pattern.php?pattern=searchpagination
|
||||
-->
|
||||
|
||||
<?php if ($this->pageCount): ?>
|
||||
<div class="paginationControl">
|
||||
<!-- Previous page link -->
|
||||
<?php if (isset($this->previous)): ?>
|
||||
<a href="<?php echo $this->base . '/news?page=' . $this->previous ?>">
|
||||
< <?php echo $this->translate('Previous') ?>
|
||||
</a> |
|
||||
<?php else: ?>
|
||||
<span class="disabled">< <?php echo $this->translate('Previous') ?></span> |
|
||||
<?php endif ?>
|
||||
|
||||
<!-- Numbered page links -->
|
||||
<?php foreach ($this->pagesInRange as $page): ?>
|
||||
<?php if ($page != $this->current): ?>
|
||||
<a href="<?php echo $this->base . '/news?page=' . $page ?>">
|
||||
<?php echo $page; ?>
|
||||
</a> |
|
||||
<?php else: ?>
|
||||
<?php echo $page; ?> |
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
||||
|
||||
<!-- Next page link -->
|
||||
<?php if (isset($this->next)): ?>
|
||||
<a href="<?php echo $this->base . '/news?page=' . $this->next ?>">
|
||||
<?php echo $this->translate('Next') ?> >
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<span class="disabled"><?php echo $this->translate('Next') ?> ></span>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<?php endif ?>
|
15
modules/news/views/scripts/view/index.phtml
Normal file
15
modules/news/views/scripts/view/index.phtml
Normal file
@ -0,0 +1,15 @@
|
||||
<h2><?= $this->escape($this->article->title) ?></h2>
|
||||
<div class="article_date">
|
||||
<?php echo $this->translate('Published on %s', $this->article->date) ?>
|
||||
<?php if ($this->user->role == Users_Model_User::ROLE_ADMIN): ?>
|
||||
<div class="linksTopRight">
|
||||
<a href="<?php echo $this->base . '/news/edit/index/id/' . $this->article->id ?>"><?php echo $this->translate('Edit Article') ?></a> |
|
||||
<a href="#" onclick="COMMID.editArticle.remove(<?php echo $this->article->id ?>);return false;"><?php echo $this->translate('Delete Article') ?></a>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<p><?= $this->escape($this->article->excerpt) ?></p>
|
||||
<hr />
|
||||
<div>
|
||||
<?php echo $this->article->content ?>
|
||||
</div>
|
Reference in New Issue
Block a user