]> git.wh0rd.org - tt-rss.git/blob - classes/handler/public.php
Changed the implementation of HOOK_QUERY_HEADLINES to deal with issue Fox raised
[tt-rss.git] / classes / handler / public.php
1 <?php
2 class Handler_Public extends Handler {
3
4 private function generate_syndicated_feed($owner_uid, $feed, $is_cat,
5 $limit, $offset, $search, $search_mode,
6 $view_mode = false, $format = 'atom', $order = false) {
7
8 require_once "lib/MiniTemplator.class.php";
9
10 $note_style = "background-color : #fff7d5;
11 border-width : 1px; ".
12 "padding : 5px; border-style : dashed; border-color : #e7d796;".
13 "margin-bottom : 1em; color : #9a8c59;";
14
15 if (!$limit) $limit = 60;
16
17 $date_sort_field = "date_entered DESC, updated DESC";
18
19 if ($feed == -2)
20 $date_sort_field = "last_published DESC";
21 else if ($feed == -1)
22 $date_sort_field = "last_marked DESC";
23
24 switch ($order) {
25 case "title":
26 $date_sort_field = "ttrss_entries.title";
27 break;
28 case "date_reverse":
29 $date_sort_field = "date_entered, updated";
30 break;
31 case "feed_dates":
32 $date_sort_field = "updated DESC";
33 break;
34 }
35
36 $qfh_ret = queryFeedHeadlines($feed,
37 1, $view_mode, $is_cat, $search, $search_mode,
38 $date_sort_field, $offset, $owner_uid,
39 false, 0, false, true);
40
41 $result = $qfh_ret[0];
42
43 if ($this->dbh->num_rows($result) != 0) {
44 $ts = strtotime($this->dbh->fetch_result($result, 0, "date_entered"));
45
46 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
47 strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $ts) {
48 header('HTTP/1.0 304 Not Modified');
49 return;
50 }
51
52 $last_modified = gmdate("D, d M Y H:i:s", $ts) . " GMT";
53 header("Last-Modified: $last_modified", true);
54 }
55
56 $qfh_ret = queryFeedHeadlines($feed,
57 $limit, $view_mode, $is_cat, $search, $search_mode,
58 $date_sort_field, $offset, $owner_uid,
59 false, 0, false, true);
60
61
62 $result = $qfh_ret[0];
63 $feed_title = htmlspecialchars($qfh_ret[1]);
64 $feed_site_url = $qfh_ret[2];
65 $last_error = $qfh_ret[3];
66
67 $feed_self_url = get_self_url_prefix() .
68 "/public.php?op=rss&id=-2&key=" .
69 get_feed_access_key(-2, false, $owner_uid);
70
71 if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
72
73 if ($format == 'atom') {
74 $tpl = new MiniTemplator;
75
76 $tpl->readTemplateFromFile("templates/generated_feed.txt");
77
78 $tpl->setVariable('FEED_TITLE', $feed_title, true);
79 $tpl->setVariable('VERSION', VERSION, true);
80 $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
81
82 if (PUBSUBHUBBUB_HUB && $feed == -2) {
83 $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB), true);
84 $tpl->addBlock('feed_hub');
85 }
86
87 $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
88 $line["content_preview"] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
89 while ($line = $this->dbh->fetch_assoc($result)) {
90 foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
91 $line = $p->hook_query_headlines($line);
92 }
93
94 $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']), true);
95 $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
96 $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
97 $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true);
98
99 $content = sanitize($line["content"], false, $owner_uid);
100
101 if ($line['note']) {
102 $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
103 $content;
104 $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true);
105 }
106
107 $tpl->setVariable('ARTICLE_CONTENT', $content, true);
108
109 $tpl->setVariable('ARTICLE_UPDATED_ATOM',
110 date('c', strtotime($line["updated"])), true);
111 $tpl->setVariable('ARTICLE_UPDATED_RFC822',
112 date(DATE_RFC822, strtotime($line["updated"])), true);
113
114 $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
115
116 $tags = get_article_tags($line["id"], $owner_uid);
117
118 foreach ($tags as $tag) {
119 $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
120 $tpl->addBlock('category');
121 }
122
123 $enclosures = get_article_enclosures($line["id"]);
124
125 foreach ($enclosures as $e) {
126 $type = htmlspecialchars($e['content_type']);
127 $url = htmlspecialchars($e['content_url']);
128 $length = $e['duration'];
129
130 $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
131 $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
132 $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
133
134 $tpl->addBlock('enclosure');
135 }
136
137 $tpl->addBlock('entry');
138 }
139
140 $tmp = "";
141
142 $tpl->addBlock('feed');
143 $tpl->generateOutputToString($tmp);
144
145 if (@!$_REQUEST["noxml"]) {
146 header("Content-Type: text/xml; charset=utf-8");
147 } else {
148 header("Content-Type: text/plain; charset=utf-8");
149 }
150
151 print $tmp;
152 } else if ($format == 'json') {
153
154 $feed = array();
155
156 $feed['title'] = $feed_title;
157 $feed['version'] = VERSION;
158 $feed['feed_url'] = $feed_self_url;
159
160 if (PUBSUBHUBBUB_HUB && $feed == -2) {
161 $feed['hub_url'] = PUBSUBHUBBUB_HUB;
162 }
163
164 $feed['self_url'] = get_self_url_prefix();
165
166 $feed['articles'] = array();
167
168 while ($line = $this->dbh->fetch_assoc($result)) {
169 $line["content_preview"]] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
170 foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
171 $line = $p->hook_query_headlines($line, 100);
172 }
173 $article = array();
174
175 $article['id'] = $line['link'];
176 $article['link'] = $line['link'];
177 $article['title'] = $line['title'];
178 $article['excerpt'] = $line["content_preview"];
179 $article['content'] = sanitize($line["content"], false, $owner_uid);
180 $article['updated'] = date('c', strtotime($line["updated"]));
181
182 if ($line['note']) $article['note'] = $line['note'];
183 if ($article['author']) $article['author'] = $line['author'];
184
185 $tags = get_article_tags($line["id"], $owner_uid);
186
187 if (count($tags) > 0) {
188 $article['tags'] = array();
189
190 foreach ($tags as $tag) {
191 array_push($article['tags'], $tag);
192 }
193 }
194
195 $enclosures = get_article_enclosures($line["id"]);
196
197 if (count($enclosures) > 0) {
198 $article['enclosures'] = array();
199
200 foreach ($enclosures as $e) {
201 $type = $e['content_type'];
202 $url = $e['content_url'];
203 $length = $e['duration'];
204
205 array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
206 }
207 }
208
209 array_push($feed['articles'], $article);
210 }
211
212 header("Content-Type: text/json; charset=utf-8");
213 print json_encode($feed);
214
215 } else {
216 header("Content-Type: text/plain; charset=utf-8");
217 print json_encode(array("error" => array("message" => "Unknown format")));
218 }
219 }
220
221 function getUnread() {
222 $login = $this->dbh->escape_string($_REQUEST["login"]);
223 $fresh = $_REQUEST["fresh"] == "1";
224
225 $result = $this->dbh->query("SELECT id FROM ttrss_users WHERE login = '$login'");
226
227 if ($this->dbh->num_rows($result) == 1) {
228 $uid = $this->dbh->fetch_result($result, 0, "id");
229
230 print getGlobalUnread($uid);
231
232 if ($fresh) {
233 print ";";
234 print getFeedArticles(-3, false, true, $uid);
235 }
236
237 } else {
238 print "-1;User not found";
239 }
240
241 }
242
243 function getProfiles() {
244 $login = $this->dbh->escape_string($_REQUEST["login"]);
245
246 $result = $this->dbh->query("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users
247 WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = '$login' ORDER BY title");
248
249 print "<select dojoType='dijit.form.Select' style='width : 220px; margin : 0px' name='profile'>";
250
251 print "<option value='0'>" . __("Default profile") . "</option>";
252
253 while ($line = $this->dbh->fetch_assoc($result)) {
254 $id = $line["id"];
255 $title = $line["title"];
256
257 print "<option value='$id'>$title</option>";
258 }
259
260 print "</select>";
261 }
262
263 function pubsub() {
264 $mode = $this->dbh->escape_string($_REQUEST['hub_mode']);
265 $feed_id = (int) $this->dbh->escape_string($_REQUEST['id']);
266 $feed_url = $this->dbh->escape_string($_REQUEST['hub_topic']);
267
268 if (!PUBSUBHUBBUB_ENABLED) {
269 header('HTTP/1.0 404 Not Found');
270 echo "404 Not found";
271 return;
272 }
273
274 // TODO: implement hub_verifytoken checking
275
276 $result = $this->dbh->query("SELECT feed_url FROM ttrss_feeds
277 WHERE id = '$feed_id'");
278
279 if ($this->dbh->num_rows($result) != 0) {
280
281 $check_feed_url = $this->dbh->fetch_result($result, 0, "feed_url");
282
283 if ($check_feed_url && ($check_feed_url == $feed_url || !$feed_url)) {
284 if ($mode == "subscribe") {
285
286 $this->dbh->query("UPDATE ttrss_feeds SET pubsub_state = 2
287 WHERE id = '$feed_id'");
288
289 print $_REQUEST['hub_challenge'];
290 return;
291
292 } else if ($mode == "unsubscribe") {
293
294 $this->dbh->query("UPDATE ttrss_feeds SET pubsub_state = 0
295 WHERE id = '$feed_id'");
296
297 print $_REQUEST['hub_challenge'];
298 return;
299
300 } else if (!$mode) {
301
302 // Received update ping, schedule feed update.
303 //update_rss_feed($feed_id, true, true);
304
305 $this->dbh->query("UPDATE ttrss_feeds SET
306 last_update_started = '1970-01-01',
307 last_updated = '1970-01-01' WHERE id = '$feed_id'");
308
309 }
310 } else {
311 header('HTTP/1.0 404 Not Found');
312 echo "404 Not found";
313 }
314 } else {
315 header('HTTP/1.0 404 Not Found');
316 echo "404 Not found";
317 }
318
319 }
320
321 function logout() {
322 logout_user();
323 header("Location: index.php");
324 }
325
326 function share() {
327 $uuid = $this->dbh->escape_string($_REQUEST["key"]);
328
329 $result = $this->dbh->query("SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
330 uuid = '$uuid'");
331
332 if ($this->dbh->num_rows($result) != 0) {
333 header("Content-Type: text/html");
334
335 $id = $this->dbh->fetch_result($result, 0, "ref_id");
336 $owner_uid = $this->dbh->fetch_result($result, 0, "owner_uid");
337
338 $article = format_article($id, false, true, $owner_uid);
339
340 print_r($article['content']);
341
342 } else {
343 print "Article not found.";
344 }
345
346 }
347
348 function rss() {
349 $feed = $this->dbh->escape_string($_REQUEST["id"]);
350 $key = $this->dbh->escape_string($_REQUEST["key"]);
351 $is_cat = $_REQUEST["is_cat"] != false;
352 $limit = (int)$this->dbh->escape_string($_REQUEST["limit"]);
353 $offset = (int)$this->dbh->escape_string($_REQUEST["offset"]);
354
355 $search = $this->dbh->escape_string($_REQUEST["q"]);
356 $search_mode = $this->dbh->escape_string($_REQUEST["smode"]);
357 $view_mode = $this->dbh->escape_string($_REQUEST["view-mode"]);
358 $order = $this->dbh->escape_string($_REQUEST["order"]);
359
360 $format = $this->dbh->escape_string($_REQUEST['format']);
361
362 if (!$format) $format = 'atom';
363
364 if (SINGLE_USER_MODE) {
365 authenticate_user("admin", null);
366 }
367
368 $owner_id = false;
369
370 if ($key) {
371 $result = $this->dbh->query("SELECT owner_uid FROM
372 ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
373
374 if ($this->dbh->num_rows($result) == 1)
375 $owner_id = $this->dbh->fetch_result($result, 0, "owner_uid");
376 }
377
378 if ($owner_id) {
379 $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
380 $offset, $search, $search_mode, $view_mode, $format, $order);
381 } else {
382 header('HTTP/1.1 403 Forbidden');
383 }
384 }
385
386 function globalUpdateFeeds() {
387 include "rssfuncs.php";
388 // Update all feeds needing a update.
389 update_daemon_common(0, true, false);
390 housekeeping_common(false);
391
392 PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", $op);
393
394 }
395
396 function sharepopup() {
397 if (SINGLE_USER_MODE) {
398 login_sequence();
399 }
400
401 header('Content-Type: text/html; charset=utf-8');
402 print "<html><head><title>Tiny Tiny RSS</title>";
403
404 stylesheet_tag("css/utility.css");
405 javascript_tag("lib/prototype.js");
406 javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,dragdrop,controls");
407 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
408 </head><body id='sharepopup'>";
409
410 $action = $_REQUEST["action"];
411
412 if ($_SESSION["uid"]) {
413
414 if ($action == 'share') {
415
416 $title = $this->dbh->escape_string(strip_tags($_REQUEST["title"]));
417 $url = $this->dbh->escape_string(strip_tags($_REQUEST["url"]));
418 $content = $this->dbh->escape_string(strip_tags($_REQUEST["content"]));
419 $labels = $this->dbh->escape_string(strip_tags($_REQUEST["labels"]));
420
421 Article::create_published_article($title, $url, $content, $labels,
422 $_SESSION["uid"]);
423
424 print "<script type='text/javascript'>";
425 print "window.close();";
426 print "</script>";
427
428 } else {
429 $title = htmlspecialchars($_REQUEST["title"]);
430 $url = htmlspecialchars($_REQUEST["url"]);
431
432 ?>
433
434 <table height='100%' width='100%'><tr><td colspan='2'>
435 <h1><?php echo __("Share with Tiny Tiny RSS") ?></h1>
436 </td></tr>
437
438 <form id='share_form' name='share_form'>
439
440 <input type="hidden" name="op" value="sharepopup">
441 <input type="hidden" name="action" value="share">
442
443 <tr><td align='right'><?php echo __("Title:") ?></td>
444 <td width='80%'><input name='title' value="<?php echo $title ?>"></td></tr>
445 <tr><td align='right'><?php echo __("URL:") ?></td>
446 <td><input name='url' value="<?php echo $url ?>"></td></tr>
447 <tr><td align='right'><?php echo __("Content:") ?></td>
448 <td><input name='content' value=""></td></tr>
449 <tr><td align='right'><?php echo __("Labels:") ?></td>
450 <td><input name='labels' id="labels_value"
451 placeholder='Alpha, Beta, Gamma' value="">
452 </td></tr>
453
454 <tr><td>
455 <div class="autocomplete" id="labels_choices"
456 style="display : block"></div></td></tr>
457
458 <script type='text/javascript'>document.forms[0].title.focus();</script>
459
460 <script type='text/javascript'>
461 new Ajax.Autocompleter('labels_value', 'labels_choices',
462 "backend.php?op=rpc&method=completeLabels",
463 { tokens: ',', paramName: "search" });
464 </script>
465
466 <tr><td colspan='2'>
467 <div style='float : right' class='insensitive-small'>
468 <?php echo __("Shared article will appear in the Published feed.") ?>
469 </div>
470 <button type="submit"><?php echo __('Share') ?></button>
471 <button onclick="return window.close()"><?php echo __('Cancel') ?></button>
472 </div>
473
474 </form>
475 </td></tr></table>
476 </body></html>
477 <?php
478
479 }
480
481 } else {
482
483 $return = urlencode($_SERVER["REQUEST_URI"])
484 ?>
485
486 <form action="public.php?return=<?php echo $return ?>"
487 method="POST" id="loginForm" name="loginForm">
488
489 <input type="hidden" name="op" value="login">
490
491 <table height='100%' width='100%'><tr><td colspan='2'>
492 <h1><?php echo __("Not logged in") ?></h1></td></tr>
493
494 <tr><td align="right"><?php echo __("Login:") ?></td>
495 <td align="right"><input name="login"
496 value="<?php echo $_SESSION["fake_login"] ?>"></td></tr>
497 <tr><td align="right"><?php echo __("Password:") ?></td>
498 <td align="right"><input type="password" name="password"
499 value="<?php echo $_SESSION["fake_password"] ?>"></td></tr>
500 <tr><td colspan='2'>
501 <button type="submit">
502 <?php echo __('Log in') ?></button>
503
504 <button onclick="return window.close()">
505 <?php echo __('Cancel') ?></button>
506 </td></tr>
507 </table>
508
509 </form>
510 <?php
511 }
512 }
513
514 function login() {
515 if (!SINGLE_USER_MODE) {
516
517 $login = $this->dbh->escape_string($_POST["login"]);
518 $password = $_POST["password"];
519 $remember_me = $_POST["remember_me"];
520
521 if ($remember_me) {
522 session_set_cookie_params(SESSION_COOKIE_LIFETIME);
523 } else {
524 session_set_cookie_params(0);
525 }
526
527 @session_start();
528
529 if (authenticate_user($login, $password)) {
530 $_POST["password"] = "";
531
532 if (get_schema_version() >= 120) {
533 $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
534 }
535
536 $_SESSION["ref_schema_version"] = get_schema_version(true);
537 $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
538
539 if ($_POST["profile"]) {
540
541 $profile = $this->dbh->escape_string($_POST["profile"]);
542
543 $result = $this->dbh->query("SELECT id FROM ttrss_settings_profiles
544 WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]);
545
546 if ($this->dbh->num_rows($result) != 0) {
547 $_SESSION["profile"] = $profile;
548 }
549 }
550 } else {
551 $_SESSION["login_error_msg"] = __("Incorrect username or password");
552 }
553
554 if ($_REQUEST['return']) {
555 header("Location: " . $_REQUEST['return']);
556 } else {
557 header("Location: " . SELF_URL_PATH);
558 }
559 }
560 }
561
562 function subscribe() {
563 if (SINGLE_USER_MODE) {
564 login_sequence();
565 }
566
567 if ($_SESSION["uid"]) {
568
569 $feed_url = $this->dbh->escape_string(trim($_REQUEST["feed_url"]));
570
571 header('Content-Type: text/html; charset=utf-8');
572 print "<html>
573 <head>
574 <title>Tiny Tiny RSS</title>
575 <link rel=\"stylesheet\" type=\"text/css\" href=\"css/utility.css\">
576 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
577 </head>
578 <body>
579 <img class=\"floatingLogo\" src=\"images/logo_small.png\"
580 alt=\"Tiny Tiny RSS\"/>
581 <h1>".__("Subscribe to feed...")."</h1><div class='content'>";
582
583 $rc = subscribe_to_feed($feed_url);
584
585 switch ($rc['code']) {
586 case 0:
587 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
588 break;
589 case 1:
590 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
591 break;
592 case 2:
593 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
594 break;
595 case 3:
596 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
597 break;
598 case 4:
599 print_notice(__("Multiple feed URLs found."));
600 $feed_urls = $rc["feeds"];
601 break;
602 case 5:
603 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
604 break;
605 }
606
607 if ($feed_urls) {
608
609 print "<form action=\"public.php\">";
610 print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">";
611
612 print "<select name=\"feed_url\">";
613
614 foreach ($feed_urls as $url => $name) {
615 $url = htmlspecialchars($url);
616 $name = htmlspecialchars($name);
617
618 print "<option value=\"$url\">$name</option>";
619 }
620
621 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
622 "\">";
623
624 print "</form>";
625 }
626
627 $tp_uri = get_self_url_prefix() . "/prefs.php";
628 $tt_uri = get_self_url_prefix();
629
630 if ($rc['code'] <= 2){
631 $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
632 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
633
634 $feed_id = $this->dbh->fetch_result($result, 0, "id");
635 } else {
636 $feed_id = 0;
637 }
638 print "<p>";
639
640 if ($feed_id) {
641 print "<form method=\"GET\" style='display: inline'
642 action=\"$tp_uri\">
643 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
644 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
645 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
646 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
647 </form>";
648 }
649
650 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
651 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
652 </form></p>";
653
654 print "</div></body></html>";
655
656 } else {
657 render_login_form();
658 }
659 }
660
661 function subscribe2() {
662 $feed_url = $this->dbh->escape_string(trim($_REQUEST["feed_url"]));
663 $cat_id = $this->dbh->escape_string($_REQUEST["cat_id"]);
664 $from = $this->dbh->escape_string($_REQUEST["from"]);
665 $feed_urls = array();
666
667 /* only read authentication information from POST */
668
669 $auth_login = $this->dbh->escape_string(trim($_POST["auth_login"]));
670 $auth_pass = $this->dbh->escape_string(trim($_POST["auth_pass"]));
671
672 $rc = subscribe_to_feed($feed_url, $cat_id, $auth_login, $auth_pass);
673
674 switch ($rc) {
675 case 1:
676 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
677 break;
678 case 2:
679 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
680 break;
681 case 3:
682 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
683 break;
684 case 0:
685 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
686 break;
687 case 4:
688 print_notice(__("Multiple feed URLs found."));
689 $contents = @fetch_file_contents($url, false, $auth_login, $auth_pass);
690 if (is_html($contents)) {
691 $feed_urls = get_feeds_from_html($url, $contents);
692 }
693 break;
694 case 5:
695 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
696 break;
697 }
698
699 if ($feed_urls) {
700 print "<form action=\"backend.php\">";
701 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
702 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
703 print "<input type=\"hidden\" name=\"method\" value=\"add\">";
704
705 print "<select name=\"feed_url\">";
706
707 foreach ($feed_urls as $url => $name) {
708 $url = htmlspecialchars($url);
709 $name = htmlspecialchars($name);
710 print "<option value=\"$url\">$name</option>";
711 }
712
713 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed")."\">";
714 print "</form>";
715 }
716
717 $tp_uri = get_self_url_prefix() . "/prefs.php";
718 $tt_uri = get_self_url_prefix();
719
720 if ($rc <= 2){
721 $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
722 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
723
724 $feed_id = $this->dbh->fetch_result($result, 0, "id");
725 } else {
726 $feed_id = 0;
727 }
728
729 print "<p>";
730
731 if ($feed_id) {
732 print "<form method=\"GET\" style='display: inline'
733 action=\"$tp_uri\">
734 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
735 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
736 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
737 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
738 </form>";
739 }
740
741 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
742 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
743 </form></p>";
744
745 print "</body></html>";
746 }
747
748 function index() {
749 header("Content-Type: text/plain");
750 print json_encode(array("error" => array("code" => 7)));
751 }
752
753 function forgotpass() {
754 startup_gettext();
755
756 header('Content-Type: text/html; charset=utf-8');
757 print "<html><head><title>Tiny Tiny RSS</title>";
758
759 stylesheet_tag("css/utility.css");
760 javascript_tag("lib/prototype.js");
761
762 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
763 </head><body id='forgotpass'>";
764
765 print '<div class="floatingLogo"><img src="images/logo_small.png"></div>';
766 print "<h1>".__("Password recovery")."</h1>";
767 print "<div class='content'>";
768
769 @$method = $_POST['method'];
770
771 if (!$method) {
772 print_notice(__("You will need to provide valid account name and email. New password will be sent on your email address."));
773
774 print "<form method='POST' action='public.php'>";
775 print "<input type='hidden' name='method' value='do'>";
776 print "<input type='hidden' name='op' value='forgotpass'>";
777
778 print "<fieldset>";
779 print "<label>".__("Login:")."</label>";
780 print "<input type='text' name='login' value='' required>";
781 print "</fieldset>";
782
783 print "<fieldset>";
784 print "<label>".__("Email:")."</label>";
785 print "<input type='email' name='email' value='' required>";
786 print "</fieldset>";
787
788 print "<fieldset>";
789 print "<label>".__("How much is two plus two:")."</label>";
790 print "<input type='text' name='test' value='' required>";
791 print "</fieldset>";
792
793 print "<p/>";
794 print "<button type='submit'>".__("Reset password")."</button>";
795
796 print "</form>";
797 } else if ($method == 'do') {
798
799 $login = $this->dbh->escape_string($_POST["login"]);
800 $email = $this->dbh->escape_string($_POST["email"]);
801 $test = $this->dbh->escape_string($_POST["test"]);
802
803 if (($test != 4 && $test != 'four') || !$email || !$login) {
804 print_error(__('Some of the required form parameters are missing or incorrect.'));
805
806 print "<form method=\"GET\" action=\"public.php\">
807 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
808 <input type=\"submit\" value=\"".__("Go back")."\">
809 </form>";
810
811 } else {
812
813 $result = $this->dbh->query("SELECT id FROM ttrss_users
814 WHERE login = '$login' AND email = '$email'");
815
816 if ($this->dbh->num_rows($result) != 0) {
817 $id = $this->dbh->fetch_result($result, 0, "id");
818
819 Pref_Users::resetUserPassword($id, false);
820
821 print "<p>";
822
823 print "<p>"."Completed."."</p>";
824
825 print "<form method=\"GET\" action=\"index.php\">
826 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
827 </form>";
828
829 } else {
830 print_error(__("Sorry, login and email combination not found."));
831
832 print "<form method=\"GET\" action=\"public.php\">
833 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
834 <input type=\"submit\" value=\"".__("Go back")."\">
835 </form>";
836
837 }
838 }
839
840 }
841
842 print "</div>";
843 print "</body>";
844 print "</html>";
845
846 }
847
848 function dbupdate() {
849 startup_gettext();
850
851 if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) {
852 $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
853 render_login_form();
854 exit;
855 }
856
857 ?><html>
858 <head>
859 <title>Database Updater</title>
860 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
861 <link rel="stylesheet" type="text/css" href="css/utility.css"/>
862 </head>
863 <style type="text/css">
864 span.ok { color : #009000; font-weight : bold; }
865 span.err { color : #ff0000; font-weight : bold; }
866 </style>
867 <body>
868 <script type='text/javascript'>
869 function confirmOP() {
870 return confirm("Update the database?");
871 }
872 </script>
873
874 <div class="floatingLogo"><img src="images/logo_small.png"></div>
875
876 <h1><?php echo __("Database Updater") ?></h1>
877
878 <div class="content">
879
880 <?php
881 @$op = $_REQUEST["subop"];
882 $updater = new DbUpdater(Db::get(), DB_TYPE, SCHEMA_VERSION);
883
884 if ($op == "performupdate") {
885 if ($updater->isUpdateRequired()) {
886
887 print "<h2>Performing updates</h2>";
888
889 print "<h3>Updating to schema version " . SCHEMA_VERSION . "</h3>";
890
891 print "<ul>";
892
893 for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) {
894 print "<li>Performing update up to version $i...";
895
896 $result = $updater->performUpdateTo($i);
897
898 if (!$result) {
899 print "<span class='err'>FAILED!</span></li></ul>";
900
901 print_warning("One of the updates failed. Either retry the process or perform updates manually.");
902 print "<p><form method=\"GET\" action=\"index.php\">
903 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
904 </form>";
905
906 break;
907 } else {
908 print "<span class='ok'>OK!</span></li>";
909 }
910 }
911
912 print "</ul>";
913
914 print_notice("Your Tiny Tiny RSS database is now updated to the latest version.");
915
916 print "<p><form method=\"GET\" action=\"index.php\">
917 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
918 </form>";
919
920 } else {
921 print "<h2>Your database is up to date.</h2>";
922
923 print "<p><form method=\"GET\" action=\"index.php\">
924 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
925 </form>";
926 }
927 } else {
928 if ($updater->isUpdateRequired()) {
929
930 print "<h2>Database update required</h2>";
931
932 print "<h3>";
933 printf("Your Tiny Tiny RSS database needs update to the latest version: %d to %d.",
934 $updater->getSchemaVersion(), SCHEMA_VERSION);
935 print "</h3>";
936
937 print_warning("Please backup your database before proceeding.");
938
939 print "<form method='POST'>
940 <input type='hidden' name='subop' value='performupdate'>
941 <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
942 </form>";
943
944 } else {
945
946 print_notice("Tiny Tiny RSS database is up to date.");
947
948 print "<p><form method=\"GET\" action=\"index.php\">
949 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
950 </form>";
951
952 }
953 }
954 ?>
955
956 </div>
957 </body>
958 </html>
959 <?php
960 }
961
962 }
963 ?>