Merge pull request #2 from MobinaNj/master

Master
This commit is contained in:
MobinaNj 2022-09-09 15:38:29 +04:30 committed by GitHub
commit c5af2e3267
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 1039 additions and 84 deletions

View file

@ -0,0 +1,78 @@
<?php
namespace Admin;
use Auth\Auth;
class Admin{
function __construct(){
$auth = new Auth();
$auth->checkAdmin();
$this->currentDomain = CURRENT_DOMAIN;
$this->basePath = BASE_PATH;
}
public function redirect($url){
header("Location: ". trim($this->currentDomain, '/ ') . '/' . trim($url, '/ '));
exit;
}
public function redirectBack()
{
header("Location: ". $_SERVER['HTTP_REFERER']);
exit;
}
protected function saveImage($image, $imagePath, $imageName = null)
{
if($imageName)
{
$extension = explode('/', $image['type'])[1];
$imageName = $imageName . '.' . $extension;
}
else{
$extension = explode('/', $image['type'])[1];
$imageName = date("Y-m-d-H-i-s"). '.' . $extension;
}
$imageTemp = $image['tmp_name'];
$imagePath = 'public/' . $imagePath . '/';
if(is_uploaded_file($imageTemp))
{
if(move_uploaded_file($imageTemp, $imagePath . $imageName))
{
return $imagePath . $imageName;
}
else{
return false;
}
}
else{
return false;
}
}
protected function removeImage($path)
{
// $path = trim($this->basePath, '/ ') . '/' . trim($path, '/ ');
$path = trim($path, '/ ');
if(file_exists($path)){
unlink($path);
}
}
}

View file

@ -0,0 +1,74 @@
<?php
namespace Admin;
use database\Database;
class Banner extends Admin{
public function index()
{
$db = new DataBase();
$banners = $db->select('SELECT * FROM banners ORDER BY `id` DESC');
require_once(BASE_PATH . '/template/admin/banners/index.php');
}
public function create()
{
require_once(BASE_PATH . '/template/admin/banners/create.php');
}
public function store($request)
{
$db = new DataBase();
$request['image'] = $this->saveImage($request['image'], 'banner-image');
if($request['image'])
{
$db->insert('banners', array_keys($request), $request);
$this->redirect('admin/banner');
}
else{
$this->redirect('admin/banner');
}
}
public function edit($id)
{
$db = new DataBase();
$banner = $db->select('SELECT * FROM banners WHERE id = ?;', [$id])->fetch();
require_once(BASE_PATH . '/template/admin/banners/edit.php');
}
public function update($request, $id)
{
$db = new DataBase();
{
if($request['image']['tmp_name'] != null)
{
$banner = $db->select('SELECT * FROM banners WHERE id = ?;', [$id])->fetch();
$this->removeImage($banner['image']);
$request['image'] = $this->saveImage($request['image'], 'banner-image');
}
else{
unset($request['image']);
}
$db->update('banners', $id , array_keys($request), $request);
$this->redirect('admin/banner');
}
}
public function delete($id)
{
$db = new DataBase();
$banner = $db->select('SELECT * FROM banners WHERE id = ?;', [$id])->fetch();
$this->removeImage($banner['image']);
$db->delete('banners', $id);
$this->redirectBack();
}
}

View file

@ -0,0 +1,51 @@
<?php
namespace Admin;
use Database\Database;
class Category extends Admin{
public function index()
{
$db = new Database();
$categories = $db->select("SELECT * FROM categories");
require_once (BASE_PATH . '/template/admin/category/index.php');
}
public function create()
{
require_once (BASE_PATH . '/template/admin/category/create.php');
}
public function store($request){
$db = new Database();
$db->insert('categories', array_keys($request), $request);
$this->redirect('admin/category');
}
public function edit($id)
{
$db = new Database();
$category = $db->select("SELECT * FROM categories WHERE id = ?", [$id])->fetch();
require_once (BASE_PATH . '/template/admin/category/edit.php');
}
public function update($request, $id)
{
$db = new Database();
$db->update('categories', $id, array_keys($request), $request);
$this->redirect('admin/category');
}
public function delete($id)
{
$db = new Database();
$db->delete('categories', $id);
$this->redirectBack();
}
}

View file

@ -0,0 +1,39 @@
<?php
namespace Admin;
use database\Database;
class Comment extends Admin{
public function index()
{
$db = new DataBase();
$comments = $db->select('SELECT comments.*, posts.title AS post_title, users.email AS email FROM comments LEFT JOIN posts ON comments.post_id = posts.id LEFT JOIN users ON comments.user_id = users.id ORDER BY `id` DESC');
$unseenComments = $db->select('SELECT * FROM comments WHERE status = ?', ['unseen']);
foreach($unseenComments as $comment){
$db->update('comments', $comment['id'], ['status'], ['seen']);
}
require_once(BASE_PATH . '/template/admin/comments/index.php');
}
public function changeStatus($id)
{
$db = new DataBase();
$comment = $db->select('SELECT * FROM comments WHERE id = ?;', [$id])->fetch();
if(empty($comment)){
$this->redirectBack();
}
if($comment['status'] == 'seen'){
$db->update('comments', $id, ['status'], ['approved']);
}
else{
$db->update('comments', $id, ['status'], ['seen']);
}
$this->redirectBack();
}
}

View file

@ -0,0 +1,33 @@
<?php
namespace Admin;
use DataBase\DataBase;
class Dashboard extends Admin
{
public function index()
{
$db = new DataBase();
$postCount = $db->select('SELECT COUNT(*) FROM `posts` ;')->fetch();
$postsViews = $db->select('SELECT SUM(view) FROM `posts` ;')->fetch();
$commentsCount = $db->select('SELECT COUNT(*) FROM `comments` ;')->fetch();
$commentsUnseenCount = $db->select("SELECT COUNT(*) FROM `comments` WHERE `status` = 'unseen' ;")->fetch();
$commentsApprovedCount = $db->select("SELECT COUNT(*) FROM `comments` WHERE `status` = 'approved' ;")->fetch();
$userCount = $db->select("SELECT COUNT(*) FROM `users` WHERE `permission` = 'user';")->fetch();
$adminCount = $db->select("SELECT COUNT(*) FROM `users` WHERE `permission` = 'admin' ;")->fetch();
$categoryCount = $db->select("SELECT COUNT(*) FROM `categories` ;")->fetch();
$postsWithView = $db->select('SELECT * FROM `posts` ORDER BY `view` DESC LIMIT 0,5 ;');
$postsComments = $db->select("SELECT `posts`.`id`, `posts`.`title`, COUNT(`comments`.`post_id`) AS 'comment_count' FROM `posts` LEFT JOIN `comments` ON `posts`.`id` = `comments`.`post_id` GROUP BY `posts`.`id` ORDER BY `comment_count` DESC LIMIT 0,5 ;");
$lastComments = $db->select('SELECT comments.id, comments.comment, comments.status, comments.post_id, users.username FROM comments, users WHERE comments.user_id = users.id order by comments.created_at DESC LIMIT 0,5 ;');
require_once (BASE_PATH . "/template/admin/dashboard/index.php");
}
}

52
activities/Admin/Menu.php Normal file
View file

@ -0,0 +1,52 @@
<?php
namespace Admin;
use database\Database;
class Menu extends Admin{
public function index()
{
$db = new DataBase();
$menus = $db->select('SELECT m1.*, m2.name AS parent_name FROM menus m1 LEFT JOIN menus m2 ON m1.parent_id = m2.id ORDER BY id DESC');
require_once(BASE_PATH . '/template/admin/menus/index.php');
}
public function create()
{
$db = new DataBase();
$menus = $db->select('SELECT * FROM menus WHERE parent_id IS NULL ORDER BY `id` DESC ');
require_once(BASE_PATH . '/template/admin/menus/create.php');
}
public function store($request)
{
$db = new DataBase();
$db->insert('menus', array_keys(array_filter($request)), array_filter($request));
$this->redirect('admin/menu');
}
public function edit($id)
{
$db = new DataBase();
$menu = $db->select('SELECT * FROM menus WHERE id = ?;', [$id])->fetch();
$menus = $db->select('SELECT * FROM menus WHERE parent_id IS NULL;');
require_once(BASE_PATH . '/template/admin/menus/edit.php');
}
public function update($request, $id)
{
$db = new DataBase();
$db->update('menus', $id, array_keys($request), $request);
$this->redirect('admin/menu');
}
public function delete($id)
{
$db = new DataBase();
$db->delete('menus', $id);
$this->redirect('admin/menu');
}
}

120
activities/Admin/Post.php Normal file
View file

@ -0,0 +1,120 @@
<?php
namespace Admin;
use Database\Database;
class Post extends Admin{
public function index()
{
$db = new Database();
$posts = $db->select("SELECT * FROM posts");
require_once (BASE_PATH . '/template/admin/post/index.php');
}
public function create()
{
$db = new Database();
$categories = $db->select('SELECT * FROM categories');
require_once (BASE_PATH . '/template/admin/post/create.php');
}
public function store($request){
$realTimestamp = substr($request['published_at'], 0, 10);
$request['published_at'] = date("Y-m-d H:i:s", (int)$realTimestamp);
$db = new Database();
if($request['cat_id'] != null){
$request['image'] = $this->saveImage($request['image'], 'post-image');
if($request['image']){
$request = array_merge($request, ['user_id' => 1]);
$db->insert('posts', array_keys($request), $request);
$this->redirect('admin/post');
}
else{
$this->redirect('admin/post');
}
}
else{
$this->redirect('admin/post');
}
}
public function edit($id)
{
$db = new Database();
$post = $db->select("SELECT * FROM posts WHERE id = ?", [$id])->fetch();
$categories = $db->select('SELECT * FROM categories');
require_once (BASE_PATH . '/template/admin/post/edit.php');
}
public function update($request, $id)
{
$realTimestamp = substr($request['published_at'], 0, 10);
$request['published_at'] = date("Y-m-d H:i:s", (int)$realTimestamp);
$db = new Database();
if ($request['cat_id'] != null) {
if($request['image']['tmp_name'] != null){
$post = $db->select("SELECT * FROM posts WHERE id = ?", [$id])->fetch();
$this->removeImage($post['image']);
$request['image'] = $this->saveImage($request['image'], 'post-image');
}
else{
unset($request['image']);
}
$request = array_merge($request, ['user_id' => 1]);
$db->update('posts', $id, array_keys($request), $request);
$this->redirect('admin/post');
}
}
public function delete($id)
{
$db = new Database();
$post = $db->select("SELECT * FROM posts WHERE id = ?", [$id])->fetch();
$this->removeImage($post['image']);
$db->delete('posts', $id);
$this->redirectBack();
}
public function breakingNews($id)
{
$db = new Database();
$post = $db->select("SELECT * FROM posts WHERE id = ?", [$id])->fetch();
if(empty($post))
{
$this->redirectBack();
}
if($post['breaking_news'] == 1) {
$db->update('posts', $id, ['breaking_news'], [2]);
}
else{
$db->update('posts', $id, ['breaking_news'], [1]);
}
$this->redirectBack();
}
public function selected($id)
{
$db = new Database();
$post = $db->select("SELECT * FROM posts WHERE id = ?", [$id])->fetch();
if(empty($post))
{
$this->redirectBack();
}
if($post['selected'] == 1) {
$db->update('posts', $id, ['selected'], [2]);
}
else{
$db->update('posts', $id, ['selected'], [1]);
}
$this->redirectBack();
}
}

56
activities/Admin/User.php Normal file
View file

@ -0,0 +1,56 @@
<?php
namespace Admin;
use database\Database;
class User extends Admin{
public function index()
{
$db = new DataBase();
$users = $db->select('SELECT * FROM users ORDER BY `id` DESC');
require_once(BASE_PATH . '/template/admin/users/index.php');
}
public function edit($id)
{
$db = new DataBase();
$user = $db->select('SELECT * FROM users WHERE id = ?;', [$id])->fetch();
require_once(BASE_PATH . '/template/admin/users/edit.php');
}
public function update($request, $id)
{
$db = new DataBase();
$request = ['username' => $request['username'], 'permission' => $request['permission']];
$db->update('users', $id, array_keys($request), $request);
$this->redirect('admin/user');
}
public function delete($id)
{
$db = new DataBase();
$db->delete('users', $id);
$this->redirect('admin/user');
}
public function permission($id)
{
$db = new DataBase();
$user = $db->select('SELECT * FROM users WHERE id = ?;', [$id])->fetch();
if(empty($user)){
$this->redirectBack();
}
if($user['permission'] == 'user'){
$db->update('users', $id, ['permission'], ['admin']);
}
else{
$db->update('users', $id, ['permission'], ['user']);
}
$this->redirectBack();
}
}

View file

@ -0,0 +1,51 @@
<?php
namespace Admin;
use DataBase\DataBase;
class WebSetting extends Admin
{
public function index()
{
$db= new DataBase();
$setting= $db->select("SELECT * FROM `websetting`;")->fetch();
require_once (BASE_PATH . "/template/admin/web-setting/index.php");
}
public function set()
{
$db= new DataBase();
$setting= $db->select("SELECT * FROM `websetting`;")->fetch();
require_once (BASE_PATH . "/template/admin/web-setting/set.php");
}
public function store($request)
{
$db= new DataBase();
$setting= $db->select("SELECT * FROM `websetting`;")->fetch();
if($request['logo']['tmp_name'] != ""){
$request['logo']= $this->saveImage($request['logo'],'setting','logo');
}
else{
unset($request['logo']);
}
if($request['icon']['tmp_name'] != ""){
$request['icon']= $this->saveImage($request['icon'],'setting','icon');
}
else{
unset($request['icon']);
}
if(!empty($setting))
$db->update('websetting', $setting['id'],array_keys($request),$request);
else
$db->insert('websetting',array_keys($request),$request);
$this->redirect('admin/web-setting');
}
}

304
activities/Auth/Auth.php Normal file
View file

@ -0,0 +1,304 @@
<?php
namespace Auth;
use Database\Database;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
class Auth{
protected function redirect($url)
{
header('Location: ' . trim(CURRENT_DOMAIN, '/ ') . '/' . trim($url, '/ '));
exit;
}
protected function redirectBack()
{
header("Location: " . $_SERVER['HTTP_REFERER']);
exit;
}
private function hash($password)
{
$hashPassword = password_hash($password, PASSWORD_DEFAULT);
return $hashPassword;
}
private function random(){
return bin2hex(openssl_random_pseudo_bytes(32));
}
// public function activationMessage($username, $verifyToken)
// {
// $message = '
// <h1>فعال سازی حساب کاربری</h1>
// <p>' . $username . 'عزیز برای فعال سازی حساب کاربری خود لطفا روی لینک زیر کلیک نمایید</p>
// <div><a href="'. url('activation/' . $verifyToken) .'">فعال سازی حساب کاربری</a></div>
// ';
// return $message;
// }
public function sendMail($emailAddress, $subject, $body)
{
//Create an instance; passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->CharSet = "UTF-8";
$mail->isSMTP(); //Send using SMTP
$mail->Host = MAIL_HOST; //Set the SMTP server to send through
$mail->SMTPAuth = SMTP_AUTH; //Enable SMTP authentication
$mail->Username = MAIL_USERNAME; //SMTP username
$mail->Password = MAIL_PASSWORD; //SMTP password
$mail->SMTPSecure = 'tls';
$mail->Port = MAIL_PORT; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
//Recipients
$mail->setFrom(SENDER_MAIL, SENDER_NAME);
$mail->addAddress($emailAddress); //Add a recipient
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $body;
$mail->send();
echo 'Message has been sent';
return true;
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
return false;
}
}
public function register(){
require_once(BASE_PATH .'/template/auth/register.php');
}
public function registerStore($request)
{
if(empty($request['email']) || empty($request['username']) || empty($request['password']))
{
flash('register_error', 'تمامی فیلد ها الزامی میباشند');
$this->redirectBack();
}
else if(strlen($request['password']) < 8 )
{
flash('register_error', 'رمز عبور باید حداقل ۸ کاراکتر باشد');
$this->redirectBack();
}
else if(!filter_var($request['email'], FILTER_VALIDATE_EMAIL))
{
flash('register_error', 'ایمیل وارد شده معتبر نمیباشد');
$this->redirectBack();
}
else{
$db = new Database();
$user = $db->select("SELECT * FROM users WHERE email = ?", [$request['email']])->fetch();
if($user != null){
flash('register_error', 'ایمیل از قبل وجود دارد');
$this->redirectBack();
}
else{
$randomToken = $this->random();
// $activationMessage = $this->activationMessage($request['username'], $randomToken);
// $result = $this->sendMail($request['email'], 'فعال سازی حساب کاربری', $activationMessage);
// if($result)
// {
$request['verify_token'] = $randomToken;
$request['password'] = $this->hash($request['password']);
$db->insert('users', array_keys($request), $request);
$this->redirect('login');
// }
}
// flash('register_error', 'ایمیل فعال سازی ارسال نشد');
$this->redirectBack();
}
}
public function activation($verifyToken)
{
$db = new Database();
$user = $db->select("SELECT * FROM users WHERE verify_token = ? AND is_active = 0", [$verifyToken])->fetch();
if($user == null){
$this->redirect('login');
}
else{
$result = $db->update('users', $user['id'], ['is_active'], [1]);
$this->redirect('login');
}
}
public function login(){
require_once(BASE_PATH .'/template/auth/login.php');
}
public function checkLogin($request)
{
if(empty($request['email']) || empty($request['password']))
{
flash('login_error', 'تمامی فیلد ها الزامی میباشند');
$this->redirectBack();
}
else{
$db = new Database();
$user = $db->select("SELECT * FROM users WHERE email = ?", [$request['email']])->fetch();
if($user != null){
if(password_verify($request['password'], $user['password']) && $user['is_active'] == 1)
{
$_SESSION['user'] = $user['id'];
$this->redirect('admin');
}
else{
flash('login_error', 'کلمه عبور اشتباه است');
$this->redirectBack();
}
}
else{
flash('login_error', 'کاربر یافت نشد');
$this->redirectBack();
}
}
}
public function checkAdmin(){
if(isset($_SESSION['user']))
{
$db = new Database();
$user = $db->select("SELECT * FROM users WHERE id = ?", [$_SESSION['user']])->fetch();
if($user != null){
if($user['permission'] != 'admin'){
$this->redirect('home');
}
}
else{
$this->redirect('home');
}
}
else{
$this->redirect('home');
}
}
public function logout()
{
if(isset($_SESSION['user']))
{
unset($_SESSION['user']);
session_destroy();
}
$this->redirect('login');
}
public function forgot(){
require_once(BASE_PATH .'/template/auth/forgot-password.php');
}
public function forgotMessage($username, $forgotToken)
{
$message = '
<h1>بازیابی رمز عبور</h1>
<p>' . $username . 'عزیز برای بازیابی رمز عبور خود لطفا روی لینک زیر کلیک نمایید</p>
<div><a href="'. url('reset-password-form/' . $forgotToken) .'">فعال سازی حساب کاربری</a></div>
';
return $message;
}
public function forgotRequest($request)
{
if(empty($request['email']))
{
flash('forgot_error', ' فیلد ایمیل الزامی میباشد');
$this->redirectBack();
}
else if(!filter_var($request['email'], FILTER_VALIDATE_EMAIL))
{
flash('forgot_error', ' ایمیل وارد شده صحیح نمیباشد');
$this->redirectBack();
}
else{
$db = new Database();
$user = $db->select("SELECT * FROM users WHERE email = ?", [$request['email']])->fetch();
if($user == null)
{
flash('forgot_error', ' ایمیل وارد شده وجود ندارد');
$this->redirectBack();
}
else{
$randomToken = $this->random();
$forgotMessage = $this->forgotMessage($user['username'], $randomToken);
$result = $this->sendMail($request['email'], 'بازیابی رمز عبور', $forgotMessage);
if($result)
{
$db->update('users', $user['id'], ['forgot_token', 'forgot_token_expire'], [$randomToken, date("Y-m-d H:i:s", strtotime('+15 minutes'))]);
$this->redirect('login');
}
else{
flash('forgot_error', ' ایمیل ارسال نشد');
$this->redirectBack();
}
}
}
}
public function resetPasswordView($forgot_token){
require_once(BASE_PATH .'/template/auth/reset-password.php');
}
public function resetPassword($request, $forgot_token)
{
if(!isset($request['password']) || strlen($request['password']) < 8)
{
flash('reset_error', 'یا رمز عبور نباید کمتر از ۸ کاراکتر باشد رمز عبور نباید خالی باشد');
$this->redirectBack();
}
else{
$db = new Database();
$user = $db->select("SELECT * FROM users WHERE forgot_token = ?", [$forgot_token])->fetch();
if($user == null){
flash('reset_error', 'کاربری با این مشخصات یافت نشد');
$this->redirectBack();
}
else{
if($user['forgot_token_expire'] < date('Y-m-d H:i:s'))
{
flash('reset_error', 'مهلت استفاده از این توکن به پایان رسیده است');
$this->redirectBack();
}
if($user)
{
$db->update('users', $user['id'], ['password'], [$this->hash($request['password'])]);
$this->redirect('login');
}
else{
$this->redirectBack();
}
}
}
}
}

118
activities/Home.php Normal file
View file

@ -0,0 +1,118 @@
<?php
namespace App;
use Database\Database;
class Home{
public function index()
{
$db = new Database();
$setting = $db->select('SELECT * FROM websetting')->fetch();
$menus = $db->select('SELECT * FROM menus WHERE parent_id IS NULL')->fetchAll();
$topSelectedPosts = $db->select('SELECT posts.*, (SELECT COUNT(*) FROM comments WHERE comments.post_id = posts.id) AS comments_count, (SELECT username FROM users WHERE users.id = posts.user_id) AS username, (SELECT name FROM categories WHERE categories.id = posts.cat_id) AS category FROM posts WHERE posts.selected = 2 ORDER BY created_at DESC LIMIT 0, 3')->fetchAll();
$breakingNews = $db->select('SELECT * FROM posts WHERE breaking_news = 2 ORDER BY created_at DESC LIMIT 0,1')->fetch();
$lastPosts = $db->select('SELECT posts.*, (SELECT COUNT(*) FROM comments WHERE comments.post_id = posts.id) AS comments_count, (SELECT username FROM users WHERE users.id = posts.user_id) AS username, (SELECT name FROM categories WHERE categories.id = posts.cat_id) AS category FROM posts ORDER BY created_at DESC LIMIT 0, 6')->fetchAll();
$bodyBanner = $db->select('SELECT * FROM banners ORDER BY created_at DESC LIMIT 0,1')->fetch();
$sidebarBanner = $db->select('SELECT * FROM banners ORDER BY created_at DESC LIMIT 0,1')->fetch();
$popularPosts =$db->select('SELECT posts.*, (SELECT COUNT(*) FROM comments WHERE comments.post_id = posts.id) AS comments_count, (SELECT username FROM users WHERE users.id = posts.user_id) AS username, (SELECT name FROM categories WHERE categories.id = posts.cat_id) AS category FROM posts ORDER BY view DESC LIMIT 0, 3')->fetchAll();
$mostCommentsPosts =$db->select('SELECT posts.*, (SELECT COUNT(*) FROM comments WHERE comments.post_id = posts.id) AS comments_count, (SELECT username FROM users WHERE users.id = posts.user_id) AS username, (SELECT name FROM categories WHERE categories.id = posts.cat_id) AS category FROM posts ORDER BY comments_count DESC LIMIT 0, 4')->fetchAll();
require_once (BASE_PATH . '/template/app/index.php');
}
public function show($id)
{
$db = new Database();
$post =$db->select('SELECT posts.*, (SELECT COUNT(*) FROM comments WHERE comments.post_id = posts.id) AS comments_count, (SELECT username FROM users WHERE users.id = posts.user_id) AS username, (SELECT name FROM categories WHERE categories.id = posts.cat_id) AS category FROM posts WHERE id = ?', [$id])->fetch();
$comments = $db->select("SELECT *, (SELECT username FROM users WHERE users.id = comments.user_id) AS username FROM comments WHERE post_id = ? AND status = 'approved'", [$id])->fetchAll();
$setting = $db->select('SELECT * FROM websetting')->fetch();
$menus = $db->select('SELECT * FROM menus WHERE parent_id IS NULL')->fetchAll();
$sidebarBanner = $db->select('SELECT * FROM banners ORDER BY created_at DESC LIMIT 0,1')->fetch();
$popularPosts =$db->select('SELECT posts.*, (SELECT COUNT(*) FROM comments WHERE comments.post_id = posts.id) AS comments_count, (SELECT username FROM users WHERE users.id = posts.user_id) AS username, (SELECT name FROM categories WHERE categories.id = posts.cat_id) AS category FROM posts ORDER BY view DESC LIMIT 0, 3')->fetchAll();
$mostCommentsPosts =$db->select('SELECT posts.*, (SELECT COUNT(*) FROM comments WHERE comments.post_id = posts.id) AS comments_count, (SELECT username FROM users WHERE users.id = posts.user_id) AS username, (SELECT name FROM categories WHERE categories.id = posts.cat_id) AS category FROM posts ORDER BY comments_count DESC LIMIT 0, 4')->fetchAll();
require_once (BASE_PATH . '/template/app/show-post.php');
}
public function commentStore($request){
if(isset($_SESSION['user']))
{
if($_SESSION['user'] != null)
{
$db = new Database();
$db->insert('comments', ['user_id', 'post_id', 'comment'], [$_SESSION['user'], $request['post_id'], $request['comment']]);
$this->redirectBack();
}
else{
$this->redirectBack();
}
}
else{
$this->redirectBack();
}
}
public function category($id)
{
$db = new DataBase();
$category = $db->select("SELECT * FROM `categories` WHERE `id` = ? ORDER BY `id` DESC ;", [$id])->fetch();
$topSelectedPosts = $db->select("SELECT posts.*, (SELECT COUNT(*) FROM comments WHERE comments.post_id = posts.id) AS comments_count, (SELECT username FROM users WHERE users.id = posts.user_id) AS username , (SELECT name FROM categories WHERE categories.id = posts.cat_id) AS category FROM posts where posts.selected = 2 ORDER BY `created_at` DESC LIMIT 0,1 ;")->fetchAll();
$categoryPosts = $db->select("SELECT posts.*, (SELECT COUNT(*) FROM comments WHERE comments.post_id = posts.id) AS comments_count, (SELECT username FROM users WHERE users.id = posts.user_id) AS username , (SELECT name FROM categories WHERE categories.id = posts.cat_id) AS category FROM posts WHERE cat_id = ? ORDER BY `created_at` DESC LIMIT 0,6 ;", [$id])->fetchAll();
$popularPosts = $db->select("SELECT posts.*, (SELECT COUNT(*) FROM comments WHERE comments.post_id = posts.id) AS comments_count, (SELECT username FROM users WHERE users.id = posts.user_id) AS username , (SELECT name FROM categories WHERE categories.id = posts.cat_id) AS category FROM posts ORDER BY `view` DESC LIMIT 0,3 ;")->fetchAll();
$breakingNews = $db->select("SELECT * FROM posts WHERE breaking_news = 2 ORDER BY `created_at` DESC LIMIT 0,1 ;")->fetch();
$mostCommentsPosts = $db->select("SELECT posts.*, (SELECT COUNT(*) FROM comments WHERE comments.post_id = posts.id) AS comments_count, (SELECT username FROM users WHERE users.id = posts.user_id) AS username , (SELECT name FROM categories WHERE categories.id = posts.cat_id) AS category FROM posts ORDER BY `comments_count` DESC LIMIT 0,4 ;")->fetchAll();
$menus = $db->select('SELECT *, (SELECT COUNT(*) FROM `menus` AS `submenus` WHERE `submenus`.`parent_id` = `menus`.`id` ) as `submenu_count` FROM `menus` WHERE `parent_id` IS NULL ;')->fetchAll();
$setting= $db->select("SELECT * FROM `websetting`;")->fetch();
$sidebarBanner= $db->select("SELECT * FROM `banners` LIMIT 0,1;")->fetch();
$bodyBanner= $db->select("SELECT * FROM `banners` ORDER BY created_at DESC LIMIT 0,1;")->fetch();
require_once (BASE_PATH . "/template/app/show-category.php");
}
protected function redirectBack(){
header("Location: " . $_SERVER['HTTP_REFERER']);
exit;
}
}

View file

@ -8,9 +8,9 @@ session_start();
//configuration //configuration
define('BASE_PATH', __DIR__); define('BASE_PATH', __DIR__);
define('CURRENT_DOMAIN', current_domain() . '/news-project/'); define('CURRENT_DOMAIN', current_domain() . '/NewsProject/');
define('DB_HOST', 'localhost'); define('DB_HOST', 'localhost');
define('DB_NAME', 'project'); define('DB_NAME', 'news-project');
define('DB_USERNAME', 'root'); define('DB_USERNAME', 'root');
define('DB_PASSWORD', ''); define('DB_PASSWORD', '');
define('DISPLAY_ERROR', true); define('DISPLAY_ERROR', true);
@ -19,11 +19,11 @@ define('DISPLAY_ERROR', true);
//mail config //mail config
define('MAIL_HOST', 'smtp.gmail.com'); define('MAIL_HOST', 'smtp.gmail.com');
define('SMTP_AUTH', true); define('SMTP_AUTH', true);
define('MAIL_USERNAME', 'onlinephp.attendance@gmail.com'); define('MAIL_USERNAME', '');
define('MAIL_PASSWORD', 'hasaan@#!ljk((#*$U&*jn&$#n322jn&'); define('MAIL_PASSWORD', '');
define('MAIL_PORT', 587); define('MAIL_PORT', 587);
define('SENDER_MAIL', 'onlinephp.attendance@gmail.com'); define('SENDER_MAIL', '');
define('SENDER_NAME', 'دوره حضوری و انلاین PHP'); define('SENDER_NAME', 'Mobina nj');
@ -31,22 +31,18 @@ define('SENDER_NAME', 'دوره حضوری و انلاین PHP');
require_once 'database/Database.php'; require_once 'database/Database.php';
require_once 'database/CreateDB.php'; require_once 'database/CreateDB.php';
// $db = new Database\Database();
// $db = new CreateDB();
// $db->run();
//admin //admin
require_once 'activities/Admin/Admin.php'; require_once 'activities/Admin/Admin.php';
require_once 'activities/Admin/Category.php'; require_once 'activities/Admin/Category.php';
require_once ("activities/Admin/Dashboard.php"); require_once 'activities/Admin/Dashboard.php';
require_once 'activities/Admin/Post.php'; require_once 'activities/Admin/Post.php';
require_once 'activities/Admin/Banner.php'; require_once 'activities/Admin/Banner.php';
require_once 'activities/Admin/User.php'; require_once 'activities/Admin/User.php';
require_once 'activities/Admin/Comment.php'; require_once 'activities/Admin/Comment.php';
require_once 'activities/Admin/Menu.php'; require_once 'activities/Admin/Menu.php';
require_once ("activities/Admin/WebSetting.php"); require_once 'activities/Admin/WebSetting.php';
@ -62,8 +58,6 @@ require_once ("activities/Home.php");
//helpers //helpers
@ -76,7 +70,7 @@ spl_autoload_register(function($className){
function jalaliDate($date) function jalaliDate($date)
{ {
return jDate::forge($date)->format('%A, %d %B %y'); return jDate::forge($date)->format('%A, %d %B %Y');
} }
@ -137,9 +131,6 @@ function uri($reservedUrl, $class, $method, $requestMethod = "GET")
$object = new $class; $object = new $class;
call_user_func_array(array($object, $method), $parameters); call_user_func_array(array($object, $method), $parameters);
// Category
// $category = new Category;
// $category->index();
exit; exit;
} }
@ -187,7 +178,7 @@ function dd($vars){
} }
// dd('hi');
function displayError($displayError){ function displayError($displayError){
@ -231,12 +222,6 @@ function flash($name, $value = null)
} }
// flash('cart', 'محصول با موفقیت به سبد خرید شما اضافه شد');
// flash('register', 'ثبت نام شما با موفقیت انجام شد');
// echo flash('cart');
// echo flash('register');
// flash('hasaan');
// flash('cart', 'محصول با موفقیت به سبد خرید شما اضافه شد');
//dashboard //dashboard

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 675 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 KiB

BIN
public/setting/icon.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View file

@ -25,18 +25,11 @@
</thead> </thead>
<tbody> <tbody>
<?php foreach ($banners as $banner) { ?> <?php foreach ($banners as $key => $banner) { ?>
<tr> <tr>
<td> <td><?= $key += 1 ?></td>
<?= $banner['id'] ?> <td><?= $banner['url'] ?></td>
</td> <td><img style="width: 80px;" src="<?= asset($banner['image']) ?>" alt=""></td>
<td>
<?= $banner['url'] ?>
</td>
<td>
<img style="width: 80px;" src="<?= asset($banner['image']) ?>" alt="">
</td>
<td> <td>
<a role="button" class="btn btn-sm btn-primary text-white" href="<?= asset('admin/banner/edit/' . $banner['id']) ?>">edit</a> <a role="button" class="btn btn-sm btn-primary text-white" href="<?= asset('admin/banner/edit/' . $banner['id']) ?>">edit</a>
<a role="button" class="btn btn-sm btn-danger text-white" href="<?= asset('admin/banner/delete/' . $banner['id']) ?>">delete</a> <a role="button" class="btn btn-sm btn-danger text-white" href="<?= asset('admin/banner/delete/' . $banner['id']) ?>">delete</a>

View file

@ -22,10 +22,10 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach ($categories as $category) { ?> <?php foreach ($categories as $key => $category) { ?>
<tr> <tr>
<td> <td>
<?= $category['id'] ?> <?= $key += 1 ?>
</td> </td>
<td> <td>
<?= $category['name'] ?> <?= $category['name'] ?>

View file

@ -25,9 +25,9 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach ($comments as $comment) { ?> <?php foreach ($comments as $key => $comment) { ?>
<tr> <tr>
<td><a href=""><?= $comment['id'] ?></a> <td><a href=""><?= $key += 1 ?></a>
</td> </td>
<td> <td>
<?= $comment['email'] ?> <?= $comment['email'] ?>

View file

@ -30,8 +30,8 @@ require_once BASE_PATH . '/template/admin/layouts/head-tag.php';
<?php foreach($menus as $menu) { ?> <?php foreach($menus as $menu) { ?>
<option value="<?= $menu['id'] ?>"> <option value="<?= $menu['id'] ?>">
<?= $menu['name'] ?> <?= $menu['name'] ?>
</option> </option>
<?php } ?> <?php } ?>

View file

@ -25,10 +25,10 @@
</thead> </thead>
<tbody> <tbody>
<?php foreach ($menus as $menu) { ?> <?php foreach ($menus as $key => $menu) { ?>
<tr> <tr>
<td> <td>
<?= $menu['id'] ?> <?= $key += 1 ?>
</td> </td>
<td> <td>
<?= $menu['name'] ?> <?= $menu['name'] ?>

View file

@ -28,33 +28,33 @@
</thead> </thead>
<tbody> <tbody>
<?php foreach ($posts as $post) { ?> <?php foreach ($posts as $key => $post) { ?>
<tr> <tr>
<td> <td>
<?= $post['id'] ?> <?= $key += 1 ?>
</td> </td>
<td> <td>
<?= $post['title'] ?> <?= $post['title'] ?>
<td> <td>
<?= $post['summary'] ?> <?= $post['summary'] ?>
</td> </td>
<td> <td>
<?= $post['view'] ?> <?= $post['view'] ?>
</td> </td>
<td> <td>
<?php if($post['breaking_news'] == 2) { ?> <?php if($post['breaking_news'] == 2) { ?>
<span class="badge badge-success">#breaking_news</span> <span class="badge badge-success">#breaking_news</span>
<?php } <?php }
if($post['selected'] == 2) { ?> if($post['selected'] == 2) { ?>
<span class="badge badge-dark">#editor_selected</span> <span class="badge badge-dark">#editor_selected</span>
<?php } ?> <?php } ?>
</td> </td>
<td> <td>
<?= $post['user_id'] ?> <?= $post['user_id'] ?>
</td> </td>
<td> <td>
<?= $post['cat_id'] ?> <?= $post['cat_id'] ?>
</td> </td>
<td> <td>
<img style="width: 80px;" src="<?= asset($post['image']) ?>" alt=""> <img style="width: 80px;" src="<?= asset($post['image']) ?>" alt="">

View file

@ -24,9 +24,9 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach ($users as $user) { ?> <?php foreach ($users as $key => $user) { ?>
<tr> <tr>
<td><?= $user['id'] ?></td> <td><?= $key += 1 ?></td>
<td><?= $user['username'] ?></td> <td><?= $user['username'] ?></td>
<td><?= $user['email'] ?></td> <td><?= $user['email'] ?></td>
<td><?= $user['permission'] ?></td> <td><?= $user['permission'] ?></td>

View file

@ -27,21 +27,26 @@ require_once(BASE_PATH . "/template/admin/layouts/head-tag.php");
<div class="form-group"> <div class="form-group">
<?php if($setting !=null){ ?>
<img style="width: 100px;" src="<?= asset($setting['logo']); ?>" alt="" >
<hr/>
<?php } ?>
<label for="logo">Logo</label> <label for="logo">Logo</label>
<input type="file" id="logo" name="logo" class="form-control-file" autofocus> <input type="file" id="logo" name="logo" class="form-control-file" autofocus>
<?php if($setting !=null){ ?>
<img style="width: 100px;" src="<?= asset($setting['logo']); ?>" alt="" >
<hr/>
<?php } ?>
</div> </div>
<div class="form-group"> <div class="form-group">
<?php if($setting !=null){ ?>
<img style="width: 100px;" src="<?= asset($setting['icon']); ?>" alt="" >
<hr/>
<?php } ?>
<label for="icon">Icon</label> <label for="icon">Icon</label>
<input type="file" id="icon" name="icon" class="form-control-file" autofocus> <input type="file" id="icon" name="icon" class="form-control-file" autofocus>
<?php if($setting !=null){ ?>
<img style="width: 100px;" src="<?= asset($setting['icon']); ?>" alt="" >
<hr/>
<?php } ?>
</div> </div>
<button type="submit" class="btn btn-primary btn-sm">set</button> <button type="submit" class="btn btn-primary btn-sm">set</button>

View file

@ -19,12 +19,12 @@
<li><a href="<?= url('show-category/' . $topSelectedPosts[0]['cat_id']) ?>"><?= $topSelectedPosts[0]['category'] ?></a></li> <li><a href="<?= url('show-category/' . $topSelectedPosts[0]['cat_id']) ?>"><?= $topSelectedPosts[0]['category'] ?></a></li>
</ul> </ul>
<a href="<?= url('show-post/' . $topSelectedPosts[0]['id']) ?>"> <a href="<?= url('show-post/' . $topSelectedPosts[0]['id']) ?>">
<h3><?= $topSelectedPosts[0]['title'] ?></h3> <h3 style="color: black;"><?= $topSelectedPosts[0]['title'] ?></h3>
</a> </a>
<ul class="meta"> <ul class="meta">
<li><a href="#"><span class="lnr lnr-user"></span><?= $topSelectedPosts[0]['username'] ?></a></li> <li><a href="#" style="color: black;"><span class="lnr lnr-user" style="color: black;"></span><?= $topSelectedPosts[0]['username'] ?></a></li>
<li><a href="#"><?= jalaliDate($topSelectedPosts[0]['created_at']) ?><span class="lnr lnr-calendar-full"></span></a></li> <li><a href="#" style="color: black;"><?= jalaliDate($topSelectedPosts[0]['created_at']) ?><span class="lnr lnr-calendar-full" style="color: black;"></span></a></li>
<li><a href="#"><?= $topSelectedPosts[0]['comments_count'] ?><span class="lnr lnr-bubble"></span></a></li> <li><a href="#" style="color: black;"><?= $topSelectedPosts[0]['comments_count'] ?><span class="lnr lnr-bubble" style="color: black;"></span></a></li>
</ul> </ul>
</div> </div>
<?php } ?> <?php } ?>

View file

@ -21,18 +21,17 @@
</div> </div>
<div class="footer-bottom row align-items-center"> <div class="footer-bottom row align-items-center">
<p class="footer-text m-0 col-lg-8 col-md-12"> <p class="footer-text m-0 col-lg-8 col-md-12">
<!-- Link back to Colorlib can't be removed. Template is licensed under CC BY 3.0. -->
Copyright &copy; Copyright &copy;
<script> <script>
document.write(new Date().getFullYear()); document.write(new Date().getFullYear());
</script> All rights reserved | This template is made with <i class="fa fa-heart-o" aria-hidden="true"></i> by <a href="https://colorlib.com" target="_blank">Colorlib</a> </script> All rights reserved
<!-- Link back to Colorlib can't be removed. Template is licensed under CC BY 3.0. -->
</p> </p>
<div class="col-lg-4 col-md-12 footer-social"> <div class="col-lg-4 col-md-12 footer-social">
<a href="#"><i class="fa fa-facebook"></i></a> <a href="#"><i class="fa fa-facebook"></i></a>
<a href="#"><i class="fa fa-twitter"></i></a> <a href="#"><i class="fa fa-twitter"></i></a>
<a href="#"><i class="fa fa-dribbble"></i></a> <a href="#"><i class="fa fa-instagram"></i></a>
<a href="#"><i class="fa fa-behance"></i></a> <a href="#"><i class="fa fa-linkedin"></i></a>
<a href="#"><i class="fa fa-telegram"></i></a>
</div> </div>
</div> </div>
</div> </div>

View file

@ -6,8 +6,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Favicon--> <!-- Favicon-->
<link rel="shortcut icon" href="<?= asset($setting['icon']) ?>"> <link rel="shortcut icon" href="<?= asset($setting['icon']) ?>">
<!-- Author Meta -->
<meta name="author" content="colorlib">
<!-- Meta Description --> <!-- Meta Description -->
<meta name="description" content="<?= $setting['description'] ?>"> <meta name="description" content="<?= $setting['description'] ?>">
<!-- Meta Keyword --> <!-- Meta Keyword -->
@ -37,18 +35,18 @@
<div class="header-top"> <div class="header-top">
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-6 header-top-left no-padding"> <!-- <div class="col-lg-6 col-md-6 col-sm-6 col-6 header-top-left no-padding">
<ul> <ul>
<li><a href="#"><i class="fa fa-facebook"></i></a></li> <li><a href="#"><i class="fa fa-facebook"></i></a></li>
<li><a href="#"><i class="fa fa-twitter"></i></a></li> <li><a href="#"><i class="fa fa-twitter"></i></a></li>
<li><a href="#"><i class="fa fa-dribbble"></i></a></li> <li><a href="#"><i class="fa fa-dribbble"></i></a></li>
<li><a href="#"><i class="fa fa-behance"></i></a></li> <li><a href="#"><i class="fa fa-behance"></i></a></li>
</ul> </ul>
</div> </div> -->
<div class="col-lg-6 col-md-6 col-sm-6 col-6 header-top-right no-padding"> <div class="col-lg-6 col-md-6 col-sm-6 col-6 header-top-left no-padding">
<ul> <ul>
<li><a href="tel:+440 012 3654 896"><span class="lnr lnr-phone-handset"></span><span>+440 012 3654 896</span></a></li> <li><a href=""><span class="lnr lnr-phone-handset"></span><span> 0903 958 2466</span></a></li>
<li><a href="mailto:support@colorlib.com"><span class="lnr lnr-envelope"></span><span>support@colorlib.com</span></a></li> <li><a href=""><span class="lnr lnr-envelope"></span><span> nimobina99@gmail.com</span></a></li>
</ul> </ul>
</div> </div>
</div> </div>
@ -58,12 +56,12 @@
<div class="container"> <div class="container">
<div class="row justify-content-between align-items-center"> <div class="row justify-content-between align-items-center">
<div class="col-lg-4 col-md-4 col-sm-12 logo-left no-padding"> <div class="col-lg-4 col-md-4 col-sm-12 logo-left no-padding">
<a href="index.html"> <a href="http://localhost/NewsProject/">
<img class="img-fluid" src="<?= asset($setting['logo']) ?>" alt=""> <img class="img-fluid" src="<?= asset($setting['logo']) ?>" alt="">
</a> </a>
</div> </div>
<div class="col-lg-8 col-md-8 col-sm-12 logo-right no-padding ads-banner"> <div class="col-lg-8 col-md-8 col-sm-12 logo-right no-padding ads-banner">
<img class="img-fluid" src="img/banner-ad.jpg" alt=""> <img class="img-fluid" src="<?= asset($bodyBanner['image']) ?>" alt="">
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,7 +1,6 @@
<?php <?php
require_once(BASE_PATH . '/template/app/layouts/header.php'); require_once(BASE_PATH . '/template/app/layouts/header.php');
?> ?>
<div class="site-main-container"> <div class="site-main-container">
<!-- Start top-post Area --> <!-- Start top-post Area -->
<!-- End top-post Area --> <!-- End top-post Area -->