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