]> git.wh0rd.org - tt-rss.git/blame - classes/handler/public.php
daemon2: make wrong schema version error display if quiet
[tt-rss.git] / classes / handler / public.php
CommitLineData
5f0a3741 1<?php
369dbc19 2class Handler_Public extends Handler {
5f0a3741 3
79178062 4 private function generate_syndicated_feed($owner_uid, $feed, $is_cat,
ca5d9be4 5 $limit, $offset, $search, $search_mode,
ce565216 6 $view_mode = false, $format = 'atom') {
79178062
AD
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
c3d2cda8 15 if (!$limit) $limit = 100;
79178062 16
8aa01d79 17 $date_sort_field = "date_entered DESC, updated DESC";
79178062 18
008ebad9 19 if ($feed == -2)
7ef7dd31 20 $date_sort_field = "last_published DESC";
feb9b2df 21 else if ($feed == -1)
7ef7dd31 22 $date_sort_field = "last_marked DESC";
008ebad9 23
79178062
AD
24 $qfh_ret = queryFeedHeadlines($this->link, $feed,
25 $limit, $view_mode, $is_cat, $search, $search_mode,
8aa01d79 26 $date_sort_field, $offset, $owner_uid,
6b3f228f 27 false, 0, false, true);
79178062
AD
28
29 $result = $qfh_ret[0];
30 $feed_title = htmlspecialchars($qfh_ret[1]);
31 $feed_site_url = $qfh_ret[2];
32 $last_error = $qfh_ret[3];
33
34 $feed_self_url = get_self_url_prefix() .
35 "/public.php?op=rss&id=-2&key=" .
2fb947eb 36 get_feed_access_key($this->link, -2, false, $owner_uid);
79178062
AD
37
38 if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
39
2ebf38a9
AD
40 if ($format == 'atom') {
41 $tpl = new MiniTemplator;
79178062 42
2ebf38a9 43 $tpl->readTemplateFromFile("templates/generated_feed.txt");
79178062 44
2ebf38a9
AD
45 $tpl->setVariable('FEED_TITLE', $feed_title, true);
46 $tpl->setVariable('VERSION', VERSION, true);
47 $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
79178062 48
2ebf38a9
AD
49 if (PUBSUBHUBBUB_HUB && $feed == -2) {
50 $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB), true);
51 $tpl->addBlock('feed_hub');
52 }
79178062 53
2ebf38a9 54 $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
79178062 55
2ebf38a9
AD
56 while ($line = db_fetch_assoc($result)) {
57 $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']), true);
58 $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
59 $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
60 $tpl->setVariable('ARTICLE_EXCERPT',
61 truncate_string(strip_tags($line["content_preview"]), 100, '...'), true);
79178062 62
b3682750 63 $content = sanitize($this->link, $line["content_preview"], false, $owner_uid);
79178062 64
2ebf38a9
AD
65 if ($line['note']) {
66 $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
67 $content;
e9c6e27d 68 $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true);
69 }
2ebf38a9
AD
70
71 $tpl->setVariable('ARTICLE_CONTENT', $content, true);
72
73 $tpl->setVariable('ARTICLE_UPDATED_ATOM',
74 date('c', strtotime($line["updated"])), true);
75 $tpl->setVariable('ARTICLE_UPDATED_RFC822',
76 date(DATE_RFC822, strtotime($line["updated"])), true);
77
78 $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
79
80 $tags = get_article_tags($this->link, $line["id"], $owner_uid);
81
82 foreach ($tags as $tag) {
83 $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
84 $tpl->addBlock('category');
85 }
79178062 86
2ebf38a9 87 $enclosures = get_article_enclosures($this->link, $line["id"]);
79178062 88
2ebf38a9
AD
89 foreach ($enclosures as $e) {
90 $type = htmlspecialchars($e['content_type']);
91 $url = htmlspecialchars($e['content_url']);
92 $length = $e['duration'];
9c97041d 93
2ebf38a9
AD
94 $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
95 $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
96 $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
79178062 97
2ebf38a9
AD
98 $tpl->addBlock('enclosure');
99 }
79178062 100
2ebf38a9 101 $tpl->addBlock('entry');
79178062
AD
102 }
103
2ebf38a9
AD
104 $tmp = "";
105
106 $tpl->addBlock('feed');
107 $tpl->generateOutputToString($tmp);
108
10bdeb4b
AD
109 if (@!$_REQUEST["noxml"]) {
110 header("Content-Type: text/xml; charset=utf-8");
111 } else {
112 header("Content-Type: text/plain; charset=utf-8");
113 }
2ebf38a9
AD
114
115 print $tmp;
116 } else if ($format == 'json') {
79178062 117
2ebf38a9 118 $feed = array();
79178062 119
2ebf38a9
AD
120 $feed['title'] = $feed_title;
121 $feed['version'] = VERSION;
122 $feed['feed_url'] = $feed_self_url;
79178062 123
2ebf38a9
AD
124 if (PUBSUBHUBBUB_HUB && $feed == -2) {
125 $feed['hub_url'] = PUBSUBHUBBUB_HUB;
79178062
AD
126 }
127
2ebf38a9
AD
128 $feed['self_url'] = get_self_url_prefix();
129
130 $feed['articles'] = array();
131
132 while ($line = db_fetch_assoc($result)) {
133 $article = array();
79178062 134
2ebf38a9
AD
135 $article['id'] = $line['link'];
136 $article['link'] = $line['link'];
137 $article['title'] = $line['title'];
138 $article['excerpt'] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
b3682750 139 $article['content'] = sanitize($this->link, $line["content_preview"], false, $owner_uid);
2ebf38a9 140 $article['updated'] = date('c', strtotime($line["updated"]));
79178062 141
2ebf38a9
AD
142 if ($line['note']) $article['note'] = $line['note'];
143 if ($article['author']) $article['author'] = $line['author'];
79178062 144
2ebf38a9
AD
145 $tags = get_article_tags($this->link, $line["id"], $owner_uid);
146
147 if (count($tags) > 0) {
148 $article['tags'] = array();
149
150 foreach ($tags as $tag) {
151 array_push($article['tags'], $tag);
152 }
153 }
154
155 $enclosures = get_article_enclosures($this->link, $line["id"]);
156
157 if (count($enclosures) > 0) {
158 $article['enclosures'] = array();
159
160 foreach ($enclosures as $e) {
161 $type = $e['content_type'];
162 $url = $e['content_url'];
163 $length = $e['duration'];
164
165 array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
166 }
167 }
168
169 array_push($feed['articles'], $article);
170 }
171
10bdeb4b 172 header("Content-Type: text/json; charset=utf-8");
2ebf38a9
AD
173 print json_encode($feed);
174
175 } else {
176 header("Content-Type: text/plain; charset=utf-8");
177 print json_encode(array("error" => array("message" => "Unknown format")));
178 }
79178062
AD
179 }
180
5f0a3741 181 function getUnread() {
3972bf59 182 $login = db_escape_string($this->link, $_REQUEST["login"]);
5f0a3741
AD
183 $fresh = $_REQUEST["fresh"] == "1";
184
185 $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE login = '$login'");
186
187 if (db_num_rows($result) == 1) {
188 $uid = db_fetch_result($result, 0, "id");
189
190 print getGlobalUnread($this->link, $uid);
191
192 if ($fresh) {
193 print ";";
194 print getFeedArticles($this->link, -3, false, true, $uid);
195 }
196
197 } else {
198 print "-1;User not found";
199 }
200
201 }
202
203 function getProfiles() {
3972bf59 204 $login = db_escape_string($this->link, $_REQUEST["login"]);
5f0a3741 205
97acbaf1
AD
206 $result = db_query($this->link, "SELECT * FROM ttrss_settings_profiles,ttrss_users
207 WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = '$login' ORDER BY title");
5f0a3741 208
eeee2ccf 209 print "<select dojoType='dijit.form.Select' style='width : 220px; margin : 0px' name='profile'>";
5f0a3741 210
97acbaf1 211 print "<option value='0'>" . __("Default profile") . "</option>";
5f0a3741 212
97acbaf1
AD
213 while ($line = db_fetch_assoc($result)) {
214 $id = $line["id"];
215 $title = $line["title"];
5f0a3741 216
97acbaf1 217 print "<option value='$id'>$title</option>";
5f0a3741 218 }
97acbaf1
AD
219
220 print "</select>";
5f0a3741
AD
221 }
222
223 function pubsub() {
3972bf59
AD
224 $mode = db_escape_string($this->link, $_REQUEST['hub_mode']);
225 $feed_id = (int) db_escape_string($this->link, $_REQUEST['id']);
226 $feed_url = db_escape_string($this->link, $_REQUEST['hub_topic']);
5f0a3741
AD
227
228 if (!PUBSUBHUBBUB_ENABLED) {
229 header('HTTP/1.0 404 Not Found');
230 echo "404 Not found";
231 return;
232 }
233
234 // TODO: implement hub_verifytoken checking
235
236 $result = db_query($this->link, "SELECT feed_url FROM ttrss_feeds
237 WHERE id = '$feed_id'");
238
239 if (db_num_rows($result) != 0) {
240
241 $check_feed_url = db_fetch_result($result, 0, "feed_url");
242
243 if ($check_feed_url && ($check_feed_url == $feed_url || !$feed_url)) {
244 if ($mode == "subscribe") {
245
246 db_query($this->link, "UPDATE ttrss_feeds SET pubsub_state = 2
247 WHERE id = '$feed_id'");
248
249 print $_REQUEST['hub_challenge'];
250 return;
251
252 } else if ($mode == "unsubscribe") {
253
254 db_query($this->link, "UPDATE ttrss_feeds SET pubsub_state = 0
255 WHERE id = '$feed_id'");
256
257 print $_REQUEST['hub_challenge'];
258 return;
259
260 } else if (!$mode) {
261
262 // Received update ping, schedule feed update.
263 //update_rss_feed($this->link, $feed_id, true, true);
264
265 db_query($this->link, "UPDATE ttrss_feeds SET
266 last_update_started = '1970-01-01',
267 last_updated = '1970-01-01' WHERE id = '$feed_id'");
268
269 }
270 } else {
271 header('HTTP/1.0 404 Not Found');
272 echo "404 Not found";
273 }
274 } else {
275 header('HTTP/1.0 404 Not Found');
276 echo "404 Not found";
277 }
278
279 }
280
281 function logout() {
282 logout_user();
283 header("Location: index.php");
284 }
285
5f0a3741 286 function share() {
3972bf59 287 $uuid = db_escape_string($this->link, $_REQUEST["key"]);
5f0a3741
AD
288
289 $result = db_query($this->link, "SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
290 uuid = '$uuid'");
291
292 if (db_num_rows($result) != 0) {
293 header("Content-Type: text/html");
294
295 $id = db_fetch_result($result, 0, "ref_id");
296 $owner_uid = db_fetch_result($result, 0, "owner_uid");
297
64436e10 298 $article = format_article($this->link, $id, false, true, $owner_uid);
5f0a3741
AD
299
300 print_r($article['content']);
301
302 } else {
303 print "Article not found.";
304 }
305
306 }
307
308 function rss() {
3972bf59
AD
309 $feed = db_escape_string($this->link, $_REQUEST["id"]);
310 $key = db_escape_string($this->link, $_REQUEST["key"]);
5f0a3741 311 $is_cat = $_REQUEST["is_cat"] != false;
3972bf59
AD
312 $limit = (int)db_escape_string($this->link, $_REQUEST["limit"]);
313 $offset = (int)db_escape_string($this->link, $_REQUEST["offset"]);
5f0a3741 314
3972bf59
AD
315 $search = db_escape_string($this->link, $_REQUEST["q"]);
316 $search_mode = db_escape_string($this->link, $_REQUEST["smode"]);
317 $view_mode = db_escape_string($this->link, $_REQUEST["view-mode"]);
5f0a3741 318
3972bf59 319 $format = db_escape_string($this->link, $_REQUEST['format']);
2ebf38a9
AD
320
321 if (!$format) $format = 'atom';
322
5f0a3741
AD
323 if (SINGLE_USER_MODE) {
324 authenticate_user($this->link, "admin", null);
325 }
326
327 $owner_id = false;
328
329 if ($key) {
330 $result = db_query($this->link, "SELECT owner_uid FROM
331 ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
332
333 if (db_num_rows($result) == 1)
334 $owner_id = db_fetch_result($result, 0, "owner_uid");
335 }
336
337 if ($owner_id) {
2fb947eb 338 $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
ca5d9be4 339 $offset, $search, $search_mode, $view_mode, $format);
5f0a3741
AD
340 } else {
341 header('HTTP/1.1 403 Forbidden');
342 }
343 }
344
07391e36
AD
345 function globalUpdateFeeds() {
346 include "rssfuncs.php";
5f0a3741 347 // Update all feeds needing a update.
036cd3a4 348 update_daemon_common($this->link, 0, true, false);
cda55d67
AD
349
350 // Update feedbrowser
351 update_feedbrowser_cache($this->link);
352
353 // Purge orphans and cleanup tags
354 purge_orphans($this->link);
355
356 cleanup_tags($this->link, 14, 50000);
357
358 global $pluginhost;
359 $pluginhost->run_hooks($pluginhost::HOOK_UPDATE_TASK, "hook_update_task", $op);
360
07391e36 361 }
8361e724
AD
362
363 function sharepopup() {
61a748f8
AD
364 if (SINGLE_USER_MODE) {
365 login_sequence($this->link);
366 }
367
8361e724 368 header('Content-Type: text/html; charset=utf-8');
9a2aed91
AD
369 print "<html><head><title>Tiny Tiny RSS</title>";
370
371 print stylesheet_tag("utility.css");
372 print javascript_tag("lib/prototype.js");
373 print javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,dragdrop,controls");
374 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
375 </head><body id='sharepopup'>";
8361e724
AD
376
377 $action = $_REQUEST["action"];
378
379 if ($_SESSION["uid"]) {
380
d493aba2 381 if ($action == 'share') {
8361e724 382
3972bf59
AD
383 $title = db_escape_string($this->link, strip_tags($_REQUEST["title"]));
384 $url = db_escape_string($this->link, strip_tags($_REQUEST["url"]));
385 $content = db_escape_string($this->link, strip_tags($_REQUEST["content"]));
386 $labels = db_escape_string($this->link, strip_tags($_REQUEST["labels"]));
8361e724 387
50832719 388 Article::create_published_article($this->link, $title, $url, $content, $labels,
1b4d1a6b 389 $_SESSION["uid"]);
8361e724 390
d493aba2
AD
391 print "<script type='text/javascript'>";
392 print "window.close();";
393 print "</script>";
8361e724 394
d493aba2 395 } else {
8361e724
AD
396 $title = htmlspecialchars($_REQUEST["title"]);
397 $url = htmlspecialchars($_REQUEST["url"]);
398
d493aba2 399 ?>
8361e724 400
d493aba2
AD
401 <table height='100%' width='100%'><tr><td colspan='2'>
402 <h1><?php echo __("Share with Tiny Tiny RSS") ?></h1>
403 </td></tr>
8361e724 404
d493aba2 405 <form id='share_form' name='share_form'>
8361e724 406
d493aba2
AD
407 <input type="hidden" name="op" value="sharepopup">
408 <input type="hidden" name="action" value="share">
8361e724 409
22439dad 410 <tr><td align='right'><?php echo __("Title:") ?></td>
d493aba2 411 <td width='80%'><input name='title' value="<?php echo $title ?>"></td></tr>
22439dad 412 <tr><td align='right'><?php echo __("URL:") ?></td>
d493aba2 413 <td><input name='url' value="<?php echo $url ?>"></td></tr>
22439dad 414 <tr><td align='right'><?php echo __("Content:") ?></td>
d493aba2 415 <td><input name='content' value=""></td></tr>
1b4d1a6b
AD
416 <tr><td align='right'><?php echo __("Labels:") ?></td>
417 <td><input name='labels' id="labels_value"
418 placeholder='Alpha, Beta, Gamma' value="">
419 </td></tr>
420
421 <tr><td>
422 <div class="autocomplete" id="labels_choices"
423 style="display : block"></div></td></tr>
8361e724 424
d493aba2 425 <script type='text/javascript'>document.forms[0].title.focus();</script>
8361e724 426
1b4d1a6b
AD
427 <script type='text/javascript'>
428 new Ajax.Autocompleter('labels_value', 'labels_choices',
429 "backend.php?op=rpc&method=completeLabels",
430 { tokens: ',', paramName: "search" });
431 </script>
432
d493aba2
AD
433 <tr><td colspan='2'>
434 <div style='float : right' class='insensitive-small'>
435 <?php echo __("Shared article will appear in the Published feed.") ?>
436 </div>
437 <button type="submit"><?php echo __('Share') ?></button>
438 <button onclick="return window.close()"><?php echo __('Cancel') ?></button>
439 </div>
8361e724 440
d493aba2
AD
441 </form>
442 </td></tr></table>
443 </body></html>
444 <?php
8361e724 445
8361e724
AD
446 }
447
448 } else {
449
d493aba2
AD
450 $return = urlencode($_SERVER["REQUEST_URI"])
451 ?>
452
453 <form action="public.php?return=<?php echo $return ?>"
22439dad 454 method="POST" id="loginForm" name="loginForm">
d493aba2
AD
455
456 <input type="hidden" name="op" value="login">
457
458 <table height='100%' width='100%'><tr><td colspan='2'>
22439dad 459 <h1><?php echo __("Not logged in") ?></h1></td></tr>
d493aba2
AD
460
461 <tr><td align="right"><?php echo __("Login:") ?></td>
462 <td align="right"><input name="login"
463 value="<?php echo $_SESSION["fake_login"] ?>"></td></tr>
464 <tr><td align="right"><?php echo __("Password:") ?></td>
465 <td align="right"><input type="password" name="password"
466 value="<?php echo $_SESSION["fake_password"] ?>"></td></tr>
467 <tr><td align="right"><?php echo __("Language:") ?></td>
468 <td align="right">
469 <?php
470 print_select_hash("language", $_COOKIE["ttrss_lang"], get_translations(),
471 "style='width : 100%''");
472
473 ?>
474 </td></tr>
475 <tr><td colspan='2'>
476 <button type="submit">
477 <?php echo __('Log in') ?></button>
478
479 <button onclick="return window.close()">
480 <?php echo __('Cancel') ?></button>
481 </td></tr>
482 </table>
483
484 </form>
485 <?php
8361e724
AD
486 }
487 }
488
97acbaf1 489 function login() {
97acbaf1
AD
490 $_SESSION["prefs_cache"] = array();
491
492 if (!SINGLE_USER_MODE) {
493
3972bf59 494 $login = db_escape_string($this->link, $_POST["login"]);
97acbaf1
AD
495 $password = $_POST["password"];
496 $remember_me = $_POST["remember_me"];
497
f231f438
AD
498 if ($remember_me) {
499 session_set_cookie_params(SESSION_COOKIE_LIFETIME);
500 } else {
501 session_set_cookie_params(0);
502 }
503
60ed4c9a
AD
504 @session_start();
505
97acbaf1
AD
506 if (authenticate_user($this->link, $login, $password)) {
507 $_POST["password"] = "";
508
509 $_SESSION["language"] = $_POST["language"];
510 $_SESSION["ref_schema_version"] = get_schema_version($this->link, true);
511 $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
512
513 if ($_POST["profile"]) {
514
3972bf59 515 $profile = db_escape_string($this->link, $_POST["profile"]);
97acbaf1
AD
516
517 $result = db_query($this->link, "SELECT id FROM ttrss_settings_profiles
518 WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]);
519
520 if (db_num_rows($result) != 0) {
521 $_SESSION["profile"] = $profile;
522 $_SESSION["prefs_cache"] = array();
523 }
524 }
525 } else {
526 $_SESSION["login_error_msg"] = __("Incorrect username or password");
527 }
528
529 if ($_REQUEST['return']) {
530 header("Location: " . $_REQUEST['return']);
531 } else {
532 header("Location: " . SELF_URL_PATH);
533 }
534 }
535 }
536
537 function subscribe() {
61a748f8
AD
538 if (SINGLE_USER_MODE) {
539 login_sequence($this->link);
540 }
541
97acbaf1
AD
542 if ($_SESSION["uid"]) {
543
3972bf59 544 $feed_url = db_escape_string($this->link, trim($_REQUEST["feed_url"]));
97acbaf1
AD
545
546 header('Content-Type: text/html; charset=utf-8');
547 print "<html>
548 <head>
549 <title>Tiny Tiny RSS</title>
550 <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
551 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
552 </head>
553 <body>
884d1650 554 <img class=\"floatingLogo\" src=\"images/logo_small.png\"
97acbaf1 555 alt=\"Tiny Tiny RSS\"/>
884d1650 556 <h1>".__("Subscribe to feed...")."</h1><div class='content'>";
97acbaf1
AD
557
558 $rc = subscribe_to_feed($this->link, $feed_url);
559
560 switch ($rc['code']) {
561 case 0:
562 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
563 break;
564 case 1:
565 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
566 break;
567 case 2:
568 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
569 break;
570 case 3:
571 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
572 break;
573 case 4:
574 print_notice(__("Multiple feed URLs found."));
759e5132 575 $feed_urls = $rc["feeds"];
97acbaf1
AD
576 break;
577 case 5:
578 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
579 break;
580 }
581
582 if ($feed_urls) {
583
584 print "<form action=\"public.php\">";
585 print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">";
586
587 print "<select name=\"feed_url\">";
588
589 foreach ($feed_urls as $url => $name) {
590 $url = htmlspecialchars($url);
591 $name = htmlspecialchars($name);
592
593 print "<option value=\"$url\">$name</option>";
594 }
595
596 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
597 "\">";
598
599 print "</form>";
600 }
601
602 $tp_uri = get_self_url_prefix() . "/prefs.php";
603 $tt_uri = get_self_url_prefix();
604
605 if ($rc['code'] <= 2){
606 $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
607 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
608
609 $feed_id = db_fetch_result($result, 0, "id");
610 } else {
611 $feed_id = 0;
612 }
613 print "<p>";
614
615 if ($feed_id) {
616 print "<form method=\"GET\" style='display: inline'
617 action=\"$tp_uri\">
618 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
619 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
620 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
621 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
622 </form>";
623 }
624
625 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
626 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
627 </form></p>";
628
884d1650 629 print "</div></body></html>";
97acbaf1
AD
630
631 } else {
632 render_login_form($this->link);
633 }
634 }
635
636 function subscribe2() {
3972bf59
AD
637 $feed_url = db_escape_string($this->link, trim($_REQUEST["feed_url"]));
638 $cat_id = db_escape_string($this->link, $_REQUEST["cat_id"]);
639 $from = db_escape_string($this->link, $_REQUEST["from"]);
97acbaf1
AD
640
641 /* only read authentication information from POST */
642
3972bf59
AD
643 $auth_login = db_escape_string($this->link, trim($_POST["auth_login"]));
644 $auth_pass = db_escape_string($this->link, trim($_POST["auth_pass"]));
97acbaf1
AD
645
646 $rc = subscribe_to_feed($this->link, $feed_url, $cat_id, $auth_login, $auth_pass);
647
648 switch ($rc) {
649 case 1:
650 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
651 break;
652 case 2:
653 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
654 break;
655 case 3:
656 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
657 break;
658 case 0:
659 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
660 break;
661 case 4:
662 print_notice(__("Multiple feed URLs found."));
663
664 $feed_urls = get_feeds_from_html($feed_url);
665 break;
666 case 5:
667 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
668 break;
669 }
670
671 if ($feed_urls) {
672 print "<form action=\"backend.php\">";
673 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
674 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
675 print "<input type=\"hidden\" name=\"method\" value=\"add\">";
676
677 print "<select name=\"feed_url\">";
678
679 foreach ($feed_urls as $url => $name) {
680 $url = htmlspecialchars($url);
681 $name = htmlspecialchars($name);
682 print "<option value=\"$url\">$name</option>";
683 }
684
685 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed")."\">";
686 print "</form>";
687 }
688
689 $tp_uri = get_self_url_prefix() . "/prefs.php";
690 $tt_uri = get_self_url_prefix();
691
692 if ($rc <= 2){
693 $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
694 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
695
696 $feed_id = db_fetch_result($result, 0, "id");
697 } else {
698 $feed_id = 0;
699 }
700
701 print "<p>";
702
703 if ($feed_id) {
704 print "<form method=\"GET\" style='display: inline'
705 action=\"$tp_uri\">
706 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
707 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
708 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
709 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
710 </form>";
711 }
712
713 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
714 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
715 </form></p>";
716
717 print "</body></html>";
718 }
719
720 function index() {
721 header("Content-Type: text/plain");
722 print json_encode(array("error" => array("code" => 7)));
723 }
724
f43e9e97
AD
725 function forgotpass() {
726 header('Content-Type: text/html; charset=utf-8');
e216d302
AD
727 print "<html><head><title>Tiny Tiny RSS</title>";
728
729 print stylesheet_tag("utility.css");
730 print javascript_tag("lib/prototype.js");
731
732 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
733 </head><body id='forgotpass'>";
f43e9e97 734
884d1650 735 print '<div class="floatingLogo"><img src="images/logo_small.png"></div>';
483f15d5 736 print "<h1>".__("Password recovery")."</h1>";
884d1650 737 print "<div class='content'>";
f43e9e97
AD
738
739 @$method = $_POST['method'];
740
741 if (!$method) {
483f15d5
AD
742 print_notice(__("You will need to provide valid account name and email. New password will be sent on your email address."));
743
f43e9e97 744 print "<form method='POST' action='public.php'>";
f43e9e97
AD
745 print "<input type='hidden' name='method' value='do'>";
746 print "<input type='hidden' name='op' value='forgotpass'>";
747
748 print "<fieldset>";
749 print "<label>".__("Login:")."</label>";
750 print "<input type='text' name='login' value='' required>";
751 print "</fieldset>";
752
753 print "<fieldset>";
754 print "<label>".__("Email:")."</label>";
755 print "<input type='email' name='email' value='' required>";
756 print "</fieldset>";
757
758 print "<fieldset>";
759 print "<label>".__("How much is two plus two:")."</label>";
760 print "<input type='text' name='test' value='' required>";
761 print "</fieldset>";
762
763 print "<p/>";
764 print "<button type='submit'>".__("Reset password")."</button>";
765
766 print "</form>";
767 } else if ($method == 'do') {
768
f43e9e97
AD
769 $login = db_escape_string($this->link, $_POST["login"]);
770 $email = db_escape_string($this->link, $_POST["email"]);
771 $test = db_escape_string($this->link, $_POST["test"]);
772
773 if (($test != 4 && $test != 'four') || !$email || !$login) {
774 print_error(__('Some of the required form parameters are missing or incorrect.'));
775
483f15d5
AD
776 print "<form method=\"GET\" action=\"public.php\">
777 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
778 <input type=\"submit\" value=\"".__("Go back")."\">
779 </form>";
f43e9e97 780
e216d302 781 } else {
f43e9e97
AD
782
783 $result = db_query($this->link, "SELECT id FROM ttrss_users
784 WHERE login = '$login' AND email = '$email'");
785
786 if (db_num_rows($result) != 0) {
787 $id = db_fetch_result($result, 0, "id");
788
789 Pref_Users::resetUserPassword($this->link, $id, false);
790
483f15d5
AD
791 print "<p>";
792
e216d302 793 print "<p>"."Completed."."</p>";
483f15d5
AD
794
795 print "<form method=\"GET\" action=\"index.php\">
796 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
797 </form>";
f43e9e97
AD
798
799 } else {
800 print_error(__("Sorry, login and email combination not found."));
483f15d5
AD
801
802 print "<form method=\"GET\" action=\"public.php\">
803 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
804 <input type=\"submit\" value=\"".__("Go back")."\">
805 </form>";
806
f43e9e97 807 }
f43e9e97
AD
808 }
809
810 }
811
884d1650 812 print "</div>";
f43e9e97
AD
813 print "</body>";
814 print "</html>";
815
816 }
817
5f0a3741
AD
818}
819?>