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