X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=plugins%2Faf_psql_trgm%2Finit.php;h=fe5b1a959909ce54fc2c9c4583bbb3263c0584f1;hb=c10a43069ec1e71b6608574a81fb29c76919e132;hp=f55aa115621dfc916e0b3b4ad969aee297a839ab;hpb=9a121298e15856638be6f3e44593ab06a172bc17;p=tt-rss.git
diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php
index f55aa115..fe5b1a95 100644
--- a/plugins/af_psql_trgm/init.php
+++ b/plugins/af_psql_trgm/init.php
@@ -1,6 +1,7 @@
1) $similarity = 1;
@@ -22,8 +24,9 @@ class Af_Psql_Trgm extends Plugin {
$this->host->set($this, "similarity", $similarity);
$this->host->set($this, "min_title_length", $min_title_length);
+ $this->host->set($this, "enable_globally", $enable_globally);
- echo T_sprintf("Data saved (%s)", $similarity);
+ echo T_sprintf("Data saved (%s, %d)", $similarity, $enable_globally);
}
function init($host) {
@@ -33,92 +36,177 @@ class Af_Psql_Trgm extends Plugin {
$host->add_hook($host::HOOK_PREFS_TAB, $this);
$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 hook_prefs_tab($args) {
- if ($args != "prefFeeds") return;
+ function get_js() {
+ return file_get_contents(__DIR__ . "/init.js");
+ }
- print "
";
+ function showrelated() {
+ $id = (int) $_REQUEST['param'];
+ $owner_uid = $_SESSION["uid"];
- if (DB_TYPE != "pgsql") {
- print_error("Database type not supported.");
- }
+ $sth = $this->pdo->prepare("SELECT title FROM ttrss_entries, ttrss_user_entries
+ WHERE ref_id = id AND id = ? AND owner_uid = ?");
+ $sth->execute([$id, $owner_uid]);
- $result = db_query("select 'similarity'::regproc");
+ if ($row = $sth->fetch()) {
- if (db_num_rows($result) == 0) {
- print_error("pg_trgm extension not found.");
- }
+ $title = $row['title'];
+
+ print "
$title
";
+
+ $sth = $this->pdo->prepare("SELECT ttrss_entries.id AS id,
+ feed_id,
+ ttrss_entries.title AS title,
+ updated, link,
+ ttrss_feeds.title AS feed_title,
+ SIMILARITY(ttrss_entries.title, '$title') AS sm
+ FROM
+ ttrss_entries, ttrss_user_entries LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id)
+ WHERE
+ ttrss_entries.id = ref_id AND
+ ttrss_user_entries.owner_uid = ? AND
+ ttrss_entries.id != ? AND
+ date_entered >= NOW() - INTERVAL '2 weeks'
+ ORDER BY
+ sm DESC, date_entered DESC
+ LIMIT 10");
+
+ $sth->execute([$owner_uid, $id]);
+
+ print "
";
- $similarity = $this->host->get($this, "similarity");
- $min_title_length = $this->host->get($this, "min_title_length");
-
- if (!$similarity) $similarity = '0.75';
- if (!$min_title_length) $min_title_length = '32';
-
- print "