diff --git a/src/Content/Item.php b/src/Content/Item.php index 823660969c..aa8662705c 100644 --- a/src/Content/Item.php +++ b/src/Content/Item.php @@ -440,7 +440,7 @@ class Item ]; if (!empty($item['language'])) { - $menu[$this->l10n->t('Languages')] = 'javascript:alert(\'' . ItemModel::getLanguageMessage($item) . '\');'; + $menu[$this->l10n->t('Languages')] = 'javascript:displayLanguage(' . $item['uri-id'] . ');'; } $menu[$this->l10n->t('Search Text')] = 'javascript:displaySearchText(' . $item['uri-id'] . ');'; diff --git a/src/Module/Item/Language.php b/src/Module/Item/Language.php new file mode 100644 index 0000000000..519a6bf4d1 --- /dev/null +++ b/src/Module/Item/Language.php @@ -0,0 +1,67 @@ +. + * + */ + +namespace Friendica\Module\Item; + +use Friendica\App; +use Friendica\BaseModule; +use Friendica\Core\L10n; +use Friendica\Core\Session\Capability\IHandleUserSessions; +use Friendica\Model\Item; +use Friendica\Model\Post; +use Friendica\Module\Api\ApiResponse; +use Friendica\Network\HTTPException; +use Friendica\Util\Profiler; +use Psr\Log\LoggerInterface; + +/** + * Return the language of a given item uri-id + */ +class Language 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(), ['language'], ['uid' => [0, $this->session->getLocalUserId()], 'uri-id' => $this->parameters['id']]); + if (empty($item)) { + throw new HTTPException\NotFoundException(); + } + + $this->httpExit(Item::getLanguageMessage($item)); + } +} diff --git a/src/Object/Post.php b/src/Object/Post.php index 2bf76924a4..b341612e8c 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -521,7 +521,7 @@ class Post $languages = []; if (!empty($item['language'])) { - $languages = [DI::l10n()->t('Languages'), Item::getLanguageMessage($item)]; + $languages = DI::l10n()->t('Languages'); } if (in_array($item['private'], [Item::PUBLIC, Item::UNLISTED]) && in_array($item['network'], Protocol::FEDERATED)) { diff --git a/static/routes.config.php b/static/routes.config.php index bc812e4c38..0f603b7e3b 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -390,8 +390,6 @@ return [ '/event/{mode:edit|copy}/{id:\d+}' => [Module\Calendar\Event\Form::class, [R::GET ]], ], -// '/callback/searchtext', - '/channel[/{content}]' => [Module\Conversation\Channel::class, [R::GET]], '/community[/{content}]' => [Module\Conversation\Community::class, [R::GET]], @@ -482,9 +480,10 @@ return [ '/activity/{verb}' => [Module\Item\Activity::class, [ R::POST]], '/follow' => [Module\Item\Follow::class, [ R::POST]], '/ignore' => [Module\Item\Ignore::class, [ R::POST]], + '/language' => [Module\Item\Language::class, [R::GET]], '/pin' => [Module\Item\Pin::class, [ R::POST]], - '/star' => [Module\Item\Star::class, [ R::POST]], '/searchtext' => [Module\Item\Searchtext::class, [R::GET]], + '/star' => [Module\Item\Star::class, [ R::POST]], ], '/localtime' => [Module\Debug\Localtime::class, [R::GET, R::POST]], diff --git a/view/js/main.js b/view/js/main.js index 27ae9b278c..89ca7607d1 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -803,6 +803,12 @@ function displaySearchText(id) { }); } +function displayLanguage(id) { + $.get('item/' + id + '/language', function(data) { + alert(data); + }); +} + var lockvisible = false; function lockview(event, type, id) { diff --git a/view/theme/frio/templates/search_item.tpl b/view/theme/frio/templates/search_item.tpl index 2472bfa27b..d2baaa56d7 100644 --- a/view/theme/frio/templates/search_item.tpl +++ b/view/theme/frio/templates/search_item.tpl @@ -221,7 +221,7 @@ {{if $item.language}}