]>
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,
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";
24 $date_sort_field = "last_read";
26 $qfh_ret = queryFeedHeadlines($this->link
, $feed,
27 $limit, $view_mode, $is_cat, $search, $search_mode,
28 "$date_sort_field DESC", $offset, $owner_uid,
29 false, 0, false, true);
31 $result = $qfh_ret[0];
32 $feed_title = htmlspecialchars($qfh_ret[1]);
33 $feed_site_url = $qfh_ret[2];
34 $last_error = $qfh_ret[3];
36 $feed_self_url = get_self_url_prefix() .
37 "/public.php?op=rss&id=-2&key=" .
38 get_feed_access_key($this->link
, -2, false, $owner_uid);
40 if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
42 if ($format == 'atom') {
43 $tpl = new MiniTemplator
;
45 $tpl->readTemplateFromFile("templates/generated_feed.txt");
47 $tpl->setVariable('FEED_TITLE', $feed_title, true);
48 $tpl->setVariable('VERSION', VERSION
, true);
49 $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
51 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
52 $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB
), true);
53 $tpl->addBlock('feed_hub');
56 $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
58 while ($line = db_fetch_assoc($result)) {
59 $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']), true);
60 $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
61 $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
62 $tpl->setVariable('ARTICLE_EXCERPT',
63 truncate_string(strip_tags($line["content_preview"]), 100, '...'), true);
65 $content = sanitize($this->link
, $line["content_preview"], false, $owner_uid);
68 $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
72 $tpl->setVariable('ARTICLE_CONTENT', $content, true);
74 $tpl->setVariable('ARTICLE_UPDATED_ATOM',
75 date('c', strtotime($line["updated"])), true);
76 $tpl->setVariable('ARTICLE_UPDATED_RFC822',
77 date(DATE_RFC822
, strtotime($line["updated"])), true);
79 $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
81 $tags = get_article_tags($this->link
, $line["id"], $owner_uid);
83 foreach ($tags as $tag) {
84 $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
85 $tpl->addBlock('category');
88 $enclosures = get_article_enclosures($this->link
, $line["id"]);
90 foreach ($enclosures as $e) {
91 $type = htmlspecialchars($e['content_type']);
92 $url = htmlspecialchars($e['content_url']);
93 $length = $e['duration'];
95 $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
96 $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
97 $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
99 $tpl->addBlock('enclosure');
102 $tpl->addBlock('entry');
107 $tpl->addBlock('feed');
108 $tpl->generateOutputToString($tmp);
110 if (@!$_REQUEST["noxml"]) {
111 header("Content-Type: text/xml; charset=utf-8");
113 header("Content-Type: text/plain; charset=utf-8");
117 } else if ($format == 'json') {
121 $feed['title'] = $feed_title;
122 $feed['version'] = VERSION
;
123 $feed['feed_url'] = $feed_self_url;
125 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
126 $feed['hub_url'] = PUBSUBHUBBUB_HUB
;
129 $feed['self_url'] = get_self_url_prefix();
131 $feed['articles'] = array();
133 while ($line = db_fetch_assoc($result)) {
136 $article['id'] = $line['link'];
137 $article['link'] = $line['link'];
138 $article['title'] = $line['title'];
139 $article['excerpt'] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
140 $article['content'] = sanitize($this->link
, $line["content_preview"], false, $owner_uid);
141 $article['updated'] = date('c', strtotime($line["updated"]));
143 if ($line['note']) $article['note'] = $line['note'];
144 if ($article['author']) $article['author'] = $line['author'];
146 $tags = get_article_tags($this->link
, $line["id"], $owner_uid);
148 if (count($tags) > 0) {
149 $article['tags'] = array();
151 foreach ($tags as $tag) {
152 array_push($article['tags'], $tag);
156 $enclosures = get_article_enclosures($this->link
, $line["id"]);
158 if (count($enclosures) > 0) {
159 $article['enclosures'] = array();
161 foreach ($enclosures as $e) {
162 $type = $e['content_type'];
163 $url = $e['content_url'];
164 $length = $e['duration'];
166 array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
170 array_push($feed['articles'], $article);
173 header("Content-Type: text/json; charset=utf-8");
174 print json_encode($feed);
177 header("Content-Type: text/plain; charset=utf-8");
178 print json_encode(array("error" => array("message" => "Unknown format")));
182 function getUnread() {
183 $login = db_escape_string($_REQUEST["login"]);
184 $fresh = $_REQUEST["fresh"] == "1";
186 $result = db_query($this->link
, "SELECT id FROM ttrss_users WHERE login = '$login'");
188 if (db_num_rows($result) == 1) {
189 $uid = db_fetch_result($result, 0, "id");
191 print getGlobalUnread($this->link
, $uid);
195 print getFeedArticles($this->link
, -3, false, true, $uid);
199 print "-1;User not found";
204 function getProfiles() {
205 $login = db_escape_string($_REQUEST["login"]);
207 $result = db_query($this->link
, "SELECT * FROM ttrss_settings_profiles,ttrss_users
208 WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = '$login' ORDER BY title");
210 print "<select dojoType='dijit.form.Select' style='width : 220px; margin : 0px' name='profile'>";
212 print "<option value='0'>" . __("Default profile") . "</option>";
214 while ($line = db_fetch_assoc($result)) {
216 $title = $line["title"];
218 print "<option value='$id'>$title</option>";
225 $mode = db_escape_string($_REQUEST['hub_mode']);
226 $feed_id = (int) db_escape_string($_REQUEST['id']);
227 $feed_url = db_escape_string($_REQUEST['hub_topic']);
229 if (!PUBSUBHUBBUB_ENABLED
) {
230 header('HTTP/1.0 404 Not Found');
231 echo "404 Not found";
235 // TODO: implement hub_verifytoken checking
237 $result = db_query($this->link
, "SELECT feed_url FROM ttrss_feeds
238 WHERE id = '$feed_id'");
240 if (db_num_rows($result) != 0) {
242 $check_feed_url = db_fetch_result($result, 0, "feed_url");
244 if ($check_feed_url && ($check_feed_url == $feed_url ||
!$feed_url)) {
245 if ($mode == "subscribe") {
247 db_query($this->link
, "UPDATE ttrss_feeds SET pubsub_state = 2
248 WHERE id = '$feed_id'");
250 print $_REQUEST['hub_challenge'];
253 } else if ($mode == "unsubscribe") {
255 db_query($this->link
, "UPDATE ttrss_feeds SET pubsub_state = 0
256 WHERE id = '$feed_id'");
258 print $_REQUEST['hub_challenge'];
263 // Received update ping, schedule feed update.
264 //update_rss_feed($this->link, $feed_id, true, true);
266 db_query($this->link
, "UPDATE ttrss_feeds SET
267 last_update_started = '1970-01-01',
268 last_updated = '1970-01-01' WHERE id = '$feed_id'");
272 header('HTTP/1.0 404 Not Found');
273 echo "404 Not found";
276 header('HTTP/1.0 404 Not Found');
277 echo "404 Not found";
284 header("Location: index.php");
288 $uuid = db_escape_string($_REQUEST["key"]);
290 $result = db_query($this->link
, "SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
293 if (db_num_rows($result) != 0) {
294 header("Content-Type: text/html");
296 $id = db_fetch_result($result, 0, "ref_id");
297 $owner_uid = db_fetch_result($result, 0, "owner_uid");
299 $article = format_article($this->link
, $id, false, true, $owner_uid);
301 print_r($article['content']);
304 print "Article not found.";
310 $feed = db_escape_string($_REQUEST["id"]);
311 $key = db_escape_string($_REQUEST["key"]);
312 $is_cat = $_REQUEST["is_cat"] != false;
313 $limit = (int)db_escape_string($_REQUEST["limit"]);
314 $offset = (int)db_escape_string($_REQUEST["offset"]);
316 $search = db_escape_string($_REQUEST["q"]);
317 $search_mode = db_escape_string($_REQUEST["smode"]);
318 $view_mode = db_escape_string($_REQUEST["view-mode"]);
320 $format = db_escape_string($_REQUEST['format']);
322 if (!$format) $format = 'atom';
324 if (SINGLE_USER_MODE
) {
325 authenticate_user($this->link
, "admin", null);
331 $result = db_query($this->link
, "SELECT owner_uid FROM
332 ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
334 if (db_num_rows($result) == 1)
335 $owner_id = db_fetch_result($result, 0, "owner_uid");
339 $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
340 $offset, $search, $search_mode, $view_mode, $format);
342 header('HTTP/1.1 403 Forbidden');
346 function globalUpdateFeeds() {
347 include "rssfuncs.php";
348 // Update all feeds needing a update.
349 update_daemon_common($this->link
, 0, true, false);
352 function sharepopup() {
353 if (SINGLE_USER_MODE
) {
354 login_sequence($this->link
);
357 header('Content-Type: text/html; charset=utf-8');
360 <title>Tiny Tiny RSS</title>
361 <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
362 <script type=\"text/javascript\" src=\"lib/prototype.js\"></script>
363 <script type=\"text/javascript\" src=\"lib/scriptaculous/scriptaculous.js?load=effects,dragdrop,controls\"></script>
364 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
366 <body id='sharepopup'>";
368 $action = $_REQUEST["action"];
370 if ($_SESSION["uid"]) {
372 if ($action == 'share') {
374 $title = db_escape_string(strip_tags($_REQUEST["title"]));
375 $url = db_escape_string(strip_tags($_REQUEST["url"]));
376 $content = db_escape_string(strip_tags($_REQUEST["content"]));
377 $labels = db_escape_string(strip_tags($_REQUEST["labels"]));
379 Article
::create_published_article($this->link
, $title, $url, $content, $labels,
382 print "<script type='text/javascript'>";
383 print "window.close();";
387 $title = htmlspecialchars($_REQUEST["title"]);
388 $url = htmlspecialchars($_REQUEST["url"]);
392 <table height
='100%' width
='100%'><tr
><td colspan
='2'>
393 <h1
><?php
echo __("Share with Tiny Tiny RSS") ?
></h1
>
396 <form id
='share_form' name
='share_form'>
398 <input type
="hidden" name
="op" value
="sharepopup">
399 <input type
="hidden" name
="action" value
="share">
401 <tr
><td align
='right'><?php
echo __("Title:") ?
></td
>
402 <td width
='80%'><input name
='title' value
="<?php echo $title ?>"></td
></tr
>
403 <tr
><td align
='right'><?php
echo __("URL:") ?
></td
>
404 <td
><input name
='url' value
="<?php echo $url ?>"></td
></tr
>
405 <tr
><td align
='right'><?php
echo __("Content:") ?
></td
>
406 <td
><input name
='content' value
=""></td
></tr
>
407 <tr
><td align
='right'><?php
echo __("Labels:") ?
></td
>
408 <td
><input name
='labels' id
="labels_value"
409 placeholder
='Alpha, Beta, Gamma' value
="">
413 <div
class="autocomplete" id
="labels_choices"
414 style
="display : block"></div
></td
></tr
>
416 <script type
='text/javascript'>document
.forms
[0].title
.focus();</script
>
418 <script type
='text/javascript'>
419 new Ajax
.Autocompleter('labels_value', 'labels_choices',
420 "backend.php?op=rpc&method=completeLabels",
421 { tokens
: ',', paramName
: "search" });
425 <div style
='float : right' class='insensitive-small'>
426 <?php
echo __("Shared article will appear in the Published feed.") ?
>
428 <button type
="submit"><?php
echo __('Share') ?
></button
>
429 <button onclick
="return window.close()"><?php
echo __('Cancel') ?
></button
>
441 $return = urlencode($_SERVER["REQUEST_URI"])
444 <form action
="public.php?return=<?php echo $return ?>"
445 method
="POST" id
="loginForm" name
="loginForm">
447 <input type
="hidden" name
="op" value
="login">
449 <table height
='100%' width
='100%'><tr
><td colspan
='2'>
450 <h1
><?php
echo __("Not logged in") ?
></h1
></td
></tr
>
452 <tr
><td align
="right"><?php
echo __("Login:") ?
></td
>
453 <td align
="right"><input name
="login"
454 value
="<?php echo $_SESSION["fake_login
"] ?>"></td
></tr
>
455 <tr
><td align
="right"><?php
echo __("Password:") ?
></td
>
456 <td align
="right"><input type
="password" name
="password"
457 value
="<?php echo $_SESSION["fake_password
"] ?>"></td
></tr
>
458 <tr
><td align
="right"><?php
echo __("Language:") ?
></td
>
461 print_select_hash("language", $_COOKIE["ttrss_lang"], get_translations(),
462 "style='width : 100%''");
467 <button type
="submit">
468 <?php
echo __('Log in') ?
></button
>
470 <button onclick
="return window.close()">
471 <?php
echo __('Cancel') ?
></button
>
482 $_SESSION["prefs_cache"] = array();
484 if (!SINGLE_USER_MODE
) {
486 $login = db_escape_string($_POST["login"]);
487 $password = $_POST["password"];
488 $remember_me = $_POST["remember_me"];
490 if (authenticate_user($this->link
, $login, $password)) {
491 $_POST["password"] = "";
493 $_SESSION["language"] = $_POST["language"];
494 $_SESSION["ref_schema_version"] = get_schema_version($this->link
, true);
495 $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
497 if ($_POST["profile"]) {
499 $profile = db_escape_string($_POST["profile"]);
501 $result = db_query($this->link
, "SELECT id FROM ttrss_settings_profiles
502 WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]);
504 if (db_num_rows($result) != 0) {
505 $_SESSION["profile"] = $profile;
506 $_SESSION["prefs_cache"] = array();
510 $_SESSION["login_error_msg"] = __("Incorrect username or password");
513 if ($_REQUEST['return']) {
514 header("Location: " . $_REQUEST['return']);
516 header("Location: " . SELF_URL_PATH
);
521 function subscribe() {
522 if (SINGLE_USER_MODE
) {
523 login_sequence($this->link
);
526 if ($_SESSION["uid"]) {
528 $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
530 header('Content-Type: text/html; charset=utf-8');
533 <title>Tiny Tiny RSS</title>
534 <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
535 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
538 <img class=\"floatingLogo\" src=\"images/logo_wide.png\"
539 alt=\"Tiny Tiny RSS\"/>
540 <h1>".__("Subscribe to feed...")."</h1>";
542 $rc = subscribe_to_feed($this->link
, $feed_url);
544 switch ($rc['code']) {
546 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
549 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
552 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
555 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
558 print_notice(__("Multiple feed URLs found."));
559 $feed_urls = $rc["feeds"];
562 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
568 print "<form action=\"public.php\">";
569 print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">";
571 print "<select name=\"feed_url\">";
573 foreach ($feed_urls as $url => $name) {
574 $url = htmlspecialchars($url);
575 $name = htmlspecialchars($name);
577 print "<option value=\"$url\">$name</option>";
580 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
586 $tp_uri = get_self_url_prefix() . "/prefs.php";
587 $tt_uri = get_self_url_prefix();
589 if ($rc['code'] <= 2){
590 $result = db_query($this->link
, "SELECT id FROM ttrss_feeds WHERE
591 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
593 $feed_id = db_fetch_result($result, 0, "id");
600 print "<form method=\"GET\" style='display: inline'
602 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
603 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
604 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
605 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
609 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
610 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
613 print "</body></html>";
616 render_login_form($this->link
);
620 function subscribe2() {
621 $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
622 $cat_id = db_escape_string($_REQUEST["cat_id"]);
623 $from = db_escape_string($_REQUEST["from"]);
625 /* only read authentication information from POST */
627 $auth_login = db_escape_string(trim($_POST["auth_login"]));
628 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
630 $rc = subscribe_to_feed($this->link
, $feed_url, $cat_id, $auth_login, $auth_pass);
634 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
637 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
640 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
643 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
646 print_notice(__("Multiple feed URLs found."));
648 $feed_urls = get_feeds_from_html($feed_url);
651 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
656 print "<form action=\"backend.php\">";
657 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
658 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
659 print "<input type=\"hidden\" name=\"method\" value=\"add\">";
661 print "<select name=\"feed_url\">";
663 foreach ($feed_urls as $url => $name) {
664 $url = htmlspecialchars($url);
665 $name = htmlspecialchars($name);
666 print "<option value=\"$url\">$name</option>";
669 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed")."\">";
673 $tp_uri = get_self_url_prefix() . "/prefs.php";
674 $tt_uri = get_self_url_prefix();
677 $result = db_query($this->link
, "SELECT id FROM ttrss_feeds WHERE
678 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
680 $feed_id = db_fetch_result($result, 0, "id");
688 print "<form method=\"GET\" style='display: inline'
690 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
691 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
692 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
693 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
697 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
698 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
701 print "</body></html>";
705 header("Content-Type: text/plain");
706 print json_encode(array("error" => array("code" => 7)));