]> git.wh0rd.org - tt-rss.git/blame - classes/handler/public.php
one more change to merge to origin
[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,
25051fb8 6 $view_mode = false, $format = 'atom', $order = 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() .
68 "/public.php?op=rss&id=-2&key=" .
a42c55f0 69 get_feed_access_key(-2, 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);
79178062 88
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
2ebf38a9
AD
94 $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']), true);
95 $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
96 $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
891e36f5 97 if(isset($line["modified_preview"]))
98 $tpl->setVariable('ARTICLE_EXCERPT', strip_tags($line["content_preview"]), true);
99 else
100 $tpl->setVariable('ARTICLE_EXCERPT',
101 truncate_string(strip_tags($line["content_preview"]), 100, '...'), 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
a42c55f0 120 $tags = get_article_tags($line["id"], $owner_uid);
2ebf38a9
AD
121
122 foreach ($tags as $tag) {
123 $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
124 $tpl->addBlock('category');
125 }
79178062 126
a42c55f0 127 $enclosures = get_article_enclosures($line["id"]);
79178062 128
2ebf38a9
AD
129 foreach ($enclosures as $e) {
130 $type = htmlspecialchars($e['content_type']);
131 $url = htmlspecialchars($e['content_url']);
132 $length = $e['duration'];
9c97041d 133
2ebf38a9
AD
134 $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
135 $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
136 $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
79178062 137
2ebf38a9
AD
138 $tpl->addBlock('enclosure');
139 }
79178062 140
2ebf38a9 141 $tpl->addBlock('entry');
79178062
AD
142 }
143
2ebf38a9
AD
144 $tmp = "";
145
146 $tpl->addBlock('feed');
147 $tpl->generateOutputToString($tmp);
148
10bdeb4b
AD
149 if (@!$_REQUEST["noxml"]) {
150 header("Content-Type: text/xml; charset=utf-8");
151 } else {
152 header("Content-Type: text/plain; charset=utf-8");
153 }
2ebf38a9
AD
154
155 print $tmp;
156 } else if ($format == 'json') {
79178062 157
2ebf38a9 158 $feed = array();
79178062 159
2ebf38a9
AD
160 $feed['title'] = $feed_title;
161 $feed['version'] = VERSION;
162 $feed['feed_url'] = $feed_self_url;
79178062 163
2ebf38a9
AD
164 if (PUBSUBHUBBUB_HUB && $feed == -2) {
165 $feed['hub_url'] = PUBSUBHUBBUB_HUB;
79178062
AD
166 }
167
2ebf38a9
AD
168 $feed['self_url'] = get_self_url_prefix();
169
170 $feed['articles'] = array();
171
d9c85e0f 172 while ($line = $this->dbh->fetch_assoc($result)) {
891e36f5 173 foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
174 $line = $p->hook_query_headlines($line, 100);
175 }
2ebf38a9 176 $article = array();
79178062 177
2ebf38a9
AD
178 $article['id'] = $line['link'];
179 $article['link'] = $line['link'];
180 $article['title'] = $line['title'];
891e36f5 181 if(isset($line["modified_preview"]))
182 $article['excerpt'] = strip_tags($line["content_preview"]);
183 else
184 $article['excerpt'] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
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"]);
5f0a3741 357 $is_cat = $_REQUEST["is_cat"] != false;
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']);
2ebf38a9
AD
367
368 if (!$format) $format = 'atom';
369
5f0a3741 370 if (SINGLE_USER_MODE) {
a42c55f0 371 authenticate_user("admin", null);
5f0a3741
AD
372 }
373
374 $owner_id = false;
375
376 if ($key) {
d9c85e0f 377 $result = $this->dbh->query("SELECT owner_uid FROM
5f0a3741
AD
378 ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
379
d9c85e0f
AD
380 if ($this->dbh->num_rows($result) == 1)
381 $owner_id = $this->dbh->fetch_result($result, 0, "owner_uid");
5f0a3741
AD
382 }
383
384 if ($owner_id) {
2fb947eb 385 $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
25051fb8 386 $offset, $search, $search_mode, $view_mode, $format, $order);
5f0a3741
AD
387 } else {
388 header('HTTP/1.1 403 Forbidden');
389 }
390 }
391
07391e36
AD
392 function globalUpdateFeeds() {
393 include "rssfuncs.php";
5f0a3741 394 // Update all feeds needing a update.
a42c55f0 395 update_daemon_common(0, true, false);
e2cf81e2 396 housekeeping_common(false);
cda55d67 397
1ffe3391 398 PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", $op);
cda55d67 399
07391e36 400 }
8361e724
AD
401
402 function sharepopup() {
61a748f8 403 if (SINGLE_USER_MODE) {
6322ac79 404 login_sequence();
61a748f8
AD
405 }
406
8361e724 407 header('Content-Type: text/html; charset=utf-8');
9a2aed91
AD
408 print "<html><head><title>Tiny Tiny RSS</title>";
409
5bbc4bb4 410 stylesheet_tag("css/utility.css");
6f7798b6
RL
411 javascript_tag("lib/prototype.js");
412 javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,dragdrop,controls");
9a2aed91
AD
413 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
414 </head><body id='sharepopup'>";
8361e724
AD
415
416 $action = $_REQUEST["action"];
417
418 if ($_SESSION["uid"]) {
419
d493aba2 420 if ($action == 'share') {
8361e724 421
d9c85e0f
AD
422 $title = $this->dbh->escape_string(strip_tags($_REQUEST["title"]));
423 $url = $this->dbh->escape_string(strip_tags($_REQUEST["url"]));
424 $content = $this->dbh->escape_string(strip_tags($_REQUEST["content"]));
425 $labels = $this->dbh->escape_string(strip_tags($_REQUEST["labels"]));
8361e724 426
a42c55f0 427 Article::create_published_article($title, $url, $content, $labels,
1b4d1a6b 428 $_SESSION["uid"]);
8361e724 429
d493aba2
AD
430 print "<script type='text/javascript'>";
431 print "window.close();";
432 print "</script>";
8361e724 433
d493aba2 434 } else {
8361e724
AD
435 $title = htmlspecialchars($_REQUEST["title"]);
436 $url = htmlspecialchars($_REQUEST["url"]);
437
d493aba2 438 ?>
8361e724 439
d493aba2
AD
440 <table height='100%' width='100%'><tr><td colspan='2'>
441 <h1><?php echo __("Share with Tiny Tiny RSS") ?></h1>
442 </td></tr>
8361e724 443
d493aba2 444 <form id='share_form' name='share_form'>
8361e724 445
d493aba2
AD
446 <input type="hidden" name="op" value="sharepopup">
447 <input type="hidden" name="action" value="share">
8361e724 448
22439dad 449 <tr><td align='right'><?php echo __("Title:") ?></td>
d493aba2 450 <td width='80%'><input name='title' value="<?php echo $title ?>"></td></tr>
22439dad 451 <tr><td align='right'><?php echo __("URL:") ?></td>
d493aba2 452 <td><input name='url' value="<?php echo $url ?>"></td></tr>
22439dad 453 <tr><td align='right'><?php echo __("Content:") ?></td>
d493aba2 454 <td><input name='content' value=""></td></tr>
1b4d1a6b
AD
455 <tr><td align='right'><?php echo __("Labels:") ?></td>
456 <td><input name='labels' id="labels_value"
457 placeholder='Alpha, Beta, Gamma' value="">
458 </td></tr>
459
460 <tr><td>
461 <div class="autocomplete" id="labels_choices"
462 style="display : block"></div></td></tr>
8361e724 463
d493aba2 464 <script type='text/javascript'>document.forms[0].title.focus();</script>
8361e724 465
1b4d1a6b
AD
466 <script type='text/javascript'>
467 new Ajax.Autocompleter('labels_value', 'labels_choices',
468 "backend.php?op=rpc&method=completeLabels",
469 { tokens: ',', paramName: "search" });
470 </script>
471
d493aba2
AD
472 <tr><td colspan='2'>
473 <div style='float : right' class='insensitive-small'>
474 <?php echo __("Shared article will appear in the Published feed.") ?>
475 </div>
476 <button type="submit"><?php echo __('Share') ?></button>
477 <button onclick="return window.close()"><?php echo __('Cancel') ?></button>
478 </div>
8361e724 479
d493aba2
AD
480 </form>
481 </td></tr></table>
482 </body></html>
483 <?php
8361e724 484
8361e724
AD
485 }
486
487 } else {
488
d493aba2
AD
489 $return = urlencode($_SERVER["REQUEST_URI"])
490 ?>
491
492 <form action="public.php?return=<?php echo $return ?>"
22439dad 493 method="POST" id="loginForm" name="loginForm">
d493aba2
AD
494
495 <input type="hidden" name="op" value="login">
496
497 <table height='100%' width='100%'><tr><td colspan='2'>
22439dad 498 <h1><?php echo __("Not logged in") ?></h1></td></tr>
d493aba2
AD
499
500 <tr><td align="right"><?php echo __("Login:") ?></td>
501 <td align="right"><input name="login"
502 value="<?php echo $_SESSION["fake_login"] ?>"></td></tr>
503 <tr><td align="right"><?php echo __("Password:") ?></td>
504 <td align="right"><input type="password" name="password"
505 value="<?php echo $_SESSION["fake_password"] ?>"></td></tr>
d493aba2
AD
506 <tr><td colspan='2'>
507 <button type="submit">
508 <?php echo __('Log in') ?></button>
509
510 <button onclick="return window.close()">
511 <?php echo __('Cancel') ?></button>
512 </td></tr>
513 </table>
514
515 </form>
516 <?php
8361e724
AD
517 }
518 }
519
97acbaf1 520 function login() {
97acbaf1
AD
521 if (!SINGLE_USER_MODE) {
522
d9c85e0f 523 $login = $this->dbh->escape_string($_POST["login"]);
97acbaf1 524 $password = $_POST["password"];
aadd636a 525 $remember_me = $_POST["remember_me"];
97acbaf1 526
f231f438
AD
527 if ($remember_me) {
528 session_set_cookie_params(SESSION_COOKIE_LIFETIME);
529 } else {
530 session_set_cookie_params(0);
531 }
532
aadd636a 533 @session_start();
60ed4c9a 534
a42c55f0 535 if (authenticate_user($login, $password)) {
97acbaf1
AD
536 $_POST["password"] = "";
537
b18d109f
AD
538 if (get_schema_version() >= 120) {
539 $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
540 }
541
a42c55f0 542 $_SESSION["ref_schema_version"] = get_schema_version(true);
97acbaf1
AD
543 $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
544
545 if ($_POST["profile"]) {
546
d9c85e0f 547 $profile = $this->dbh->escape_string($_POST["profile"]);
97acbaf1 548
d9c85e0f 549 $result = $this->dbh->query("SELECT id FROM ttrss_settings_profiles
97acbaf1
AD
550 WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]);
551
d9c85e0f 552 if ($this->dbh->num_rows($result) != 0) {
97acbaf1 553 $_SESSION["profile"] = $profile;
97acbaf1
AD
554 }
555 }
556 } else {
557 $_SESSION["login_error_msg"] = __("Incorrect username or password");
558 }
559
560 if ($_REQUEST['return']) {
561 header("Location: " . $_REQUEST['return']);
562 } else {
563 header("Location: " . SELF_URL_PATH);
564 }
565 }
566 }
567
568 function subscribe() {
61a748f8 569 if (SINGLE_USER_MODE) {
6322ac79 570 login_sequence();
61a748f8
AD
571 }
572
97acbaf1
AD
573 if ($_SESSION["uid"]) {
574
d9c85e0f 575 $feed_url = $this->dbh->escape_string(trim($_REQUEST["feed_url"]));
97acbaf1
AD
576
577 header('Content-Type: text/html; charset=utf-8');
578 print "<html>
579 <head>
580 <title>Tiny Tiny RSS</title>
5bbc4bb4 581 <link rel=\"stylesheet\" type=\"text/css\" href=\"css/utility.css\">
97acbaf1
AD
582 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
583 </head>
584 <body>
884d1650 585 <img class=\"floatingLogo\" src=\"images/logo_small.png\"
97acbaf1 586 alt=\"Tiny Tiny RSS\"/>
884d1650 587 <h1>".__("Subscribe to feed...")."</h1><div class='content'>";
97acbaf1 588
a42c55f0 589 $rc = subscribe_to_feed($feed_url);
97acbaf1
AD
590
591 switch ($rc['code']) {
592 case 0:
593 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
594 break;
595 case 1:
596 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
597 break;
598 case 2:
599 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
600 break;
601 case 3:
602 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
603 break;
604 case 4:
605 print_notice(__("Multiple feed URLs found."));
759e5132 606 $feed_urls = $rc["feeds"];
97acbaf1
AD
607 break;
608 case 5:
609 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
610 break;
611 }
612
613 if ($feed_urls) {
614
615 print "<form action=\"public.php\">";
616 print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">";
617
618 print "<select name=\"feed_url\">";
619
620 foreach ($feed_urls as $url => $name) {
621 $url = htmlspecialchars($url);
622 $name = htmlspecialchars($name);
623
624 print "<option value=\"$url\">$name</option>";
625 }
626
627 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
628 "\">";
629
630 print "</form>";
631 }
632
633 $tp_uri = get_self_url_prefix() . "/prefs.php";
634 $tt_uri = get_self_url_prefix();
635
636 if ($rc['code'] <= 2){
d9c85e0f 637 $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
97acbaf1
AD
638 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
639
d9c85e0f 640 $feed_id = $this->dbh->fetch_result($result, 0, "id");
97acbaf1
AD
641 } else {
642 $feed_id = 0;
643 }
644 print "<p>";
645
646 if ($feed_id) {
647 print "<form method=\"GET\" style='display: inline'
648 action=\"$tp_uri\">
649 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
650 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
651 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
652 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
653 </form>";
654 }
655
656 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
657 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
658 </form></p>";
659
884d1650 660 print "</div></body></html>";
97acbaf1
AD
661
662 } else {
6322ac79 663 render_login_form();
97acbaf1
AD
664 }
665 }
666
667 function subscribe2() {
d9c85e0f
AD
668 $feed_url = $this->dbh->escape_string(trim($_REQUEST["feed_url"]));
669 $cat_id = $this->dbh->escape_string($_REQUEST["cat_id"]);
670 $from = $this->dbh->escape_string($_REQUEST["from"]);
6f7798b6 671 $feed_urls = array();
97acbaf1
AD
672
673 /* only read authentication information from POST */
674
d9c85e0f
AD
675 $auth_login = $this->dbh->escape_string(trim($_POST["auth_login"]));
676 $auth_pass = $this->dbh->escape_string(trim($_POST["auth_pass"]));
97acbaf1 677
a42c55f0 678 $rc = subscribe_to_feed($feed_url, $cat_id, $auth_login, $auth_pass);
97acbaf1
AD
679
680 switch ($rc) {
681 case 1:
682 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
683 break;
684 case 2:
685 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
686 break;
687 case 3:
688 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
689 break;
690 case 0:
691 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
692 break;
693 case 4:
694 print_notice(__("Multiple feed URLs found."));
6f7798b6
RL
695 $contents = @fetch_file_contents($url, false, $auth_login, $auth_pass);
696 if (is_html($contents)) {
697 $feed_urls = get_feeds_from_html($url, $contents);
698 }
97acbaf1
AD
699 break;
700 case 5:
701 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
702 break;
703 }
704
705 if ($feed_urls) {
706 print "<form action=\"backend.php\">";
707 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
708 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
709 print "<input type=\"hidden\" name=\"method\" value=\"add\">";
710
711 print "<select name=\"feed_url\">";
712
713 foreach ($feed_urls as $url => $name) {
714 $url = htmlspecialchars($url);
715 $name = htmlspecialchars($name);
716 print "<option value=\"$url\">$name</option>";
717 }
718
719 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed")."\">";
720 print "</form>";
721 }
722
723 $tp_uri = get_self_url_prefix() . "/prefs.php";
724 $tt_uri = get_self_url_prefix();
725
726 if ($rc <= 2){
d9c85e0f 727 $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
97acbaf1
AD
728 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
729
d9c85e0f 730 $feed_id = $this->dbh->fetch_result($result, 0, "id");
97acbaf1
AD
731 } else {
732 $feed_id = 0;
733 }
734
735 print "<p>";
736
737 if ($feed_id) {
738 print "<form method=\"GET\" style='display: inline'
739 action=\"$tp_uri\">
740 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
741 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
742 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
743 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
744 </form>";
745 }
746
747 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
748 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
749 </form></p>";
750
751 print "</body></html>";
752 }
753
754 function index() {
755 header("Content-Type: text/plain");
756 print json_encode(array("error" => array("code" => 7)));
757 }
758
f43e9e97 759 function forgotpass() {
67e0cf9a
AD
760 startup_gettext();
761
f43e9e97 762 header('Content-Type: text/html; charset=utf-8');
e216d302
AD
763 print "<html><head><title>Tiny Tiny RSS</title>";
764
5bbc4bb4 765 stylesheet_tag("css/utility.css");
6f7798b6 766 javascript_tag("lib/prototype.js");
e216d302
AD
767
768 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
769 </head><body id='forgotpass'>";
f43e9e97 770
884d1650 771 print '<div class="floatingLogo"><img src="images/logo_small.png"></div>';
483f15d5 772 print "<h1>".__("Password recovery")."</h1>";
884d1650 773 print "<div class='content'>";
f43e9e97
AD
774
775 @$method = $_POST['method'];
776
777 if (!$method) {
483f15d5
AD
778 print_notice(__("You will need to provide valid account name and email. New password will be sent on your email address."));
779
f43e9e97 780 print "<form method='POST' action='public.php'>";
f43e9e97
AD
781 print "<input type='hidden' name='method' value='do'>";
782 print "<input type='hidden' name='op' value='forgotpass'>";
783
784 print "<fieldset>";
785 print "<label>".__("Login:")."</label>";
786 print "<input type='text' name='login' value='' required>";
787 print "</fieldset>";
788
789 print "<fieldset>";
790 print "<label>".__("Email:")."</label>";
791 print "<input type='email' name='email' value='' required>";
792 print "</fieldset>";
793
794 print "<fieldset>";
795 print "<label>".__("How much is two plus two:")."</label>";
796 print "<input type='text' name='test' value='' required>";
797 print "</fieldset>";
798
799 print "<p/>";
800 print "<button type='submit'>".__("Reset password")."</button>";
801
802 print "</form>";
803 } else if ($method == 'do') {
804
d9c85e0f
AD
805 $login = $this->dbh->escape_string($_POST["login"]);
806 $email = $this->dbh->escape_string($_POST["email"]);
807 $test = $this->dbh->escape_string($_POST["test"]);
f43e9e97
AD
808
809 if (($test != 4 && $test != 'four') || !$email || !$login) {
810 print_error(__('Some of the required form parameters are missing or incorrect.'));
811
483f15d5
AD
812 print "<form method=\"GET\" action=\"public.php\">
813 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
814 <input type=\"submit\" value=\"".__("Go back")."\">
815 </form>";
f43e9e97 816
e216d302 817 } else {
f43e9e97 818
d9c85e0f 819 $result = $this->dbh->query("SELECT id FROM ttrss_users
f43e9e97
AD
820 WHERE login = '$login' AND email = '$email'");
821
d9c85e0f
AD
822 if ($this->dbh->num_rows($result) != 0) {
823 $id = $this->dbh->fetch_result($result, 0, "id");
f43e9e97 824
a42c55f0 825 Pref_Users::resetUserPassword($id, false);
f43e9e97 826
483f15d5
AD
827 print "<p>";
828
e216d302 829 print "<p>"."Completed."."</p>";
483f15d5
AD
830
831 print "<form method=\"GET\" action=\"index.php\">
832 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
833 </form>";
f43e9e97
AD
834
835 } else {
836 print_error(__("Sorry, login and email combination not found."));
483f15d5
AD
837
838 print "<form method=\"GET\" action=\"public.php\">
839 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
840 <input type=\"submit\" value=\"".__("Go back")."\">
841 </form>";
842
f43e9e97 843 }
f43e9e97
AD
844 }
845
846 }
847
884d1650 848 print "</div>";
f43e9e97
AD
849 print "</body>";
850 print "</html>";
851
b4c47f7e
AD
852 }
853
854 function dbupdate() {
67e0cf9a
AD
855 startup_gettext();
856
f240d26e
AD
857 if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) {
858 $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
6322ac79 859 render_login_form();
f240d26e
AD
860 exit;
861 }
862
863 ?><html>
864 <head>
865 <title>Database Updater</title>
866 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5bbc4bb4 867 <link rel="stylesheet" type="text/css" href="css/utility.css"/>
f240d26e
AD
868 </head>
869 <style type="text/css">
870 span.ok { color : #009000; font-weight : bold; }
871 span.err { color : #ff0000; font-weight : bold; }
872 </style>
873 <body>
874 <script type='text/javascript'>
875 function confirmOP() {
876 return confirm("Update the database?");
877 }
878 </script>
879
880 <div class="floatingLogo"><img src="images/logo_small.png"></div>
881
882 <h1><?php echo __("Database Updater") ?></h1>
883
884 <div class="content">
885
886 <?php
887 @$op = $_REQUEST["subop"];
0630a100 888 $updater = new DbUpdater(Db::get(), DB_TYPE, SCHEMA_VERSION);
f240d26e
AD
889
890 if ($op == "performupdate") {
891 if ($updater->isUpdateRequired()) {
892
893 print "<h2>Performing updates</h2>";
894
895 print "<h3>Updating to schema version " . SCHEMA_VERSION . "</h3>";
896
897 print "<ul>";
898
899 for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) {
900 print "<li>Performing update up to version $i...";
901
902 $result = $updater->performUpdateTo($i);
903
904 if (!$result) {
905 print "<span class='err'>FAILED!</span></li></ul>";
906
907 print_warning("One of the updates failed. Either retry the process or perform updates manually.");
908 print "<p><form method=\"GET\" action=\"index.php\">
909 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
910 </form>";
911
912 break;
913 } else {
914 print "<span class='ok'>OK!</span></li>";
915 }
916 }
917
918 print "</ul>";
b4c47f7e 919
f240d26e 920 print_notice("Your Tiny Tiny RSS database is now updated to the latest version.");
b4c47f7e 921
f240d26e
AD
922 print "<p><form method=\"GET\" action=\"index.php\">
923 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
924 </form>";
925
926 } else {
927 print "<h2>Your database is up to date.</h2>";
928
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 if ($updater->isUpdateRequired()) {
935
936 print "<h2>Database update required</h2>";
b4c47f7e 937
f240d26e
AD
938 print "<h3>";
939 printf("Your Tiny Tiny RSS database needs update to the latest version: %d to %d.",
940 $updater->getSchemaVersion(), SCHEMA_VERSION);
941 print "</h3>";
b4c47f7e 942
f240d26e 943 print_warning("Please backup your database before proceeding.");
b4c47f7e 944
f240d26e
AD
945 print "<form method='POST'>
946 <input type='hidden' name='subop' value='performupdate'>
947 <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
948 </form>";
949
950 } else {
951
3c200461 952 print_notice("Tiny Tiny RSS database is up to date.");
f240d26e
AD
953
954 print "<p><form method=\"GET\" action=\"index.php\">
955 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
956 </form>";
957
958 }
959 }
960 ?>
b4c47f7e 961
f240d26e
AD
962 </div>
963 </body>
964 </html>
965 <?php
f43e9e97
AD
966 }
967
5f0a3741
AD
968}
969?>