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");
10 require_once("mod/share.php");
20 // It is not sufficient to use local_user() to check whether someone is allowed to use the API,
21 // because this will open CSRF holes (just embed an image with src=friendicasite.com/api/statuses/update?status=CSRF
22 // into a page, and visitors will post something without noticing it).
23 // Instead, use this function.
24 if ($_SESSION["allow_api"])
30 function api_source() {
31 if (requestdata('source'))
32 return (requestdata('source'));
34 // Support for known clients that doesn't send a source name
35 if (strstr($_SERVER['HTTP_USER_AGENT'], "Twidere"))
38 logger("Unrecognized user-agent ".$_SERVER['HTTP_USER_AGENT'], LOGGER_DEBUG);
43 function api_date($str){
44 //Wed May 23 06:01:13 +0000 2007
45 return datetime_convert('UTC', 'UTC', $str, "D M d H:i:s +0000 Y" );
49 function api_register_func($path, $func, $auth=false){
51 $API[$path] = array('func'=>$func, 'auth'=>$auth);
53 // Workaround for hotot
54 $path = str_replace("api/", "api/1.1/", $path);
55 $API[$path] = array('func'=>$func, 'auth'=>$auth);
62 function api_login(&$a){
65 $oauth = new FKOAuth1();
66 list($consumer,$token) = $oauth->verify_request(OAuthRequest::from_request());
67 if (!is_null($token)){
68 $oauth->loginUser($token->uid);
69 call_hooks('logged_in', $a->user);
72 echo __file__.__line__.__function__."<pre>"; var_dump($consumer, $token); die();
74 logger(__file__.__line__.__function__."\n".$e);
75 //die(__file__.__line__.__function__."<pre>".$e); die();
80 // workaround for HTTP-auth in CGI mode
81 if(x($_SERVER,'REDIRECT_REMOTE_USER')) {
82 $userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"],6)) ;
83 if(strlen($userpass)) {
84 list($name, $password) = explode(':', $userpass);
85 $_SERVER['PHP_AUTH_USER'] = $name;
86 $_SERVER['PHP_AUTH_PW'] = $password;
90 if (!isset($_SERVER['PHP_AUTH_USER'])) {
91 logger('API_login: ' . print_r($_SERVER,true), LOGGER_DEBUG);
92 header('WWW-Authenticate: Basic realm="Friendica"');
93 header('HTTP/1.0 401 Unauthorized');
94 die((api_error($a, 'json', "This api requires login")));
96 //die('This api requires login');
99 $user = $_SERVER['PHP_AUTH_USER'];
100 $password = $_SERVER['PHP_AUTH_PW'];
101 $encrypted = hash('whirlpool',trim($password));
105 * next code from mod/auth.php. needs better solution
110 'username' => trim($user),
111 'password' => trim($password),
112 'authenticated' => 0,
113 'user_record' => null
118 * A plugin indicates successful login by setting 'authenticated' to non-zero value and returning a user record
119 * Plugins should never set 'authenticated' except to indicate success - as hooks may be chained
120 * and later plugins should not interfere with an earlier one that succeeded.
124 call_hooks('authenticate', $addon_auth);
126 if(($addon_auth['authenticated']) && (count($addon_auth['user_record']))) {
127 $record = $addon_auth['user_record'];
130 // process normal login request
132 $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' )
133 AND `password` = '%s' AND `blocked` = 0 AND `account_expired` = 0 AND `account_removed` = 0 AND `verified` = 1 LIMIT 1",
142 if((! $record) || (! count($record))) {
143 logger('API_login failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
144 header('WWW-Authenticate: Basic realm="Friendica"');
145 header('HTTP/1.0 401 Unauthorized');
146 die('This api requires login');
149 require_once('include/security.php');
150 authenticate_success($record); $_SESSION["allow_api"] = true;
152 call_hooks('logged_in', $a->user);
156 /**************************
157 * MAIN API ENTRY POINT *
158 **************************/
159 function api_call(&$a){
160 GLOBAL $API, $called_api;
164 foreach ($API as $p=>$info){
165 if (strpos($a->query_string, $p)===0){
166 $called_api= explode("/",$p);
167 //unset($_SERVER['PHP_AUTH_USER']);
168 if ($info['auth']===true && api_user()===false) {
172 load_contact_links(api_user());
174 logger('API call for ' . $a->user['username'] . ': ' . $a->query_string);
175 logger('API parameters: ' . print_r($_REQUEST,true));
177 if (strpos($a->query_string, ".xml")>0) $type="xml";
178 if (strpos($a->query_string, ".json")>0) $type="json";
179 if (strpos($a->query_string, ".rss")>0) $type="rss";
180 if (strpos($a->query_string, ".atom")>0) $type="atom";
181 if (strpos($a->query_string, ".as")>0) $type="as";
183 $r = call_user_func($info['func'], $a, $type);
184 if ($r===false) return;
188 $r = mb_convert_encoding($r, "UTF-8",mb_detect_encoding($r));
189 header ("Content-Type: text/xml");
190 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
193 header ("Content-Type: application/json");
195 $json = json_encode($rr);
196 if ($_GET['callback'])
197 $json = $_GET['callback']."(".$json.")";
201 header ("Content-Type: application/rss+xml");
202 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
205 header ("Content-Type: application/atom+xml");
206 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
209 //header ("Content-Type: application/json");
211 // return json_encode($rr);
212 return json_encode($r);
216 //echo "<pre>"; var_dump($r); die();
219 header("HTTP/1.1 404 Not Found");
220 logger('API call not implemented: '.$a->query_string." - ".print_r($_REQUEST,true));
221 return(api_error($a, $type, "not implemented"));
225 function api_error(&$a, $type, $error) {
226 # TODO: https://dev.twitter.com/overview/api/response-codes
227 $r = "<status><error>".$error."</error><request>".$a->query_string."</request></status>";
230 header ("Content-Type: text/xml");
231 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
234 header ("Content-Type: application/json");
235 return json_encode(array('error' => $error, 'request' => $a->query_string));
238 header ("Content-Type: application/rss+xml");
239 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
242 header ("Content-Type: application/atom+xml");
243 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
251 function api_rss_extra(&$a, $arr, $user_info){
252 if (is_null($user_info)) $user_info = api_get_user($a);
253 $arr['$user'] = $user_info;
254 $arr['$rss'] = array(
255 'alternate' => $user_info['url'],
256 'self' => $a->get_baseurl(). "/". $a->query_string,
257 'base' => $a->get_baseurl(),
258 'updated' => api_date(null),
259 'atom_updated' => datetime_convert('UTC','UTC','now',ATOM_TIME),
260 'language' => $user_info['language'],
261 'logo' => $a->get_baseurl()."/images/friendica-32.png",
269 * Unique contact to contact url.
271 function api_unique_id_to_url($id){
272 $r = q("SELECT url FROM unique_contacts WHERE id=%d LIMIT 1",
275 return ($r[0]["url"]);
281 * Returns user info array.
283 function api_get_user(&$a, $contact_id = Null, $type = "json"){
290 logger("api_get_user: Fetching user data for user ".$contact_id, LOGGER_DEBUG);
292 // Searching for contact URL
293 if(!is_null($contact_id) AND (intval($contact_id) == 0)){
294 $user = dbesc(normalise_link($contact_id));
296 $extra_query = "AND `contact`.`nurl` = '%s' ";
297 if (api_user()!==false) $extra_query .= "AND `contact`.`uid`=".intval(api_user());
300 // Searching for unique contact id
301 if(!is_null($contact_id) AND (intval($contact_id) != 0)){
302 $user = dbesc(api_unique_id_to_url($contact_id));
305 die(api_error($a, $type, t("User not found.")));
308 $extra_query = "AND `contact`.`nurl` = '%s' ";
309 if (api_user()!==false) $extra_query .= "AND `contact`.`uid`=".intval(api_user());
312 if(is_null($user) && x($_GET, 'user_id')) {
313 $user = dbesc(api_unique_id_to_url($_GET['user_id']));
316 die(api_error($a, $type, t("User not found.")));
319 $extra_query = "AND `contact`.`nurl` = '%s' ";
320 if (api_user()!==false) $extra_query .= "AND `contact`.`uid`=".intval(api_user());
322 if(is_null($user) && x($_GET, 'screen_name')) {
323 $user = dbesc($_GET['screen_name']);
325 $extra_query = "AND `contact`.`nick` = '%s' ";
326 if (api_user()!==false) $extra_query .= "AND `contact`.`uid`=".intval(api_user());
329 if (is_null($user) AND ($a->argc > (count($called_api)-1)) AND (count($called_api) > 0)){
330 $argid = count($called_api);
331 list($user, $null) = explode(".",$a->argv[$argid]);
332 if(is_numeric($user)){
333 $user = dbesc(api_unique_id_to_url($user));
339 $extra_query = "AND `contact`.`nurl` = '%s' ";
340 if (api_user()!==false) $extra_query .= "AND `contact`.`uid`=".intval(api_user());
342 $user = dbesc($user);
344 $extra_query = "AND `contact`.`nick` = '%s' ";
345 if (api_user()!==false) $extra_query .= "AND `contact`.`uid`=".intval(api_user());
349 logger("api_get_user: user ".$user, LOGGER_DEBUG);
352 if (api_user()===false) {
353 api_login($a); return False;
355 $user = $_SESSION['uid'];
356 $extra_query = "AND `contact`.`uid` = %d AND `contact`.`self` = 1 ";
361 logger('api_user: ' . $extra_query . ', user: ' . $user);
363 $uinfo = q("SELECT *, `contact`.`id` as `cid` FROM `contact`
369 // Selecting the id by priority, friendica first
370 api_best_nickname($uinfo);
372 // if the contact wasn't found, fetch it from the unique contacts
373 if (count($uinfo)==0) {
377 $r = q("SELECT * FROM unique_contacts WHERE url='%s' LIMIT 1", $url);
379 $r = q("SELECT * FROM unique_contacts WHERE nick='%s' LIMIT 1", $nick);
382 // If no nick where given, extract it from the address
383 if (($r[0]['nick'] == "") OR ($r[0]['name'] == $r[0]['nick']))
384 $r[0]['nick'] = api_get_nick($r[0]["url"]);
388 'id_str' => (string) $r[0]["id"],
389 'name' => $r[0]["name"],
390 'screen_name' => (($r[0]['nick']) ? $r[0]['nick'] : $r[0]['name']),
392 'description' => NULL,
393 'profile_image_url' => $r[0]["avatar"],
394 'profile_image_url_https' => $r[0]["avatar"],
395 'url' => $r[0]["url"],
396 'protected' => false,
397 'followers_count' => 0,
398 'friends_count' => 0,
399 'created_at' => api_date(0),
400 'favourites_count' => 0,
402 'time_zone' => 'UTC',
403 'statuses_count' => 0,
404 'following' => false,
406 'statusnet_blocking' => false,
407 'notifications' => false,
408 'statusnet_profile_url' => $r[0]["url"],
417 die(api_error($a, $type, t("User not found.")));
421 if($uinfo[0]['self']) {
422 $usr = q("select * from user where uid = %d limit 1",
425 $profile = q("select * from profile where uid = %d and `is-default` = 1 limit 1",
429 //AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
430 // count public wall messages
431 $r = q("SELECT count(*) as `count` FROM `item`
434 intval($uinfo[0]['uid'])
436 $countitms = $r[0]['count'];
439 //AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
440 $r = q("SELECT count(*) as `count` FROM `item`
441 WHERE `contact-id` = %d",
442 intval($uinfo[0]['id'])
444 $countitms = $r[0]['count'];
448 $r = q("SELECT count(*) as `count` FROM `contact`
449 WHERE `uid` = %d AND `rel` IN ( %d, %d )
450 AND `self`=0 AND `blocked`=0 AND `pending`=0 AND `hidden`=0",
451 intval($uinfo[0]['uid']),
452 intval(CONTACT_IS_SHARING),
453 intval(CONTACT_IS_FRIEND)
455 $countfriends = $r[0]['count'];
457 $r = q("SELECT count(*) as `count` FROM `contact`
458 WHERE `uid` = %d AND `rel` IN ( %d, %d )
459 AND `self`=0 AND `blocked`=0 AND `pending`=0 AND `hidden`=0",
460 intval($uinfo[0]['uid']),
461 intval(CONTACT_IS_FOLLOWER),
462 intval(CONTACT_IS_FRIEND)
464 $countfollowers = $r[0]['count'];
466 $r = q("SELECT count(*) as `count` FROM item where starred = 1 and uid = %d and deleted = 0",
467 intval($uinfo[0]['uid'])
469 $starred = $r[0]['count'];
472 if(! $uinfo[0]['self']) {
478 // Add a nick if it isn't present there
479 if (($uinfo[0]['nick'] == "") OR ($uinfo[0]['name'] == $uinfo[0]['nick'])) {
480 $uinfo[0]['nick'] = api_get_nick($uinfo[0]["url"]);
483 // Fetching unique id
484 $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", dbesc(normalise_link($uinfo[0]['url'])));
486 // If not there, then add it
487 if (count($r) == 0) {
488 q("INSERT INTO unique_contacts (url, name, nick, avatar) VALUES ('%s', '%s', '%s', '%s')",
489 dbesc(normalise_link($uinfo[0]['url'])), dbesc($uinfo[0]['name']),dbesc($uinfo[0]['nick']), dbesc($uinfo[0]['micro']));
491 $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", dbesc(normalise_link($uinfo[0]['url'])));
494 require_once('include/contact_selectors.php');
495 $network_name = network_to_name($uinfo[0]['network']);
498 'id' => intval($r[0]['id']),
499 'id_str' => (string) intval($r[0]['id']),
500 'name' => (($uinfo[0]['name']) ? $uinfo[0]['name'] : $uinfo[0]['nick']),
501 'screen_name' => (($uinfo[0]['nick']) ? $uinfo[0]['nick'] : $uinfo[0]['name']),
502 'location' => ($usr) ? $usr[0]['default-location'] : $network_name,
503 'description' => (($profile) ? $profile[0]['pdesc'] : NULL),
504 'profile_image_url' => $uinfo[0]['micro'],
505 'profile_image_url_https' => $uinfo[0]['micro'],
506 'url' => $uinfo[0]['url'],
507 'protected' => false,
508 'followers_count' => intval($countfollowers),
509 'friends_count' => intval($countfriends),
510 'created_at' => api_date($uinfo[0]['created']),
511 'favourites_count' => intval($starred),
513 'time_zone' => 'UTC',
514 'statuses_count' => intval($countitms),
515 'following' => (($uinfo[0]['rel'] == CONTACT_IS_FOLLOWER) OR ($uinfo[0]['rel'] == CONTACT_IS_FRIEND)),
517 'statusnet_blocking' => false,
518 'notifications' => false,
519 'statusnet_profile_url' => $a->get_baseurl()."/contacts/".$uinfo[0]['cid'],
520 'uid' => intval($uinfo[0]['uid']),
521 'cid' => intval($uinfo[0]['cid']),
522 'self' => $uinfo[0]['self'],
523 'network' => $uinfo[0]['network'],
530 function api_item_get_user(&$a, $item) {
532 $author = q("SELECT * FROM unique_contacts WHERE url='%s' LIMIT 1",
533 dbesc(normalise_link($item['author-link'])));
535 if (count($author) == 0) {
536 q("INSERT INTO unique_contacts (url, name, avatar) VALUES ('%s', '%s', '%s')",
537 dbesc(normalise_link($item["author-link"])), dbesc($item["author-name"]), dbesc($item["author-avatar"]));
539 $author = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1",
540 dbesc(normalise_link($item['author-link'])));
541 } else if ($item["author-link"].$item["author-name"] != $author[0]["url"].$author[0]["name"]) {
542 q("UPDATE unique_contacts SET name = '%s', avatar = '%s' WHERE url = '%s'",
543 dbesc($item["author-name"]), dbesc($item["author-avatar"]), dbesc(normalise_link($item["author-link"])));
546 $owner = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1",
547 dbesc(normalise_link($item['owner-link'])));
549 if (count($owner) == 0) {
550 q("INSERT INTO unique_contacts (url, name, avatar) VALUES ('%s', '%s', '%s')",
551 dbesc(normalise_link($item["owner-link"])), dbesc($item["owner-name"]), dbesc($item["owner-avatar"]));
553 $owner = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1",
554 dbesc(normalise_link($item['owner-link'])));
555 } else if ($item["owner-link"].$item["owner-name"] != $owner[0]["url"].$owner[0]["name"]) {
556 q("UPDATE unique_contacts SET name = '%s', avatar = '%s' WHERE url = '%s'",
557 dbesc($item["owner-name"]), dbesc($item["owner-avatar"]), dbesc(normalise_link($item["owner-link"])));
560 // Comments in threads may appear as wall-to-wall postings.
561 // So only take the owner at the top posting.
562 if ($item["id"] == $item["parent"])
563 $status_user = api_get_user($a,$item["owner-link"]);
565 $status_user = api_get_user($a,$item["author-link"]);
567 $status_user["protected"] = (($item["allow_cid"] != "") OR
568 ($item["allow_gid"] != "") OR
569 ($item["deny_cid"] != "") OR
570 ($item["deny_gid"] != "") OR
573 return ($status_user);
578 * load api $templatename for $type and replace $data array
580 function api_apply_template($templatename, $type, $data){
588 $data = array_xmlify($data);
589 $tpl = get_markup_template("api_".$templatename."_".$type.".tpl");
591 header ("Content-Type: text/xml");
592 echo '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<status><error>not implemented</error></status>';
595 $ret = replace_macros($tpl, $data);
610 * Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful;
611 * returns a 401 status code and an error message if not.
612 * http://developer.twitter.com/doc/get/account/verify_credentials
614 function api_account_verify_credentials(&$a, $type){
615 if (api_user()===false) return false;
617 unset($_REQUEST["user_id"]);
618 unset($_GET["user_id"]);
620 unset($_REQUEST["screen_name"]);
621 unset($_GET["screen_name"]);
623 $skip_status = (x($_REQUEST,'skip_status')?$_REQUEST['skip_status']:false);
625 $user_info = api_get_user($a);
627 // "verified" isn't used here in the standard
628 unset($user_info["verified"]);
630 // - Adding last status
632 $user_info["status"] = api_status_show($a,"raw");
633 if (!count($user_info["status"]))
634 unset($user_info["status"]);
636 unset($user_info["status"]["user"]);
639 // "uid" and "self" are only needed for some internal stuff, so remove it from here
640 unset($user_info["uid"]);
641 unset($user_info["self"]);
643 return api_apply_template("user", $type, array('$user' => $user_info));
646 api_register_func('api/account/verify_credentials','api_account_verify_credentials', true);
650 * get data from $_POST or $_GET
652 function requestdata($k){
653 if (isset($_POST[$k])){
656 if (isset($_GET[$k])){
662 /*Waitman Gobble Mod*/
663 function api_statuses_mediap(&$a, $type) {
664 if (api_user()===false) {
665 logger('api_statuses_update: no user');
668 $user_info = api_get_user($a);
670 $_REQUEST['type'] = 'wall';
671 $_REQUEST['profile_uid'] = api_user();
672 $_REQUEST['api_source'] = true;
673 $txt = requestdata('status');
674 //$txt = urldecode(requestdata('status'));
676 require_once('library/HTMLPurifier.auto.php');
677 require_once('include/html2bbcode.php');
679 if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
680 $txt = html2bb_video($txt);
681 $config = HTMLPurifier_Config::createDefault();
682 $config->set('Cache.DefinitionImpl', null);
683 $purifier = new HTMLPurifier($config);
684 $txt = $purifier->purify($txt);
686 $txt = html2bbcode($txt);
688 $a->argv[1]=$user_info['screen_name']; //should be set to username?
690 $_REQUEST['hush']='yeah'; //tell wall_upload function to return img info instead of echo
691 require_once('mod/wall_upload.php');
692 $bebop = wall_upload_post($a);
694 //now that we have the img url in bbcode we can add it to the status and insert the wall item.
695 $_REQUEST['body']=$txt."\n\n".$bebop;
696 require_once('mod/item.php');
699 // this should output the last post (the one we just posted).
700 return api_status_show($a,$type);
702 api_register_func('api/statuses/mediap','api_statuses_mediap', true);
703 /*Waitman Gobble Mod*/
706 function api_statuses_update(&$a, $type) {
707 if (api_user()===false) {
708 logger('api_statuses_update: no user');
712 $user_info = api_get_user($a);
714 // convert $_POST array items to the form we use for web posts.
716 // logger('api_post: ' . print_r($_POST,true));
718 if(requestdata('htmlstatus')) {
719 require_once('library/HTMLPurifier.auto.php');
720 require_once('include/html2bbcode.php');
722 $txt = requestdata('htmlstatus');
723 if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
725 $txt = html2bb_video($txt);
727 $config = HTMLPurifier_Config::createDefault();
728 $config->set('Cache.DefinitionImpl', null);
731 $purifier = new HTMLPurifier($config);
732 $txt = $purifier->purify($txt);
734 $_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';
816 if(x($_FILES,'media')) {
817 // upload the image if we have one
818 $_REQUEST['hush']='yeah'; //tell wall_upload function to return img info instead of echo
819 require_once('mod/wall_upload.php');
820 $media = wall_upload_post($a);
822 $_REQUEST['body'] .= "\n\n".$media;
825 // set this so that the item_post() function is quiet and doesn't redirect or emit json
827 $_REQUEST['api_source'] = true;
829 if (!x($_REQUEST, "source"))
830 $_REQUEST["source"] = api_source();
832 // call out normal post function
834 require_once('mod/item.php');
837 // this should output the last post (the one we just posted).
838 return api_status_show($a,$type);
840 api_register_func('api/statuses/update','api_statuses_update', true);
841 api_register_func('api/statuses/update_with_media','api_statuses_update', true);
844 function api_status_show(&$a, $type){
845 $user_info = api_get_user($a);
847 logger('api_status_show: user_info: '.print_r($user_info, true), LOGGER_DEBUG);
849 // get last public wall message
850 $lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `i`.`author-link` AS `item-author`
851 FROM `item`, `item` as `i`
852 WHERE `item`.`contact-id` = %d AND `item`.`uid` = %d
853 AND ((`item`.`author-link` IN ('%s', '%s')) OR (`item`.`owner-link` IN ('%s', '%s')))
854 AND `i`.`id` = `item`.`parent`
855 AND `item`.`type`!='activity'
856 AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''
857 ORDER BY `item`.`created` DESC
859 intval($user_info['cid']),
861 dbesc($user_info['url']),
862 dbesc(normalise_link($user_info['url'])),
863 dbesc($user_info['url']),
864 dbesc(normalise_link($user_info['url']))
867 if (count($lastwall)>0){
868 $lastwall = $lastwall[0];
870 $in_reply_to_status_id = NULL;
871 $in_reply_to_user_id = NULL;
872 $in_reply_to_status_id_str = NULL;
873 $in_reply_to_user_id_str = NULL;
874 $in_reply_to_screen_name = NULL;
875 if (intval($lastwall['parent']) != intval($lastwall['id'])) {
876 $in_reply_to_status_id= intval($lastwall['parent']);
877 $in_reply_to_status_id_str = (string) intval($lastwall['parent']);
879 $r = q("SELECT * FROM unique_contacts WHERE `url` = '%s'", dbesc(normalise_link($lastwall['item-author'])));
881 if ($r[0]['nick'] == "")
882 $r[0]['nick'] = api_get_nick($r[0]["url"]);
884 $in_reply_to_screen_name = (($r[0]['nick']) ? $r[0]['nick'] : $r[0]['name']);
885 $in_reply_to_user_id = intval($r[0]['id']);
886 $in_reply_to_user_id_str = (string) intval($r[0]['id']);
890 // There seems to be situation, where both fields are identical:
891 // https://github.com/friendica/friendica/issues/1010
892 // This is a bugfix for that.
893 if (intval($in_reply_to_status_id) == intval($lastwall['id'])) {
894 logger('api_status_show: this message should never appear: id: '.$lastwall['id'].' similar to reply-to: '.$in_reply_to_status_id, LOGGER_DEBUG);
895 $in_reply_to_status_id = NULL;
896 $in_reply_to_user_id = NULL;
897 $in_reply_to_status_id_str = NULL;
898 $in_reply_to_user_id_str = NULL;
899 $in_reply_to_screen_name = NULL;
902 $converted = api_convert_item($item);
904 $status_info = array(
905 'text' => $converted["text"],
906 'truncated' => false,
907 'created_at' => api_date($lastwall['created']),
908 'in_reply_to_status_id' => $in_reply_to_status_id,
909 'in_reply_to_status_id_str' => $in_reply_to_status_id_str,
910 'source' => (($lastwall['app']) ? $lastwall['app'] : 'web'),
911 'id' => intval($lastwall['id']),
912 'id_str' => (string) $lastwall['id'],
913 'in_reply_to_user_id' => $in_reply_to_user_id,
914 'in_reply_to_user_id_str' => $in_reply_to_user_id_str,
915 'in_reply_to_screen_name' => $in_reply_to_screen_name,
917 'favorited' => $lastwall['starred'] ? true : false,
918 'user' => $user_info,
919 'statusnet_html' => $converted["html"],
920 'statusnet_conversation_id' => $lastwall['parent'],
923 if (count($converted["attachments"]) > 0)
924 $status_info["attachments"] = $converted["attachments"];
926 if (count($converted["entities"]) > 0)
927 $status_info["entities"] = $converted["entities"];
929 if (($lastwall['item_network'] != "") AND ($status["source"] == 'web'))
930 $status_info["source"] = network_to_name($lastwall['item_network']);
931 elseif (($lastwall['item_network'] != "") AND (network_to_name($lastwall['item_network']) != $status_info["source"]))
932 $status_info["source"] = trim($status_info["source"].' ('.network_to_name($lastwall['item_network']).')');
934 // "uid" and "self" are only needed for some internal stuff, so remove it from here
935 unset($status_info["user"]["uid"]);
936 unset($status_info["user"]["self"]);
940 return($status_info);
942 return api_apply_template("status", $type, array('$status' => $status_info));
951 * Returns extended information of a given user, specified by ID or screen name as per the required id parameter.
952 * The author's most recent status will be returned inline.
953 * http://developer.twitter.com/doc/get/users/show
955 function api_users_show(&$a, $type){
956 $user_info = api_get_user($a);
958 $lastwall = q("SELECT `item`.*
959 FROM `item`, `contact`
960 WHERE `item`.`uid` = %d AND `verb` = '%s' AND `item`.`contact-id` = %d
961 AND ((`item`.`author-link` IN ('%s', '%s')) OR (`item`.`owner-link` IN ('%s', '%s')))
962 AND `contact`.`id`=`item`.`contact-id`
963 AND `type`!='activity'
964 AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''
965 ORDER BY `created` DESC
968 dbesc(ACTIVITY_POST),
969 intval($user_info['cid']),
970 dbesc($user_info['url']),
971 dbesc(normalise_link($user_info['url'])),
972 dbesc($user_info['url']),
973 dbesc(normalise_link($user_info['url']))
975 if (count($lastwall)>0){
976 $lastwall = $lastwall[0];
978 $in_reply_to_status_id = NULL;
979 $in_reply_to_user_id = NULL;
980 $in_reply_to_status_id_str = NULL;
981 $in_reply_to_user_id_str = NULL;
982 $in_reply_to_screen_name = NULL;
983 if ($lastwall['parent']!=$lastwall['id']) {
984 $reply = q("SELECT `item`.`id`, `item`.`contact-id` as `reply_uid`, `contact`.`nick` as `reply_author`, `item`.`author-link` AS `item-author`
985 FROM `item`,`contact` WHERE `contact`.`id`=`item`.`contact-id` AND `item`.`id` = %d", intval($lastwall['parent']));
986 if (count($reply)>0) {
987 $in_reply_to_status_id = intval($lastwall['parent']);
988 $in_reply_to_status_id_str = (string) intval($lastwall['parent']);
990 $r = q("SELECT * FROM unique_contacts WHERE `url` = '%s'", dbesc(normalise_link($reply[0]['item-author'])));
992 if ($r[0]['nick'] == "")
993 $r[0]['nick'] = api_get_nick($r[0]["url"]);
995 $in_reply_to_screen_name = (($r[0]['nick']) ? $r[0]['nick'] : $r[0]['name']);
996 $in_reply_to_user_id = intval($r[0]['id']);
997 $in_reply_to_user_id_str = (string) intval($r[0]['id']);
1002 $converted = api_convert_item($item);
1004 $user_info['status'] = array(
1005 'text' => $converted["text"],
1006 'truncated' => false,
1007 'created_at' => api_date($lastwall['created']),
1008 'in_reply_to_status_id' => $in_reply_to_status_id,
1009 'in_reply_to_status_id_str' => $in_reply_to_status_id_str,
1010 'source' => (($lastwall['app']) ? $lastwall['app'] : 'web'),
1011 'id' => intval($lastwall['contact-id']),
1012 'id_str' => (string) $lastwall['contact-id'],
1013 'in_reply_to_user_id' => $in_reply_to_user_id,
1014 'in_reply_to_user_id_str' => $in_reply_to_user_id_str,
1015 'in_reply_to_screen_name' => $in_reply_to_screen_name,
1017 'favorited' => $lastwall['starred'] ? true : false,
1018 'statusnet_html' => $converted["html"],
1019 'statusnet_conversation_id' => $lastwall['parent'],
1022 if (count($converted["attachments"]) > 0)
1023 $user_info["status"]["attachments"] = $converted["attachments"];
1025 if (count($converted["entities"]) > 0)
1026 $user_info["status"]["entities"] = $converted["entities"];
1028 if (($lastwall['item_network'] != "") AND ($user_info["status"]["source"] == 'web'))
1029 $user_info["status"]["source"] = network_to_name($lastwall['item_network']);
1030 if (($lastwall['item_network'] != "") AND (network_to_name($lastwall['item_network']) != $user_info["status"]["source"]))
1031 $user_info["status"]["source"] = trim($user_info["status"]["source"].' ('.network_to_name($lastwall['item_network']).')');
1035 // "uid" and "self" are only needed for some internal stuff, so remove it from here
1036 unset($user_info["uid"]);
1037 unset($user_info["self"]);
1039 return api_apply_template("user", $type, array('$user' => $user_info));
1042 api_register_func('api/users/show','api_users_show');
1045 function api_users_search(&$a, $type) {
1046 $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
1048 $userlist = array();
1050 if (isset($_GET["q"])) {
1051 $r = q("SELECT id FROM unique_contacts WHERE name='%s'", dbesc($_GET["q"]));
1053 $r = q("SELECT id FROM unique_contacts WHERE nick='%s'", dbesc($_GET["q"]));
1056 foreach ($r AS $user) {
1057 $user_info = api_get_user($a, $user["id"]);
1058 //echo print_r($user_info, true)."\n";
1059 $userdata = api_apply_template("user", $type, array('user' => $user_info));
1060 $userlist[] = $userdata["user"];
1062 $userlist = array("users" => $userlist);
1064 die(api_error($a, $type, t("User not found.")));
1066 die(api_error($a, $type, t("User not found.")));
1071 api_register_func('api/users/search','api_users_search');
1075 * http://developer.twitter.com/doc/get/statuses/home_timeline
1077 * TODO: Optional parameters
1078 * TODO: Add reply info
1080 function api_statuses_home_timeline(&$a, $type){
1081 if (api_user()===false) return false;
1083 unset($_REQUEST["user_id"]);
1084 unset($_GET["user_id"]);
1086 unset($_REQUEST["screen_name"]);
1087 unset($_GET["screen_name"]);
1089 $user_info = api_get_user($a);
1090 // get last newtork messages
1094 $count = (x($_REQUEST,'count')?$_REQUEST['count']:20);
1095 $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
1096 if ($page<0) $page=0;
1097 $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
1098 $max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
1099 //$since_id = 0;//$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
1100 $exclude_replies = (x($_REQUEST,'exclude_replies')?1:0);
1101 $conversation_id = (x($_REQUEST,'conversation_id')?$_REQUEST['conversation_id']:0);
1103 $start = $page*$count;
1107 $sql_extra .= ' AND `item`.`id` <= '.intval($max_id);
1108 if ($exclude_replies > 0)
1109 $sql_extra .= ' AND `item`.`parent` = `item`.`id`';
1110 if ($conversation_id > 0)
1111 $sql_extra .= ' AND `item`.`parent` = '.intval($conversation_id);
1113 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
1114 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
1115 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
1116 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1117 FROM `item`, `contact`
1118 WHERE `item`.`uid` = %d AND `verb` = '%s'
1119 AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
1120 AND `contact`.`id` = `item`.`contact-id`
1121 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1124 ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
1126 dbesc(ACTIVITY_POST),
1128 intval($start), intval($count)
1131 $ret = api_format_items($r,$user_info);
1133 // Set all posts from the query above to seen
1135 foreach ($r AS $item)
1136 $idarray[] = intval($item["id"]);
1138 $idlist = implode(",", $idarray);
1140 $r = q("UPDATE `item` SET `unseen` = 0 WHERE `unseen` AND `id` IN (%s)", $idlist);
1143 $data = array('$statuses' => $ret);
1147 $data = api_rss_extra($a, $data, $user_info);
1150 $as = api_format_as($a, $ret, $user_info);
1151 $as['title'] = $a->config['sitename']." Home Timeline";
1152 $as['link']['url'] = $a->get_baseurl()."/".$user_info["screen_name"]."/all";
1157 return api_apply_template("timeline", $type, $data);
1159 api_register_func('api/statuses/home_timeline','api_statuses_home_timeline', true);
1160 api_register_func('api/statuses/friends_timeline','api_statuses_home_timeline', true);
1162 function api_statuses_public_timeline(&$a, $type){
1163 if (api_user()===false) return false;
1165 $user_info = api_get_user($a);
1166 // get last newtork messages
1170 $count = (x($_REQUEST,'count')?$_REQUEST['count']:20);
1171 $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
1172 if ($page<0) $page=0;
1173 $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
1174 $max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
1175 //$since_id = 0;//$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
1176 $exclude_replies = (x($_REQUEST,'exclude_replies')?1:0);
1177 $conversation_id = (x($_REQUEST,'conversation_id')?$_REQUEST['conversation_id']:0);
1179 $start = $page*$count;
1182 $sql_extra = 'AND `item`.`id` <= '.intval($max_id);
1183 if ($exclude_replies > 0)
1184 $sql_extra .= ' AND `item`.`parent` = `item`.`id`';
1185 if ($conversation_id > 0)
1186 $sql_extra .= ' AND `item`.`parent` = '.intval($conversation_id);
1188 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
1189 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
1190 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
1191 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
1192 `user`.`nickname`, `user`.`hidewall`
1193 FROM `item` STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1194 STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid`
1195 WHERE `verb` = '%s' AND `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1196 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
1197 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
1198 AND `item`.`private` = 0 AND `item`.`wall` = 1 AND `user`.`hidewall` = 0
1199 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1202 ORDER BY `item`.`id` DESC LIMIT %d, %d ",
1203 dbesc(ACTIVITY_POST),
1208 $ret = api_format_items($r,$user_info);
1211 $data = array('$statuses' => $ret);
1215 $data = api_rss_extra($a, $data, $user_info);
1218 $as = api_format_as($a, $ret, $user_info);
1219 $as['title'] = $a->config['sitename']." Public Timeline";
1220 $as['link']['url'] = $a->get_baseurl()."/";
1225 return api_apply_template("timeline", $type, $data);
1227 api_register_func('api/statuses/public_timeline','api_statuses_public_timeline', true);
1232 function api_statuses_show(&$a, $type){
1233 if (api_user()===false) return false;
1235 $user_info = api_get_user($a);
1238 $id = intval($a->argv[3]);
1241 $id = intval($_REQUEST["id"]);
1245 $id = intval($a->argv[4]);
1247 logger('API: api_statuses_show: '.$id);
1249 $conversation = (x($_REQUEST,'conversation')?1:0);
1253 $sql_extra .= " AND `item`.`parent` = %d ORDER BY `received` ASC ";
1255 $sql_extra .= " AND `item`.`id` = %d";
1257 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
1258 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
1259 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
1260 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1261 FROM `item`, `contact`
1262 WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
1263 AND `contact`.`id` = `item`.`contact-id` AND `item`.`uid` = %d AND `item`.`verb` = '%s'
1264 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1267 dbesc(ACTIVITY_POST),
1272 die(api_error($a, $type, t("There is no status with this id.")));
1274 $ret = api_format_items($r,$user_info);
1276 if ($conversation) {
1277 $data = array('$statuses' => $ret);
1278 return api_apply_template("timeline", $type, $data);
1280 $data = array('$status' => $ret[0]);
1284 $data = api_rss_extra($a, $data, $user_info);
1286 return api_apply_template("status", $type, $data);
1289 api_register_func('api/statuses/show','api_statuses_show', true);
1295 function api_conversation_show(&$a, $type){
1296 if (api_user()===false) return false;
1298 $user_info = api_get_user($a);
1301 $id = intval($a->argv[3]);
1302 $count = (x($_REQUEST,'count')?$_REQUEST['count']:20);
1303 $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
1304 if ($page<0) $page=0;
1305 $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
1306 $max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
1308 $start = $page*$count;
1311 $id = intval($_REQUEST["id"]);
1315 $id = intval($a->argv[4]);
1317 logger('API: api_conversation_show: '.$id);
1322 $sql_extra = ' AND `item`.`id` <= '.intval($max_id);
1324 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
1325 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
1326 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
1327 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1328 FROM `item` INNER JOIN (SELECT `uri`,`parent` FROM `item` WHERE `id` = %d) AS `temp1`
1329 ON (`item`.`thr-parent` = `temp1`.`uri` AND `item`.`parent` = `temp1`.`parent`), `contact`
1330 WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
1331 AND `item`.`uid` = %d AND `item`.`verb` = '%s' AND `contact`.`id` = `item`.`contact-id`
1332 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1333 AND `item`.`id`>%d $sql_extra
1334 ORDER BY `item`.`id` DESC LIMIT %d ,%d",
1335 intval($id), intval(api_user()),
1336 dbesc(ACTIVITY_POST),
1338 intval($start), intval($count)
1342 die(api_error($a, $type, t("There is no conversation with this id.")));
1344 $ret = api_format_items($r,$user_info);
1346 $data = array('$statuses' => $ret);
1347 return api_apply_template("timeline", $type, $data);
1349 api_register_func('api/conversation/show','api_conversation_show', true);
1355 function api_statuses_repeat(&$a, $type){
1358 if (api_user()===false) return false;
1360 $user_info = api_get_user($a);
1363 $id = intval($a->argv[3]);
1366 $id = intval($_REQUEST["id"]);
1370 $id = intval($a->argv[4]);
1372 logger('API: api_statuses_repeat: '.$id);
1374 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`nick` as `reply_author`,
1375 `contact`.`name`, `contact`.`photo` as `reply_photo`, `contact`.`url` as `reply_url`, `contact`.`rel`,
1376 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
1377 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1378 FROM `item`, `contact`
1379 WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
1380 AND `contact`.`id` = `item`.`contact-id`
1381 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1383 AND `item`.`id`=%d",
1387 if ($r[0]['body'] != "") {
1388 if (!intval(get_config('system','old_share'))) {
1389 if (strpos($r[0]['body'], "[/share]") !== false) {
1390 $pos = strpos($r[0]['body'], "[share");
1391 $post = substr($r[0]['body'], $pos);
1393 $post = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']);
1395 $post .= $r[0]['body'];
1396 $post .= "[/share]";
1398 $_REQUEST['body'] = $post;
1400 $_REQUEST['body'] = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8')."[url=".$r[0]['reply_url']."]".$r[0]['reply_author']."[/url] \n".$r[0]['body'];
1402 $_REQUEST['profile_uid'] = api_user();
1403 $_REQUEST['type'] = 'wall';
1404 $_REQUEST['api_source'] = true;
1406 if (!x($_REQUEST, "source"))
1407 $_REQUEST["source"] = api_source();
1409 require_once('mod/item.php');
1413 // this should output the last post (the one we just posted).
1415 return(api_status_show($a,$type));
1417 api_register_func('api/statuses/retweet','api_statuses_repeat', true);
1422 function api_statuses_destroy(&$a, $type){
1423 if (api_user()===false) return false;
1425 $user_info = api_get_user($a);
1428 $id = intval($a->argv[3]);
1431 $id = intval($_REQUEST["id"]);
1435 $id = intval($a->argv[4]);
1437 logger('API: api_statuses_destroy: '.$id);
1439 $ret = api_statuses_show($a, $type);
1441 require_once('include/items.php');
1442 drop_item($id, false);
1446 api_register_func('api/statuses/destroy','api_statuses_destroy', true);
1450 * http://developer.twitter.com/doc/get/statuses/mentions
1453 function api_statuses_mentions(&$a, $type){
1454 if (api_user()===false) return false;
1456 unset($_REQUEST["user_id"]);
1457 unset($_GET["user_id"]);
1459 unset($_REQUEST["screen_name"]);
1460 unset($_GET["screen_name"]);
1462 $user_info = api_get_user($a);
1463 // get last newtork messages
1467 $count = (x($_REQUEST,'count')?$_REQUEST['count']:20);
1468 $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
1469 if ($page<0) $page=0;
1470 $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
1471 $max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
1472 //$since_id = 0;//$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
1474 $start = $page*$count;
1476 // Ugly code - should be changed
1477 $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
1478 $myurl = substr($myurl,strpos($myurl,'://')+3);
1479 //$myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
1480 $myurl = str_replace('www.','',$myurl);
1481 $diasp_url = str_replace('/profile/','/u/',$myurl);
1484 $sql_extra = ' AND `item`.`id` <= '.intval($max_id);
1486 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
1487 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
1488 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
1489 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1490 FROM `item`, `contact`
1491 WHERE `item`.`uid` = %d AND `verb` = '%s'
1492 AND NOT (`item`.`author-link` IN ('https://%s', 'http://%s'))
1493 AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
1494 AND `contact`.`id` = `item`.`contact-id`
1495 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1496 AND `item`.`parent` IN (SELECT `iid` from thread where uid = %d AND `mention` AND !`ignored`)
1499 ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
1501 dbesc(ACTIVITY_POST),
1502 dbesc(protect_sprintf($myurl)),
1503 dbesc(protect_sprintf($myurl)),
1506 intval($start), intval($count)
1509 $ret = api_format_items($r,$user_info);
1512 $data = array('$statuses' => $ret);
1516 $data = api_rss_extra($a, $data, $user_info);
1519 $as = api_format_as($a, $ret, $user_info);
1520 $as["title"] = $a->config['sitename']." Mentions";
1521 $as['link']['url'] = $a->get_baseurl()."/";
1526 return api_apply_template("timeline", $type, $data);
1528 api_register_func('api/statuses/mentions','api_statuses_mentions', true);
1529 api_register_func('api/statuses/replies','api_statuses_mentions', true);
1532 function api_statuses_user_timeline(&$a, $type){
1533 if (api_user()===false) return false;
1535 $user_info = api_get_user($a);
1536 // get last network messages
1538 logger("api_statuses_user_timeline: api_user: ". api_user() .
1539 "\nuser_info: ".print_r($user_info, true) .
1540 "\n_REQUEST: ".print_r($_REQUEST, true),
1544 $count = (x($_REQUEST,'count')?$_REQUEST['count']:20);
1545 $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
1546 if ($page<0) $page=0;
1547 $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
1548 //$since_id = 0;//$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
1549 $exclude_replies = (x($_REQUEST,'exclude_replies')?1:0);
1550 $conversation_id = (x($_REQUEST,'conversation_id')?$_REQUEST['conversation_id']:0);
1552 $start = $page*$count;
1555 if ($user_info['self']==1)
1556 $sql_extra .= " AND `item`.`wall` = 1 ";
1558 if ($exclude_replies > 0)
1559 $sql_extra .= ' AND `item`.`parent` = `item`.`id`';
1560 if ($conversation_id > 0)
1561 $sql_extra .= ' AND `item`.`parent` = '.intval($conversation_id);
1563 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
1564 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
1565 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
1566 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1567 FROM `item`, `contact`
1568 WHERE `item`.`uid` = %d AND `verb` = '%s'
1569 AND `item`.`contact-id` = %d
1570 AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
1571 AND `contact`.`id` = `item`.`contact-id`
1572 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1575 ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
1577 dbesc(ACTIVITY_POST),
1578 intval($user_info['cid']),
1580 intval($start), intval($count)
1583 $ret = api_format_items($r,$user_info, true);
1585 $data = array('$statuses' => $ret);
1589 $data = api_rss_extra($a, $data, $user_info);
1592 return api_apply_template("timeline", $type, $data);
1595 api_register_func('api/statuses/user_timeline','api_statuses_user_timeline', true);
1599 * Star/unstar an item
1600 * param: id : id of the item
1602 * api v1 : https://web.archive.org/web/20131019055350/https://dev.twitter.com/docs/api/1/post/favorites/create/%3Aid
1604 function api_favorites_create_destroy(&$a, $type){
1605 if (api_user()===false) return false;
1607 # for versioned api.
1608 # TODO: we need a better global soluton
1610 if ($a->argv[1]=="1.1") $action_argv_id=3;
1612 if ($a->argc<=$action_argv_id) die(api_error($a, $type, t("Invalid request.")));
1613 $action = str_replace(".".$type,"",$a->argv[$action_argv_id]);
1614 if ($a->argc==$action_argv_id+2) {
1615 $itemid = intval($a->argv[$action_argv_id+1]);
1617 $itemid = intval($_REQUEST['id']);
1620 $item = q("SELECT * FROM item WHERE id=%d AND uid=%d",
1621 $itemid, api_user());
1623 if ($item===false || count($item)==0) die(api_error($a, $type, t("Invalid item.")));
1627 $item[0]['starred']=1;
1630 $item[0]['starred']=0;
1633 die(api_error($a, $type, t("Invalid action. ".$action)));
1635 $r = q("UPDATE item SET starred=%d WHERE id=%d AND uid=%d",
1636 $item[0]['starred'], $itemid, api_user());
1638 q("UPDATE thread SET starred=%d WHERE iid=%d AND uid=%d",
1639 $item[0]['starred'], $itemid, api_user());
1641 if ($r===false) die(api_error($a, $type, t("DB error")));
1644 $user_info = api_get_user($a);
1645 $rets = api_format_items($item,$user_info);
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($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(&$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];
2667 preg_match("/link='(.*?)'/ism", $attributes, $matches);
2668 if ($matches[1] != "")
2669 $link = $matches[1];
2671 preg_match('/link="(.*?)"/ism', $attributes, $matches);
2672 if ($matches[1] != "")
2673 $link = $matches[1];
2675 $shared_body = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$2",$body);
2677 if (($shared_body == "") OR ($profile == "") OR ($author == "") OR ($avatar == ""))
2680 $item["body"] = $shared_body;
2681 $item["author-name"] = $author;
2682 $item["author-link"] = $profile;
2683 $item["author-avatar"] = $avatar;
2684 $item["plink"] = $link;
2690 function api_get_nick($profile) {
2692 - remove trailing jung from profile url
2693 - pump.io check has to check the website
2698 $friendica = preg_replace("=https?://(.*)/profile/(.*)=ism", "$2", $profile);
2699 if ($friendica != $profile)
2703 $diaspora = preg_replace("=https?://(.*)/u/(.*)=ism", "$2", $profile);
2704 if ($diaspora != $profile)
2709 $twitter = preg_replace("=https?://twitter.com/(.*)=ism", "$1", $profile);
2710 if ($twitter != $profile)
2716 $StatusnetHost = preg_replace("=https?://(.*)/user/(.*)=ism", "$1", $profile);
2717 if ($StatusnetHost != $profile) {
2718 $StatusnetUser = preg_replace("=https?://(.*)/user/(.*)=ism", "$2", $profile);
2719 if ($StatusnetUser != $profile) {
2720 $UserData = fetch_url("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser);
2721 $user = json_decode($UserData);
2723 $nick = $user->screen_name;
2728 // To-Do: look at the page if its really a pumpio site
2729 //if (!$nick == "") {
2730 // $pumpio = preg_replace("=https?://(.*)/(.*)/=ism", "$2", $profile."/");
2731 // if ($pumpio != $profile)
2733 // <div class="media" id="profile-block" data-profile-id="acct:kabniel@microca.st">
2738 q("UPDATE unique_contacts SET nick = '%s' WHERE url = '%s'",
2739 dbesc($nick), dbesc(normalise_link($profile)));
2746 function api_clean_plain_items($Text) {
2747 $include_entities = strtolower(x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:"false");
2749 $Text = bb_CleanPictureLinks($Text);
2751 $URLSearchString = "^\[\]";
2753 $Text = preg_replace("/([!#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",'$1$3',$Text);
2755 if ($include_entities == "true") {
2756 $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",'[url=$1]$1[/url]',$Text);
2759 $Text = preg_replace_callback("((.*?)\[class=(.*?)\](.*?)\[\/class\])ism","api_cleanup_share",$Text);
2763 function api_cleanup_share($shared) {
2764 if ($shared[2] != "type-link")
2767 if (!preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",$shared[3], $bookmark))
2773 if (isset($bookmark[2][0]))
2774 $title = $bookmark[2][0];
2776 if (isset($bookmark[1][0]))
2777 $link = $bookmark[1][0];
2779 if (strpos($shared[1],$title) !== false)
2782 if (strpos($shared[1],$link) !== false)
2785 $text = trim($shared[1]);
2787 //if (strlen($text) < strlen($title))
2788 if (($text == "") AND ($title != ""))
2789 $text .= "\n\n".trim($title);
2792 $text .= "\n".trim($link);
2794 return(trim($text));
2797 function api_best_nickname(&$contacts) {
2798 $best_contact = array();
2800 if (count($contact) == 0)
2803 foreach ($contacts AS $contact)
2804 if ($contact["network"] == "") {
2805 $contact["network"] = "dfrn";
2806 $best_contact = array($contact);
2809 if (sizeof($best_contact) == 0)
2810 foreach ($contacts AS $contact)
2811 if ($contact["network"] == "dfrn")
2812 $best_contact = array($contact);
2814 if (sizeof($best_contact) == 0)
2815 foreach ($contacts AS $contact)
2816 if ($contact["network"] == "dspr")
2817 $best_contact = array($contact);
2819 if (sizeof($best_contact) == 0)
2820 foreach ($contacts AS $contact)
2821 if ($contact["network"] == "stat")
2822 $best_contact = array($contact);
2824 if (sizeof($best_contact) == 0)
2825 foreach ($contacts AS $contact)
2826 if ($contact["network"] == "pump")
2827 $best_contact = array($contact);
2829 if (sizeof($best_contact) == 0)
2830 foreach ($contacts AS $contact)
2831 if ($contact["network"] == "twit")
2832 $best_contact = array($contact);
2834 if (sizeof($best_contact) == 1)
2835 $contacts = $best_contact;
2837 $contacts = array($contacts[0]);
2841 Not implemented by now:
2842 statuses/retweets_of_me
2847 account/update_location
2848 account/update_profile_background_image
2849 account/update_profile_image
2853 Not implemented in status.net:
2854 statuses/retweeted_to_me
2855 statuses/retweeted_by_me
2856 direct_messages/destroy
2858 account/update_delivery_device
2859 notifications/follow