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