mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-17 12:25:14 +02:00
Menu option to display the search text
This commit is contained in:
parent
44344af055
commit
50b1de5959
9 changed files with 152 additions and 44 deletions
|
@ -443,6 +443,8 @@ class Item
|
|||
$menu[$this->l10n->t('Languages')] = 'javascript:alert(\'' . ItemModel::getLanguageMessage($item) . '\');';
|
||||
}
|
||||
|
||||
$menu[$this->l10n->t('Search Text')] = 'javascript:displaySearchText(' . $item['uri-id'] . ');';
|
||||
|
||||
if ((($cid == 0) || ($rel == Contact::FOLLOWER)) &&
|
||||
in_array($item['network'], Protocol::FEDERATED)
|
||||
) {
|
||||
|
|
|
@ -418,4 +418,12 @@ class Engagement
|
|||
}
|
||||
return $fullTextSearch;
|
||||
}
|
||||
|
||||
public static function unescapeKeywords(string $fullTextSearch): string
|
||||
{
|
||||
foreach (self::KEYWORDS as $keyword) {
|
||||
$fullTextSearch = preg_replace('~(' . $keyword . ')_(.[\w\*@\.-]+)~', '$1:$2', $fullTextSearch);
|
||||
}
|
||||
return $fullTextSearch;
|
||||
}
|
||||
}
|
||||
|
|
72
src/Module/Item/Searchtext.php
Normal file
72
src/Module/Item/Searchtext.php
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2024, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Item;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Module\Api\ApiResponse;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Util\Profiler;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Return the search text of a given item id
|
||||
*/
|
||||
class Searchtext extends BaseModule
|
||||
{
|
||||
/** @var IHandleUserSessions */
|
||||
private $session;
|
||||
|
||||
public function __construct(IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
if (!$this->session->isAuthenticated()) {
|
||||
throw new HttpException\ForbiddenException($this->l10n->t('Access denied.'));
|
||||
}
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
throw new HTTPException\BadRequestException();
|
||||
}
|
||||
|
||||
$item = Post::selectFirstForUser($this->session->getLocalUserId(), ['uri-id'], ['uid' => [0, $this->session->getLocalUserId()], 'uri-id' => $this->parameters['id']]);
|
||||
if (empty($item)) {
|
||||
throw new HTTPException\NotFoundException();
|
||||
}
|
||||
|
||||
$search = DBA::selectFirst('post-searchindex', [], ['uri-id' => $item['uri-id']]);
|
||||
if (empty($search)) {
|
||||
throw new HTTPException\NotFoundException();
|
||||
}
|
||||
|
||||
$this->httpExit(Post\Engagement::unescapeKeywords($search['searchtext']));
|
||||
}
|
||||
}
|
|
@ -600,6 +600,7 @@ class Post
|
|||
'tagger' => $tagger,
|
||||
'filer' => $filer,
|
||||
'language' => $languages,
|
||||
'searchtext' => DI::l10n()->t('Search Text'),
|
||||
'drop' => $drop,
|
||||
'block' => $block,
|
||||
'ignore_author' => $ignore,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue