]> git.wh0rd.org Git - tt-rss.git/blob - classes/dlg.php
allow subscribing to twitter feeds without oauth (if require auth checkbox is unset)
[tt-rss.git] / classes / dlg.php
1 <?php
2 class Dlg extends Protected_Handler {
3         private $param;
4
5         function before() {
6                 if (parent::before()) {
7                         header("Content-Type: text/xml; charset=utf-8");
8                         $this->param = db_escape_string($_REQUEST["param"]);
9                         print "<dlg>";
10                         return true;
11                 }
12                 return false;
13         }
14
15         function after() {
16                 print "</dlg>";
17         }
18
19         function exportData() {
20
21                 print "<p style='text-align : center' id='export_status_message'>You need to prepare exported data first by clicking the button below.</p>";
22
23                 print "<div align='center'>";
24                 print "<button dojoType=\"dijit.form.Button\"
25                         onclick=\"dijit.byId('dataExportDlg').prepare()\">".
26                         __('Prepare data')."</button>";
27
28                 print "<button dojoType=\"dijit.form.Button\"
29                         onclick=\"dijit.byId('dataExportDlg').hide()\">".
30                         __('Close this window')."</button>";
31
32                 print "</div>";
33
34
35         }
36
37         function importOpml() {
38                 header("Content-Type: text/html"); # required for iframe
39
40                 print __("If you have imported labels and/or filters, you might need to reload preferences to see your new data.") . "</p>";
41
42                 print "<div class=\"prefFeedOPMLHolder\">";
43                 $owner_uid = $_SESSION["uid"];
44
45                 db_query($this->link, "BEGIN");
46
47                 /* create Imported feeds category just in case */
48
49                 $result = db_query($this->link, "SELECT id FROM
50                         ttrss_feed_categories WHERE title = 'Imported feeds' AND
51                         owner_uid = '$owner_uid' LIMIT 1");
52
53                 if (db_num_rows($result) == 0) {
54                         db_query($this->link, "INSERT INTO ttrss_feed_categories
55                                 (title,owner_uid)
56                                         VALUES ('Imported feeds', '$owner_uid')");
57                 }
58
59                 db_query($this->link, "COMMIT");
60
61                 /* Handle OPML import by DOMXML/DOMDocument */
62
63                 print "<ul class='nomarks'>";
64                 require_once "opml.php";
65                 opml_import_domdoc($this->link, $owner_uid);
66                 print "</ul>";
67                 print "</div>";
68
69                 print "<div align='center'>";
70                 print "<button dojoType=\"dijit.form.Button\"
71                         onclick=\"dijit.byId('opmlImportDlg').execute()\">".
72                         __('Close this window')."</button>";
73                 print "</div>";
74
75                 print "</div>";
76
77                 //return;
78         }
79
80         function editPrefProfiles() {
81                 print "<div dojoType=\"dijit.Toolbar\">";
82
83                 print "<input name=\"newprofile\" dojoType=\"dijit.form.ValidationTextBox\"
84                                 required=\"1\">
85                         <button dojoType=\"dijit.form.Button\"
86                         onclick=\"dijit.byId('profileEditDlg').addProfile()\">".
87                                 __('Create profile')."</button></div>";
88
89                 $result = db_query($this->link, "SELECT title,id FROM ttrss_settings_profiles
90                         WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
91
92                 print "<div class=\"prefFeedCatHolder\">";
93
94                 print "<form id=\"profile_edit_form\" onsubmit=\"return false\">";
95
96                 print "<table width=\"100%\" class=\"prefFeedProfileList\"
97                         cellspacing=\"0\" id=\"prefFeedProfileList\">";
98
99                 print "<tr class=\"\" id=\"FCATR-0\">"; #odd
100
101                 print "<td width='5%' align='center'><input
102                         onclick='toggleSelectRow2(this);'
103                         dojoType=\"dijit.form.CheckBox\"
104                         type=\"checkbox\"></td>";
105
106                 if (!$_SESSION["profile"]) {
107                         $is_active = __("(active)");
108                 } else {
109                         $is_active = "";
110                 }
111
112                 print "<td><span>" .
113                         __("Default profile") . " $is_active</span></td>";
114
115                 print "</tr>";
116
117                 $lnum = 1;
118
119                 while ($line = db_fetch_assoc($result)) {
120
121                         $class = ($lnum % 2) ? "even" : "odd";
122
123                         $profile_id = $line["id"];
124                         $this_row_id = "id=\"FCATR-$profile_id\"";
125
126                         print "<tr class=\"\" $this_row_id>";
127
128                         $edit_title = htmlspecialchars($line["title"]);
129
130                         print "<td width='5%' align='center'><input
131                                 onclick='toggleSelectRow2(this);'
132                                 dojoType=\"dijit.form.CheckBox\"
133                                 type=\"checkbox\"></td>";
134
135                         if ($_SESSION["profile"] == $line["id"]) {
136                                 $is_active = __("(active)");
137                         } else {
138                                 $is_active = "";
139                         }
140
141                         print "<td><span dojoType=\"dijit.InlineEditBox\"
142                                 width=\"300px\" autoSave=\"false\"
143                                 profile-id=\"$profile_id\">" . $edit_title .
144                                 "<script type=\"dojo/method\" event=\"onChange\" args=\"item\">
145                                         var elem = this;
146                                         dojo.xhrPost({
147                                                 url: 'backend.php',
148                                                 content: {op: 'rpc', method: 'saveprofile',
149                                                         value: this.value,
150                                                         id: this.srcNodeRef.getAttribute('profile-id')},
151                                                         load: function(response) {
152                                                                 elem.attr('value', response);
153                                                 }
154                                         });
155                                 </script>
156                         </span> $is_active</td>";
157
158                         print "</tr>";
159
160                         ++$lnum;
161                 }
162
163                 print "</table>";
164                 print "</form>";
165                 print "</div>";
166
167                 print "<div class='dlgButtons'>
168                         <div style='float : left'>
169                         <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').removeSelected()\">".
170                         __('Remove selected profiles')."</button>
171                         <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').activateProfile()\">".
172                         __('Activate profile')."</button>
173                         </div>";
174
175                 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').hide()\">".
176                         __('Close this window')."</button>";
177                 print "</div>";
178
179         }
180
181         function pubOPMLUrl() {
182                 print "<title>".__('Public OPML URL')."</title>";
183                 print "<content><![CDATA[";
184
185                 $url_path = opml_publish_url($this->link);
186
187                 print __("Your Public OPML URL is:");
188
189                 print "<div class=\"tagCloudContainer\">";
190                 print "<a id='pub_opml_url' href='$url_path' target='_blank'>$url_path</a>";
191                 print "</div>";
192
193                 print "<div align='center'>";
194
195                 print "<button dojoType=\"dijit.form.Button\" onclick=\"return opmlRegenKey()\">".
196                         __('Generate new URL')."</button> ";
197
198                 print "<button dojoType=\"dijit.form.Button\" onclick=\"return closeInfoBox()\">".
199                         __('Close this window')."</button>";
200
201                 print "</div>";
202                 print "]]></content>";
203
204                 //return;
205         }
206
207         function explainError() {
208                 print "<title>".__('Notice')."</title>";
209                 print "<content><![CDATA[";
210
211                 print "<div class=\"errorExplained\">";
212
213                 if ($this->param == 1) {
214                         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.");
215
216                         $stamp = (int) file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp");
217
218                         print "<p>" . __("Last update:") . " " . date("Y.m.d, G:i", $stamp);
219
220                 }
221
222                 if ($this->param == 3) {
223                         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.");
224
225                         $stamp = (int) file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp");
226
227                         print "<p>" . __("Last update:") . " " . date("Y.m.d, G:i", $stamp);
228
229                 }
230
231                 print "</div>";
232
233                 print "<div align='center'>";
234
235                 print "<button onclick=\"return closeInfoBox()\">".
236                         __('Close this window')."</button>";
237
238                 print "</div>";
239                 print "]]></content>";
240
241                 //return;
242         }
243
244         function quickAddFeed() {
245                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
246                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"addfeed\">";
247
248                 print "<div class=\"dlgSec\">".__("Feed")."</div>";
249                 print "<div class=\"dlgSecCont\">";
250
251                 print "<input style=\"font-size : 16px; width : 20em;\"
252                         placeHolder=\"".__("Feed URL")."\"
253                         dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"feed\" id=\"feedDlg_feedUrl\">";
254
255                 print "<hr/>";
256
257                 if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
258                         print __('Place in category:') . " ";
259                         print_feed_cat_select($this->link, "cat", false, 'dojoType="dijit.form.Select"');
260                 }
261
262                 print "</div>";
263
264                 print '<div id="feedDlg_feedsContainer" style="display : none">
265
266                                 <div class="dlgSec">' . __('Available feeds') . '</div>
267                                 <div class="dlgSecCont">'.
268                                 '<select id="feedDlg_feedContainerSelect"
269                                         dojoType="dijit.form.Select" size="3">
270                                         <script type="dojo/method" event="onChange" args="value">
271                                                 dijit.byId("feedDlg_feedUrl").attr("value", value);
272                                         </script>
273                                 </select>'.
274                                 '</div></div>';
275
276                 print "<div id='feedDlg_loginContainer' style='display : none'>
277
278                                 <div class=\"dlgSec\">".__("Authentication")."</div>
279                                 <div class=\"dlgSecCont\">".
280
281                                 " <input dojoType=\"dijit.form.TextBox\" name='login'\"
282                                         placeHolder=\"".__("Login")."\"
283                                         style=\"width : 10em;\"> ".
284                                 " <input
285                                         placeHolder=\"".__("Password")."\"
286                                         dojoType=\"dijit.form.TextBox\" type='password'
287                                         style=\"width : 10em;\" name='pass'\">".
288                                 " <p class='insensitive'>".__("OAuth will be used automatically for Twitter feeds.")."</p>
289                         </div></div>";
290
291
292                 print "<div style=\"clear : both\">
293                         <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\"
294                                         onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'>
295                                 <label for=\"feedDlg_loginCheck\">".
296                                 __('This feed requires authentication.')."</div>";
297
298                 print "</form>";
299
300                 print "<div class=\"dlgButtons\">
301                         <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').execute()\">".__('Subscribe')."</button>
302                         <button dojoType=\"dijit.form.Button\" onclick=\"return feedBrowser()\">".__('More feeds')."</button>
303                         <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').hide()\">".__('Cancel')."</button>
304                         </div>";
305
306                 //return;
307         }
308
309         function feedBrowser() {
310                 $browser_search = db_escape_string($_REQUEST["search"]);
311
312                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
313                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"updateFeedBrowser\">";
314
315                 print "<div dojoType=\"dijit.Toolbar\">
316                         <div style='float : right'>
317                         <img style='display : none'
318                                 id='feed_browser_spinner' src='".
319                                 theme_image($this->link, 'images/indicator_white.gif')."'>
320                         <input name=\"search\" dojoType=\"dijit.form.TextBox\" size=\"20\" type=\"search\"
321                                 onchange=\"dijit.byId('feedBrowserDlg').update()\" value=\"$browser_search\">
322                         <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').update()\">".__('Search')."</button>
323                 </div>";
324
325                 print " <select name=\"mode\" dojoType=\"dijit.form.Select\" onchange=\"dijit.byId('feedBrowserDlg').update()\">
326                         <option value='1'>" . __('Popular feeds') . "</option>
327                         <option value='2'>" . __('Feed archive') . "</option>
328                         </select> ";
329
330                 print __("limit:");
331
332                 print " <select dojoType=\"dijit.form.Select\" name=\"limit\" onchange=\"dijit.byId('feedBrowserDlg').update()\">";
333
334                 foreach (array(25, 50, 100, 200) as $l) {
335                         $issel = ($l == $limit) ? "selected=\"1\"" : "";
336                         print "<option $issel value=\"$l\">$l</option>";
337                 }
338
339                 print "</select> ";
340
341                 print "</div>";
342
343                 $owner_uid = $_SESSION["uid"];
344
345                 print "<ul class='browseFeedList' id='browseFeedList'>";
346                 print make_feed_browser($this->link, $search, 25);
347                 print "</ul>";
348
349                 print "<div align='center'>
350                         <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').execute()\">".__('Subscribe')."</button>
351                         <button dojoType=\"dijit.form.Button\" style='display : none' id='feed_archive_remove' onclick=\"dijit.byId('feedBrowserDlg').removeFromArchive()\">".__('Remove')."</button>
352                         <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').hide()\" >".__('Cancel')."</button></div>";
353
354         }
355
356         function search() {
357                 $this->params = explode(":", db_escape_string($_REQUEST["param"]), 2);
358
359                 $active_feed_id = sprintf("%d", $this->params[0]);
360                 $is_cat = $this->params[1] != "false";
361
362                 print "<div class=\"dlgSec\">".__('Look for')."</div>";
363
364                 print "<div class=\"dlgSecCont\">";
365
366                 if (!SPHINX_ENABLED) {
367
368                         print "<input dojoType=\"dijit.form.ValidationTextBox\"
369                                 style=\"font-size : 16px; width : 12em;\"
370                                 required=\"1\" name=\"query\" type=\"search\" value=''>";
371
372                         print " " . __('match on')." ";
373
374                         $search_fields = array(
375                                 "title" => __("Title"),
376                                         "content" => __("Content"),
377                                 "both" => __("Title or content"));
378
379                         print_select_hash("match_on", 3, $search_fields,
380                                 'dojoType="dijit.form.Select"');
381                 } else {
382                         print "<input dojoType=\"dijit.form.ValidationTextBox\"
383                                 style=\"font-size : 16px; width : 20em;\"
384                                 required=\"1\" name=\"query\" type=\"search\" value=''>";
385                 }
386
387
388                 print "<hr/>".__('Limit search to:')." ";
389
390                 print "<select name=\"search_mode\" dojoType=\"dijit.form.Select\">
391                         <option value=\"all_feeds\">".__('All feeds')."</option>";
392
393                 $feed_title = getFeedTitle($this->link, $active_feed_id);
394
395                 if (!$is_cat) {
396                         $feed_cat_title = getFeedCatTitle($this->link, $active_feed_id);
397                 } else {
398                         $feed_cat_title = getCategoryTitle($this->link, $active_feed_id);
399                 }
400
401                 if ($active_feed_id && !$is_cat) {
402                         print "<option selected=\"1\" value=\"this_feed\">$feed_title</option>";
403                 } else {
404                         print "<option disabled=\"1\" value=\"false\">".__('This feed')."</option>";
405                 }
406
407                 if ($is_cat) {
408                         $cat_preselected = "selected=\"1\"";
409                 }
410
411                 if (get_pref($this->link, 'ENABLE_FEED_CATS') && ($active_feed_id > 0 || $is_cat)) {
412                         print "<option $cat_preselected value=\"this_cat\">$feed_cat_title</option>";
413                 } else {
414                         //print "<option disabled>".__('This category')."</option>";
415                 }
416
417                 print "</select>";
418
419                 print "</div>";
420
421                 print "<div class=\"dlgButtons\">";
422
423                 if (!SPHINX_ENABLED) {
424                         print "<div style=\"float : left\">
425                                 <a class=\"visibleLink\" target=\"_blank\" href=\"http://tt-rss.org/redmine/wiki/tt-rss/SearchSyntax\">Search syntax</a>
426                                 </div>";
427                 }
428
429                 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').execute()\">".__('Search')."</button>
430                 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').hide()\">".__('Cancel')."</button>
431                 </div>";
432         }
433
434         function quickAddFilter() {
435                 $active_feed_id = db_escape_string($_REQUEST["param"]);
436
437                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
438                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"quiet\" value=\"1\">";
439                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"add\">";
440                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">";
441
442                 $result = db_query($this->link, "SELECT id,description
443                         FROM ttrss_filter_types ORDER BY description");
444
445                 $filter_types = array();
446
447                 while ($line = db_fetch_assoc($result)) {
448                         //array_push($filter_types, $line["description"]);
449                         $filter_types[$line["id"]] = __($line["description"]);
450                 }
451
452                 print "<div class=\"dlgSec\">".__("Match")."</div>";
453
454                 print "<div class=\"dlgSecCont\">";
455
456                 print "<span id=\"filterDlg_dateModBox\" style=\"display : none\">";
457
458                 $filter_params = array(
459                         "before" => __("before"),
460                         "after" => __("after"));
461
462                 print_select_hash("filter_date_modifier", "before",
463                         $filter_params, 'dojoType="dijit.form.Select"');
464
465                 print "&nbsp;</span>";
466
467                 print "<input dojoType=\"dijit.form.ValidationTextBox\"
468                          required=\"true\" id=\"filterDlg_regExp\"
469                          style=\"font-size : 16px\"
470                          name=\"reg_exp\" value=\"$reg_exp\"/>";
471
472                 print "<span id=\"filterDlg_dateChkBox\" style=\"display : none\">";
473                 print "&nbsp;<button dojoType=\"dijit.form.Button\"
474                         onclick=\"return filterDlgCheckDate()\">".
475                         __('Check it')."</button>";
476                 print "</span>";
477
478                 print "<hr/>" .  __("on field") . " ";
479                 print_select_hash("filter_type", 1, $filter_types,
480                         'onchange="filterDlgCheckType(this)" dojoType="dijit.form.Select"');
481
482                 print "<hr/>";
483
484                 print __("in") . " ";
485
486                 print "<span id='filterDlg_feeds'>";
487                 print_feed_select($this->link, "feed_id", $active_feed_id,
488                         'dojoType="dijit.form.FilteringSelect"');
489                 print "</span>";
490
491                 print "<span id='filterDlg_cats' style='display : none'>";
492                 print_feed_cat_select($this->link, "cat_id", $active_cat_id,
493                         'dojoType="dijit.form.FilteringSelect"');
494                 print "</span>";
495
496                 print "</div>";
497
498                 print "<div class=\"dlgSec\">".__("Perform Action")."</div>";
499
500                 print "<div class=\"dlgSecCont\">";
501
502                 print "<select name=\"action_id\" dojoType=\"dijit.form.Select\"
503                         onchange=\"filterDlgCheckAction(this)\">";
504
505                 $result = db_query($this->link, "SELECT id,description FROM ttrss_filter_actions
506                         ORDER BY name");
507
508                 while ($line = db_fetch_assoc($result)) {
509                         printf("<option value='%d'>%s</option>", $line["id"], __($line["description"]));
510                 }
511
512                 print "</select>";
513
514                 print "<span id=\"filterDlg_paramBox\" style=\"display : none\">";
515                 print " " . __("with parameters:") . " ";
516                 print "<input dojoType=\"dijit.form.TextBox\"
517                         id=\"filterDlg_actionParam\"
518                         name=\"action_param\">";
519
520                 print_label_select($this->link, "action_param_label", $action_param,
521                  'id="filterDlg_actionParamLabel" dojoType="dijit.form.Select"');
522
523                 print "</span>";
524
525                 print "&nbsp;"; // tiny layout hack
526
527                 print "</div>";
528
529                 print "<div class=\"dlgSec\">".__("Options")."</div>";
530                 print "<div class=\"dlgSecCont\">";
531
532                 print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" checked=\"1\">
533                                 <label for=\"enabled\">".__('Enabled')."</label><hr/>";
534
535                 print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\">
536                         <label for=\"inverse\">".__('Inverse match')."</label><hr/>";
537
538                 print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"cat_filter\" id=\"cat_filter\" onchange=\"filterDlgCheckCat(this)\">
539                                 <label for=\"cat_filter\">".__('Apply to category')."</label><hr/>";
540
541
542                 print "</div>";
543
544                 print "<div class=\"dlgButtons\">";
545
546                 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
547                         __('Test')."</button> ";
548
549                 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
550                         __('Create')."</button> ";
551
552                 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">".
553                         __('Cancel')."</button>";
554
555                 print "</div>";
556         }
557
558         function inactiveFeeds() {
559
560                 if (DB_TYPE == "pgsql") {
561                         $interval_qpart = "NOW() - INTERVAL '3 months'";
562                 } else {
563                         $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
564                 }
565
566                 $result = db_query($this->link, "SELECT ttrss_feeds.title, ttrss_feeds.site_url,
567                                 ttrss_feeds.feed_url, ttrss_feeds.id, MAX(updated) AS last_article
568                         FROM ttrss_feeds, ttrss_entries, ttrss_user_entries WHERE
569                                 (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
570                                         ttrss_entries.id = ref_id AND
571                                                 ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart
572                         AND ttrss_feeds.owner_uid = ".$_SESSION["uid"]." AND
573                                 ttrss_user_entries.feed_id = ttrss_feeds.id AND
574                                 ttrss_entries.id = ref_id
575                         GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url
576                         ORDER BY last_article");
577
578                 print __("These feeds have not been updated with new content for 3 months (oldest first):");
579
580                 print "<div class=\"inactiveFeedHolder\">";
581
582                 print "<table width=\"100%\" cellspacing=\"0\" id=\"prefInactiveFeedList\">";
583
584                 $lnum = 1;
585
586                 while ($line = db_fetch_assoc($result)) {
587
588                         $class = ($lnum % 2) ? "even" : "odd";
589                         $feed_id = $line["id"];
590                         $this_row_id = "id=\"FUPDD-$feed_id\"";
591
592                         print "<tr class=\"\" $this_row_id>";
593
594                         $edit_title = htmlspecialchars($line["title"]);
595
596                         print "<td width='5%' align='center'><input
597                                 onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"
598                                 type=\"checkbox\"></td>";
599                         print "<td>";
600
601                         print "<a class=\"visibleLink\" href=\"#\" ".
602                                 "title=\"".__("Click to edit feed")."\" ".
603                                 "onclick=\"editFeed(".$line["id"].")\">".
604                                 htmlspecialchars($line["title"])."</a>";
605
606                         print "</td><td class=\"insensitive\" align='right'>";
607                         print make_local_datetime($this->link, $line['last_article'], false);
608                         print "</td>";
609                         print "</tr>";
610
611                         ++$lnum;
612                 }
613
614                 print "</table>";
615                 print "</div>";
616
617                 print "<div class='dlgButtons'>";
618                 print "<div style='float : left'>";
619                 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').removeSelected()\">"
620                         .__('Unsubscribe from selected feeds')."</button> ";
621                 print "</div>";
622
623                 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').hide()\">".
624                         __('Close this window')."</button>";
625
626                 print "</div>";
627
628         }
629
630         function feedsWithErrors() {
631                 print __("These feeds have not been updated because of errors:");
632
633                 $result = db_query($this->link, "SELECT id,title,feed_url,last_error,site_url
634                 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
635
636                 print "<div class=\"inactiveFeedHolder\">";
637
638                 print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
639
640                 $lnum = 1;
641
642                 while ($line = db_fetch_assoc($result)) {
643
644                         $class = ($lnum % 2) ? "even" : "odd";
645                         $feed_id = $line["id"];
646                         $this_row_id = "id=\"FUPDD-$feed_id\"";
647
648                         print "<tr class=\"\" $this_row_id>";
649
650                         $edit_title = htmlspecialchars($line["title"]);
651
652                         print "<td width='5%' align='center'><input
653                                 onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"
654                                 type=\"checkbox\"></td>";
655                         print "<td>";
656
657                         print "<a class=\"visibleLink\" href=\"#\" ".
658                                 "title=\"".__("Click to edit feed")."\" ".
659                                 "onclick=\"editFeed(".$line["id"].")\">".
660                                 htmlspecialchars($line["title"])."</a>: ";
661
662                         print "<span class=\"insensitive\">";
663                         print htmlspecialchars($line["last_error"]);
664                         print "</span>";
665
666                         print "</td>";
667                         print "</tr>";
668
669                         ++$lnum;
670                 }
671
672                 print "</table>";
673                 print "</div>";
674
675                 print "<div class='dlgButtons'>";
676                 print "<div style='float : left'>";
677                 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').removeSelected()\">"
678                         .__('Unsubscribe from selected feeds')."</button> ";
679                 print "</div>";
680
681                 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').hide()\">".
682                         __('Close this window')."</button>";
683
684                 print "</div>";
685         }
686
687         function editArticleTags() {
688
689                 print __("Tags for this article (separated by commas):")."<br>";
690
691                 $tags = get_article_tags($this->link, $this->param);
692
693                 $tags_str = join(", ", $tags);
694
695                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$this->param\">";
696                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
697                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setArticleTags\">";
698
699                 print "<table width='100%'><tr><td>";
700
701                 print "<textarea dojoType=\"dijit.form.SimpleTextarea\" rows='4'
702                         style='font-size : 12px; width : 100%' id=\"tags_str\"
703                         name='tags_str'>$tags_str</textarea>
704                 <div class=\"autocomplete\" id=\"tags_choices\"
705                                 style=\"display:none\"></div>";
706
707                 print "</td></tr></table>";
708
709                 print "<div class='dlgButtons'>";
710
711                 print "<button dojoType=\"dijit.form.Button\"
712                         onclick=\"dijit.byId('editTagsDlg').execute()\">".__('Save')."</button> ";
713                 print "<button dojoType=\"dijit.form.Button\"
714                         onclick=\"dijit.byId('editTagsDlg').hide()\">".__('Cancel')."</button>";
715                 print "</div>";
716
717         }
718
719         function printTagCloud() {
720                 print "<title>".__('Tag Cloud')."</title>";
721                 print "<content><![CDATA[";
722
723                 print "<div class=\"tagCloudContainer\">";
724
725                 // from here: http://www.roscripts.com/Create_tag_cloud-71.html
726
727                 $query = "SELECT tag_name, COUNT(post_int_id) AS count
728                         FROM ttrss_tags WHERE owner_uid = ".$_SESSION["uid"]."
729                         GROUP BY tag_name ORDER BY count DESC LIMIT 50";
730
731                 $result = db_query($this->link, $query);
732
733                 $tags = array();
734
735                 while ($line = db_fetch_assoc($result)) {
736                         $tags[$line["tag_name"]] = $line["count"];
737                 }
738
739         if( count($tags) == 0 ){ return; }
740
741                 ksort($tags);
742
743                 $max_size = 32; // max font size in pixels
744                 $min_size = 11; // min font size in pixels
745
746                 // largest and smallest array values
747                 $max_qty = max(array_values($tags));
748                 $min_qty = min(array_values($tags));
749
750                 // find the range of values
751                 $spread = $max_qty - $min_qty;
752                 if ($spread == 0) { // we don't want to divide by zero
753                                 $spread = 1;
754                 }
755
756                 // set the font-size increment
757                 $step = ($max_size - $min_size) / ($spread);
758
759                 // loop through the tag array
760                 foreach ($tags as $key => $value) {
761                         // calculate font-size
762                         // find the $value in excess of $min_qty
763                         // multiply by the font-size increment ($size)
764                         // and add the $min_size set above
765                         $size = round($min_size + (($value - $min_qty) * $step));
766
767                         $key_escaped = str_replace("'", "\\'", $key);
768
769                         echo "<a href=\"javascript:viewfeed('$key_escaped') \" style=\"font-size: " .
770                                 $size . "px\" title=\"$value articles tagged with " .
771                                 $key . '">' . $key . '</a> ';
772                 }
773
774
775
776                 print "</div>";
777
778                 print "<div align='center'>";
779                 print "<button dojoType=\"dijit.form.Button\"
780                         onclick=\"return closeInfoBox()\">".
781                         __('Close this window')."</button>";
782                 print "</div>";
783
784                 print "]]></content>";
785         }
786
787         function printTagSelect() {
788
789                 print "<title>" . __('Select item(s) by tags') . "</title>";
790                 print "<content><![CDATA[";
791
792                 print __("Match:"). "&nbsp;" .
793                           "<input class=\"noborder\" dojoType=\"dijit.form.RadioButton\" type=\"radio\" checked value=\"any\" name=\"tag_mode\">&nbsp;Any&nbsp;";
794                 print "<input class=\"noborder\" dojoType=\"dijit.form.RadioButton\" type=\"radio\" value=\"all\" name=\"tag_mode\">&nbsp;All&nbsp;";
795                 print "&nbsp;tags.";
796
797                 print "<select id=\"all_tags\" name=\"all_tags\" title=\"" . __('Which Tags?') . "\" multiple=\"multiple\" size=\"10\" style=\"width : 100%\">";
798                 $result = db_query($this->link, "SELECT DISTINCT tag_name FROM ttrss_tags WHERE owner_uid = ".$_SESSION['uid']."
799                         AND LENGTH(tag_name) <= 30 ORDER BY tag_name ASC");
800
801                 while ($row = db_fetch_assoc($result)) {
802                         $tmp = htmlspecialchars($row["tag_name"]);
803                         print "<option value=\"" . str_replace(" ", "%20", $tmp) . "\">$tmp</option>";
804                 }
805
806                 print "</select>";
807
808                 print "<div align='right'>";
809                 print "<button dojoType=\"dijit.form.Button\" onclick=\"viewfeed(get_all_tags($('all_tags')),
810                         get_radio_checked($('tag_mode')));\">" . __('Display entries') . "</button>";
811                 print "&nbsp;";
812                 print "<button dojoType=\"dijit.form.Button\"
813                 onclick=\"return closeInfoBox()\">" .
814                         __('Close this window') . "</button>";
815                 print "</div>";
816
817                 print "]]></content>";
818         }
819
820         function generatedFeed() {
821
822                 print "<title>".__('View as RSS')."</title>";
823                 print "<content><![CDATA[";
824
825                 $this->params = explode(":", $this->param, 3);
826                 $feed_id = db_escape_string($this->params[0]);
827                 $is_cat = (bool) $this->params[1];
828
829                 $key = get_feed_access_key($this->link, $feed_id, $is_cat);
830
831                 $url_path = htmlspecialchars($this->params[2]) . "&key=" . $key;
832
833                 print __("You can view this feed as RSS using the following URL:");
834
835                 print "<div class=\"tagCloudContainer\">";
836                 print "<a id='gen_feed_url' href='$url_path' target='_blank'>$url_path</a>";
837                 print "</div>";
838
839                 print "<div align='center'>";
840
841                 print "<button dojoType=\"dijit.form.Button\" onclick=\"return genUrlChangeKey('$feed_id', '$is_cat')\">".
842                         __('Generate new URL')."</button> ";
843
844                 print "<button dojoType=\"dijit.form.Button\" onclick=\"return closeInfoBox()\">".
845                         __('Close this window')."</button>";
846
847                 print "</div>";
848                 print "]]></content>";
849
850                 //return;
851         }
852
853         function newVersion() {
854
855                 $version_data = check_for_update($this->link);
856                 $version = $version_data['version'];
857                 $id = $version_data['version_id'];
858
859                 print "<div class='tagCloudContainer'>";
860
861                 print T_sprintf("New version of Tiny Tiny RSS is available (%s).",
862                         "<b>$version</b>");
863
864                 print "</div>";
865
866                 $details = "http://tt-rss.org/redmine/versions/show/$id";
867                 $download = "http://tt-rss.org/#Download";
868
869                 print "<div style='text-align : center'>";
870                 print "<button dojoType=\"dijit.form.Button\"
871                         onclick=\"return window.open('$details')\">".__("Details")."</button>";
872                 print "<button dojoType=\"dijit.form.Button\"
873                         onclick=\"return window.open('$download')\">".__("Download")."</button>";
874                 print "<button dojoType=\"dijit.form.Button\"
875                         onclick=\"return dijit.byId('newVersionDlg').hide()\">".
876                         __('Close this window')."</button>";
877                 print "</div>";
878
879         }
880
881         function customizeCSS() {
882                 $value = get_pref($this->link, "USER_STYLESHEET");
883
884                 $value = str_replace("<br/>", "\n", $value);
885
886                 print T_sprintf("You can override colors, fonts and layout of your currently selected theme with custom CSS declarations here. <a target=\"_blank\" class=\"visibleLink\" href=\"%s\">This file</a> can be used as a baseline.", "tt-rss.css");
887
888                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
889                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setpref\">";
890                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"key\" value=\"USER_STYLESHEET\">";
891
892                 print "<table width='100%'><tr><td>";
893                 print "<textarea dojoType=\"dijit.form.SimpleTextarea\"
894                         style='font-size : 12px; width : 100%; height: 200px;'
895                         placeHolder='body#ttrssMain { font-size : 14px; };'
896                         name='value'>$value</textarea>";
897                 print "</td></tr></table>";
898
899                 print "<div class='dlgButtons'>";
900                 print "<button dojoType=\"dijit.form.Button\"
901                         onclick=\"dijit.byId('cssEditDlg').execute()\">".__('Save')."</button> ";
902                 print "<button dojoType=\"dijit.form.Button\"
903                         onclick=\"dijit.byId('cssEditDlg').hide()\">".__('Cancel')."</button>";
904                 print "</div>";
905
906         }
907
908         function addInstance() {
909                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\"  name=\"op\" value=\"pref-instances\">";
910                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\"  name=\"method\" value=\"add\">";
911
912                 print "<div class=\"dlgSec\">".__("Instance")."</div>";
913
914                 print "<div class=\"dlgSecCont\">";
915
916                 /* URL */
917
918                 print __("URL:") . " ";
919
920                 print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"
921                         placeHolder=\"".__("Instance URL")."\"
922                         regExp='^(http|https)://.*'
923                         style=\"font-size : 16px; width: 20em\" name=\"access_url\">";
924
925                 print "<hr/>";
926
927                 $access_key = sha1(uniqid(rand(), true));
928
929                 /* Access key */
930
931                 print __("Access key:") . " ";
932
933                 print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"
934                         placeHolder=\"".__("Access key")."\" regExp='\w{40}'
935                         style=\"width: 20em\" name=\"access_key\" id=\"instance_add_key\"
936                         value=\"$access_key\">";
937
938                 print "<p class='insensitive'>" . __("Use one access key for both linked instances.");
939
940                 print "</div>";
941
942                 print "<div class=\"dlgButtons\">
943                         <div style='float : left'>
944                                 <button dojoType=\"dijit.form.Button\"
945                                         onclick=\"return dijit.byId('instanceAddDlg').regenKey()\">".
946                                         __('Generate new key')."</button>
947                         </div>
948                         <button dojoType=\"dijit.form.Button\"
949                                 onclick=\"return dijit.byId('instanceAddDlg').execute()\">".
950                                 __('Create link')."</button>
951                         <button dojoType=\"dijit.form.Button\"
952                                 onclick=\"return dijit.byId('instanceAddDlg').hide()\"\">".
953                                 __('Cancel')."</button></div>";
954
955                 return;
956         }
957
958         function dataImport() {
959                 header("Content-Type: text/html"); # required for iframe
960
961                 print "<div style='text-align : center'>";
962
963                 if (is_file($_FILES['export_file']['tmp_name'])) {
964
965                         perform_data_import($this->link, $_FILES['export_file']['tmp_name'], $_SESSION['uid']);
966
967                 } else {
968                         print "<p>" . T_sprintf("Could not upload file. You might need to adjust upload_max_filesize
969                                 in PHP.ini (current value = %s)", ini_get("upload_max_filesize")) . " or use CLI import tool.</p>";
970
971                 }
972
973                 print "<button dojoType=\"dijit.form.Button\"
974                         onclick=\"dijit.byId('dataImportDlg').hide()\">".
975                         __('Close this window')."</button>";
976
977                 print "</div>";
978
979         }
980
981 }
982 ?>