4f624ff18d894c7246e946504d9bf0ff263b0e57
[tt-rss-subtome.git] / init.php
1 <?php
2 /**
3  * Allows user to register their Tiny Tiny RSS instance at subtome.com,
4  * so that they can subscribe to feeds with a few clicks.
5  *
6  * PHP version 5
7  *
8  * @author  Christian Weiske <cweiske@cweiske.de>
9  * @license AGPLv3 or later
10  * @link    http://docs.subtome.com/developers/
11  * @link    https://tt-rss.org/redmine/projects/tt-rss/wiki/FrequentlyAskedQuestions#I-need-a-URL-I-can-call-to-subscribe-to-feed-to-integrate-with-some-third-party-browser-extensionapplication
12  */
13 class SubToMe extends Plugin
14 {
15     public function about()
16     {
17         return array(
18             0.1,
19             'Add TT-RSS to SubToMe.com',
20             'cweiske',
21             false//not a system plugin
22         );
23     }
24     
25     public function init($host)
26     {
27         $host->add_hook($host::HOOK_PREFS_TAB, $this);
28     }
29
30     public function hook_prefs_tab($args)
31     {
32         if ($args != "prefPrefs") {
33             return;
34         }
35
36         $ttSubscribeUrl = get_self_url_prefix()
37             . '/public.php?op=subscribe&feed_url={url}';
38
39         $regUrl = 'https://www.subtome.com/register-no-ui.html'
40             . '?name=##NAME##'
41             . '&url=' . urlencode($ttSubscribeUrl);
42         $jRegUrl = json_encode($regUrl);
43
44         echo <<<HTM
45 <div dojoType="dijit.layout.AccordionPane" title="SubToMe">
46  <form dojoType="dijit.form.Form" id="subtome_reg_form">
47   <script type="dojo/method" event="onSubmit" args="evt">
48     evt.preventDefault();
49     if (this.validate()) {
50         var regUrl = $jRegUrl.replace(
51             '##NAME##', document.getElementById("subtome_name").value
52         );
53         var me = document.getElementById('subtome_reg_form');
54         me.insertAdjacentHTML(
55             'afterend',
56             '<iframe style="display:none;" src="' + regUrl + '" />'
57         );
58         document.getElementById("subtome_done").style = "";
59     }
60   </script>
61
62   <table width="100%" class="prefPrefsList">
63    <tr><td colspan="2"><h3>Configure SubToMe</h3></td></tr>
64    <tr>
65     <td width="40%" class="prefName">
66      <label for="subtome_name">Name</label>
67     </td>
68     <td class="prefValue">
69      <input name="subtome_name" id="subtome_name" type="text" size="20" value="Tiny Tiny RSS" dojoType="dijit.form.TextBox"/>
70     </td>
71    </tr>
72   </table>
73   <p>
74    <input type="submit" value="Add TT-RSS to SubToMe.com"/>
75    <span id="subtome_done" style="display: none">
76     <input type="checkbox" checked="checked" value="1"
77            dojoType="dijit.form.CheckBox" />
78     Registration finished!
79    </span>
80   </p>
81  </form>
82
83  <h3>Testing</h3>
84  <p>
85   Try the "Subscribe" button on
86   <a href="http://blog.superfeedr.com/">blog.superfeedr.com</a>.
87  </p>
88 </div>
89 HTM;
90     }
91
92     public function api_version()
93     {
94         return 2;
95     }
96 }
97 ?>