diff --git a/Changelog b/Changelog
index 574836e54..554cb6f13 100755
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,5 @@
+2018-04-09 DariusIII
+ * Chg: Add ForumController and routes
2018-04-08 DariusIII
* Chg: Add FileListController and routes
* Chg: Add FailedReleasesController and routes
diff --git a/app/Http/Controllers/ForumController.php b/app/Http/Controllers/ForumController.php
new file mode 100644
index 000000000..ca1c91b52
--- /dev/null
+++ b/app/Http/Controllers/ForumController.php
@@ -0,0 +1,107 @@
+setPrefs();
+ if ($this->isPostBack() && $request->has('addMessage') && $request->has('addSubject')) {
+ Forumpost::add(0, Auth::id(), $request->input('addSubject'), $request->input('addMessage'));
+ header('/forum');
+ }
+
+ $lock = $unlock = null;
+
+ if ($request->has('lock')) {
+ $lock = $request->input('lock');
+ }
+
+ if ($request->has('unlock')) {
+ $unlock = $request->input('unlock');
+ }
+
+ if ($lock !== null) {
+ Forumpost::lockUnlockTopic($lock, 1);
+ header('/forum');
+ die();
+ }
+
+ if ($unlock !== null) {
+ Forumpost::lockUnlockTopic($unlock, 0);
+ header('/forum');
+ die();
+ }
+
+ $results = Forumpost::getBrowseRange();
+
+ $this->smarty->assign('privateprofiles', (int) Settings::settingValue('..privateprofiles') === 1);
+
+ $this->smarty->assign('results', $results);
+
+ $meta_title = 'Forum';
+ $meta_keywords = 'forum,chat,posts';
+ $meta_description = 'Forum';
+
+ $content = $this->smarty->fetch('forum.tpl');
+
+ $this->smarty->assign(
+ [
+ 'content' => $content,
+ 'meta_title' => $meta_title,
+ 'meta_keywords' => $meta_keywords,
+ 'meta_description' => $meta_description,
+ ]
+ );
+ $this->pagerender();
+ }
+
+ /**
+ * @param \Illuminate\Http\Request $request
+ * @throws \Exception
+ */
+ public function getPosts(Request $request)
+ {
+ $this->setPrefs();
+ $id = $request->input('id') + 0;
+
+ if (! empty($request->input('addMessage')) && $this->isPostBack()) {
+ Forumpost::add($id, Auth::id(), '', $request->input('addMessage'));
+ header('/forumpost/'.$id.'#last');
+ }
+
+ $results = Forumpost::getPosts($id);
+ if (\count($results) === 0) {
+ header('/forum');
+ }
+
+ $meta_title = 'Forum Post';
+ $meta_keywords = 'view,forum,post,thread';
+ $meta_description = 'View forum post';
+
+ $this->smarty->assign('results', $results);
+ $this->smarty->assign('privateprofiles', (int) Settings::settingValue('..privateprofiles') === 1);
+
+ $content = $this->smarty->fetch('forumpost.tpl');
+
+ $this->smarty->assign(
+ [
+ 'content' => $content,
+ 'meta_title' => $meta_title,
+ 'meta_keywords' => $meta_keywords,
+ 'meta_description' => $meta_description,
+ ]
+ );
+ $this->pagerender();
+ }
+}
diff --git a/app/Models/Forumpost.php b/app/Models/Forumpost.php
index 059aa4ed2..b3bd3c565 100644
--- a/app/Models/Forumpost.php
+++ b/app/Models/Forumpost.php
@@ -109,27 +109,15 @@ class Forumpost extends Model
return self::query()->where('id', $id)->first();
}
- /**
- * Get count of posts for parent forum.
- *
- * @return int
- */
- public static function getBrowseCount(): int
- {
- $res = self::query()->count('id');
-
- return $res ?? 0;
- }
-
/**
* Get browse range for forum.
*
*
* @param $start
*
- * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection|static[]
+ * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
- public static function getBrowseRange($start)
+ public static function getBrowseRange()
{
return self::query()
->where('forumpost.parentid', '=', 0)
@@ -137,8 +125,7 @@ class Forumpost extends Model
->leftJoin('user_roles', 'user_roles.id', '=', 'users.user_roles_id')
->select(['forumpost.*', 'users.username', 'user_roles.name as rolename'])
->orderBy('forumpost.updated_at', 'desc')
- ->limit(config('nntmux.items_per_page'))->offset($start)
- ->get();
+ ->paginate(config('nntmux.items_per_page'));
}
/**
diff --git a/public/pages/ajax_mediainfo.php b/public/pages/ajax_mediainfo.php
deleted file mode 100644
index c5cf9a3ba..000000000
--- a/public/pages/ajax_mediainfo.php
+++ /dev/null
@@ -1,44 +0,0 @@
-show403();
-}
-
-if (! request()->has('id')) {
- $page->show404();
-}
-
-$re = new ReleaseExtra($page->settings);
-$redata = $re->getBriefByGuid(request()->input('id'));
-
-if (! $redata) {
- echo 'No media info';
-} else {
- echo "
\n";
- if ($redata['videocodec'] !== '' && $redata['containerformat'] !== '') {
- $redata['videocodec'] = $re->makeCodecPretty($redata['videocodec']);
- echo '| Format: | '.htmlentities($redata['videocodec'], ENT_QUOTES).' - '.htmlentities($redata['containerformat'], ENT_QUOTES)." |
\n";
- }
- if ($redata['videoduration'] !== '') {
- echo '| Duration: | '.htmlentities($redata['videoduration'], ENT_QUOTES)." |
\n";
- }
- if ($redata['size'] !== '') {
- echo '| Resolution: | '.htmlentities($redata['size'], ENT_QUOTES)." |
\n";
- }
- if ($redata['videoaspect'] !== '') {
- echo '| Aspect Ratio: | '.htmlentities($redata['videoaspect'], ENT_QUOTES)." |
\n";
- }
- if ($redata['audio'] !== '' && $redata['audio'] !== ', ') {
- echo '| Audio Languages: | '.htmlentities($redata['audio'], ENT_QUOTES)." |
\n";
- }
- if ($redata['audioformat'] !== '' && $redata['audioformat'] !== ', ') {
- echo '| Audio Format: | '.htmlentities($redata['audioformat'], ENT_QUOTES)." |
\n";
- }
- if ($redata['subs'] !== '') {
- echo '| Subtitles: | '.htmlentities($redata['subs'], ENT_QUOTES)." |
\n";
- }
- echo '
';
-}
diff --git a/public/pages/ajax_preinfo.php b/public/pages/ajax_preinfo.php
deleted file mode 100644
index dd7053bbc..000000000
--- a/public/pages/ajax_preinfo.php
+++ /dev/null
@@ -1,58 +0,0 @@
-show403();
-}
-
-if (! request()->has('id')) {
- $page->show404();
-}
-
-$predata = Predb::getOne(request()->input('id'));
-
-if (! $predata) {
- echo 'No pre info';
-} else {
- echo "\n";
- if (isset($predata['nuked'])) {
- $nuked = '';
- switch ($predata['nuked']) {
- case Predb::PRE_NUKED:
- $nuked = 'NUKED';
- break;
- case Predb::PRE_MODNUKE:
- $nuked = 'MODNUKED';
- break;
- case Predb::PRE_OLDNUKE:
- $nuked = 'OLDNUKE';
- break;
- case Predb::PRE_RENUKED:
- $nuked = 'RENUKE';
- break;
- case Predb::PRE_UNNUKED:
- $nuked = 'UNNUKED';
- break;
- }
- if ($nuked !== '') {
- echo '| '.$nuked.': | '.htmlentities($predata['nukereason'] ?? '', ENT_QUOTES)." |
\n";
- }
- }
- echo '| Title: | '.htmlentities($predata['title'], ENT_QUOTES)." |
\n";
- if (isset($predata['category']) && $predata['category'] !== '') {
- echo '| Cat: | '.htmlentities($predata['category'], ENT_QUOTES)." |
\n";
- }
- echo '| Source: | '.htmlentities($predata['source'], ENT_QUOTES)." |
\n";
- if (isset($predata['size'])) {
- if (isset($predata['size'][0]) && $predata['size'][0] > 0) {
- echo '| Size: | '.htmlentities($predata['size'], ENT_QUOTES)." |
\n";
- }
- }
- if (isset($predata['files'])) {
- echo '| Files: | '.htmlentities((preg_match('/F|B/', $predata['files'], $match) ? $predata['files'] : ($predata['files'].'MB')), ENT_QUOTES)." |
\n";
- }
- echo '| Pred: | '.htmlentities($predata['predate'], ENT_QUOTES)." |
\n";
- echo '
';
-}
diff --git a/public/pages/ajax_profile.php b/public/pages/ajax_profile.php
deleted file mode 100644
index c55cdf163..000000000
--- a/public/pages/ajax_profile.php
+++ /dev/null
@@ -1,20 +0,0 @@
-show403();
-}
-
-if (request()->has('action') && request()->has('emailto') && (int) request()->input('action') === 1) {
- $emailto = request()->input('emalto');
- $ret = User::sendInvite($page->serverurl, Auth::id(), $emailto);
- if (! $ret) {
- echo 'Invite not sent.';
- } else {
- echo 'Invite sent. Alternatively paste them following link to register - '.$ret;
- }
-} else {
- echo 'Invite not sent.';
-}
diff --git a/public/pages/ajax_rarfilelist.php b/public/pages/ajax_rarfilelist.php
deleted file mode 100644
index c1574b40e..000000000
--- a/public/pages/ajax_rarfilelist.php
+++ /dev/null
@@ -1,24 +0,0 @@
-show403();
-}
-
-if (! request()->has('id')) {
- $page->show404();
-}
-
-$files = ReleaseFile::getByGuid(request()->input('id'));
-
-if (count($files) === 0) {
- echo 'No files';
-} else {
- echo "\n";
- foreach ($files as $f) {
- echo '- '.htmlentities($f['name'], ENT_QUOTES).' '.($f['passworded'] === 1 ? '
' : '')." \n";
- }
- echo '
';
-}
diff --git a/public/pages/ajax_release-admin.php b/public/pages/ajax_release-admin.php
deleted file mode 100644
index 6601604ca..000000000
--- a/public/pages/ajax_release-admin.php
+++ /dev/null
@@ -1,59 +0,0 @@
-show403();
-}
-$page = new BasePage();
-$releases = new Releases(['Settings' => $page->settings]);
-
-// Set the current action.
-$action = request()->input('action') ?? '';
-
-// Request is for id, but guid is actually being provided
-if (request()->has('id') && is_array(request()->input('id'))) {
- $id = request()->input('id');
- //Get info for first guid to populate form
- $rel = Release::getByGuid(request()->input('id')[0]);
-} else {
- $id = $rel = '';
-}
-
-$page->smarty->assign('action', $action);
-$page->smarty->assign('idArr', $id);
-
-switch ($action) {
- case 'doedit':
- case 'edit':
- $success = false;
- if ($action === 'doedit') {
- $success = $releases->updateMulti(
- request()->input('id'),
- request()->input('category'),
- request()->input('grabs'),
- request()->input('videosid'),
- request()->input('episodesid'),
- request()->input('anidbid'),
- request()->input('imdbid')
- );
- }
- $page->smarty->assign('release', $rel);
- $page->smarty->assign('success', $success);
- $page->smarty->assign('from', request()->input('from') ?? '');
- $page->smarty->assign('catlist', Category::getForSelect(false));
- $page->content = $page->smarty->fetch('ajax_release-edit.tpl');
- echo $page->content;
-
- break;
- case 'dodelete':
- $releases->deleteMultiple(request()->input('id'));
- break;
- default:
- $page->show404();
- break;
-}
diff --git a/public/pages/ajax_resetusergrabs-admin.php b/public/pages/ajax_resetusergrabs-admin.php
deleted file mode 100644
index e3d684d4e..000000000
--- a/public/pages/ajax_resetusergrabs-admin.php
+++ /dev/null
@@ -1,27 +0,0 @@
-show403();
-}
-
-$page = new BasePage();
-
-$action = request()->input('action') ?? '';
-$id = request()->input('id') ?? '';
-
-switch ($action) {
- case 'grabs':
- UserDownload::delDownloadRequests($id);
- break;
- case 'api':
- UserRequest::delApiRequests($id);
- break;
- default:
- $page->show404();
- break;
-}
diff --git a/public/pages/ajax_tvinfo.php b/public/pages/ajax_tvinfo.php
deleted file mode 100644
index baf915820..000000000
--- a/public/pages/ajax_tvinfo.php
+++ /dev/null
@@ -1,31 +0,0 @@
-show403();
-}
-
-if (! request()->has('id')) {
- $page->show404();
-}
-
-$rel = Release::getByGuid(request()->input('id'));
-
-if (! $rel) {
- echo 'No tv info';
-} else {
- echo "';
-
- if (isset($rel['videos_id']) && $rel['videos_id'] > 0) {
- $show = Video::getByVideoID($rel['videos_id']);
- if (count($show) > 0 && (int) $show['image'] !== 0) {
- echo '
';
- }
- }
-}
diff --git a/public/pages/filelist.php b/public/pages/filelist.php
deleted file mode 100644
index b10eeefa0..000000000
--- a/public/pages/filelist.php
+++ /dev/null
@@ -1,50 +0,0 @@
-has('id')) {
- $rel = Release::getByGuid(request()->input('id'));
- if (! $rel) {
- $page->show404();
- }
-
- $nzbpath = $nzb->NZBPath(request()->input('id'));
-
- if (! file_exists($nzbpath)) {
- $page->show404();
- }
-
- ob_start();
- @readgzfile($nzbpath);
- $nzbfile = ob_get_contents();
- ob_end_clean();
-
- $ret = $nzb->nzbFileList($nzbfile);
-
- $page->smarty->assign('rel', $rel);
- $page->smarty->assign('files', $ret);
-
- $page->title = 'File List';
- $page->meta_title = 'View Nzb file list';
- $page->meta_keywords = 'view,nzb,file,list,description,details';
- $page->meta_description = 'View Nzb File List';
-
- $modal = false;
- if (request()->has('modal')) {
- $modal = true;
- $page->smarty->assign('modal', true);
- }
-
- $page->content = $page->smarty->fetch('viewfilelist.tpl');
-
- if ($modal) {
- echo $page->content;
- } else {
- $page->pagerender();
- }
-}
diff --git a/routes/web.php b/routes/web.php
index 9930acb55..5fc122b52 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -103,21 +103,13 @@ Route::get('/xxx', function () {
Route::get('contact-us', 'ContactUsController@showContactForm');
Route::post('contact-us', 'ContactUsController@contact');
-Route::get('/forum', function () {
- redirect('/forum');
-})->middleware('auth');
+Route::get('forum', 'ForumController@forum');
-Route::post('/forum', function () {
- redirect('/forum');
-})->middleware('auth');
+Route::post('forum', 'ForumController@forum');
-Route::get('/forumpost/{id}', function () {
- redirect('/forumpost');
-})->middleware('auth');
+Route::get('forumpost/{id}', 'ForumController@getPosts');
-Route::post('/forumpost/{id}', function () {
- redirect('/forumpost');
-})->middleware('auth');
+Route::post('forumpost/{id}', 'ForumController@getPosts');
Route::get('/profileedit', function () {
redirect('/profileedit');