]>
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";
24 $date_sort_field = "last_read";
26 $qfh_ret = queryFeedHeadlines($this->link
, $feed,
27 $limit, $view_mode, $is_cat, $search, $search_mode,
28 $match_on, "$date_sort_field DESC", $offset, $owner_uid);
30 $result = $qfh_ret[0];
31 $feed_title = htmlspecialchars($qfh_ret[1]);
32 $feed_site_url = $qfh_ret[2];
33 $last_error = $qfh_ret[3];
35 $feed_self_url = get_self_url_prefix() .
36 "/public.php?op=rss&id=-2&key=" .
37 get_feed_access_key($this->link
, -2, false, $owner_uid);
39 if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
41 if ($format == 'atom') {
42 $tpl = new MiniTemplator
;
44 $tpl->readTemplateFromFile("templates/generated_feed.txt");
46 $tpl->setVariable('FEED_TITLE', $feed_title, true);
47 $tpl->setVariable('VERSION', VERSION
, true);
48 $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
50 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
51 $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB
), true);
52 $tpl->addBlock('feed_hub');
55 $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
57 while ($line = db_fetch_assoc($result)) {
58 $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']), true);
59 $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
60 $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
61 $tpl->setVariable('ARTICLE_EXCERPT',
62 truncate_string(strip_tags($line["content_preview"]), 100, '...'), true);
64 $content = sanitize($this->link
, $line["content_preview"], false, $owner_uid);
67 $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
71 $tpl->setVariable('ARTICLE_CONTENT', $content, true);
73 $tpl->setVariable('ARTICLE_UPDATED_ATOM',
74 date('c', strtotime($line["updated"])), true);
75 $tpl->setVariable('ARTICLE_UPDATED_RFC822',
76 date(DATE_RFC822
, strtotime($line["updated"])), true);
78 $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
80 $tags = get_article_tags($this->link
, $line["id"], $owner_uid);
82 foreach ($tags as $tag) {
83 $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
84 $tpl->addBlock('category');
87 $enclosures = get_article_enclosures($this->link
, $line["id"]);
89 foreach ($enclosures as $e) {
90 $type = htmlspecialchars($e['content_type']);
91 $url = htmlspecialchars($e['content_url']);
92 $length = $e['duration'];
94 $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
95 $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
96 $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
98 $tpl->addBlock('enclosure');
101 $tpl->addBlock('entry');
106 $tpl->addBlock('feed');
107 $tpl->generateOutputToString($tmp);
109 header("Content-Type: text/xml; charset=utf-8");
112 } else if ($format == 'json') {
116 $feed['title'] = $feed_title;
117 $feed['version'] = VERSION
;
118 $feed['feed_url'] = $feed_self_url;
120 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
121 $feed['hub_url'] = PUBSUBHUBBUB_HUB
;
124 $feed['self_url'] = get_self_url_prefix();
126 $feed['articles'] = array();
128 while ($line = db_fetch_assoc($result)) {
131 $article['id'] = $line['link'];
132 $article['link'] = $line['link'];
133 $article['title'] = $line['title'];
134 $article['excerpt'] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
135 $article['content'] = sanitize($this->link
, $line["content_preview"], false, $owner_uid);
136 $article['updated'] = date('c', strtotime($line["updated"]));
138 if ($line['note']) $article['note'] = $line['note'];
139 if ($article['author']) $article['author'] = $line['author'];
141 $tags = get_article_tags($this->link
, $line["id"], $owner_uid);
143 if (count($tags) > 0) {
144 $article['tags'] = array();
146 foreach ($tags as $tag) {
147 array_push($article['tags'], $tag);
151 $enclosures = get_article_enclosures($this->link
, $line["id"]);
153 if (count($enclosures) > 0) {
154 $article['enclosures'] = array();
156 foreach ($enclosures as $e) {
157 $type = $e['content_type'];
158 $url = $e['content_url'];
159 $length = $e['duration'];
161 array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
165 array_push($feed['articles'], $article);
168 header("Content-Type: text/plain; charset=utf-8");
170 print json_encode($feed);
173 header("Content-Type: text/plain; charset=utf-8");
174 print json_encode(array("error" => array("message" => "Unknown format")));
178 function getUnread() {
179 $login = db_escape_string($_REQUEST["login"]);
180 $fresh = $_REQUEST["fresh"] == "1";
182 $result = db_query($this->link
, "SELECT id FROM ttrss_users WHERE login = '$login'");
184 if (db_num_rows($result) == 1) {
185 $uid = db_fetch_result($result, 0, "id");
187 print getGlobalUnread($this->link
, $uid);
191 print getFeedArticles($this->link
, -3, false, true, $uid);
195 print "-1;User not found";
200 function getProfiles() {
201 $login = db_escape_string($_REQUEST["login"]);
203 $result = db_query($this->link
, "SELECT * FROM ttrss_settings_profiles,ttrss_users
204 WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = '$login' ORDER BY title");
206 print "<select dojoType='dijit.form.Select' style='width : 220px; margin : 0px' name='profile'>";
208 print "<option value='0'>" . __("Default profile") . "</option>";
210 while ($line = db_fetch_assoc($result)) {
212 $title = $line["title"];
214 print "<option value='$id'>$title</option>";
221 $mode = db_escape_string($_REQUEST['hub_mode']);
222 $feed_id = (int) db_escape_string($_REQUEST['id']);
223 $feed_url = db_escape_string($_REQUEST['hub_topic']);
225 if (!PUBSUBHUBBUB_ENABLED
) {
226 header('HTTP/1.0 404 Not Found');
227 echo "404 Not found";
231 // TODO: implement hub_verifytoken checking
233 $result = db_query($this->link
, "SELECT feed_url FROM ttrss_feeds
234 WHERE id = '$feed_id'");
236 if (db_num_rows($result) != 0) {
238 $check_feed_url = db_fetch_result($result, 0, "feed_url");
240 if ($check_feed_url && ($check_feed_url == $feed_url ||
!$feed_url)) {
241 if ($mode == "subscribe") {
243 db_query($this->link
, "UPDATE ttrss_feeds SET pubsub_state = 2
244 WHERE id = '$feed_id'");
246 print $_REQUEST['hub_challenge'];
249 } else if ($mode == "unsubscribe") {
251 db_query($this->link
, "UPDATE ttrss_feeds SET pubsub_state = 0
252 WHERE id = '$feed_id'");
254 print $_REQUEST['hub_challenge'];
259 // Received update ping, schedule feed update.
260 //update_rss_feed($this->link, $feed_id, true, true);
262 db_query($this->link
, "UPDATE ttrss_feeds SET
263 last_update_started = '1970-01-01',
264 last_updated = '1970-01-01' WHERE id = '$feed_id'");
268 header('HTTP/1.0 404 Not Found');
269 echo "404 Not found";
272 header('HTTP/1.0 404 Not Found');
273 echo "404 Not found";
280 header("Location: index.php");
284 $uuid = db_escape_string($_REQUEST["key"]);
286 $result = db_query($this->link
, "SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
289 if (db_num_rows($result) != 0) {
290 header("Content-Type: text/html");
292 $id = db_fetch_result($result, 0, "ref_id");
293 $owner_uid = db_fetch_result($result, 0, "owner_uid");
295 $article = format_article($this->link
, $id, false, true, $owner_uid);
297 print_r($article['content']);
300 print "Article not found.";
306 $feed = db_escape_string($_REQUEST["id"]);
307 $key = db_escape_string($_REQUEST["key"]);
308 $is_cat = $_REQUEST["is_cat"] != false;
309 $limit = (int)db_escape_string($_REQUEST["limit"]);
310 $offset = (int)db_escape_string($_REQUEST["offset"]);
312 $search = db_escape_string($_REQUEST["q"]);
313 $match_on = db_escape_string($_REQUEST["m"]);
314 $search_mode = db_escape_string($_REQUEST["smode"]);
315 $view_mode = db_escape_string($_REQUEST["view-mode"]);
317 $format = db_escape_string($_REQUEST['format']);
319 if (!$format) $format = 'atom';
321 if (SINGLE_USER_MODE
) {
322 authenticate_user($this->link
, "admin", null);
328 $result = db_query($this->link
, "SELECT owner_uid FROM
329 ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
331 if (db_num_rows($result) == 1)
332 $owner_id = db_fetch_result($result, 0, "owner_uid");
336 $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
337 $offset, $search, $search_mode, $match_on, $view_mode, $format);
339 header('HTTP/1.1 403 Forbidden');
343 function globalUpdateFeeds() {
344 include "rssfuncs.php";
345 // Update all feeds needing a update.
346 update_daemon_common($this->link
, 0, true, false);
349 function sharepopup() {
350 if (SINGLE_USER_MODE
) {
351 login_sequence($this->link
);
354 header('Content-Type: text/html; charset=utf-8');
357 <title>Tiny Tiny RSS</title>
358 <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
359 <script type=\"text/javascript\" src=\"lib/prototype.js\"></script>
360 <script type=\"text/javascript\" src=\"lib/scriptaculous/scriptaculous.js?load=effects,dragdrop,controls\"></script>
361 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
363 <body id='sharepopup'>";
365 $action = $_REQUEST["action"];
367 if ($_SESSION["uid"]) {
369 if ($action == 'share') {
371 $title = db_escape_string(strip_tags($_REQUEST["title"]));
372 $url = db_escape_string(strip_tags($_REQUEST["url"]));
373 $content = db_escape_string(strip_tags($_REQUEST["content"]));
374 $labels = db_escape_string(strip_tags($_REQUEST["labels"]));
376 create_published_article($this->link
, $title, $url, $content, $labels,
379 print "<script type='text/javascript'>";
380 print "window.close();";
384 $title = htmlspecialchars($_REQUEST["title"]);
385 $url = htmlspecialchars($_REQUEST["url"]);
389 <table height
='100%' width
='100%'><tr
><td colspan
='2'>
390 <h1
><?php
echo __("Share with Tiny Tiny RSS") ?
></h1
>
393 <form id
='share_form' name
='share_form'>
395 <input type
="hidden" name
="op" value
="sharepopup">
396 <input type
="hidden" name
="action" value
="share">
398 <tr
><td align
='right'><?php
echo __("Title:") ?
></td
>
399 <td width
='80%'><input name
='title' value
="<?php echo $title ?>"></td
></tr
>
400 <tr
><td align
='right'><?php
echo __("URL:") ?
></td
>
401 <td
><input name
='url' value
="<?php echo $url ?>"></td
></tr
>
402 <tr
><td align
='right'><?php
echo __("Content:") ?
></td
>
403 <td
><input name
='content' value
=""></td
></tr
>
404 <tr
><td align
='right'><?php
echo __("Labels:") ?
></td
>
405 <td
><input name
='labels' id
="labels_value"
406 placeholder
='Alpha, Beta, Gamma' value
="">
410 <div
class="autocomplete" id
="labels_choices"
411 style
="display : block"></div
></td
></tr
>
413 <script type
='text/javascript'>document
.forms
[0].title
.focus();</script
>
415 <script type
='text/javascript'>
416 new Ajax
.Autocompleter('labels_value', 'labels_choices',
417 "backend.php?op=rpc&method=completeLabels",
418 { tokens
: ',', paramName
: "search" });
422 <div style
='float : right' class='insensitive-small'>
423 <?php
echo __("Shared article will appear in the Published feed.") ?
>
425 <button type
="submit"><?php
echo __('Share') ?
></button
>
426 <button onclick
="return window.close()"><?php
echo __('Cancel') ?
></button
>
438 $return = urlencode($_SERVER["REQUEST_URI"])
441 <form action
="public.php?return=<?php echo $return ?>"
442 method
="POST" id
="loginForm" name
="loginForm">
444 <input type
="hidden" name
="op" value
="login">
446 <table height
='100%' width
='100%'><tr
><td colspan
='2'>
447 <h1
><?php
echo __("Not logged in") ?
></h1
></td
></tr
>
449 <tr
><td align
="right"><?php
echo __("Login:") ?
></td
>
450 <td align
="right"><input name
="login"
451 value
="<?php echo $_SESSION["fake_login
"] ?>"></td
></tr
>
452 <tr
><td align
="right"><?php
echo __("Password:") ?
></td
>
453 <td align
="right"><input type
="password" name
="password"
454 value
="<?php echo $_SESSION["fake_password
"] ?>"></td
></tr
>
455 <tr
><td align
="right"><?php
echo __("Language:") ?
></td
>
458 print_select_hash("language", $_COOKIE["ttrss_lang"], get_translations(),
459 "style='width : 100%''");
464 <button type
="submit">
465 <?php
echo __('Log in') ?
></button
>
467 <button onclick
="return window.close()">
468 <?php
echo __('Cancel') ?
></button
>
479 $_SESSION["prefs_cache"] = array();
481 if (!SINGLE_USER_MODE
) {
483 $login = db_escape_string($_POST["login"]);
484 $password = $_POST["password"];
485 $remember_me = $_POST["remember_me"];
487 if (authenticate_user($this->link
, $login, $password)) {
488 $_POST["password"] = "";
490 $_SESSION["language"] = $_POST["language"];
491 $_SESSION["ref_schema_version"] = get_schema_version($this->link
, true);
492 $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
494 if ($_POST["profile"]) {
496 $profile = db_escape_string($_POST["profile"]);
498 $result = db_query($this->link
, "SELECT id FROM ttrss_settings_profiles
499 WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]);
501 if (db_num_rows($result) != 0) {
502 $_SESSION["profile"] = $profile;
503 $_SESSION["prefs_cache"] = array();
507 $_SESSION["login_error_msg"] = __("Incorrect username or password");
510 if ($_REQUEST['return']) {
511 header("Location: " . $_REQUEST['return']);
513 header("Location: " . SELF_URL_PATH
);
518 function subscribe() {
519 if (SINGLE_USER_MODE
) {
520 login_sequence($this->link
);
523 if ($_SESSION["uid"]) {
525 $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
527 header('Content-Type: text/html; charset=utf-8');
530 <title>Tiny Tiny RSS</title>
531 <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
532 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
535 <img class=\"floatingLogo\" src=\"images/logo_wide.png\"
536 alt=\"Tiny Tiny RSS\"/>
537 <h1>".__("Subscribe to feed...")."</h1>";
539 $rc = subscribe_to_feed($this->link
, $feed_url);
541 switch ($rc['code']) {
543 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
546 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
549 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
552 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
555 print_notice(__("Multiple feed URLs found."));
556 $feed_urls = $rc["feeds"];
559 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
565 print "<form action=\"public.php\">";
566 print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">";
568 print "<select name=\"feed_url\">";
570 foreach ($feed_urls as $url => $name) {
571 $url = htmlspecialchars($url);
572 $name = htmlspecialchars($name);
574 print "<option value=\"$url\">$name</option>";
577 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
583 $tp_uri = get_self_url_prefix() . "/prefs.php";
584 $tt_uri = get_self_url_prefix();
586 if ($rc['code'] <= 2){
587 $result = db_query($this->link
, "SELECT id FROM ttrss_feeds WHERE
588 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
590 $feed_id = db_fetch_result($result, 0, "id");
597 print "<form method=\"GET\" style='display: inline'
599 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
600 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
601 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
602 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
606 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
607 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
610 print "</body></html>";
613 render_login_form($this->link
);
617 function subscribe2() {
618 $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
619 $cat_id = db_escape_string($_REQUEST["cat_id"]);
620 $from = db_escape_string($_REQUEST["from"]);
622 /* only read authentication information from POST */
624 $auth_login = db_escape_string(trim($_POST["auth_login"]));
625 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
627 $rc = subscribe_to_feed($this->link
, $feed_url, $cat_id, $auth_login, $auth_pass);
631 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
634 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
637 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
640 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
643 print_notice(__("Multiple feed URLs found."));
645 $feed_urls = get_feeds_from_html($feed_url);
648 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
653 print "<form action=\"backend.php\">";
654 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
655 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
656 print "<input type=\"hidden\" name=\"method\" value=\"add\">";
658 print "<select name=\"feed_url\">";
660 foreach ($feed_urls as $url => $name) {
661 $url = htmlspecialchars($url);
662 $name = htmlspecialchars($name);
663 print "<option value=\"$url\">$name</option>";
666 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed")."\">";
670 $tp_uri = get_self_url_prefix() . "/prefs.php";
671 $tt_uri = get_self_url_prefix();
674 $result = db_query($this->link
, "SELECT id FROM ttrss_feeds WHERE
675 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
677 $feed_id = db_fetch_result($result, 0, "id");
685 print "<form method=\"GET\" style='display: inline'
687 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
688 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
689 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
690 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
694 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
695 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
698 print "</body></html>";
702 header("Content-Type: text/plain");
703 print json_encode(array("error" => array("code" => 7)));