2020-01-05 23:29:54 +01:00
|
|
|
<?php
|
2020-02-09 15:45:36 +01:00
|
|
|
/**
|
2024-01-02 21:57:26 +01:00
|
|
|
* @copyright Copyright (C) 2010-2024, the Friendica project
|
2020-02-09 15:45:36 +01:00
|
|
|
*
|
|
|
|
* @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/>.
|
|
|
|
*
|
|
|
|
*/
|
2020-01-05 23:29:54 +01:00
|
|
|
|
2020-01-28 13:33:37 +01:00
|
|
|
namespace Friendica\Factory\Api\Mastodon;
|
2020-01-05 23:29:54 +01:00
|
|
|
|
2020-01-28 13:33:37 +01:00
|
|
|
use Friendica\BaseFactory;
|
2020-01-28 03:33:51 +01:00
|
|
|
use Friendica\Collection\Api\Mastodon\Emojis;
|
2020-01-05 23:29:54 +01:00
|
|
|
|
2020-01-28 13:33:37 +01:00
|
|
|
class Emoji extends BaseFactory
|
2020-01-05 23:29:54 +01:00
|
|
|
{
|
2021-06-09 00:09:32 +02:00
|
|
|
public function create(string $shortcode, string $url): \Friendica\Object\Api\Mastodon\Emoji
|
2020-01-05 23:29:54 +01:00
|
|
|
{
|
2020-01-28 03:33:51 +01:00
|
|
|
return new \Friendica\Object\Api\Mastodon\Emoji($shortcode, $url);
|
2020-01-05 23:29:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-11-12 13:59:49 +01:00
|
|
|
* Creates an emoji collection from shortcode => image mappings.
|
|
|
|
*
|
2020-01-28 03:33:51 +01:00
|
|
|
* @param array $smilies
|
2022-08-12 13:35:27 +02:00
|
|
|
*
|
2020-01-28 03:33:51 +01:00
|
|
|
* @return Emojis
|
2020-01-05 23:29:54 +01:00
|
|
|
*/
|
2023-11-15 16:53:38 +01:00
|
|
|
public function createCollectionFromArray(array $smilies): Emojis
|
2020-01-05 23:29:54 +01:00
|
|
|
{
|
2020-01-28 03:33:51 +01:00
|
|
|
$prototype = null;
|
2020-01-05 23:29:54 +01:00
|
|
|
|
2020-01-28 03:33:51 +01:00
|
|
|
$emojis = [];
|
|
|
|
|
2023-11-14 03:52:34 +01:00
|
|
|
foreach ($smilies as $shortcode => $url) {
|
2023-11-15 16:53:38 +01:00
|
|
|
if ($shortcode !== '' && $url !== '') {
|
2023-11-12 13:59:49 +01:00
|
|
|
$shortcode = trim($shortcode, ':');
|
2020-01-28 03:33:51 +01:00
|
|
|
|
|
|
|
if ($prototype === null) {
|
|
|
|
$prototype = $this->create($shortcode, $url);
|
2021-06-09 00:09:32 +02:00
|
|
|
$emojis[] = $prototype;
|
2020-01-28 03:33:51 +01:00
|
|
|
} else {
|
|
|
|
$emojis[] = \Friendica\Object\Api\Mastodon\Emoji::createFromPrototype($prototype, $shortcode, $url);
|
|
|
|
}
|
2023-11-12 13:59:49 +01:00
|
|
|
}
|
2020-01-28 03:33:51 +01:00
|
|
|
}
|
2020-01-05 23:29:54 +01:00
|
|
|
|
2020-01-28 03:33:51 +01:00
|
|
|
return new Emojis($emojis);
|
2020-01-05 23:29:54 +01:00
|
|
|
}
|
2023-11-12 13:59:49 +01:00
|
|
|
|
|
|
|
/**
|
2023-11-15 16:53:38 +01:00
|
|
|
* @param array $smilies as is returned by Smilies::getList()
|
2023-11-12 13:59:49 +01:00
|
|
|
*
|
|
|
|
* @return Emojis
|
|
|
|
*/
|
|
|
|
public function createCollectionFromSmilies(array $smilies): Emojis
|
|
|
|
{
|
2023-11-15 16:53:38 +01:00
|
|
|
$emojis = [];
|
|
|
|
$icons = $smilies['icons'];
|
|
|
|
foreach ($smilies['texts'] as $i => $name) {
|
|
|
|
$url = $icons[$i];
|
|
|
|
if (preg_match('/src="(.+?)"/', $url, $matches)) {
|
|
|
|
$emojis[$name] = $matches[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self::createCollectionFromArray($emojis);
|
2023-11-12 13:59:49 +01:00
|
|
|
}
|
2020-01-05 23:29:54 +01:00
|
|
|
}
|