1
0
mirror of https://git.tt-rss.org/git/tt-rss.git synced 2026-02-10 16:01:33 +00:00

make pluginhost a singleton

This commit is contained in:
Andrew Dolgov
2013-04-18 12:27:34 +04:00
parent 52d88392da
commit 1ffe3391f9
19 changed files with 89 additions and 148 deletions

View File

@@ -341,8 +341,7 @@ class API extends Handler {
"score" => (int)$line["score"]
);
global $pluginhost;
foreach ($pluginhost->get_hooks($pluginhost::HOOK_RENDER_ARTICLE_API) as $p) {
foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_API) as $p) {
$article = $p->hook_render_article_api(array("article" => $article));
}
@@ -466,9 +465,7 @@ class API extends Handler {
}
function index($method) {
global $pluginhost;
$plugin = $pluginhost->get_api_method(strtolower($method));
$plugin = PluginHost::getInstance()->get_api_method(strtolower($method));
if ($plugin && method_exists($plugin, $method)) {
$reply = $plugin->$method();
@@ -697,8 +694,7 @@ class API extends Handler {
$headline_row["author"] = $line["author"];
$headline_row["score"] = (int)$line["score"];
global $pluginhost;
foreach ($pluginhost->get_hooks($pluginhost::HOOK_RENDER_ARTICLE_API) as $p) {
foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_API) as $p) {
$headline_row = $p->hook_render_article_api(array("headline" => $headline_row));
}

View File

@@ -108,14 +108,12 @@ class Feeds extends Handler_Protected {
}
global $pluginhost;
if ($pluginhost->get_plugin("mail")) {
if (PluginHost::getInstance()->get_plugin("mail")) {
$reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
"</option>";
}
if ($pluginhost->get_plugin("mailto")) {
if (PluginHost::getInstance()->get_plugin("mailto")) {
$reply .= "<option value=\"mailtoArticle(false)\">".__('Forward by email').
"</option>";
}
@@ -132,7 +130,7 @@ class Feeds extends Handler_Protected {
//$reply .= "</h2";
foreach ($pluginhost->get_hooks($pluginhost::HOOK_HEADLINE_TOOLBAR_BUTTON) as $p) {
foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HEADLINE_TOOLBAR_BUTTON) as $p) {
echo $p->hook_headline_toolbar_button($feed_id, $is_cat);
}
@@ -214,9 +212,7 @@ class Feeds extends Handler_Protected {
// error_log("search_mode: " . $search_mode);
if (!$cat_view && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) {
global $pluginhost;
$handler = $pluginhost->get_feed_handler(
$handler = PluginHost::getInstance()->get_feed_handler(
PluginHost::feed_to_pfeed_id($feed));
// function queryFeedHeadlines($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) {
@@ -273,8 +269,6 @@ class Feeds extends Handler_Protected {
}
} */
global $pluginhost;
if ($this->dbh->num_rows($result) > 0) {
$lnum = $offset;
@@ -521,7 +515,7 @@ class Feeds extends Handler_Protected {
$line["content"] = sanitize($line["content_preview"],
sql_bool_to_bool($line['hide_images']), false, $entry_site_url);
foreach ($pluginhost->get_hooks($pluginhost::HOOK_RENDER_ARTICLE_CDM) as $p) {
foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_CDM) as $p) {
$line = $p->hook_render_article_cdm($line);
}
@@ -679,7 +673,7 @@ class Feeds extends Handler_Protected {
$reply['content'] .= "<div class=\"cdmFooter\">";
foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_LEFT_BUTTON) as $p) {
foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_LEFT_BUTTON) as $p) {
$reply['content'] .= $p->hook_article_left_button($line);
}
@@ -713,7 +707,7 @@ class Feeds extends Handler_Protected {
// $reply['content'] .= "$marked_pic";
// $reply['content'] .= "$published_pic";
foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_BUTTON) as $p) {
foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_BUTTON) as $p) {
$reply['content'] .= $p->hook_article_button($line);
}

View File

@@ -377,8 +377,7 @@ class Handler_Public extends Handler {
cleanup_tags(14, 50000);
global $pluginhost;
$pluginhost->run_hooks($pluginhost::HOOK_UPDATE_TASK, "hook_update_task", $op);
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", $op);
}

View File

@@ -5,9 +5,7 @@ class PluginHandler extends Handler_Protected {
}
function catchall($method) {
global $pluginhost;
$plugin = $pluginhost->get_plugin($_REQUEST["plugin"]);
$plugin = PluginHost::getInstance()->get_plugin($_REQUEST["plugin"]);
if ($plugin) {
if (method_exists($plugin, $method)) {

View File

@@ -10,6 +10,7 @@ class PluginHost {
private $api_methods = array();
private $owner_uid;
private $debug;
private static $instance;
const HOOK_ARTICLE_BUTTON = 1;
const HOOK_ARTICLE_FILTER = 2;
@@ -35,13 +36,24 @@ class PluginHost {
const KIND_SYSTEM = 2;
const KIND_USER = 3;
function __construct($dbh) {
$this->dbh = $dbh;
function __construct($ignored = false) {
$this->dbh = Db::get();
$this->storage = $_SESSION["plugin_storage"];
if (!$this->storage) $this->storage = array();
}
private function __clone() {
//
}
public static function getInstance() {
if (self::$instance == null)
self::$instance = new self();
return self::$instance;
}
private function register_plugin($name, $plugin) {
//array_push($this->plugins, $plugin);
$this->plugins[$name] = $plugin;

View File

@@ -124,9 +124,7 @@ class Pref_Feeds extends Handler_Protected {
/* Plugin feeds for -1 */
global $pluginhost;
$feeds = $pluginhost->get_feeds(-1);
$feeds = PluginHost::getInstance()->get_feeds(-1);
if ($feeds) {
foreach ($feeds as $feed) {
@@ -1456,8 +1454,7 @@ class Pref_Feeds extends Handler_Protected {
print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("Public OPML URL")."','pubOPMLUrl')\">".
__('Display published OPML URL')."</button> ";
global $pluginhost;
$pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
"hook_prefs_tab_section", "prefFeedsOPML");
print "</div>"; # pane
@@ -1503,15 +1500,12 @@ class Pref_Feeds extends Handler_Protected {
print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearArticleAccessKeys()\">".
__('Unshare all articles')."</button> ";
global $pluginhost;
$pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
"hook_prefs_tab_section", "prefFeedsPublishedGenerated");
print "</div>"; #pane
global $pluginhost;
$pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB,
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
"hook_prefs_tab", "prefFeeds");
print "</div>"; #container

View File

@@ -706,8 +706,7 @@ class Pref_Filters extends Handler_Protected {
print "</div>"; #pane
global $pluginhost;
$pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB,
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
"hook_prefs_tab", "prefFilters");
print "</div>"; #container

View File

@@ -319,8 +319,7 @@ class Pref_Labels extends Handler_Protected {
print "</div>"; #pane
global $pluginhost;
$pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB,
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
"hook_prefs_tab", "prefLabels");
print "</div>"; #container

View File

@@ -79,8 +79,7 @@ class Pref_Prefs extends Handler_Protected {
return;
}
global $pluginhost;
$authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
$authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
if (method_exists($authenticator, "change_password")) {
print $authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw);
@@ -255,10 +254,7 @@ class Pref_Prefs extends Handler_Protected {
print "</form>";
if ($_SESSION["auth_module"]) {
global $pluginhost;
$authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
$authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
} else {
$authenticator = false;
}
@@ -436,8 +432,7 @@ class Pref_Prefs extends Handler_Protected {
}
}
global $pluginhost;
$pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
"hook_prefs_tab_section", "prefPrefsAuth");
print "</div>"; #pane
@@ -675,8 +670,7 @@ class Pref_Prefs extends Handler_Protected {
print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"boolean_prefs\" value=\"$listed_boolean_prefs\">";
global $pluginhost;
$pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
"hook_prefs_tab_section", "prefPrefsPrefsInside");
print '</div>'; # inside pane
@@ -712,8 +706,7 @@ class Pref_Prefs extends Handler_Protected {
<label for='prefs_show_advanced'>" .
__("Show additional preferences") . "</label>"; */
global $pluginhost;
$pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
"hook_prefs_tab_section", "prefPrefsPrefsOutside");
print "</form>";
@@ -877,8 +870,7 @@ class Pref_Prefs extends Handler_Protected {
print "</div>"; #pane
global $pluginhost;
$pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB,
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
"hook_prefs_tab", "prefPrefs");
print "</div>"; #container
@@ -918,8 +910,7 @@ class Pref_Prefs extends Handler_Protected {
$password = $_REQUEST["password"];
$otp = $_REQUEST["otp"];
global $pluginhost;
$authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
$authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
if ($authenticator->check_password($_SESSION["uid"], $password)) {
@@ -951,8 +942,7 @@ class Pref_Prefs extends Handler_Protected {
function otpdisable() {
$password = $this->dbh->escape_string($_REQUEST["password"]);
global $pluginhost;
$authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
$authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
if ($authenticator->check_password($_SESSION["uid"], $password)) {
@@ -978,8 +968,7 @@ class Pref_Prefs extends Handler_Protected {
function clearplugindata() {
$name = $this->dbh->escape_string($_REQUEST["name"]);
global $pluginhost;
$pluginhost->clear_data($pluginhost->get_plugin($name));
PluginHost::getInstance()->clear_data(PluginHost::getInstance()->get_plugin($name));
}
function customizeCSS() {

View File

@@ -66,8 +66,7 @@ class Pref_System extends Handler_Protected {
print "</div>";
global $pluginhost;
$pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB,
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
"hook_prefs_tab", "prefSystem");
print "</div>"; #container

View File

@@ -453,8 +453,7 @@ class Pref_Users extends Handler_Protected {
print "</div>"; #pane
global $pluginhost;
$pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB,
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
"hook_prefs_tab", "prefUsers");
print "</div>"; #container