X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=testcms-final-anon%2Fsystem%2Fadmin%2Fcontrollers%2Fposts.php;fp=testcms-final-anon%2Fsystem%2Fadmin%2Fcontrollers%2Fposts.php;h=3e173e36fdcd2acf0e4c71e1682158689e58c65e;hb=487e0193c6d3093651c15b478e9e56b6a2f550f9;hp=0000000000000000000000000000000000000000;hpb=e48921c08b5a6cae18d285ef9979b625e4558b4b;p=ssproject1617.git diff --git a/testcms-final-anon/system/admin/controllers/posts.php b/testcms-final-anon/system/admin/controllers/posts.php new file mode 100644 index 0000000..3e173e3 --- /dev/null +++ b/testcms-final-anon/system/admin/controllers/posts.php @@ -0,0 +1,56 @@ +admin_url = Config::get('application.admin_folder'); + } + + public function index() { + $data['posts'] = Posts::list_all(array('sortby' => 'id', 'sortmode' => 'desc')); + Template::render('posts/index', $data); + } + + public function add() { + if(Input::method() == 'POST') { + if(Posts::add()) { + return Response::redirect($this->admin_url . '/posts/edit/' . Db::insert_id()); + } + } + + Template::render('posts/add'); + } + + public function edit($id) { + // find article + if(($article = Posts::find(array('id' => $id))) === false) { + return Response::redirect($this->admin_url . '/posts'); + } + + // process post request + if(Input::method() == 'POST') { + if(Posts::update($id)) { + // redirect path + return Response::redirect($this->admin_url . '/posts/edit/' . $id); + } + } + + // get comments + $comments = Comments::list_all(array('post' => $id)); + $pending = array(); + + foreach($comments as $comment) { + if($comment->status == 'pending') { + $pending[] = $comment->id; + } + } + + $pending = count($pending); + + // get posts page + $page = Pages::find(array('id' => Config::get('metadata.posts_page'))); + + Template::render('posts/edit', array('article' => $article, 'comments' => $comments, 'page' => $page, 'pending' => $pending)); + } + +}