diff --git a/app/Controllers/AdminController.php b/app/Controllers/AdminController.php index 07494cf..0055fd7 100644 --- a/app/Controllers/AdminController.php +++ b/app/Controllers/AdminController.php @@ -5,7 +5,7 @@ use \App\Services\{Router, Auth, DB, Json}; use \App\Controllers\ExceptionRegister; use \App\Core\Page; -class AdminController +class AdminController extends NGController { static $file = 'General'; diff --git a/app/Controllers/ExceptionRegister.php b/app/Controllers/ExceptionRegister.php index fa0fa13..c6cd6db 100644 --- a/app/Controllers/ExceptionRegister.php +++ b/app/Controllers/ExceptionRegister.php @@ -1,20 +1,17 @@ render('Errors/404'); } - - public static function notfound() { - Page::set('Errors/404'); - } - - - -} \ No newline at end of file +} diff --git a/app/Controllers/LoginController.php b/app/Controllers/LoginController.php index 83e8bca..71d3ba9 100644 --- a/app/Controllers/LoginController.php +++ b/app/Controllers/LoginController.php @@ -2,16 +2,17 @@ namespace App\Controllers; use \App\Services\{Router, Auth, DB, Json}; -use \App\Controllers\ExceptionRegister; -use \App\Core\Page; -class LoginController +class LoginController extends NGController { - - public static function i() + public function i() { - Page::set('Login'); + if (Auth::userid() > 0) { + Router::redirect('/'); + } else{ + $this->render('System/Login'); + } } diff --git a/app/Controllers/MainController.php b/app/Controllers/MainController.php index 2fb8899..c45e1cd 100644 --- a/app/Controllers/MainController.php +++ b/app/Controllers/MainController.php @@ -1,110 +1,99 @@ render('t'); + } + + public function i() + { + $this->render('System/Main'); + } + public static function page() + { + Page::set('Page'); + } + public function about() + { + $this->render('System/About'); + } + public static function rules() + { + Page::set('Rules'); + } + public static function publicationRules() + { + Page::set('PublicationRules'); + } + public static function photoRules() + { + Page::set('PhotoRules'); + } + public static function videoRules() + { + Page::set('VideoRules'); + } + public static function update() + { + Page::set('Update'); + } + public function top30() + { + $this->render('Top30'); + } + public static function feed() + { + Page::set('Feed'); + } + public static function fav() + { + Page::set('Fav'); + } + public static function gallery() + { + Page::set('Gallery'); + } + public static function favauthors() + { + Page::set('FavAuthors'); + } + public static function emailverify() + { + Page::set('Errors/EmailVerify'); + } + public static function comments() + { + Page::set('Comments/Index'); + } + public static function tour() + { + Page::set('Tour'); + } + public static function robots() + { echo 'User-Agent: * Disallow: /lk/ Clean-Param: vid&gid&upd /photo/ -Host: https://'.$_SERVER['SERVER_NAME']; -header("Content-Type: text/plain"); - } +Host: https://' . $_SERVER['SERVER_NAME']; + header("Content-Type: text/plain"); + } - public static function logout() - { - DB::query('DELETE FROM login_tokens WHERE token=:userid', array(':userid'=>$_COOKIE['NGALLERYSESS'])); - setcookie('NGALLERYSERVICE', '', 1); - setcookie('NGALLERYSESS', '', 1); - setcookie('NGALLERYSESS_', '', 1); - setcookie('NGALLERYID', '', 1); - header('Location: /'); - } - -} \ No newline at end of file + public static function logout() + { + DB::query('DELETE FROM login_tokens WHERE token=:userid', array(':userid' => $_COOKIE['NGALLERYSESS'])); + setcookie('NGALLERYSERVICE', '', 1); + setcookie('NGALLERYSESS', '', 1); + setcookie('NGALLERYSESS_', '', 1); + setcookie('NGALLERYID', '', 1); + header('Location: /'); + } +} diff --git a/app/Controllers/MessagesController.php b/app/Controllers/MessagesController.php new file mode 100644 index 0000000..cae2165 --- /dev/null +++ b/app/Controllers/MessagesController.php @@ -0,0 +1,15 @@ +render('Messages/Index'); + } +} diff --git a/app/Controllers/PhotoController.php b/app/Controllers/PhotoController.php index 453d2e5..04e9d68 100644 --- a/app/Controllers/PhotoController.php +++ b/app/Controllers/PhotoController.php @@ -1,23 +1,98 @@ page = new Page(); + $this->user = new User(Auth::userid()); + } + + public function i(): void + { + $id = $this->getPhotoId(); + $this->photo = new Photo($id); + + if (!$this->photo->exists()) { + $this->renderNotFound(); + return; + } + + $this->setPhotoDetails($id); + $this->checkModerationStatus($id); + + if ($this->params['moderated']) { + $this->render('Photo/Index', $this->params); + } else { + $this->renderNotFound(); + } + } -} \ No newline at end of file + public function photoext(): void + { + $_GET['id'] ? $this->render('Photo/Ext') : $this->renderNotFound(); + } + + private function getPhotoId(): ?int + { + return isset($_SERVER['REQUEST_URI']) ? (int) explode('/', $_SERVER['REQUEST_URI'])[2] : null; + } + + private function setPhotoDetails(int $id): void + { + $this->params = [ + 'photo_id' => $id, + 'photouser' => new User($this->photo->i('user_id')), + 'extname' => $this->photo->content('video') ? 'видео' : 'фото', + 'extnamef' => $this->photo->content('video') ? 'видеоролик' : 'фотография' + ]; + + if ($this->photo->i('entitydata_id') >= 1) { + $entitydata = DB::query('SELECT * FROM entities_data WHERE id=:id', [':id' => $this->photo->i('entitydata_id')])[0]; + $this->params['vehicle'] = new Vehicle($entitydata['entityid']); + } + } + + private function checkModerationStatus(int $id): void + { + $moderated = $this->photo->i('moderated'); + + if ($moderated === 0) { + $this->params['moderated'] = ($this->photo->i('user_id') === Auth::userid() || $this->user->i('admin') > 0); + } elseif ($moderated === 1) { + $this->params['moderated'] = true; + $this->trackPhotoView($id); + } + } + + private function trackPhotoView(int $id): void + { + $lastView = DB::query( + 'SELECT time FROM photos_views WHERE user_id=:uid AND photo_id=:pid ORDER BY id DESC LIMIT 1', + [':uid' => Auth::userid(), ':pid' => $id] + )[0]['time'] ?? 0; + + if ($lastView <= time() - 86400) { + DB::query( + 'INSERT INTO photos_views VALUES (0, :uid, :pid, :time)', + [':uid' => Auth::userid(), ':pid' => $id, ':time' => time()] + ); + } + } + + private function renderNotFound(): void + { + $this->render('Photo/NotFound', $this->params); + } +} diff --git a/app/Controllers/ProfileController.php b/app/Controllers/ProfileController.php index cc5183e..3e4248e 100644 --- a/app/Controllers/ProfileController.php +++ b/app/Controllers/ProfileController.php @@ -1,39 +1,59 @@ render('Profile/LK/Index'); + } + public function i() + { + $profile_id = explode('/', $_SERVER['REQUEST_URI'])[2]; + $this->params['userprofile'] = new \App\Models\User($profile_id); + if (explode('/', $_SERVER['REQUEST_URI'])[2] && (int)$this->params['userprofile']->i('id') === (int)$profile_id) { + $this->params['profile_id'] = explode('/', $_SERVER['REQUEST_URI'])[2]; + if ($this->params['userprofile']->i('status') > 0) { + $this->params['status'] = $this->params['userprofile']->i('status'); + $this->render('Errors/UserDeactivated', $this->params); + } else { + $this->render('Profile/Index', $this->params); + } + } else { + $this->render('Errors/UserNotFound'); + } + } + public static function photoindexhistory() + { + Page::set('Profile/LK/PhotoIndexHistory'); + } + public function upload() + { + $user = new \App\Models\User(Auth::userid()); + $this->params['user'] = $user; + if (NGALLERY['root']['registration']['emailverify'] != false || $user->i('status') === 3) { + $problems[] = 'Чтобы публиковать медиафайлы, нужно подтвердить электронную почту.'; + $this->params['problems'] = $problems; + $this->render('Errors/PublicProblems', $this->params); + } else { + $this->render('Profile/UploadPhoto'); + } + } + public static function lkhistory() + { + Page::set('Profile/LK/History'); + } + public static function lkprofile() + { + Page::set('Profile/LK/Profile'); + } +} diff --git a/app/Controllers/RegisterController.php b/app/Controllers/RegisterController.php index cf67a8d..c81fabf 100644 --- a/app/Controllers/RegisterController.php +++ b/app/Controllers/RegisterController.php @@ -5,13 +5,17 @@ use \App\Services\{Router, Auth, DB, Json}; use \App\Controllers\ExceptionRegister; use \App\Core\Page; -class RegisterController +class RegisterController extends NGController { - public static function i() + public function i() { - Page::set('Register'); + if (Auth::userid() > 0) { + Router::redirect('/'); + } else{ + $this->render('System/Register'); + } } diff --git a/app/Controllers/SearchController.php b/app/Controllers/SearchController.php index 86c5cda..8a46619 100644 --- a/app/Controllers/SearchController.php +++ b/app/Controllers/SearchController.php @@ -5,7 +5,7 @@ use \App\Services\{Router, Auth, DB, Json}; use \App\Controllers\ExceptionRegister; use \App\Core\Page; -class SearchController +class SearchController extends NGController { public static function i() { diff --git a/app/Controllers/VehicleController.php b/app/Controllers/VehicleController.php index 6813358..942babb 100644 --- a/app/Controllers/VehicleController.php +++ b/app/Controllers/VehicleController.php @@ -6,7 +6,7 @@ use \App\Services\{Router, Auth, DB, Json}; use \App\Controllers\ExceptionRegister; use \App\Core\Page; -class VehicleController +class VehicleController extends NGController { public static function i() {