summaryrefslogtreecommitdiff
path: root/plugins/bookmarklets/init.php
blob: 9e0f8f3480e0d44d0125da97947343e7bbcb84e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
class Bookmarklets extends Plugin {
  private $host;

  function about() {
    return array(1.0,
		 "Easy feed subscription and web page sharing using bookmarklets",
		 "fox",
	     false,
		 "https://git.tt-rss.org/fox/tt-rss/wiki/ShareAnything");
  }

  function init($host) {
    $this->host = $host;

    $host->add_hook($host::HOOK_PREFS_TAB, $this);
  }

  private function subscribe_to_feed_url() {
		$url_path = get_self_url_prefix() .
			"/public.php?op=subscribe&feed_url=%s";
		return $url_path;
	}

  function hook_prefs_tab($args) {
    if ($args == "prefFeeds") {

		print "<div dojoType=\"dijit.layout.AccordionPane\"
			title=\"<i class='material-icons'>bookmark</i> ".__('Bookmarklets')."\">";

		print "<h3>" . __("Drag the link below to your browser toolbar, open the feed you're interested in in your browser and click on the link to subscribe to it.") . "</h3>";

		$bm_subscribe_url = str_replace('%s', '', $this->subscribe_to_feed_url());

		$confirm_str = str_replace("'", "\'", __('Subscribe to %s in Tiny Tiny RSS?'));

		$bm_url = htmlspecialchars("javascript:{if(confirm('$confirm_str'.replace('%s',window.location.href)))window.location.href='$bm_subscribe_url'+encodeURIComponent(window.location.href)}");

		print "<p><label class='dijitButton'>";
		print "<a href=\"$bm_url\">" . __('Subscribe in Tiny Tiny RSS'). "</a>";
		print "</label></p>";

		print "<h3>" . __("Use this bookmarklet to publish arbitrary pages using Tiny Tiny RSS") . "</h3>";

		print "<label class='dijitButton'>";
		$bm_url = htmlspecialchars("javascript:(function(){var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='".get_self_url_prefix()."/public.php?op=sharepopup',l=d.location,e=encodeURIComponent,g=f+'&title='+((e(s))?e(s):e(document.title))+'&url='+e(l.href);function a(){if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=500,height=250')){l.href=g;}}a();})()");
		print "<a href=\"$bm_url\">" . __('Share with Tiny Tiny RSS'). "</a>";
		print "</label>";

		print "<button dojoType='dijit.form.Button' class='alt-info' onclick='window.open(\"https://tt-rss.org/wiki/ShareAnything\")'>
					<i class='material-icons'>help</i> ".__("More info...")."</button>";

		print "</div>"; #pane

	 }
  }

	function api_version() {
		return 2;
	}

}