Exemple #1
0
 function makefeedtree()
 {
     if ($_REQUEST['mode'] != 2) {
         $search = $_SESSION["prefs_feed_search"];
     } else {
         $search = "";
     }
     if ($search) {
         $search_qpart = " AND LOWER(title) LIKE LOWER('%{$search}%')";
     }
     $root = array();
     $root['id'] = 'root';
     $root['name'] = __('Feeds');
     $root['items'] = array();
     $root['type'] = 'category';
     $enable_cats = get_pref('ENABLE_FEED_CATS');
     if ($_REQUEST['mode'] == 2) {
         if ($enable_cats) {
             $cat = $this->feedlist_init_cat(-1);
         } else {
             $cat['items'] = array();
         }
         foreach (array(-4, -3, -1, -2, 0, -6) as $i) {
             array_push($cat['items'], $this->feedlist_init_feed($i));
         }
         /* Plugin feeds for -1 */
         $feeds = PluginHost::getInstance()->get_feeds(-1);
         if ($feeds) {
             foreach ($feeds as $feed) {
                 $feed_id = PluginHost::pfeed_to_feed_id($feed['id']);
                 $item = array();
                 $item['id'] = 'FEED:' . $feed_id;
                 $item['bare_id'] = (int) $feed_id;
                 $item['auxcounter'] = 0;
                 $item['name'] = $feed['title'];
                 $item['checkbox'] = false;
                 $item['error'] = '';
                 $item['icon'] = $feed['icon'];
                 $item['param'] = '';
                 $item['unread'] = 0;
                 //$feed['sender']->get_unread($feed['id']);
                 $item['type'] = 'feed';
                 array_push($cat['items'], $item);
             }
         }
         if ($enable_cats) {
             array_push($root['items'], $cat);
         } else {
             $root['items'] = array_merge($root['items'], $cat['items']);
         }
         $result = $this->dbh->query("SELECT * FROM\n\t\t\t\tttrss_labels2 WHERE owner_uid = " . $_SESSION['uid'] . " ORDER by caption");
         if ($this->dbh->num_rows($result) > 0) {
             if (get_pref('ENABLE_FEED_CATS')) {
                 $cat = $this->feedlist_init_cat(-2);
             } else {
                 $cat['items'] = array();
             }
             while ($line = $this->dbh->fetch_assoc($result)) {
                 $label_id = label_to_feed_id($line['id']);
                 $feed = $this->feedlist_init_feed($label_id, false, 0);
                 $feed['fg_color'] = $line['fg_color'];
                 $feed['bg_color'] = $line['bg_color'];
                 array_push($cat['items'], $feed);
             }
             if ($enable_cats) {
                 array_push($root['items'], $cat);
             } else {
                 $root['items'] = array_merge($root['items'], $cat['items']);
             }
         }
     }
     if ($enable_cats) {
         $show_empty_cats = $_REQUEST['force_show_empty'] || $_REQUEST['mode'] != 2 && !$search;
         $result = $this->dbh->query("SELECT id, title FROM ttrss_feed_categories\n\t\t\t\tWHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat IS NULL ORDER BY order_id, title");
         while ($line = $this->dbh->fetch_assoc($result)) {
             $cat = array();
             $cat['id'] = 'CAT:' . $line['id'];
             $cat['bare_id'] = (int) $line['id'];
             $cat['auxcounter'] = 0;
             $cat['name'] = $line['title'];
             $cat['items'] = array();
             $cat['checkbox'] = false;
             $cat['type'] = 'category';
             $cat['unread'] = 0;
             $cat['child_unread'] = 0;
             $cat['items'] = $this->get_category_items($line['id']);
             $num_children = $this->calculate_children_count($cat);
             $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', $num_children), $num_children);
             if ($num_children > 0 || $show_empty_cats) {
                 array_push($root['items'], $cat);
             }
             $root['param'] += count($cat['items']);
         }
         /* Uncategorized is a special case */
         $cat = array();
         $cat['id'] = 'CAT:0';
         $cat['bare_id'] = 0;
         $cat['auxcounter'] = 0;
         $cat['name'] = __("Uncategorized");
         $cat['items'] = array();
         $cat['type'] = 'category';
         $cat['checkbox'] = false;
         $cat['unread'] = 0;
         $cat['child_unread'] = 0;
         $feed_result = $this->dbh->query("SELECT id, title,last_error,\n\t\t\t\t" . SUBSTRING_FOR_DATE . "(last_updated,1,19) AS last_updated\n\t\t\t\tFROM ttrss_feeds\n\t\t\t\tWHERE cat_id IS NULL AND owner_uid = " . $_SESSION["uid"] . "{$search_qpart} ORDER BY order_id, title");
         while ($feed_line = $this->dbh->fetch_assoc($feed_result)) {
             $feed = array();
             $feed['id'] = 'FEED:' . $feed_line['id'];
             $feed['bare_id'] = (int) $feed_line['id'];
             $feed['auxcounter'] = 0;
             $feed['name'] = $feed_line['title'];
             $feed['checkbox'] = false;
             $feed['error'] = $feed_line['last_error'];
             $feed['icon'] = getFeedIcon($feed_line['id']);
             $feed['param'] = make_local_datetime($feed_line['last_updated'], true);
             $feed['unread'] = 0;
             $feed['type'] = 'feed';
             array_push($cat['items'], $feed);
         }
         $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
         if (count($cat['items']) > 0 || $show_empty_cats) {
             array_push($root['items'], $cat);
         }
         $num_children = $this->calculate_children_count($root);
         $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', $num_children), $num_children);
     } else {
         $feed_result = $this->dbh->query("SELECT id, title, last_error,\n\t\t\t\t" . SUBSTRING_FOR_DATE . "(last_updated,1,19) AS last_updated\n\t\t\t\tFROM ttrss_feeds\n\t\t\t\tWHERE owner_uid = " . $_SESSION["uid"] . "{$search_qpart} ORDER BY order_id, title");
         while ($feed_line = $this->dbh->fetch_assoc($feed_result)) {
             $feed = array();
             $feed['id'] = 'FEED:' . $feed_line['id'];
             $feed['bare_id'] = (int) $feed_line['id'];
             $feed['auxcounter'] = 0;
             $feed['name'] = $feed_line['title'];
             $feed['checkbox'] = false;
             $feed['error'] = $feed_line['last_error'];
             $feed['icon'] = getFeedIcon($feed_line['id']);
             $feed['param'] = make_local_datetime($feed_line['last_updated'], true);
             $feed['unread'] = 0;
             $feed['type'] = 'feed';
             array_push($root['items'], $feed);
         }
         $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
     }
     $fl = array();
     $fl['identifier'] = 'id';
     $fl['label'] = 'name';
     if ($_REQUEST['mode'] != 2) {
         $fl['items'] = array($root);
     } else {
         $fl['items'] =& $root['items'];
     }
     return $fl;
 }
Exemple #2
0
function getVirtCounters()
{
    $ret_arr = array();
    for ($i = 0; $i >= -4; $i--) {
        $count = getFeedUnread($i);
        if ($i == 0 || $i == -1 || $i == -2) {
            $auxctr = getFeedArticles($i, false);
        } else {
            $auxctr = 0;
        }
        $cv = array("id" => $i, "counter" => (int) $count, "auxcounter" => $auxctr);
        //			if (get_pref('EXTENDED_FEEDLIST'))
        //				$cv["xmsg"] = getFeedArticles($i)." ".__("total");
        array_push($ret_arr, $cv);
    }
    $feeds = PluginHost::getInstance()->get_feeds(-1);
    if (is_array($feeds)) {
        foreach ($feeds as $feed) {
            $cv = array("id" => PluginHost::pfeed_to_feed_id($feed['id']), "counter" => $feed['sender']->get_unread($feed['id']));
            if (method_exists($feed['sender'], 'get_total')) {
                $cv["auxcounter"] = $feed['sender']->get_total($feed['id']);
            }
            array_push($ret_arr, $cv);
        }
    }
    return $ret_arr;
}