]> git.mxchange.org Git - friendica.git/commitdiff
API: Some more stuff to make the API more complete (compared to the original Twitter...
authorMichael Vogel <icarus@dabo.de>
Mon, 13 Jan 2014 19:03:05 +0000 (20:03 +0100)
committerMichael Vogel <icarus@dabo.de>
Mon, 13 Jan 2014 19:03:05 +0000 (20:03 +0100)
include/api.php

index 579449fc85fc3cb6b9907f6a0441cc7ec1e62984..651d46f33cd042c2491d639da52bbda9eb1cd51e 100644 (file)
 
        function api_register_func($path, $func, $auth=false){
                global $API;
-               $API[$path] = array('func'=>$func,
-                                                       'auth'=>$auth);
+               $API[$path] = array('func'=>$func, 'auth'=>$auth);
+
+               // Workaround for hotot
+               $path = str_replace("api/", "api/1.1/", $path);
+               $API[$path] = array('func'=>$func, 'auth'=>$auth);
        }
 
        /**
 
                                $ret = array(
                                        'id' => $r[0]["id"],
+                                       'id_str' => (string) $r[0]["id"],
                                        'name' => $r[0]["name"],
                                        'screen_name' => (($r[0]['nick']) ? $r[0]['nick'] : $r[0]['name']),
                                        'location' => NULL,
                        );
 
                        // count public wall messages
-                       $r = q("SELECT COUNT(`id`) as `count` FROM `item` USE INDEX (uid, type)
+                       $r = q("SELECT COUNT(`id`) as `count` FROM `item`
                                        WHERE  `uid` = %d
                                        AND `type`='wall'
                                        AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
                        $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", dbesc(normalise_link($uinfo[0]['url'])));
                }
 
+               require_once('include/contact_selectors.php');
+               $network_name = network_to_name($uinfo[0]['network']);
+
                $ret = Array(
                        'id' => intval($r[0]['id']),
+                       'id_str' => (string) intval($r[0]['id']),
                        'name' => (($uinfo[0]['name']) ? $uinfo[0]['name'] : $uinfo[0]['nick']),
                        'screen_name' => (($uinfo[0]['nick']) ? $uinfo[0]['nick'] : $uinfo[0]['name']),
-                       'location' => ($usr) ? $usr[0]['default-location'] : NULL,
+                       'location' => ($usr) ? $usr[0]['default-location'] : $network_name,
                        'description' => (($profile) ? $profile[0]['pdesc'] : NULL),
                        'profile_image_url' => $uinfo[0]['micro'],
                        'profile_image_url_https' => $uinfo[0]['micro'],
                        'protected' => false,
                        'followers_count' => intval($countfollowers),
                        'friends_count' => intval($countfriends),
-                       'created_at' => api_date($uinfo[0]['name-date']),
+                       'created_at' => api_date($uinfo[0]['created']),
                        'favourites_count' => intval($starred),
-                       'utc_offset' => "0", // To-Do
-                       'time_zone' => 'UTC', // To-Do $uinfo[0]['timezone'],
+                       'utc_offset' => "0",
+                       'time_zone' => 'UTC',
                        'statuses_count' => intval($countitms),
-                       'following' => true, //#XXX: fix me
-                       'verified' => true, //#XXX: fix me
+                       'following' => (($uinfo[0]['rel'] == CONTACT_IS_FOLLOWER) OR ($uinfo[0]['rel'] == CONTACT_IS_FRIEND)),
+                       'verified' => true,
                        'statusnet_blocking' => false,
                        'notifications' => false,
                        'statusnet_profile_url' => $a->get_baseurl()."/contacts/".$uinfo[0]['cid'],
                // get last public wall message
                $lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `c`.`nick` as `reply_author`, `i`.`author-link` AS `item-author`
                                FROM `item`, `contact`, `item` as `i`, `contact` as `c`
-                               WHERE `item`.`contact-id` = %d AND `item`.`owner-link` = '%s'
+                               WHERE `item`.`contact-id` = %d
+                                       AND ((`item`.`author-link` IN ('%s', '%s')) OR (`item`.`owner-link` IN ('%s', '%s')))
                                        AND `i`.`id` = `item`.`parent`
                                        AND `contact`.`id`=`item`.`contact-id` AND `c`.`id`=`i`.`contact-id` AND `contact`.`self`=1
                                        AND `item`.`type`!='activity'
                                ORDER BY `item`.`created` DESC
                                LIMIT 1",
                                intval($user_info['cid']),
-                               dbesc($user_info['url'])
+                               dbesc($user_info['url']),
+                               dbesc(normalise_link($user_info['url'])),
+                               dbesc($user_info['url']),
+                               dbesc(normalise_link($user_info['url']))
                );
 
                if (count($lastwall)>0){
 
                        $in_reply_to_status_id = NULL;
                        $in_reply_to_user_id = NULL;
+                       $in_reply_to_status_id_str = NULL;
+                       $in_reply_to_user_id_str = NULL;
                        $in_reply_to_screen_name = NULL;
                        if ($lastwall['parent']!=$lastwall['id']) {
-                               $in_reply_to_status_id=$lastwall['parent'];
+                               $in_reply_to_status_id= intval($lastwall['parent']);
+                               $in_reply_to_status_id_str = (string) intval($lastwall['parent']);
                                //$in_reply_to_user_id = $lastwall['reply_uid'];
                                //$in_reply_to_screen_name = $lastwall['reply_author'];
 
                                                $r[0]['nick'] = api_get_nick($r[0]["url"]);
 
                                        $in_reply_to_screen_name = (($r[0]['nick']) ? $r[0]['nick'] : $r[0]['name']);
-                                       $in_reply_to_user_id = $r[0]['id'];
+                                       $in_reply_to_user_id = intval($r[0]['id']);
+                                       $in_reply_to_user_id_str = (string) intval($r[0]['id']);
                                }
                        }
 
                                'truncated' => false,
                                'created_at' => api_date($lastwall['created']),
                                'in_reply_to_status_id' => $in_reply_to_status_id,
+                               'in_reply_to_status_id_str' => $in_reply_to_status_id_str,
                                'source' => (($lastwall['app']) ? $lastwall['app'] : 'web'),
-                               'id' => $lastwall['id'],
+                               'id' => intval($lastwall['id']),
+                               'id_str' => (string) $lastwall['id'],
                                'in_reply_to_user_id' => $in_reply_to_user_id,
+                               'in_reply_to_user_id_str' => $in_reply_to_user_id_str,
                                'in_reply_to_screen_name' => $in_reply_to_screen_name,
                                'geo' => NULL,
                                'favorited' => false,
 
                $lastwall = q("SELECT `item`.*
                                FROM `item`, `contact`
-                               WHERE `item`.`contact-id` = %d  AND `item`.`owner-link` = '%s'
+                               WHERE `item`.`contact-id` = %d
+                                       AND ((`item`.`author-link` IN ('%s', '%s')) OR (`item`.`owner-link` IN ('%s', '%s')))
                                        AND `contact`.`id`=`item`.`contact-id`
                                        AND `type`!='activity'
                                        AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''
                                ORDER BY `created` DESC
                                LIMIT 1",
                                intval($user_info['cid']),
-                               dbesc($user_info['url'])
+                               dbesc($user_info['url']),
+                               dbesc(normalise_link($user_info['url'])),
+                               dbesc($user_info['url']),
+                               dbesc(normalise_link($user_info['url']))
                );
-
+//print_r($user_info);
                if (count($lastwall)>0){
                        $lastwall = $lastwall[0];
 
                        $in_reply_to_status_id = NULL;
                        $in_reply_to_user_id = NULL;
+                       $in_reply_to_status_id_str = NULL;
+                       $in_reply_to_user_id_str = NULL;
                        $in_reply_to_screen_name = NULL;
                        if ($lastwall['parent']!=$lastwall['id']) {
                                $reply = q("SELECT `item`.`id`, `item`.`contact-id` as `reply_uid`, `contact`.`nick` as `reply_author`, `item`.`author-link` AS `item-author`
                                             FROM `item`,`contact` WHERE `contact`.`id`=`item`.`contact-id` AND `item`.`id` = %d", intval($lastwall['parent']));
                                if (count($reply)>0) {
-                                       $in_reply_to_status_id=$lastwall['parent'];
-                                       //$in_reply_to_user_id = $reply[0]['reply_uid'];
-                                       //$in_reply_to_screen_name = $reply[0]['reply_author'];
+                                       $in_reply_to_status_id = intval($lastwall['parent']);
+                                       $in_reply_to_status_id_str = (string) intval($lastwall['parent']);
+
                                        $r = q("SELECT * FROM unique_contacts WHERE `url` = '%s'", dbesc(normalise_link($reply[0]['item-author'])));
                                        if ($r) {
                                                if ($r[0]['nick'] == "")
                                                        $r[0]['nick'] = api_get_nick($r[0]["url"]);
 
                                                $in_reply_to_screen_name = (($r[0]['nick']) ? $r[0]['nick'] : $r[0]['name']);
-                                               $in_reply_to_user_id = $r[0]['id'];
+                                               $in_reply_to_user_id = intval($r[0]['id']);
+                                               $in_reply_to_user_id_str = (string) intval($r[0]['id']);
                                        }
                                }
                        }
                                'truncated' => false,
                                'created_at' => api_date($lastwall['created']),
                                'in_reply_to_status_id' => $in_reply_to_status_id,
+                               'in_reply_to_status_id_str' => $in_reply_to_status_id_str,
                                'source' => (($lastwall['app']) ? $lastwall['app'] : 'web'),
-                               'id' => $lastwall['contact-id'],
+                               'id' => intval($lastwall['contact-id']),
+                               'id_str' => (string) $lastwall['contact-id'],
                                'in_reply_to_user_id' => $in_reply_to_user_id,
+                               'in_reply_to_user_id_str' => $in_reply_to_user_id_str,
                                'in_reply_to_screen_name' => $in_reply_to_screen_name,
                                'geo' => NULL,
                                'favorited' => false,
                if ($id == 0)
                        $id = intval($_REQUEST["id"]);
 
+               // Hotot workaround
+               if ($id == 0)
+                       $id = intval($a->argv[4]);
+
                logger('API: api_statuses_show: '.$id);
 
                //$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false);
                if ($id == 0)
                        $id = intval($_REQUEST["id"]);
 
+               // Hotot workaround
+               if ($id == 0)
+                       $id = intval($a->argv[4]);
+
                logger('API: api_statuses_repeat: '.$id);
 
                //$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false);
                if ($id == 0)
                        $id = intval($_REQUEST["id"]);
 
+               // Hotot workaround
+               if ($id == 0)
+                       $id = intval($a->argv[4]);
+
                logger('API: api_statuses_destroy: '.$id);
 
                $ret = api_statuses_show($a, $type);
                                        intval(api_user()),
                                        dbesc($item['thr-parent']));
                                if ($r)
-                                       $in_reply_to_status_id = $r[0]['id'];
+                                       $in_reply_to_status_id = intval($r[0]['id']);
                                else
-                                       $in_reply_to_status_id = $item['parent'];
+                                       $in_reply_to_status_id = intval($item['parent']);
+
+                               $in_reply_to_status_id_str = (string) intval($item['parent']);
 
                                $in_reply_to_screen_name = NULL;
                                $in_reply_to_user_id = NULL;
+                               $in_reply_to_user_id_str = NULL;
 
                                $r = q("SELECT `author-link` FROM item WHERE uid=%d AND id=%d LIMIT 1",
                                        intval(api_user()),
                                                        $r[0]['nick'] = api_get_nick($r[0]["url"]);
 
                                                $in_reply_to_screen_name = (($r[0]['nick']) ? $r[0]['nick'] : $r[0]['name']);
-                                               $in_reply_to_user_id = $r[0]['id'];
+                                               $in_reply_to_user_id = intval($r[0]['id']);
+                                               $in_reply_to_user_id_str = (string) intval($r[0]['id']);
                                        }
                                }
                        } else {
                                $in_reply_to_screen_name = NULL;
                                $in_reply_to_user_id = NULL;
                                $in_reply_to_status_id = NULL;
+                               $in_reply_to_user_id_str = NULL;
+                               $in_reply_to_status_id_str = NULL;
                        }
 
                        // Workaround for ostatus messages where the title is identically to the body
                                'truncated' => False,
                                'created_at'=> api_date($item['created']),
                                'in_reply_to_status_id' => $in_reply_to_status_id,
+                               'in_reply_to_status_id_str' => $in_reply_to_status_id,
                                'source'    => (($item['app']) ? $item['app'] : 'web'),
                                'id'            => intval($item['id']),
+                               'id_str'        => (string) intval($item['id']),
                                'in_reply_to_user_id' => $in_reply_to_user_id,
+                               'in_reply_to_user_id_str' => $in_reply_to_user_id,
                                'in_reply_to_screen_name' => $in_reply_to_screen_name,
                                'geo' => NULL,
                                'favorited' => $item['starred'] ? true : false,