X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FItem.php;h=68bbdfd8f22b06428c5130ec0514357423058c41;hb=2df2f623e17d729a3adac61eb823d9eb110496cc;hp=1da9eeaaac51f28137f35d225451cf58be24e1ff;hpb=abda71ac0181873c8f9fa2f7c913727bcb9cdd81;p=friendica.git diff --git a/src/Model/Item.php b/src/Model/Item.php index 1da9eeaaac..68bbdfd8f2 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -27,6 +27,7 @@ use Friendica\Util\Map; use Friendica\Util\XML; use Friendica\Util\Security; use Friendica\Util\Strings; +use Friendica\Util\Network; use Text_LanguageDetect; class Item extends BaseObject @@ -1336,7 +1337,11 @@ class Item extends BaseObject $expire_date = time() - ($expire_interval * 86400); $created_date = strtotime($item['created']); if ($created_date < $expire_date) { - Logger::log('item-store: item created ('.date('c', $created_date).') before expiration time ('.date('c', $expire_date).'). ignored. ' . print_r($item,true), Logger::DEBUG); + Logger::notice('Item created before expiration interval.', [ + 'created' => date('c', $created_date), + 'expired' => date('c', $expire_date), + '$item' => $item + ]); return 0; } } @@ -1354,7 +1359,13 @@ class Item extends BaseObject if (DBA::isResult($existing)) { // We only log the entries with a different user id than 0. Otherwise we would have too many false positives if ($uid != 0) { - Logger::log("Item with uri ".$item['uri']." already existed for user ".$uid." with id ".$existing["id"]." target network ".$existing["network"]." - new network: ".$item['network']); + Logger::notice('Item already existed for user', [ + 'uri' => $item['uri'], + 'uid' => $uid, + 'network' => $item['network'], + 'existing_id' => $existing["id"], + 'existing_network' => $existing["network"] + ]); } return $existing["id"]; @@ -1405,7 +1416,7 @@ class Item extends BaseObject // When there is no content then we don't post it if ($item['body'].$item['title'] == '') { - Logger::log('No body, no title.'); + Logger::notice('No body, no title.'); return 0; } @@ -1429,35 +1440,50 @@ class Item extends BaseObject $default = ['url' => $item['author-link'], 'name' => $item['author-name'], 'photo' => $item['author-avatar'], 'network' => $item['network']]; - $item['author-id'] = defaults($item, 'author-id', Contact::getIdForURL($item["author-link"], 0, false, $default)); + $item['author-id'] = defaults($item, 'author-id', Contact::getIdForURL($item['author-link'], 0, false, $default)); + + if (Contact::isBlocked($item['author-id'])) { + Logger::notice('Author is blocked node-wide', ['author-link' => $item['author-link'], 'item-uri' => $item['uri']]); + return 0; + } - if (Contact::isBlocked($item["author-id"])) { - Logger::log('Contact '.$item["author-id"].' is blocked, item '.$item["uri"].' will not be stored'); + if (!empty($item['author-link']) && Network::isUrlBlocked($item['author-link'])) { + Logger::notice('Author server is blocked', ['author-link' => $item['author-link'], 'item-uri' => $item['uri']]); return 0; } $default = ['url' => $item['owner-link'], 'name' => $item['owner-name'], 'photo' => $item['owner-avatar'], 'network' => $item['network']]; - $item['owner-id'] = defaults($item, 'owner-id', Contact::getIdForURL($item["owner-link"], 0, false, $default)); + $item['owner-id'] = defaults($item, 'owner-id', Contact::getIdForURL($item['owner-link'], 0, false, $default)); - if (Contact::isBlocked($item["owner-id"])) { - Logger::log('Contact '.$item["owner-id"].' is blocked, item '.$item["uri"].' will not be stored'); + if (Contact::isBlocked($item['owner-id'])) { + Logger::notice('Owner is blocked node-wide', ['owner-link' => $item['owner-link'], 'item-uri' => $item['uri']]); return 0; } - if ($item['network'] == Protocol::PHANTOM) { - Logger::log('Missing network. Called by: '.System::callstack(), Logger::DEBUG); + if (!empty($item['owner-link']) && Network::isUrlBlocked($item['owner-link'])) { + Logger::notice('Owner server is blocked', ['owner-link' => $item['owner-link'], 'item-uri' => $item['uri']]); + return 0; + } + if ($item['network'] == Protocol::PHANTOM) { $item['network'] = Protocol::DFRN; - Logger::log("Set network to " . $item["network"] . " for " . $item["uri"], Logger::DEBUG); + Logger::notice('Missing network, setting to {network}.', [ + 'uri' => $item["uri"], + 'network' => $item['network'], + 'callstack' => System::callstack() + ]); } // Checking if there is already an item with the same guid - Logger::log('Checking for an item for user '.$item['uid'].' on network '.$item['network'].' with the guid '.$item['guid'], Logger::DEBUG); $condition = ['guid' => $item['guid'], 'network' => $item['network'], 'uid' => $item['uid']]; if (self::exists($condition)) { - Logger::log('found item with guid '.$item['guid'].' for user '.$item['uid'].' on network '.$item['network'], Logger::DEBUG); + Logger::notice('Found already existing item', [ + 'guid' => $item['guid'], + 'uid' => $item['uid'], + 'network' => $item['network'] + ]); return 0; } @@ -1609,7 +1635,7 @@ class Item extends BaseObject $item["global"] = true; // Set the global flag on all items if this was a global item entry - self::update(['global' => true], ['uri' => $item["uri"]]); + DBA::update('item', ['global' => true], ['uri' => $item["uri"]]); } else { $item["global"] = self::exists(['uid' => 0, 'uri' => $item["uri"]]); } @@ -1765,7 +1791,7 @@ class Item extends BaseObject } // Set parent id - self::update(['parent' => $parent_id], ['id' => $current_post]); + DBA::update('item', ['parent' => $parent_id], ['id' => $current_post]); $item['id'] = $current_post; $item['parent'] = $parent_id; @@ -1773,9 +1799,9 @@ class Item extends BaseObject // update the commented timestamp on the parent // Only update "commented" if it is really a comment if (($item['gravity'] != GRAVITY_ACTIVITY) || !Config::get("system", "like_no_comment")) { - self::update(['commented' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()], ['id' => $parent_id]); + DBA::update('item', ['commented' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()], ['id' => $parent_id]); } else { - self::update(['changed' => DateTimeFormat::utcNow()], ['id' => $parent_id]); + DBA::update('item', ['changed' => DateTimeFormat::utcNow()], ['id' => $parent_id]); } if ($dsprsig) { @@ -3566,4 +3592,31 @@ class Item extends BaseObject return $ret; } + + /** + * Is the given item array a post that is sent as starting post to a forum? + * + * @param array $item + * @param array $owner + * + * @return boolean "true" when it is a forum post + */ + public static function isForumPost(array $item, array $owner = []) + { + if (empty($owner)) { + $owner = User::getOwnerDataById($item['uid']); + if (empty($owner)) { + return false; + } + } + + if (($item['author-id'] == $item['owner-id']) || + ($owner['id'] == $item['contact-id']) || + ($item['uri'] != $item['parent-uri']) || + $item['origin']) { + return false; + } + + return Contact::isForum($item['contact-id']); + } }