link_compare calls

implement compareLink function.
This commit is contained in:
Adam Magness
2018-11-08 10:46:50 -05:00
parent 6fc9c6de3b
commit 5276c28a78
19 changed files with 32 additions and 30 deletions

View 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());
}
}

View 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]);
}

View 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;

View 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)) {

View 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) {

View 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]);
}

View 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;
}

View 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);
}
}

View 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)) {