/** * @fn diario * @short Action method that generates the feed of Diario articles. */ public function diario() { $post_factory = new DiarioPost(); $this->posts = $post_factory->find_by_query('SELECT * ' . 'FROM `diario_posts` ' . 'WHERE `status` = \'pubblicato\' ' . 'ORDER BY `created_at` DESC ' . 'LIMIT 10'); }
/** * @fn post_comment * @short Action method to receive a comment for an article. */ public function post_comment() { if (!$this->request->is_post()) { $this->redirect_to(array('action' => 'index')); } $post = new DiarioPost(); if ($post->find_by_id($_POST['post_id']) === FALSE) { $this->flash(l('No such article'), 'error'); $this->redirect_to(array('action' => 'index')); } if (!Email::is_valid($_POST['email'])) { $this->flash(l('Please enter a valid email address'), 'error'); $this->redirect_to($post->permalink(FALSE)); } if (!Antispam::check_math()) { $this->flash(Antispam::random_comment(), 'error'); $this->redirect_to($post->permalink(FALSE)); } // A static class method would be infinitely better... $comment = new DiarioComment($_POST); $comment->created_at = date("Y-m-d H:i:s"); $comment->save(); // Send an email to notify this comment $email = new DiarioCommentEmail(array('comment' => $comment, 'name' => $_POST['author'], 'email' => $_POST['email'], 'URL' => $_POST['URL'])); $email->send(); if (isset($_POST['remember_me'])) { $this->set_credentials($_POST['author'], $_POST['email'], $_POST['URL']); } // Expires the cache $this->expire_cached_page(array('action' => 'index')); $this->expire_cached_page(array('action' => 'read', 'id' => $_POST['post_id'])); // Expires the cache of Comments feed $this->expire_cached_page(array('controller' => 'feed', 'action' => 'diario_comments', 'id' => $_POST['post_id'])); $this->redirect_to(array('action' => 'read', 'id' => $_POST['post_id'], 'hash' => "comment-{$comment->id}")); }
/** * @fn diario_post_list * @short Action method to show the list of articles. */ public function diario_post_list() { $post_factory = new DiarioPost(); $this->posts = $post_factory->find_all(array('order_by' => '`id` DESC', 'start' => isset($_REQUEST['page']) && is_numeric($_REQUEST['page']) ? 20 * ($_REQUEST['page'] - 1) : 0, 'limit' => 20)); }