From a413f53ebff7d28033090dc343d1ed1d0993ae0b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 27 Mar 2013 16:14:27 +0400 Subject: [PATCH] add experimental base for plugin vfeeds (3 pane mode not yet implemented) --- classes/feeds.php | 35 +++++++++++++++++++++--- classes/pluginhost.php | 39 +++++++++++++++++++++++++++ classes/pref/feeds.php | 26 ++++++++++++++++++ include/functions.php | 15 +++++++++++ plugins/example_vfeed/init.php | 49 ++++++++++++++++++++++++++++++++++ 5 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 plugins/example_vfeed/init.php diff --git a/classes/feeds.php b/classes/feeds.php index f38e621f..52fec80e 100644 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -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); diff --git a/classes/pluginhost.php b/classes/pluginhost.php index 0ef17b77..5f584cd0 100644 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -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); + } + } ?> diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index a6811f3f..d2e69c50 100644 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -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 { diff --git a/include/functions.php b/include/functions.php index b2f1a655..c2bd7673 100644 --- a/include/functions.php +++ b/include/functions.php @@ -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; @@ -1430,6 +1431,20 @@ 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 index 00000000..e646809a --- /dev/null +++ b/plugins/example_vfeed/init.php @@ -0,0 +1,49 @@ +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; + } +} +?> -- 2.39.5