summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2013-04-18 12:27:34 +0400
committerAndrew Dolgov <[email protected]>2013-04-18 12:27:34 +0400
commit1ffe3391f902c4baa984982f19e61a0e45de21ff (patch)
tree4b0b7554c42a6df823db9cf90b925151c796f696 /include
parent52d88392dad52ec4d5607fef7479d74dee8b8be4 (diff)
make pluginhost a singleton
Diffstat (limited to 'include')
-rw-r--r--include/functions.php65
-rw-r--r--include/rssfuncs.php12
2 files changed, 28 insertions, 49 deletions
diff --git a/include/functions.php b/include/functions.php
index 3c8e9d62c..9f890eba7 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -9,7 +9,6 @@
$fetch_last_error_code = false;
$fetch_last_content_type = false;
$fetch_curl_used = false;
- $pluginhost = false;
mb_internal_encoding("UTF-8");
date_default_timezone_set('UTC');
@@ -622,8 +621,7 @@
if (!SINGLE_USER_MODE) {
$user_id = false;
- global $pluginhost;
- foreach ($pluginhost->get_hooks($pluginhost::HOOK_AUTH_USER) as $plugin) {
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_AUTH_USER) as $plugin) {
$user_id = (int) $plugin->authenticate($login, $password);
@@ -734,11 +732,10 @@
if ($owner_uid) {
$plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
- global $pluginhost;
- $pluginhost->load($plugins, $pluginhost::KIND_USER, $owner_uid);
+ PluginHost::getInstance()->load($plugins, PluginHost::KIND_USER, $owner_uid);
if (get_schema_version() > 100) {
- $pluginhost->load_data();
+ PluginHost::getInstance()->load_data();
}
}
}
@@ -1443,18 +1440,13 @@
array_push($ret_arr, $cv);
}
- global $pluginhost;
-
- if ($pluginhost) {
- $feeds = $pluginhost->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']));
+ $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']));
array_push($ret_arr, $cv);
- }
}
}
@@ -1982,8 +1974,7 @@
"help_dialog" => __("Show help dialog"))
);
- global $pluginhost;
- foreach ($pluginhost->get_hooks($pluginhost::HOOK_HOTKEY_INFO) as $plugin) {
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HOTKEY_INFO) as $plugin) {
$hotkeys = $plugin->hook_hotkey_info($hotkeys);
}
@@ -2059,8 +2050,7 @@
$hotkeys["^(40)|Ctrl-down"] = "next_article_noscroll";
}
- global $pluginhost;
- foreach ($pluginhost->get_hooks($pluginhost::HOOK_HOTKEY_MAP) as $plugin) {
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HOTKEY_MAP) as $plugin) {
$hotkeys = $plugin->hook_hotkey_map($hotkeys);
}
@@ -2753,18 +2743,14 @@
$disallowed_attributes = array('id', 'style', 'class');
- global $pluginhost;
-
- if (isset($pluginhost)) {
- foreach ($pluginhost->get_hooks($pluginhost::HOOK_SANITIZE) as $plugin) {
- $retval = $plugin->hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes);
- if (is_array($retval)) {
- $doc = $retval[0];
- $allowed_elements = $retval[1];
- $disallowed_attributes = $retval[2];
- } else {
- $doc = $retval;
- }
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SANITIZE) as $plugin) {
+ $retval = $plugin->hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes);
+ if (is_array($retval)) {
+ $doc = $retval[0];
+ $allowed_elements = $retval[1];
+ $disallowed_attributes = $retval[2];
+ } else {
+ $doc = $retval;
}
}
@@ -3065,9 +3051,7 @@
$line["content"] = sanitize($line["content"], false, $owner_uid, $line["site_url"]);
- global $pluginhost;
-
- foreach ($pluginhost->get_hooks($pluginhost::HOOK_RENDER_ARTICLE) as $p) {
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE) as $p) {
$line = $p->hook_render_article($line);
}
@@ -3142,8 +3126,7 @@
id=\"ATSTRTIP-$id\" connectId=\"ATSTR-$id\"
position=\"below\">$tags_str_full</div>";
- global $pluginhost;
- foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_BUTTON) as $p) {
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_BUTTON) as $p) {
$rv['content'] .= $p->hook_article_button($line);
}
@@ -3154,8 +3137,7 @@
$rv['content'] .= "</div>";
$rv['content'] .= "<div clear='both'>";
- global $pluginhost;
- foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_LEFT_BUTTON) as $p) {
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_LEFT_BUTTON) as $p) {
$rv['content'] .= $p->hook_article_left_button($line);
}
@@ -3361,10 +3343,7 @@
}
function init_plugins() {
- global $pluginhost;
-
- $pluginhost = new PluginHost(Db::get());
- $pluginhost->load(PLUGINS, $pluginhost::KIND_ALL);
+ PluginHost::getInstance()->load(PLUGINS, PluginHost::KIND_ALL);
return true;
}
diff --git a/include/rssfuncs.php b/include/rssfuncs.php
index b2d7e0c59..9c80a72d6 100644
--- a/include/rssfuncs.php
+++ b/include/rssfuncs.php
@@ -343,15 +343,15 @@
}
}
- $pluginhost = new PluginHost(Db::get());
+ $pluginhost = new PluginHost();
$pluginhost->set_debug($debug_enabled);
$user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
- $pluginhost->load(PLUGINS, $pluginhost::KIND_ALL);
- $pluginhost->load($user_plugins, $pluginhost::KIND_USER, $owner_uid);
+ $pluginhost->load(PLUGINS, PluginHost::KIND_ALL);
+ $pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid);
$pluginhost->load_data();
- foreach ($pluginhost->get_hooks($pluginhost::HOOK_FEED_FETCHED) as $plugin) {
+ foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_FETCHED) as $plugin) {
$feed_data = $plugin->hook_feed_fetched($feed_data);
}
@@ -388,7 +388,7 @@
}
// We use local pluginhost here because we need to load different per-user feed plugins
- $pluginhost->run_hooks($pluginhost::HOOK_FEED_PARSED, "hook_feed_parsed", $rss);
+ $pluginhost->run_hooks(PluginHost::HOOK_FEED_PARSED, "hook_feed_parsed", $rss);
if ($debug_enabled) {
_debug("update_rss_feed: processing feed data...");
@@ -673,7 +673,7 @@
"author" => $entry_author,
"stored" => $stored_article);
- foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_FILTER) as $plugin) {
+ foreach ($pluginhost->get_hooks(PluginHost::HOOK_ARTICLE_FILTER) as $plugin) {
$article = $plugin->hook_article_filter($article);
}