Example #1
0
 /**
  * returns items
  *
  * @return mixed items as array
  * @param mixed $options search, offset and filter params
  */
 public function get($options = array())
 {
     $params = array();
     $where = '';
     $order = 'DESC';
     // only starred
     if (isset($options['type']) && $options['type'] == 'starred') {
         $where .= ' AND starred=true ';
     } else {
         if (isset($options['type']) && $options['type'] == 'unread') {
             $where .= ' AND unread=true ';
             if (\F3::get('unread_order') == 'asc') {
                 $order = 'ASC';
             }
         }
     }
     // search
     if (isset($options['search']) && strlen($options['search']) > 0) {
         $search = implode('%', \helpers\Search::splitTerms($options['search']));
         $params[':search'] = $params[':search2'] = $params[':search3'] = array("%" . $search . "%", \PDO::PARAM_STR);
         $where .= ' AND (items.title LIKE :search OR items.content LIKE :search2 OR sources.title LIKE :search3) ';
     }
     // tag filter
     if (isset($options['tag']) && strlen($options['tag']) > 0) {
         $params[':tag'] = array("%," . $options['tag'] . ",%", \PDO::PARAM_STR);
         $where .= " AND ( (',' || sources.tags || ',') LIKE :tag ) ";
     } elseif (isset($options['source']) && strlen($options['source']) > 0) {
         $params[':source'] = array($options['source'], \PDO::PARAM_INT);
         $where .= " AND items.source=:source ";
     }
     // update time filter
     if (isset($options['updatedsince']) && strlen($options['updatedsince']) > 0) {
         $params[':updatedsince'] = array($options['updatedsince'], \PDO::PARAM_STR);
         $where .= " AND items.updatetime > :updatedsince ";
     }
     // set limit
     if (!is_numeric($options['items']) || $options['items'] > 200) {
         $options['items'] = \F3::get('items_perpage');
     }
     // first check whether more items are available
     $result = \F3::get('db')->exec('SELECT items.id
                FROM items, sources
                WHERE items.source=sources.id ' . $where . ' 
                LIMIT 1 OFFSET ' . ($options['offset'] + $options['items']), $params);
     $this->hasMore = count($result);
     // get items from database
     return \F3::get('db')->exec('SELECT 
                 items.id, datetime, items.title AS title, content, unread, starred, source, thumbnail, icon, uid, link, updatetime, author, sources.title as sourcetitle, sources.tags as tags
                FROM items, sources 
                WHERE items.source=sources.id ' . $where . ' 
                ORDER BY items.datetime ' . $order . ' 
                LIMIT ' . $options['items'] . ' OFFSET ' . $options['offset'], $params);
 }
Example #2
0
 /** encloses all searchWords with <span class=found>$word</span>
  * for later highlitning with CSS
  *
  * @return string with highlited words
  * @param string $content which contains words
  * @param array|string $searchWords words for highlighting
  */
 public function highlight($content, $searchWords)
 {
     if (strlen(trim($searchWords)) == 0) {
         return $content;
     }
     if (!is_array($searchWords)) {
         $searchWords = \helpers\Search::splitTerms($searchWords);
     }
     foreach ($searchWords as $word) {
         $content = preg_replace('/(?!<[^<>])(' . $word . ')(?![^<>]*>)/i', '<span class=found>$0</span>', $content);
     }
     return $content;
 }
Example #3
0
<?php

function no_products($app, $type, $query = NULL)
{
    $app->render('products/list/no_products.php', array('page_title' => $type, 'type' => $type, 'query' => $query));
    $app->stop();
}
$app->get('/products/search', function () use($app, $db, $config) {
    $params = $app->request()->get();
    $records_per_page = $config['records_per_page'];
    $pagination = new \Zebra\Pagination();
    $pagination->selectable_pages(5);
    $results = \Helpers\Search::search($db, $params['q'], $pagination, $records_per_page);
    if ($results) {
        $rows = \Data\ProductsRepository::get_total_records($db);
        $pagination->records($rows['rows']);
        $pagination->records_per_page($records_per_page);
        $app->render('products/list/list.php', array('type' => 'search', 'page_title' => 'Search', 'search_result' => $results, 'pagination' => $pagination));
    } else {
        no_products($app, 'search', $params['q']);
    }
});
$app->get('/products/:category', function ($category) use($app, $db, $config) {
    if (!in_array($category, $config['products'], true)) {
        $app->notFound();
    }
    $records_per_page = $config['records_per_page'];
    $pagination = new \Zebra\Pagination();
    $pagination->selectable_pages(5);
    $products = \Data\ProductsRepository::get_products_by_category($db, $category, $pagination, $records_per_page);
    if ($products) {