]> git.wh0rd.org - tt-rss.git/blame - plugins/example/init.php
rebase translations
[tt-rss.git] / plugins / example / init.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
d2a421e3 9 function about() {
7a866114
AD
10 return array(1.0,
11 "Example plugin #1",
de612e7a
AD
12 "fox",
13 true);
7a866114
AD
14 }
15
d2a421e3 16 function init($host) {
b9546011
AD
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() {
3972bf59 24 $example_value = db_escape_string($this->link, $_POST["example_value"]);
b9546011 25
d8a1d2a2
AD
26 $this->host->set($this, "example", $example_value);
27
28 echo "Value set to $example_value";
b9546011
AD
29 }
30
31 function get_prefs_js() {
32 return file_get_contents(dirname(__FILE__) . "/example.js");
33 }
34
35 function hook_prefs_tab($args) {
36 if ($args != "prefPrefs") return;
37
38 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__("Example Pane")."\">";
39
d8a1d2a2
AD
40 print "<br/>";
41
42// print_r($this->host->set($this, "example", rand(0,100)));
43// print_r($this->host->get_all($this));
44
45 $value = $this->host->get($this, "example");
46
b9546011
AD
47 print "<form dojoType=\"dijit.form.Form\">";
48
49 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
50 evt.preventDefault();
51 if (this.validate()) {
52 console.log(dojo.objectToQuery(this.getValues()));
53 new Ajax.Request('backend.php', {
54 parameters: dojo.objectToQuery(this.getValues()),
55 onComplete: function(transport) {
56 notify_info(transport.responseText);
57 }
58 });
d8a1d2a2 59 //this.reset();
b9546011
AD
60 }
61 </script>";
62
63 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">";
64 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"save\">";
65 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"example\">";
66
67 print "<table width=\"100%\" class=\"prefPrefsList\">";
68
69 print "<tr><td width=\"40%\">".__("Sample value")."</td>";
d8a1d2a2 70 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"example_value\" value=\"$value\"></td></tr>";
b9546011
AD
71
72 print "</table>";
73
74 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
75 __("Set value")."</button>";
76
77 print "</form>";
78
79 print "</div>"; #pane
80 }
81}
82?>