Exemplo n.º 1
0
 /**
  *	@fn search
  *	@short Action method that returns a list of articles that satisfy a search query.
  */
 public function search()
 {
     if (isset($_REQUEST['term']) && !empty($_REQUEST['term'])) {
         $conn = Db::get_connection();
         $post_factory = new DiarioPost();
         $terms = explode(' ', $_REQUEST['term']);
         $where_clause = '1';
         for ($i = 0; $i < count($terms); $i++) {
             $where_clause .= " AND (`title` LIKE '%{$conn->escape($terms[$i])}%' OR " . "`author` LIKE '%{$conn->escape($terms[$i])}%' OR " . "`text` LIKE '%{$conn->escape($terms[$i])}%') ";
         }
         $this->articles = $post_factory->find_by_query("SELECT * " . "FROM `diario_posts` " . "WHERE {$where_clause} " . "AND `status` = 'pubblicato' LIMIT 20");
         if (count($this->articles) < 1) {
             $this->redirect_to(array('action' => 'index'));
         }
         Db::close_connection($conn);
         $this->render(array('action' => 'index'));
     } else {
         $this->redirect_to(array('action' => 'index'));
     }
 }
Exemplo n.º 2
0
 /**
  *	@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');
 }