]> git.mxchange.org Git - friendica.git/blobdiff - include/api.php
Merge pull request #3284 from annando/issue-3278
[friendica.git] / include / api.php
index 66703bd6cac3e155477955ddcc3e397b2a413dc5..9fc853340af520d22f9a56b945906a7bd54e9fd2 100644 (file)
@@ -154,9 +154,9 @@ use \Friendica\Core\Config;
 
 
                // workaround for HTTP-auth in CGI mode
-               if (x($_SERVER,'REDIRECT_REMOTE_USER')) {
+               if(x($_SERVER,'REDIRECT_REMOTE_USER')) {
                        $userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"],6)) ;
-                       if (strlen($userpass)) {
+                       if(strlen($userpass)) {
                                list($name, $password) = explode(':', $userpass);
                                $_SERVER['PHP_AUTH_USER'] = $name;
                                $_SERVER['PHP_AUTH_PW'] = $password;
@@ -199,7 +199,7 @@ use \Friendica\Core\Config;
 
                call_hooks('authenticate', $addon_auth);
 
-               if (($addon_auth['authenticated']) && (count($addon_auth['user_record']))) {
+               if(($addon_auth['authenticated']) && (count($addon_auth['user_record']))) {
                        $record = $addon_auth['user_record'];
                }
                else {
@@ -215,7 +215,7 @@ use \Friendica\Core\Config;
                                $record = $r[0];
                }
 
-               if ((! $record) || (! count($record))) {
+               if((! $record) || (! count($record))) {
                        logger('API_login failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
                        header('WWW-Authenticate: Basic realm="Friendica"');
                        #header('HTTP/1.0 401 Unauthorized');
@@ -352,6 +352,7 @@ use \Friendica\Core\Config;
                                        }
                                }
                        }
+                       logger('API call not implemented: '.$a->query_string);
                        throw new NotImplementedException();
                } catch (HTTPException $e) {
                        header("HTTP/1.1 {$e->httpcode} {$e->httpdesc}");
@@ -457,7 +458,7 @@ use \Friendica\Core\Config;
                logger("api_get_user: Fetching user data for user ".$contact_id, LOGGER_DEBUG);
 
                // Searching for contact URL
-               if (!is_null($contact_id) AND (intval($contact_id) == 0)){
+               if(!is_null($contact_id) AND (intval($contact_id) == 0)){
                        $user = dbesc(normalise_link($contact_id));
                        $url = $user;
                        $extra_query = "AND `contact`.`nurl` = '%s' ";
@@ -465,7 +466,7 @@ use \Friendica\Core\Config;
                }
 
                // Searching for contact id with uid = 0
-               if (!is_null($contact_id) AND (intval($contact_id) != 0)){
+               if(!is_null($contact_id) AND (intval($contact_id) != 0)){
                        $user = dbesc(api_unique_id_to_url($contact_id));
 
                        if ($user == "")
@@ -476,7 +477,7 @@ use \Friendica\Core\Config;
                        if (api_user()!==false)  $extra_query .= "AND `contact`.`uid`=".intval(api_user());
                }
 
-               if (is_null($user) && x($_GET, 'user_id')) {
+               if(is_null($user) && x($_GET, 'user_id')) {
                        $user = dbesc(api_unique_id_to_url($_GET['user_id']));
 
                        if ($user == "")
@@ -486,7 +487,7 @@ use \Friendica\Core\Config;
                        $extra_query = "AND `contact`.`nurl` = '%s' ";
                        if (api_user()!==false)  $extra_query .= "AND `contact`.`uid`=".intval(api_user());
                }
-               if (is_null($user) && x($_GET, 'screen_name')) {
+               if(is_null($user) && x($_GET, 'screen_name')) {
                        $user = dbesc($_GET['screen_name']);
                        $nick = $user;
                        $extra_query = "AND `contact`.`nick` = '%s' ";
@@ -496,7 +497,7 @@ use \Friendica\Core\Config;
                if (is_null($user) AND ($a->argc > (count($called_api)-1)) AND (count($called_api) > 0)){
                        $argid = count($called_api);
                        list($user, $null) = explode(".",$a->argv[$argid]);
-                       if (is_numeric($user)){
+                       if(is_numeric($user)){
                                $user = dbesc(api_unique_id_to_url($user));
 
                                if ($user == "")
@@ -593,7 +594,7 @@ use \Friendica\Core\Config;
                        }
                }
 
-               if ($uinfo[0]['self']) {
+               if($uinfo[0]['self']) {
 
                        if ($uinfo[0]['network'] == "")
                                $uinfo[0]['network'] = NETWORK_DFRN;
@@ -648,7 +649,7 @@ use \Friendica\Core\Config;
                $starred = $r[0]['count'];
 
 
-               if (! $uinfo[0]['self']) {
+               if(! $uinfo[0]['self']) {
                        $countfriends = 0;
                        $countfollowers = 0;
                        $starred = 0;
@@ -923,7 +924,7 @@ use \Friendica\Core\Config;
                $txt = requestdata('status');
                //$txt = urldecode(requestdata('status'));
 
-               if ((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
+               if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
 
                        $txt = html2bb_video($txt);
                        $config = HTMLPurifier_Config::createDefault();
@@ -964,9 +965,9 @@ use \Friendica\Core\Config;
 
                // logger('api_post: ' . print_r($_POST,true));
 
-               if (requestdata('htmlstatus')) {
+               if(requestdata('htmlstatus')) {
                        $txt = requestdata('htmlstatus');
-                       if ((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
+                       if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
                                $txt = html2bb_video($txt);
 
                                $config = HTMLPurifier_Config::createDefault();
@@ -989,16 +990,16 @@ use \Friendica\Core\Config;
                if ($parent == -1)
                        $parent = "";
 
-               if (ctype_digit($parent))
+               if(ctype_digit($parent))
                        $_REQUEST['parent'] = $parent;
                else
                        $_REQUEST['parent_uri'] = $parent;
 
-               if (requestdata('lat') && requestdata('long'))
+               if(requestdata('lat') && requestdata('long'))
                        $_REQUEST['coord'] = sprintf("%s %s",requestdata('lat'),requestdata('long'));
                $_REQUEST['profile_uid'] = api_user();
 
-               if ($parent)
+               if($parent)
                        $_REQUEST['type'] = 'net-comment';
                else {
                        // Check for throttling (maximum posts per day, week and month)
@@ -1066,11 +1067,11 @@ use \Friendica\Core\Config;
                        $_REQUEST['type'] = 'wall';
                }
 
-               if (x($_FILES,'media')) {
+               if(x($_FILES,'media')) {
                        // upload the image if we have one
                        $_REQUEST['hush']='yeah'; //tell wall_upload function to return img info instead of echo
                        $media = wall_upload_post($a);
-                       if (strlen($media)>0)
+                       if(strlen($media)>0)
                                $_REQUEST['body'] .= "\n\n".$media;
                }
 
@@ -1115,13 +1116,13 @@ use \Friendica\Core\Config;
 
                $user_info = api_get_user($a);
 
-               if (!x($_FILES,'media')) {
+               if(!x($_FILES,'media')) {
                        // Output error
                        throw new BadRequestException("No media.");
                }
 
                $media = wall_upload_post($a, false);
-               if (!$media) {
+               if(!$media) {
                        // Output error
                        throw new InternalServerErrorException();
                }
@@ -2641,9 +2642,9 @@ use \Friendica\Core\Config;
                        return false;
                }
 
-               if ($qtype == 'friends')
+               if($qtype == 'friends')
                        $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND));
-               if ($qtype == 'followers')
+               if($qtype == 'followers')
                        $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_FOLLOWER), intval(CONTACT_IS_FRIEND));
 
                // friends and followers only for self
@@ -2697,7 +2698,7 @@ use \Friendica\Core\Config;
                $closed = (($a->config['register_policy'] == REGISTER_CLOSED) ? 'true' : 'false');
                $private = ((Config::get('system', 'block_public')) ? 'true' : 'false');
                $textlimit = (string) (($a->config['max_import_size']) ? $a->config['max_import_size'] : 200000);
-               if ($a->config['api_import_size'])
+               if($a->config['api_import_size'])
                        $texlimit = string($a->config['api_import_size']);
                $ssl = ((Config::get('system', 'have_ssl')) ? 'true' : 'false');
                $sslserver = (($ssl === 'true') ? str_replace('http:','https:',App::get_baseurl()) : '');
@@ -2720,6 +2721,7 @@ use \Friendica\Core\Config;
                return api_format_data('config', $type, array('config' => $config));
 
        }
+       api_register_func('api/gnusocial/config','api_statusnet_config',false);
        api_register_func('api/statusnet/config','api_statusnet_config',false);
 
        function api_statusnet_version($type) {
@@ -2728,6 +2730,7 @@ use \Friendica\Core\Config;
 
                return api_format_data('version', $type, array('version' => $fake_statusnet_version));
        }
+       api_register_func('api/gnusocial/version','api_statusnet_version',false);
        api_register_func('api/statusnet/version','api_statusnet_version',false);
 
        /**
@@ -2737,13 +2740,13 @@ use \Friendica\Core\Config;
 
                $a = get_app();
 
-               if (! api_user()) throw new ForbiddenException();
+               if(! api_user()) throw new ForbiddenException();
 
                $user_info = api_get_user($a);
 
-               if ($qtype == 'friends')
+               if($qtype == 'friends')
                        $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND));
-               if ($qtype == 'followers')
+               if($qtype == 'followers')
                        $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_FOLLOWER), intval(CONTACT_IS_FRIEND));
 
                if (!$user_info["self"])
@@ -2967,7 +2970,7 @@ use \Friendica\Core\Config;
                if ($user_id !="") {
                        $sql_extra .= ' AND `mail`.`contact-id` = ' . intval($user_id);
                }
-               elseif ($screen_name !=""){
+               elseif($screen_name !=""){
                        $sql_extra .= " AND `contact`.`nick` = '" . dbesc($screen_name). "'";
                }
 
@@ -2978,7 +2981,7 @@ use \Friendica\Core\Config;
                );
                if ($verbose == "true") {
                        // stop execution and return error message if no mails available
-                       if ($r == null) {
+                       if($r == null) {
                                $answer = array('result' => 'error', 'message' => 'no mails available');
                                return api_format_data("direct_messages_all", $type, array('$result' => $answer));
                        }
@@ -3092,7 +3095,7 @@ use \Friendica\Core\Config;
 
        function api_fr_photo_detail($type) {
                if (api_user()===false) throw new ForbiddenException();
-               if (!x($_REQUEST,'photo_id')) throw new BadRequestException("No photo id.");
+               if(!x($_REQUEST,'photo_id')) throw new BadRequestException("No photo id.");
 
                $scale = (x($_REQUEST, 'scale') ? intval($_REQUEST['scale']) : false);
                $scale_sql = ($scale === false ? "" : sprintf("and scale=%d",intval($scale)));
@@ -3183,11 +3186,11 @@ use \Friendica\Core\Config;
 
                $dfrn_id = $orig_id = (($r[0]['issued-id']) ? $r[0]['issued-id'] : $r[0]['dfrn-id']);
 
-               if ($r[0]['duplex'] && $r[0]['issued-id']) {
+               if($r[0]['duplex'] && $r[0]['issued-id']) {
                        $orig_id = $r[0]['issued-id'];
                        $dfrn_id = '1:' . $orig_id;
                }
-               if ($r[0]['duplex'] && $r[0]['dfrn-id']) {
+               if($r[0]['duplex'] && $r[0]['dfrn-id']) {
                        $orig_id = $r[0]['dfrn-id'];
                        $dfrn_id = '0:' . $orig_id;
                }
@@ -3963,7 +3966,7 @@ use \Friendica\Core\Config;
                $multi_profiles = feature_enabled(api_user(),'multi_profiles');
                $directory = get_config('system', 'directory');
 
-// get data of the specified profile id or all profiles of the user if not specified
+               // get data of the specified profile id or all profiles of the user if not specified
                if ($profileid != 0) {
                        $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d",
                                intval(api_user()),
@@ -3971,11 +3974,10 @@ use \Friendica\Core\Config;
                        // error message if specified gid is not in database
                        if (!dbm::is_result($r))
                                throw new BadRequestException("profile_id not available");
-               }
-               else
+               } else {
                        $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
                                intval(api_user()));
-
+               }
                // loop through all returned profiles and retrieve data and users
                $k = 0;
                foreach ($r as $rr) {
@@ -4002,9 +4004,11 @@ use \Friendica\Core\Config;
                }
 
                // return settings, authenticated user and profiles data
+               $self = q("SELECT `nurl` FROM `contact` WHERE `uid`= %d AND `self` LIMIT 1", intval(api_user()));
+
                $result = array('multi_profiles' => $multi_profiles ? true : false,
                                                'global_dir' => $directory,
-                                               'friendica_owner' => api_get_user($a, intval(api_user())),
+                                               'friendica_owner' => api_get_user($a, $self[0]['nurl']),
                                                'profiles' => $profiles);
                return api_format_data("friendica_profiles", $type, array('$result' => $result));
        }