]> git.mxchange.org Git - friendica.git/commitdiff
link_compare calls
authorAdam Magness <adam.magness@gmail.com>
Thu, 8 Nov 2018 15:46:50 +0000 (10:46 -0500)
committerAdam Magness <adam.magness@gmail.com>
Thu, 8 Nov 2018 15:46:50 +0000 (10:46 -0500)
implement compareLink function.

19 files changed:
mod/dirfind.php
mod/invite.php
mod/item.php
mod/message.php
mod/openid.php
mod/photos.php
mod/pubsub.php
mod/pubsubhubbub.php
mod/redir.php
mod/settings.php
src/App.php
src/Model/Item.php
src/Model/Profile.php
src/Model/User.php
src/Object/Post.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php
src/Util/Strings.php
src/Worker/Delivery.php

index cf58098ab96014a5a5d7e0cad307757b1f066270..738ac124f8cfb2986cb2fd6e067af58feeb55f00 100644 (file)
@@ -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]));
index e63f81d4e8ad769a455f031285edd1f1916a341b..5d33dd30aa6afb5a109dfe6bc3f6ff2f3922bfb0 100644 (file)
@@ -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;
                }
index c6f359cf4824bf3c3a52e19e3afba9431c7b4463..bf8c5f7217170b9451dff977e785eb5d4f2cb004 100644 (file)
@@ -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])) {
index afb3391474c116d8dabd47d8e7b35a5f18b4af49..6ac5d183a244e04125b63a8586916b45cb4332d4 100644 (file)
@@ -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']);
index 663bc1cecbae0a44142e9771ee0bb42202b78486..287b12781fbdf3e8bdb238b0bdad70a9a0d6d012 100644 (file)
@@ -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)) {
index 1b2e8d52b6ba66456b7ffdef6971c58cd8aeed5a..b5c648d3bd49494d6e2a2fd4d6993496a8dd40ae 100644 (file)
@@ -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) {
index edab03e3f4bed925cba660fab95e25c6eaa96cc3..06ebacbe3273487659503e1c4e29ae361743b1fc 100644 (file)
@@ -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, '');
                }
index d23f1fe47da3b7695cf195ab3ee7bfbe9ec944f9..b0557782701ce9a563f91df48cb86ef307fb48ce 100644 (file)
@@ -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);
                }
index 6077a26f9a2925041edb20572dd54f969d664ac7..f22af545f7bbe1b9d4809773911c9910082277d1 100644 (file)
@@ -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);
index 589b2383a3d189301250742b2d759e8fe5fc9304..142555691fc6f2c0ac309ae92114c78a32a41ae5 100644 (file)
@@ -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)))) {
index cf8fc7abe4c2ae2547b223a3415a04e05c39a5c3..a9fc7173c0144f2e6b2ddaabb1dac8af3ed283bc 100644 (file)
@@ -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());
                }
        }
index c2238c1c45bcc239237d2ac67038b43836cb71c4..5a44796773adf92328364aa406afdf0eecff2f63 100644 (file)
@@ -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]);
                                }
index 4fc7b3ab4bcfb4dc9bf295bd72d499a9529de06c..be667ee60fe9b13f2f687f1c100cab65089f2cf6 100644 (file)
@@ -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;
index cbf86244614a388aa5b1508bbd96190a97d1f445..84083b868f4452cdeef2a966ce9c0beeadc64d21 100644 (file)
@@ -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)) {
index e0e3beadb3ec53200bfe9549395f987773d1d9ef..22016834375b19da3377aef636db75bb01e758a9 100644 (file)
@@ -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) {
index 71ef636a3f50ab9b36cdfb61248a09458bd4d7b8..7f7e52f54f42652e46d34fb8870c7430f40a1846 100644 (file)
@@ -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]);
                                }
index 39053c3937554bc381bbd523206bc5714734ae53..657009e7764fef624f9500b822fca1e94b4fa91b 100644 (file)
@@ -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;
                        }
index dbab71d352db9dbdcc22fe382891b340e971afa0..3febe60bd8b4139a29927a5564a49ca2b4b53df2 100644 (file)
@@ -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);
     }
 }
index 59d506af3dd6ad4499e9879254351aa6308bb610..f67390f843e35cc3ddc011cd8fed68a34b3c4cc8 100644 (file)
@@ -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)) {