X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fitems.php;h=a67971cf57b90d833f263b0ece1ae24df3040f19;hb=5498f04ffa88197f49e1f37b814d6954f8785fb7;hp=e8ec81277c8d5e48b563368c6371be88b038be4a;hpb=94f6f12ba3a5c1d506255803e709cb640147ebf4;p=friendica.git diff --git a/include/items.php b/include/items.php index e8ec81277c..a67971cf57 100644 --- a/include/items.php +++ b/include/items.php @@ -397,15 +397,24 @@ function uri_to_guid($uri, $host = "") { // We have to avoid that different routines could accidentally create the same value $parsed = parse_url($uri); + // When the hostname isn't given, we take it from the uri if ($host == "") { - $host = $parsed["host"]; + // Is it in the format data@host.tld? + if ((count($parsed) == 1) && strstr($uri, '@')) { + $mailparts = explode('@', $uri); + $host = array_pop($mailparts); + } else { + $host = $parsed["host"]; + } } + // We use a hash of the hostname as prefix for the guid $guid_prefix = hash("crc32", $host); // Remove the scheme to make sure that "https" and "http" doesn't make a difference unset($parsed["scheme"]); + // Glue it together to be able to make a hash from it $host_id = implode("/", $parsed); // We could use any hash algorithm since it isn't a security issue @@ -534,6 +543,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f } // Converting the plink + /// @todo Check if this is really still needed if ($arr['network'] == NETWORK_OSTATUS) { if (isset($arr['plink'])) { $arr['plink'] = ostatus::convert_href($arr['plink']); @@ -666,7 +676,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f } if (($arr['author-link'] == "") && ($arr['owner-link'] == "")) { - logger("Both author-link and owner-link are empty. Called by: " . App::callstack(), LOGGER_DEBUG); + logger("Both author-link and owner-link are empty. Called by: " . System::callstack(), LOGGER_DEBUG); } if ($arr['plink'] == "") { @@ -751,10 +761,20 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f $arr["author-id"] = get_contact($arr["author-link"], 0); } + if (blockedContact($arr["author-id"])) { + logger('Contact '.$arr["author-id"].' is blocked, item '.$arr["uri"].' will not be stored'); + return 0; + } + if ($arr["owner-id"] == 0) { $arr["owner-id"] = get_contact($arr["owner-link"], 0); } + if (blockedContact($arr["owner-id"])) { + logger('Contact '.$arr["owner-id"].' is blocked, item '.$arr["uri"].' will not be stored'); + return 0; + } + if ($arr['guid'] != "") { // Checking if there is already an item with the same guid logger('checking for an item for user '.$arr['uid'].' on network '.$arr['network'].' with the guid '.$arr['guid'], LOGGER_DEBUG); @@ -939,6 +959,10 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f call_hooks('post_remote', $arr); } + // This array field is used to trigger some automatic reactions + // It is mainly used in the "post_local" hook. + unset($arr['api_source']); + if (x($arr, 'cancel')) { logger('item_store: post cancelled by plugin.'); return 0; @@ -950,7 +974,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f * An unique index would help - but the limitations of MySQL (maximum size of index values) prevent this. */ if ($arr["uid"] == 0) { - $r = qu("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = 0 LIMIT 1", dbesc(trim($arr['uri']))); + $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = 0 LIMIT 1", dbesc(trim($arr['uri']))); if (dbm::is_result($r)) { logger('Global item already stored. URI: '.$arr['uri'].' on network '.$arr['network'], LOGGER_DEBUG); return 0; @@ -1616,6 +1640,13 @@ function item_is_remote_self($contact, &$datarray) { $datarray["app"] = "Feed"; } + // Trigger automatic reactions for addons + $datarray['api_source'] = true; + + // We have to tell the hooks who we are - this really should be improved + $_SESSION["authenticated"] = true; + $_SESSION["uid"] = $contact['uid']; + return true; } @@ -1672,7 +1703,7 @@ function new_follower($importer, $contact, $datarray, $item, $sharing = false) { intval($importer['uid']) ); - if (dbm::is_result($r) && !in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE))) { + if (dbm::is_result($r) && !in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE, PAGE_COMMUNITY))) { // create notification $hash = random_string(); @@ -1708,7 +1739,7 @@ function new_follower($importer, $contact, $datarray, $item, $sharing = false) { )); } - } elseif (dbm::is_result($r) && in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE))) { + } elseif (dbm::is_result($r) && in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE, PAGE_COMMUNITY))) { $r = q("UPDATE `contact` SET `pending` = 0 WHERE `uid` = %d AND `url` = '%s' AND `pending` LIMIT 1", intval($importer['uid']), dbesc($url)