return Strings::compareLink(self::getBasepath($url, true), DI::baseUrl());
}
+ /**
+ * Check if the given contact ID is on the same server
+ *
+ * @param string $url The contact link
+ *
+ * @return boolean Is it the same server?
+ */
+ public static function isLocalById(int $cid)
+ {
+ $contact = DBA::selectFirst('contact', ['url', 'baseurl'], ['id' => $cid]);
+ if (!DBA::isResult($contact)) {
+ return false;
+ }
+
+ if (empty($contact['baseurl'])) {
+ $baseurl = self::getBasepath($contact['url'], true);
+ } else {
+ $baseurl = $contact['baseurl'];
+ }
+
+ return Strings::compareLink($baseurl, DI::baseUrl());
+ }
+
/**
* Returns the public contact id of the given user id
*
$data = [$contact["photo"], $contact["thumb"], $contact["micro"]];
}
+ foreach ($data as $image_uri) {
+ $image_rid = Photo::ridFromURI($image_uri);
+ if ($image_rid && !Photo::exists(['resource-id' => $image_rid, 'uid' => $uid])) {
+ Logger::info('Regenerating avatar', ['contact uid' => $uid, 'cid' => $cid, 'missing photo' => $image_rid, 'avatar' => $contact['avatar']]);
+ $force = true;
+ }
+ }
+
if (($contact["avatar"] != $avatar) || $force) {
$photos = Photo::importProfilePhoto($avatar, $uid, $cid, true);
if ($force) {
self::updateContact($id, $uid, $ret['url'], ['last-update' => $updated, 'success_update' => $updated]);
}
+
+ // Update the public contact
+ if ($uid != 0) {
+ self::updateFromProbeByURL($ret['url']);
+ }
+
return true;
}
* Remove the unavailable contact ids from the provided list
*
* @param array $contact_ids Contact id list
+ * @return array
* @throws \Exception
*/
- public static function pruneUnavailable(array &$contact_ids)
+ public static function pruneUnavailable(array $contact_ids)
{
if (empty($contact_ids)) {
- return;
- }
-
- $str = DBA::escape(implode(',', $contact_ids));
-
- $stmt = DBA::p("SELECT `id` FROM `contact` WHERE `id` IN ( " . $str . ") AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0");
-
- $return = [];
- while($contact = DBA::fetch($stmt)) {
- $return[] = $contact['id'];
+ return [];
}
- DBA::close($stmt);
+ $contacts = Contact::selectToArray(['id'], [
+ 'id' => $contact_ids,
+ 'blocked' => false,
+ 'pending' => false,
+ 'archive' => false,
+ ]);
- $contact_ids = $return;
+ return array_column($contacts, 'id');
}
/**