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