]>
Commit | Line | Data |
---|---|---|
5f0a3741 | 1 | <?php |
369dbc19 | 2 | class Handler_Public extends Handler { |
5f0a3741 | 3 | |
79178062 | 4 | private function generate_syndicated_feed($owner_uid, $feed, $is_cat, |
ca5d9be4 | 5 | $limit, $offset, $search, $search_mode, |
25051fb8 | 6 | $view_mode = false, $format = 'atom', $order = false) { |
79178062 AD |
7 | |
8 | require_once "lib/MiniTemplator.class.php"; | |
9 | ||
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;"; | |
14 | ||
2faef834 | 15 | if (!$limit) $limit = 60; |
79178062 | 16 | |
8aa01d79 | 17 | $date_sort_field = "date_entered DESC, updated DESC"; |
79178062 | 18 | |
008ebad9 | 19 | if ($feed == -2) |
7ef7dd31 | 20 | $date_sort_field = "last_published DESC"; |
feb9b2df | 21 | else if ($feed == -1) |
7ef7dd31 | 22 | $date_sort_field = "last_marked DESC"; |
008ebad9 | 23 | |
25051fb8 AD |
24 | switch ($order) { |
25 | case "title": | |
26 | $date_sort_field = "ttrss_entries.title"; | |
27 | break; | |
28 | case "date_reverse": | |
29 | $date_sort_field = "date_entered, updated"; | |
30 | break; | |
31 | case "feed_dates": | |
32 | $date_sort_field = "updated DESC"; | |
33 | break; | |
34 | } | |
35 | ||
a42c55f0 | 36 | $qfh_ret = queryFeedHeadlines($feed, |
2e35a707 AD |
37 | 1, $view_mode, $is_cat, $search, $search_mode, |
38 | $date_sort_field, $offset, $owner_uid, | |
39 | false, 0, false, true); | |
40 | ||
41 | $result = $qfh_ret[0]; | |
42 | ||
d9c85e0f AD |
43 | if ($this->dbh->num_rows($result) != 0) { |
44 | $ts = strtotime($this->dbh->fetch_result($result, 0, "date_entered")); | |
2e35a707 AD |
45 | |
46 | if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && | |
d6ba77f3 | 47 | strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $ts) { |
2e35a707 AD |
48 | header('HTTP/1.0 304 Not Modified'); |
49 | return; | |
50 | } | |
51 | ||
52 | $last_modified = gmdate("D, d M Y H:i:s", $ts) . " GMT"; | |
53 | header("Last-Modified: $last_modified", true); | |
54 | } | |
55 | ||
a42c55f0 | 56 | $qfh_ret = queryFeedHeadlines($feed, |
79178062 | 57 | $limit, $view_mode, $is_cat, $search, $search_mode, |
8aa01d79 | 58 | $date_sort_field, $offset, $owner_uid, |
6b3f228f | 59 | false, 0, false, true); |
79178062 | 60 | |
2e35a707 | 61 | |
79178062 AD |
62 | $result = $qfh_ret[0]; |
63 | $feed_title = htmlspecialchars($qfh_ret[1]); | |
64 | $feed_site_url = $qfh_ret[2]; | |
65 | $last_error = $qfh_ret[3]; | |
66 | ||
67 | $feed_self_url = get_self_url_prefix() . | |
68 | "/public.php?op=rss&id=-2&key=" . | |
a42c55f0 | 69 | get_feed_access_key(-2, false, $owner_uid); |
79178062 AD |
70 | |
71 | if (!$feed_site_url) $feed_site_url = get_self_url_prefix(); | |
72 | ||
2ebf38a9 AD |
73 | if ($format == 'atom') { |
74 | $tpl = new MiniTemplator; | |
79178062 | 75 | |
2ebf38a9 | 76 | $tpl->readTemplateFromFile("templates/generated_feed.txt"); |
79178062 | 77 | |
2ebf38a9 AD |
78 | $tpl->setVariable('FEED_TITLE', $feed_title, true); |
79 | $tpl->setVariable('VERSION', VERSION, true); | |
80 | $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true); | |
79178062 | 81 | |
2ebf38a9 AD |
82 | if (PUBSUBHUBBUB_HUB && $feed == -2) { |
83 | $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB), true); | |
84 | $tpl->addBlock('feed_hub'); | |
85 | } | |
79178062 | 86 | |
2ebf38a9 | 87 | $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true); |
67631438 | 88 | $line["content_preview"] = truncate_string(strip_tags($line["content_preview"]), 100, '...'); |
d9c85e0f | 89 | while ($line = $this->dbh->fetch_assoc($result)) { |
891e36f5 | 90 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
91 | $line = $p->hook_query_headlines($line); | |
92 | } | |
2e35a707 | 93 | |
2ebf38a9 AD |
94 | $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']), true); |
95 | $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true); | |
96 | $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true); | |
67631438 | 97 | $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true); |
79178062 | 98 | |
891e36f5 | 99 | $content = sanitize($line["content"], false, $owner_uid); |
79178062 | 100 | |
2ebf38a9 AD |
101 | if ($line['note']) { |
102 | $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" . | |
103 | $content; | |
e9c6e27d | 104 | $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true); |
105 | } | |
2ebf38a9 AD |
106 | |
107 | $tpl->setVariable('ARTICLE_CONTENT', $content, true); | |
108 | ||
109 | $tpl->setVariable('ARTICLE_UPDATED_ATOM', | |
110 | date('c', strtotime($line["updated"])), true); | |
111 | $tpl->setVariable('ARTICLE_UPDATED_RFC822', | |
112 | date(DATE_RFC822, strtotime($line["updated"])), true); | |
113 | ||
114 | $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true); | |
115 | ||
a42c55f0 | 116 | $tags = get_article_tags($line["id"], $owner_uid); |
2ebf38a9 AD |
117 | |
118 | foreach ($tags as $tag) { | |
119 | $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true); | |
120 | $tpl->addBlock('category'); | |
121 | } | |
79178062 | 122 | |
a42c55f0 | 123 | $enclosures = get_article_enclosures($line["id"]); |
79178062 | 124 | |
2ebf38a9 AD |
125 | foreach ($enclosures as $e) { |
126 | $type = htmlspecialchars($e['content_type']); | |
127 | $url = htmlspecialchars($e['content_url']); | |
128 | $length = $e['duration']; | |
9c97041d | 129 | |
2ebf38a9 AD |
130 | $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true); |
131 | $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true); | |
132 | $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true); | |
79178062 | 133 | |
2ebf38a9 AD |
134 | $tpl->addBlock('enclosure'); |
135 | } | |
79178062 | 136 | |
2ebf38a9 | 137 | $tpl->addBlock('entry'); |
79178062 AD |
138 | } |
139 | ||
2ebf38a9 AD |
140 | $tmp = ""; |
141 | ||
142 | $tpl->addBlock('feed'); | |
143 | $tpl->generateOutputToString($tmp); | |
144 | ||
10bdeb4b AD |
145 | if (@!$_REQUEST["noxml"]) { |
146 | header("Content-Type: text/xml; charset=utf-8"); | |
147 | } else { | |
148 | header("Content-Type: text/plain; charset=utf-8"); | |
149 | } | |
2ebf38a9 AD |
150 | |
151 | print $tmp; | |
152 | } else if ($format == 'json') { | |
79178062 | 153 | |
2ebf38a9 | 154 | $feed = array(); |
79178062 | 155 | |
2ebf38a9 AD |
156 | $feed['title'] = $feed_title; |
157 | $feed['version'] = VERSION; | |
158 | $feed['feed_url'] = $feed_self_url; | |
79178062 | 159 | |
2ebf38a9 AD |
160 | if (PUBSUBHUBBUB_HUB && $feed == -2) { |
161 | $feed['hub_url'] = PUBSUBHUBBUB_HUB; | |
79178062 AD |
162 | } |
163 | ||
2ebf38a9 AD |
164 | $feed['self_url'] = get_self_url_prefix(); |
165 | ||
166 | $feed['articles'] = array(); | |
167 | ||
d9c85e0f | 168 | while ($line = $this->dbh->fetch_assoc($result)) { |
575a5287 | 169 | $line["content_preview"] = truncate_string(strip_tags($line["content_preview"]), 100, '...'); |
891e36f5 | 170 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
171 | $line = $p->hook_query_headlines($line, 100); | |
172 | } | |
2ebf38a9 | 173 | $article = array(); |
79178062 | 174 | |
2ebf38a9 AD |
175 | $article['id'] = $line['link']; |
176 | $article['link'] = $line['link']; | |
177 | $article['title'] = $line['title']; | |
67631438 | 178 | $article['excerpt'] = $line["content_preview"]; |
891e36f5 | 179 | $article['content'] = sanitize($line["content"], false, $owner_uid); |
2ebf38a9 | 180 | $article['updated'] = date('c', strtotime($line["updated"])); |
79178062 | 181 | |
2ebf38a9 AD |
182 | if ($line['note']) $article['note'] = $line['note']; |
183 | if ($article['author']) $article['author'] = $line['author']; | |
79178062 | 184 | |
a42c55f0 | 185 | $tags = get_article_tags($line["id"], $owner_uid); |
2ebf38a9 AD |
186 | |
187 | if (count($tags) > 0) { | |
188 | $article['tags'] = array(); | |
189 | ||
190 | foreach ($tags as $tag) { | |
191 | array_push($article['tags'], $tag); | |
192 | } | |
193 | } | |
194 | ||
a42c55f0 | 195 | $enclosures = get_article_enclosures($line["id"]); |
2ebf38a9 AD |
196 | |
197 | if (count($enclosures) > 0) { | |
198 | $article['enclosures'] = array(); | |
199 | ||
200 | foreach ($enclosures as $e) { | |
201 | $type = $e['content_type']; | |
202 | $url = $e['content_url']; | |
203 | $length = $e['duration']; | |
204 | ||
205 | array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length)); | |
206 | } | |
207 | } | |
208 | ||
209 | array_push($feed['articles'], $article); | |
210 | } | |
211 | ||
10bdeb4b | 212 | header("Content-Type: text/json; charset=utf-8"); |
2ebf38a9 AD |
213 | print json_encode($feed); |
214 | ||
215 | } else { | |
216 | header("Content-Type: text/plain; charset=utf-8"); | |
217 | print json_encode(array("error" => array("message" => "Unknown format"))); | |
218 | } | |
79178062 AD |
219 | } |
220 | ||
5f0a3741 | 221 | function getUnread() { |
d9c85e0f | 222 | $login = $this->dbh->escape_string($_REQUEST["login"]); |
5f0a3741 AD |
223 | $fresh = $_REQUEST["fresh"] == "1"; |
224 | ||
d9c85e0f | 225 | $result = $this->dbh->query("SELECT id FROM ttrss_users WHERE login = '$login'"); |
5f0a3741 | 226 | |
d9c85e0f AD |
227 | if ($this->dbh->num_rows($result) == 1) { |
228 | $uid = $this->dbh->fetch_result($result, 0, "id"); | |
5f0a3741 | 229 | |
a42c55f0 | 230 | print getGlobalUnread($uid); |
5f0a3741 AD |
231 | |
232 | if ($fresh) { | |
233 | print ";"; | |
a42c55f0 | 234 | print getFeedArticles(-3, false, true, $uid); |
5f0a3741 AD |
235 | } |
236 | ||
237 | } else { | |
238 | print "-1;User not found"; | |
239 | } | |
240 | ||
241 | } | |
242 | ||
243 | function getProfiles() { | |
d9c85e0f | 244 | $login = $this->dbh->escape_string($_REQUEST["login"]); |
5f0a3741 | 245 | |
0806d68b | 246 | $result = $this->dbh->query("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users |
97acbaf1 | 247 | WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = '$login' ORDER BY title"); |
5f0a3741 | 248 | |
eeee2ccf | 249 | print "<select dojoType='dijit.form.Select' style='width : 220px; margin : 0px' name='profile'>"; |
5f0a3741 | 250 | |
97acbaf1 | 251 | print "<option value='0'>" . __("Default profile") . "</option>"; |
5f0a3741 | 252 | |
d9c85e0f | 253 | while ($line = $this->dbh->fetch_assoc($result)) { |
97acbaf1 AD |
254 | $id = $line["id"]; |
255 | $title = $line["title"]; | |
5f0a3741 | 256 | |
97acbaf1 | 257 | print "<option value='$id'>$title</option>"; |
5f0a3741 | 258 | } |
97acbaf1 AD |
259 | |
260 | print "</select>"; | |
5f0a3741 AD |
261 | } |
262 | ||
263 | function pubsub() { | |
d9c85e0f AD |
264 | $mode = $this->dbh->escape_string($_REQUEST['hub_mode']); |
265 | $feed_id = (int) $this->dbh->escape_string($_REQUEST['id']); | |
266 | $feed_url = $this->dbh->escape_string($_REQUEST['hub_topic']); | |
5f0a3741 AD |
267 | |
268 | if (!PUBSUBHUBBUB_ENABLED) { | |
269 | header('HTTP/1.0 404 Not Found'); | |
270 | echo "404 Not found"; | |
271 | return; | |
272 | } | |
273 | ||
274 | // TODO: implement hub_verifytoken checking | |
275 | ||
d9c85e0f | 276 | $result = $this->dbh->query("SELECT feed_url FROM ttrss_feeds |
5f0a3741 AD |
277 | WHERE id = '$feed_id'"); |
278 | ||
d9c85e0f | 279 | if ($this->dbh->num_rows($result) != 0) { |
5f0a3741 | 280 | |
d9c85e0f | 281 | $check_feed_url = $this->dbh->fetch_result($result, 0, "feed_url"); |
5f0a3741 AD |
282 | |
283 | if ($check_feed_url && ($check_feed_url == $feed_url || !$feed_url)) { | |
284 | if ($mode == "subscribe") { | |
285 | ||
d9c85e0f | 286 | $this->dbh->query("UPDATE ttrss_feeds SET pubsub_state = 2 |
5f0a3741 AD |
287 | WHERE id = '$feed_id'"); |
288 | ||
289 | print $_REQUEST['hub_challenge']; | |
290 | return; | |
291 | ||
292 | } else if ($mode == "unsubscribe") { | |
293 | ||
d9c85e0f | 294 | $this->dbh->query("UPDATE ttrss_feeds SET pubsub_state = 0 |
5f0a3741 AD |
295 | WHERE id = '$feed_id'"); |
296 | ||
297 | print $_REQUEST['hub_challenge']; | |
298 | return; | |
299 | ||
300 | } else if (!$mode) { | |
301 | ||
302 | // Received update ping, schedule feed update. | |
a42c55f0 | 303 | //update_rss_feed($feed_id, true, true); |
5f0a3741 | 304 | |
d9c85e0f | 305 | $this->dbh->query("UPDATE ttrss_feeds SET |
5f0a3741 AD |
306 | last_update_started = '1970-01-01', |
307 | last_updated = '1970-01-01' WHERE id = '$feed_id'"); | |
308 | ||
309 | } | |
310 | } else { | |
311 | header('HTTP/1.0 404 Not Found'); | |
312 | echo "404 Not found"; | |
313 | } | |
314 | } else { | |
315 | header('HTTP/1.0 404 Not Found'); | |
316 | echo "404 Not found"; | |
317 | } | |
318 | ||
319 | } | |
320 | ||
321 | function logout() { | |
322 | logout_user(); | |
323 | header("Location: index.php"); | |
324 | } | |
325 | ||
5f0a3741 | 326 | function share() { |
d9c85e0f | 327 | $uuid = $this->dbh->escape_string($_REQUEST["key"]); |
5f0a3741 | 328 | |
d9c85e0f | 329 | $result = $this->dbh->query("SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE |
5f0a3741 AD |
330 | uuid = '$uuid'"); |
331 | ||
d9c85e0f | 332 | if ($this->dbh->num_rows($result) != 0) { |
5f0a3741 AD |
333 | header("Content-Type: text/html"); |
334 | ||
d9c85e0f AD |
335 | $id = $this->dbh->fetch_result($result, 0, "ref_id"); |
336 | $owner_uid = $this->dbh->fetch_result($result, 0, "owner_uid"); | |
5f0a3741 | 337 | |
a42c55f0 | 338 | $article = format_article($id, false, true, $owner_uid); |
5f0a3741 AD |
339 | |
340 | print_r($article['content']); | |
341 | ||
342 | } else { | |
343 | print "Article not found."; | |
344 | } | |
345 | ||
346 | } | |
347 | ||
348 | function rss() { | |
d9c85e0f AD |
349 | $feed = $this->dbh->escape_string($_REQUEST["id"]); |
350 | $key = $this->dbh->escape_string($_REQUEST["key"]); | |
5f0a3741 | 351 | $is_cat = $_REQUEST["is_cat"] != false; |
d9c85e0f AD |
352 | $limit = (int)$this->dbh->escape_string($_REQUEST["limit"]); |
353 | $offset = (int)$this->dbh->escape_string($_REQUEST["offset"]); | |
5f0a3741 | 354 | |
d9c85e0f AD |
355 | $search = $this->dbh->escape_string($_REQUEST["q"]); |
356 | $search_mode = $this->dbh->escape_string($_REQUEST["smode"]); | |
357 | $view_mode = $this->dbh->escape_string($_REQUEST["view-mode"]); | |
25051fb8 | 358 | $order = $this->dbh->escape_string($_REQUEST["order"]); |
5f0a3741 | 359 | |
d9c85e0f | 360 | $format = $this->dbh->escape_string($_REQUEST['format']); |
2ebf38a9 AD |
361 | |
362 | if (!$format) $format = 'atom'; | |
363 | ||
5f0a3741 | 364 | if (SINGLE_USER_MODE) { |
a42c55f0 | 365 | authenticate_user("admin", null); |
5f0a3741 AD |
366 | } |
367 | ||
368 | $owner_id = false; | |
369 | ||
370 | if ($key) { | |
d9c85e0f | 371 | $result = $this->dbh->query("SELECT owner_uid FROM |
5f0a3741 AD |
372 | ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'"); |
373 | ||
d9c85e0f AD |
374 | if ($this->dbh->num_rows($result) == 1) |
375 | $owner_id = $this->dbh->fetch_result($result, 0, "owner_uid"); | |
5f0a3741 AD |
376 | } |
377 | ||
378 | if ($owner_id) { | |
2fb947eb | 379 | $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit, |
25051fb8 | 380 | $offset, $search, $search_mode, $view_mode, $format, $order); |
5f0a3741 AD |
381 | } else { |
382 | header('HTTP/1.1 403 Forbidden'); | |
383 | } | |
384 | } | |
385 | ||
07391e36 AD |
386 | function globalUpdateFeeds() { |
387 | include "rssfuncs.php"; | |
5f0a3741 | 388 | // Update all feeds needing a update. |
a42c55f0 | 389 | update_daemon_common(0, true, false); |
e2cf81e2 | 390 | housekeeping_common(false); |
cda55d67 | 391 | |
1ffe3391 | 392 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", $op); |
cda55d67 | 393 | |
07391e36 | 394 | } |
8361e724 AD |
395 | |
396 | function sharepopup() { | |
61a748f8 | 397 | if (SINGLE_USER_MODE) { |
6322ac79 | 398 | login_sequence(); |
61a748f8 AD |
399 | } |
400 | ||
8361e724 | 401 | header('Content-Type: text/html; charset=utf-8'); |
9a2aed91 AD |
402 | print "<html><head><title>Tiny Tiny RSS</title>"; |
403 | ||
5bbc4bb4 | 404 | stylesheet_tag("css/utility.css"); |
6f7798b6 RL |
405 | javascript_tag("lib/prototype.js"); |
406 | javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,dragdrop,controls"); | |
9a2aed91 AD |
407 | print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/> |
408 | </head><body id='sharepopup'>"; | |
8361e724 AD |
409 | |
410 | $action = $_REQUEST["action"]; | |
411 | ||
412 | if ($_SESSION["uid"]) { | |
413 | ||
d493aba2 | 414 | if ($action == 'share') { |
8361e724 | 415 | |
d9c85e0f AD |
416 | $title = $this->dbh->escape_string(strip_tags($_REQUEST["title"])); |
417 | $url = $this->dbh->escape_string(strip_tags($_REQUEST["url"])); | |
418 | $content = $this->dbh->escape_string(strip_tags($_REQUEST["content"])); | |
419 | $labels = $this->dbh->escape_string(strip_tags($_REQUEST["labels"])); | |
8361e724 | 420 | |
a42c55f0 | 421 | Article::create_published_article($title, $url, $content, $labels, |
1b4d1a6b | 422 | $_SESSION["uid"]); |
8361e724 | 423 | |
d493aba2 AD |
424 | print "<script type='text/javascript'>"; |
425 | print "window.close();"; | |
426 | print "</script>"; | |
8361e724 | 427 | |
d493aba2 | 428 | } else { |
8361e724 AD |
429 | $title = htmlspecialchars($_REQUEST["title"]); |
430 | $url = htmlspecialchars($_REQUEST["url"]); | |
431 | ||
d493aba2 | 432 | ?> |
8361e724 | 433 | |
d493aba2 AD |
434 | <table height='100%' width='100%'><tr><td colspan='2'> |
435 | <h1><?php echo __("Share with Tiny Tiny RSS") ?></h1> | |
436 | </td></tr> | |
8361e724 | 437 | |
d493aba2 | 438 | <form id='share_form' name='share_form'> |
8361e724 | 439 | |
d493aba2 AD |
440 | <input type="hidden" name="op" value="sharepopup"> |
441 | <input type="hidden" name="action" value="share"> | |
8361e724 | 442 | |
22439dad | 443 | <tr><td align='right'><?php echo __("Title:") ?></td> |
d493aba2 | 444 | <td width='80%'><input name='title' value="<?php echo $title ?>"></td></tr> |
22439dad | 445 | <tr><td align='right'><?php echo __("URL:") ?></td> |
d493aba2 | 446 | <td><input name='url' value="<?php echo $url ?>"></td></tr> |
22439dad | 447 | <tr><td align='right'><?php echo __("Content:") ?></td> |
d493aba2 | 448 | <td><input name='content' value=""></td></tr> |
1b4d1a6b AD |
449 | <tr><td align='right'><?php echo __("Labels:") ?></td> |
450 | <td><input name='labels' id="labels_value" | |
451 | placeholder='Alpha, Beta, Gamma' value=""> | |
452 | </td></tr> | |
453 | ||
454 | <tr><td> | |
455 | <div class="autocomplete" id="labels_choices" | |
456 | style="display : block"></div></td></tr> | |
8361e724 | 457 | |
d493aba2 | 458 | <script type='text/javascript'>document.forms[0].title.focus();</script> |
8361e724 | 459 | |
1b4d1a6b AD |
460 | <script type='text/javascript'> |
461 | new Ajax.Autocompleter('labels_value', 'labels_choices', | |
462 | "backend.php?op=rpc&method=completeLabels", | |
463 | { tokens: ',', paramName: "search" }); | |
464 | </script> | |
465 | ||
d493aba2 AD |
466 | <tr><td colspan='2'> |
467 | <div style='float : right' class='insensitive-small'> | |
468 | <?php echo __("Shared article will appear in the Published feed.") ?> | |
469 | </div> | |
470 | <button type="submit"><?php echo __('Share') ?></button> | |
471 | <button onclick="return window.close()"><?php echo __('Cancel') ?></button> | |
472 | </div> | |
8361e724 | 473 | |
d493aba2 AD |
474 | </form> |
475 | </td></tr></table> | |
476 | </body></html> | |
477 | <?php | |
8361e724 | 478 | |
8361e724 AD |
479 | } |
480 | ||
481 | } else { | |
482 | ||
d493aba2 AD |
483 | $return = urlencode($_SERVER["REQUEST_URI"]) |
484 | ?> | |
485 | ||
486 | <form action="public.php?return=<?php echo $return ?>" | |
22439dad | 487 | method="POST" id="loginForm" name="loginForm"> |
d493aba2 AD |
488 | |
489 | <input type="hidden" name="op" value="login"> | |
490 | ||
491 | <table height='100%' width='100%'><tr><td colspan='2'> | |
22439dad | 492 | <h1><?php echo __("Not logged in") ?></h1></td></tr> |
d493aba2 AD |
493 | |
494 | <tr><td align="right"><?php echo __("Login:") ?></td> | |
495 | <td align="right"><input name="login" | |
496 | value="<?php echo $_SESSION["fake_login"] ?>"></td></tr> | |
497 | <tr><td align="right"><?php echo __("Password:") ?></td> | |
498 | <td align="right"><input type="password" name="password" | |
499 | value="<?php echo $_SESSION["fake_password"] ?>"></td></tr> | |
d493aba2 AD |
500 | <tr><td colspan='2'> |
501 | <button type="submit"> | |
502 | <?php echo __('Log in') ?></button> | |
503 | ||
504 | <button onclick="return window.close()"> | |
505 | <?php echo __('Cancel') ?></button> | |
506 | </td></tr> | |
507 | </table> | |
508 | ||
509 | </form> | |
510 | <?php | |
8361e724 AD |
511 | } |
512 | } | |
513 | ||
97acbaf1 | 514 | function login() { |
97acbaf1 AD |
515 | if (!SINGLE_USER_MODE) { |
516 | ||
d9c85e0f | 517 | $login = $this->dbh->escape_string($_POST["login"]); |
97acbaf1 | 518 | $password = $_POST["password"]; |
aadd636a | 519 | $remember_me = $_POST["remember_me"]; |
97acbaf1 | 520 | |
f231f438 AD |
521 | if ($remember_me) { |
522 | session_set_cookie_params(SESSION_COOKIE_LIFETIME); | |
523 | } else { | |
524 | session_set_cookie_params(0); | |
525 | } | |
526 | ||
aadd636a | 527 | @session_start(); |
60ed4c9a | 528 | |
a42c55f0 | 529 | if (authenticate_user($login, $password)) { |
97acbaf1 AD |
530 | $_POST["password"] = ""; |
531 | ||
b18d109f AD |
532 | if (get_schema_version() >= 120) { |
533 | $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]); | |
534 | } | |
535 | ||
a42c55f0 | 536 | $_SESSION["ref_schema_version"] = get_schema_version(true); |
97acbaf1 AD |
537 | $_SESSION["bw_limit"] = !!$_POST["bw_limit"]; |
538 | ||
539 | if ($_POST["profile"]) { | |
540 | ||
d9c85e0f | 541 | $profile = $this->dbh->escape_string($_POST["profile"]); |
97acbaf1 | 542 | |
d9c85e0f | 543 | $result = $this->dbh->query("SELECT id FROM ttrss_settings_profiles |
97acbaf1 AD |
544 | WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]); |
545 | ||
d9c85e0f | 546 | if ($this->dbh->num_rows($result) != 0) { |
97acbaf1 | 547 | $_SESSION["profile"] = $profile; |
97acbaf1 AD |
548 | } |
549 | } | |
550 | } else { | |
551 | $_SESSION["login_error_msg"] = __("Incorrect username or password"); | |
552 | } | |
553 | ||
554 | if ($_REQUEST['return']) { | |
555 | header("Location: " . $_REQUEST['return']); | |
556 | } else { | |
557 | header("Location: " . SELF_URL_PATH); | |
558 | } | |
559 | } | |
560 | } | |
561 | ||
562 | function subscribe() { | |
61a748f8 | 563 | if (SINGLE_USER_MODE) { |
6322ac79 | 564 | login_sequence(); |
61a748f8 AD |
565 | } |
566 | ||
97acbaf1 AD |
567 | if ($_SESSION["uid"]) { |
568 | ||
d9c85e0f | 569 | $feed_url = $this->dbh->escape_string(trim($_REQUEST["feed_url"])); |
97acbaf1 AD |
570 | |
571 | header('Content-Type: text/html; charset=utf-8'); | |
572 | print "<html> | |
573 | <head> | |
574 | <title>Tiny Tiny RSS</title> | |
5bbc4bb4 | 575 | <link rel=\"stylesheet\" type=\"text/css\" href=\"css/utility.css\"> |
97acbaf1 AD |
576 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/> |
577 | </head> | |
578 | <body> | |
884d1650 | 579 | <img class=\"floatingLogo\" src=\"images/logo_small.png\" |
97acbaf1 | 580 | alt=\"Tiny Tiny RSS\"/> |
884d1650 | 581 | <h1>".__("Subscribe to feed...")."</h1><div class='content'>"; |
97acbaf1 | 582 | |
a42c55f0 | 583 | $rc = subscribe_to_feed($feed_url); |
97acbaf1 AD |
584 | |
585 | switch ($rc['code']) { | |
586 | case 0: | |
587 | print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url)); | |
588 | break; | |
589 | case 1: | |
590 | print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url)); | |
591 | break; | |
592 | case 2: | |
593 | print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url)); | |
594 | break; | |
595 | case 3: | |
596 | print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url)); | |
597 | break; | |
598 | case 4: | |
599 | print_notice(__("Multiple feed URLs found.")); | |
759e5132 | 600 | $feed_urls = $rc["feeds"]; |
97acbaf1 AD |
601 | break; |
602 | case 5: | |
603 | print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url)); | |
604 | break; | |
605 | } | |
606 | ||
607 | if ($feed_urls) { | |
608 | ||
609 | print "<form action=\"public.php\">"; | |
610 | print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">"; | |
611 | ||
612 | print "<select name=\"feed_url\">"; | |
613 | ||
614 | foreach ($feed_urls as $url => $name) { | |
615 | $url = htmlspecialchars($url); | |
616 | $name = htmlspecialchars($name); | |
617 | ||
618 | print "<option value=\"$url\">$name</option>"; | |
619 | } | |
620 | ||
621 | print "<input type=\"submit\" value=\"".__("Subscribe to selected feed"). | |
622 | "\">"; | |
623 | ||
624 | print "</form>"; | |
625 | } | |
626 | ||
627 | $tp_uri = get_self_url_prefix() . "/prefs.php"; | |
628 | $tt_uri = get_self_url_prefix(); | |
629 | ||
630 | if ($rc['code'] <= 2){ | |
d9c85e0f | 631 | $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE |
97acbaf1 AD |
632 | feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); |
633 | ||
d9c85e0f | 634 | $feed_id = $this->dbh->fetch_result($result, 0, "id"); |
97acbaf1 AD |
635 | } else { |
636 | $feed_id = 0; | |
637 | } | |
638 | print "<p>"; | |
639 | ||
640 | if ($feed_id) { | |
641 | print "<form method=\"GET\" style='display: inline' | |
642 | action=\"$tp_uri\"> | |
643 | <input type=\"hidden\" name=\"tab\" value=\"feedConfig\"> | |
644 | <input type=\"hidden\" name=\"method\" value=\"editFeed\"> | |
645 | <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\"> | |
646 | <input type=\"submit\" value=\"".__("Edit subscription options")."\"> | |
647 | </form>"; | |
648 | } | |
649 | ||
650 | print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\"> | |
651 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
652 | </form></p>"; | |
653 | ||
884d1650 | 654 | print "</div></body></html>"; |
97acbaf1 AD |
655 | |
656 | } else { | |
6322ac79 | 657 | render_login_form(); |
97acbaf1 AD |
658 | } |
659 | } | |
660 | ||
661 | function subscribe2() { | |
d9c85e0f AD |
662 | $feed_url = $this->dbh->escape_string(trim($_REQUEST["feed_url"])); |
663 | $cat_id = $this->dbh->escape_string($_REQUEST["cat_id"]); | |
664 | $from = $this->dbh->escape_string($_REQUEST["from"]); | |
6f7798b6 | 665 | $feed_urls = array(); |
97acbaf1 AD |
666 | |
667 | /* only read authentication information from POST */ | |
668 | ||
d9c85e0f AD |
669 | $auth_login = $this->dbh->escape_string(trim($_POST["auth_login"])); |
670 | $auth_pass = $this->dbh->escape_string(trim($_POST["auth_pass"])); | |
97acbaf1 | 671 | |
a42c55f0 | 672 | $rc = subscribe_to_feed($feed_url, $cat_id, $auth_login, $auth_pass); |
97acbaf1 AD |
673 | |
674 | switch ($rc) { | |
675 | case 1: | |
676 | print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url)); | |
677 | break; | |
678 | case 2: | |
679 | print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url)); | |
680 | break; | |
681 | case 3: | |
682 | print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url)); | |
683 | break; | |
684 | case 0: | |
685 | print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url)); | |
686 | break; | |
687 | case 4: | |
688 | print_notice(__("Multiple feed URLs found.")); | |
6f7798b6 RL |
689 | $contents = @fetch_file_contents($url, false, $auth_login, $auth_pass); |
690 | if (is_html($contents)) { | |
691 | $feed_urls = get_feeds_from_html($url, $contents); | |
692 | } | |
97acbaf1 AD |
693 | break; |
694 | case 5: | |
695 | print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url)); | |
696 | break; | |
697 | } | |
698 | ||
699 | if ($feed_urls) { | |
700 | print "<form action=\"backend.php\">"; | |
701 | print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">"; | |
702 | print "<input type=\"hidden\" name=\"quiet\" value=\"1\">"; | |
703 | print "<input type=\"hidden\" name=\"method\" value=\"add\">"; | |
704 | ||
705 | print "<select name=\"feed_url\">"; | |
706 | ||
707 | foreach ($feed_urls as $url => $name) { | |
708 | $url = htmlspecialchars($url); | |
709 | $name = htmlspecialchars($name); | |
710 | print "<option value=\"$url\">$name</option>"; | |
711 | } | |
712 | ||
713 | print "<input type=\"submit\" value=\"".__("Subscribe to selected feed")."\">"; | |
714 | print "</form>"; | |
715 | } | |
716 | ||
717 | $tp_uri = get_self_url_prefix() . "/prefs.php"; | |
718 | $tt_uri = get_self_url_prefix(); | |
719 | ||
720 | if ($rc <= 2){ | |
d9c85e0f | 721 | $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE |
97acbaf1 AD |
722 | feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); |
723 | ||
d9c85e0f | 724 | $feed_id = $this->dbh->fetch_result($result, 0, "id"); |
97acbaf1 AD |
725 | } else { |
726 | $feed_id = 0; | |
727 | } | |
728 | ||
729 | print "<p>"; | |
730 | ||
731 | if ($feed_id) { | |
732 | print "<form method=\"GET\" style='display: inline' | |
733 | action=\"$tp_uri\"> | |
734 | <input type=\"hidden\" name=\"tab\" value=\"feedConfig\"> | |
735 | <input type=\"hidden\" name=\"method\" value=\"editFeed\"> | |
736 | <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\"> | |
737 | <input type=\"submit\" value=\"".__("Edit subscription options")."\"> | |
738 | </form>"; | |
739 | } | |
740 | ||
741 | print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\"> | |
742 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
743 | </form></p>"; | |
744 | ||
745 | print "</body></html>"; | |
746 | } | |
747 | ||
748 | function index() { | |
749 | header("Content-Type: text/plain"); | |
750 | print json_encode(array("error" => array("code" => 7))); | |
751 | } | |
752 | ||
f43e9e97 | 753 | function forgotpass() { |
67e0cf9a AD |
754 | startup_gettext(); |
755 | ||
f43e9e97 | 756 | header('Content-Type: text/html; charset=utf-8'); |
e216d302 AD |
757 | print "<html><head><title>Tiny Tiny RSS</title>"; |
758 | ||
5bbc4bb4 | 759 | stylesheet_tag("css/utility.css"); |
6f7798b6 | 760 | javascript_tag("lib/prototype.js"); |
e216d302 AD |
761 | |
762 | print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/> | |
763 | </head><body id='forgotpass'>"; | |
f43e9e97 | 764 | |
884d1650 | 765 | print '<div class="floatingLogo"><img src="images/logo_small.png"></div>'; |
483f15d5 | 766 | print "<h1>".__("Password recovery")."</h1>"; |
884d1650 | 767 | print "<div class='content'>"; |
f43e9e97 AD |
768 | |
769 | @$method = $_POST['method']; | |
770 | ||
771 | if (!$method) { | |
483f15d5 AD |
772 | print_notice(__("You will need to provide valid account name and email. New password will be sent on your email address.")); |
773 | ||
f43e9e97 | 774 | print "<form method='POST' action='public.php'>"; |
f43e9e97 AD |
775 | print "<input type='hidden' name='method' value='do'>"; |
776 | print "<input type='hidden' name='op' value='forgotpass'>"; | |
777 | ||
778 | print "<fieldset>"; | |
779 | print "<label>".__("Login:")."</label>"; | |
780 | print "<input type='text' name='login' value='' required>"; | |
781 | print "</fieldset>"; | |
782 | ||
783 | print "<fieldset>"; | |
784 | print "<label>".__("Email:")."</label>"; | |
785 | print "<input type='email' name='email' value='' required>"; | |
786 | print "</fieldset>"; | |
787 | ||
788 | print "<fieldset>"; | |
789 | print "<label>".__("How much is two plus two:")."</label>"; | |
790 | print "<input type='text' name='test' value='' required>"; | |
791 | print "</fieldset>"; | |
792 | ||
793 | print "<p/>"; | |
794 | print "<button type='submit'>".__("Reset password")."</button>"; | |
795 | ||
796 | print "</form>"; | |
797 | } else if ($method == 'do') { | |
798 | ||
d9c85e0f AD |
799 | $login = $this->dbh->escape_string($_POST["login"]); |
800 | $email = $this->dbh->escape_string($_POST["email"]); | |
801 | $test = $this->dbh->escape_string($_POST["test"]); | |
f43e9e97 AD |
802 | |
803 | if (($test != 4 && $test != 'four') || !$email || !$login) { | |
804 | print_error(__('Some of the required form parameters are missing or incorrect.')); | |
805 | ||
483f15d5 AD |
806 | print "<form method=\"GET\" action=\"public.php\"> |
807 | <input type=\"hidden\" name=\"op\" value=\"forgotpass\"> | |
808 | <input type=\"submit\" value=\"".__("Go back")."\"> | |
809 | </form>"; | |
f43e9e97 | 810 | |
e216d302 | 811 | } else { |
f43e9e97 | 812 | |
d9c85e0f | 813 | $result = $this->dbh->query("SELECT id FROM ttrss_users |
f43e9e97 AD |
814 | WHERE login = '$login' AND email = '$email'"); |
815 | ||
d9c85e0f AD |
816 | if ($this->dbh->num_rows($result) != 0) { |
817 | $id = $this->dbh->fetch_result($result, 0, "id"); | |
f43e9e97 | 818 | |
a42c55f0 | 819 | Pref_Users::resetUserPassword($id, false); |
f43e9e97 | 820 | |
483f15d5 AD |
821 | print "<p>"; |
822 | ||
e216d302 | 823 | print "<p>"."Completed."."</p>"; |
483f15d5 AD |
824 | |
825 | print "<form method=\"GET\" action=\"index.php\"> | |
826 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
827 | </form>"; | |
f43e9e97 AD |
828 | |
829 | } else { | |
830 | print_error(__("Sorry, login and email combination not found.")); | |
483f15d5 AD |
831 | |
832 | print "<form method=\"GET\" action=\"public.php\"> | |
833 | <input type=\"hidden\" name=\"op\" value=\"forgotpass\"> | |
834 | <input type=\"submit\" value=\"".__("Go back")."\"> | |
835 | </form>"; | |
836 | ||
f43e9e97 | 837 | } |
f43e9e97 AD |
838 | } |
839 | ||
840 | } | |
841 | ||
884d1650 | 842 | print "</div>"; |
f43e9e97 AD |
843 | print "</body>"; |
844 | print "</html>"; | |
845 | ||
b4c47f7e AD |
846 | } |
847 | ||
848 | function dbupdate() { | |
67e0cf9a AD |
849 | startup_gettext(); |
850 | ||
f240d26e AD |
851 | if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) { |
852 | $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script."); | |
6322ac79 | 853 | render_login_form(); |
f240d26e AD |
854 | exit; |
855 | } | |
856 | ||
857 | ?><html> | |
858 | <head> | |
859 | <title>Database Updater</title> | |
860 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | |
5bbc4bb4 | 861 | <link rel="stylesheet" type="text/css" href="css/utility.css"/> |
f240d26e AD |
862 | </head> |
863 | <style type="text/css"> | |
864 | span.ok { color : #009000; font-weight : bold; } | |
865 | span.err { color : #ff0000; font-weight : bold; } | |
866 | </style> | |
867 | <body> | |
868 | <script type='text/javascript'> | |
869 | function confirmOP() { | |
870 | return confirm("Update the database?"); | |
871 | } | |
872 | </script> | |
873 | ||
874 | <div class="floatingLogo"><img src="images/logo_small.png"></div> | |
875 | ||
876 | <h1><?php echo __("Database Updater") ?></h1> | |
877 | ||
878 | <div class="content"> | |
879 | ||
880 | <?php | |
881 | @$op = $_REQUEST["subop"]; | |
0630a100 | 882 | $updater = new DbUpdater(Db::get(), DB_TYPE, SCHEMA_VERSION); |
f240d26e AD |
883 | |
884 | if ($op == "performupdate") { | |
885 | if ($updater->isUpdateRequired()) { | |
886 | ||
887 | print "<h2>Performing updates</h2>"; | |
888 | ||
889 | print "<h3>Updating to schema version " . SCHEMA_VERSION . "</h3>"; | |
890 | ||
891 | print "<ul>"; | |
892 | ||
893 | for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) { | |
894 | print "<li>Performing update up to version $i..."; | |
895 | ||
896 | $result = $updater->performUpdateTo($i); | |
897 | ||
898 | if (!$result) { | |
899 | print "<span class='err'>FAILED!</span></li></ul>"; | |
900 | ||
901 | print_warning("One of the updates failed. Either retry the process or perform updates manually."); | |
902 | print "<p><form method=\"GET\" action=\"index.php\"> | |
903 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
904 | </form>"; | |
905 | ||
906 | break; | |
907 | } else { | |
908 | print "<span class='ok'>OK!</span></li>"; | |
909 | } | |
910 | } | |
911 | ||
912 | print "</ul>"; | |
b4c47f7e | 913 | |
f240d26e | 914 | print_notice("Your Tiny Tiny RSS database is now updated to the latest version."); |
b4c47f7e | 915 | |
f240d26e AD |
916 | print "<p><form method=\"GET\" action=\"index.php\"> |
917 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
918 | </form>"; | |
919 | ||
920 | } else { | |
921 | print "<h2>Your database is up to date.</h2>"; | |
922 | ||
923 | print "<p><form method=\"GET\" action=\"index.php\"> | |
924 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
925 | </form>"; | |
926 | } | |
927 | } else { | |
928 | if ($updater->isUpdateRequired()) { | |
929 | ||
930 | print "<h2>Database update required</h2>"; | |
b4c47f7e | 931 | |
f240d26e AD |
932 | print "<h3>"; |
933 | printf("Your Tiny Tiny RSS database needs update to the latest version: %d to %d.", | |
934 | $updater->getSchemaVersion(), SCHEMA_VERSION); | |
935 | print "</h3>"; | |
b4c47f7e | 936 | |
f240d26e | 937 | print_warning("Please backup your database before proceeding."); |
b4c47f7e | 938 | |
f240d26e AD |
939 | print "<form method='POST'> |
940 | <input type='hidden' name='subop' value='performupdate'> | |
941 | <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'> | |
942 | </form>"; | |
943 | ||
944 | } else { | |
945 | ||
3c200461 | 946 | print_notice("Tiny Tiny RSS database is up to date."); |
f240d26e AD |
947 | |
948 | print "<p><form method=\"GET\" action=\"index.php\"> | |
949 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
950 | </form>"; | |
951 | ||
952 | } | |
953 | } | |
954 | ?> | |
b4c47f7e | 955 | |
f240d26e AD |
956 | </div> |
957 | </body> | |
958 | </html> | |
959 | <?php | |
f43e9e97 AD |
960 | } |
961 | ||
5f0a3741 AD |
962 | } |
963 | ?> |