]> git.wh0rd.org - tt-rss.git/commitdiff
add experimental base for plugin vfeeds (3 pane mode not yet
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 27 Mar 2013 12:14:27 +0000 (16:14 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 27 Mar 2013 12:15:25 +0000 (16:15 +0400)
implemented)

classes/feeds.php
classes/pluginhost.php
classes/pref/feeds.php
include/functions.php
plugins/example_vfeed/init.php [new file with mode: 0644]

index f38e621f734317808e970529544b6c10bbee47f6..52fec80e7bf6e417aff0831a7a8b2cc640d4c085 100644 (file)
@@ -217,9 +217,38 @@ class Feeds extends Handler_Protected {
                    $search_mode = $method;
                }
 //             error_log("search_mode: " . $search_mode);
-               $qfh_ret = queryFeedHeadlines($this->link, $feed, $limit, $view_mode, $cat_view,
-                       $search, $search_mode, $override_order, $offset, 0,
-                       false, 0, $include_children);
+
+               if (!$cat_view && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX) {
+                       global $pluginhost;
+
+                       $handler = $pluginhost->get_feed_handler(
+                               PluginHost::feed_to_pfeed_id($feed));
+
+               //      function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false, $ignore_vfeed_group = false) {
+
+                       if ($handler) {
+                               $options = array(
+                                       "limit" => $limit,
+                                       "view_mode" => $view_mode,
+                                       "cat_view" => $cat_view,
+                                       "search" => $search,
+                                       "search_mode" => $search_mode,
+                                       "override_order" => $override_order,
+                                       "offset" => $offset,
+                                       "owner_uid" => $_SESSION["uid"],
+                                       "filter" => false,
+                                       "since_id" => 0,
+                                       "include_children" => $include_children);
+
+                               $qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed),
+                                       $options);
+                       }
+
+               } else {
+                       $qfh_ret = queryFeedHeadlines($this->link, $feed, $limit, $view_mode, $cat_view,
+                               $search, $search_mode, $override_order, $offset, 0,
+                               false, 0, $include_children);
+               }
 
                if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
 
index 0ef17b77e31359024d394959a15e01cc7e7c8233..5f584cd00c9eab6a8cb52dd80f80fabd9443bf7b 100644 (file)
@@ -6,6 +6,7 @@ class PluginHost {
        private $handlers = array();
        private $commands = array();
        private $storage = array();
+       private $feeds = array();
        private $owner_uid;
        private $debug;
 
@@ -301,5 +302,43 @@ class PluginHost {
        function get_debug() {
                return $this->debug;
        }
+
+       // Plugin feed functions are *EXPERIMENTAL*!
+
+       // cat_id: only -1 is supported (Special)
+       function add_feed($cat_id, $title, $icon, $sender) {
+               if (!$this->feeds[$cat_id]) $this->feeds[$cat_id] = array();
+
+               $id = count($this->feeds[$cat_id]);
+
+               array_push($this->feeds[$cat_id],
+                       array('id' => $id, 'title' => $title, 'sender' => $sender, 'icon' => $icon));
+
+               return $id;
+       }
+
+       function get_feeds($cat_id) {
+               return $this->feeds[$cat_id];
+       }
+
+       // convert feed_id (e.g. -129) to pfeed_id first
+       function get_feed_handler($pfeed_id) {
+               foreach ($this->feeds as $cat) {
+                       foreach ($cat as $feed) {
+                               if ($feed['id'] == $pfeed_id) {
+                                       return $feed['sender'];
+                               }
+                       }
+               }
+       }
+
+       static function pfeed_to_feed_id($label) {
+               return PLUGIN_FEED_BASE_INDEX - 1 - abs($label);
+       }
+
+       static function feed_to_pfeed_id($feed) {
+               return PLUGIN_FEED_BASE_INDEX - 1 + abs($feed);
+       }
+
 }
 ?>
index a6811f3fc1bfeda80e54ba0e574ebb6b7bf66d13..d2e69c502e7238aeaafa9bf3b6cd53e4a973a2fb 100644 (file)
@@ -115,6 +115,32 @@ class Pref_Feeds extends Handler_Protected {
                                array_push($cat['items'], $this->feedlist_init_feed($i));
                        }
 
+                       /* Plugin feeds for -1 */
+
+                       global $pluginhost;
+
+                       $feeds = $pluginhost->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['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 {
index b2f1a655959540c2338bad9affee5326c8d09928..c2bd7673b74e2d8888aa8c5d53a2308c0572c5d1 100644 (file)
@@ -3,6 +3,7 @@
        define('SCHEMA_VERSION', 109);
 
        define('LABEL_BASE_INDEX', -1024);
+       define('PLUGIN_FEED_BASE_INDEX', -128);
 
        $fetch_last_error = false;
        $pluginhost = false;
                        array_push($ret_arr, $cv);
                }
 
+               global $pluginhost;
+
+               if ($pluginhost) {
+                       $feeds = $pluginhost->get_feeds(-1);
+
+                       foreach ($feeds as $feed) {
+                               $cv = array("id" => PluginHost::pfeed_to_feed_id($feed['id']),
+                                       "counter" => $feed['sender']->get_unread($feed['id']));
+
+                               array_push($ret_arr, $cv);
+                       }
+
+               }
+
                return $ret_arr;
        }
 
diff --git a/plugins/example_vfeed/init.php b/plugins/example_vfeed/init.php
new file mode 100644 (file)
index 0000000..e646809
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+class Example_VFeed extends Plugin {
+
+       // Demonstrates how to create a dummy special feed and chain
+       // headline generation to queryFeedHeadlines();
+
+       // Not implemented yet: stuff for 3 panel mode
+
+       private $link;
+       private $host;
+       private $dummy_id;
+
+       function about() {
+               return array(1.0,
+                       "Example vfeed plugin",
+                       "fox",
+                       false);
+       }
+
+       function init($host) {
+               $this->link = $host->get_link();
+               $this->host = $host;
+
+               $this->dummy_id = $host->add_feed(-1, 'Dummy feed', 'images/pub_set.svg', $this);
+       }
+
+       function get_unread($feed_id) {
+               return 1234;
+       }
+
+       function get_headlines($feed_id, $options) {
+               $qfh_ret = queryFeedHeadlines($this->link, -4,
+                       $options['limit'],
+                       $options['view_mode'], $options['cat_view'],
+                       $options['search'],
+                       $options['search_mode'],
+                       $options['override_order'],
+                       $options['offset'],
+                       $options['owner_uid'],
+                       $options['filter'],
+                       $options['since_id'],
+                       $options['include_children']);
+
+               $qfh_ret[1] = 'Dummy feed';
+
+               return $qfh_ret;
+       }
+}
+?>