From 853cc128d6e262b4a7a693c6321a406674837d73 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 17 Jun 2015 10:36:11 +0300 Subject: add placeholder stuff for af_sort_bayes --- plugins/af_sort_bayes/init.php | 111 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 plugins/af_sort_bayes/init.php (limited to 'plugins/af_sort_bayes/init.php') diff --git a/plugins/af_sort_bayes/init.php b/plugins/af_sort_bayes/init.php new file mode 100644 index 000000000..213c6aede --- /dev/null +++ b/plugins/af_sort_bayes/init.php @@ -0,0 +1,111 @@ +host = $host; + $this->dbh = Db::get(); + + $this->init_database(); + + $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); + $host->add_hook($host::HOOK_PREFS_TAB, $this); + $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this); + + } + + function trainArticle() { + $article_id = (int) $_REQUEST["article_id"]; + $train_up = sql_bool_to_bool($_REQUEST["train_up"]); + + print "FIXME: $article_id :: $train_up"; + + } + + function get_js() { + return file_get_contents(__DIR__ . "/init.js"); + } + + function hook_article_button($line) { + return "" . + ""; + + } + + function init_database() { + $prefix = "ttrss_plugin_af_sort_bayes"; + + /*$this->dbh->query("DROP TABLE IF EXISTS ${prefix}_references", false); + $this->dbh->query("DROP TABLE IF EXISTS ${prefix}_categories", false); + $this->dbh->query("DROP TABLE IF EXISTS ${prefix}_wordfreqs", false);*/ + + $this->dbh->query("BEGIN"); + + // PG only for the time being + + $this->dbh->query("CREATE TABLE IF NOT EXISTS ${prefix}_categories ( + id SERIAL NOT NULL PRIMARY KEY, + category varchar(100) NOT NULL DEFAULT '', + probability DOUBLE PRECISION NOT NULL DEFAULT '0', + owner_uid INTEGER NOT NULL REFERENCES ttrss_users(id) ON DELETE CASCADE, + word_count BIGINT NOT NULL DEFAULT '0')"); + + $this->dbh->query("CREATE TABLE IF NOT EXISTS ${prefix}_documents ( + id SERIAL NOT NULL PRIMARY KEY, + document varchar(250) NOT NULL DEFAULT '', + category_id INTEGER NOT NULL REFERENCES ${prefix}_categories(id) ON DELETE CASCADE, + owner_uid INTEGER NOT NULL REFERENCES ttrss_users(id) ON DELETE CASCADE, + content text NOT NULL)"); + + $this->dbh->query("CREATE TABLE IF NOT EXISTS ${prefix}_wordfreqs ( + word varchar(100) NOT NULL DEFAULT '', + category_id INTEGER NOT NULL REFERENCES ${prefix}_categories(id) ON DELETE CASCADE, + owner_uid INTEGER NOT NULL REFERENCES ttrss_users(id) ON DELETE CASCADE, + count BIGINT NOT NULL DEFAULT '0')"); + + $this->dbh->query("COMMIT"); + } + + function hook_prefs_tab($args) { + if ($args != "prefPrefs") return; + + print "
"; + + // + + print "
"; + } + + function hook_article_filter($article) { + $owner_uid = $article["owner_uid"]; + + + return $article; + + } + + function api_version() { + return 2; + } + +} +?> -- cgit v1.2.3