Merge pull request #12122 from annando/issue-2657
Issue 2657: Mentions will now be recognized by clients
This commit is contained in:
commit
4b5c6994b2
|
@ -1971,13 +1971,20 @@ class BBCode
|
||||||
$text = preg_replace("/([#])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
$text = preg_replace("/([#])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||||
'<a href="$2" class="mention hashtag" rel="tag">$1<span>$3</span></a>',
|
'<a href="$2" class="mention hashtag" rel="tag">$1<span>$3</span></a>',
|
||||||
$text);
|
$text);
|
||||||
} elseif (in_array($simple_html, [self::INTERNAL, self::EXTERNAL, self::API])) {
|
} elseif (in_array($simple_html, [self::INTERNAL, self::EXTERNAL])) {
|
||||||
$text = preg_replace("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
$text = preg_replace("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||||
'<bdi>$1<a href="$2" class="userinfo mention" title="$3">$3</a></bdi>',
|
'<bdi>$1<a href="$2" class="userinfo mention" title="$3">$3</a></bdi>',
|
||||||
$text);
|
$text);
|
||||||
$text = preg_replace("/([#])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
$text = preg_replace("/([#])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||||
'<a class="mention hashtag status-link" href="$2" rel="tag">$1<span>$3</span></a>',
|
'<a class="mention hashtag status-link" href="$2" rel="tag">$1<span>$3</span></a>',
|
||||||
$text);
|
$text);
|
||||||
|
} elseif ($simple_html == self::API) {
|
||||||
|
$text = preg_replace("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||||
|
'<a class="u-url mention status-link" href="$2" rel="nofollow noopener noreferrer" target="_blank" title="$3">$1<span>$3</span></a>',
|
||||||
|
$text);
|
||||||
|
$text = preg_replace("/([#])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||||
|
'<a class="mention hashtag status-link" href="$2" rel="tag">$1<span>$3</span></a>',
|
||||||
|
$text);
|
||||||
} else {
|
} else {
|
||||||
$text = preg_replace("/([#@!])\[url\=(.*?)\](.*?)\[\/url\]/ism", '$1$3', $text);
|
$text = preg_replace("/([#@!])\[url\=(.*?)\](.*?)\[\/url\]/ism", '$1$3', $text);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,11 @@
|
||||||
|
|
||||||
namespace Friendica\Module\Api\Mastodon\Accounts;
|
namespace Friendica\Module\Api\Mastodon\Accounts;
|
||||||
|
|
||||||
use Friendica\Core\Search as CoreSearch;
|
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Module\BaseApi;
|
use Friendica\Module\BaseApi;
|
||||||
use Friendica\Object\Search\ContactResult;
|
|
||||||
use Friendica\Util\Network;
|
use Friendica\Util\Network;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,27 +50,15 @@ class Search extends BaseApi
|
||||||
|
|
||||||
$accounts = [];
|
$accounts = [];
|
||||||
|
|
||||||
if ($request['resolve']) {
|
|
||||||
if ((strrpos($request['q'], '@') > 0) || Network::isValidHttpUrl($request['q'])) {
|
if ((strrpos($request['q'], '@') > 0) || Network::isValidHttpUrl($request['q'])) {
|
||||||
$results = CoreSearch::getContactsFromProbe($request['q']);
|
$id = Contact::getIdForURL($request['q'], 0, $request['resolve'] ? null : false);
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($results)) {
|
|
||||||
$counter = 0;
|
|
||||||
foreach ($results->getResults() as $result) {
|
|
||||||
if (++$counter > $request['limit']) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ($result instanceof ContactResult) {
|
|
||||||
$id = Contact::getIdForURL($result->getUrl(), 0, false);
|
|
||||||
|
|
||||||
|
if (!empty($id)) {
|
||||||
$accounts[] = DI::mstdnAccount()->createFromContactId($id, $uid);
|
$accounts[] = DI::mstdnAccount()->createFromContactId($id, $uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($accounts) < $request['limit']) {
|
if (empty($accounts)) {
|
||||||
$contacts = Contact::searchByName($request['q'], '', $request['following'] ? $uid : 0, $request['limit']);
|
$contacts = Contact::searchByName($request['q'], '', $request['following'] ? $uid : 0, $request['limit']);
|
||||||
foreach ($contacts as $contact) {
|
foreach ($contacts as $contact) {
|
||||||
$accounts[] = DI::mstdnAccount()->createFromContactId($contact['id'], $uid);
|
$accounts[] = DI::mstdnAccount()->createFromContactId($contact['id'], $uid);
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
namespace Friendica\Module\Api\Mastodon;
|
namespace Friendica\Module\Api\Mastodon;
|
||||||
|
|
||||||
use Friendica\Core\Protocol;
|
use Friendica\Core\Protocol;
|
||||||
use Friendica\Core\Search as CoreSearch;
|
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
@ -30,7 +29,6 @@ use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
use Friendica\Model\Tag;
|
use Friendica\Model\Tag;
|
||||||
use Friendica\Module\BaseApi;
|
use Friendica\Module\BaseApi;
|
||||||
use Friendica\Object\Search\ContactResult;
|
|
||||||
use Friendica\Util\Network;
|
use Friendica\Util\Network;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,28 +82,16 @@ class Search extends BaseApi
|
||||||
{
|
{
|
||||||
$accounts = [];
|
$accounts = [];
|
||||||
|
|
||||||
if ($resolve) {
|
|
||||||
if ((strrpos($q, '@') > 0) || Network::isValidHttpUrl($q)) {
|
if ((strrpos($q, '@') > 0) || Network::isValidHttpUrl($q)) {
|
||||||
$results = CoreSearch::getContactsFromProbe($q);
|
$id = Contact::getIdForURL($q, 0, $resolve ? null : false);
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($results)) {
|
|
||||||
$counter = 0;
|
|
||||||
foreach ($results->getResults() as $result) {
|
|
||||||
if (++$counter > $limit) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ($result instanceof ContactResult) {
|
|
||||||
$id = Contact::getIdForURL($result->getUrl(), 0, false);
|
|
||||||
|
|
||||||
|
if (!empty($id)) {
|
||||||
$accounts[] = DI::mstdnAccount()->createFromContactId($id, $uid);
|
$accounts[] = DI::mstdnAccount()->createFromContactId($id, $uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($accounts) < $limit) {
|
if (empty($accounts)) {
|
||||||
$contacts = Contact::searchByName($q, '', $following ? $uid : 0, $limit - count($accounts), $offset);
|
$contacts = Contact::searchByName($q, '', $following ? $uid : 0, $limit, $offset);
|
||||||
foreach ($contacts as $contact) {
|
foreach ($contacts as $contact) {
|
||||||
$accounts[] = DI::mstdnAccount()->createFromContactId($contact['id'], $uid);
|
$accounts[] = DI::mstdnAccount()->createFromContactId($contact['id'], $uid);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user