]>
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);
42 $tpl->setVariable('VERSION', VERSION
);
43 $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url));
45 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
46 $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB
));
47 $tpl->addBlock('feed_hub');
50 $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()));
52 while ($line = db_fetch_assoc($result)) {
53 $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']));
54 $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']));
55 $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']));
56 $tpl->setVariable('ARTICLE_EXCERPT',
57 truncate_string(strip_tags($line["content_preview"]), 100, '...'));
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);
68 $tpl->setVariable('ARTICLE_UPDATED', date('c', strtotime($line["updated"])));
69 $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']));
71 $tags = get_article_tags($this->link
, $line["id"], $owner_uid);
73 foreach ($tags as $tag) {
74 $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag));
75 $tpl->addBlock('category');
78 $enclosures = get_article_enclosures($this->link
, $line["id"]);
80 foreach ($enclosures as $e) {
81 $type = htmlspecialchars($e['content_type']);
82 $url = htmlspecialchars($e['content_url']);
83 $length = $e['duration'];
85 $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url);
86 $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type);
87 $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length);
89 $tpl->addBlock('enclosure');
92 $tpl->addBlock('entry');
97 $tpl->addBlock('feed');
98 $tpl->generateOutputToString($tmp);
103 function getUnread() {
104 $login = db_escape_string($_REQUEST["login"]);
105 $fresh = $_REQUEST["fresh"] == "1";
107 $result = db_query($this->link
, "SELECT id FROM ttrss_users WHERE login = '$login'");
109 if (db_num_rows($result) == 1) {
110 $uid = db_fetch_result($result, 0, "id");
112 print getGlobalUnread($this->link
, $uid);
116 print getFeedArticles($this->link
, -3, false, true, $uid);
120 print "-1;User not found";
125 function getProfiles() {
126 $login = db_escape_string($_REQUEST["login"]);
127 $password = db_escape_string($_REQUEST["password"]);
129 if (authenticate_user($this->link
, $login, $password)) {
130 $result = db_query($this->link
, "SELECT * FROM ttrss_settings_profiles
131 WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY title");
133 print "<select style='width: 100%' name='profile'>";
135 print "<option value='0'>" . __("Default profile") . "</option>";
137 while ($line = db_fetch_assoc($result)) {
139 $title = $line["title"];
141 print "<option value='$id'>$title</option>";
151 $mode = db_escape_string($_REQUEST['hub_mode']);
152 $feed_id = (int) db_escape_string($_REQUEST['id']);
153 $feed_url = db_escape_string($_REQUEST['hub_topic']);
155 if (!PUBSUBHUBBUB_ENABLED
) {
156 header('HTTP/1.0 404 Not Found');
157 echo "404 Not found";
161 // TODO: implement hub_verifytoken checking
163 $result = db_query($this->link
, "SELECT feed_url FROM ttrss_feeds
164 WHERE id = '$feed_id'");
166 if (db_num_rows($result) != 0) {
168 $check_feed_url = db_fetch_result($result, 0, "feed_url");
170 if ($check_feed_url && ($check_feed_url == $feed_url ||
!$feed_url)) {
171 if ($mode == "subscribe") {
173 db_query($this->link
, "UPDATE ttrss_feeds SET pubsub_state = 2
174 WHERE id = '$feed_id'");
176 print $_REQUEST['hub_challenge'];
179 } else if ($mode == "unsubscribe") {
181 db_query($this->link
, "UPDATE ttrss_feeds SET pubsub_state = 0
182 WHERE id = '$feed_id'");
184 print $_REQUEST['hub_challenge'];
189 // Received update ping, schedule feed update.
190 //update_rss_feed($this->link, $feed_id, true, true);
192 db_query($this->link
, "UPDATE ttrss_feeds SET
193 last_update_started = '1970-01-01',
194 last_updated = '1970-01-01' WHERE id = '$feed_id'");
198 header('HTTP/1.0 404 Not Found');
199 echo "404 Not found";
202 header('HTTP/1.0 404 Not Found');
203 echo "404 Not found";
210 header("Location: index.php");
213 function fbexport() {
215 $access_key = db_escape_string($_POST["key"]);
217 // TODO: rate limit checking using last_connected
218 $result = db_query($this->link
, "SELECT id FROM ttrss_linked_instances
219 WHERE access_key = '$access_key'");
221 if (db_num_rows($result) == 1) {
223 $instance_id = db_fetch_result($result, 0, "id");
225 $result = db_query($this->link
, "SELECT feed_url, site_url, title, subscribers
226 FROM ttrss_feedbrowser_cache ORDER BY subscribers DESC LIMIT 100");
230 while ($line = db_fetch_assoc($result)) {
231 array_push($feeds, $line);
234 db_query($this->link
, "UPDATE ttrss_linked_instances SET
235 last_status_in = 1 WHERE id = '$instance_id'");
237 print json_encode(array("feeds" => $feeds));
239 print json_encode(array("error" => array("code" => 6)));
244 $uuid = db_escape_string($_REQUEST["key"]);
246 $result = db_query($this->link
, "SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
249 if (db_num_rows($result) != 0) {
250 header("Content-Type: text/html");
252 $id = db_fetch_result($result, 0, "ref_id");
253 $owner_uid = db_fetch_result($result, 0, "owner_uid");
255 $_SESSION["uid"] = $owner_uid;
256 $article = format_article($this->link
, $id, false, true);
257 $_SESSION["uid"] = "";
259 print_r($article['content']);
262 print "Article not found.";
268 header("Content-Type: text/xml; charset=utf-8");
270 $feed = db_escape_string($_REQUEST["id"]);
271 $key = db_escape_string($_REQUEST["key"]);
272 $is_cat = $_REQUEST["is_cat"] != false;
273 $limit = (int)db_escape_string($_REQUEST["limit"]);
275 $search = db_escape_string($_REQUEST["q"]);
276 $match_on = db_escape_string($_REQUEST["m"]);
277 $search_mode = db_escape_string($_REQUEST["smode"]);
278 $view_mode = db_escape_string($_REQUEST["view-mode"]);
280 if (SINGLE_USER_MODE
) {
281 authenticate_user($this->link
, "admin", null);
287 $result = db_query($this->link
, "SELECT owner_uid FROM
288 ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
290 if (db_num_rows($result) == 1)
291 $owner_id = db_fetch_result($result, 0, "owner_uid");
295 $_SESSION['uid'] = $owner_id;
297 $this->generate_syndicated_feed(0, $feed, $is_cat, $limit,
298 $search, $search_mode, $match_on, $view_mode);
300 header('HTTP/1.1 403 Forbidden');
304 /* function globalUpdateFeeds() {
305 // Update all feeds needing a update.
306 update_daemon_common($this->link, 0, true, true);