Merge pull request #7159 from nupplaphil/task/mod_notice

Move mod/notice to src/Module/Notice
This commit is contained in:
Hypolite Petovan 2019-05-18 22:16:35 -04:00 committed by GitHub
commit 7a13582c67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 23 deletions

View file

@ -1,23 +0,0 @@
<?php
/**
* @file mod/notice.php
* GNU Social -> friendica items permanent-url compatibility
*/
use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Database\DBA;
function notice_init(App $a)
{
$id = $a->argv[1];
$r = q("SELECT `user`.`nickname` FROM `user` LEFT JOIN `item` ON `item`.`uid` = `user`.`uid` WHERE `item`.`id` = %d", intval($id));
if (DBA::isResult($r)) {
$nick = $r[0]['nickname'];
$a->internalRedirect('display/' . $nick . '/' . $id);
} else {
throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('Item not found.'));
}
return;
}

View file

@ -169,6 +169,7 @@ class Router
$collector->addRoute(['GET'], '/view/{id:\d+}', Module\Notifications\Notify::class); $collector->addRoute(['GET'], '/view/{id:\d+}', Module\Notifications\Notify::class);
$collector->addRoute(['GET'], '/mark/all', Module\Notifications\Notify::class); $collector->addRoute(['GET'], '/mark/all', Module\Notifications\Notify::class);
}); });
$this->routeCollector->addRoute(['GET'], '/notice/{id:\d+}', Module\GnuSocial\Notice::class);
$this->routeCollector->addRoute(['GET'], '/objects/{guid}', Module\Objects::class); $this->routeCollector->addRoute(['GET'], '/objects/{guid}', Module\Objects::class);
$this->routeCollector->addGroup('/oembed', function (RouteCollector $collector) { $this->routeCollector->addGroup('/oembed', function (RouteCollector $collector) {
$collector->addRoute(['GET'], '/b2h', Module\Oembed::class); $collector->addRoute(['GET'], '/b2h', Module\Oembed::class);

View file

@ -0,0 +1,34 @@
<?php
namespace Friendica\Module\GnuSocial;
use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Database\DBA;
use Friendica\Network\HTTPException;
/**
* GNU Social -> friendica items permanent-url compatibility
*/
class Notice extends BaseModule
{
public static function content()
{
$a = self::getApp();
// @TODO: Replace with parameter from router
$id = ($a->argc > 1) ? $a->argv[1] : 0;
if (empty($id)) {
throw new HTTPException\NotFoundException(L10n::t('Item not found.'));
}
$item = DBA::selectFirst('item', ['guid'], ['id' => $id]);
if (empty($item )) {
throw new HTTPException\NotFoundException(L10n::t('Item not found.'));
} else {
$a->internalRedirect('display/' . $item['guid']);
}
}
}