]> git.mxchange.org Git - friendica.git/blobdiff - include/api.php
Code standards
[friendica.git] / include / api.php
index 6ca47c01dd5e28acb93b7fac309a8cb76d9df7d8..22ed066bafb7a968aac62d897bbeff832c6d3d55 100644 (file)
@@ -46,7 +46,6 @@ use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
 
-require_once 'include/conversation.php';
 require_once 'mod/share.php';
 require_once 'mod/item.php';
 require_once 'mod/wall_upload.php';
@@ -431,7 +430,7 @@ function api_call(App $a)
  */
 function api_error($type, $e)
 {
-       $a = get_app();
+       $a = \get_app();
 
        $error = ($e->getMessage() !== "" ? $e->getMessage() : $e->httpdesc);
        /// @TODO:  https://dev.twitter.com/overview/api/response-codes
@@ -643,8 +642,6 @@ function api_get_user(App $a, $contact_id = null)
                $contact = DBA::selectFirst('contact', [], ['uid' => 0, 'nurl' => Strings::normaliseLink($url)]);
 
                if (DBA::isResult($contact)) {
-                       $network_name = ContactSelector::networkToName($contact['network'], $contact['url']);
-
                        // If no nick where given, extract it from the address
                        if (($contact['nick'] == "") || ($contact['name'] == $contact['nick'])) {
                                $contact['nick'] = api_get_nick($contact["url"]);
@@ -655,7 +652,7 @@ function api_get_user(App $a, $contact_id = null)
                                'id_str' => (string) $contact["id"],
                                'name' => $contact["name"],
                                'screen_name' => (($contact['nick']) ? $contact['nick'] : $contact['name']),
-                               'location' => ($contact["location"] != "") ? $contact["location"] : $network_name,
+                               'location' => ($contact["location"] != "") ? $contact["location"] : ContactSelector::networkToName($contact['network'], $contact['url']),
                                'description' => $contact["about"],
                                'profile_image_url' => $contact["micro"],
                                'profile_image_url_https' => $contact["micro"],
@@ -713,8 +710,6 @@ function api_get_user(App $a, $contact_id = null)
                $uinfo[0]['nick'] = api_get_nick($uinfo[0]["url"]);
        }
 
-       $network_name = ContactSelector::networkToName($uinfo[0]['network'], $uinfo[0]['url']);
-
        $pcontact_id  = Contact::getIdForURL($uinfo[0]['url'], 0, true);
 
        if (!empty($profile['about'])) {
@@ -728,7 +723,7 @@ function api_get_user(App $a, $contact_id = null)
        } elseif (!empty($uinfo[0]["location"])) {
                $location = $uinfo[0]["location"];
        } else {
-               $location = $network_name;
+               $location = ContactSelector::networkToName($uinfo[0]['network'], $uinfo[0]['url']);
        }
 
        $ret = [
@@ -968,7 +963,7 @@ function api_format_data($root_element, $type, $data)
 function api_account_verify_credentials($type)
 {
 
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                throw new ForbiddenException();
@@ -1032,7 +1027,7 @@ function requestdata($k)
  */
 function api_statuses_mediap($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                Logger::log('api_statuses_update: no user');
@@ -1080,7 +1075,7 @@ api_register_func('api/statuses/mediap', 'api_statuses_mediap', true, API_METHOD
  */
 function api_statuses_update($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                Logger::log('api_statuses_update: no user');
@@ -1222,7 +1217,7 @@ api_register_func('api/statuses/update_with_media', 'api_statuses_update', true,
  */
 function api_media_upload()
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                Logger::log('no user');
@@ -1266,7 +1261,7 @@ api_register_func('api/media/upload', 'api_media_upload', true, API_METHOD_POST)
  */
 function api_status_show($type, $item_id = 0)
 {
-       $a = get_app();
+       $a = \get_app();
 
        $user_info = api_get_user($a);
 
@@ -1365,7 +1360,7 @@ function api_status_show($type, $item_id = 0)
  */
 function api_users_show($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        $user_info = api_get_user($a);
 
@@ -1441,7 +1436,7 @@ api_register_func('api/externalprofile/show', 'api_users_show');
  */
 function api_users_search($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        $userlist = [];
 
@@ -1521,7 +1516,7 @@ api_register_func('api/users/lookup', 'api_users_lookup', true);
  */
 function api_search($type)
 {
-       $a = get_app();
+       $a = \get_app();
        $user_info = api_get_user($a);
 
        if (api_user() === false || $user_info === false) {
@@ -1582,7 +1577,7 @@ api_register_func('api/search', 'api_search', true);
  */
 function api_statuses_home_timeline($type)
 {
-       $a = get_app();
+       $a = \get_app();
        $user_info = api_get_user($a);
 
        if (api_user() === false || $user_info === false) {
@@ -1670,7 +1665,7 @@ api_register_func('api/statuses/friends_timeline', 'api_statuses_home_timeline',
  */
 function api_statuses_public_timeline($type)
 {
-       $a = get_app();
+       $a = \get_app();
        $user_info = api_get_user($a);
 
        if (api_user() === false || $user_info === false) {
@@ -1752,7 +1747,7 @@ api_register_func('api/statuses/public_timeline', 'api_statuses_public_timeline'
  */
 function api_statuses_networkpublic_timeline($type)
 {
-       $a = get_app();
+       $a = \get_app();
        $user_info = api_get_user($a);
 
        if (api_user() === false || $user_info === false) {
@@ -1807,7 +1802,7 @@ api_register_func('api/statuses/networkpublic_timeline', 'api_statuses_networkpu
  */
 function api_statuses_show($type)
 {
-       $a = get_app();
+       $a = \get_app();
        $user_info = api_get_user($a);
 
        if (api_user() === false || $user_info === false) {
@@ -1880,7 +1875,7 @@ api_register_func('api/statuses/show', 'api_statuses_show', true);
  */
 function api_conversation_show($type)
 {
-       $a = get_app();
+       $a = \get_app();
        $user_info = api_get_user($a);
 
        if (api_user() === false || $user_info === false) {
@@ -1959,7 +1954,7 @@ function api_statuses_repeat($type)
 {
        global $called_api;
 
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                throw new ForbiddenException();
@@ -2024,7 +2019,7 @@ api_register_func('api/statuses/retweet', 'api_statuses_repeat', true, API_METHO
  */
 function api_statuses_destroy($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                throw new ForbiddenException();
@@ -2065,7 +2060,7 @@ api_register_func('api/statuses/destroy', 'api_statuses_destroy', true, API_METH
  */
 function api_statuses_mentions($type)
 {
-       $a = get_app();
+       $a = \get_app();
        $user_info = api_get_user($a);
 
        if (api_user() === false || $user_info === false) {
@@ -2133,7 +2128,7 @@ api_register_func('api/statuses/replies', 'api_statuses_mentions', true);
  */
 function api_statuses_user_timeline($type)
 {
-       $a = get_app();
+       $a = \get_app();
        $user_info = api_get_user($a);
 
        if (api_user() === false || $user_info === false) {
@@ -2211,7 +2206,7 @@ api_register_func('api/statuses/user_timeline', 'api_statuses_user_timeline', tr
  */
 function api_favorites_create_destroy($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                throw new ForbiddenException();
@@ -2289,7 +2284,7 @@ function api_favorites($type)
 {
        global $called_api;
 
-       $a = get_app();
+       $a = \get_app();
        $user_info = api_get_user($a);
 
        if (api_user() === false || $user_info === false) {
@@ -2742,7 +2737,7 @@ function api_contactlink_to_array($txt)
  */
 function api_format_items_activities($item, $type = "json")
 {
-       $a = get_app();
+       $a = \get_app();
 
        $activities = [
                'like' => [],
@@ -2864,7 +2859,7 @@ function api_format_items_profiles($profile_row)
  */
 function api_format_items($r, $user_info, $filter_user = false, $type = "json")
 {
-       $a = get_app();
+       $a = \get_app();
 
        $ret = [];
 
@@ -3054,7 +3049,7 @@ api_register_func('api/lists/subscriptions', 'api_lists_list', true);
  */
 function api_lists_ownerships($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                throw new ForbiddenException();
@@ -3098,7 +3093,7 @@ api_register_func('api/lists/ownerships', 'api_lists_ownerships', true);
  */
 function api_lists_statuses($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        $user_info = api_get_user($a);
        if (api_user() === false || $user_info === false) {
@@ -3175,7 +3170,7 @@ api_register_func('api/lists/statuses', 'api_lists_statuses', true);
  */
 function api_statuses_f($qtype)
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                throw new ForbiddenException();
@@ -3351,7 +3346,7 @@ api_register_func('api/friendships/incoming', 'api_friendships_incoming', true);
  */
 function api_statusnet_config($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        $name      = Config::get('config', 'sitename');
        $server    = $a->getHostName();
@@ -3415,7 +3410,7 @@ function api_ff_ids($type)
                throw new ForbiddenException();
        }
 
-       $a = get_app();
+       $a = \get_app();
 
        api_get_user($a);
 
@@ -3483,7 +3478,7 @@ api_register_func('api/followers/ids', 'api_followers_ids', true);
  */
 function api_direct_messages_new($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                throw new ForbiddenException();
@@ -3571,7 +3566,7 @@ api_register_func('api/direct_messages/new', 'api_direct_messages_new', true, AP
  */
 function api_direct_messages_destroy($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                throw new ForbiddenException();
@@ -3729,7 +3724,7 @@ api_register_func('api/friendships/destroy', 'api_friendships_destroy', true, AP
  */
 function api_direct_messages_box($type, $box, $verbose)
 {
-       $a = get_app();
+       $a = \get_app();
        if (api_user() === false) {
                throw new ForbiddenException();
        }
@@ -4358,7 +4353,7 @@ function api_account_update_profile_image($type)
        Contact::updateSelfFromUserID(api_user(), true);
 
        // Update global directory in background
-       $url = System::baseUrl() . '/profile/' . get_app()->user['nickname'];
+       $url = System::baseUrl() . '/profile/' . \get_app()->user['nickname'];
        if ($url && strlen(Config::get('system', 'directory'))) {
                Worker::add(PRIORITY_LOW, "Directory", $url);
        }
@@ -4673,7 +4668,7 @@ function post_photo_item($hash, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $f
  */
 function prepare_photo_data($type, $scale, $photo_id)
 {
-       $a = get_app();
+       $a = \get_app();
        $user_info = api_get_user($a);
 
        if ($user_info === false) {
@@ -4932,6 +4927,7 @@ function api_share_as_retweet(&$item)
        }
 
        $reshared_item["body"] = $shared_body;
+       $reshared_item["author-id"] = Contact::getIdForURL($profile, 0, true);
        $reshared_item["author-name"] = $author;
        $reshared_item["author-link"] = $profile;
        $reshared_item["author-avatar"] = $avatar;
@@ -5213,7 +5209,7 @@ function api_best_nickname(&$contacts)
  */
 function api_friendica_group_show($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                throw new ForbiddenException();
@@ -5278,7 +5274,7 @@ api_register_func('api/friendica/group_show', 'api_friendica_group_show', true);
  */
 function api_friendica_group_delete($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                throw new ForbiddenException();
@@ -5340,7 +5336,7 @@ api_register_func('api/friendica/group_delete', 'api_friendica_group_delete', tr
  */
 function api_lists_destroy($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                throw new ForbiddenException();
@@ -5456,7 +5452,7 @@ function group_create($name, $uid, $users = [])
  */
 function api_friendica_group_create($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                throw new ForbiddenException();
@@ -5485,7 +5481,7 @@ api_register_func('api/friendica/group_create', 'api_friendica_group_create', tr
  */
 function api_lists_create($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                throw new ForbiddenException();
@@ -5519,7 +5515,7 @@ api_register_func('api/lists/create', 'api_lists_create', true, API_METHOD_POST)
  */
 function api_friendica_group_update($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                throw new ForbiddenException();
@@ -5593,7 +5589,7 @@ api_register_func('api/friendica/group_update', 'api_friendica_group_update', tr
  */
 function api_lists_update($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                throw new ForbiddenException();
@@ -5639,7 +5635,7 @@ api_register_func('api/lists/update', 'api_lists_update', true, API_METHOD_POST)
  */
 function api_friendica_activity($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                throw new ForbiddenException();
@@ -5683,7 +5679,7 @@ api_register_func('api/friendica/activity/unattendmaybe', 'api_friendica_activit
 */
 function api_friendica_notification($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                throw new ForbiddenException();
@@ -5719,7 +5715,7 @@ function api_friendica_notification($type)
  */
 function api_friendica_notification_seen($type)
 {
-       $a = get_app();
+       $a = \get_app();
        $user_info = api_get_user($a);
 
        if (api_user() === false || $user_info === false) {
@@ -5764,7 +5760,7 @@ api_register_func('api/friendica/notification', 'api_friendica_notification', tr
  */
 function api_friendica_direct_messages_setseen($type)
 {
-       $a = get_app();
+       $a = \get_app();
        if (api_user() === false) {
                throw new ForbiddenException();
        }
@@ -5813,7 +5809,7 @@ api_register_func('api/friendica/direct_messages_setseen', 'api_friendica_direct
  */
 function api_friendica_direct_messages_search($type, $box = "")
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                throw new ForbiddenException();
@@ -5876,7 +5872,7 @@ api_register_func('api/friendica/direct_messages_search', 'api_friendica_direct_
  */
 function api_friendica_profile_show($type)
 {
-       $a = get_app();
+       $a = \get_app();
 
        if (api_user() === false) {
                throw new ForbiddenException();