diff --git a/CHANGELOG.md b/CHANGELOG.md index 99d2859be..8f4eb35e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ v0.18.1 (trunk) * Order Communities in Servers by last published * Rename Communities page in Explore * Add WebM and H264 video embedding support in the Chat + * Add Tenor support for GIF/videos search and integration in Chat v0.18 --------------------------- diff --git a/app/Configuration.php b/app/Configuration.php index 2643bddcd..9404cb03b 100644 --- a/app/Configuration.php +++ b/app/Configuration.php @@ -14,6 +14,7 @@ class Configuration extends Model 'description', 'info', 'unregister', + 'gifapikey', 'restrictsuggestions', 'locale', 'loglevel', diff --git a/app/widgets/AdminMain/adminmain.tpl b/app/widgets/AdminMain/adminmain.tpl index 3ac3764cd..adf393bd3 100644 --- a/app/widgets/AdminMain/adminmain.tpl +++ b/app/widgets/AdminMain/adminmain.tpl @@ -162,6 +162,25 @@ +

{$c->__('tenor.title')}

+ +
+ + +
+ + +

{$c->__('credentials.title')}

diff --git a/app/widgets/AdminMain/locales.ini b/app/widgets/AdminMain/locales.ini index dc6db997f..5da9ee51d 100644 --- a/app/widgets/AdminMain/locales.ini +++ b/app/widgets/AdminMain/locales.ini @@ -41,6 +41,12 @@ description = Main XMPP server description country = Main XMPP server country country_pick= Pick a country in the list +[tenor] +title = Tenor integration +label = Yout Tenor API Key +info1 = Movim integrates the Tenor API to allow GIF search and publication in Chat +info2 = Access Tenor and get your API key + [log] empty = Empty syslog = Syslog diff --git a/app/widgets/Chat/chat.js b/app/widgets/Chat/chat.js index d4d59df0f..1c2ff8374 100644 --- a/app/widgets/Chat/chat.js +++ b/app/widgets/Chat/chat.js @@ -984,9 +984,21 @@ var Chat = { var video = document.createElement('video'); video.setAttribute('src', file.uri); video.setAttribute('controls', 'controls'); + video.setAttribute('loop', 'loop'); + + // Tenor implementation + if (file.host && file.host == 'media.tenor.com') { + video.setAttribute('autoplay', 'autoplay'); + } + div.appendChild(video); } + // Tenor implementation + if (file.host && file.host == 'media.tenor.com') { + return div; + } + var a = document.createElement('a'); if (sticker == null) { diff --git a/app/widgets/Stickers/Stickers.php b/app/widgets/Stickers/Stickers.php index 5bb9e6724..11a9971b2 100644 --- a/app/widgets/Stickers/Stickers.php +++ b/app/widgets/Stickers/Stickers.php @@ -5,8 +5,12 @@ use Moxl\Xec\Action\BOB\Answer; use Respect\Validation\Validator; +use App\Configuration; + class Stickers extends \Movim\Widget\Base { + private $paginate = 20; + public function load() { $this->addcss('stickers.css'); @@ -107,11 +111,13 @@ class Stickers extends \Movim\Widget\Base return; } - $packs = $this->getPacks(); + $configuration = Configuration::get(); + $isGifEnabled = !empty($configuration->gifapikey); + $packs = $this->getPacks(); $pack = isset($pack) ? $pack : current($packs); - if (in_array($pack, $packs)) { + if (!$isGifEnabled) { $files = scandir(PUBLIC_PATH.'/stickers/'.$pack); array_shift($files); @@ -122,10 +128,18 @@ class Stickers extends \Movim\Widget\Base $view->assign('stickers', $files); $view->assign('packs', $packs); $view->assign('pack', $pack); + $view->assign('gifEnabled', $isGifEnabled); $view->assign('info', parse_ini_file(PUBLIC_PATH.'/stickers/'.$pack.'/info.ini')); $view->assign('path', $this->respath('stickers', false, false, true)); Drawer::fill($view->draw('_stickers'), true); + } else { + $view = $this->tpl(); + $view->assign('jid', $to); + $view->assign('packs', $packs); + + Drawer::fill($view->draw('_stickers_gifs'), true); + $this->rpc('Stickers.setGifsSearchEvent', $to); } } @@ -144,6 +158,46 @@ class Stickers extends \Movim\Widget\Base $this->rpc('Stickers.setEmojisEvent', $mid); } + /** + * @brief Search for gifs + */ + public function ajaxHttpSearchGifs($keyword, int $page = 0) + { + $configuration = Configuration::get(); + $apiKey = $configuration->gifapikey; + + if (empty($apiKey)) return; + + $keyword = filter_var($keyword, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); + $results = requestURL( + 'https://api.tenor.com/v1/search?q='.$keyword. + '&key='.$apiKey. + '&limit='.$this->paginate. + '&pos='.($page*$this->paginate) + ); + + $view = $this->tpl(); + + if ($results) { + $results = \json_decode($results); + + if ($results) { + foreach ($results->results as $result) { + $gif = [ + 'url' => $result->media[0]->tinywebm->url, + 'preview' => $result->media[0]->tinywebm->preview, + 'width' => $result->media[0]->tinywebm->dims[0], + 'height' => $result->media[0]->tinywebm->dims[1], + ]; + $view->assign('gif', $gif); + $this->rpc('MovimTpl.append', '#gifs .masonry', $view->draw('_stickers_gifs_result')); + } + } + } + + $this->rpc('Stickers.setGifsEvents'); + } + /** * @brief Get the path of an emoji */ diff --git a/app/widgets/Stickers/_stickers.tpl b/app/widgets/Stickers/_stickers.tpl index d7bc0bc6f..235c8ae41 100644 --- a/app/widgets/Stickers/_stickers.tpl +++ b/app/widgets/Stickers/_stickers.tpl @@ -28,6 +28,11 @@