3 - Automatically detect if incoming data is HTML or BBCode
5 require_once("include/bbcode.php");
6 require_once("include/datetime.php");
7 require_once("include/conversation.php");
8 require_once("include/oauth.php");
9 require_once("include/html2plain.php");
19 // It is not sufficient to use local_user() to check whether someone is allowed to use the API,
20 // because this will open CSRF holes (just embed an image with src=friendicasite.com/api/statuses/update?status=CSRF
21 // into a page, and visitors will post something without noticing it).
22 // Instead, use this function.
23 if ($_SESSION["allow_api"])
29 function api_source() {
30 if (requestdata('source'))
31 return (requestdata('source'));
33 // Support for known clients that doesn't send a source name
34 if (strstr($_SERVER['HTTP_USER_AGENT'], "Twidere"))
37 logger("Unrecognized user-agent ".$_SERVER['HTTP_USER_AGENT'], LOGGER_DEBUG);
42 function api_date($str){
43 //Wed May 23 06:01:13 +0000 2007
44 return datetime_convert('UTC', 'UTC', $str, "D M d H:i:s +0000 Y" );
48 function api_register_func($path, $func, $auth=false){
50 $API[$path] = array('func'=>$func, 'auth'=>$auth);
52 // Workaround for hotot
53 $path = str_replace("api/", "api/1.1/", $path);
54 $API[$path] = array('func'=>$func, 'auth'=>$auth);
61 function api_login(&$a){
64 $oauth = new FKOAuth1();
65 list($consumer,$token) = $oauth->verify_request(OAuthRequest::from_request());
66 if (!is_null($token)){
67 $oauth->loginUser($token->uid);
68 call_hooks('logged_in', $a->user);
71 echo __file__.__line__.__function__."<pre>"; var_dump($consumer, $token); die();
73 logger(__file__.__line__.__function__."\n".$e);
74 //die(__file__.__line__.__function__."<pre>".$e); die();
79 // workaround for HTTP-auth in CGI mode
80 if(x($_SERVER,'REDIRECT_REMOTE_USER')) {
81 $userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"],6)) ;
82 if(strlen($userpass)) {
83 list($name, $password) = explode(':', $userpass);
84 $_SERVER['PHP_AUTH_USER'] = $name;
85 $_SERVER['PHP_AUTH_PW'] = $password;
89 if (!isset($_SERVER['PHP_AUTH_USER'])) {
90 logger('API_login: ' . print_r($_SERVER,true), LOGGER_DEBUG);
91 header('WWW-Authenticate: Basic realm="Friendica"');
92 header('HTTP/1.0 401 Unauthorized');
93 die((api_error($a, 'json', "This api requires login")));
95 //die('This api requires login');
98 $user = $_SERVER['PHP_AUTH_USER'];
99 $password = $_SERVER['PHP_AUTH_PW'];
100 $encrypted = hash('whirlpool',trim($password));
104 * next code from mod/auth.php. needs better solution
109 'username' => trim($user),
110 'password' => trim($password),
111 'authenticated' => 0,
112 'user_record' => null
117 * A plugin indicates successful login by setting 'authenticated' to non-zero value and returning a user record
118 * Plugins should never set 'authenticated' except to indicate success - as hooks may be chained
119 * and later plugins should not interfere with an earlier one that succeeded.
123 call_hooks('authenticate', $addon_auth);
125 if(($addon_auth['authenticated']) && (count($addon_auth['user_record']))) {
126 $record = $addon_auth['user_record'];
129 // process normal login request
131 $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' )
132 AND `password` = '%s' AND `blocked` = 0 AND `account_expired` = 0 AND `account_removed` = 0 AND `verified` = 1 LIMIT 1",
141 if((! $record) || (! count($record))) {
142 logger('API_login failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
143 header('WWW-Authenticate: Basic realm="Friendica"');
144 header('HTTP/1.0 401 Unauthorized');
145 die('This api requires login');
148 require_once('include/security.php');
149 authenticate_success($record); $_SESSION["allow_api"] = true;
151 call_hooks('logged_in', $a->user);
155 /**************************
156 * MAIN API ENTRY POINT *
157 **************************/
158 function api_call(&$a){
159 GLOBAL $API, $called_api;
163 foreach ($API as $p=>$info){
164 if (strpos($a->query_string, $p)===0){
165 $called_api= explode("/",$p);
166 //unset($_SERVER['PHP_AUTH_USER']);
167 if ($info['auth']===true && api_user()===false) {
171 load_contact_links(api_user());
173 logger('API call for ' . $a->user['username'] . ': ' . $a->query_string);
174 logger('API parameters: ' . print_r($_REQUEST,true));
176 if (strpos($a->query_string, ".xml")>0) $type="xml";
177 if (strpos($a->query_string, ".json")>0) $type="json";
178 if (strpos($a->query_string, ".rss")>0) $type="rss";
179 if (strpos($a->query_string, ".atom")>0) $type="atom";
180 if (strpos($a->query_string, ".as")>0) $type="as";
182 $r = call_user_func($info['func'], $a, $type);
183 if ($r===false) return;
187 $r = mb_convert_encoding($r, "UTF-8",mb_detect_encoding($r));
188 header ("Content-Type: text/xml");
189 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
192 header ("Content-Type: application/json");
194 $json = json_encode($rr);
195 if ($_GET['callback'])
196 $json = $_GET['callback']."(".$json.")";
200 header ("Content-Type: application/rss+xml");
201 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
204 header ("Content-Type: application/atom+xml");
205 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
208 //header ("Content-Type: application/json");
210 // return json_encode($rr);
211 return json_encode($r);
215 //echo "<pre>"; var_dump($r); die();
218 header("HTTP/1.1 404 Not Found");
219 logger('API call not implemented: '.$a->query_string." - ".print_r($_REQUEST,true));
220 return(api_error($a, $type, "not implemented"));
224 function api_error(&$a, $type, $error) {
225 # TODO: https://dev.twitter.com/overview/api/response-codes
226 $r = "<status><error>".$error."</error><request>".$a->query_string."</request></status>";
229 header ("Content-Type: text/xml");
230 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
233 header ("Content-Type: application/json");
234 return json_encode(array('error' => $error, 'request' => $a->query_string));
237 header ("Content-Type: application/rss+xml");
238 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
241 header ("Content-Type: application/atom+xml");
242 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
250 function api_rss_extra(&$a, $arr, $user_info){
251 if (is_null($user_info)) $user_info = api_get_user($a);
252 $arr['$user'] = $user_info;
253 $arr['$rss'] = array(
254 'alternate' => $user_info['url'],
255 'self' => $a->get_baseurl(). "/". $a->query_string,
256 'base' => $a->get_baseurl(),
257 'updated' => api_date(null),
258 'atom_updated' => datetime_convert('UTC','UTC','now',ATOM_TIME),
259 'language' => $user_info['language'],
260 'logo' => $a->get_baseurl()."/images/friendica-32.png",
268 * Unique contact to contact url.
270 function api_unique_id_to_url($id){
271 $r = q("SELECT url FROM unique_contacts WHERE id=%d LIMIT 1",
274 return ($r[0]["url"]);
280 * Returns user info array.
282 function api_get_user(&$a, $contact_id = Null, $type = "json"){
289 logger("api_get_user: Fetching user data for user ".$contact_id, LOGGER_DEBUG);
291 // Searching for contact URL
292 if(!is_null($contact_id) AND (intval($contact_id) == 0)){
293 $user = dbesc(normalise_link($contact_id));
295 $extra_query = "AND `contact`.`nurl` = '%s' ";
296 if (api_user()!==false) $extra_query .= "AND `contact`.`uid`=".intval(api_user());
299 // Searching for unique contact id
300 if(!is_null($contact_id) AND (intval($contact_id) != 0)){
301 $user = dbesc(api_unique_id_to_url($contact_id));
304 die(api_error($a, $type, t("User not found.")));
307 $extra_query = "AND `contact`.`nurl` = '%s' ";
308 if (api_user()!==false) $extra_query .= "AND `contact`.`uid`=".intval(api_user());
311 if(is_null($user) && x($_GET, 'user_id')) {
312 $user = dbesc(api_unique_id_to_url($_GET['user_id']));
315 die(api_error($a, $type, t("User not found.")));
318 $extra_query = "AND `contact`.`nurl` = '%s' ";
319 if (api_user()!==false) $extra_query .= "AND `contact`.`uid`=".intval(api_user());
321 if(is_null($user) && x($_GET, 'screen_name')) {
322 $user = dbesc($_GET['screen_name']);
324 $extra_query = "AND `contact`.`nick` = '%s' ";
325 if (api_user()!==false) $extra_query .= "AND `contact`.`uid`=".intval(api_user());
328 if (is_null($user) AND ($a->argc > (count($called_api)-1)) AND (count($called_api) > 0)){
329 $argid = count($called_api);
330 list($user, $null) = explode(".",$a->argv[$argid]);
331 if(is_numeric($user)){
332 $user = dbesc(api_unique_id_to_url($user));
338 $extra_query = "AND `contact`.`nurl` = '%s' ";
339 if (api_user()!==false) $extra_query .= "AND `contact`.`uid`=".intval(api_user());
341 $user = dbesc($user);
343 $extra_query = "AND `contact`.`nick` = '%s' ";
344 if (api_user()!==false) $extra_query .= "AND `contact`.`uid`=".intval(api_user());
348 logger("api_get_user: user ".$user, LOGGER_DEBUG);
351 if (api_user()===false) {
352 api_login($a); return False;
354 $user = $_SESSION['uid'];
355 $extra_query = "AND `contact`.`uid` = %d AND `contact`.`self` = 1 ";
360 logger('api_user: ' . $extra_query . ', user: ' . $user);
362 $uinfo = q("SELECT *, `contact`.`id` as `cid` FROM `contact`
368 // Selecting the id by priority, friendica first
369 api_best_nickname($uinfo);
371 // if the contact wasn't found, fetch it from the unique contacts
372 if (count($uinfo)==0) {
376 $r = q("SELECT * FROM unique_contacts WHERE url='%s' LIMIT 1", $url);
378 $r = q("SELECT * FROM unique_contacts WHERE nick='%s' LIMIT 1", $nick);
381 // If no nick where given, extract it from the address
382 if (($r[0]['nick'] == "") OR ($r[0]['name'] == $r[0]['nick']))
383 $r[0]['nick'] = api_get_nick($r[0]["url"]);
387 'id_str' => (string) $r[0]["id"],
388 'name' => $r[0]["name"],
389 'screen_name' => (($r[0]['nick']) ? $r[0]['nick'] : $r[0]['name']),
391 'description' => NULL,
392 'profile_image_url' => $r[0]["avatar"],
393 'profile_image_url_https' => $r[0]["avatar"],
394 'url' => $r[0]["url"],
395 'protected' => false,
396 'followers_count' => 0,
397 'friends_count' => 0,
398 'created_at' => api_date(0),
399 'favourites_count' => 0,
401 'time_zone' => 'UTC',
402 'statuses_count' => 0,
403 'following' => false,
405 'statusnet_blocking' => false,
406 'notifications' => false,
407 'statusnet_profile_url' => $r[0]["url"],
416 die(api_error($a, $type, t("User not found.")));
420 if($uinfo[0]['self']) {
421 $usr = q("select * from user where uid = %d limit 1",
424 $profile = q("select * from profile where uid = %d and `is-default` = 1 limit 1",
428 //AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
429 // count public wall messages
430 $r = q("SELECT count(*) as `count` FROM `item`
433 intval($uinfo[0]['uid'])
435 $countitms = $r[0]['count'];
438 //AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
439 $r = q("SELECT count(*) as `count` FROM `item`
440 WHERE `contact-id` = %d",
441 intval($uinfo[0]['id'])
443 $countitms = $r[0]['count'];
447 $r = q("SELECT count(*) as `count` FROM `contact`
448 WHERE `uid` = %d AND `rel` IN ( %d, %d )
449 AND `self`=0 AND `blocked`=0 AND `pending`=0 AND `hidden`=0",
450 intval($uinfo[0]['uid']),
451 intval(CONTACT_IS_SHARING),
452 intval(CONTACT_IS_FRIEND)
454 $countfriends = $r[0]['count'];
456 $r = q("SELECT count(*) as `count` FROM `contact`
457 WHERE `uid` = %d AND `rel` IN ( %d, %d )
458 AND `self`=0 AND `blocked`=0 AND `pending`=0 AND `hidden`=0",
459 intval($uinfo[0]['uid']),
460 intval(CONTACT_IS_FOLLOWER),
461 intval(CONTACT_IS_FRIEND)
463 $countfollowers = $r[0]['count'];
465 $r = q("SELECT count(*) as `count` FROM item where starred = 1 and uid = %d and deleted = 0",
466 intval($uinfo[0]['uid'])
468 $starred = $r[0]['count'];
471 if(! $uinfo[0]['self']) {
477 // Add a nick if it isn't present there
478 if (($uinfo[0]['nick'] == "") OR ($uinfo[0]['name'] == $uinfo[0]['nick'])) {
479 $uinfo[0]['nick'] = api_get_nick($uinfo[0]["url"]);
482 // Fetching unique id
483 $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", dbesc(normalise_link($uinfo[0]['url'])));
485 // If not there, then add it
486 if (count($r) == 0) {
487 q("INSERT INTO unique_contacts (url, name, nick, avatar) VALUES ('%s', '%s', '%s', '%s')",
488 dbesc(normalise_link($uinfo[0]['url'])), dbesc($uinfo[0]['name']),dbesc($uinfo[0]['nick']), dbesc($uinfo[0]['micro']));
490 $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", dbesc(normalise_link($uinfo[0]['url'])));
493 require_once('include/contact_selectors.php');
494 $network_name = network_to_name($uinfo[0]['network']);
497 'id' => intval($r[0]['id']),
498 'id_str' => (string) intval($r[0]['id']),
499 'name' => (($uinfo[0]['name']) ? $uinfo[0]['name'] : $uinfo[0]['nick']),
500 'screen_name' => (($uinfo[0]['nick']) ? $uinfo[0]['nick'] : $uinfo[0]['name']),
501 'location' => ($usr) ? $usr[0]['default-location'] : $network_name,
502 'description' => (($profile) ? $profile[0]['pdesc'] : NULL),
503 'profile_image_url' => $uinfo[0]['micro'],
504 'profile_image_url_https' => $uinfo[0]['micro'],
505 'url' => $uinfo[0]['url'],
506 'protected' => false,
507 'followers_count' => intval($countfollowers),
508 'friends_count' => intval($countfriends),
509 'created_at' => api_date($uinfo[0]['created']),
510 'favourites_count' => intval($starred),
512 'time_zone' => 'UTC',
513 'statuses_count' => intval($countitms),
514 'following' => (($uinfo[0]['rel'] == CONTACT_IS_FOLLOWER) OR ($uinfo[0]['rel'] == CONTACT_IS_FRIEND)),
516 'statusnet_blocking' => false,
517 'notifications' => false,
518 'statusnet_profile_url' => $a->get_baseurl()."/contacts/".$uinfo[0]['cid'],
519 'uid' => intval($uinfo[0]['uid']),
520 'cid' => intval($uinfo[0]['cid']),
521 'self' => $uinfo[0]['self'],
522 'network' => $uinfo[0]['network'],
529 function api_item_get_user(&$a, $item) {
531 $author = q("SELECT * FROM unique_contacts WHERE url='%s' LIMIT 1",
532 dbesc(normalise_link($item['author-link'])));
534 if (count($author) == 0) {
535 q("INSERT INTO unique_contacts (url, name, avatar) VALUES ('%s', '%s', '%s')",
536 dbesc(normalise_link($item["author-link"])), dbesc($item["author-name"]), dbesc($item["author-avatar"]));
538 $author = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1",
539 dbesc(normalise_link($item['author-link'])));
540 } else if ($item["author-link"].$item["author-name"] != $author[0]["url"].$author[0]["name"]) {
541 q("UPDATE unique_contacts SET name = '%s', avatar = '%s' WHERE url = '%s'",
542 dbesc($item["author-name"]), dbesc($item["author-avatar"]), dbesc(normalise_link($item["author-link"])));
545 $owner = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1",
546 dbesc(normalise_link($item['owner-link'])));
548 if (count($owner) == 0) {
549 q("INSERT INTO unique_contacts (url, name, avatar) VALUES ('%s', '%s', '%s')",
550 dbesc(normalise_link($item["owner-link"])), dbesc($item["owner-name"]), dbesc($item["owner-avatar"]));
552 $owner = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1",
553 dbesc(normalise_link($item['owner-link'])));
554 } else if ($item["owner-link"].$item["owner-name"] != $owner[0]["url"].$owner[0]["name"]) {
555 q("UPDATE unique_contacts SET name = '%s', avatar = '%s' WHERE url = '%s'",
556 dbesc($item["owner-name"]), dbesc($item["owner-avatar"]), dbesc(normalise_link($item["owner-link"])));
559 // Comments in threads may appear as wall-to-wall postings.
560 // So only take the owner at the top posting.
561 if ($item["id"] == $item["parent"])
562 $status_user = api_get_user($a,$item["owner-link"]);
564 $status_user = api_get_user($a,$item["author-link"]);
566 $status_user["protected"] = (($item["allow_cid"] != "") OR
567 ($item["allow_gid"] != "") OR
568 ($item["deny_cid"] != "") OR
569 ($item["deny_gid"] != "") OR
572 return ($status_user);
577 * load api $templatename for $type and replace $data array
579 function api_apply_template($templatename, $type, $data){
587 $data = array_xmlify($data);
588 $tpl = get_markup_template("api_".$templatename."_".$type.".tpl");
590 header ("Content-Type: text/xml");
591 echo '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<status><error>not implemented</error></status>';
594 $ret = replace_macros($tpl, $data);
609 * Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful;
610 * returns a 401 status code and an error message if not.
611 * http://developer.twitter.com/doc/get/account/verify_credentials
613 function api_account_verify_credentials(&$a, $type){
614 if (api_user()===false) return false;
616 unset($_REQUEST["user_id"]);
617 unset($_GET["user_id"]);
619 unset($_REQUEST["screen_name"]);
620 unset($_GET["screen_name"]);
622 $skip_status = (x($_REQUEST,'skip_status')?$_REQUEST['skip_status']:false);
624 $user_info = api_get_user($a);
626 // "verified" isn't used here in the standard
627 unset($user_info["verified"]);
629 // - Adding last status
631 $user_info["status"] = api_status_show($a,"raw");
632 if (!count($user_info["status"]))
633 unset($user_info["status"]);
635 unset($user_info["status"]["user"]);
638 // "uid" and "self" are only needed for some internal stuff, so remove it from here
639 unset($user_info["uid"]);
640 unset($user_info["self"]);
642 return api_apply_template("user", $type, array('$user' => $user_info));
645 api_register_func('api/account/verify_credentials','api_account_verify_credentials', true);
649 * get data from $_POST or $_GET
651 function requestdata($k){
652 if (isset($_POST[$k])){
655 if (isset($_GET[$k])){
661 /*Waitman Gobble Mod*/
662 function api_statuses_mediap(&$a, $type) {
663 if (api_user()===false) {
664 logger('api_statuses_update: no user');
667 $user_info = api_get_user($a);
669 $_REQUEST['type'] = 'wall';
670 $_REQUEST['profile_uid'] = api_user();
671 $_REQUEST['api_source'] = true;
672 $txt = requestdata('status');
673 //$txt = urldecode(requestdata('status'));
675 require_once('library/HTMLPurifier.auto.php');
676 require_once('include/html2bbcode.php');
678 if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
679 $txt = html2bb_video($txt);
680 $config = HTMLPurifier_Config::createDefault();
681 $config->set('Cache.DefinitionImpl', null);
682 $purifier = new HTMLPurifier($config);
683 $txt = $purifier->purify($txt);
685 $txt = html2bbcode($txt);
687 $a->argv[1]=$user_info['screen_name']; //should be set to username?
689 $_REQUEST['hush']='yeah'; //tell wall_upload function to return img info instead of echo
690 require_once('mod/wall_upload.php');
691 $bebop = wall_upload_post($a);
693 //now that we have the img url in bbcode we can add it to the status and insert the wall item.
694 $_REQUEST['body']=$txt."\n\n".$bebop;
695 require_once('mod/item.php');
698 // this should output the last post (the one we just posted).
699 return api_status_show($a,$type);
701 api_register_func('api/statuses/mediap','api_statuses_mediap', true);
702 /*Waitman Gobble Mod*/
705 function api_statuses_update(&$a, $type) {
706 if (api_user()===false) {
707 logger('api_statuses_update: no user');
711 $user_info = api_get_user($a);
713 // convert $_POST array items to the form we use for web posts.
715 // logger('api_post: ' . print_r($_POST,true));
717 if(requestdata('htmlstatus')) {
718 require_once('library/HTMLPurifier.auto.php');
719 require_once('include/html2bbcode.php');
721 $txt = requestdata('htmlstatus');
722 if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
724 $txt = html2bb_video($txt);
726 $config = HTMLPurifier_Config::createDefault();
727 $config->set('Cache.DefinitionImpl', null);
730 $purifier = new HTMLPurifier($config);
731 $txt = $purifier->purify($txt);
733 $_REQUEST['body'] = html2bbcode($txt);
738 $_REQUEST['body'] = requestdata('status');
740 $_REQUEST['title'] = requestdata('title');
742 $parent = requestdata('in_reply_to_status_id');
743 if(ctype_digit($parent))
744 $_REQUEST['parent'] = $parent;
746 $_REQUEST['parent_uri'] = $parent;
748 if(requestdata('lat') && requestdata('long'))
749 $_REQUEST['coord'] = sprintf("%s %s",requestdata('lat'),requestdata('long'));
750 $_REQUEST['profile_uid'] = api_user();
753 $_REQUEST['type'] = 'net-comment';
755 // Check for throttling (maximum posts per day, week and month)
756 $throttle_day = get_config('system','throttle_limit_day');
757 if ($throttle_day > 0) {
758 $datefrom = date("Y-m-d H:i:s", time() - 24*60*60);
760 $r = q("SELECT COUNT(*) AS `posts_day` FROM `item` WHERE `uid`=%d AND `wall`
761 AND `created` > '%s' AND `id` = `parent`",
762 intval(api_user()), dbesc($datefrom));
765 $posts_day = $r[0]["posts_day"];
769 if ($posts_day > $throttle_day) {
770 logger('Daily posting limit reached for user '.api_user(), LOGGER_DEBUG);
771 die(api_error($a, $type, sprintf(t("Daily posting limit of %d posts reached. The post was rejected."), $throttle_day)));
775 $throttle_week = get_config('system','throttle_limit_week');
776 if ($throttle_week > 0) {
777 $datefrom = date("Y-m-d H:i:s", time() - 24*60*60*7);
779 $r = q("SELECT COUNT(*) AS `posts_week` FROM `item` WHERE `uid`=%d AND `wall`
780 AND `created` > '%s' AND `id` = `parent`",
781 intval(api_user()), dbesc($datefrom));
784 $posts_week = $r[0]["posts_week"];
788 if ($posts_week > $throttle_week) {
789 logger('Weekly posting limit reached for user '.api_user(), LOGGER_DEBUG);
790 die(api_error($a, $type, sprintf(t("Weekly posting limit of %d posts reached. The post was rejected."), $throttle_week)));
794 $throttle_month = get_config('system','throttle_limit_month');
795 if ($throttle_month > 0) {
796 $datefrom = date("Y-m-d H:i:s", time() - 24*60*60*30);
798 $r = q("SELECT COUNT(*) AS `posts_month` FROM `item` WHERE `uid`=%d AND `wall`
799 AND `created` > '%s' AND `id` = `parent`",
800 intval(api_user()), dbesc($datefrom));
803 $posts_month = $r[0]["posts_month"];
807 if ($posts_month > $throttle_month) {
808 logger('Monthly posting limit reached for user '.api_user(), LOGGER_DEBUG);
809 die(api_error($a, $type, sprintf(t("Monthly posting limit of %d posts reached. The post was rejected."), $throttle_month)));
813 $_REQUEST['type'] = 'wall';
814 if(x($_FILES,'media')) {
815 // upload the image if we have one
816 $_REQUEST['hush']='yeah'; //tell wall_upload function to return img info instead of echo
817 require_once('mod/wall_upload.php');
818 $media = wall_upload_post($a);
820 $_REQUEST['body'] .= "\n\n".$media;
824 // set this so that the item_post() function is quiet and doesn't redirect or emit json
826 $_REQUEST['api_source'] = true;
828 if (!x($_REQUEST, "source"))
829 $_REQUEST["source"] = api_source();
831 // call out normal post function
833 require_once('mod/item.php');
836 // this should output the last post (the one we just posted).
837 return api_status_show($a,$type);
839 api_register_func('api/statuses/update','api_statuses_update', true);
840 api_register_func('api/statuses/update_with_media','api_statuses_update', true);
843 function api_status_show(&$a, $type){
844 $user_info = api_get_user($a);
846 logger('api_status_show: user_info: '.print_r($user_info, true), LOGGER_DEBUG);
848 // get last public wall message
849 $lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `i`.`author-link` AS `item-author`
850 FROM `item`, `item` as `i`
851 WHERE `item`.`contact-id` = %d
852 AND ((`item`.`author-link` IN ('%s', '%s')) OR (`item`.`owner-link` IN ('%s', '%s')))
853 AND `i`.`id` = `item`.`parent`
854 AND `item`.`type`!='activity'
855 AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''
856 ORDER BY `item`.`created` DESC
858 intval($user_info['cid']),
859 dbesc($user_info['url']),
860 dbesc(normalise_link($user_info['url'])),
861 dbesc($user_info['url']),
862 dbesc(normalise_link($user_info['url']))
865 if (count($lastwall)>0){
866 $lastwall = $lastwall[0];
868 $in_reply_to_status_id = NULL;
869 $in_reply_to_user_id = NULL;
870 $in_reply_to_status_id_str = NULL;
871 $in_reply_to_user_id_str = NULL;
872 $in_reply_to_screen_name = NULL;
873 if (intval($lastwall['parent']) != intval($lastwall['id'])) {
874 $in_reply_to_status_id= intval($lastwall['parent']);
875 $in_reply_to_status_id_str = (string) intval($lastwall['parent']);
877 $r = q("SELECT * FROM unique_contacts WHERE `url` = '%s'", dbesc(normalise_link($lastwall['item-author'])));
879 if ($r[0]['nick'] == "")
880 $r[0]['nick'] = api_get_nick($r[0]["url"]);
882 $in_reply_to_screen_name = (($r[0]['nick']) ? $r[0]['nick'] : $r[0]['name']);
883 $in_reply_to_user_id = intval($r[0]['id']);
884 $in_reply_to_user_id_str = (string) intval($r[0]['id']);
888 // There seems to be situation, where both fields are identical:
889 // https://github.com/friendica/friendica/issues/1010
890 // This is a bugfix for that.
891 if (intval($in_reply_to_status_id) == intval($lastwall['id'])) {
892 logger('api_status_show: this message should never appear: id: '.$lastwall['id'].' similar to reply-to: '.$in_reply_to_status_id, LOGGER_DEBUG);
893 $in_reply_to_status_id = NULL;
894 $in_reply_to_user_id = NULL;
895 $in_reply_to_status_id_str = NULL;
896 $in_reply_to_user_id_str = NULL;
897 $in_reply_to_screen_name = NULL;
900 $converted = api_convert_item($item);
902 $status_info = array(
903 'text' => $converted["text"],
904 'truncated' => false,
905 'created_at' => api_date($lastwall['created']),
906 'in_reply_to_status_id' => $in_reply_to_status_id,
907 'in_reply_to_status_id_str' => $in_reply_to_status_id_str,
908 'source' => (($lastwall['app']) ? $lastwall['app'] : 'web'),
909 'id' => intval($lastwall['id']),
910 'id_str' => (string) $lastwall['id'],
911 'in_reply_to_user_id' => $in_reply_to_user_id,
912 'in_reply_to_user_id_str' => $in_reply_to_user_id_str,
913 'in_reply_to_screen_name' => $in_reply_to_screen_name,
915 'favorited' => $lastwall['starred'] ? true : false,
916 'user' => $user_info,
917 'statusnet_html' => $converted["html"],
918 'statusnet_conversation_id' => $lastwall['parent'],
921 if (count($converted["attachments"]) > 0)
922 $status_info["attachments"] = $converted["attachments"];
924 if (count($converted["entities"]) > 0)
925 $status_info["entities"] = $converted["entities"];
927 if (($lastwall['item_network'] != "") AND ($status["source"] == 'web'))
928 $status_info["source"] = network_to_name($lastwall['item_network']);
929 elseif (($lastwall['item_network'] != "") AND (network_to_name($lastwall['item_network']) != $status_info["source"]))
930 $status_info["source"] = trim($status_info["source"].' ('.network_to_name($lastwall['item_network']).')');
932 // "uid" and "self" are only needed for some internal stuff, so remove it from here
933 unset($status_info["user"]["uid"]);
934 unset($status_info["user"]["self"]);
938 return($status_info);
940 return api_apply_template("status", $type, array('$status' => $status_info));
949 * Returns extended information of a given user, specified by ID or screen name as per the required id parameter.
950 * The author's most recent status will be returned inline.
951 * http://developer.twitter.com/doc/get/users/show
953 function api_users_show(&$a, $type){
954 $user_info = api_get_user($a);
956 $lastwall = q("SELECT `item`.*
957 FROM `item`, `contact`
958 WHERE `item`.`uid` = %d AND `verb` = '%s' AND `item`.`contact-id` = %d
959 AND ((`item`.`author-link` IN ('%s', '%s')) OR (`item`.`owner-link` IN ('%s', '%s')))
960 AND `contact`.`id`=`item`.`contact-id`
961 AND `type`!='activity'
962 AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''
963 ORDER BY `created` DESC
966 dbesc(ACTIVITY_POST),
967 intval($user_info['cid']),
968 dbesc($user_info['url']),
969 dbesc(normalise_link($user_info['url'])),
970 dbesc($user_info['url']),
971 dbesc(normalise_link($user_info['url']))
973 if (count($lastwall)>0){
974 $lastwall = $lastwall[0];
976 $in_reply_to_status_id = NULL;
977 $in_reply_to_user_id = NULL;
978 $in_reply_to_status_id_str = NULL;
979 $in_reply_to_user_id_str = NULL;
980 $in_reply_to_screen_name = NULL;
981 if ($lastwall['parent']!=$lastwall['id']) {
982 $reply = q("SELECT `item`.`id`, `item`.`contact-id` as `reply_uid`, `contact`.`nick` as `reply_author`, `item`.`author-link` AS `item-author`
983 FROM `item`,`contact` WHERE `contact`.`id`=`item`.`contact-id` AND `item`.`id` = %d", intval($lastwall['parent']));
984 if (count($reply)>0) {
985 $in_reply_to_status_id = intval($lastwall['parent']);
986 $in_reply_to_status_id_str = (string) intval($lastwall['parent']);
988 $r = q("SELECT * FROM unique_contacts WHERE `url` = '%s'", dbesc(normalise_link($reply[0]['item-author'])));
990 if ($r[0]['nick'] == "")
991 $r[0]['nick'] = api_get_nick($r[0]["url"]);
993 $in_reply_to_screen_name = (($r[0]['nick']) ? $r[0]['nick'] : $r[0]['name']);
994 $in_reply_to_user_id = intval($r[0]['id']);
995 $in_reply_to_user_id_str = (string) intval($r[0]['id']);
1000 $converted = api_convert_item($item);
1002 $user_info['status'] = array(
1003 'text' => $converted["text"],
1004 'truncated' => false,
1005 'created_at' => api_date($lastwall['created']),
1006 'in_reply_to_status_id' => $in_reply_to_status_id,
1007 'in_reply_to_status_id_str' => $in_reply_to_status_id_str,
1008 'source' => (($lastwall['app']) ? $lastwall['app'] : 'web'),
1009 'id' => intval($lastwall['contact-id']),
1010 'id_str' => (string) $lastwall['contact-id'],
1011 'in_reply_to_user_id' => $in_reply_to_user_id,
1012 'in_reply_to_user_id_str' => $in_reply_to_user_id_str,
1013 'in_reply_to_screen_name' => $in_reply_to_screen_name,
1015 'favorited' => $lastwall['starred'] ? true : false,
1016 'statusnet_html' => $converted["html"],
1017 'statusnet_conversation_id' => $lastwall['parent'],
1020 if (count($converted["attachments"]) > 0)
1021 $user_info["status"]["attachments"] = $converted["attachments"];
1023 if (count($converted["entities"]) > 0)
1024 $user_info["status"]["entities"] = $converted["entities"];
1026 if (($lastwall['item_network'] != "") AND ($user_info["status"]["source"] == 'web'))
1027 $user_info["status"]["source"] = network_to_name($lastwall['item_network']);
1028 if (($lastwall['item_network'] != "") AND (network_to_name($lastwall['item_network']) != $user_info["status"]["source"]))
1029 $user_info["status"]["source"] = trim($user_info["status"]["source"].' ('.network_to_name($lastwall['item_network']).')');
1033 // "uid" and "self" are only needed for some internal stuff, so remove it from here
1034 unset($user_info["uid"]);
1035 unset($user_info["self"]);
1037 return api_apply_template("user", $type, array('$user' => $user_info));
1040 api_register_func('api/users/show','api_users_show');
1043 function api_users_search(&$a, $type) {
1044 $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
1046 $userlist = array();
1048 if (isset($_GET["q"])) {
1049 $r = q("SELECT id FROM unique_contacts WHERE name='%s'", dbesc($_GET["q"]));
1051 $r = q("SELECT id FROM unique_contacts WHERE nick='%s'", dbesc($_GET["q"]));
1054 foreach ($r AS $user) {
1055 $user_info = api_get_user($a, $user["id"]);
1056 //echo print_r($user_info, true)."\n";
1057 $userdata = api_apply_template("user", $type, array('user' => $user_info));
1058 $userlist[] = $userdata["user"];
1060 $userlist = array("users" => $userlist);
1062 die(api_error($a, $type, t("User not found.")));
1064 die(api_error($a, $type, t("User not found.")));
1069 api_register_func('api/users/search','api_users_search');
1073 * http://developer.twitter.com/doc/get/statuses/home_timeline
1075 * TODO: Optional parameters
1076 * TODO: Add reply info
1078 function api_statuses_home_timeline(&$a, $type){
1079 if (api_user()===false) return false;
1081 unset($_REQUEST["user_id"]);
1082 unset($_GET["user_id"]);
1084 unset($_REQUEST["screen_name"]);
1085 unset($_GET["screen_name"]);
1087 $user_info = api_get_user($a);
1088 // get last newtork messages
1092 $count = (x($_REQUEST,'count')?$_REQUEST['count']:20);
1093 $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
1094 if ($page<0) $page=0;
1095 $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
1096 $max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
1097 //$since_id = 0;//$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
1098 $exclude_replies = (x($_REQUEST,'exclude_replies')?1:0);
1099 $conversation_id = (x($_REQUEST,'conversation_id')?$_REQUEST['conversation_id']:0);
1101 $start = $page*$count;
1105 $sql_extra .= ' AND `item`.`id` <= '.intval($max_id);
1106 if ($exclude_replies > 0)
1107 $sql_extra .= ' AND `item`.`parent` = `item`.`id`';
1108 if ($conversation_id > 0)
1109 $sql_extra .= ' AND `item`.`parent` = '.intval($conversation_id);
1111 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
1112 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
1113 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
1114 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1115 FROM `item`, `contact`
1116 WHERE `item`.`uid` = %d AND `verb` = '%s'
1117 AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
1118 AND `contact`.`id` = `item`.`contact-id`
1119 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1122 ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
1124 dbesc(ACTIVITY_POST),
1126 intval($start), intval($count)
1129 $ret = api_format_items($r,$user_info);
1131 // We aren't going to try to figure out at the item, group, and page
1132 // level which items you've seen and which you haven't. If you're looking
1133 // at the network timeline just mark everything seen.
1135 $r = q("UPDATE `item` SET `unseen` = 0
1136 WHERE `unseen` = 1 AND `uid` = %d",
1137 //intval($user_info['uid'])
1142 $data = array('$statuses' => $ret);
1146 $data = api_rss_extra($a, $data, $user_info);
1149 $as = api_format_as($a, $ret, $user_info);
1150 $as['title'] = $a->config['sitename']." Home Timeline";
1151 $as['link']['url'] = $a->get_baseurl()."/".$user_info["screen_name"]."/all";
1156 return api_apply_template("timeline", $type, $data);
1158 api_register_func('api/statuses/home_timeline','api_statuses_home_timeline', true);
1159 api_register_func('api/statuses/friends_timeline','api_statuses_home_timeline', true);
1161 function api_statuses_public_timeline(&$a, $type){
1162 if (api_user()===false) return false;
1164 $user_info = api_get_user($a);
1165 // get last newtork messages
1169 $count = (x($_REQUEST,'count')?$_REQUEST['count']:20);
1170 $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
1171 if ($page<0) $page=0;
1172 $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
1173 $max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
1174 //$since_id = 0;//$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
1175 $exclude_replies = (x($_REQUEST,'exclude_replies')?1:0);
1176 $conversation_id = (x($_REQUEST,'conversation_id')?$_REQUEST['conversation_id']:0);
1178 $start = $page*$count;
1181 $sql_extra = 'AND `item`.`id` <= '.intval($max_id);
1182 if ($exclude_replies > 0)
1183 $sql_extra .= ' AND `item`.`parent` = `item`.`id`';
1184 if ($conversation_id > 0)
1185 $sql_extra .= ' AND `item`.`parent` = '.intval($conversation_id);
1187 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
1188 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
1189 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
1190 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
1191 `user`.`nickname`, `user`.`hidewall`
1192 FROM `item` STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1193 STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid`
1194 WHERE `verb` = '%s' AND `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1195 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
1196 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
1197 AND `item`.`private` = 0 AND `item`.`wall` = 1 AND `user`.`hidewall` = 0
1198 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1201 ORDER BY `item`.`id` DESC LIMIT %d, %d ",
1202 dbesc(ACTIVITY_POST),
1207 $ret = api_format_items($r,$user_info);
1210 $data = array('$statuses' => $ret);
1214 $data = api_rss_extra($a, $data, $user_info);
1217 $as = api_format_as($a, $ret, $user_info);
1218 $as['title'] = $a->config['sitename']." Public Timeline";
1219 $as['link']['url'] = $a->get_baseurl()."/";
1224 return api_apply_template("timeline", $type, $data);
1226 api_register_func('api/statuses/public_timeline','api_statuses_public_timeline', true);
1231 function api_statuses_show(&$a, $type){
1232 if (api_user()===false) return false;
1234 $user_info = api_get_user($a);
1237 $id = intval($a->argv[3]);
1240 $id = intval($_REQUEST["id"]);
1244 $id = intval($a->argv[4]);
1246 logger('API: api_statuses_show: '.$id);
1248 $conversation = (x($_REQUEST,'conversation')?1:0);
1252 $sql_extra .= " AND `item`.`parent` = %d ORDER BY `received` ASC ";
1254 $sql_extra .= " AND `item`.`id` = %d";
1256 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
1257 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
1258 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
1259 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1260 FROM `item`, `contact`
1261 WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
1262 AND `contact`.`id` = `item`.`contact-id` AND `item`.`uid` = %d AND `item`.`verb` = '%s'
1263 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1266 dbesc(ACTIVITY_POST),
1271 die(api_error($a, $type, t("There is no status with this id.")));
1273 $ret = api_format_items($r,$user_info);
1275 if ($conversation) {
1276 $data = array('$statuses' => $ret);
1277 return api_apply_template("timeline", $type, $data);
1279 $data = array('$status' => $ret[0]);
1283 $data = api_rss_extra($a, $data, $user_info);
1285 return api_apply_template("status", $type, $data);
1288 api_register_func('api/statuses/show','api_statuses_show', true);
1294 function api_conversation_show(&$a, $type){
1295 if (api_user()===false) return false;
1297 $user_info = api_get_user($a);
1300 $id = intval($a->argv[3]);
1301 $count = (x($_REQUEST,'count')?$_REQUEST['count']:20);
1302 $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
1303 if ($page<0) $page=0;
1304 $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
1305 $max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
1307 $start = $page*$count;
1310 $id = intval($_REQUEST["id"]);
1314 $id = intval($a->argv[4]);
1316 logger('API: api_conversation_show: '.$id);
1321 $sql_extra = ' AND `item`.`id` <= '.intval($max_id);
1323 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
1324 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
1325 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
1326 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1327 FROM `item` INNER JOIN (SELECT `uri`,`parent` FROM `item` WHERE `id` = %d) AS `temp1`
1328 ON (`item`.`thr-parent` = `temp1`.`uri` AND `item`.`parent` = `temp1`.`parent`), `contact`
1329 WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
1330 AND `item`.`uid` = %d AND `item`.`verb` = '%s' AND `contact`.`id` = `item`.`contact-id`
1331 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1332 AND `item`.`id`>%d $sql_extra
1333 ORDER BY `item`.`id` DESC LIMIT %d ,%d",
1334 intval($id), intval(api_user()),
1335 dbesc(ACTIVITY_POST),
1337 intval($start), intval($count)
1341 die(api_error($a, $type, t("There is no conversation with this id.")));
1343 $ret = api_format_items($r,$user_info);
1345 $data = array('$statuses' => $ret);
1346 return api_apply_template("timeline", $type, $data);
1348 api_register_func('api/conversation/show','api_conversation_show', true);
1354 function api_statuses_repeat(&$a, $type){
1357 if (api_user()===false) return false;
1359 $user_info = api_get_user($a);
1362 $id = intval($a->argv[3]);
1365 $id = intval($_REQUEST["id"]);
1369 $id = intval($a->argv[4]);
1371 logger('API: api_statuses_repeat: '.$id);
1373 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`nick` as `reply_author`,
1374 `contact`.`name`, `contact`.`photo` as `reply_photo`, `contact`.`url` as `reply_url`, `contact`.`rel`,
1375 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
1376 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1377 FROM `item`, `contact`
1378 WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
1379 AND `contact`.`id` = `item`.`contact-id`
1380 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1382 AND `item`.`id`=%d",
1386 if ($r[0]['body'] != "") {
1387 if (!intval(get_config('system','old_share'))) {
1388 if (strpos($r[0]['body'], "[/share]") !== false) {
1389 $pos = strpos($r[0]['body'], "[share");
1390 $post = substr($r[0]['body'], $pos);
1392 $post = "[share author='".str_replace("'", "'", $r[0]['author-name']).
1393 "' profile='".$r[0]['author-link'].
1394 "' avatar='".$r[0]['author-avatar'].
1395 "' link='".$r[0]['plink']."']";
1396 $post .= $r[0]['body'];
1397 $post .= "[/share]";
1399 $_REQUEST['body'] = $post;
1401 $_REQUEST['body'] = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8')."[url=".$r[0]['reply_url']."]".$r[0]['reply_author']."[/url] \n".$r[0]['body'];
1403 $_REQUEST['profile_uid'] = api_user();
1404 $_REQUEST['type'] = 'wall';
1405 $_REQUEST['api_source'] = true;
1407 if (!x($_REQUEST, "source"))
1408 $_REQUEST["source"] = api_source();
1410 require_once('mod/item.php');
1414 // this should output the last post (the one we just posted).
1416 return(api_status_show($a,$type));
1418 api_register_func('api/statuses/retweet','api_statuses_repeat', true);
1423 function api_statuses_destroy(&$a, $type){
1424 if (api_user()===false) return false;
1426 $user_info = api_get_user($a);
1429 $id = intval($a->argv[3]);
1432 $id = intval($_REQUEST["id"]);
1436 $id = intval($a->argv[4]);
1438 logger('API: api_statuses_destroy: '.$id);
1440 $ret = api_statuses_show($a, $type);
1442 require_once('include/items.php');
1443 drop_item($id, false);
1447 api_register_func('api/statuses/destroy','api_statuses_destroy', true);
1451 * http://developer.twitter.com/doc/get/statuses/mentions
1454 function api_statuses_mentions(&$a, $type){
1455 if (api_user()===false) return false;
1457 unset($_REQUEST["user_id"]);
1458 unset($_GET["user_id"]);
1460 unset($_REQUEST["screen_name"]);
1461 unset($_GET["screen_name"]);
1463 $user_info = api_get_user($a);
1464 // get last newtork messages
1468 $count = (x($_REQUEST,'count')?$_REQUEST['count']:20);
1469 $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
1470 if ($page<0) $page=0;
1471 $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
1472 $max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
1473 //$since_id = 0;//$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
1475 $start = $page*$count;
1477 // Ugly code - should be changed
1478 $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
1479 $myurl = substr($myurl,strpos($myurl,'://')+3);
1480 //$myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
1481 $myurl = str_replace('www.','',$myurl);
1482 $diasp_url = str_replace('/profile/','/u/',$myurl);
1485 $sql_extra = ' AND `item`.`id` <= '.intval($max_id);
1487 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
1488 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
1489 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
1490 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1491 FROM `item`, `contact`
1492 WHERE `item`.`uid` = %d AND `verb` = '%s'
1493 AND NOT (`item`.`author-link` IN ('https://%s', 'http://%s'))
1494 AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
1495 AND `contact`.`id` = `item`.`contact-id`
1496 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1497 AND `item`.`parent` IN (SELECT `iid` from thread where uid = %d AND `mention` AND !`ignored`)
1500 ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
1502 dbesc(ACTIVITY_POST),
1503 dbesc(protect_sprintf($myurl)),
1504 dbesc(protect_sprintf($myurl)),
1507 intval($start), intval($count)
1510 $ret = api_format_items($r,$user_info);
1513 $data = array('$statuses' => $ret);
1517 $data = api_rss_extra($a, $data, $user_info);
1520 $as = api_format_as($a, $ret, $user_info);
1521 $as["title"] = $a->config['sitename']." Mentions";
1522 $as['link']['url'] = $a->get_baseurl()."/";
1527 return api_apply_template("timeline", $type, $data);
1529 api_register_func('api/statuses/mentions','api_statuses_mentions', true);
1530 api_register_func('api/statuses/replies','api_statuses_mentions', true);
1533 function api_statuses_user_timeline(&$a, $type){
1534 if (api_user()===false) return false;
1536 $user_info = api_get_user($a);
1537 // get last network messages
1539 logger("api_statuses_user_timeline: api_user: ". api_user() .
1540 "\nuser_info: ".print_r($user_info, true) .
1541 "\n_REQUEST: ".print_r($_REQUEST, true),
1545 $count = (x($_REQUEST,'count')?$_REQUEST['count']:20);
1546 $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
1547 if ($page<0) $page=0;
1548 $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
1549 //$since_id = 0;//$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
1550 $exclude_replies = (x($_REQUEST,'exclude_replies')?1:0);
1551 $conversation_id = (x($_REQUEST,'conversation_id')?$_REQUEST['conversation_id']:0);
1553 $start = $page*$count;
1556 if ($user_info['self']==1)
1557 $sql_extra .= " AND `item`.`wall` = 1 ";
1559 if ($exclude_replies > 0)
1560 $sql_extra .= ' AND `item`.`parent` = `item`.`id`';
1561 if ($conversation_id > 0)
1562 $sql_extra .= ' AND `item`.`parent` = '.intval($conversation_id);
1564 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
1565 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
1566 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
1567 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1568 FROM `item`, `contact`
1569 WHERE `item`.`uid` = %d AND `verb` = '%s'
1570 AND `item`.`contact-id` = %d
1571 AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
1572 AND `contact`.`id` = `item`.`contact-id`
1573 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1576 ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
1578 dbesc(ACTIVITY_POST),
1579 intval($user_info['cid']),
1581 intval($start), intval($count)
1584 $ret = api_format_items($r,$user_info, true);
1586 $data = array('$statuses' => $ret);
1590 $data = api_rss_extra($a, $data, $user_info);
1593 return api_apply_template("timeline", $type, $data);
1596 api_register_func('api/statuses/user_timeline','api_statuses_user_timeline', true);
1600 * Star/unstar an item
1601 * param: id : id of the item
1603 * api v1 : https://web.archive.org/web/20131019055350/https://dev.twitter.com/docs/api/1/post/favorites/create/%3Aid
1605 function api_favorites_create_destroy(&$a, $type){
1606 if (api_user()===false) return false;
1608 # for versioned api.
1609 # TODO: we need a better global soluton
1611 if ($a->argv[1]=="1.1") $action_argv_id=3;
1613 if ($a->argc<=$action_argv_id) die(api_error($a, $type, t("Invalid request.")));
1614 $action = str_replace(".".$type,"",$a->argv[$action_argv_id]);
1615 if ($a->argc==$action_argv_id+2) {
1616 $itemid = intval($a->argv[$action_argv_id+1]);
1618 $itemid = intval($_REQUEST['id']);
1621 $item = q("SELECT * FROM item WHERE id=%d AND uid=%d",
1622 $itemid, api_user());
1624 if ($item===false || count($item)==0) die(api_error($a, $type, t("Invalid item.")));
1628 $item[0]['starred']=1;
1631 $item[0]['starred']=0;
1634 die(api_error($a, $type, t("Invalid action. ".$action)));
1636 $r = q("UPDATE item SET starred=%d WHERE id=%d AND uid=%d",
1637 $item[0]['starred'], $itemid, api_user());
1639 q("UPDATE thread SET starred=%d WHERE iid=%d AND uid=%d",
1640 $item[0]['starred'], $itemid, api_user());
1642 if ($r===false) die(api_error($a, $type, t("DB error")));
1645 $user_info = api_get_user($a);
1646 $ret = api_format_items($item,$user_info)[0];
1648 $data = array('$status' => $ret);
1652 $data = api_rss_extra($a, $data, $user_info);
1655 return api_apply_template("status", $type, $data);
1658 api_register_func('api/favorites/create', 'api_favorites_create_destroy', true);
1659 api_register_func('api/favorites/destroy', 'api_favorites_create_destroy', true);
1661 function api_favorites(&$a, $type){
1664 if (api_user()===false) return false;
1666 $called_api= array();
1668 $user_info = api_get_user($a);
1670 // in friendica starred item are private
1671 // return favorites only for self
1672 logger('api_favorites: self:' . $user_info['self']);
1674 if ($user_info['self']==0) {
1680 $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
1681 $max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
1682 $count = (x($_GET,'count')?$_GET['count']:20);
1683 $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
1684 if ($page<0) $page=0;
1686 $start = $page*$count;
1689 $sql_extra .= ' AND `item`.`id` <= '.intval($max_id);
1691 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
1692 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
1693 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
1694 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1695 FROM `item`, `contact`
1696 WHERE `item`.`uid` = %d
1697 AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
1698 AND `item`.`starred` = 1
1699 AND `contact`.`id` = `item`.`contact-id`
1700 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1703 ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
1706 intval($start), intval($count)
1709 $ret = api_format_items($r,$user_info);
1713 $data = array('$statuses' => $ret);
1717 $data = api_rss_extra($a, $data, $user_info);
1720 return api_apply_template("timeline", $type, $data);
1723 api_register_func('api/favorites','api_favorites', true);
1728 function api_format_as($a, $ret, $user_info) {
1731 $as['title'] = $a->config['sitename']." Public Timeline";
1733 foreach ($ret as $item) {
1734 $singleitem["actor"]["displayName"] = $item["user"]["name"];
1735 $singleitem["actor"]["id"] = $item["user"]["contact_url"];
1736 $avatar[0]["url"] = $item["user"]["profile_image_url"];
1737 $avatar[0]["rel"] = "avatar";
1738 $avatar[0]["type"] = "";
1739 $avatar[0]["width"] = 96;
1740 $avatar[0]["height"] = 96;
1741 $avatar[1]["url"] = $item["user"]["profile_image_url"];
1742 $avatar[1]["rel"] = "avatar";
1743 $avatar[1]["type"] = "";
1744 $avatar[1]["width"] = 48;
1745 $avatar[1]["height"] = 48;
1746 $avatar[2]["url"] = $item["user"]["profile_image_url"];
1747 $avatar[2]["rel"] = "avatar";
1748 $avatar[2]["type"] = "";
1749 $avatar[2]["width"] = 24;
1750 $avatar[2]["height"] = 24;
1751 $singleitem["actor"]["avatarLinks"] = $avatar;
1753 $singleitem["actor"]["image"]["url"] = $item["user"]["profile_image_url"];
1754 $singleitem["actor"]["image"]["rel"] = "avatar";
1755 $singleitem["actor"]["image"]["type"] = "";
1756 $singleitem["actor"]["image"]["width"] = 96;
1757 $singleitem["actor"]["image"]["height"] = 96;
1758 $singleitem["actor"]["type"] = "person";
1759 $singleitem["actor"]["url"] = $item["person"]["contact_url"];
1760 $singleitem["actor"]["statusnet:profile_info"]["local_id"] = $item["user"]["id"];
1761 $singleitem["actor"]["statusnet:profile_info"]["following"] = $item["user"]["following"] ? "true" : "false";
1762 $singleitem["actor"]["statusnet:profile_info"]["blocking"] = "false";
1763 $singleitem["actor"]["contact"]["preferredUsername"] = $item["user"]["screen_name"];
1764 $singleitem["actor"]["contact"]["displayName"] = $item["user"]["name"];
1765 $singleitem["actor"]["contact"]["addresses"] = "";
1767 $singleitem["body"] = $item["text"];
1768 $singleitem["object"]["displayName"] = $item["text"];
1769 $singleitem["object"]["id"] = $item["url"];
1770 $singleitem["object"]["type"] = "note";
1771 $singleitem["object"]["url"] = $item["url"];
1772 //$singleitem["context"] =;
1773 $singleitem["postedTime"] = date("c", strtotime($item["published"]));
1774 $singleitem["provider"]["objectType"] = "service";
1775 $singleitem["provider"]["displayName"] = "Test";
1776 $singleitem["provider"]["url"] = "http://test.tld";
1777 $singleitem["title"] = $item["text"];
1778 $singleitem["verb"] = "post";
1779 $singleitem["statusnet:notice_info"]["local_id"] = $item["id"];
1780 $singleitem["statusnet:notice_info"]["source"] = $item["source"];
1781 $singleitem["statusnet:notice_info"]["favorite"] = "false";
1782 $singleitem["statusnet:notice_info"]["repeated"] = "false";
1783 //$singleitem["original"] = $item;
1784 $items[] = $singleitem;
1786 $as['items'] = $items;
1787 $as['link']['url'] = $a->get_baseurl()."/".$user_info["screen_name"]."/all";
1788 $as['link']['rel'] = "alternate";
1789 $as['link']['type'] = "text/html";
1793 function api_format_messages($item, $recipient, $sender) {
1794 // standard meta information
1796 'id' => $item['id'],
1797 'sender_id' => $sender['id'] ,
1799 'recipient_id' => $recipient['id'],
1800 'created_at' => api_date($item['created']),
1801 'sender_screen_name' => $sender['screen_name'],
1802 'recipient_screen_name' => $recipient['screen_name'],
1803 'sender' => $sender,
1804 'recipient' => $recipient,
1807 // "uid" and "self" are only needed for some internal stuff, so remove it from here
1808 unset($ret["sender"]["uid"]);
1809 unset($ret["sender"]["self"]);
1810 unset($ret["recipient"]["uid"]);
1811 unset($ret["recipient"]["self"]);
1813 //don't send title to regular StatusNET requests to avoid confusing these apps
1814 if (x($_GET, 'getText')) {
1815 $ret['title'] = $item['title'] ;
1816 if ($_GET["getText"] == "html") {
1817 $ret['text'] = bbcode($item['body'], false, false);
1819 elseif ($_GET["getText"] == "plain") {
1820 //$ret['text'] = html2plain(bbcode($item['body'], false, false, true), 0);
1821 $ret['text'] = trim(html2plain(bbcode(api_clean_plain_items($item['body']), false, false, 2, true), 0));
1825 $ret['text'] = $item['title']."\n".html2plain(bbcode(api_clean_plain_items($item['body']), false, false, 2, true), 0);
1827 if (isset($_GET["getUserObjects"]) && $_GET["getUserObjects"] == "false") {
1828 unset($ret['sender']);
1829 unset($ret['recipient']);
1835 function api_convert_item($item) {
1837 $body = $item['body'];
1838 $attachments = api_get_attachments($body);
1840 // Workaround for ostatus messages where the title is identically to the body
1841 $html = bbcode(api_clean_plain_items($body), false, false, 2, true);
1842 $statusbody = trim(html2plain($html, 0));
1844 // handle data: images
1845 $statusbody = api_format_items_embeded_images($item,$statusbody);
1847 $statustitle = trim($item['title']);
1849 if (($statustitle != '') and (strpos($statusbody, $statustitle) !== false))
1850 $statustext = trim($statusbody);
1852 $statustext = trim($statustitle."\n\n".$statusbody);
1854 if (($item["network"] == NETWORK_FEED) and (strlen($statustext)> 1000))
1855 $statustext = substr($statustext, 0, 1000)."... \n".$item["plink"];
1857 $statushtml = trim(bbcode($body, false, false));
1859 if ($item['title'] != "")
1860 $statushtml = "<h4>".bbcode($item['title'])."</h4>\n".$statushtml;
1862 $entities = api_get_entitities($statustext, $body);
1864 return(array("text" => $statustext, "html" => $statushtml, "attachments" => $attachments, "entities" => $entities));
1867 function api_get_attachments(&$body) {
1870 $text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $text);
1872 $URLSearchString = "^\[\]";
1873 $ret = preg_match_all("/\[img\]([$URLSearchString]*)\[\/img\]/ism", $text, $images);
1878 require_once("include/Photo.php");
1880 $attachments = array();
1882 foreach ($images[1] AS $image) {
1883 $imagedata = get_photo_info($image);
1886 $attachments[] = array("url" => $image, "mimetype" => $imagedata["mime"], "size" => $imagedata["size"]);
1889 if (strstr($_SERVER['HTTP_USER_AGENT'], "AndStatus"))
1890 foreach ($images[0] AS $orig)
1891 $body = str_replace($orig, "", $body);
1893 return $attachments;
1896 function api_get_entitities(&$text, $bbcode) {
1899 * Links at the first character of the post
1904 $include_entities = strtolower(x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:"false");
1906 if ($include_entities != "true") {
1907 require_once("mod/proxy.php");
1909 preg_match_all("/\[img](.*?)\[\/img\]/ism", $bbcode, $images);
1911 foreach ($images[1] AS $image) {
1912 $replace = proxy_url($image);
1913 $text = str_replace($image, $replace, $text);
1918 $bbcode = bb_CleanPictureLinks($bbcode);
1920 // Change pure links in text to bbcode uris
1921 $bbcode = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1[url=$2]$2[/url]', $bbcode);
1923 $entities = array();
1924 $entities["hashtags"] = array();
1925 $entities["symbols"] = array();
1926 $entities["urls"] = array();
1927 $entities["user_mentions"] = array();
1929 $URLSearchString = "^\[\]";
1931 $bbcode = preg_replace("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",'#$2',$bbcode);
1933 $bbcode = preg_replace("/\[bookmark\=([$URLSearchString]*)\](.*?)\[\/bookmark\]/ism",'[url=$1]$2[/url]',$bbcode);
1934 //$bbcode = preg_replace("/\[url\](.*?)\[\/url\]/ism",'[url=$1]$1[/url]',$bbcode);
1935 $bbcode = preg_replace("/\[video\](.*?)\[\/video\]/ism",'[url=$1]$1[/url]',$bbcode);
1937 $bbcode = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism",
1938 '[url=https://www.youtube.com/watch?v=$1]https://www.youtube.com/watch?v=$1[/url]', $bbcode);
1939 $bbcode = preg_replace("/\[youtube\](.*?)\[\/youtube\]/ism",'[url=$1]$1[/url]',$bbcode);
1941 $bbcode = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism",
1942 '[url=https://vimeo.com/$1]https://vimeo.com/$1[/url]', $bbcode);
1943 $bbcode = preg_replace("/\[vimeo\](.*?)\[\/vimeo\]/ism",'[url=$1]$1[/url]',$bbcode);
1945 $bbcode = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $bbcode);
1947 //preg_match_all("/\[url\]([$URLSearchString]*)\[\/url\]/ism", $bbcode, $urls1);
1948 preg_match_all("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", $bbcode, $urls);
1950 $ordered_urls = array();
1951 foreach ($urls[1] AS $id=>$url) {
1952 //$start = strpos($text, $url, $offset);
1953 $start = iconv_strpos($text, $url, 0, "UTF-8");
1954 if (!($start === false))
1955 $ordered_urls[$start] = array("url" => $url, "title" => $urls[2][$id]);
1958 ksort($ordered_urls);
1961 //foreach ($urls[1] AS $id=>$url) {
1962 foreach ($ordered_urls AS $url) {
1963 if ((substr($url["title"], 0, 7) != "http://") AND (substr($url["title"], 0, 8) != "https://") AND
1964 !strpos($url["title"], "http://") AND !strpos($url["title"], "https://"))
1965 $display_url = $url["title"];
1967 $display_url = str_replace(array("http://www.", "https://www."), array("", ""), $url["url"]);
1968 $display_url = str_replace(array("http://", "https://"), array("", ""), $display_url);
1970 if (strlen($display_url) > 26)
1971 $display_url = substr($display_url, 0, 25)."…";
1974 //$start = strpos($text, $url, $offset);
1975 $start = iconv_strpos($text, $url["url"], $offset, "UTF-8");
1976 if (!($start === false)) {
1977 $entities["urls"][] = array("url" => $url["url"],
1978 "expanded_url" => $url["url"],
1979 "display_url" => $display_url,
1980 "indices" => array($start, $start+strlen($url["url"])));
1981 $offset = $start + 1;
1985 preg_match_all("/\[img](.*?)\[\/img\]/ism", $bbcode, $images);
1986 $ordered_images = array();
1987 foreach ($images[1] AS $image) {
1988 //$start = strpos($text, $url, $offset);
1989 $start = iconv_strpos($text, $image, 0, "UTF-8");
1990 if (!($start === false))
1991 $ordered_images[$start] = $image;
1993 //$entities["media"] = array();
1996 foreach ($ordered_images AS $url) {
1997 $display_url = str_replace(array("http://www.", "https://www."), array("", ""), $url);
1998 $display_url = str_replace(array("http://", "https://"), array("", ""), $display_url);
2000 if (strlen($display_url) > 26)
2001 $display_url = substr($display_url, 0, 25)."…";
2003 $start = iconv_strpos($text, $url, $offset, "UTF-8");
2004 if (!($start === false)) {
2005 require_once("include/Photo.php");
2006 $image = get_photo_info($url);
2008 // If image cache is activated, then use the following sizes:
2009 // thumb (150), small (340), medium (600) and large (1024)
2010 if (!get_config("system", "proxy_disabled")) {
2011 require_once("mod/proxy.php");
2012 $media_url = proxy_url($url);
2015 $scale = scale_image($image[0], $image[1], 150);
2016 $sizes["thumb"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
2018 if (($image[0] > 150) OR ($image[1] > 150)) {
2019 $scale = scale_image($image[0], $image[1], 340);
2020 $sizes["small"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
2023 $scale = scale_image($image[0], $image[1], 600);
2024 $sizes["medium"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
2026 if (($image[0] > 600) OR ($image[1] > 600)) {
2027 $scale = scale_image($image[0], $image[1], 1024);
2028 $sizes["large"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
2032 $sizes["medium"] = array("w" => $image[0], "h" => $image[1], "resize" => "fit");
2035 $entities["media"][] = array(
2037 "id_str" => (string)$start+1,
2038 "indices" => array($start, $start+strlen($url)),
2039 "media_url" => normalise_link($media_url),
2040 "media_url_https" => $media_url,
2042 "display_url" => $display_url,
2043 "expanded_url" => $url,
2047 $offset = $start + 1;
2053 function api_format_items_embeded_images($item, $text){
2055 $text = preg_replace_callback(
2056 "|data:image/([^;]+)[^=]+=*|m",
2057 function($match) use ($a, $item) {
2058 return $a->get_baseurl()."/display/".$item['guid'];
2064 function api_format_items($r,$user_info, $filter_user = false) {
2069 foreach($r as $item) {
2070 api_share_as_retweet($a, api_user(), $item);
2072 localize_item($item);
2073 $status_user = api_item_get_user($a,$item);
2075 // Look if the posts are matching if they should be filtered by user id
2076 if ($filter_user AND ($status_user["id"] != $user_info["id"]))
2079 if ($item['thr-parent'] != $item['uri']) {
2080 $r = q("SELECT id FROM item WHERE uid=%d AND uri='%s' LIMIT 1",
2082 dbesc($item['thr-parent']));
2084 $in_reply_to_status_id = intval($r[0]['id']);
2086 $in_reply_to_status_id = intval($item['parent']);
2088 $in_reply_to_status_id_str = (string) intval($item['parent']);
2090 $in_reply_to_screen_name = NULL;
2091 $in_reply_to_user_id = NULL;
2092 $in_reply_to_user_id_str = NULL;
2094 $r = q("SELECT `author-link` FROM item WHERE uid=%d AND id=%d LIMIT 1",
2096 intval($in_reply_to_status_id));
2098 $r = q("SELECT * FROM unique_contacts WHERE `url` = '%s'", dbesc(normalise_link($r[0]['author-link'])));
2101 if ($r[0]['nick'] == "")
2102 $r[0]['nick'] = api_get_nick($r[0]["url"]);
2104 $in_reply_to_screen_name = (($r[0]['nick']) ? $r[0]['nick'] : $r[0]['name']);
2105 $in_reply_to_user_id = intval($r[0]['id']);
2106 $in_reply_to_user_id_str = (string) intval($r[0]['id']);
2110 $in_reply_to_screen_name = NULL;
2111 $in_reply_to_user_id = NULL;
2112 $in_reply_to_status_id = NULL;
2113 $in_reply_to_user_id_str = NULL;
2114 $in_reply_to_status_id_str = NULL;
2117 $converted = api_convert_item($item);
2120 'text' => $converted["text"],
2121 'truncated' => False,
2122 'created_at'=> api_date($item['created']),
2123 'in_reply_to_status_id' => $in_reply_to_status_id,
2124 'in_reply_to_status_id_str' => $in_reply_to_status_id_str,
2125 'source' => (($item['app']) ? $item['app'] : 'web'),
2126 'id' => intval($item['id']),
2127 'id_str' => (string) intval($item['id']),
2128 'in_reply_to_user_id' => $in_reply_to_user_id,
2129 'in_reply_to_user_id_str' => $in_reply_to_user_id_str,
2130 'in_reply_to_screen_name' => $in_reply_to_screen_name,
2132 'favorited' => $item['starred'] ? true : false,
2133 'user' => $status_user ,
2134 //'entities' => NULL,
2135 'statusnet_html' => $converted["html"],
2136 'statusnet_conversation_id' => $item['parent'],
2139 if (count($converted["attachments"]) > 0)
2140 $status["attachments"] = $converted["attachments"];
2142 if (count($converted["entities"]) > 0)
2143 $status["entities"] = $converted["entities"];
2145 if (($item['item_network'] != "") AND ($status["source"] == 'web'))
2146 $status["source"] = network_to_name($item['item_network']);
2147 else if (($item['item_network'] != "") AND (network_to_name($item['item_network']) != $status["source"]))
2148 $status["source"] = trim($status["source"].' ('.network_to_name($item['item_network']).')');
2151 // Retweets are only valid for top postings
2152 // It doesn't work reliable with the link if its a feed
2153 $IsRetweet = ($item['owner-link'] != $item['author-link']);
2155 $IsRetweet = (($item['owner-name'] != $item['author-name']) OR ($item['owner-avatar'] != $item['author-avatar']));
2157 if ($IsRetweet AND ($item["id"] == $item["parent"])) {
2158 $retweeted_status = $status;
2159 $retweeted_status["user"] = api_get_user($a,$item["author-link"]);
2161 $status["retweeted_status"] = $retweeted_status;
2164 // "uid" and "self" are only needed for some internal stuff, so remove it from here
2165 unset($status["user"]["uid"]);
2166 unset($status["user"]["self"]);
2168 // 'geo' => array('type' => 'Point',
2169 // 'coordinates' => array((float) $notice->lat,
2170 // (float) $notice->lon));
2178 function api_account_rate_limit_status(&$a,$type) {
2181 'reset_time_in_seconds' => strtotime('now + 1 hour'),
2182 'remaining_hits' => (string) 150,
2183 'hourly_limit' => (string) 150,
2184 'reset_time' => api_date(datetime_convert('UTC','UTC','now + 1 hour',ATOM_TIME)),
2187 $hash['resettime_in_seconds'] = $hash['reset_time_in_seconds'];
2189 return api_apply_template('ratelimit', $type, array('$hash' => $hash));
2192 api_register_func('api/account/rate_limit_status','api_account_rate_limit_status',true);
2194 function api_help_test(&$a,$type) {
2201 return api_apply_template('test', $type, array("$ok" => $ok));
2204 api_register_func('api/help/test','api_help_test',false);
2206 function api_lists(&$a,$type) {
2211 api_register_func('api/lists','api_lists',true);
2213 function api_lists_list(&$a,$type) {
2218 api_register_func('api/lists/list','api_lists_list',true);
2221 * https://dev.twitter.com/docs/api/1/get/statuses/friends
2222 * This function is deprecated by Twitter
2223 * returns: json, xml
2225 function api_statuses_f(&$a, $type, $qtype) {
2226 if (api_user()===false) return false;
2227 $user_info = api_get_user($a);
2229 if (x($_GET,'cursor') && $_GET['cursor']=='undefined'){
2230 /* this is to stop Hotot to load friends multiple times
2231 * I'm not sure if I'm missing return something or
2232 * is a bug in hotot. Workaround, meantime
2236 return array('$users' => $ret);*/
2240 if($qtype == 'friends')
2241 $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND));
2242 if($qtype == 'followers')
2243 $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_FOLLOWER), intval(CONTACT_IS_FRIEND));
2245 // friends and followers only for self
2246 if ($user_info['self'] == 0)
2247 $sql_extra = " AND false ";
2249 $r = q("SELECT `nurl` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 $sql_extra",
2254 foreach($r as $cid){
2255 $user = api_get_user($a, $cid['nurl']);
2256 // "uid" and "self" are only needed for some internal stuff, so remove it from here
2257 unset($user["uid"]);
2258 unset($user["self"]);
2264 return array('$users' => $ret);
2267 function api_statuses_friends(&$a, $type){
2268 $data = api_statuses_f($a,$type,"friends");
2269 if ($data===false) return false;
2270 return api_apply_template("friends", $type, $data);
2272 function api_statuses_followers(&$a, $type){
2273 $data = api_statuses_f($a,$type,"followers");
2274 if ($data===false) return false;
2275 return api_apply_template("friends", $type, $data);
2277 api_register_func('api/statuses/friends','api_statuses_friends',true);
2278 api_register_func('api/statuses/followers','api_statuses_followers',true);
2285 function api_statusnet_config(&$a,$type) {
2286 $name = $a->config['sitename'];
2287 $server = $a->get_hostname();
2288 $logo = $a->get_baseurl() . '/images/friendica-64.png';
2289 $email = $a->config['admin_email'];
2290 $closed = (($a->config['register_policy'] == REGISTER_CLOSED) ? 'true' : 'false');
2291 $private = (($a->config['system']['block_public']) ? 'true' : 'false');
2292 $textlimit = (string) (($a->config['max_import_size']) ? $a->config['max_import_size'] : 200000);
2293 if($a->config['api_import_size'])
2294 $texlimit = string($a->config['api_import_size']);
2295 $ssl = (($a->config['system']['have_ssl']) ? 'true' : 'false');
2296 $sslserver = (($ssl === 'true') ? str_replace('http:','https:',$a->get_baseurl()) : '');
2299 'site' => array('name' => $name,'server' => $server, 'theme' => 'default', 'path' => '',
2300 'logo' => $logo, 'fancy' => true, 'language' => 'en', 'email' => $email, 'broughtby' => '',
2301 'broughtbyurl' => '', 'timezone' => 'UTC', 'closed' => $closed, 'inviteonly' => false,
2302 'private' => $private, 'textlimit' => $textlimit, 'sslserver' => $sslserver, 'ssl' => $ssl,
2303 'shorturllength' => '30',
2304 'friendica' => array(
2305 'FRIENDICA_PLATFORM' => FRIENDICA_PLATFORM,
2306 'FRIENDICA_VERSION' => FRIENDICA_VERSION,
2307 'DFRN_PROTOCOL_VERSION' => DFRN_PROTOCOL_VERSION,
2308 'DB_UPDATE_VERSION' => DB_UPDATE_VERSION
2313 return api_apply_template('config', $type, array('$config' => $config));
2316 api_register_func('api/statusnet/config','api_statusnet_config',false);
2318 function api_statusnet_version(&$a,$type) {
2322 if($type === 'xml') {
2323 header("Content-type: application/xml");
2324 echo '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n" . '<version>0.9.7</version>' . "\r\n";
2327 elseif($type === 'json') {
2328 header("Content-type: application/json");
2333 api_register_func('api/statusnet/version','api_statusnet_version',false);
2336 function api_ff_ids(&$a,$type,$qtype) {
2340 $user_info = api_get_user($a);
2342 if($qtype == 'friends')
2343 $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND));
2344 if($qtype == 'followers')
2345 $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_FOLLOWER), intval(CONTACT_IS_FRIEND));
2347 if (!$user_info["self"])
2348 $sql_extra = " AND false ";
2350 $stringify_ids = (x($_REQUEST,'stringify_ids')?$_REQUEST['stringify_ids']:false);
2352 $r = q("SELECT unique_contacts.id FROM contact, unique_contacts WHERE contact.nurl = unique_contacts.url AND `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 $sql_extra",
2358 if($type === 'xml') {
2359 header("Content-type: application/xml");
2360 echo '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n" . '<ids>' . "\r\n";
2362 echo '<id>' . $rr['id'] . '</id>' . "\r\n";
2363 echo '</ids>' . "\r\n";
2366 elseif($type === 'json') {
2368 header("Content-type: application/json");
2373 $ret[] = intval($rr['id']);
2375 echo json_encode($ret);
2381 function api_friends_ids(&$a,$type) {
2382 api_ff_ids($a,$type,'friends');
2384 function api_followers_ids(&$a,$type) {
2385 api_ff_ids($a,$type,'followers');
2387 api_register_func('api/friends/ids','api_friends_ids',true);
2388 api_register_func('api/followers/ids','api_followers_ids',true);
2391 function api_direct_messages_new(&$a, $type) {
2392 if (api_user()===false) return false;
2394 if (!x($_POST, "text") OR (!x($_POST,"screen_name") AND !x($_POST,"user_id"))) return;
2396 $sender = api_get_user($a);
2398 require_once("include/message.php");
2400 if ($_POST['screen_name']) {
2401 $r = q("SELECT `id`, `nurl`, `network` FROM `contact` WHERE `uid`=%d AND `nick`='%s'",
2403 dbesc($_POST['screen_name']));
2405 // Selecting the id by priority, friendica first
2406 api_best_nickname($r);
2408 $recipient = api_get_user($a, $r[0]['nurl']);
2410 $recipient = api_get_user($a, $_POST['user_id']);
2414 if (x($_REQUEST,'replyto')) {
2415 $r = q('SELECT `parent-uri`, `title` FROM `mail` WHERE `uid`=%d AND `id`=%d',
2417 intval($_REQUEST['replyto']));
2418 $replyto = $r[0]['parent-uri'];
2419 $sub = $r[0]['title'];
2422 if (x($_REQUEST,'title')) {
2423 $sub = $_REQUEST['title'];
2426 $sub = ((strlen($_POST['text'])>10)?substr($_POST['text'],0,10)."...":$_POST['text']);
2430 $id = send_message($recipient['cid'], $_POST['text'], $sub, $replyto);
2433 $r = q("SELECT * FROM `mail` WHERE id=%d", intval($id));
2434 $ret = api_format_messages($r[0], $recipient, $sender);
2437 $ret = array("error"=>$id);
2440 $data = Array('$messages'=>$ret);
2445 $data = api_rss_extra($a, $data, $user_info);
2448 return api_apply_template("direct_messages", $type, $data);
2451 api_register_func('api/direct_messages/new','api_direct_messages_new',true);
2453 function api_direct_messages_box(&$a, $type, $box) {
2454 if (api_user()===false) return false;
2458 $count = (x($_GET,'count')?$_GET['count']:20);
2459 $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
2460 if ($page<0) $page=0;
2462 $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
2463 $max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
2465 $user_id = (x($_REQUEST,'user_id')?$_REQUEST['user_id']:"");
2466 $screen_name = (x($_REQUEST,'screen_name')?$_REQUEST['screen_name']:"");
2469 unset($_REQUEST["user_id"]);
2470 unset($_GET["user_id"]);
2472 unset($_REQUEST["screen_name"]);
2473 unset($_GET["screen_name"]);
2475 $user_info = api_get_user($a);
2476 //$profile_url = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
2477 $profile_url = $user_info["url"];
2481 $start = $page*$count;
2484 if ($box=="sentbox") {
2485 $sql_extra = "`mail`.`from-url`='".dbesc( $profile_url )."'";
2487 elseif ($box=="conversation") {
2488 $sql_extra = "`mail`.`parent-uri`='".dbesc( $_GET["uri"] ) ."'";
2490 elseif ($box=="all") {
2491 $sql_extra = "true";
2493 elseif ($box=="inbox") {
2494 $sql_extra = "`mail`.`from-url`!='".dbesc( $profile_url )."'";
2498 $sql_extra .= ' AND `mail`.`id` <= '.intval($max_id);
2500 if ($user_id !="") {
2501 $sql_extra .= ' AND `mail`.`contact-id` = ' . intval($user_id);
2503 elseif($screen_name !=""){
2504 $sql_extra .= " AND `contact`.`nick` = '" . dbesc($screen_name). "'";
2507 $r = q("SELECT `mail`.*, `contact`.`nurl` AS `contact-url` FROM `mail`,`contact` WHERE `mail`.`contact-id` = `contact`.`id` AND `mail`.`uid`=%d AND $sql_extra AND `mail`.`id` > %d ORDER BY `mail`.`id` DESC LIMIT %d,%d",
2510 intval($start), intval($count)
2515 foreach($r as $item) {
2516 if ($box == "inbox" || $item['from-url'] != $profile_url){
2517 $recipient = $user_info;
2518 $sender = api_get_user($a,normalise_link($item['contact-url']));
2520 elseif ($box == "sentbox" || $item['from-url'] == $profile_url){
2521 $recipient = api_get_user($a,normalise_link($item['contact-url']));
2522 $sender = $user_info;
2525 $ret[]=api_format_messages($item, $recipient, $sender);
2529 $data = array('$messages' => $ret);
2533 $data = api_rss_extra($a, $data, $user_info);
2536 return api_apply_template("direct_messages", $type, $data);
2540 function api_direct_messages_sentbox(&$a, $type){
2541 return api_direct_messages_box($a, $type, "sentbox");
2543 function api_direct_messages_inbox(&$a, $type){
2544 return api_direct_messages_box($a, $type, "inbox");
2546 function api_direct_messages_all(&$a, $type){
2547 return api_direct_messages_box($a, $type, "all");
2549 function api_direct_messages_conversation(&$a, $type){
2550 return api_direct_messages_box($a, $type, "conversation");
2552 api_register_func('api/direct_messages/conversation','api_direct_messages_conversation',true);
2553 api_register_func('api/direct_messages/all','api_direct_messages_all',true);
2554 api_register_func('api/direct_messages/sent','api_direct_messages_sentbox',true);
2555 api_register_func('api/direct_messages','api_direct_messages_inbox',true);
2559 function api_oauth_request_token(&$a, $type){
2561 $oauth = new FKOAuth1();
2562 $r = $oauth->fetch_request_token(OAuthRequest::from_request());
2563 }catch(Exception $e){
2564 echo "error=". OAuthUtil::urlencode_rfc3986($e->getMessage()); killme();
2569 function api_oauth_access_token(&$a, $type){
2571 $oauth = new FKOAuth1();
2572 $r = $oauth->fetch_access_token(OAuthRequest::from_request());
2573 }catch(Exception $e){
2574 echo "error=". OAuthUtil::urlencode_rfc3986($e->getMessage()); killme();
2580 api_register_func('api/oauth/request_token', 'api_oauth_request_token', false);
2581 api_register_func('api/oauth/access_token', 'api_oauth_access_token', false);
2584 function api_fr_photos_list(&$a,$type) {
2585 if (api_user()===false) return false;
2586 $r = q("select distinct `resource-id` from photo where uid = %d and album != 'Contact Photos' ",
2587 intval(local_user())
2592 $ret[] = $rr['resource-id'];
2593 header("Content-type: application/json");
2594 echo json_encode($ret);
2599 function api_fr_photo_detail(&$a,$type) {
2600 if (api_user()===false) return false;
2601 if(! $_REQUEST['photo_id']) return false;
2602 $scale = ((array_key_exists('scale',$_REQUEST)) ? intval($_REQUEST['scale']) : 0);
2603 $r = q("select * from photo where uid = %d and `resource-id` = '%s' and scale = %d limit 1",
2604 intval(local_user()),
2605 dbesc($_REQUEST['photo_id']),
2609 header("Content-type: application/json");
2610 $r[0]['data'] = base64_encode($r[0]['data']);
2611 echo json_encode($r[0]);
2617 api_register_func('api/friendica/photos/list', 'api_fr_photos_list', true);
2618 api_register_func('api/friendica/photo', 'api_fr_photo_detail', true);
2622 function api_share_as_retweet($a, $uid, &$item) {
2623 $body = trim($item["body"]);
2625 // Skip if it isn't a pure repeated messages
2626 // Does it start with a share?
2627 if (strpos($body, "[share") > 0)
2630 // Does it end with a share?
2631 if (strlen($body) > (strrpos($body, "[/share]") + 8))
2634 $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body);
2635 // Skip if there is no shared message in there
2636 if ($body == $attributes)
2640 preg_match("/author='(.*?)'/ism", $attributes, $matches);
2641 if ($matches[1] != "")
2642 $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
2644 preg_match('/author="(.*?)"/ism', $attributes, $matches);
2645 if ($matches[1] != "")
2646 $author = $matches[1];
2649 preg_match("/profile='(.*?)'/ism", $attributes, $matches);
2650 if ($matches[1] != "")
2651 $profile = $matches[1];
2653 preg_match('/profile="(.*?)"/ism', $attributes, $matches);
2654 if ($matches[1] != "")
2655 $profile = $matches[1];
2658 preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
2659 if ($matches[1] != "")
2660 $avatar = $matches[1];
2662 preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
2663 if ($matches[1] != "")
2664 $avatar = $matches[1];
2666 $shared_body = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$2",$body);
2668 if (($shared_body == "") OR ($profile == "") OR ($author == "") OR ($avatar == ""))
2671 $item["body"] = $shared_body;
2672 $item["author-name"] = $author;
2673 $item["author-link"] = $profile;
2674 $item["author-avatar"] = $avatar;
2680 function api_get_nick($profile) {
2682 - remove trailing jung from profile url
2683 - pump.io check has to check the website
2688 $friendica = preg_replace("=https?://(.*)/profile/(.*)=ism", "$2", $profile);
2689 if ($friendica != $profile)
2693 $diaspora = preg_replace("=https?://(.*)/u/(.*)=ism", "$2", $profile);
2694 if ($diaspora != $profile)
2699 $twitter = preg_replace("=https?://twitter.com/(.*)=ism", "$1", $profile);
2700 if ($twitter != $profile)
2706 $StatusnetHost = preg_replace("=https?://(.*)/user/(.*)=ism", "$1", $profile);
2707 if ($StatusnetHost != $profile) {
2708 $StatusnetUser = preg_replace("=https?://(.*)/user/(.*)=ism", "$2", $profile);
2709 if ($StatusnetUser != $profile) {
2710 $UserData = fetch_url("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser);
2711 $user = json_decode($UserData);
2713 $nick = $user->screen_name;
2718 // To-Do: look at the page if its really a pumpio site
2719 //if (!$nick == "") {
2720 // $pumpio = preg_replace("=https?://(.*)/(.*)/=ism", "$2", $profile."/");
2721 // if ($pumpio != $profile)
2723 // <div class="media" id="profile-block" data-profile-id="acct:kabniel@microca.st">
2728 q("UPDATE unique_contacts SET nick = '%s' WHERE url = '%s'",
2729 dbesc($nick), dbesc(normalise_link($profile)));
2736 function api_clean_plain_items($Text) {
2737 $include_entities = strtolower(x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:"false");
2739 $Text = bb_CleanPictureLinks($Text);
2741 $URLSearchString = "^\[\]";
2743 $Text = preg_replace("/([!#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",'$1$3',$Text);
2745 if ($include_entities == "true") {
2746 $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",'[url=$1]$1[/url]',$Text);
2749 $Text = preg_replace_callback("((.*?)\[class=(.*?)\](.*?)\[\/class\])ism","api_cleanup_share",$Text);
2753 function api_cleanup_share($shared) {
2754 if ($shared[2] != "type-link")
2757 if (!preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",$shared[3], $bookmark))
2763 if (isset($bookmark[2][0]))
2764 $title = $bookmark[2][0];
2766 if (isset($bookmark[1][0]))
2767 $link = $bookmark[1][0];
2769 if (strpos($shared[1],$title) !== false)
2772 if (strpos($shared[1],$link) !== false)
2775 $text = trim($shared[1]);
2777 //if (strlen($text) < strlen($title))
2778 if (($text == "") AND ($title != ""))
2779 $text .= "\n\n".trim($title);
2782 $text .= "\n".trim($link);
2784 return(trim($text));
2787 function api_best_nickname(&$contacts) {
2788 $best_contact = array();
2790 if (count($contact) == 0)
2793 foreach ($contacts AS $contact)
2794 if ($contact["network"] == "") {
2795 $contact["network"] = "dfrn";
2796 $best_contact = array($contact);
2799 if (sizeof($best_contact) == 0)
2800 foreach ($contacts AS $contact)
2801 if ($contact["network"] == "dfrn")
2802 $best_contact = array($contact);
2804 if (sizeof($best_contact) == 0)
2805 foreach ($contacts AS $contact)
2806 if ($contact["network"] == "dspr")
2807 $best_contact = array($contact);
2809 if (sizeof($best_contact) == 0)
2810 foreach ($contacts AS $contact)
2811 if ($contact["network"] == "stat")
2812 $best_contact = array($contact);
2814 if (sizeof($best_contact) == 0)
2815 foreach ($contacts AS $contact)
2816 if ($contact["network"] == "pump")
2817 $best_contact = array($contact);
2819 if (sizeof($best_contact) == 0)
2820 foreach ($contacts AS $contact)
2821 if ($contact["network"] == "twit")
2822 $best_contact = array($contact);
2824 if (sizeof($best_contact) == 1)
2825 $contacts = $best_contact;
2827 $contacts = array($contacts[0]);
2831 Not implemented by now:
2832 statuses/retweets_of_me
2837 account/update_location
2838 account/update_profile_background_image
2839 account/update_profile_image
2843 Not implemented in status.net:
2844 statuses/retweeted_to_me
2845 statuses/retweeted_by_me
2846 direct_messages/destroy
2848 account/update_delivery_device
2849 notifications/follow