diff options
-rwxr-xr-x | classes/article.php | 2 | ||||
-rw-r--r-- | classes/diskcache.php | 2 | ||||
-rwxr-xr-x | classes/handler/public.php | 18 | ||||
-rwxr-xr-x | classes/pluginhost.php | 11 | ||||
-rw-r--r-- | classes/pref/prefs.php | 2 | ||||
-rwxr-xr-x | classes/rssutils.php | 4 | ||||
-rw-r--r-- | classes/userhelper.php | 4 | ||||
-rw-r--r-- | plugins/af_psql_trgm/init.php | 78 | ||||
-rw-r--r-- | themes/compact.css | 2 | ||||
-rw-r--r-- | themes/compact_night.css | 2 | ||||
-rw-r--r-- | themes/light.css | 2 | ||||
-rw-r--r-- | themes/light/tt-rss.less | 1 | ||||
-rw-r--r-- | themes/light/zoom.less | 1 | ||||
-rw-r--r-- | themes/night.css | 2 | ||||
-rw-r--r-- | themes/night_blue.css | 2 |
15 files changed, 82 insertions, 51 deletions
diff --git a/classes/article.php b/classes/article.php index 5527b7253..3a58f4576 100755 --- a/classes/article.php +++ b/classes/article.php @@ -29,7 +29,7 @@ class Article extends Handler_Protected { if (!$content) { $pluginhost = new PluginHost(); $pluginhost->load_all(PluginHost::KIND_ALL, $owner_uid); - $pluginhost->load_data(); + //$pluginhost->load_data(); foreach ($pluginhost->get_hooks(PluginHost::HOOK_GET_FULL_TEXT) as $p) { $extracted_content = $p->hook_get_full_text($url); diff --git a/classes/diskcache.php b/classes/diskcache.php index c56dc6f14..daa171bf6 100644 --- a/classes/diskcache.php +++ b/classes/diskcache.php @@ -395,7 +395,7 @@ class DiskCache { $tmppluginhost = new PluginHost(); $tmppluginhost->load(PLUGINS, PluginHost::KIND_SYSTEM); - $tmppluginhost->load_data(); + //$tmppluginhost->load_data(); foreach ($tmppluginhost->get_hooks(PluginHost::HOOK_SEND_LOCAL_FILE) as $plugin) { if ($plugin->hook_send_local_file($filename)) return true; diff --git a/classes/handler/public.php b/classes/handler/public.php index 86a82cc61..7fbad5530 100755 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -45,7 +45,7 @@ class Handler_Public extends Handler { $tmppluginhost = new PluginHost(); $tmppluginhost->load(PLUGINS, PluginHost::KIND_ALL); $tmppluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); - $tmppluginhost->load_data(); + //$tmppluginhost->load_data(); $handler = $tmppluginhost->get_feed_handler( PluginHost::feed_to_pfeed_id($feed)); @@ -82,13 +82,14 @@ class Handler_Public extends Handler { while ($line = $result->fetch()) { $line["content_preview"] = Sanitizer::sanitize(truncate_string(strip_tags($line["content"]), 100, '...')); + $line["tags"] = Article::get_article_tags($line["id"], $owner_uid); foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { $line = $p->hook_query_headlines($line); } foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) { - $line = $p->hook_article_export_feed($line, $feed, $is_cat); + $line = $p->hook_article_export_feed($line, $feed, $is_cat, $owner_uid); } $tpl->setVariable('ARTICLE_ID', @@ -121,9 +122,7 @@ class Handler_Public extends Handler { $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url'] ? $line["site_url"] : get_self_url_prefix()), true); $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ? $line['feed_title'] : $feed_title), true); - $tags = Article::get_article_tags($line["id"], $owner_uid); - - foreach ($tags as $tag) { + foreach ($line["tags"] as $tag) { $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true); $tpl->addBlock('category'); } @@ -181,6 +180,7 @@ class Handler_Public extends Handler { while ($line = $result->fetch()) { $line["content_preview"] = Sanitizer::sanitize(truncate_string(strip_tags($line["content_preview"]), 100, '...')); + $line["tags"] = Article::get_article_tags($line["id"], $owner_uid); foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { $line = $p->hook_query_headlines($line, 100); @@ -202,12 +202,10 @@ class Handler_Public extends Handler { if ($line['note']) $article['note'] = $line['note']; if ($article['author']) $article['author'] = $line['author']; - $tags = Article::get_article_tags($line["id"], $owner_uid); - - if (count($tags) > 0) { + if (count($line["tags"]) > 0) { $article['tags'] = array(); - foreach ($tags as $tag) { + foreach ($line["tags"] as $tag) { array_push($article['tags'], $tag); } } @@ -1248,7 +1246,7 @@ class Handler_Public extends Handler { $method = clean($_REQUEST["pmethod"]); $host->load($plugin_name, PluginHost::KIND_USER, 0); - $host->load_data(); + //$host->load_data(); $plugin = $host->get_plugin($plugin_name); diff --git a/classes/pluginhost.php b/classes/pluginhost.php index 3ff658918..f84b07251 100755 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -14,6 +14,7 @@ class PluginHost { private $plugin_actions = array(); private $owner_uid; private $last_registered; + private $data_loaded; private static $instance; const API_VERSION = 2; @@ -268,6 +269,8 @@ class PluginHost { } } } + + $this->load_data(); } function is_system($plugin) { @@ -352,8 +355,8 @@ class PluginHost { } } - function load_data() { - if ($this->owner_uid) { + private function load_data() { + if ($this->owner_uid && !$this->data_loaded && get_schema_version() > 100) { $sth = $this->pdo->prepare("SELECT name, content FROM ttrss_plugin_storage WHERE owner_uid = ?"); $sth->execute([$this->owner_uid]); @@ -361,6 +364,8 @@ class PluginHost { while ($line = $sth->fetch()) { $this->storage[$line["name"]] = unserialize($line["content"]); } + + $this->data_loaded = true; } } @@ -411,6 +416,8 @@ class PluginHost { function get($sender, $name, $default_value = false) { $idx = get_class($sender); + $this->load_data(); + if (isset($this->storage[$idx][$name])) { return $this->storage[$idx][$name]; } else { diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index bce3c171b..55a15efb8 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -911,7 +911,7 @@ class Pref_Prefs extends Handler_Protected { $tmppluginhost = new PluginHost(); $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true); - $tmppluginhost->load_data(true); + //$tmppluginhost->load_data(true); foreach ($tmppluginhost->get_plugins() as $name => $plugin) { $about = $plugin->about(); diff --git a/classes/rssutils.php b/classes/rssutils.php index 857bc2948..dc80dd965 100755 --- a/classes/rssutils.php +++ b/classes/rssutils.php @@ -276,7 +276,7 @@ class RSSUtils { $pluginhost->load(PLUGINS, PluginHost::KIND_ALL); $pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); - $pluginhost->load_data(); + //$pluginhost->load_data(); $basic_info = array(); foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_BASIC_INFO) as $plugin) { @@ -403,7 +403,7 @@ class RSSUtils { $pluginhost->load(PLUGINS, PluginHost::KIND_ALL); $pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); - $pluginhost->load_data(); + //$pluginhost->load_data(); $rss_hash = false; diff --git a/classes/userhelper.php b/classes/userhelper.php index 6a80aed2b..76bb338d4 100644 --- a/classes/userhelper.php +++ b/classes/userhelper.php @@ -80,9 +80,9 @@ class UserHelper { $pluginhost->load($plugins, PluginHost::KIND_USER, $owner_uid); - if (get_schema_version() > 100) { + /*if (get_schema_version() > 100) { $pluginhost->load_data(); - } + }*/ } } diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php index 20e3981ce..a38386d5b 100644 --- a/plugins/af_psql_trgm/init.php +++ b/plugins/af_psql_trgm/init.php @@ -3,6 +3,8 @@ class Af_Psql_Trgm extends Plugin { /* @var PluginHost $host */ private $host; + private $default_similarity = 0.75; + private $default_min_length = 32; function about() { return array(1.0, @@ -37,7 +39,6 @@ class Af_Psql_Trgm extends Plugin { $host->add_hook($host::HOOK_PREFS_EDIT_FEED, $this); $host->add_hook($host::HOOK_PREFS_SAVE_FEED, $this); $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this); - } function get_js() { @@ -124,7 +125,7 @@ class Af_Psql_Trgm extends Plugin { if ($args != "prefFeeds") return; print "<div dojoType=\"dijit.layout.AccordionPane\" - title=\"<i class='material-icons'>extension</i> ".__('Mark similar articles as read')."\">"; + title=\"<i class='material-icons'>extension</i> ".__('Mark similar articles as read (af_psql_trgm)')."\">"; if (DB_TYPE != "pgsql") { print_error("Database type not supported."); @@ -132,17 +133,14 @@ class Af_Psql_Trgm extends Plugin { $res = $this->pdo->query("select 'similarity'::regproc"); - if (!$res->fetch()) { + if (!$res || !$res->fetch()) { print_error("pg_trgm extension not found."); } - $similarity = $this->host->get($this, "similarity"); - $min_title_length = $this->host->get($this, "min_title_length"); + $similarity = $this->host->get($this, "similarity", $this->default_similarity); + $min_title_length = $this->host->get($this, "min_title_length", $this->default_min_length); $enable_globally = $this->host->get($this, "enable_globally"); - if (!$similarity) $similarity = '0.75'; - if (!$min_title_length) $min_title_length = '32'; - print "<form dojoType=\"dijit.form.Form\">"; print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> @@ -197,10 +195,10 @@ class Af_Psql_Trgm extends Plugin { print_button("submit", __("Save"), "class='alt-primary'"); print "</form>"; - $enabled_feeds = $this->host->get($this, "enabled_feeds"); - if (!array($enabled_feeds)) $enabled_feeds = array(); + /* cleanup */ + $enabled_feeds = $this->filter_unknown_feeds( + $this->get_stored_array("enabled_feeds")); - $enabled_feeds = $this->filter_unknown_feeds($enabled_feeds); $this->host->set($this, "enabled_feeds", $enabled_feeds); if (count($enabled_feeds) > 0) { @@ -221,14 +219,11 @@ class Af_Psql_Trgm extends Plugin { } function hook_prefs_edit_feed($feed_id) { - print "<header>".__("Similarity (pg_trgm)")."</header>"; + print "<header>".__("Similarity (af_psql_trgm)")."</header>"; print "<section>"; - $enabled_feeds = $this->host->get($this, "enabled_feeds"); - if (!array($enabled_feeds)) $enabled_feeds = array(); - - $key = array_search($feed_id, $enabled_feeds); - $checked = $key !== false ? "checked" : ""; + $enabled_feeds = $this->get_stored_array("enabled_feeds"); + $checked = in_array($feed_id, $enabled_feeds) ? "checked" : ""; print "<fieldset>"; @@ -241,8 +236,7 @@ class Af_Psql_Trgm extends Plugin { } function hook_prefs_save_feed($feed_id) { - $enabled_feeds = $this->host->get($this, "enabled_feeds"); - if (!is_array($enabled_feeds)) $enabled_feeds = array(); + $enabled_feeds = $this->get_stored_array("enabled_feeds"); $enable = checkbox_to_sql_bool($_POST["trgm_similarity_enabled"]); $key = array_search($feed_id, $enabled_feeds); @@ -265,29 +259,39 @@ class Af_Psql_Trgm extends Plugin { if (DB_TYPE != "pgsql") return $article; $res = $this->pdo->query("select 'similarity'::regproc"); - if (!$res->fetch()) return $article; + if (!$res || !$res->fetch()) return $article; $enable_globally = $this->host->get($this, "enable_globally"); - if (!$enable_globally) { - $enabled_feeds = $this->host->get($this, "enabled_feeds"); - $key = array_search($article["feed"]["id"], $enabled_feeds); - if ($key === false) return $article; + if (!$enable_globally && + !in_array($article["feed"]["id"], + $this->get_stored_array("enabled_feeds"))) { + + return $article; } - $similarity = (float) $this->host->get($this, "similarity"); - if ($similarity < 0.01) return $article; + $similarity = (float) $this->host->get($this, "similarity", $this->default_similarity); - $min_title_length = (int) $this->host->get($this, "min_title_length"); - if (mb_strlen($article["title"]) < $min_title_length) return $article; + if ($similarity < 0.01) { + Debug::log("af_psql_trgm: similarity is set too low ($similarity)", Debug::$LOG_EXTENDED); + return $article; + } + + $min_title_length = (int) $this->host->get($this, "min_title_length", $this->default_min_length); + + if (mb_strlen($article["title"]) < $min_title_length) { + Debug::log("af_psql_trgm: article title is too short (min: $min_title_length)", Debug::$LOG_EXTENDED); + return $article; + } $owner_uid = $article["owner_uid"]; $entry_guid = $article["guid_hashed"]; $title_escaped = $article["title"]; // trgm does not return similarity=1 for completely equal strings + // this seems to be no longer the case (fixed in upstream?) - $sth = $this->pdo->prepare("SELECT COUNT(id) AS nequal + /* $sth = $this->pdo->prepare("SELECT COUNT(id) AS nequal FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id AND date_entered >= NOW() - interval '3 days' AND title = ? AND @@ -303,7 +307,7 @@ class Af_Psql_Trgm extends Plugin { if ($nequal != 0) { $article["force_catchup"] = true; return $article; - } + } */ $sth = $this->pdo->prepare("SELECT MAX(SIMILARITY(title, ?)) AS ms FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id AND @@ -315,14 +319,15 @@ class Af_Psql_Trgm extends Plugin { $row = $sth->fetch(); $similarity_result = $row['ms']; - Debug::log("af_psql_trgm: similarity result: $similarity_result", Debug::$LOG_EXTENDED); + Debug::log("af_psql_trgm: similarity result for $title_escaped: $similarity_result", Debug::$LOG_EXTENDED); if ($similarity_result >= $similarity) { + Debug::log("af_psql_trgm: marking article as read ($similarity_result >= $similarity)", Debug::$LOG_EXTENDED); + $article["force_catchup"] = true; } return $article; - } function api_version() { @@ -345,4 +350,13 @@ class Af_Psql_Trgm extends Plugin { return $tmp; } + private function get_stored_array($name) { + $tmp = $this->host->get($this, $name); + + if (!is_array($tmp)) $tmp = []; + + return $tmp; + } + + } diff --git a/themes/compact.css b/themes/compact.css index c2828c587..a9cd43304 100644 --- a/themes/compact.css +++ b/themes/compact.css @@ -343,6 +343,7 @@ body.ttrss_main .dijitContentPane pre { display: block; max-width: 98%; overflow: auto; + white-space: pre-wrap; } body.ttrss_main div.prefHelp { color: #555; @@ -1880,6 +1881,7 @@ body.ttrss_zoom div.post div.content pre { display: block; max-width: 98%; overflow: auto; + white-space: pre-wrap; } /* rules specific to compact.css */ body.ttrss_main.ttrss_index.flat #feedTree.dijitTree .dijitTreeLabel { diff --git a/themes/compact_night.css b/themes/compact_night.css index 6666787b0..69a2d5034 100644 --- a/themes/compact_night.css +++ b/themes/compact_night.css @@ -343,6 +343,7 @@ body.ttrss_main .dijitContentPane pre { display: block; max-width: 98%; overflow: auto; + white-space: pre-wrap; } body.ttrss_main div.prefHelp { color: #ccc; @@ -1871,6 +1872,7 @@ body.ttrss_zoom div.post div.content pre { display: block; max-width: 98%; overflow: auto; + white-space: pre-wrap; } body.flat.ttrss_main.ttrss_prefs #main, body.flat.ttrss_main.ttrss_prefs #footer { diff --git a/themes/light.css b/themes/light.css index d2f5aa4ee..bd8e9219e 100644 --- a/themes/light.css +++ b/themes/light.css @@ -343,6 +343,7 @@ body.ttrss_main .dijitContentPane pre { display: block; max-width: 98%; overflow: auto; + white-space: pre-wrap; } body.ttrss_main div.prefHelp { color: #555; @@ -1880,4 +1881,5 @@ body.ttrss_zoom div.post div.content pre { display: block; max-width: 98%; overflow: auto; + white-space: pre-wrap; } diff --git a/themes/light/tt-rss.less b/themes/light/tt-rss.less index 5a0f8542d..835585fe6 100644 --- a/themes/light/tt-rss.less +++ b/themes/light/tt-rss.less @@ -394,6 +394,7 @@ body.ttrss_main { display: block; max-width: 98%; overflow: auto; + white-space: pre-wrap; } div.prefHelp { diff --git a/themes/light/zoom.less b/themes/light/zoom.less index e06939ac2..e599bc447 100644 --- a/themes/light/zoom.less +++ b/themes/light/zoom.less @@ -64,6 +64,7 @@ body.ttrss_zoom { display : block; max-width : 98%; overflow : auto; + white-space: pre-wrap; } } } diff --git a/themes/night.css b/themes/night.css index face01932..e47120d8f 100644 --- a/themes/night.css +++ b/themes/night.css @@ -344,6 +344,7 @@ body.ttrss_main .dijitContentPane pre { display: block; max-width: 98%; overflow: auto; + white-space: pre-wrap; } body.ttrss_main div.prefHelp { color: #ccc; @@ -1872,6 +1873,7 @@ body.ttrss_zoom div.post div.content pre { display: block; max-width: 98%; overflow: auto; + white-space: pre-wrap; } body.flat.ttrss_main.ttrss_prefs #main, body.flat.ttrss_main.ttrss_prefs #footer { diff --git a/themes/night_blue.css b/themes/night_blue.css index d5cda927f..de8acffdf 100644 --- a/themes/night_blue.css +++ b/themes/night_blue.css @@ -344,6 +344,7 @@ body.ttrss_main .dijitContentPane pre { display: block; max-width: 98%; overflow: auto; + white-space: pre-wrap; } body.ttrss_main div.prefHelp { color: #ccc; @@ -1872,6 +1873,7 @@ body.ttrss_zoom div.post div.content pre { display: block; max-width: 98%; overflow: auto; + white-space: pre-wrap; } body.flat.ttrss_main.ttrss_prefs #main, body.flat.ttrss_main.ttrss_prefs #footer { |