]> git.wh0rd.org - tt-rss.git/blob - plugins/example/example.php
more work on user-selectable plugins; properly process system and user plugins
[tt-rss.git] / plugins / example / example.php
1 <?php
2 class Example extends Plugin {
3
4 // Demonstrates how to add a separate panel to the preferences screen and inject Javascript/save data using Dojo forms.
5
6 private $link;
7 private $host;
8
9 function about() {
10 return array(1.0,
11 "Example plugin #1",
12 "fox",
13 true);
14 }
15
16 function init($host) {
17 $this->link = $host->get_link();
18 $this->host = $host;
19
20 $host->add_hook($host::HOOK_PREFS_TAB, $this);
21 }
22
23 function save() {
24 $example_value = db_escape_string($_POST["example_value"]);
25
26 echo "Value set to $example_value (not really)";
27 }
28
29 function get_prefs_js() {
30 return file_get_contents(dirname(__FILE__) . "/example.js");
31 }
32
33 function hook_prefs_tab($args) {
34 if ($args != "prefPrefs") return;
35
36 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__("Example Pane")."\">";
37
38 print "<form dojoType=\"dijit.form.Form\">";
39
40 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
41 evt.preventDefault();
42 if (this.validate()) {
43 console.log(dojo.objectToQuery(this.getValues()));
44 new Ajax.Request('backend.php', {
45 parameters: dojo.objectToQuery(this.getValues()),
46 onComplete: function(transport) {
47 notify_info(transport.responseText);
48 }
49 });
50 this.reset();
51 }
52 </script>";
53
54 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">";
55 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"save\">";
56 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"example\">";
57
58 print "<table width=\"100%\" class=\"prefPrefsList\">";
59
60 print "<tr><td width=\"40%\">".__("Sample value")."</td>";
61 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"example_value\"></td></tr>";
62
63 print "</table>";
64
65 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
66 __("Set value")."</button>";
67
68 print "</form>";
69
70 print "</div>"; #pane
71 }
72 }
73 ?>