1 <?php
defined('IN_CMS') or die('No direct access allowed.');
3 class Posts_controller
{
5 public function __construct() {
6 $this->admin_url
= Config
::get('application.admin_folder');
9 public function index() {
10 $data['posts'] = Posts
::list_all(array('sortby' => 'id', 'sortmode' => 'desc'));
11 Template
::render('posts/index', $data);
14 public function add() {
15 if(Input
::method() == 'POST') {
17 return Response
::redirect($this->admin_url
. '/posts/edit/' . Db
::insert_id());
21 Template
::render('posts/add');
24 public function edit($id) {
26 if(($article = Posts
::find(array('id' => $id))) === false) {
27 return Response
::redirect($this->admin_url
. '/posts');
30 // process post request
31 if(Input
::method() == 'POST') {
32 if(Posts
::update($id)) {
34 return Response
::redirect($this->admin_url
. '/posts/edit/' . $id);
39 $comments = Comments
::list_all(array('post' => $id));
42 foreach($comments as $comment) {
43 if($comment->status
== 'pending') {
44 $pending[] = $comment->id
;
48 $pending = count($pending);
51 $page = Pages
::find(array('id' => Config
::get('metadata.posts_page')));
53 Template
::render('posts/edit', array('article' => $article, 'comments' => $comments, 'page' => $page, 'pending' => $pending));