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, %d)", $similarity, $enable_globally);
}
function init($host) {
$this->host = $host;
$host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
$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 get_js() {
return file_get_contents(__DIR__ . "/init.js");
}
/** @return void */
function showrelated() {
$id = (int) $_REQUEST['id'];
$owner_uid = $_SESSION["uid"];
$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]);
if ($row = $sth->fetch()) {
$title = $row['title'];
print "
$title
";
if (Config::get(Config::DB_TYPE) == "pgsql") {
$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 = :owner_uid AND
ttrss_entries.id != :id AND
date_entered >= NOW() - INTERVAL '2 weeks'
ORDER BY
sm DESC, date_entered DESC
LIMIT 10");
} else {
$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,
(MATCH (ttrss_entries.title) AGAINST (:title) / LENGTH(ttrss_entries.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 = :owner_uid AND
ttrss_entries.id != :id AND
date_entered >= DATE_SUB(NOW(), INTERVAL 2 WEEK)
ORDER BY
sm DESC, date_entered DESC
LIMIT 10");
}
$sth->execute(['title' => $title, "owner_uid" => $owner_uid, "id" => $id]);
print "