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