mirror of
https://github.com/friendica/friendica
synced 2024-12-22 22:40:16 +00:00
link_compare calls
implement compareLink function.
This commit is contained in:
parent
6fc9c6de3b
commit
5276c28a78
19 changed files with 32 additions and 30 deletions
|
@ -53,7 +53,7 @@ function dirfind_content(App $a, $prefix = "") {
|
||||||
if (strpos($search,'@') === 0) {
|
if (strpos($search,'@') === 0) {
|
||||||
$search = substr($search,1);
|
$search = substr($search,1);
|
||||||
$header = L10n::t('People Search - %s', $search);
|
$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://")) {
|
(substr(normalise_link($search), 0, 7) == "http://")) {
|
||||||
$user_data = Probe::uri($search);
|
$user_data = Probe::uri($search);
|
||||||
$discover_user = (in_array($user_data["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA]));
|
$discover_user = (in_array($user_data["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA]));
|
||||||
|
|
|
@ -56,7 +56,7 @@ function invite_post(App $a)
|
||||||
foreach ($recipients as $recipient) {
|
foreach ($recipients as $recipient) {
|
||||||
$recipient = trim($recipient);
|
$recipient = trim($recipient);
|
||||||
|
|
||||||
if (! valid_email($recipient)) {
|
if (! Strings::isValidEmail($recipient)) {
|
||||||
notice(L10n::t('%s : Not a valid email address.', $recipient) . EOL);
|
notice(L10n::t('%s : Not a valid email address.', $recipient) . EOL);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -348,7 +348,7 @@ function item_post(App $a) {
|
||||||
$str_tags = '';
|
$str_tags = '';
|
||||||
$inform = '';
|
$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)
|
// 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])) {
|
if ($parent && in_array($thr_parent_contact['network'], [Protocol::OSTATUS, Protocol::ACTIVITYPUB])) {
|
||||||
|
|
|
@ -463,7 +463,7 @@ function render_messages(array $msg, $t)
|
||||||
foreach ($msg as $rr) {
|
foreach ($msg as $rr) {
|
||||||
if ($rr['unknown']) {
|
if ($rr['unknown']) {
|
||||||
$participants = L10n::t("Unknown sender - %s", $rr['from-name']);
|
$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']);
|
$participants = L10n::t("You and %s", $rr['name']);
|
||||||
} else {
|
} else {
|
||||||
$participants = L10n::t("%s and You", $rr['from-name']);
|
$participants = L10n::t("%s and You", $rr['from-name']);
|
||||||
|
|
|
@ -44,7 +44,7 @@ function openid_content(App $a) {
|
||||||
AND `blocked` = 0 AND `account_expired` = 0
|
AND `blocked` = 0 AND `account_expired` = 0
|
||||||
AND `account_removed` = 0 AND `verified` = 1
|
AND `account_removed` = 0 AND `verified` = 1
|
||||||
LIMIT 1",
|
LIMIT 1",
|
||||||
DBA::escape($authid), DBA::escape(normalise_openid($authid))
|
DBA::escape($authid), DBA::escape(Strings::normaliseOpenID($authid))
|
||||||
);
|
);
|
||||||
|
|
||||||
if (DBA::isResult($r)) {
|
if (DBA::isResult($r)) {
|
||||||
|
|
|
@ -525,7 +525,7 @@ function photos_post(App $a)
|
||||||
}
|
}
|
||||||
|
|
||||||
$taginfo = [];
|
$taginfo = [];
|
||||||
$tags = get_tags($rawtags);
|
$tags = Strings::getTags($rawtags);
|
||||||
|
|
||||||
if (count($tags)) {
|
if (count($tags)) {
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
|
|
|
@ -64,7 +64,7 @@ function pubsub_init(App $a)
|
||||||
hub_return(false, '');
|
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']);
|
Logger::log('Hub topic ' . $hub_topic . ' != ' . $contact['poll']);
|
||||||
hub_return(false, '');
|
hub_return(false, '');
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ function pubsubhubbub_init(App $a) {
|
||||||
|
|
||||||
// sanity check that topic URLs are the same
|
// sanity check that topic URLs are the same
|
||||||
$hub_topic2 = str_replace('/feed/', '/dfrn_poll/', $hub_topic);
|
$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']);
|
Logger::log('Hub topic ' . $hub_topic . ' != ' . $contact['poll']);
|
||||||
System::httpExit(404);
|
System::httpExit(404);
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ function redir_init(App $a) {
|
||||||
if (!empty($url)) {
|
if (!empty($url)) {
|
||||||
$my_profile = Profile::getMyURL();
|
$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, '?') ? '&' : '?';
|
$separator = strpos($url, '?') ? '&' : '?';
|
||||||
|
|
||||||
$url .= $separator . 'zrl=' . urlencode($my_profile);
|
$url .= $separator . 'zrl=' . urlencode($my_profile);
|
||||||
|
|
|
@ -517,7 +517,7 @@ function settings_post(App $a)
|
||||||
$email = $a->user['email'];
|
$email = $a->user['email'];
|
||||||
}
|
}
|
||||||
// check the email is valid
|
// check the email is valid
|
||||||
if (!valid_email($email)) {
|
if (!Strings::isValidEmail($email)) {
|
||||||
$err .= L10n::t('Invalid email.');
|
$err .= L10n::t('Invalid email.');
|
||||||
}
|
}
|
||||||
// ensure new email is not the admin mail
|
// 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']) : '';
|
$str_contact_deny = !empty($_POST['contact_deny']) ? perms2str($_POST['contact_deny']) : '';
|
||||||
|
|
||||||
$openidserver = $a->user['openidserver'];
|
$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 has changed or if there's an openid but no openidserver, try and discover it.
|
||||||
if ($openid != $a->user['openid'] || (strlen($openid) && (!strlen($openidserver)))) {
|
if ($openid != $a->user['openid'] || (strlen($openid) && (!strlen($openidserver)))) {
|
||||||
|
|
|
@ -1443,7 +1443,7 @@ class App
|
||||||
// and www.example.com vs example.com.
|
// and www.example.com vs example.com.
|
||||||
// We will only change the url to an ip address if there is no existing setting
|
// 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());
|
Core\Config::set('system', 'url', $this->getBaseURL());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2403,7 +2403,7 @@ class Item extends BaseObject
|
||||||
public static function setHashtags(&$item)
|
public static function setHashtags(&$item)
|
||||||
{
|
{
|
||||||
|
|
||||||
$tags = get_tags($item["body"]);
|
$tags = Strings::getTags($item["body"]);
|
||||||
|
|
||||||
// No hashtags?
|
// No hashtags?
|
||||||
if (!count($tags)) {
|
if (!count($tags)) {
|
||||||
|
@ -2556,7 +2556,7 @@ class Item extends BaseObject
|
||||||
$cnt = preg_match_all('/[\@\!]\[url\=(.*?)\](.*?)\[\/url\]/ism', $item['body'], $matches, PREG_SET_ORDER);
|
$cnt = preg_match_all('/[\@\!]\[url\=(.*?)\](.*?)\[\/url\]/ism', $item['body'], $matches, PREG_SET_ORDER);
|
||||||
if ($cnt) {
|
if ($cnt) {
|
||||||
foreach ($matches as $mtch) {
|
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;
|
$mention = true;
|
||||||
Logger::log('mention found: ' . $mtch[2]);
|
Logger::log('mention found: ' . $mtch[2]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1141,7 +1141,7 @@ class Profile
|
||||||
}
|
}
|
||||||
$achar = strpos($s, '?') ? '&' : '?';
|
$achar = strpos($s, '?') ? '&' : '?';
|
||||||
$mine = self::getMyURL();
|
$mine = self::getMyURL();
|
||||||
if ($mine && !link_compare($mine, $s)) {
|
if ($mine && !Strings::compareLink($mine, $s)) {
|
||||||
return $s . $achar . 'zrl=' . urlencode($mine);
|
return $s . $achar . 'zrl=' . urlencode($mine);
|
||||||
}
|
}
|
||||||
return $s;
|
return $s;
|
||||||
|
|
|
@ -499,7 +499,7 @@ class User
|
||||||
throw new Exception(L10n::t('Your email domain is not among those allowed on this site.'));
|
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.'));
|
throw new Exception(L10n::t('Not a valid email address.'));
|
||||||
}
|
}
|
||||||
if (self::isNicknameBlocked($nickname)) {
|
if (self::isNicknameBlocked($nickname)) {
|
||||||
|
|
|
@ -21,6 +21,7 @@ use Friendica\Model\Term;
|
||||||
use Friendica\Util\Crypto;
|
use Friendica\Util\Crypto;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\Proxy as ProxyUtils;
|
use Friendica\Util\Proxy as ProxyUtils;
|
||||||
|
use Friendica\Util\Strings;
|
||||||
use Friendica\Util\Temporal;
|
use Friendica\Util\Temporal;
|
||||||
|
|
||||||
require_once 'include/dba.php';
|
require_once 'include/dba.php';
|
||||||
|
@ -156,7 +157,7 @@ class Post extends BaseObject
|
||||||
|
|
||||||
$shareable = in_array($conv->getProfileOwner(), [0, local_user()]) && $item['private'] != 1;
|
$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) {
|
if ($item["event-id"] != 0) {
|
||||||
$edpost = ["events/event/" . $item['event-id'], L10n::t("Edit")];
|
$edpost = ["events/event/" . $item['event-id'], L10n::t("Edit")];
|
||||||
} else {
|
} else {
|
||||||
|
@ -854,8 +855,8 @@ class Post extends BaseObject
|
||||||
$this->owner_name = $a->page_contact['name'];
|
$this->owner_name = $a->page_contact['name'];
|
||||||
$this->wall_to_wall = true;
|
$this->wall_to_wall = true;
|
||||||
} elseif ($this->getDataValue('owner-link')) {
|
} elseif ($this->getDataValue('owner-link')) {
|
||||||
$owner_linkmatch = (($this->getDataValue('owner-link')) && link_compare($this->getDataValue('owner-link'), $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')) && link_compare($this->getDataValue('alias'), $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'));
|
$owner_namematch = (($this->getDataValue('owner-name')) && $this->getDataValue('owner-name') == $this->getDataValue('author-name'));
|
||||||
|
|
||||||
if (!$owner_linkmatch && !$alias_linkmatch && !$owner_namematch) {
|
if (!$owner_linkmatch && !$alias_linkmatch && !$owner_namematch) {
|
||||||
|
|
|
@ -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']]);
|
$author = DBA::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item['author-id']]);
|
||||||
|
|
||||||
$item['id'] = $posted_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);
|
Logger::log("Contact ".$importer["id"]." isn't known to user ".$importer["importer_uid"].". The post will be ignored.", Logger::DEBUG);
|
||||||
return;
|
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,
|
* 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.
|
* 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);
|
$cnt = preg_match_all('/[\@\!]\[url\=(.*?)\](.*?)\[\/url\]/ism', $item['body'], $matches, PREG_SET_ORDER);
|
||||||
if ($cnt) {
|
if ($cnt) {
|
||||||
foreach ($matches as $mtch) {
|
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;
|
$mention = true;
|
||||||
Logger::log('mention found: ' . $mtch[2]);
|
Logger::log('mention found: ' . $mtch[2]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ class Diaspora
|
||||||
// Now we are collecting all relay contacts
|
// Now we are collecting all relay contacts
|
||||||
foreach ($serverlist as $server_url) {
|
foreach ($serverlist as $server_url) {
|
||||||
// We don't send messages to ourselves
|
// We don't send messages to ourselves
|
||||||
if (link_compare($server_url, System::baseUrl())) {
|
if (Strings::compareLink($server_url, System::baseUrl())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$contact = self::getRelayContact($server_url);
|
$contact = self::getRelayContact($server_url);
|
||||||
|
@ -2706,7 +2706,7 @@ class Diaspora
|
||||||
$parent = Item::selectFirst(['author-link'], ['id' => $item["parent"]]);
|
$parent = Item::selectFirst(['author-link'], ['id' => $item["parent"]]);
|
||||||
|
|
||||||
// Only delete it if the parent author really fits
|
// 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);
|
Logger::log("Thread author ".$parent["author-link"]." and item author ".$item["author-link"]." don't fit to expected contact ".$contact["url"], Logger::DEBUG);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -289,7 +289,7 @@ class Strings
|
||||||
*
|
*
|
||||||
* @return array List of tag and person names
|
* @return array List of tag and person names
|
||||||
*/
|
*/
|
||||||
public static function getTags($string) // get_tags()
|
public static function getTags($string)
|
||||||
{
|
{
|
||||||
$ret = [];
|
$ret = [];
|
||||||
|
|
||||||
|
@ -357,7 +357,7 @@ class Strings
|
||||||
*
|
*
|
||||||
* @return boolean Value indicating whether or not the string is a valid email address.
|
* @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);
|
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
|
* @return string normalized OpenId Identity
|
||||||
*/
|
*/
|
||||||
function normaliseOpenID($s) // normalize_openid()
|
function normaliseOpenID($s)
|
||||||
{
|
{
|
||||||
return trim(str_replace(['http://', 'https://'], ['', ''], $s), '/');
|
return trim(str_replace(['http://', 'https://'], ['', ''], $s), '/');
|
||||||
}
|
}
|
||||||
|
@ -398,8 +398,8 @@ class Strings
|
||||||
* @return boolean True if the URLs match, otherwise False
|
* @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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ use Friendica\Model\User;
|
||||||
use Friendica\Protocol\DFRN;
|
use Friendica\Protocol\DFRN;
|
||||||
use Friendica\Protocol\Diaspora;
|
use Friendica\Protocol\Diaspora;
|
||||||
use Friendica\Protocol\Email;
|
use Friendica\Protocol\Email;
|
||||||
|
use Friendica\Util\Strings;
|
||||||
|
|
||||||
require_once 'include/items.php';
|
require_once 'include/items.php';
|
||||||
|
|
||||||
|
@ -247,7 +248,7 @@ class Delivery extends BaseObject
|
||||||
|
|
||||||
// perform local delivery if we are on the same site
|
// 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];
|
$condition = ['nurl' => normalise_link($contact['url']), 'self' => true];
|
||||||
$target_self = DBA::selectFirst('contact', ['uid'], $condition);
|
$target_self = DBA::selectFirst('contact', ['uid'], $condition);
|
||||||
if (!DBA::isResult($target_self)) {
|
if (!DBA::isResult($target_self)) {
|
||||||
|
|
Loading…
Reference in a new issue