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