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