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