]> git.mxchange.org Git - friendica.git/blobdiff - include/api.php
Merge pull request #7988 from friendica/MrPetovan-notice
[friendica.git] / include / api.php
index f5f9b50c3485959154c39ec740ce797e95763853..80abb750f7d666b7f9c256d1b7da005d9b2c91f4 100644 (file)
@@ -605,11 +605,6 @@ function api_get_user(App $a, $contact_id = null)
                $contact = DBA::selectFirst('contact', [], ['uid' => 0, 'nurl' => Strings::normaliseLink($url)]);
 
                if (DBA::isResult($contact)) {
-                       // If no nick where given, extract it from the address
-                       if (($contact['nick'] == "") || ($contact['name'] == $contact['nick'])) {
-                               $contact['nick'] = api_get_nick($contact["url"]);
-                       }
-
                        $ret = [
                                'id' => $contact["id"],
                                'id_str' => (string) $contact["id"],
@@ -668,11 +663,6 @@ function api_get_user(App $a, $contact_id = null)
        $countfollowers = 0;
        $starred = 0;
 
-       // Add a nick if it isn't present there
-       if (($uinfo[0]['nick'] == "") || ($uinfo[0]['name'] == $uinfo[0]['nick'])) {
-               $uinfo[0]['nick'] = api_get_nick($uinfo[0]["url"]);
-       }
-
        $pcontact_id  = Contact::getIdForURL($uinfo[0]['url'], 0, true);
 
        if (!empty($profile['about'])) {
@@ -2165,8 +2155,8 @@ function api_statuses_mentions($type)
 
        $start = max(0, ($page - 1) * $count);
 
-       $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `item`.`id` > ? AND `author-id` != ?
-               AND `item`.`parent` IN (SELECT `iid` FROM `thread` WHERE `thread`.`uid` = ? AND `thread`.`mention` AND NOT `thread`.`ignored`)",
+       $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `item`.`id` > ? AND `author-id` != ? AND `mention`
+               AND `item`.`parent` IN (SELECT `iid` FROM `thread` WHERE `thread`.`uid` = ? AND NOT `thread`.`ignored`)",
                api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, $user_info['pid'], api_user()];
 
        if ($max_id > 0) {
@@ -2851,9 +2841,10 @@ function api_format_items_activities($item, $type = "json")
                'attendyes' => [],
                'attendno' => [],
                'attendmaybe' => [],
+               'announce' => [],
        ];
 
-       $condition = ['uid' => $item['uid'], 'thr-parent' => $item['uri']];
+       $condition = ['uid' => $item['uid'], 'thr-parent' => $item['uri'], 'gravity' => GRAVITY_ACTIVITY];
        $ret = Item::selectForUser($item['uid'], ['author-id', 'verb'], $condition);
 
        while ($parent_item = Item::fetch($ret)) {
@@ -2878,6 +2869,9 @@ function api_format_items_activities($item, $type = "json")
                        case Activity::ATTENDMAYBE:
                                $activities['attendmaybe'][] = $user;
                                break;
+                       case Activity::ANNOUNCE:
+                               $activities['announce'][] = $user;
+                               break;
                        default:
                                break;
                }
@@ -3626,6 +3620,7 @@ api_register_func('api/statusnet/version', 'api_statusnet_version', false);
  *
  * @param string $type Return type (atom, rss, xml, json)
  *
+ * @param int $rel A contact relationship constant
  * @return array|string|void
  * @throws BadRequestException
  * @throws ForbiddenException
@@ -3634,7 +3629,7 @@ api_register_func('api/statusnet/version', 'api_statusnet_version', false);
  * @throws UnauthorizedException
  * @todo use api_format_data() to return data
  */
-function api_ff_ids($type)
+function api_ff_ids($type, int $rel)
 {
        if (!api_user()) {
                throw new ForbiddenException();
@@ -3646,26 +3641,29 @@ function api_ff_ids($type)
 
        $stringify_ids = $_REQUEST['stringify_ids'] ?? false;
 
-       $r = q(
-               "SELECT `pcontact`.`id` FROM `contact`
-                       INNER JOIN `contact` AS `pcontact` ON `contact`.`nurl` = `pcontact`.`nurl` AND `pcontact`.`uid` = 0
-                       WHERE `contact`.`uid` = %s AND NOT `contact`.`self`",
-               intval(api_user())
+       $contacts = DBA::p("SELECT `pcontact`.`id`
+               FROM `contact`
+               INNER JOIN `contact` AS `pcontact`
+                   ON `contact`.`nurl` = `pcontact`.`nurl`
+                   AND `pcontact`.`uid` = 0
+               WHERE `contact`.`uid` = ?
+               AND NOT `contact`.`self`
+               AND `contact`.`rel` IN (?, ?)",
+               api_user(),
+               $rel,
+               Contact::FRIEND
        );
-       if (!DBA::isResult($r)) {
-               return;
-       }
 
        $ids = [];
-       foreach ($r as $rr) {
+       foreach (DBA::toArray($contacts) as $contact) {
                if ($stringify_ids) {
-                       $ids[] = $rr['id'];
+                       $ids[] = $contact['id'];
                } else {
-                       $ids[] = intval($rr['id']);
+                       $ids[] = intval($contact['id']);
                }
        }
 
-       return api_format_data("ids", $type, ['id' => $ids]);
+       return api_format_data('ids', $type, ['id' => $ids]);
 }
 
 /**
@@ -3676,11 +3674,14 @@ function api_ff_ids($type)
  * @return array|string
  * @throws BadRequestException
  * @throws ForbiddenException
+ * @throws ImagickException
+ * @throws InternalServerErrorException
+ * @throws UnauthorizedException
  * @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friends-ids
  */
 function api_friends_ids($type)
 {
-       return api_ff_ids($type);
+       return api_ff_ids($type, Contact::SHARING);
 }
 
 /**
@@ -3691,11 +3692,14 @@ function api_friends_ids($type)
  * @return array|string
  * @throws BadRequestException
  * @throws ForbiddenException
+ * @throws ImagickException
+ * @throws InternalServerErrorException
+ * @throws UnauthorizedException
  * @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-followers-ids
  */
 function api_followers_ids($type)
 {
-       return api_ff_ids($type);
+       return api_ff_ids($type, Contact::FOLLOWER);
 }
 
 /// @TODO move to top of file or somewhere better
@@ -5084,14 +5088,17 @@ function api_friendica_remoteauth()
        // traditional DFRN
 
        $contact = DBA::selectFirst('contact', [], ['uid' => api_user(), 'nurl' => $c_url]);
-
-       if (!DBA::isResult($contact) || ($contact['network'] !== Protocol::DFRN)) {
+       if (!DBA::isResult($contact)) {
                throw new BadRequestException("Unknown contact");
        }
 
        $cid = $contact['id'];
 
-       $dfrn_id = $contact['issued-id'] ?? $contact['dfrn-id'];
+       $dfrn_id = $contact['issued-id'] ?: $contact['dfrn-id'];
+
+       if (($contact['network'] !== Protocol::DFRN) || empty($dfrn_id)) {
+               System::externalRedirect($url ?: $c_url);
+       }
 
        if ($contact['duplex'] && $contact['issued-id']) {
                $orig_id = $contact['issued-id'];
@@ -5223,91 +5230,6 @@ function api_share_as_retweet(&$item)
        return $reshared_item;
 }
 
-/**
- *
- * @param string $profile
- *
- * @return string|false
- * @throws InternalServerErrorException
- * @todo remove trailing junk from profile url
- * @todo pump.io check has to check the website
- */
-function api_get_nick($profile)
-{
-       $nick = "";
-
-       $r = q(
-               "SELECT `nick` FROM `contact` WHERE `uid` = 0 AND `nurl` = '%s'",
-               DBA::escape(Strings::normaliseLink($profile))
-       );
-
-       if (DBA::isResult($r)) {
-               $nick = $r[0]["nick"];
-       }
-
-       if (!$nick == "") {
-               $r = q(
-                       "SELECT `nick` FROM `contact` WHERE `uid` = 0 AND `nurl` = '%s'",
-                       DBA::escape(Strings::normaliseLink($profile))
-               );
-
-               if (DBA::isResult($r)) {
-                       $nick = $r[0]["nick"];
-               }
-       }
-
-       if (!$nick == "") {
-               $friendica = preg_replace("=https?://(.*)/profile/(.*)=ism", "$2", $profile);
-               if ($friendica != $profile) {
-                       $nick = $friendica;
-               }
-       }
-
-       if (!$nick == "") {
-               $diaspora = preg_replace("=https?://(.*)/u/(.*)=ism", "$2", $profile);
-               if ($diaspora != $profile) {
-                       $nick = $diaspora;
-               }
-       }
-
-       if (!$nick == "") {
-               $twitter = preg_replace("=https?://twitter.com/(.*)=ism", "$1", $profile);
-               if ($twitter != $profile) {
-                       $nick = $twitter;
-               }
-       }
-
-
-       if (!$nick == "") {
-               $StatusnetHost = preg_replace("=https?://(.*)/user/(.*)=ism", "$1", $profile);
-               if ($StatusnetHost != $profile) {
-                       $StatusnetUser = preg_replace("=https?://(.*)/user/(.*)=ism", "$2", $profile);
-                       if ($StatusnetUser != $profile) {
-                               $UserData = Network::fetchUrl("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser);
-                               $user = json_decode($UserData);
-                               if ($user) {
-                                       $nick = $user->screen_name;
-                               }
-                       }
-               }
-       }
-
-       // To-Do: look at the page if its really a pumpio site
-       //if (!$nick == "") {
-       //      $pumpio = preg_replace("=https?://(.*)/(.*)/=ism", "$2", $profile."/");
-       //      if ($pumpio != $profile)
-       //              $nick = $pumpio;
-               //      <div class="media" id="profile-block" data-profile-id="acct:kabniel@microca.st">
-
-       //}
-
-       if ($nick != "") {
-               return $nick;
-       }
-
-       return false;
-}
-
 /**
  *
  * @param array $item
@@ -5339,10 +5261,6 @@ function api_in_reply_to($item)
                $parent = Item::selectFirst($fields, ['id' => $in_reply_to['status_id']]);
 
                if (DBA::isResult($parent)) {
-                       if ($parent['author-nick'] == "") {
-                               $parent['author-nick'] = api_get_nick($parent['author-link']);
-                       }
-
                        $in_reply_to['screen_name'] = (($parent['author-nick']) ? $parent['author-nick'] : $parent['author-name']);
                        $in_reply_to['user_id'] = intval($parent['author-id']);
                        $in_reply_to['user_id_str'] = (string) intval($parent['author-id']);