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