]> git.wh0rd.org Git - tt-rss.git/blob - classes/dlg.php
feedbrowser hack
[tt-rss.git] / classes / dlg.php
1 <?php
2 class Dlg extends Handler_Protected {
3         private $param;
4     private $params;
5
6     function before($method) {
7                 if (parent::before($method)) {
8                         header("Content-Type: text/html"); # required for iframe
9
10                         $this->param = $_REQUEST["param"];
11                         return true;
12                 }
13                 return false;
14         }
15
16         function importOpml() {
17                 print __("If you have imported labels and/or filters, you might need to reload preferences to see your new data.") . "</p>";
18
19                 print "<div class=\"prefFeedOPMLHolder\">";
20
21                 print "<ul class='nomarks'>";
22
23                 $opml = new Opml($_REQUEST);
24
25                 $opml->opml_import($_SESSION["uid"]);
26
27                 print "</ul>";
28                 print "</div>";
29
30                 print "<div align='center'>";
31                 print "<button dojoType=\"dijit.form.Button\"
32                         onclick=\"dijit.byId('opmlImportDlg').execute()\">".
33                         __('Close this window')."</button>";
34                 print "</div>";
35
36                 print "</div>";
37
38                 //return;
39         }
40
41         function pubOPMLUrl() {
42                 $url_path = Opml::opml_publish_url();
43
44                 print __("Your Public OPML URL is:");
45
46                 print "<div class=\"tagCloudContainer\">";
47                 print "<a id='pub_opml_url' href='$url_path' target='_blank'>$url_path</a>";
48                 print "</div>";
49
50                 print "<div align='center'>";
51
52                 print "<button dojoType=\"dijit.form.Button\" onclick=\"return opmlRegenKey()\">".
53                         __('Generate new URL')."</button> ";
54
55                 print "<button dojoType=\"dijit.form.Button\" onclick=\"return closeInfoBox()\">".
56                         __('Close this window')."</button>";
57
58                 print "</div>";
59
60                 //return;
61         }
62
63         function explainError() {
64                 print "<div class=\"errorExplained\">";
65
66                 if ($this->param == 1) {
67                         print __("Update daemon is enabled in configuration, but daemon process is not running, which prevents all feeds from updating. Please start the daemon process or contact instance owner.");
68
69                         $stamp = (int) file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp");
70
71                         print "<p>" . __("Last update:") . " " . date("Y.m.d, G:i", $stamp);
72
73                 }
74
75                 if ($this->param == 3) {
76                         print __("Update daemon is taking too long to perform a feed update. This could indicate a problem like crash or a hang. Please check the daemon process or contact instance owner.");
77
78                         $stamp = (int) file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp");
79
80                         print "<p>" . __("Last update:") . " " . date("Y.m.d, G:i", $stamp);
81
82                 }
83
84                 print "</div>";
85
86                 print "<div align='center'>";
87
88                 print "<button onclick=\"return closeInfoBox()\">".
89                         __('Close this window')."</button>";
90
91                 print "</div>";
92
93                 //return;
94         }
95
96         function printTagCloud() {
97                 print "<div class=\"tagCloudContainer\">";
98
99                 // from here: http://www.roscripts.com/Create_tag_cloud-71.html
100
101                 $sth = $this->pdo->prepare("SELECT tag_name, COUNT(post_int_id) AS count
102                         FROM ttrss_tags WHERE owner_uid = ?
103                         GROUP BY tag_name ORDER BY count DESC LIMIT 50");
104                 $sth->execute([$_SESSION['uid']]);
105
106                 $tags = array();
107
108                 while ($line = $sth->fetch()) {
109                         $tags[$line["tag_name"]] = $line["count"];
110                 }
111
112         if(count($tags) == 0 ){ return; }
113
114                 ksort($tags);
115
116                 $max_size = 32; // max font size in pixels
117                 $min_size = 11; // min font size in pixels
118
119                 // largest and smallest array values
120                 $max_qty = max(array_values($tags));
121                 $min_qty = min(array_values($tags));
122
123                 // find the range of values
124                 $spread = $max_qty - $min_qty;
125                 if ($spread == 0) { // we don't want to divide by zero
126                                 $spread = 1;
127                 }
128
129                 // set the font-size increment
130                 $step = ($max_size - $min_size) / ($spread);
131
132                 // loop through the tag array
133                 foreach ($tags as $key => $value) {
134                         // calculate font-size
135                         // find the $value in excess of $min_qty
136                         // multiply by the font-size increment ($size)
137                         // and add the $min_size set above
138                         $size = round($min_size + (($value - $min_qty) * $step));
139
140                         $key_escaped = str_replace("'", "\\'", $key);
141
142                         echo "<a href=\"javascript:viewfeed({feed:'$key_escaped'}) \" style=\"font-size: " .
143                                 $size . "px\" title=\"$value articles tagged with " .
144                                 $key . '">' . $key . '</a> ';
145                 }
146
147
148
149                 print "</div>";
150
151                 print "<div align='center'>";
152                 print "<button dojoType=\"dijit.form.Button\"
153                         onclick=\"return closeInfoBox()\">".
154                         __('Close this window')."</button>";
155                 print "</div>";
156
157         }
158
159         function generatedFeed() {
160
161                 $this->params = explode(":", $this->param, 3);
162                 $feed_id = $this->params[0];
163                 $is_cat = (bool) $this->params[1];
164
165                 $key = get_feed_access_key($feed_id, $is_cat);
166
167                 $url_path = htmlspecialchars($this->params[2]) . "&key=" . $key;
168
169                 print "<h2>".__("You can view this feed as RSS using the following URL:")."</h2>";
170
171                 print "<div class=\"tagCloudContainer\">";
172                 print "<a id='gen_feed_url' href='$url_path' target='_blank'>$url_path</a>";
173                 print "</div>";
174
175                 print "<div align='center'>";
176
177                 print "<button dojoType=\"dijit.form.Button\" onclick=\"return genUrlChangeKey('$feed_id', '$is_cat')\">".
178                         __('Generate new URL')."</button> ";
179
180                 print "<button dojoType=\"dijit.form.Button\" onclick=\"return closeInfoBox()\">".
181                         __('Close this window')."</button>";
182
183                 print "</div>";
184
185                 //return;
186         }
187
188         function defaultPasswordWarning() {
189
190         print_warning(__("You are using default tt-rss password. Please change it in the Preferences (Personal data / Authentication)."));
191
192                 print "<div align='center'>";
193                 print "<button dojoType=\"dijit.form.Button\" onclick=\"gotoPreferences()\">".
194                         __('Open Preferences')."</button> ";
195                 print "<button dojoType=\"dijit.form.Button\"
196                         onclick=\"return closeInfoBox()\">".
197                         __('Close this window')."</button>";
198                 print "</div>";
199         }
200 }