]> git.wh0rd.org - tt-rss.git/blob - classes/handler/public.php
Merge pull request #252 from Djuuu/master
[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
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=$feed&key=" .
69 get_feed_access_key($feed, 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
89 while ($line = $this->dbh->fetch_assoc($result)) {
90
91 $tpl->setVariable('ARTICLE_ID',
92 htmlspecialchars($orig_guid ? $line['link'] :
93 get_self_url_prefix() .
94 "/public.php?url=" . urlencode($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',
98 truncate_string(strip_tags($line["content_preview"]), 100, '...'), true);
99
100 $content = sanitize($line["content_preview"], false, $owner_uid);
101
102 if ($line['note']) {
103 $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
104 $content;
105 $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true);
106 }
107
108 $tpl->setVariable('ARTICLE_CONTENT', $content, true);
109
110 $tpl->setVariable('ARTICLE_UPDATED_ATOM',
111 date('c', strtotime($line["updated"])), true);
112 $tpl->setVariable('ARTICLE_UPDATED_RFC822',
113 date(DATE_RFC822, strtotime($line["updated"])), true);
114
115 $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
116
117 $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url']), true);
118 $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title']), true);
119
120 $tags = get_article_tags($line["id"], $owner_uid);
121
122 foreach ($tags as $tag) {
123 $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
124 $tpl->addBlock('category');
125 }
126
127 $enclosures = get_article_enclosures($line["id"]);
128
129 foreach ($enclosures as $e) {
130 $type = htmlspecialchars($e['content_type']);
131 $url = htmlspecialchars($e['content_url']);
132 $length = $e['duration'];
133
134 $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
135 $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
136 $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
137
138 $tpl->addBlock('enclosure');
139 }
140
141 $tpl->addBlock('entry');
142 }
143
144 $tmp = "";
145
146 $tpl->addBlock('feed');
147 $tpl->generateOutputToString($tmp);
148
149 if (@!$_REQUEST["noxml"]) {
150 header("Content-Type: text/xml; charset=utf-8");
151 } else {
152 header("Content-Type: text/plain; charset=utf-8");
153 }
154
155 print $tmp;
156 } else if ($format == 'json') {
157
158 $feed = array();
159
160 $feed['title'] = $feed_title;
161 $feed['version'] = VERSION;
162 $feed['feed_url'] = $feed_self_url;
163
164 if (PUBSUBHUBBUB_HUB && $feed == -2) {
165 $feed['hub_url'] = PUBSUBHUBBUB_HUB;
166 }
167
168 $feed['self_url'] = get_self_url_prefix();
169
170 $feed['articles'] = array();
171
172 while ($line = $this->dbh->fetch_assoc($result)) {
173 $article = array();
174
175 $article['id'] = $line['link'];
176 $article['link'] = $line['link'];
177 $article['title'] = $line['title'];
178 $article['excerpt'] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
179 $article['content'] = sanitize($line["content_preview"], 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 = sql_bool_to_bool($_REQUEST["is_cat"]);
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 $orig_guid = !sql_bool_to_bool($_REQUEST["no_orig_guid"]);
362
363 if (!$format) $format = 'atom';
364
365 if (SINGLE_USER_MODE) {
366 authenticate_user("admin", null);
367 }
368
369 $owner_id = false;
370
371 if ($key) {
372 $result = $this->dbh->query("SELECT owner_uid FROM
373 ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
374
375 if ($this->dbh->num_rows($result) == 1)
376 $owner_id = $this->dbh->fetch_result($result, 0, "owner_uid");
377 }
378
379 if ($owner_id) {
380 $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
381 $offset, $search, $search_mode, $view_mode, $format, $order, $orig_guid);
382 } else {
383 header('HTTP/1.1 403 Forbidden');
384 }
385 }
386
387 function globalUpdateFeeds() {
388 include "rssfuncs.php";
389 // Update all feeds needing a update.
390 update_daemon_common(0, true, false);
391 housekeeping_common(false);
392
393 PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", $op);
394
395 }
396
397 function sharepopup() {
398 if (SINGLE_USER_MODE) {
399 login_sequence();
400 }
401
402 header('Content-Type: text/html; charset=utf-8');
403 print "<html><head><title>Tiny Tiny RSS</title>";
404
405 stylesheet_tag("css/utility.css");
406 javascript_tag("lib/prototype.js");
407 javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,dragdrop,controls");
408 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
409 </head><body id='sharepopup'>";
410
411 $action = $_REQUEST["action"];
412
413 if ($_SESSION["uid"]) {
414
415 if ($action == 'share') {
416
417 $title = $this->dbh->escape_string(strip_tags($_REQUEST["title"]));
418 $url = $this->dbh->escape_string(strip_tags($_REQUEST["url"]));
419 $content = $this->dbh->escape_string(strip_tags($_REQUEST["content"]));
420 $labels = $this->dbh->escape_string(strip_tags($_REQUEST["labels"]));
421
422 Article::create_published_article($title, $url, $content, $labels,
423 $_SESSION["uid"]);
424
425 print "<script type='text/javascript'>";
426 print "window.close();";
427 print "</script>";
428
429 } else {
430 $title = htmlspecialchars($_REQUEST["title"]);
431 $url = htmlspecialchars($_REQUEST["url"]);
432
433 ?>
434
435 <table height='100%' width='100%'><tr><td colspan='2'>
436 <h1><?php echo __("Share with Tiny Tiny RSS") ?></h1>
437 </td></tr>
438
439 <form id='share_form' name='share_form'>
440
441 <input type="hidden" name="op" value="sharepopup">
442 <input type="hidden" name="action" value="share">
443
444 <tr><td align='right'><?php echo __("Title:") ?></td>
445 <td width='80%'><input name='title' value="<?php echo $title ?>"></td></tr>
446 <tr><td align='right'><?php echo __("URL:") ?></td>
447 <td><input name='url' value="<?php echo $url ?>"></td></tr>
448 <tr><td align='right'><?php echo __("Content:") ?></td>
449 <td><input name='content' value=""></td></tr>
450 <tr><td align='right'><?php echo __("Labels:") ?></td>
451 <td><input name='labels' id="labels_value"
452 placeholder='Alpha, Beta, Gamma' value="">
453 </td></tr>
454
455 <tr><td>
456 <div class="autocomplete" id="labels_choices"
457 style="display : block"></div></td></tr>
458
459 <script type='text/javascript'>document.forms[0].title.focus();</script>
460
461 <script type='text/javascript'>
462 new Ajax.Autocompleter('labels_value', 'labels_choices',
463 "backend.php?op=rpc&method=completeLabels",
464 { tokens: ',', paramName: "search" });
465 </script>
466
467 <tr><td colspan='2'>
468 <div style='float : right' class='insensitive-small'>
469 <?php echo __("Shared article will appear in the Published feed.") ?>
470 </div>
471 <button type="submit"><?php echo __('Share') ?></button>
472 <button onclick="return window.close()"><?php echo __('Cancel') ?></button>
473 </div>
474
475 </form>
476 </td></tr></table>
477 </body></html>
478 <?php
479
480 }
481
482 } else {
483
484 $return = urlencode($_SERVER["REQUEST_URI"])
485 ?>
486
487 <form action="public.php?return=<?php echo $return ?>"
488 method="POST" id="loginForm" name="loginForm">
489
490 <input type="hidden" name="op" value="login">
491
492 <table height='100%' width='100%'><tr><td colspan='2'>
493 <h1><?php echo __("Not logged in") ?></h1></td></tr>
494
495 <tr><td align="right"><?php echo __("Login:") ?></td>
496 <td align="right"><input name="login"
497 value="<?php echo $_SESSION["fake_login"] ?>"></td></tr>
498 <tr><td align="right"><?php echo __("Password:") ?></td>
499 <td align="right"><input type="password" name="password"
500 value="<?php echo $_SESSION["fake_password"] ?>"></td></tr>
501 <tr><td colspan='2'>
502 <button type="submit">
503 <?php echo __('Log in') ?></button>
504
505 <button onclick="return window.close()">
506 <?php echo __('Cancel') ?></button>
507 </td></tr>
508 </table>
509
510 </form>
511 <?php
512 }
513 }
514
515 function login() {
516 if (!SINGLE_USER_MODE) {
517
518 $login = $this->dbh->escape_string($_POST["login"]);
519 $password = $_POST["password"];
520 $remember_me = $_POST["remember_me"];
521
522 if ($remember_me) {
523 session_set_cookie_params(SESSION_COOKIE_LIFETIME);
524 } else {
525 session_set_cookie_params(0);
526 }
527
528 @session_start();
529
530 if (authenticate_user($login, $password)) {
531 $_POST["password"] = "";
532
533 if (get_schema_version() >= 120) {
534 $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
535 }
536
537 $_SESSION["ref_schema_version"] = get_schema_version(true);
538 $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
539
540 if ($_POST["profile"]) {
541
542 $profile = $this->dbh->escape_string($_POST["profile"]);
543
544 $result = $this->dbh->query("SELECT id FROM ttrss_settings_profiles
545 WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]);
546
547 if ($this->dbh->num_rows($result) != 0) {
548 $_SESSION["profile"] = $profile;
549 }
550 }
551 } else {
552 $_SESSION["login_error_msg"] = __("Incorrect username or password");
553 user_error("Failed login attempt from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING);
554 }
555
556 if ($_REQUEST['return']) {
557 header("Location: " . $_REQUEST['return']);
558 } else {
559 header("Location: " . SELF_URL_PATH);
560 }
561 }
562 }
563
564 function subscribe() {
565 if (SINGLE_USER_MODE) {
566 login_sequence();
567 }
568
569 if ($_SESSION["uid"]) {
570
571 $feed_url = $this->dbh->escape_string(trim($_REQUEST["feed_url"]));
572
573 header('Content-Type: text/html; charset=utf-8');
574 print "<html>
575 <head>
576 <title>Tiny Tiny RSS</title>
577 <link rel=\"stylesheet\" type=\"text/css\" href=\"css/utility.css\">
578 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
579 </head>
580 <body>
581 <img class=\"floatingLogo\" src=\"images/logo_small.png\"
582 alt=\"Tiny Tiny RSS\"/>
583 <h1>".__("Subscribe to feed...")."</h1><div class='content'>";
584
585 $rc = subscribe_to_feed($feed_url);
586
587 switch ($rc['code']) {
588 case 0:
589 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
590 break;
591 case 1:
592 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
593 break;
594 case 2:
595 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
596 break;
597 case 3:
598 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
599 break;
600 case 4:
601 print_notice(__("Multiple feed URLs found."));
602 $feed_urls = $rc["feeds"];
603 break;
604 case 5:
605 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
606 break;
607 }
608
609 if ($feed_urls) {
610
611 print "<form action=\"public.php\">";
612 print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">";
613
614 print "<select name=\"feed_url\">";
615
616 foreach ($feed_urls as $url => $name) {
617 $url = htmlspecialchars($url);
618 $name = htmlspecialchars($name);
619
620 print "<option value=\"$url\">$name</option>";
621 }
622
623 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
624 "\">";
625
626 print "</form>";
627 }
628
629 $tp_uri = get_self_url_prefix() . "/prefs.php";
630 $tt_uri = get_self_url_prefix();
631
632 if ($rc['code'] <= 2){
633 $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
634 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
635
636 $feed_id = $this->dbh->fetch_result($result, 0, "id");
637 } else {
638 $feed_id = 0;
639 }
640 print "<p>";
641
642 if ($feed_id) {
643 print "<form method=\"GET\" style='display: inline'
644 action=\"$tp_uri\">
645 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
646 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
647 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
648 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
649 </form>";
650 }
651
652 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
653 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
654 </form></p>";
655
656 print "</div></body></html>";
657
658 } else {
659 render_login_form();
660 }
661 }
662
663 function subscribe2() {
664 $feed_url = $this->dbh->escape_string(trim($_REQUEST["feed_url"]));
665 $cat_id = $this->dbh->escape_string($_REQUEST["cat_id"]);
666 $from = $this->dbh->escape_string($_REQUEST["from"]);
667 $feed_urls = array();
668
669 /* only read authentication information from POST */
670
671 $auth_login = $this->dbh->escape_string(trim($_POST["auth_login"]));
672 $auth_pass = $this->dbh->escape_string(trim($_POST["auth_pass"]));
673
674 $rc = subscribe_to_feed($feed_url, $cat_id, $auth_login, $auth_pass);
675
676 switch ($rc) {
677 case 1:
678 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
679 break;
680 case 2:
681 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
682 break;
683 case 3:
684 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
685 break;
686 case 0:
687 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
688 break;
689 case 4:
690 print_notice(__("Multiple feed URLs found."));
691 $contents = @fetch_file_contents($url, false, $auth_login, $auth_pass);
692 if (is_html($contents)) {
693 $feed_urls = get_feeds_from_html($url, $contents);
694 }
695 break;
696 case 5:
697 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
698 break;
699 }
700
701 if ($feed_urls) {
702 print "<form action=\"backend.php\">";
703 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
704 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
705 print "<input type=\"hidden\" name=\"method\" value=\"add\">";
706
707 print "<select name=\"feed_url\">";
708
709 foreach ($feed_urls as $url => $name) {
710 $url = htmlspecialchars($url);
711 $name = htmlspecialchars($name);
712 print "<option value=\"$url\">$name</option>";
713 }
714
715 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed")."\">";
716 print "</form>";
717 }
718
719 $tp_uri = get_self_url_prefix() . "/prefs.php";
720 $tt_uri = get_self_url_prefix();
721
722 if ($rc <= 2){
723 $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
724 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
725
726 $feed_id = $this->dbh->fetch_result($result, 0, "id");
727 } else {
728 $feed_id = 0;
729 }
730
731 print "<p>";
732
733 if ($feed_id) {
734 print "<form method=\"GET\" style='display: inline'
735 action=\"$tp_uri\">
736 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
737 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
738 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
739 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
740 </form>";
741 }
742
743 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
744 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
745 </form></p>";
746
747 print "</body></html>";
748 }
749
750 function index() {
751 header("Content-Type: text/plain");
752 print json_encode(array("error" => array("code" => 7)));
753 }
754
755 function forgotpass() {
756 startup_gettext();
757
758 header('Content-Type: text/html; charset=utf-8');
759 print "<html><head><title>Tiny Tiny RSS</title>";
760
761 stylesheet_tag("css/utility.css");
762 javascript_tag("lib/prototype.js");
763
764 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
765 </head><body id='forgotpass'>";
766
767 print '<div class="floatingLogo"><img src="images/logo_small.png"></div>';
768 print "<h1>".__("Password recovery")."</h1>";
769 print "<div class='content'>";
770
771 @$method = $_POST['method'];
772
773 if (!$method) {
774 print_notice(__("You will need to provide valid account name and email. New password will be sent on 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 $result = $this->dbh->query("SELECT id FROM ttrss_users
816 WHERE login = '$login' AND email = '$email'");
817
818 if ($this->dbh->num_rows($result) != 0) {
819 $id = $this->dbh->fetch_result($result, 0, "id");
820
821 Pref_Users::resetUserPassword($id, false);
822
823 print "<p>";
824
825 print "<p>"."Completed."."</p>";
826
827 print "<form method=\"GET\" action=\"index.php\">
828 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
829 </form>";
830
831 } else {
832 print_error(__("Sorry, login and email combination not found."));
833
834 print "<form method=\"GET\" action=\"public.php\">
835 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
836 <input type=\"submit\" value=\"".__("Go back")."\">
837 </form>";
838
839 }
840 }
841
842 }
843
844 print "</div>";
845 print "</body>";
846 print "</html>";
847
848 }
849
850 function dbupdate() {
851 startup_gettext();
852
853 if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) {
854 $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
855 render_login_form();
856 exit;
857 }
858
859 ?><html>
860 <head>
861 <title>Database Updater</title>
862 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
863 <link rel="stylesheet" type="text/css" href="css/utility.css"/>
864 </head>
865 <style type="text/css">
866 span.ok { color : #009000; font-weight : bold; }
867 span.err { color : #ff0000; font-weight : bold; }
868 </style>
869 <body>
870 <script type='text/javascript'>
871 function confirmOP() {
872 return confirm("Update the database?");
873 }
874 </script>
875
876 <div class="floatingLogo"><img src="images/logo_small.png"></div>
877
878 <h1><?php echo __("Database Updater") ?></h1>
879
880 <div class="content">
881
882 <?php
883 @$op = $_REQUEST["subop"];
884 $updater = new DbUpdater(Db::get(), DB_TYPE, SCHEMA_VERSION);
885
886 if ($op == "performupdate") {
887 if ($updater->isUpdateRequired()) {
888
889 print "<h2>Performing updates</h2>";
890
891 print "<h3>Updating to schema version " . SCHEMA_VERSION . "</h3>";
892
893 print "<ul>";
894
895 for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) {
896 print "<li>Performing update up to version $i...";
897
898 $result = $updater->performUpdateTo($i);
899
900 if (!$result) {
901 print "<span class='err'>FAILED!</span></li></ul>";
902
903 print_warning("One of the updates failed. Either retry the process or perform updates manually.");
904 print "<p><form method=\"GET\" action=\"index.php\">
905 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
906 </form>";
907
908 break;
909 } else {
910 print "<span class='ok'>OK!</span></li>";
911 }
912 }
913
914 print "</ul>";
915
916 print_notice("Your Tiny Tiny RSS database is now updated to the latest version.");
917
918 print "<p><form method=\"GET\" action=\"index.php\">
919 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
920 </form>";
921
922 } else {
923 print "<h2>Your database is up to date.</h2>";
924
925 print "<p><form method=\"GET\" action=\"index.php\">
926 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
927 </form>";
928 }
929 } else {
930 if ($updater->isUpdateRequired()) {
931
932 print "<h2>Database update required</h2>";
933
934 print "<h3>";
935 printf("Your Tiny Tiny RSS database needs update to the latest version: %d to %d.",
936 $updater->getSchemaVersion(), SCHEMA_VERSION);
937 print "</h3>";
938
939 print_warning("Please backup your database before proceeding.");
940
941 print "<form method='POST'>
942 <input type='hidden' name='subop' value='performupdate'>
943 <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
944 </form>";
945
946 } else {
947
948 print_notice("Tiny Tiny RSS database is up to date.");
949
950 print "<p><form method=\"GET\" action=\"index.php\">
951 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
952 </form>";
953
954 }
955 }
956 ?>
957
958 </div>
959 </body>
960 </html>
961 <?php
962 }
963
964 }
965 ?>