]>
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, $search, $search_mode, $match_on, $view_mode = false, $format = 'atom') {
7 require_once "lib/MiniTemplator.class.php";
9 $note_style = "background-color : #fff7d5;
10 border-width : 1px; ".
11 "padding : 5px; border-style : dashed; border-color : #e7d796;".
12 "margin-bottom : 1em; color : #9a8c59;";
14 if (!$limit) $limit = 30;
16 if (get_pref($this->link
, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
17 $date_sort_field = "updated";
19 $date_sort_field = "date_entered";
22 $qfh_ret = queryFeedHeadlines($this->link
, $feed,
23 $limit, $view_mode, $is_cat, $search, $search_mode,
24 $match_on, "$date_sort_field DESC", 0, $owner_uid);
26 $result = $qfh_ret[0];
27 $feed_title = htmlspecialchars($qfh_ret[1]);
28 $feed_site_url = $qfh_ret[2];
29 $last_error = $qfh_ret[3];
31 $feed_self_url = get_self_url_prefix() .
32 "/public.php?op=rss&id=-2&key=" .
33 get_feed_access_key($this->link
, -2, false, $owner_uid);
35 if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
37 if ($format == 'atom') {
38 $tpl = new MiniTemplator
;
40 $tpl->readTemplateFromFile("templates/generated_feed.txt");
42 $tpl->setVariable('FEED_TITLE', $feed_title, true);
43 $tpl->setVariable('VERSION', VERSION
, true);
44 $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
46 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
47 $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB
), true);
48 $tpl->addBlock('feed_hub');
51 $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
53 while ($line = db_fetch_assoc($result)) {
54 $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']), true);
55 $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
56 $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
57 $tpl->setVariable('ARTICLE_EXCERPT',
58 truncate_string(strip_tags($line["content_preview"]), 100, '...'), true);
60 $content = sanitize($this->link
, $line["content_preview"], false, $owner_uid);
63 $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
67 $tpl->setVariable('ARTICLE_CONTENT', $content, true);
69 $tpl->setVariable('ARTICLE_UPDATED_ATOM',
70 date('c', strtotime($line["updated"])), true);
71 $tpl->setVariable('ARTICLE_UPDATED_RFC822',
72 date(DATE_RFC822
, strtotime($line["updated"])), true);
74 $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
76 $tags = get_article_tags($this->link
, $line["id"], $owner_uid);
78 foreach ($tags as $tag) {
79 $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
80 $tpl->addBlock('category');
83 $enclosures = get_article_enclosures($this->link
, $line["id"]);
85 foreach ($enclosures as $e) {
86 $type = htmlspecialchars($e['content_type']);
87 $url = htmlspecialchars($e['content_url']);
88 $length = $e['duration'];
90 $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
91 $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
92 $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
94 $tpl->addBlock('enclosure');
97 $tpl->addBlock('entry');
102 $tpl->addBlock('feed');
103 $tpl->generateOutputToString($tmp);
105 header("Content-Type: text/xml; charset=utf-8");
108 } else if ($format == 'json') {
112 $feed['title'] = $feed_title;
113 $feed['version'] = VERSION
;
114 $feed['feed_url'] = $feed_self_url;
116 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
117 $feed['hub_url'] = PUBSUBHUBBUB_HUB
;
120 $feed['self_url'] = get_self_url_prefix();
122 $feed['articles'] = array();
124 while ($line = db_fetch_assoc($result)) {
127 $article['id'] = $line['link'];
128 $article['link'] = $line['link'];
129 $article['title'] = $line['title'];
130 $article['excerpt'] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
131 $article['content'] = sanitize($this->link
, $line["content_preview"], false, $owner_uid);
132 $article['updated'] = date('c', strtotime($line["updated"]));
134 if ($line['note']) $article['note'] = $line['note'];
135 if ($article['author']) $article['author'] = $line['author'];
137 $tags = get_article_tags($this->link
, $line["id"], $owner_uid);
139 if (count($tags) > 0) {
140 $article['tags'] = array();
142 foreach ($tags as $tag) {
143 array_push($article['tags'], $tag);
147 $enclosures = get_article_enclosures($this->link
, $line["id"]);
149 if (count($enclosures) > 0) {
150 $article['enclosures'] = array();
152 foreach ($enclosures as $e) {
153 $type = $e['content_type'];
154 $url = $e['content_url'];
155 $length = $e['duration'];
157 array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
161 array_push($feed['articles'], $article);
164 header("Content-Type: text/plain; charset=utf-8");
166 print json_encode($feed);
169 header("Content-Type: text/plain; charset=utf-8");
170 print json_encode(array("error" => array("message" => "Unknown format")));
174 function getUnread() {
175 $login = db_escape_string($_REQUEST["login"]);
176 $fresh = $_REQUEST["fresh"] == "1";
178 $result = db_query($this->link
, "SELECT id FROM ttrss_users WHERE login = '$login'");
180 if (db_num_rows($result) == 1) {
181 $uid = db_fetch_result($result, 0, "id");
183 print getGlobalUnread($this->link
, $uid);
187 print getFeedArticles($this->link
, -3, false, true, $uid);
191 print "-1;User not found";
196 function getProfiles() {
197 $login = db_escape_string($_REQUEST["login"]);
198 $password = db_escape_string($_REQUEST["password"]);
200 if (authenticate_user($this->link
, $login, $password)) {
201 $result = db_query($this->link
, "SELECT * FROM ttrss_settings_profiles
202 WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY title");
204 print "<select style='width: 100%' name='profile'>";
206 print "<option value='0'>" . __("Default profile") . "</option>";
208 while ($line = db_fetch_assoc($result)) {
210 $title = $line["title"];
212 print "<option value='$id'>$title</option>";
222 $mode = db_escape_string($_REQUEST['hub_mode']);
223 $feed_id = (int) db_escape_string($_REQUEST['id']);
224 $feed_url = db_escape_string($_REQUEST['hub_topic']);
226 if (!PUBSUBHUBBUB_ENABLED
) {
227 header('HTTP/1.0 404 Not Found');
228 echo "404 Not found";
232 // TODO: implement hub_verifytoken checking
234 $result = db_query($this->link
, "SELECT feed_url FROM ttrss_feeds
235 WHERE id = '$feed_id'");
237 if (db_num_rows($result) != 0) {
239 $check_feed_url = db_fetch_result($result, 0, "feed_url");
241 if ($check_feed_url && ($check_feed_url == $feed_url ||
!$feed_url)) {
242 if ($mode == "subscribe") {
244 db_query($this->link
, "UPDATE ttrss_feeds SET pubsub_state = 2
245 WHERE id = '$feed_id'");
247 print $_REQUEST['hub_challenge'];
250 } else if ($mode == "unsubscribe") {
252 db_query($this->link
, "UPDATE ttrss_feeds SET pubsub_state = 0
253 WHERE id = '$feed_id'");
255 print $_REQUEST['hub_challenge'];
260 // Received update ping, schedule feed update.
261 //update_rss_feed($this->link, $feed_id, true, true);
263 db_query($this->link
, "UPDATE ttrss_feeds SET
264 last_update_started = '1970-01-01',
265 last_updated = '1970-01-01' WHERE id = '$feed_id'");
269 header('HTTP/1.0 404 Not Found');
270 echo "404 Not found";
273 header('HTTP/1.0 404 Not Found');
274 echo "404 Not found";
281 header("Location: index.php");
284 function fbexport() {
286 $access_key = db_escape_string($_POST["key"]);
288 // TODO: rate limit checking using last_connected
289 $result = db_query($this->link
, "SELECT id FROM ttrss_linked_instances
290 WHERE access_key = '$access_key'");
292 if (db_num_rows($result) == 1) {
294 $instance_id = db_fetch_result($result, 0, "id");
296 $result = db_query($this->link
, "SELECT feed_url, site_url, title, subscribers
297 FROM ttrss_feedbrowser_cache ORDER BY subscribers DESC LIMIT 100");
301 while ($line = db_fetch_assoc($result)) {
302 array_push($feeds, $line);
305 db_query($this->link
, "UPDATE ttrss_linked_instances SET
306 last_status_in = 1 WHERE id = '$instance_id'");
308 print json_encode(array("feeds" => $feeds));
310 print json_encode(array("error" => array("code" => 6)));
315 $uuid = db_escape_string($_REQUEST["key"]);
317 $result = db_query($this->link
, "SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
320 if (db_num_rows($result) != 0) {
321 header("Content-Type: text/html");
323 $id = db_fetch_result($result, 0, "ref_id");
324 $owner_uid = db_fetch_result($result, 0, "owner_uid");
326 $article = format_article($this->link
, $id, false, true, $owner_uid);
328 print_r($article['content']);
331 print "Article not found.";
337 $feed = db_escape_string($_REQUEST["id"]);
338 $key = db_escape_string($_REQUEST["key"]);
339 $is_cat = $_REQUEST["is_cat"] != false;
340 $limit = (int)db_escape_string($_REQUEST["limit"]);
342 $search = db_escape_string($_REQUEST["q"]);
343 $match_on = db_escape_string($_REQUEST["m"]);
344 $search_mode = db_escape_string($_REQUEST["smode"]);
345 $view_mode = db_escape_string($_REQUEST["view-mode"]);
347 $format = db_escape_string($_REQUEST['format']);
349 if (!$format) $format = 'atom';
351 if (SINGLE_USER_MODE
) {
352 authenticate_user($this->link
, "admin", null);
358 $result = db_query($this->link
, "SELECT owner_uid FROM
359 ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
361 if (db_num_rows($result) == 1)
362 $owner_id = db_fetch_result($result, 0, "owner_uid");
366 $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
367 $search, $search_mode, $match_on, $view_mode, $format);
369 header('HTTP/1.1 403 Forbidden');
373 function globalUpdateFeeds() {
374 include "rssfuncs.php";
375 // Update all feeds needing a update.
376 update_daemon_common($this->link
, 0, true, false);
379 function sharepopup() {
380 header('Content-Type: text/html; charset=utf-8');
383 <title>Tiny Tiny RSS</title>
384 <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
385 <script type=\"text/javascript\" src=\"lib/prototype.js\"></script>
386 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
388 <body id='sharepopup'>";
390 $action = $_REQUEST["action"];
392 if ($_SESSION["uid"]) {
396 print "<table height='100%' width='100%'><tr><td colspan='2'>";
397 print "<h1>".__("Share with Tiny Tiny RSS")."</h1>";
400 print "<form id='share_form' name='share_form'>";
402 print "<input type=\"hidden\" name=\"op\" value=\"sharepopup\">";
403 print "<input type=\"hidden\" name=\"action\" value=\"share\">";
405 $title = htmlspecialchars($_REQUEST["title"]);
406 $url = htmlspecialchars($_REQUEST["url"]);
408 print "<tr><td>".__("Title:")."</td><td width='80%'><input name='title' value=\"$title\"></td></tr>";
409 print "<tr><td>".__("URL:")."</td><td><input name='url' value=\"$url\"></td></tr>";
410 print "<tr><td>".__("Content:")."</td><td><input name='content' value=\"\"></td></tr>";
412 print "<script type='text/javascript'>";
413 print "document.forms[0].title.focus();";
416 print "<tr><td colspan='2'>
417 <div style='float : right' class='insensitive-small'>".
418 __("Shared article will appear in the Published feed.").
419 "</div><button type=\"submit\">".
420 __('Share')."</button>
421 <button onclick=\"return window.close()\">".
422 __('Cancel')."</button>
426 print "</td></tr></table>";
428 print "</body></html>";
432 $title = db_escape_string(strip_tags($_REQUEST["title"]));
433 $url = db_escape_string(strip_tags($_REQUEST["url"]));
434 $content = db_escape_string(strip_tags($_REQUEST["content"]));
436 create_published_article($this->link
, $title, $url, $content, $_SESSION["uid"]);
438 print "<script type='text/javascript'>";
439 print "window.close();";
445 print "<table><tr><td>" . __("Not logged in.") . "</td></tr></table>";