mirror of
https://github.com/friendica/friendica
synced 2024-11-20 11:03:42 +00:00
Merge pull request #2911 from annando/1611-well-formatted-uri
URI of "remote self" are looking better now.
This commit is contained in:
commit
44d79cbc27
2 changed files with 29 additions and 4 deletions
|
@ -325,6 +325,14 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
|
||||||
logger("Stored feed: ".print_r($item, true), LOGGER_DEBUG);
|
logger("Stored feed: ".print_r($item, true), LOGGER_DEBUG);
|
||||||
|
|
||||||
$notify = item_is_remote_self($contact, $item);
|
$notify = item_is_remote_self($contact, $item);
|
||||||
|
|
||||||
|
// Distributed items should have a well formatted URI.
|
||||||
|
// Additionally we have to avoid conflicts with identical URI between imported feeds and these items.
|
||||||
|
if ($notify) {
|
||||||
|
unset($item['uri']);
|
||||||
|
unset($item['parent-uri']);
|
||||||
|
}
|
||||||
|
|
||||||
$id = item_store($item, false, $notify);
|
$id = item_store($item, false, $notify);
|
||||||
|
|
||||||
logger("Feed for contact ".$contact["url"]." stored under id ".$id);
|
logger("Feed for contact ".$contact["url"]." stored under id ".$id);
|
||||||
|
|
|
@ -359,14 +359,20 @@ function item_add_language_opt(&$arr) {
|
||||||
* @brief Creates an unique guid out of a given uri
|
* @brief Creates an unique guid out of a given uri
|
||||||
*
|
*
|
||||||
* @param string $uri uri of an item entry
|
* @param string $uri uri of an item entry
|
||||||
|
* @param string $host (Optional) hostname for the GUID prefix
|
||||||
* @return string unique guid
|
* @return string unique guid
|
||||||
*/
|
*/
|
||||||
function uri_to_guid($uri) {
|
function uri_to_guid($uri, $host = "") {
|
||||||
|
|
||||||
// Our regular guid routine is using this kind of prefix as well
|
// Our regular guid routine is using this kind of prefix as well
|
||||||
// We have to avoid that different routines could accidentally create the same value
|
// We have to avoid that different routines could accidentally create the same value
|
||||||
$parsed = parse_url($uri);
|
$parsed = parse_url($uri);
|
||||||
$guid_prefix = hash("crc32", $parsed["host"]);
|
|
||||||
|
if ($host == "") {
|
||||||
|
$host = $parsed["host"];
|
||||||
|
}
|
||||||
|
|
||||||
|
$guid_prefix = hash("crc32", $host);
|
||||||
|
|
||||||
// Remove the scheme to make sure that "https" and "http" doesn't make a difference
|
// Remove the scheme to make sure that "https" and "http" doesn't make a difference
|
||||||
unset($parsed["scheme"]);
|
unset($parsed["scheme"]);
|
||||||
|
@ -381,6 +387,8 @@ function uri_to_guid($uri) {
|
||||||
|
|
||||||
function item_store($arr,$force_parent = false, $notify = false, $dontcache = false) {
|
function item_store($arr,$force_parent = false, $notify = false, $dontcache = false) {
|
||||||
|
|
||||||
|
$a = get_app();
|
||||||
|
|
||||||
// If it is a posting where users should get notifications, then define it as wall posting
|
// If it is a posting where users should get notifications, then define it as wall posting
|
||||||
if ($notify) {
|
if ($notify) {
|
||||||
$arr['wall'] = 1;
|
$arr['wall'] = 1;
|
||||||
|
@ -388,6 +396,15 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
|
||||||
$arr['origin'] = 1;
|
$arr['origin'] = 1;
|
||||||
$arr['last-child'] = 1;
|
$arr['last-child'] = 1;
|
||||||
$arr['network'] = NETWORK_DFRN;
|
$arr['network'] = NETWORK_DFRN;
|
||||||
|
|
||||||
|
// We have to avoid duplicates. So we create the GUID in form of a hash of the plink or uri.
|
||||||
|
// In difference to the call to "uri_to_guid" several lines below we add the hash of our own host.
|
||||||
|
// This is done because our host is the original creator of the post.
|
||||||
|
if (isset($arr['plink'])) {
|
||||||
|
$arr['guid'] = uri_to_guid($arr['plink'], $a->get_hostname());
|
||||||
|
} elseif (isset($arr['uri'])) {
|
||||||
|
$arr['guid'] = uri_to_guid($arr['uri'], $a->get_hostname());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a Diaspora signature structure was passed in, pull it out of the
|
// If a Diaspora signature structure was passed in, pull it out of the
|
||||||
|
@ -474,7 +491,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
|
||||||
|
|
||||||
$arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0);
|
$arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0);
|
||||||
$arr['guid'] = ((x($arr,'guid')) ? notags(trim($arr['guid'])) : get_guid(32, $guid_prefix));
|
$arr['guid'] = ((x($arr,'guid')) ? notags(trim($arr['guid'])) : get_guid(32, $guid_prefix));
|
||||||
$arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : $arr['guid']);
|
$arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : item_new_uri($a->get_hostname(), $uid, $arr['guid']));
|
||||||
$arr['extid'] = ((x($arr,'extid')) ? notags(trim($arr['extid'])) : '');
|
$arr['extid'] = ((x($arr,'extid')) ? notags(trim($arr['extid'])) : '');
|
||||||
$arr['author-name'] = ((x($arr,'author-name')) ? trim($arr['author-name']) : '');
|
$arr['author-name'] = ((x($arr,'author-name')) ? trim($arr['author-name']) : '');
|
||||||
$arr['author-link'] = ((x($arr,'author-link')) ? notags(trim($arr['author-link'])) : '');
|
$arr['author-link'] = ((x($arr,'author-link')) ? notags(trim($arr['author-link'])) : '');
|
||||||
|
@ -493,7 +510,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
|
||||||
$arr['last-child'] = ((x($arr,'last-child')) ? intval($arr['last-child']) : 0 );
|
$arr['last-child'] = ((x($arr,'last-child')) ? intval($arr['last-child']) : 0 );
|
||||||
$arr['visible'] = ((x($arr,'visible') !== false) ? intval($arr['visible']) : 1 );
|
$arr['visible'] = ((x($arr,'visible') !== false) ? intval($arr['visible']) : 1 );
|
||||||
$arr['deleted'] = 0;
|
$arr['deleted'] = 0;
|
||||||
$arr['parent-uri'] = ((x($arr,'parent-uri')) ? notags(trim($arr['parent-uri'])) : '');
|
$arr['parent-uri'] = ((x($arr,'parent-uri')) ? notags(trim($arr['parent-uri'])) : $arr['uri']);
|
||||||
$arr['verb'] = ((x($arr,'verb')) ? notags(trim($arr['verb'])) : '');
|
$arr['verb'] = ((x($arr,'verb')) ? notags(trim($arr['verb'])) : '');
|
||||||
$arr['object-type'] = ((x($arr,'object-type')) ? notags(trim($arr['object-type'])) : '');
|
$arr['object-type'] = ((x($arr,'object-type')) ? notags(trim($arr['object-type'])) : '');
|
||||||
$arr['object'] = ((x($arr,'object')) ? trim($arr['object']) : '');
|
$arr['object'] = ((x($arr,'object')) ? trim($arr['object']) : '');
|
||||||
|
|
Loading…
Reference in a new issue