]>
git.wh0rd.org - tt-rss.git/blob - classes/handler/public.php
2 class Handler_Public
extends Handler
{
4 private function generate_syndicated_feed($owner_uid, $feed, $is_cat,
5 $limit, $offset, $search, $search_mode, $match_on,
6 $view_mode = false, $format = 'atom') {
8 require_once "lib/MiniTemplator.class.php";
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;";
15 if (!$limit) $limit = 100;
17 if (get_pref($this->link
, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
18 $date_sort_field = "updated";
20 $date_sort_field = "date_entered";
23 $qfh_ret = queryFeedHeadlines($this->link
, $feed,
24 $limit, $view_mode, $is_cat, $search, $search_mode,
25 $match_on, "$date_sort_field DESC", $offset, $owner_uid);
27 $result = $qfh_ret[0];
28 $feed_title = htmlspecialchars($qfh_ret[1]);
29 $feed_site_url = $qfh_ret[2];
30 $last_error = $qfh_ret[3];
32 $feed_self_url = get_self_url_prefix() .
33 "/public.php?op=rss&id=-2&key=" .
34 get_feed_access_key($this->link
, -2, false, $owner_uid);
36 if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
38 if ($format == 'atom') {
39 $tpl = new MiniTemplator
;
41 $tpl->readTemplateFromFile("templates/generated_feed.txt");
43 $tpl->setVariable('FEED_TITLE', $feed_title, true);
44 $tpl->setVariable('VERSION', VERSION
, true);
45 $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
47 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
48 $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB
), true);
49 $tpl->addBlock('feed_hub');
52 $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
54 while ($line = db_fetch_assoc($result)) {
55 $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']), true);
56 $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
57 $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
58 $tpl->setVariable('ARTICLE_EXCERPT',
59 truncate_string(strip_tags($line["content_preview"]), 100, '...'), true);
61 $content = sanitize($this->link
, $line["content_preview"], false, $owner_uid);
64 $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
68 $tpl->setVariable('ARTICLE_CONTENT', $content, true);
70 $tpl->setVariable('ARTICLE_UPDATED_ATOM',
71 date('c', strtotime($line["updated"])), true);
72 $tpl->setVariable('ARTICLE_UPDATED_RFC822',
73 date(DATE_RFC822
, strtotime($line["updated"])), true);
75 $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
77 $tags = get_article_tags($this->link
, $line["id"], $owner_uid);
79 foreach ($tags as $tag) {
80 $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
81 $tpl->addBlock('category');
84 $enclosures = get_article_enclosures($this->link
, $line["id"]);
86 foreach ($enclosures as $e) {
87 $type = htmlspecialchars($e['content_type']);
88 $url = htmlspecialchars($e['content_url']);
89 $length = $e['duration'];
91 $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
92 $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
93 $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
95 $tpl->addBlock('enclosure');
98 $tpl->addBlock('entry');
103 $tpl->addBlock('feed');
104 $tpl->generateOutputToString($tmp);
106 header("Content-Type: text/xml; charset=utf-8");
109 } else if ($format == 'json') {
113 $feed['title'] = $feed_title;
114 $feed['version'] = VERSION
;
115 $feed['feed_url'] = $feed_self_url;
117 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
118 $feed['hub_url'] = PUBSUBHUBBUB_HUB
;
121 $feed['self_url'] = get_self_url_prefix();
123 $feed['articles'] = array();
125 while ($line = db_fetch_assoc($result)) {
128 $article['id'] = $line['link'];
129 $article['link'] = $line['link'];
130 $article['title'] = $line['title'];
131 $article['excerpt'] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
132 $article['content'] = sanitize($this->link
, $line["content_preview"], false, $owner_uid);
133 $article['updated'] = date('c', strtotime($line["updated"]));
135 if ($line['note']) $article['note'] = $line['note'];
136 if ($article['author']) $article['author'] = $line['author'];
138 $tags = get_article_tags($this->link
, $line["id"], $owner_uid);
140 if (count($tags) > 0) {
141 $article['tags'] = array();
143 foreach ($tags as $tag) {
144 array_push($article['tags'], $tag);
148 $enclosures = get_article_enclosures($this->link
, $line["id"]);
150 if (count($enclosures) > 0) {
151 $article['enclosures'] = array();
153 foreach ($enclosures as $e) {
154 $type = $e['content_type'];
155 $url = $e['content_url'];
156 $length = $e['duration'];
158 array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
162 array_push($feed['articles'], $article);
165 header("Content-Type: text/plain; charset=utf-8");
167 print json_encode($feed);
170 header("Content-Type: text/plain; charset=utf-8");
171 print json_encode(array("error" => array("message" => "Unknown format")));
175 function getUnread() {
176 $login = db_escape_string($_REQUEST["login"]);
177 $fresh = $_REQUEST["fresh"] == "1";
179 $result = db_query($this->link
, "SELECT id FROM ttrss_users WHERE login = '$login'");
181 if (db_num_rows($result) == 1) {
182 $uid = db_fetch_result($result, 0, "id");
184 print getGlobalUnread($this->link
, $uid);
188 print getFeedArticles($this->link
, -3, false, true, $uid);
192 print "-1;User not found";
197 function getProfiles() {
198 $login = db_escape_string($_REQUEST["login"]);
200 $result = db_query($this->link
, "SELECT * FROM ttrss_settings_profiles,ttrss_users
201 WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = '$login' ORDER BY title");
203 print "<select dojoType='dijit.form.Select' style='width : 220px; margin : 0px' name='profile'>";
205 print "<option value='0'>" . __("Default profile") . "</option>";
207 while ($line = db_fetch_assoc($result)) {
209 $title = $line["title"];
211 print "<option value='$id'>$title</option>";
218 $mode = db_escape_string($_REQUEST['hub_mode']);
219 $feed_id = (int) db_escape_string($_REQUEST['id']);
220 $feed_url = db_escape_string($_REQUEST['hub_topic']);
222 if (!PUBSUBHUBBUB_ENABLED
) {
223 header('HTTP/1.0 404 Not Found');
224 echo "404 Not found";
228 // TODO: implement hub_verifytoken checking
230 $result = db_query($this->link
, "SELECT feed_url FROM ttrss_feeds
231 WHERE id = '$feed_id'");
233 if (db_num_rows($result) != 0) {
235 $check_feed_url = db_fetch_result($result, 0, "feed_url");
237 if ($check_feed_url && ($check_feed_url == $feed_url ||
!$feed_url)) {
238 if ($mode == "subscribe") {
240 db_query($this->link
, "UPDATE ttrss_feeds SET pubsub_state = 2
241 WHERE id = '$feed_id'");
243 print $_REQUEST['hub_challenge'];
246 } else if ($mode == "unsubscribe") {
248 db_query($this->link
, "UPDATE ttrss_feeds SET pubsub_state = 0
249 WHERE id = '$feed_id'");
251 print $_REQUEST['hub_challenge'];
256 // Received update ping, schedule feed update.
257 //update_rss_feed($this->link, $feed_id, true, true);
259 db_query($this->link
, "UPDATE ttrss_feeds SET
260 last_update_started = '1970-01-01',
261 last_updated = '1970-01-01' WHERE id = '$feed_id'");
265 header('HTTP/1.0 404 Not Found');
266 echo "404 Not found";
269 header('HTTP/1.0 404 Not Found');
270 echo "404 Not found";
277 header("Location: index.php");
280 function fbexport() {
282 $access_key = db_escape_string($_POST["key"]);
284 // TODO: rate limit checking using last_connected
285 $result = db_query($this->link
, "SELECT id FROM ttrss_linked_instances
286 WHERE access_key = '$access_key'");
288 if (db_num_rows($result) == 1) {
290 $instance_id = db_fetch_result($result, 0, "id");
292 $result = db_query($this->link
, "SELECT feed_url, site_url, title, subscribers
293 FROM ttrss_feedbrowser_cache ORDER BY subscribers DESC LIMIT 100");
297 while ($line = db_fetch_assoc($result)) {
298 array_push($feeds, $line);
301 db_query($this->link
, "UPDATE ttrss_linked_instances SET
302 last_status_in = 1 WHERE id = '$instance_id'");
304 print json_encode(array("feeds" => $feeds));
306 print json_encode(array("error" => array("code" => 6)));
311 $uuid = db_escape_string($_REQUEST["key"]);
313 $result = db_query($this->link
, "SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
316 if (db_num_rows($result) != 0) {
317 header("Content-Type: text/html");
319 $id = db_fetch_result($result, 0, "ref_id");
320 $owner_uid = db_fetch_result($result, 0, "owner_uid");
322 $article = format_article($this->link
, $id, false, true, $owner_uid);
324 print_r($article['content']);
327 print "Article not found.";
333 $feed = db_escape_string($_REQUEST["id"]);
334 $key = db_escape_string($_REQUEST["key"]);
335 $is_cat = $_REQUEST["is_cat"] != false;
336 $limit = (int)db_escape_string($_REQUEST["limit"]);
337 $offset = (int)db_escape_string($_REQUEST["offset"]);
339 $search = db_escape_string($_REQUEST["q"]);
340 $match_on = db_escape_string($_REQUEST["m"]);
341 $search_mode = db_escape_string($_REQUEST["smode"]);
342 $view_mode = db_escape_string($_REQUEST["view-mode"]);
344 $format = db_escape_string($_REQUEST['format']);
346 if (!$format) $format = 'atom';
348 if (SINGLE_USER_MODE
) {
349 authenticate_user($this->link
, "admin", null);
355 $result = db_query($this->link
, "SELECT owner_uid FROM
356 ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
358 if (db_num_rows($result) == 1)
359 $owner_id = db_fetch_result($result, 0, "owner_uid");
363 $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
364 $offset, $search, $search_mode, $match_on, $view_mode, $format);
366 header('HTTP/1.1 403 Forbidden');
370 function globalUpdateFeeds() {
371 include "rssfuncs.php";
372 // Update all feeds needing a update.
373 update_daemon_common($this->link
, 0, true, false);
376 function sharepopup() {
377 header('Content-Type: text/html; charset=utf-8');
380 <title>Tiny Tiny RSS</title>
381 <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
382 <script type=\"text/javascript\" src=\"lib/prototype.js\"></script>
383 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
385 <body id='sharepopup'>";
387 $action = $_REQUEST["action"];
389 if ($_SESSION["uid"]) {
391 if ($action == 'share') {
393 $title = db_escape_string(strip_tags($_REQUEST["title"]));
394 $url = db_escape_string(strip_tags($_REQUEST["url"]));
395 $content = db_escape_string(strip_tags($_REQUEST["content"]));
397 create_published_article($this->link
, $title, $url, $content, $_SESSION["uid"]);
399 print "<script type='text/javascript'>";
400 print "window.close();";
404 $title = htmlspecialchars($_REQUEST["title"]);
405 $url = htmlspecialchars($_REQUEST["url"]);
409 <table height
='100%' width
='100%'><tr
><td colspan
='2'>
410 <h1
><?php
echo __("Share with Tiny Tiny RSS") ?
></h1
>
413 <form id
='share_form' name
='share_form'>
415 <input type
="hidden" name
="op" value
="sharepopup">
416 <input type
="hidden" name
="action" value
="share">
418 <tr
><td align
='right'><?php
echo __("Title:") ?
></td
>
419 <td width
='80%'><input name
='title' value
="<?php echo $title ?>"></td
></tr
>
420 <tr
><td align
='right'><?php
echo __("URL:") ?
></td
>
421 <td
><input name
='url' value
="<?php echo $url ?>"></td
></tr
>
422 <tr
><td align
='right'><?php
echo __("Content:") ?
></td
>
423 <td
><input name
='content' value
=""></td
></tr
>
425 <script type
='text/javascript'>document
.forms
[0].title
.focus();</script
>
428 <div style
='float : right' class='insensitive-small'>
429 <?php
echo __("Shared article will appear in the Published feed.") ?
>
431 <button type
="submit"><?php
echo __('Share') ?
></button
>
432 <button onclick
="return window.close()"><?php
echo __('Cancel') ?
></button
>
444 $return = urlencode($_SERVER["REQUEST_URI"])
447 <form action
="public.php?return=<?php echo $return ?>"
448 method
="POST" id
="loginForm" name
="loginForm">
450 <input type
="hidden" name
="op" value
="login">
452 <table height
='100%' width
='100%'><tr
><td colspan
='2'>
453 <h1
><?php
echo __("Not logged in") ?
></h1
></td
></tr
>
455 <tr
><td align
="right"><?php
echo __("Login:") ?
></td
>
456 <td align
="right"><input name
="login"
457 value
="<?php echo $_SESSION["fake_login
"] ?>"></td
></tr
>
458 <tr
><td align
="right"><?php
echo __("Password:") ?
></td
>
459 <td align
="right"><input type
="password" name
="password"
460 value
="<?php echo $_SESSION["fake_password
"] ?>"></td
></tr
>
461 <tr
><td align
="right"><?php
echo __("Language:") ?
></td
>
464 print_select_hash("language", $_COOKIE["ttrss_lang"], get_translations(),
465 "style='width : 100%''");
470 <button type
="submit">
471 <?php
echo __('Log in') ?
></button
>
473 <button onclick
="return window.close()">
474 <?php
echo __('Cancel') ?
></button
>
485 $_SESSION["prefs_cache"] = array();
487 if (!SINGLE_USER_MODE
) {
489 $login = db_escape_string($_POST["login"]);
490 $password = $_POST["password"];
491 $remember_me = $_POST["remember_me"];
493 if (authenticate_user($this->link
, $login, $password)) {
494 $_POST["password"] = "";
496 $_SESSION["language"] = $_POST["language"];
497 $_SESSION["ref_schema_version"] = get_schema_version($this->link
, true);
498 $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
500 if ($_POST["profile"]) {
502 $profile = db_escape_string($_POST["profile"]);
504 $result = db_query($this->link
, "SELECT id FROM ttrss_settings_profiles
505 WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]);
507 if (db_num_rows($result) != 0) {
508 $_SESSION["profile"] = $profile;
509 $_SESSION["prefs_cache"] = array();
513 $_SESSION["login_error_msg"] = __("Incorrect username or password");
516 if ($_REQUEST['return']) {
517 header("Location: " . $_REQUEST['return']);
519 header("Location: " . SELF_URL_PATH
);
524 function subscribe() {
525 if ($_SESSION["uid"]) {
527 $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
529 header('Content-Type: text/html; charset=utf-8');
532 <title>Tiny Tiny RSS</title>
533 <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
534 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
537 <img class=\"floatingLogo\" src=\"images/logo_wide.png\"
538 alt=\"Tiny Tiny RSS\"/>
539 <h1>".__("Subscribe to feed...")."</h1>";
541 $rc = subscribe_to_feed($this->link
, $feed_url);
543 switch ($rc['code']) {
545 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
548 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
551 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
554 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
557 print_notice(__("Multiple feed URLs found."));
558 $feed_urls = $rc["feeds"];
561 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
567 print "<form action=\"public.php\">";
568 print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">";
570 print "<select name=\"feed_url\">";
572 foreach ($feed_urls as $url => $name) {
573 $url = htmlspecialchars($url);
574 $name = htmlspecialchars($name);
576 print "<option value=\"$url\">$name</option>";
579 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
585 $tp_uri = get_self_url_prefix() . "/prefs.php";
586 $tt_uri = get_self_url_prefix();
588 if ($rc['code'] <= 2){
589 $result = db_query($this->link
, "SELECT id FROM ttrss_feeds WHERE
590 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
592 $feed_id = db_fetch_result($result, 0, "id");
599 print "<form method=\"GET\" style='display: inline'
601 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
602 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
603 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
604 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
608 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
609 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
612 print "</body></html>";
615 render_login_form($this->link
);
619 function subscribe2() {
620 $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
621 $cat_id = db_escape_string($_REQUEST["cat_id"]);
622 $from = db_escape_string($_REQUEST["from"]);
624 /* only read authentication information from POST */
626 $auth_login = db_escape_string(trim($_POST["auth_login"]));
627 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
629 $rc = subscribe_to_feed($this->link
, $feed_url, $cat_id, $auth_login, $auth_pass);
633 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
636 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
639 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
642 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
645 print_notice(__("Multiple feed URLs found."));
647 $feed_urls = get_feeds_from_html($feed_url);
650 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
655 print "<form action=\"backend.php\">";
656 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
657 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
658 print "<input type=\"hidden\" name=\"method\" value=\"add\">";
660 print "<select name=\"feed_url\">";
662 foreach ($feed_urls as $url => $name) {
663 $url = htmlspecialchars($url);
664 $name = htmlspecialchars($name);
665 print "<option value=\"$url\">$name</option>";
668 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed")."\">";
672 $tp_uri = get_self_url_prefix() . "/prefs.php";
673 $tt_uri = get_self_url_prefix();
676 $result = db_query($this->link
, "SELECT id FROM ttrss_feeds WHERE
677 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
679 $feed_id = db_fetch_result($result, 0, "id");
687 print "<form method=\"GET\" style='display: inline'
689 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
690 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
691 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
692 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
696 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
697 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
700 print "</body></html>";
704 header("Content-Type: text/plain");
705 print json_encode(array("error" => array("code" => 7)));