]> git.wh0rd.org - tt-rss.git/blame - plugins/af_sort_bayes/init.php
add placeholder stuff for af_sort_bayes
[tt-rss.git] / plugins / af_sort_bayes / init.php
CommitLineData
853cc128
AD
1<?php
2
3class Af_Sort_Bayes extends Plugin {
4
5 private $host;
6 private $filters = array();
7 private $dbh;
8
9 function about() {
10 return array(1.0,
11 "Bayesian classifier for tt-rss (WIP)",
12 "fox");
13 }
14
15 function init($host) {
16 require_once __DIR__ . "/lib/class.naivebayesian.php";
17 require_once __DIR__ . "/lib/class.naivebayesianstorage.php";
18
19 $this->host = $host;
20 $this->dbh = Db::get();
21
22 $this->init_database();
23
24 $host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
25 $host->add_hook($host::HOOK_PREFS_TAB, $this);
26 $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
27
28 }
29
30 function trainArticle() {
31 $article_id = (int) $_REQUEST["article_id"];
32 $train_up = sql_bool_to_bool($_REQUEST["train_up"]);
33
34 print "FIXME: $article_id :: $train_up";
35
36 }
37
38 function get_js() {
39 return file_get_contents(__DIR__ . "/init.js");
40 }
41
42 function hook_article_button($line) {
43 return "<img src=\"plugins/af_sort_bayes/thumb_up.png\"
44 style=\"cursor : pointer\" style=\"cursor : pointer\"
45 onclick=\"bayesTrain(".$line["id"].", true)\"
46 class='tagsPic' title='".__('+1')."'>" .
47 "<img src=\"plugins/af_sort_bayes/thumb_down.png\"
48 style=\"cursor : pointer\" style=\"cursor : pointer\"
49 onclick=\"bayesTrain(".$line["id"].", false)\"
50 class='tagsPic' title='".__('-1')."'>";
51
52 }
53
54 function init_database() {
55 $prefix = "ttrss_plugin_af_sort_bayes";
56
57 /*$this->dbh->query("DROP TABLE IF EXISTS ${prefix}_references", false);
58 $this->dbh->query("DROP TABLE IF EXISTS ${prefix}_categories", false);
59 $this->dbh->query("DROP TABLE IF EXISTS ${prefix}_wordfreqs", false);*/
60
61 $this->dbh->query("BEGIN");
62
63 // PG only for the time being
64
65 $this->dbh->query("CREATE TABLE IF NOT EXISTS ${prefix}_categories (
66 id SERIAL NOT NULL PRIMARY KEY,
67 category varchar(100) NOT NULL DEFAULT '',
68 probability DOUBLE PRECISION NOT NULL DEFAULT '0',
69 owner_uid INTEGER NOT NULL REFERENCES ttrss_users(id) ON DELETE CASCADE,
70 word_count BIGINT NOT NULL DEFAULT '0')");
71
72 $this->dbh->query("CREATE TABLE IF NOT EXISTS ${prefix}_documents (
73 id SERIAL NOT NULL PRIMARY KEY,
74 document varchar(250) NOT NULL DEFAULT '',
75 category_id INTEGER NOT NULL REFERENCES ${prefix}_categories(id) ON DELETE CASCADE,
76 owner_uid INTEGER NOT NULL REFERENCES ttrss_users(id) ON DELETE CASCADE,
77 content text NOT NULL)");
78
79 $this->dbh->query("CREATE TABLE IF NOT EXISTS ${prefix}_wordfreqs (
80 word varchar(100) NOT NULL DEFAULT '',
81 category_id INTEGER NOT NULL REFERENCES ${prefix}_categories(id) ON DELETE CASCADE,
82 owner_uid INTEGER NOT NULL REFERENCES ttrss_users(id) ON DELETE CASCADE,
83 count BIGINT NOT NULL DEFAULT '0')");
84
85 $this->dbh->query("COMMIT");
86 }
87
88 function hook_prefs_tab($args) {
89 if ($args != "prefPrefs") return;
90
91 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('af_sort_bayes')."\">";
92
93 //
94
95 print "</div>";
96 }
97
98 function hook_article_filter($article) {
99 $owner_uid = $article["owner_uid"];
100
101
102 return $article;
103
104 }
105
106 function api_version() {
107 return 2;
108 }
109
110}
111?>