mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
Move more functions from Releases to appropriate models
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
2017-12-27 DariusIII
|
||||
* Chg: Move more functions from Releases to appropriate models
|
||||
* Chg: Move updateGrab, getById functions from Releases class to Release model (rename getById to getCatByRelId)
|
||||
* Chg: Move createGUID function to helpers.php
|
||||
* Chg: Update laravel/framework and nikic/php-parser to latest versions
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
@@ -45,4 +47,30 @@ class Category extends Model
|
||||
{
|
||||
return $this->belongsTo(RoleExcludedCategory::class, 'categories_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection|static[]
|
||||
*/
|
||||
public static function getRecentlyAdded()
|
||||
{
|
||||
$recent = Cache::get('recentlyadded');
|
||||
if ($recent !== null) {
|
||||
return $recent;
|
||||
}
|
||||
|
||||
$recent = self::query()
|
||||
->where('r.adddate', '>', Carbon::now()->subWeek())
|
||||
->selectRaw('CONCAT(cp.title, " > ", categories.title) as title')
|
||||
->selectRaw('COUNT(r.id) as count')
|
||||
->join('categories as cp', 'cp.id', '=', 'categories.parentid')
|
||||
->join('releases as r', 'r.categories_id', '=', 'categories.id')
|
||||
->groupBy('title')
|
||||
->orderBy('count', 'desc')
|
||||
->get();
|
||||
|
||||
$expiresAt = Carbon::now()->addSeconds(NN_CACHE_EXPIRY_LONG);
|
||||
Cache::put('recentlyadded', $recent, $expiresAt);
|
||||
|
||||
return $recent;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use nntmux\SphinxSearch;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -209,4 +210,73 @@ class Release extends Model
|
||||
{
|
||||
return self::query()->where('id', $id)->first(['categories_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $videoId
|
||||
* @return int
|
||||
*/
|
||||
public static function removeVideoIdFromReleases($videoId): int
|
||||
{
|
||||
return self::query()->where('videos_id', $videoId)->update(['videos_id' => 0, 'tv_episodes_id' => 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $anidbID
|
||||
* @return int
|
||||
*/
|
||||
public static function removeAnidbIdFromReleases($anidbID): int
|
||||
{
|
||||
return self::query()->where('anidbid', $anidbID)->update(['anidbid' => -1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection|static[]
|
||||
*/
|
||||
public static function getTopDownloads()
|
||||
{
|
||||
$releases = Cache::get('topdownloads');
|
||||
if ($releases !== null) {
|
||||
return $releases;
|
||||
}
|
||||
|
||||
$releases = self::query()
|
||||
->where('grabs', '>', 0)
|
||||
->select(['id', 'searchname', 'guid', 'adddate'])
|
||||
->selectRaw('SUM(grabs) as grabs')
|
||||
->groupBy('id', 'searchname', 'adddate')
|
||||
->havingRaw('SUM(grabs) > 0')
|
||||
->orderBy('grabs', 'desc')
|
||||
->limit(10)
|
||||
->get();
|
||||
|
||||
$expiresAt = Carbon::now()->addSeconds(NN_CACHE_EXPIRY_LONG);
|
||||
Cache::put('topdownloads', $releases, $expiresAt);
|
||||
|
||||
return $releases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection|static[]
|
||||
*/
|
||||
public static function getTopComments()
|
||||
{
|
||||
$comments = Cache::get('topcomments');
|
||||
if ($comments !== null) {
|
||||
return $comments;
|
||||
}
|
||||
|
||||
$comments = self::query()
|
||||
->where('comments', '>', 0)
|
||||
->select(['id', 'guid', 'searchname'])
|
||||
->selectRaw('SUM(comments) AS comments')
|
||||
->groupBy('id', 'searchname', 'adddate')
|
||||
->havingRaw('SUM(comments) > 0')
|
||||
->orderBy('comments', 'desc')
|
||||
->limit(10)
|
||||
->get();
|
||||
$expiresAt = Carbon::now()->addSeconds(NN_CACHE_EXPIRY_LONG);
|
||||
Cache::put('topcomments', $comments, $expiresAt);
|
||||
|
||||
return $comments;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,4 +27,19 @@ class ReleaseNfo extends Model
|
||||
{
|
||||
return $this->belongsTo(Release::class, 'releases_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param bool $getNfoString
|
||||
* @return \Illuminate\Database\Eloquent\Model|null|static
|
||||
*/
|
||||
public static function getReleaseNfo($id, $getNfoString = true)
|
||||
{
|
||||
$nfo = self::query()->where('releases_id', $id)->whereNotNull('nfo')->select(['releases_id']);
|
||||
if ($getNfoString === true) {
|
||||
$nfo->selectRaw('UNCOMPRESS(nfo) AS nfo');
|
||||
}
|
||||
|
||||
return $nfo->first();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1313,116 +1313,6 @@ class Releases
|
||||
return $zipFile->file();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $videoId
|
||||
* @return int
|
||||
*/
|
||||
public function removeVideoIdFromReleases($videoId): int
|
||||
{
|
||||
return Release::query()->where('videos_id', $videoId)->update(['videos_id' => 0, 'tv_episodes_id' => 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $anidbID
|
||||
* @return int
|
||||
*/
|
||||
public function removeAnidbIdFromReleases($anidbID): int
|
||||
{
|
||||
return Release::query()->where('anidbid', $anidbID)->update(['anidbid' => -1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param bool $getNfoString
|
||||
* @return \Illuminate\Database\Eloquent\Model|null|static
|
||||
*/
|
||||
public function getReleaseNfo($id, $getNfoString = true)
|
||||
{
|
||||
$nfo = ReleaseNfo::query()->where('releases_id', $id)->whereNotNull('nfo')->select(['releases_id']);
|
||||
if ($getNfoString === true) {
|
||||
$nfo->selectRaw('UNCOMPRESS(nfo) AS nfo');
|
||||
}
|
||||
|
||||
return $nfo->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection|static[]
|
||||
*/
|
||||
public function getTopDownloads()
|
||||
{
|
||||
$releases = Cache::get('topdownloads');
|
||||
if ($releases !== null) {
|
||||
return $releases;
|
||||
}
|
||||
|
||||
$releases = Release::query()
|
||||
->where('grabs', '>', 0)
|
||||
->select(['id', 'searchname', 'guid', 'adddate'])
|
||||
->selectRaw('SUM(grabs) as grabs')
|
||||
->groupBy('id', 'searchname', 'adddate')
|
||||
->havingRaw('SUM(grabs) > 0')
|
||||
->orderBy('grabs', 'desc')
|
||||
->limit(10)
|
||||
->get();
|
||||
|
||||
$expiresAt = Carbon::now()->addSeconds(NN_CACHE_EXPIRY_LONG);
|
||||
Cache::put('topdownloads', $releases, $expiresAt);
|
||||
|
||||
return $releases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection|static[]
|
||||
*/
|
||||
public function getTopComments()
|
||||
{
|
||||
$comments = Cache::get('topcomments');
|
||||
if ($comments !== null) {
|
||||
return $comments;
|
||||
}
|
||||
|
||||
$comments = Release::query()
|
||||
->where('comments', '>', 0)
|
||||
->select(['id', 'guid', 'searchname'])
|
||||
->selectRaw('SUM(comments) AS comments')
|
||||
->groupBy('id', 'searchname', 'adddate')
|
||||
->havingRaw('SUM(comments) > 0')
|
||||
->orderBy('comments', 'desc')
|
||||
->limit(10)
|
||||
->get();
|
||||
$expiresAt = Carbon::now()->addSeconds(NN_CACHE_EXPIRY_LONG);
|
||||
Cache::put('topcomments', $comments, $expiresAt);
|
||||
|
||||
return $comments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection|static[]
|
||||
*/
|
||||
public function getRecentlyAdded()
|
||||
{
|
||||
$recent = Cache::get('recentlyadded');
|
||||
if ($recent !== null) {
|
||||
return $recent;
|
||||
}
|
||||
|
||||
$recent = CategoryModel::query()
|
||||
->where('r.adddate', '>', Carbon::now()->subWeek())
|
||||
->selectRaw('CONCAT(cp.title, " > ", categories.title) as title')
|
||||
->selectRaw('COUNT(r.id) as count')
|
||||
->join('categories as cp', 'cp.id', '=', 'categories.parentid')
|
||||
->join('releases as r', 'r.categories_id', '=', 'categories.id')
|
||||
->groupBy('title')
|
||||
->orderBy('count', 'desc')
|
||||
->get();
|
||||
|
||||
$expiresAt = Carbon::now()->addSeconds(NN_CACHE_EXPIRY_LONG);
|
||||
Cache::put('recentlyadded', $recent, $expiresAt);
|
||||
|
||||
return $recent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all newest movies with coves for poster wall.
|
||||
*
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
|
||||
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php';
|
||||
|
||||
use nntmux\Releases;
|
||||
use App\Models\Release;
|
||||
|
||||
$page = new AdminPage();
|
||||
$releases = new Releases(['Settings' => $page->pdo]);
|
||||
|
||||
$success = false;
|
||||
|
||||
if (isset($_GET['id'])) {
|
||||
$success = $releases->removeAnidbIdFromReleases($_GET['id']);
|
||||
$success = Release::removeAnidbIdFromReleases($_GET['id']);
|
||||
$page->smarty->assign('anidbid', $_GET['id']);
|
||||
}
|
||||
$page->smarty->assign('success', $success);
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
|
||||
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php';
|
||||
|
||||
use nntmux\Releases;
|
||||
use App\Models\Release;
|
||||
|
||||
$page = new AdminPage();
|
||||
$releases = new Releases(['Settings' => $page->pdo]);
|
||||
|
||||
$success = false;
|
||||
|
||||
if (isset($_GET['id'])) {
|
||||
$success = $releases->removeVideoIdFromReleases($_GET['id']);
|
||||
$success = Release::removeVideoIdFromReleases($_GET['id']);
|
||||
$page->smarty->assign('videoid', $_GET['id']);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,25 +2,25 @@
|
||||
|
||||
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php';
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Release;
|
||||
use App\Models\User;
|
||||
use nntmux\Releases;
|
||||
use App\Models\UserRole;
|
||||
|
||||
$page = new AdminPage();
|
||||
$releases = new Releases();
|
||||
|
||||
$page->title = 'Site Stats';
|
||||
|
||||
$topgrabs = User::getTopGrabbers();
|
||||
$page->smarty->assign('topgrabs', $topgrabs);
|
||||
|
||||
$topdownloads = $releases->getTopDownloads();
|
||||
$topdownloads = Release::getTopDownloads();
|
||||
$page->smarty->assign('topdownloads', $topdownloads);
|
||||
|
||||
$topcomments = $releases->getTopComments();
|
||||
$topcomments = Release::getTopComments();
|
||||
$page->smarty->assign('topcomments', $topcomments);
|
||||
|
||||
$recent = $releases->getRecentlyAdded();
|
||||
$recent = Category::getRecentlyAdded();
|
||||
$page->smarty->assign('recent', $recent);
|
||||
|
||||
$usersbymonth = User::getUsersByMonth();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Models\ReleaseNfo;
|
||||
use App\Models\User;
|
||||
use nntmux\http\API;
|
||||
use nntmux\Releases;
|
||||
@@ -270,7 +271,7 @@ switch ($function) {
|
||||
|
||||
UserRequest::addApiRequest($uid, $_SERVER['REQUEST_URI']);
|
||||
$rel = $releases->getByGuid($_GET['id']);
|
||||
$data = $releases->getReleaseNfo($rel['id']);
|
||||
$data = ReleaseNfo::getReleaseNfo($rel['id']);
|
||||
|
||||
if ($rel !== false && ! empty($rel)) {
|
||||
if ($data !== false) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Models\ReleaseNfo;
|
||||
use nntmux\XXX;
|
||||
use nntmux\AniDB;
|
||||
use nntmux\Books;
|
||||
@@ -41,7 +42,7 @@ if (isset($_GET['id'])) {
|
||||
$rc->addComment($data['id'], $data['gid'], $_POST['txtAddComment'], User::currentUserId(), $_SERVER['REMOTE_ADDR']);
|
||||
}
|
||||
|
||||
$nfo = $releases->getReleaseNfo($data['id']);
|
||||
$nfo = ReleaseNfo::getReleaseNfo($data['id']);
|
||||
$reVideo = $re->getVideo($data['id']);
|
||||
$reAudio = $re->getAudio($data['id']);
|
||||
$reSubs = $re->getSubs($data['id']);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Models\ReleaseNfo;
|
||||
use App\Models\User;
|
||||
use nntmux\Releases;
|
||||
use nntmux\utility\Utility;
|
||||
@@ -17,7 +18,7 @@ if (isset($_GET['id'])) {
|
||||
$page->show404();
|
||||
}
|
||||
|
||||
$nfo = $releases->getReleaseNfo($rel['id']);
|
||||
$nfo = ReleaseNfo::getReleaseNfo($rel['id']);
|
||||
$nfo['nfoUTF'] = Utility::cp437toUTF($nfo['nfo']);
|
||||
|
||||
$page->smarty->assign('rel', $rel);
|
||||
|
||||
Reference in New Issue
Block a user