]> git.wh0rd.org Git - tt-rss.git/blob - plugins/owncloud/init.php
48377e9d97cfa48525a64e5b29eecb9996fa886f
[tt-rss.git] / plugins / owncloud / init.php
1 <?php
2 require_once "config.php";
3
4 class OwnCloud extends Plugin {
5   private $link;
6   private $host;
7
8   function about() {
9     return array(1.0,
10                  "Adds support for OwnCloud ReadLater",
11                  "cy8aer");
12   }
13
14   function init($host) {
15     $this->link = $host->get_link();
16     $this->host = $host;
17
18     $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
19     $host->add_hook($host::HOOK_PREFS_TAB, $this);
20   }
21
22   function save() {
23     $owncloud_url = db_escape_string($_POST["owncloud_url"]);
24     $this->host->set($this, "owncloud", $owncloud_url);
25     echo "Value set to $owncloud_url";
26   }
27
28   function get_js() {
29     return file_get_contents(dirname(__FILE__) . "/owncloud.js");
30   }
31
32   function hook_prefs_tab($args) {
33     if ($args != "prefPrefs") return;
34
35     print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__("Owncloud")."\">";
36
37     print "<br/>";
38
39     $value = $this->host->get($this, "owncloud");
40     print "<form dojoType=\"dijit.form.Form\">";
41
42     print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
43            evt.preventDefault();
44            if (this.validate()) {
45                console.log(dojo.objectToQuery(this.getValues()));
46                new Ajax.Request('backend.php', {
47                                     parameters: dojo.objectToQuery(this.getValues()),
48                                     onComplete: function(transport) {
49                                          notify_info(transport.responseText);
50                                     }
51                                 });
52            }
53            </script>";
54
55     print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">";
56     print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"save\">";
57     print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"owncloud\">";
58     print "<table width=\"100%\" class=\"prefPrefsList\">";
59         print "<tr><td width=\"40%\">".__("Owncloud url")."</td>";
60         print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"owncloud_url\" regExp='^(http|https)://.*' value=\"$value\"></td></tr>";
61     print "</table>";
62     print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".__("Save")."</button>";
63
64     print "</form>";
65
66     print "</div>"; #pane
67
68   }
69
70   function hook_article_button($line) {
71     return "<img src=\"plugins/owncloud/owncloud.png\"
72              style=\"cursor : pointer\" style=\"cursor : pointer\"
73              onclick=\"ownArticle(".$line["id"].")\"
74              class='tagsPic' title='".__('Bookmark on OwnCloud ')."'>";
75   }
76
77   function getOwnCloud() {
78     $id = db_escape_string($_REQUEST['id']);
79
80     $result = db_query($this->link, "SELECT title, link
81                       FROM ttrss_entries, ttrss_user_entries
82                       WHERE id = '$id' AND ref_id = id AND owner_uid = " .$_SESSION['uid']);
83
84     if (db_num_rows($result) != 0) {
85       $title = truncate_string(strip_tags(db_fetch_result($result, 0, 'title')),
86                                100, '...');
87       $article_link = db_fetch_result($result, 0, 'link');
88     }
89
90     $own_url = $this->host->get($this, "owncloud");
91
92     print json_encode(array("title" => $title, "link" => $article_link,
93                             "id" => $id, "ownurl" => $own_url));
94   }
95 }
96 ?>