83 lines
2.7 KiB
PHP
83 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace RomhackPlaza\Master\Pub\Controller;
|
|
|
|
use RomhackPlaza\Master\Helper\Laravel;
|
|
use XF\Mvc\ParameterBag;
|
|
use XF\Mvc\Reply\AbstractReply;
|
|
use XF\Pub\Controller\AbstractController;
|
|
|
|
class Entry extends AbstractController {
|
|
|
|
public function actionIndex(ParameterBag $params): AbstractReply
|
|
{
|
|
$entryId = $params->id;
|
|
$laravelDb = \RomhackPlaza\Master\Helper\Laravel::db();
|
|
if( !$laravelDb )
|
|
return $this->notFound();
|
|
|
|
$entry = $laravelDb->fetchRow("SELECT id, slug, type FROM entries WHERE id = ?", $entryId);
|
|
if( !$entry )
|
|
return $this->notFound();
|
|
|
|
return $this->redirect(\XF::options()->homePageUrl . '/' . $entry['type'] . '/' . $entry['slug']);
|
|
}
|
|
|
|
public function actionReport(ParameterBag $params): AbstractReply
|
|
{
|
|
|
|
$this->assertRegistrationRequired();
|
|
|
|
$entryId = $params->id;
|
|
$laravelDb = \RomhackPlaza\Master\Helper\Laravel::db();
|
|
if( !$laravelDb )
|
|
return $this->notFound();
|
|
|
|
$entry = $laravelDb->fetchRow("SELECT id, complete_title as title, slug, type, user_id, description FROM entries WHERE id = ?", $entryId);
|
|
if( !$entry )
|
|
return $this->notFound();
|
|
|
|
$entity = $this->em()->instantiateEntity('RomhackPlaza\Master:Entry', $entry);
|
|
$entity->setReadOnly(true);
|
|
|
|
$reportPlugin = $this->plugin('XF:Report');
|
|
return $reportPlugin->actionReport(
|
|
'romhackplaza_entry', $entity,
|
|
$this->buildLink('romhackplaza_entry/report', $entity),
|
|
\XF::options()->homePageUrl . '/entry/report_redirect?id=' . $entity->id
|
|
);
|
|
|
|
}
|
|
|
|
public static function getActivityDetails(array $activities)
|
|
{
|
|
return self::getActivityDetailsForContent(
|
|
$activities,
|
|
\XF::phrase('viewing_romhackplaza_entry'),
|
|
'entry_id',
|
|
function (array $ids)
|
|
{
|
|
$db = Laravel::db();
|
|
if( !$db || empty($ids) )
|
|
return [];
|
|
|
|
$entries = $db->fetchAll("
|
|
SELECT id, complete_title as title, slug, type
|
|
FROM entries
|
|
WHERE id IN (" . $db->quote($ids) . ")
|
|
");
|
|
|
|
$data = [];
|
|
foreach( $entries as $entry ){
|
|
$data[$entry['id']] = [
|
|
'title' => $entry['title'],
|
|
'url' => \XF::options()->homePageUrl . '/' . $entry['type'] . '/' . $entry['slug'],
|
|
];
|
|
}
|
|
|
|
return $data;
|
|
},
|
|
\XF::phrase('viewing_romhackplaza_database')
|
|
);
|
|
}
|
|
} |