]>
git.wh0rd.org - tt-rss.git/blob - classes/public_handler.php
2 class Public_Handler
extends Handler
{
4 private function generate_syndicated_feed($owner_uid, $feed, $is_cat,
5 $limit, $search, $search_mode, $match_on, $view_mode = false) {
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);
35 if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
37 $tpl = new MiniTemplator
;
39 $tpl->readTemplateFromFile("templates/generated_feed.txt");
41 $tpl->setVariable('FEED_TITLE', $feed_title, true);
42 $tpl->setVariable('VERSION', VERSION
, true);
43 $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
45 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
46 $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB
), true);
47 $tpl->addBlock('feed_hub');
50 $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
52 while ($line = db_fetch_assoc($result)) {
53 $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']), true);
54 $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
55 $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
56 $tpl->setVariable('ARTICLE_EXCERPT',
57 truncate_string(strip_tags($line["content_preview"]), 100, '...'), true);
59 $content = sanitize($this->link
, $line["content_preview"], false, $owner_uid);
62 $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
66 $tpl->setVariable('ARTICLE_CONTENT', $content, true);
68 $tpl->setVariable('ARTICLE_UPDATED_ATOM',
69 date('c', strtotime($line["updated"])), true);
70 $tpl->setVariable('ARTICLE_UPDATED_RFC822',
71 date(DATE_RFC822
, strtotime($line["updated"])), true);
73 $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
75 $tags = get_article_tags($this->link
, $line["id"], $owner_uid);
77 foreach ($tags as $tag) {
78 $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
79 $tpl->addBlock('category');
82 $enclosures = get_article_enclosures($this->link
, $line["id"]);
84 foreach ($enclosures as $e) {
85 $type = htmlspecialchars($e['content_type']);
86 $url = htmlspecialchars($e['content_url']);
87 $length = $e['duration'];
89 $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
90 $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
91 $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
93 $tpl->addBlock('enclosure');
96 $tpl->addBlock('entry');
101 $tpl->addBlock('feed');
102 $tpl->generateOutputToString($tmp);
107 function getUnread() {
108 $login = db_escape_string($_REQUEST["login"]);
109 $fresh = $_REQUEST["fresh"] == "1";
111 $result = db_query($this->link
, "SELECT id FROM ttrss_users WHERE login = '$login'");
113 if (db_num_rows($result) == 1) {
114 $uid = db_fetch_result($result, 0, "id");
116 print getGlobalUnread($this->link
, $uid);
120 print getFeedArticles($this->link
, -3, false, true, $uid);
124 print "-1;User not found";
129 function getProfiles() {
130 $login = db_escape_string($_REQUEST["login"]);
131 $password = db_escape_string($_REQUEST["password"]);
133 if (authenticate_user($this->link
, $login, $password)) {
134 $result = db_query($this->link
, "SELECT * FROM ttrss_settings_profiles
135 WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY title");
137 print "<select style='width: 100%' name='profile'>";
139 print "<option value='0'>" . __("Default profile") . "</option>";
141 while ($line = db_fetch_assoc($result)) {
143 $title = $line["title"];
145 print "<option value='$id'>$title</option>";
155 $mode = db_escape_string($_REQUEST['hub_mode']);
156 $feed_id = (int) db_escape_string($_REQUEST['id']);
157 $feed_url = db_escape_string($_REQUEST['hub_topic']);
159 if (!PUBSUBHUBBUB_ENABLED
) {
160 header('HTTP/1.0 404 Not Found');
161 echo "404 Not found";
165 // TODO: implement hub_verifytoken checking
167 $result = db_query($this->link
, "SELECT feed_url FROM ttrss_feeds
168 WHERE id = '$feed_id'");
170 if (db_num_rows($result) != 0) {
172 $check_feed_url = db_fetch_result($result, 0, "feed_url");
174 if ($check_feed_url && ($check_feed_url == $feed_url ||
!$feed_url)) {
175 if ($mode == "subscribe") {
177 db_query($this->link
, "UPDATE ttrss_feeds SET pubsub_state = 2
178 WHERE id = '$feed_id'");
180 print $_REQUEST['hub_challenge'];
183 } else if ($mode == "unsubscribe") {
185 db_query($this->link
, "UPDATE ttrss_feeds SET pubsub_state = 0
186 WHERE id = '$feed_id'");
188 print $_REQUEST['hub_challenge'];
193 // Received update ping, schedule feed update.
194 //update_rss_feed($this->link, $feed_id, true, true);
196 db_query($this->link
, "UPDATE ttrss_feeds SET
197 last_update_started = '1970-01-01',
198 last_updated = '1970-01-01' WHERE id = '$feed_id'");
202 header('HTTP/1.0 404 Not Found');
203 echo "404 Not found";
206 header('HTTP/1.0 404 Not Found');
207 echo "404 Not found";
214 header("Location: index.php");
217 function fbexport() {
219 $access_key = db_escape_string($_POST["key"]);
221 // TODO: rate limit checking using last_connected
222 $result = db_query($this->link
, "SELECT id FROM ttrss_linked_instances
223 WHERE access_key = '$access_key'");
225 if (db_num_rows($result) == 1) {
227 $instance_id = db_fetch_result($result, 0, "id");
229 $result = db_query($this->link
, "SELECT feed_url, site_url, title, subscribers
230 FROM ttrss_feedbrowser_cache ORDER BY subscribers DESC LIMIT 100");
234 while ($line = db_fetch_assoc($result)) {
235 array_push($feeds, $line);
238 db_query($this->link
, "UPDATE ttrss_linked_instances SET
239 last_status_in = 1 WHERE id = '$instance_id'");
241 print json_encode(array("feeds" => $feeds));
243 print json_encode(array("error" => array("code" => 6)));
248 $uuid = db_escape_string($_REQUEST["key"]);
250 $result = db_query($this->link
, "SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
253 if (db_num_rows($result) != 0) {
254 header("Content-Type: text/html");
256 $id = db_fetch_result($result, 0, "ref_id");
257 $owner_uid = db_fetch_result($result, 0, "owner_uid");
259 $article = format_article($this->link
, $id, false, true, $owner_uid);
261 print_r($article['content']);
264 print "Article not found.";
270 header("Content-Type: text/xml; charset=utf-8");
272 $feed = db_escape_string($_REQUEST["id"]);
273 $key = db_escape_string($_REQUEST["key"]);
274 $is_cat = $_REQUEST["is_cat"] != false;
275 $limit = (int)db_escape_string($_REQUEST["limit"]);
277 $search = db_escape_string($_REQUEST["q"]);
278 $match_on = db_escape_string($_REQUEST["m"]);
279 $search_mode = db_escape_string($_REQUEST["smode"]);
280 $view_mode = db_escape_string($_REQUEST["view-mode"]);
282 if (SINGLE_USER_MODE
) {
283 authenticate_user($this->link
, "admin", null);
289 $result = db_query($this->link
, "SELECT owner_uid FROM
290 ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
292 if (db_num_rows($result) == 1)
293 $owner_id = db_fetch_result($result, 0, "owner_uid");
297 $_SESSION['uid'] = $owner_id;
299 $this->generate_syndicated_feed(0, $feed, $is_cat, $limit,
300 $search, $search_mode, $match_on, $view_mode);
302 header('HTTP/1.1 403 Forbidden');
306 function globalUpdateFeeds() {
307 include "rssfuncs.php";
308 // Update all feeds needing a update.
309 update_daemon_common($this->link
, 0, true, false);