]> git.wh0rd.org - tt-rss.git/blame - plugins/example/example.php
add example plugin
[tt-rss.git] / plugins / example / example.php
CommitLineData
b9546011
AD
1<?php
2class 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 __construct($host) {
10 $this->link = $host->get_link();
11 $this->host = $host;
12
13 $host->add_hook($host::HOOK_PREFS_TAB, $this);
14 }
15
16 function save() {
17 $example_value = db_escape_string($_POST["example_value"]);
18
19 echo "Value set to $example_value (not really)";
20 }
21
22 function get_prefs_js() {
23 return file_get_contents(dirname(__FILE__) . "/example.js");
24 }
25
26 function hook_prefs_tab($args) {
27 if ($args != "prefPrefs") return;
28
29 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__("Example Pane")."\">";
30
31 print "<form dojoType=\"dijit.form.Form\">";
32
33 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
34 evt.preventDefault();
35 if (this.validate()) {
36 console.log(dojo.objectToQuery(this.getValues()));
37 new Ajax.Request('backend.php', {
38 parameters: dojo.objectToQuery(this.getValues()),
39 onComplete: function(transport) {
40 notify_info(transport.responseText);
41 }
42 });
43 this.reset();
44 }
45 </script>";
46
47 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">";
48 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"save\">";
49 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"example\">";
50
51 print "<table width=\"100%\" class=\"prefPrefsList\">";
52
53 print "<tr><td width=\"40%\">".__("Sample value")."</td>";
54 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"example_value\"></td></tr>";
55
56 print "</table>";
57
58 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
59 __("Set value")."</button>";
60
61 print "</form>";
62
63 print "</div>"; #pane
64 }
65}
66?>