From e90876cd86895a64c8a0d8fec2e2caddc3ac5613 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sun, 5 May 2019 19:39:02 +0200 Subject: [PATCH 1/3] Move mod/smilies to src/Module/Smilies --- mod/smilies.php | 32 ------------------------------- src/App/Router.php | 1 + src/Module/Smilies.php | 39 ++++++++++++++++++++++++++++++++++++++ view/templates/smilies.tpl | 10 ++++++++++ 4 files changed, 50 insertions(+), 32 deletions(-) delete mode 100644 mod/smilies.php create mode 100644 src/Module/Smilies.php create mode 100644 view/templates/smilies.tpl diff --git a/mod/smilies.php b/mod/smilies.php deleted file mode 100644 index bbb7de2e2..000000000 --- a/mod/smilies.php +++ /dev/null @@ -1,32 +0,0 @@ -argv[1]) && ($a->argv[1] === "json")) { - $results = []; - for ($i = 0; $i < count($smilies['texts']); $i++) { - $results[] = ['text' => $smilies['texts'][$i], 'icon' => $smilies['icons'][$i]]; - } - System::jsonExit($results); - } else { - $s = '
'; - for ($x = 0; $x < count($smilies['texts']); $x ++) { - $s .= '
' . $smilies['texts'][$x] . '
' . $smilies['icons'][$x] . '
'; - } - $s .= '
'; - - return $s; - } -} diff --git a/src/App/Router.php b/src/App/Router.php index 1dffb6b40..30375667a 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -165,6 +165,7 @@ class Router }); $this->routeCollector->addRoute(['GET', 'POST'], '/register', Module\Register::class); $this->routeCollector->addRoute(['GET'], '/rsd.xml', Module\ReallySimpleDiscovery::class); + $this->routeCollector->addRoute(['GET'], '/smilies[/json]', Module\Smilies::class); $this->routeCollector->addRoute(['GET'], '/statistics.json', Module\Statistics::class); $this->routeCollector->addRoute(['GET'], '/tos', Module\Tos::class); $this->routeCollector->addRoute(['GET'], '/webfinger', Module\WebFinger::class); diff --git a/src/Module/Smilies.php b/src/Module/Smilies.php new file mode 100644 index 000000000..df4b4e1cd --- /dev/null +++ b/src/Module/Smilies.php @@ -0,0 +1,39 @@ + $count, + '$smilies' => $smilies, + ]); + } + + public static function rawContent() + { + $app = self::getApp(); + $smilies = \Friendica\Content\Smilies::getList(); + + if (!empty($app->argv[1]) && ($app->argv[1] === "json")) { + $results = []; + for ($i = 0; $i < count($smilies['texts']); $i++) { + $results[] = ['text' => $smilies['texts'][$i], 'icon' => $smilies['icons'][$i]]; + } + System::jsonExit($results); + } + } +} diff --git a/view/templates/smilies.tpl b/view/templates/smilies.tpl new file mode 100644 index 000000000..6f9fda83b --- /dev/null +++ b/view/templates/smilies.tpl @@ -0,0 +1,10 @@ +
+
+ {{for $i=0 to $count}} +
+
{{$smilies.texts[$i] nofilter}}
+
{{$smilies.icons[$i] nofilter}}
+
+ {{/for}} +
+
From 23158bc3c87c118b3260e1b9cd42ff0bc48c80ae Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Mon, 6 May 2019 08:27:57 +0200 Subject: [PATCH 2/3] add feedback --- src/Module/Smilies.php | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Module/Smilies.php b/src/Module/Smilies.php index df4b4e1cd..346ae0914 100644 --- a/src/Module/Smilies.php +++ b/src/Module/Smilies.php @@ -3,6 +3,7 @@ namespace Friendica\Module; use Friendica\BaseModule; +use Friendica\Content; use Friendica\Core\Renderer; use Friendica\Core\System; @@ -11,22 +12,10 @@ use Friendica\Core\System; */ class Smilies extends BaseModule { - public static function content() - { - $smilies = \Friendica\Content\Smilies::getList(); - $count = count(defaults($smilies, 'texts', [])); - - $tpl = Renderer::getMarkupTemplate('smilies.tpl'); - return Renderer::replaceMacros($tpl, [ - '$count' => $count, - '$smilies' => $smilies, - ]); - } - public static function rawContent() { $app = self::getApp(); - $smilies = \Friendica\Content\Smilies::getList(); + $smilies = Content\Smilies::getList(); if (!empty($app->argv[1]) && ($app->argv[1] === "json")) { $results = []; @@ -36,4 +25,16 @@ class Smilies extends BaseModule System::jsonExit($results); } } + + public static function content() + { + $smilies = Content\Smilies::getList(); + $count = count(defaults($smilies, 'texts', [])); + + $tpl = Renderer::getMarkupTemplate('smilies.tpl'); + return Renderer::replaceMacros($tpl, [ + '$count' => $count, + '$smilies' => $smilies, + ]); + } } From 97f02c267001f3a5c97e332ddedf837668d00ed2 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Mon, 6 May 2019 18:46:37 +0200 Subject: [PATCH 3/3] Move Smilies::getList() into if --- src/Module/Smilies.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module/Smilies.php b/src/Module/Smilies.php index 346ae0914..422f37d3e 100644 --- a/src/Module/Smilies.php +++ b/src/Module/Smilies.php @@ -15,9 +15,9 @@ class Smilies extends BaseModule public static function rawContent() { $app = self::getApp(); - $smilies = Content\Smilies::getList(); if (!empty($app->argv[1]) && ($app->argv[1] === "json")) { + $smilies = Content\Smilies::getList(); $results = []; for ($i = 0; $i < count($smilies['texts']); $i++) { $results[] = ['text' => $smilies['texts'][$i], 'icon' => $smilies['icons'][$i]];