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