X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2FModel%2FItem.php;h=b0a346bc0b6cb3d839626a91899c08c8e43ab6cb;hb=5a3991d4f7bc929c1087d9275716fc1c8cc299a6;hp=1eb96609f2ace041f2f9ade9af459bc340753fad;hpb=df6436d982768bdeabe6188cb47534700c491796;p=friendica.git diff --git a/src/Model/Item.php b/src/Model/Item.php index 1eb96609f2..b0a346bc0b 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -33,6 +33,7 @@ use Friendica\Util\DateTimeFormat; use Friendica\Util\Map; use Friendica\Util\XML; use Friendica\Util\Security; +use Friendica\Util\Strings; use Text_LanguageDetect; require_once 'boot.php'; @@ -831,7 +832,7 @@ class Item extends BaseObject $files = $fields['file']; $fields['file'] = null; } else { - $files = ''; + $files = null; } $delivery_data = ['postopts' => defaults($fields, 'postopts', ''), @@ -910,7 +911,7 @@ class Item extends BaseObject } } - if (!empty($files)) { + if (!is_null($files)) { Term::insertFromFileFieldByItemId($item['id'], $files); if (!empty($item['file'])) { DBA::update('item', ['file' => ''], ['id' => $item['id']]); @@ -1010,10 +1011,8 @@ class Item extends BaseObject $matches = false; $cnt = preg_match_all('/<(.*?)>/', $item['file'], $matches, PREG_SET_ORDER); - if ($cnt) - { - foreach ($matches as $mtch) - { + if ($cnt) { + foreach ($matches as $mtch) { FileTag::unsaveFile($item['uid'], $item['id'], $mtch[1],true); } } @@ -1022,10 +1021,8 @@ class Item extends BaseObject $cnt = preg_match_all('/\[(.*?)\]/', $item['file'], $matches, PREG_SET_ORDER); - if ($cnt) - { - foreach ($matches as $mtch) - { + if ($cnt) { + foreach ($matches as $mtch) { FileTag::unsaveFile($item['uid'], $item['id'], $mtch[1],false); } } @@ -1149,7 +1146,7 @@ class Item extends BaseObject private static function guid($item, $notify) { if (!empty($item['guid'])) { - return notags(trim($item['guid'])); + return Strings::escapeTags(trim($item['guid'])); } if ($notify) { @@ -1264,7 +1261,7 @@ class Item extends BaseObject } $item['guid'] = self::guid($item, $notify); - $item['uri'] = notags(trim(defaults($item, 'uri', self::newURI($item['uid'], $item['guid'])))); + $item['uri'] = Strings::escapeTags(trim(defaults($item, 'uri', self::newURI($item['uid'], $item['guid'])))); // Store URI data $item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]); @@ -1362,15 +1359,15 @@ class Item extends BaseObject $item['owner-name'] = trim(defaults($item, 'owner-name', '')); $item['owner-link'] = trim(defaults($item, 'owner-link', '')); $item['owner-avatar'] = trim(defaults($item, 'owner-avatar', '')); - $item['received'] = ((x($item, 'received') !== false) ? DateTimeFormat::utc($item['received']) : DateTimeFormat::utcNow()); - $item['created'] = ((x($item, 'created') !== false) ? DateTimeFormat::utc($item['created']) : $item['received']); - $item['edited'] = ((x($item, 'edited') !== false) ? DateTimeFormat::utc($item['edited']) : $item['created']); - $item['changed'] = ((x($item, 'changed') !== false) ? DateTimeFormat::utc($item['changed']) : $item['created']); - $item['commented'] = ((x($item, 'commented') !== false) ? DateTimeFormat::utc($item['commented']) : $item['created']); + $item['received'] = (isset($item['received']) ? DateTimeFormat::utc($item['received']) : DateTimeFormat::utcNow()); + $item['created'] = (isset($item['created']) ? DateTimeFormat::utc($item['created']) : $item['received']); + $item['edited'] = (isset($item['edited']) ? DateTimeFormat::utc($item['edited']) : $item['created']); + $item['changed'] = (isset($item['changed']) ? DateTimeFormat::utc($item['changed']) : $item['created']); + $item['commented'] = (isset($item['commented']) ? DateTimeFormat::utc($item['commented']) : $item['created']); $item['title'] = trim(defaults($item, 'title', '')); $item['location'] = trim(defaults($item, 'location', '')); $item['coord'] = trim(defaults($item, 'coord', '')); - $item['visible'] = ((x($item, 'visible') !== false) ? intval($item['visible']) : 1); + $item['visible'] = (isset($item['visible']) ? intval($item['visible']) : 1); $item['deleted'] = 0; $item['parent-uri'] = trim(defaults($item, 'parent-uri', $item['uri'])); $item['post-type'] = defaults($item, 'post-type', self::PT_ARTICLE); @@ -1534,7 +1531,7 @@ class Item extends BaseObject Logger::log("Checking if parent ".$parent_id." has to be tagged as mention for user ".$item['uid'], Logger::DEBUG); $user = DBA::selectFirst('user', ['nickname'], ['uid' => $item['uid']]); if (DBA::isResult($user)) { - $self = normalise_link(System::baseUrl() . '/profile/' . $user['nickname']); + $self = Strings::normaliseLink(System::baseUrl() . '/profile/' . $user['nickname']); $self_id = Contact::getIdForURL($self, 0, true); Logger::log("'myself' is ".$self_id." for parent ".$parent_id." checking against ".$item['author-id']." and ".$item['owner-id'], Logger::DEBUG); if (($item['author-id'] == $self_id) || ($item['owner-id'] == $self_id)) { @@ -1629,7 +1626,7 @@ class Item extends BaseObject // It is mainly used in the "post_local" hook. unset($item['api_source']); - if (x($item, 'cancel')) { + if (!empty($item['cancel'])) { Logger::log('post cancelled by addon.'); return 0; } @@ -2402,7 +2399,7 @@ class Item extends BaseObject public static function setHashtags(&$item) { - $tags = get_tags($item["body"]); + $tags = BBCode::getTags($item["body"]); // No hashtags? if (!count($tags)) { @@ -2451,15 +2448,15 @@ class Item extends BaseObject $basetag = str_replace('_',' ',substr($tag,1)); - $newtag = '#[url=' . System::baseUrl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]'; + $newtag = '#[url=' . System::baseUrl() . '/search?tag=' . $basetag . ']' . $basetag . '[/url]'; $item["body"] = str_replace($tag, $newtag, $item["body"]); if (!stristr($item["tag"], "/search?tag=" . $basetag . "]" . $basetag . "[/url]")) { if (strlen($item["tag"])) { - $item["tag"] = ','.$item["tag"]; + $item["tag"] = ',' . $item["tag"]; } - $item["tag"] = $newtag.$item["tag"]; + $item["tag"] = $newtag . $item["tag"]; } } @@ -2544,18 +2541,18 @@ class Item extends BaseObject return; } - $link = normalise_link(System::baseUrl() . '/profile/' . $user['nickname']); + $link = Strings::normaliseLink(System::baseUrl() . '/profile/' . $user['nickname']); /* * Diaspora uses their own hardwired link URL in @-tags * instead of the one we supply with webfinger */ - $dlink = normalise_link(System::baseUrl() . '/u/' . $user['nickname']); + $dlink = Strings::normaliseLink(System::baseUrl() . '/u/' . $user['nickname']); $cnt = preg_match_all('/[\@\!]\[url\=(.*?)\](.*?)\[\/url\]/ism', $item['body'], $matches, PREG_SET_ORDER); if ($cnt) { foreach ($matches as $mtch) { - if (link_compare($link, $mtch[1]) || link_compare($dlink, $mtch[1])) { + if (Strings::compareLink($link, $mtch[1]) || Strings::compareLink($dlink, $mtch[1])) { $mention = true; Logger::log('mention found: ' . $mtch[2]); } @@ -3446,7 +3443,7 @@ class Item extends BaseObject $filesubtype = 'unkn'; } - $title = escape_tags(trim(!empty($mtch[4]) ? $mtch[4] : $mtch[1])); + $title = Strings::escapeHtml(trim(defaults($mtch, 4, $mtch[1]))); $title .= ' ' . $mtch[2] . ' ' . L10n::t('bytes'); $icon = '
'; @@ -3458,7 +3455,7 @@ class Item extends BaseObject } // Map. - if (strpos($s, '
') !== false && x($item, 'coord')) { + if (strpos($s, '
') !== false && !empty($item['coord'])) { $x = Map::byCoordinates(trim($item['coord'])); if ($x) { $s = preg_replace('/\
/', '$0' . $x, $s); @@ -3479,7 +3476,7 @@ class Item extends BaseObject while ((strpos($s, $spoilersearch) !== false)) { $pos = strpos($s, $spoilersearch); - $rnd = random_string(8); + $rnd = Strings::getRandomHex(8); $spoilerreplace = '
' . L10n::t('Click to open/close') . ''. '