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