mirror of
https://github.com/friendica/friendica
synced 2025-04-26 15:10:11 +00:00
Merge pull request #5230 from annando/new-item-uri
New function for generating item URI
This commit is contained in:
commit
7d1bb9ecf4
10 changed files with 51 additions and 45 deletions
|
@ -234,7 +234,7 @@ class Event extends BaseObject
|
|||
$event['id'] = intval(defaults($arr, 'id' , 0));
|
||||
$event['uid'] = intval(defaults($arr, 'uid' , 0));
|
||||
$event['cid'] = intval(defaults($arr, 'cid' , 0));
|
||||
$event['uri'] = defaults($arr, 'uri' , item_new_uri($a->get_hostname(), $event['uid']));
|
||||
$event['uri'] = defaults($arr, 'uri' , Item::newURI($event['uid']));
|
||||
$event['type'] = defaults($arr, 'type' , 'event');
|
||||
$event['summary'] = defaults($arr, 'summary' , '');
|
||||
$event['desc'] = defaults($arr, 'desc' , '');
|
||||
|
|
|
@ -675,7 +675,7 @@ class Item extends BaseObject
|
|||
}
|
||||
|
||||
$item['guid'] = self::guid($item, $notify);
|
||||
$item['uri'] = notags(trim(defaults($item, 'uri', item_new_uri($a->get_hostname(), $item['uid'], $item['guid']))));
|
||||
$item['uri'] = notags(trim(defaults($item, 'uri', self::newURI($item['uid'], $item['guid']))));
|
||||
|
||||
// Store conversation data
|
||||
$item = Conversation::insert($item);
|
||||
|
@ -853,8 +853,8 @@ class Item extends BaseObject
|
|||
}
|
||||
|
||||
//unset($item['author-link']);
|
||||
//unset($item['author-name']);
|
||||
//unset($item['author-avatar']);
|
||||
unset($item['author-name']);
|
||||
unset($item['author-avatar']);
|
||||
|
||||
//unset($item['owner-link']);
|
||||
unset($item['owner-name']);
|
||||
|
@ -1528,6 +1528,29 @@ class Item extends BaseObject
|
|||
return $guid_prefix.$host_hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate an unique URI
|
||||
*
|
||||
* @param integer $uid User id
|
||||
* @param string $guid An existing GUID (Otherwise it will be generated)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function newURI($uid, $guid = "")
|
||||
{
|
||||
if ($guid == "") {
|
||||
$guid = get_guid(32);
|
||||
}
|
||||
|
||||
$hostname = self::getApp()->get_hostname();
|
||||
|
||||
$user = dba::selectFirst('user', ['nickname'], ['uid' => $uid]);
|
||||
|
||||
$uri = "urn:X-dfrn:" . $hostname . ':' . $user['nickname'] . ':' . $guid;
|
||||
|
||||
return $uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set "success_update" and "last-item" to the date of the last time we heard from this contact
|
||||
*
|
||||
|
@ -1844,7 +1867,7 @@ class Item extends BaseObject
|
|||
if ($contact['network'] != NETWORK_FEED) {
|
||||
$datarray["guid"] = get_guid(32);
|
||||
unset($datarray["plink"]);
|
||||
$datarray["uri"] = item_new_uri($a->get_hostname(), $contact['uid'], $datarray["guid"]);
|
||||
$datarray["uri"] = self::newURI($contact['uid'], $datarray["guid"]);
|
||||
$datarray["parent-uri"] = $datarray["uri"];
|
||||
$datarray["thr-parent"] = $datarray["uri"];
|
||||
$datarray["extid"] = NETWORK_DFRN;
|
||||
|
@ -2316,7 +2339,7 @@ EOT;
|
|||
|
||||
$new_item = [
|
||||
'guid' => get_guid(32),
|
||||
'uri' => item_new_uri(self::getApp()->get_hostname(), $item['uid']),
|
||||
'uri' => self::newURI($item['uid']),
|
||||
'uid' => $item['uid'],
|
||||
'contact-id' => $item_contact_id,
|
||||
'type' => 'activity',
|
||||
|
|
|
@ -1602,11 +1602,21 @@ class Diaspora
|
|||
*/
|
||||
private static function getUriFromGuid($author, $guid, $onlyfound = false)
|
||||
{
|
||||
$r = q("SELECT `uri` FROM `item` WHERE `guid` = '%s' LIMIT 1", dbesc($guid));
|
||||
if (DBM::is_result($r)) {
|
||||
return $r[0]["uri"];
|
||||
$item = dba::selectFirst('item', ['uri'], ['guid' => $guid]);
|
||||
if (DBM::is_result($item)) {
|
||||
return $item["uri"];
|
||||
} elseif (!$onlyfound) {
|
||||
return $author.":".$guid;
|
||||
$contact = Contact::getDetailsByAddr($author, 0);
|
||||
if (!empty($contact['network'])) {
|
||||
$prefix = 'urn:X-' . $contact['network'] . ':';
|
||||
} else {
|
||||
// This fallback should happen most unlikely
|
||||
$prefix = 'urn:X-dspr:';
|
||||
}
|
||||
|
||||
$author_parts = explode('@', $author);
|
||||
|
||||
return $prefix . $author_parts[1] . ':' . $author_parts[0] . ':'. $guid;
|
||||
}
|
||||
|
||||
return "";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue