From 5276c28a78e188eb4ec8dcbf87a4dd1ac193c8d7 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Thu, 8 Nov 2018 10:46:50 -0500 Subject: [PATCH] link_compare calls implement compareLink function. --- mod/dirfind.php | 2 +- mod/invite.php | 2 +- mod/item.php | 2 +- mod/message.php | 2 +- mod/openid.php | 2 +- mod/photos.php | 2 +- mod/pubsub.php | 2 +- mod/pubsubhubbub.php | 2 +- mod/redir.php | 2 +- mod/settings.php | 4 ++-- src/App.php | 2 +- src/Model/Item.php | 4 ++-- src/Model/Profile.php | 2 +- src/Model/User.php | 2 +- src/Object/Post.php | 7 ++++--- src/Protocol/DFRN.php | 6 +++--- src/Protocol/Diaspora.php | 4 ++-- src/Util/Strings.php | 10 +++++----- src/Worker/Delivery.php | 3 ++- 19 files changed, 32 insertions(+), 30 deletions(-) diff --git a/mod/dirfind.php b/mod/dirfind.php index cf58098ab..738ac124f 100644 --- a/mod/dirfind.php +++ b/mod/dirfind.php @@ -53,7 +53,7 @@ function dirfind_content(App $a, $prefix = "") { if (strpos($search,'@') === 0) { $search = substr($search,1); $header = L10n::t('People Search - %s', $search); - if ((valid_email($search) && Network::isEmailDomainValid($search)) || + if ((Strings::isValidEmail($search) && Network::isEmailDomainValid($search)) || (substr(normalise_link($search), 0, 7) == "http://")) { $user_data = Probe::uri($search); $discover_user = (in_array($user_data["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])); diff --git a/mod/invite.php b/mod/invite.php index e63f81d4e..5d33dd30a 100644 --- a/mod/invite.php +++ b/mod/invite.php @@ -56,7 +56,7 @@ function invite_post(App $a) foreach ($recipients as $recipient) { $recipient = trim($recipient); - if (! valid_email($recipient)) { + if (! Strings::isValidEmail($recipient)) { notice(L10n::t('%s : Not a valid email address.', $recipient) . EOL); continue; } diff --git a/mod/item.php b/mod/item.php index c6f359cf4..bf8c5f721 100644 --- a/mod/item.php +++ b/mod/item.php @@ -348,7 +348,7 @@ function item_post(App $a) { $str_tags = ''; $inform = ''; - $tags = get_tags($body); + $tags = Strings::getTags($body); // Add a tag if the parent contact is from ActivityPub or OStatus (This will notify them) if ($parent && in_array($thr_parent_contact['network'], [Protocol::OSTATUS, Protocol::ACTIVITYPUB])) { diff --git a/mod/message.php b/mod/message.php index afb339147..6ac5d183a 100644 --- a/mod/message.php +++ b/mod/message.php @@ -463,7 +463,7 @@ function render_messages(array $msg, $t) foreach ($msg as $rr) { if ($rr['unknown']) { $participants = L10n::t("Unknown sender - %s", $rr['from-name']); - } elseif (link_compare($rr['from-url'], $myprofile)) { + } elseif (Strings::compareLink($rr['from-url'], $myprofile)) { $participants = L10n::t("You and %s", $rr['name']); } else { $participants = L10n::t("%s and You", $rr['from-name']); diff --git a/mod/openid.php b/mod/openid.php index 663bc1cec..287b12781 100644 --- a/mod/openid.php +++ b/mod/openid.php @@ -44,7 +44,7 @@ function openid_content(App $a) { AND `blocked` = 0 AND `account_expired` = 0 AND `account_removed` = 0 AND `verified` = 1 LIMIT 1", - DBA::escape($authid), DBA::escape(normalise_openid($authid)) + DBA::escape($authid), DBA::escape(Strings::normaliseOpenID($authid)) ); if (DBA::isResult($r)) { diff --git a/mod/photos.php b/mod/photos.php index 1b2e8d52b..b5c648d3b 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -525,7 +525,7 @@ function photos_post(App $a) } $taginfo = []; - $tags = get_tags($rawtags); + $tags = Strings::getTags($rawtags); if (count($tags)) { foreach ($tags as $tag) { diff --git a/mod/pubsub.php b/mod/pubsub.php index edab03e3f..06ebacbe3 100644 --- a/mod/pubsub.php +++ b/mod/pubsub.php @@ -64,7 +64,7 @@ function pubsub_init(App $a) hub_return(false, ''); } - if (!empty($hub_topic) && !link_compare($hub_topic, $contact['poll'])) { + if (!empty($hub_topic) && !Strings::compareLink($hub_topic, $contact['poll'])) { Logger::log('Hub topic ' . $hub_topic . ' != ' . $contact['poll']); hub_return(false, ''); } diff --git a/mod/pubsubhubbub.php b/mod/pubsubhubbub.php index d23f1fe47..b05577827 100644 --- a/mod/pubsubhubbub.php +++ b/mod/pubsubhubbub.php @@ -88,7 +88,7 @@ function pubsubhubbub_init(App $a) { // sanity check that topic URLs are the same $hub_topic2 = str_replace('/feed/', '/dfrn_poll/', $hub_topic); - if (!link_compare($hub_topic, $contact['poll']) && !link_compare($hub_topic2, $contact['poll'])) { + if (!Strings::compareLink($hub_topic, $contact['poll']) && !Strings::compareLink($hub_topic2, $contact['poll'])) { Logger::log('Hub topic ' . $hub_topic . ' != ' . $contact['poll']); System::httpExit(404); } diff --git a/mod/redir.php b/mod/redir.php index 6077a26f9..f22af545f 100644 --- a/mod/redir.php +++ b/mod/redir.php @@ -116,7 +116,7 @@ function redir_init(App $a) { if (!empty($url)) { $my_profile = Profile::getMyURL(); - if (!empty($my_profile) && !link_compare($my_profile, $url)) { + if (!empty($my_profile) && !Strings::compareLink($my_profile, $url)) { $separator = strpos($url, '?') ? '&' : '?'; $url .= $separator . 'zrl=' . urlencode($my_profile); diff --git a/mod/settings.php b/mod/settings.php index 589b2383a..142555691 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -517,7 +517,7 @@ function settings_post(App $a) $email = $a->user['email']; } // check the email is valid - if (!valid_email($email)) { + if (!Strings::isValidEmail($email)) { $err .= L10n::t('Invalid email.'); } // ensure new email is not the admin mail @@ -545,7 +545,7 @@ function settings_post(App $a) $str_contact_deny = !empty($_POST['contact_deny']) ? perms2str($_POST['contact_deny']) : ''; $openidserver = $a->user['openidserver']; - //$openid = normalise_openid($openid); + //$openid = Strings::normaliseOpenID($openid); // If openid has changed or if there's an openid but no openidserver, try and discover it. if ($openid != $a->user['openid'] || (strlen($openid) && (!strlen($openidserver)))) { diff --git a/src/App.php b/src/App.php index cf8fc7abe..a9fc7173c 100644 --- a/src/App.php +++ b/src/App.php @@ -1443,7 +1443,7 @@ class App // and www.example.com vs example.com. // We will only change the url to an ip address if there is no existing setting - if (empty($url) || (!link_compare($url, $this->getBaseURL())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $this->getHostName()))) { + if (empty($url) || (!Util\Strings::compareLink($url, $this->getBaseURL())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $this->getHostName()))) { Core\Config::set('system', 'url', $this->getBaseURL()); } } diff --git a/src/Model/Item.php b/src/Model/Item.php index c2238c1c4..5a4479677 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -2403,7 +2403,7 @@ class Item extends BaseObject public static function setHashtags(&$item) { - $tags = get_tags($item["body"]); + $tags = Strings::getTags($item["body"]); // No hashtags? if (!count($tags)) { @@ -2556,7 +2556,7 @@ class Item extends BaseObject $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]); } diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 4fc7b3ab4..be667ee60 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -1141,7 +1141,7 @@ class Profile } $achar = strpos($s, '?') ? '&' : '?'; $mine = self::getMyURL(); - if ($mine && !link_compare($mine, $s)) { + if ($mine && !Strings::compareLink($mine, $s)) { return $s . $achar . 'zrl=' . urlencode($mine); } return $s; diff --git a/src/Model/User.php b/src/Model/User.php index cbf862446..84083b868 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -499,7 +499,7 @@ class User throw new Exception(L10n::t('Your email domain is not among those allowed on this site.')); } - if (!valid_email($email) || !Network::isEmailDomainValid($email)) { + if (!Strings::isValidEmail($email) || !Network::isEmailDomainValid($email)) { throw new Exception(L10n::t('Not a valid email address.')); } if (self::isNicknameBlocked($nickname)) { diff --git a/src/Object/Post.php b/src/Object/Post.php index e0e3beadb..220168343 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -21,6 +21,7 @@ use Friendica\Model\Term; use Friendica\Util\Crypto; use Friendica\Util\DateTimeFormat; use Friendica\Util\Proxy as ProxyUtils; +use Friendica\Util\Strings; use Friendica\Util\Temporal; require_once 'include/dba.php'; @@ -156,7 +157,7 @@ class Post extends BaseObject $shareable = in_array($conv->getProfileOwner(), [0, local_user()]) && $item['private'] != 1; - if (local_user() && link_compare($a->contact['url'], $item['author-link'])) { + if (local_user() && Strings::compareLink($a->contact['url'], $item['author-link'])) { if ($item["event-id"] != 0) { $edpost = ["events/event/" . $item['event-id'], L10n::t("Edit")]; } else { @@ -854,8 +855,8 @@ class Post extends BaseObject $this->owner_name = $a->page_contact['name']; $this->wall_to_wall = true; } elseif ($this->getDataValue('owner-link')) { - $owner_linkmatch = (($this->getDataValue('owner-link')) && link_compare($this->getDataValue('owner-link'), $this->getDataValue('author-link'))); - $alias_linkmatch = (($this->getDataValue('alias')) && link_compare($this->getDataValue('alias'), $this->getDataValue('author-link'))); + $owner_linkmatch = (($this->getDataValue('owner-link')) && Strings::compareLink($this->getDataValue('owner-link'), $this->getDataValue('author-link'))); + $alias_linkmatch = (($this->getDataValue('alias')) && Strings::compareLink($this->getDataValue('alias'), $this->getDataValue('author-link'))); $owner_namematch = (($this->getDataValue('owner-name')) && $this->getDataValue('owner-name') == $this->getDataValue('author-name')); if (!$owner_linkmatch && !$alias_linkmatch && !$owner_namematch) { diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 71ef636a3..7f7e52f54 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -2256,7 +2256,7 @@ class DFRN } } - if ($Blink && link_compare($Blink, System::baseUrl() . "/profile/" . $importer["nickname"])) { + if ($Blink && Strings::compareLink($Blink, System::baseUrl() . "/profile/" . $importer["nickname"])) { $author = DBA::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item['author-id']]); $item['id'] = $posted_id; @@ -2738,7 +2738,7 @@ class DFRN Logger::log("Contact ".$importer["id"]." isn't known to user ".$importer["importer_uid"].". The post will be ignored.", Logger::DEBUG); return; } - if (!link_compare($item["owner-link"], $importer["url"])) { + if (!Strings::compareLink($item["owner-link"], $importer["url"])) { /* * The item owner info is not our contact. It's OK and is to be expected if this is a tgroup delivery, * but otherwise there's a possible data mixup on the sender's system. @@ -3090,7 +3090,7 @@ class DFRN $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]); } diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 39053c393..657009e77 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -113,7 +113,7 @@ class Diaspora // Now we are collecting all relay contacts foreach ($serverlist as $server_url) { // We don't send messages to ourselves - if (link_compare($server_url, System::baseUrl())) { + if (Strings::compareLink($server_url, System::baseUrl())) { continue; } $contact = self::getRelayContact($server_url); @@ -2706,7 +2706,7 @@ class Diaspora $parent = Item::selectFirst(['author-link'], ['id' => $item["parent"]]); // Only delete it if the parent author really fits - if (!link_compare($parent["author-link"], $contact["url"]) && !link_compare($item["author-link"], $contact["url"])) { + if (!Strings::compareLink($parent["author-link"], $contact["url"]) && !Strings::compareLink($item["author-link"], $contact["url"])) { Logger::log("Thread author ".$parent["author-link"]." and item author ".$item["author-link"]." don't fit to expected contact ".$contact["url"], Logger::DEBUG); continue; } diff --git a/src/Util/Strings.php b/src/Util/Strings.php index dbab71d35..3febe60bd 100644 --- a/src/Util/Strings.php +++ b/src/Util/Strings.php @@ -289,7 +289,7 @@ class Strings * * @return array List of tag and person names */ - public static function getTags($string) // get_tags() + public static function getTags($string) { $ret = []; @@ -357,7 +357,7 @@ class Strings * * @return boolean Value indicating whether or not the string is a valid email address. */ - public static function isValidEmail($email_address) // valid_email() + public static function isValidEmail($email_address) { return preg_match('/^[_a-zA-Z0-9\-\+]+(\.[_a-zA-Z0-9\-\+]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/', $email_address); } @@ -382,7 +382,7 @@ class Strings * * @return string normalized OpenId Identity */ - function normaliseOpenID($s) // normalize_openid() + function normaliseOpenID($s) { return trim(str_replace(['http://', 'https://'], ['', ''], $s), '/'); } @@ -398,8 +398,8 @@ class Strings * @return boolean True if the URLs match, otherwise False * */ - public static function compareLink($a, $b) // link_compare() + public static function compareLink($a, $b) { - return (strcasecmp(normalise_link($a), normalise_link($b)) === 0); + return (strcasecmp(self::normaliseLink($a), self::normaliseLink($b)) === 0); } } diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index 59d506af3..f67390f84 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -18,6 +18,7 @@ use Friendica\Model\User; use Friendica\Protocol\DFRN; use Friendica\Protocol\Diaspora; use Friendica\Protocol\Email; +use Friendica\Util\Strings; require_once 'include/items.php'; @@ -247,7 +248,7 @@ class Delivery extends BaseObject // perform local delivery if we are on the same site - if (link_compare($basepath, System::baseUrl())) { + if (Strings::compareLink($basepath, System::baseUrl())) { $condition = ['nurl' => normalise_link($contact['url']), 'self' => true]; $target_self = DBA::selectFirst('contact', ['uid'], $condition); if (!DBA::isResult($target_self)) {