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