--- /dev/null
+<?php defined('IN_CMS') or die('No direct access allowed.');\r
+\r
+class Posts_controller {\r
+\r
+ public function __construct() {\r
+ $this->admin_url = Config::get('application.admin_folder');\r
+ }\r
+\r
+ public function index() {\r
+ $data['posts'] = Posts::list_all(array('sortby' => 'id', 'sortmode' => 'desc'));\r
+ Template::render('posts/index', $data);\r
+ }\r
+ \r
+ public function add() {\r
+ if(Input::method() == 'POST') {\r
+ if(Posts::add()) {\r
+ return Response::redirect($this->admin_url . '/posts/edit/' . Db::insert_id());\r
+ }\r
+ }\r
+\r
+ Template::render('posts/add');\r
+ }\r
+ \r
+ public function edit($id) {\r
+ // find article\r
+ if(($article = Posts::find(array('id' => $id))) === false) {\r
+ return Response::redirect($this->admin_url . '/posts');\r
+ }\r
+\r
+ // process post request\r
+ if(Input::method() == 'POST') {\r
+ if(Posts::update($id)) {\r
+ // redirect path\r
+ return Response::redirect($this->admin_url . '/posts/edit/' . $id);\r
+ }\r
+ }\r
+ \r
+ // get comments\r
+ $comments = Comments::list_all(array('post' => $id));\r
+ $pending = array();\r
+ \r
+ foreach($comments as $comment) {\r
+ if($comment->status == 'pending') {\r
+ $pending[] = $comment->id;\r
+ }\r
+ }\r
+ \r
+ $pending = count($pending);\r
+\r
+ // get posts page\r
+ $page = Pages::find(array('id' => Config::get('metadata.posts_page')));\r
+\r
+ Template::render('posts/edit', array('article' => $article, 'comments' => $comments, 'page' => $page, 'pending' => $pending));\r
+ }\r
+ \r
+}\r