]>
Commit | Line | Data |
---|---|---|
e3d0198a TR |
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); | |
7e8b6f32 TR |
19 | $host->add_hook($host::HOOK_PREFS_TAB, $this); |
20 | } | |
21 | ||
22 | function save() { | |
3972bf59 | 23 | $owncloud_url = db_escape_string($this->link, $_POST["owncloud_url"]); |
7e8b6f32 TR |
24 | $this->host->set($this, "owncloud", $owncloud_url); |
25 | echo "Value set to $owncloud_url"; | |
e3d0198a TR |
26 | } |
27 | ||
28 | function get_js() { | |
29 | return file_get_contents(dirname(__FILE__) . "/owncloud.js"); | |
30 | } | |
31 | ||
7e8b6f32 TR |
32 | function hook_prefs_tab($args) { |
33 | if ($args != "prefPrefs") return; | |
34 | ||
7278dc0e | 35 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__("Owncloud")."\">"; |
7e8b6f32 TR |
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\"> | |
7278dc0e | 43 | evt.preventDefault(); |
7e8b6f32 | 44 | if (this.validate()) { |
7278dc0e | 45 | console.log(dojo.objectToQuery(this.getValues())); |
7e8b6f32 TR |
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>"; | |
0ed86aa1 | 54 | |
7e8b6f32 TR |
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\">"; | |
7278dc0e | 57 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"owncloud\">"; |
7e8b6f32 TR |
58 | print "<table width=\"100%\" class=\"prefPrefsList\">"; |
59 | print "<tr><td width=\"40%\">".__("Owncloud url")."</td>"; | |
0ed86aa1 | 60 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"owncloud_url\" regExp='^(http|https)://.*' value=\"$value\"></td></tr>"; |
7e8b6f32 | 61 | print "</table>"; |
e236d876 | 62 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".__("Save")."</button>"; |
0ed86aa1 | 63 | |
7e8b6f32 | 64 | print "</form>"; |
0ed86aa1 | 65 | |
7e8b6f32 TR |
66 | print "</div>"; #pane |
67 | ||
68 | } | |
69 | ||
e3d0198a | 70 | function hook_article_button($line) { |
2a3b6de0 | 71 | return "<img src=\"plugins/owncloud/owncloud.png\" |
e3d0198a TR |
72 | style=\"cursor : pointer\" style=\"cursor : pointer\" |
73 | onclick=\"ownArticle(".$line["id"].")\" | |
74 | class='tagsPic' title='".__('Bookmark on OwnCloud ')."'>"; | |
75 | } | |
76 | ||
77 | function getOwnCloud() { | |
3972bf59 | 78 | $id = db_escape_string($this->link, $_REQUEST['id']); |
0ed86aa1 | 79 | |
e3d0198a TR |
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']); | |
0ed86aa1 | 83 | |
e3d0198a TR |
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 | } | |
0ed86aa1 | 89 | |
7278dc0e | 90 | $own_url = $this->host->get($this, "owncloud"); |
e3d0198a TR |
91 | |
92 | print json_encode(array("title" => $title, "link" => $article_link, | |
93 | "id" => $id, "ownurl" => $own_url)); | |
94 | } | |
95 | } | |
96 | ?> |