Merge pull request #7103 from nupplaphil/task/mod_smilies

Move mod/smilies to src/Module/Smilies
This commit is contained in:
Hypolite Petovan 2019-05-06 12:53:45 -04:00 committed by GitHub
commit 20c9d5fe1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 32 deletions

View File

@ -1,32 +0,0 @@
<?php
/**
* @file mod/smilies.php
*/
use Friendica\App;
use Friendica\Content\Smilies;
use Friendica\Core\System;
/**
* @param App $a App
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
function smilies_content(App $a)
{
$smilies = Smilies::getList();
if (!empty($a->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 = '<div class="smiley-sample">';
for ($x = 0; $x < count($smilies['texts']); $x ++) {
$s .= '<dl><dt>' . $smilies['texts'][$x] . '</dt><dd>' . $smilies['icons'][$x] . '</dd></dl>';
}
$s .= '</div>';
return $s;
}
}

View File

@ -171,6 +171,7 @@ class Router
$this->routeCollector->addRoute(['GET', 'POST'], '/register', Module\Register::class);
$this->routeCollector->addRoute(['GET'], '/robots.txt', Module\RobotsTxt::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'], '/viewsrc/{item:\d+}', Module\ItemBody::class);

40
src/Module/Smilies.php Normal file
View File

@ -0,0 +1,40 @@
<?php
namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Content;
use Friendica\Core\Renderer;
use Friendica\Core\System;
/**
* Prints the possible Smilies of this node
*/
class Smilies extends BaseModule
{
public static function rawContent()
{
$app = self::getApp();
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]];
}
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,
]);
}
}

View File

@ -0,0 +1,10 @@
<div id="smilies" class="generic-page-wrapper">
<div class="smiley-sample">
{{for $i=0 to $count}}
<dl>
<dt>{{$smilies.texts[$i] nofilter}}</dt>
<dd>{{$smilies.icons[$i] nofilter}}</dd>
</dl>
{{/for}}
</div>
</div>