This commit is contained in:
mobinajafarian 2023-06-12 22:58:54 +03:30
parent 0421b54d36
commit c8b0b098ae

293
index.php Normal file → Executable file
View file

@ -6,16 +6,14 @@ use Parsidev\Jalali\jDate;
session_start(); session_start();
//configuration //configuration
define('BASE_PATH', __DIR__); define('BASE_PATH', __DIR__);
define('CURRENT_DOMAIN', current_domain() . '/NewsProject/'); define('CURRENT_DOMAIN', current_domain() . '/OnlineNewsSite/');
define('DB_HOST', 'localhost'); define('DB_HOST', 'localhost');
define('DB_NAME', 'news-project'); define('DB_NAME', 'news-project');
define('DB_USERNAME', 'root'); define('DB_USERNAME', 'mobina');
define('DB_PASSWORD', ''); define('DB_PASSWORD', '1999');
define('DISPLAY_ERROR', true); 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);
@ -25,13 +23,9 @@ define('MAIL_PORT', 587);
define('SENDER_MAIL', ''); define('SENDER_MAIL', '');
define('SENDER_NAME', 'Mobina nj'); define('SENDER_NAME', 'Mobina nj');
//database //database
require_once 'database/Database.php'; require_once 'database/DataBase.php';
require_once 'database/CreateDB.php'; require_once 'database/createDB.php';
//admin //admin
require_once 'activities/Admin/Admin.php'; require_once 'activities/Admin/Admin.php';
@ -44,154 +38,143 @@ 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';
//auth //auth
require_once 'activities/Auth/Auth.php'; require_once 'activities/Auth/Auth.php';
//Home //Home
require_once ("activities/Home.php"); require_once "activities/Home.php";
//helpers //helpers
spl_autoload_register(function ($className) {
spl_autoload_register(function($className){ $path = BASE_PATH . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR;
$path = BASE_PATH . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR; $className = str_replace('\\', DIRECTORY_SEPARATOR, $className);
$className = str_replace('\\', DIRECTORY_SEPARATOR, $className); include $path . $className . '.php';
include $path . $className . '.php';
}); });
function jalaliDate($date) function jalaliDate($date)
{ {
return jDate::forge($date)->format('%A, %d %B %Y'); return jDate::forge($date)->format('%A, %d %B %Y');
} }
// uri('admin/category', 'Admin\Category', 'index'); // uri('admin/category', 'Admin\Category', 'index');
function uri($reservedUrl, $class, $method, $requestMethod = "GET") function uri($reservedUrl, $class, $method, $requestMethod = "GET")
{ {
// current url array
// current url array $currentUrl = explode('?', currentUrl())[0];
$currentUrl = explode('?', currentUrl())[0]; $currentUrl = str_replace(CURRENT_DOMAIN, '', $currentUrl);
$currentUrl = str_replace(CURRENT_DOMAIN, '', $currentUrl); $currentUrl = trim($currentUrl, '/');
$currentUrl = trim($currentUrl, '/'); $currentUrlArray = explode('/', $currentUrl);
$currentUrlArray = explode('/', $currentUrl); $currentUrlArray = array_filter($currentUrlArray);
$currentUrlArray = array_filter($currentUrlArray);
// reserved url array // reserved url array
$reservedUrl = trim($reservedUrl, '/'); $reservedUrl = trim($reservedUrl, '/');
$reservedUrlArray = explode('/', $reservedUrl); $reservedUrlArray = explode('/', $reservedUrl);
$reservedUrlArray = array_filter($reservedUrlArray); $reservedUrlArray = array_filter($reservedUrlArray);
// admin/category/create // admin/category/create
// admin/category/create // admin/category/create
if(sizeof($currentUrlArray) != sizeof($reservedUrlArray) || methodField() != $requestMethod){ if(sizeof($currentUrlArray) != sizeof($reservedUrlArray) || methodField() != $requestMethod){
return false; return false;
} }
// admin/category/edit/2 // admin/category/edit/2
// admin/category/edit/{id} // admin/category/edit/{id}
$parameters = []; $parameters = [];
for($key = 0; $key < sizeof($currentUrlArray); $key++) for($key = 0; $key < sizeof($currentUrlArray); $key++)
{ {
if($reservedUrlArray[$key][0] == '{' && $reservedUrlArray[$key][strlen($reservedUrlArray[$key]) - 1] == "}") if($reservedUrlArray[$key][0] == '{' && $reservedUrlArray[$key][strlen($reservedUrlArray[$key]) - 1] == "}")
{ {
array_push($parameters, $currentUrlArray[$key]); array_push($parameters, $currentUrlArray[$key]);
} }
elseif($currentUrlArray[$key] !== $reservedUrlArray[$key]){ elseif($currentUrlArray[$key] !== $reservedUrlArray[$key]){
// admin/category/delete/2 // admin/category/delete/2
// admin/category/edit/{id} // admin/category/edit/{id}
return false; return false;
} }
} }
if(methodField() == 'POST') if(methodField() == 'POST')
{ {
$request = isset($_FILES) ? array_merge($_POST, $_FILES) : $_POST; $request = isset($_FILES) ? array_merge($_POST, $_FILES) : $_POST;
$parameters = array_merge([$request], $parameters); $parameters = array_merge([$request], $parameters);
} }
$object = new $class; $object = new $class;
call_user_func_array(array($object, $method), $parameters); call_user_func_array(array($object, $method), $parameters);
exit; // Category
// $category = new Category;
// $category->index();
exit;
} }
function asset($src)
function asset($src) {
$domain = trim(CURRENT_DOMAIN, '/ ');
$src = $domain . '/' . trim($src, '/ ');
return $src;
}
function url($url) {
$domain = trim(CURRENT_DOMAIN, '/ ');
$url = $domain . '/' . trim($url, '/ ');
return $url;
}
function protocol()
{ {
return stripos($_SERVER['SERVER_PROTOCOL'], 'https') === true ? 'https://' : 'http://'; $domain = trim(CURRENT_DOMAIN, '/ ');
$src = $domain . '/' . trim($src, '/ ');
return $src;
} }
function current_domain(){ function url($url)
return protocol() . $_SERVER['HTTP_HOST']; {
$domain = trim(CURRENT_DOMAIN, '/ ');
$url = $domain . '/' . trim($url, '/ ');
return $url;
}
function protocol()
{
return stripos($_SERVER['SERVER_PROTOCOL'], 'https') === true ? 'https://' : 'http://';
}
function current_domain()
{
return protocol() . $_SERVER['HTTP_HOST'];
} }
// echo current_domain(); // echo current_domain();
function currentUrl(){ function currentUrl()
return current_domain() . $_SERVER['REQUEST_URI']; {
return current_domain() . $_SERVER['REQUEST_URI'];
} }
// echo currentUrl(); // echo currentUrl();
function methodField(){ function methodField()
return $_SERVER['REQUEST_METHOD']; {
return $_SERVER['REQUEST_METHOD'];
} }
// echo methodField(); // echo methodField();
function dd($vars){ function dd($vars)
{
echo '<pre>'; echo '<pre>';
var_dump($vars); var_dump($vars);
exit; exit;
} }
function displayError($displayError)
{
if ($displayError) {
function displayError($displayError){ ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
if($displayError){ error_reporting(E_ALL);
ini_set('display_errors', 1); } else {
ini_set('display_startup_errors', 1); ini_set('display_errors', 0);
error_reporting(E_ALL); ini_set('display_startup_errors', 0);
} error_reporting(0);
else{ }
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
error_reporting(0);
}
} }
@ -199,34 +182,27 @@ displayError(DISPLAY_ERROR);
global $flashMessage; global $flashMessage;
if(isset($_SESSION['flash_message'])){ if (isset($_SESSION['flash_message'])) {
$flashMessage = $_SESSION['flash_message']; $flashMessage = $_SESSION['flash_message'];
unset($_SESSION['flash_message']); unset($_SESSION['flash_message']);
} }
function flash($name, $value = null) function flash($name, $value = null)
{ {
if($value === null){ if ($value === null) {
global $flashMessage; global $flashMessage;
$message = isset($flashMessage[$name]) ? $flashMessage[$name] : ''; $message = isset($flashMessage[$name]) ? $flashMessage[$name] : '';
return $message; return $message;
} } else {
else{ $_SESSION['flash_message'][$name] = $value;
$_SESSION['flash_message'][$name] = $value; }
}
} }
//dashboard //dashboard
uri('admin','Admin\Dashboard','index'); uri('admin', 'Admin\Dashboard', 'index');
//category //category
uri('admin/category', 'Admin\Category', 'index'); uri('admin/category', 'Admin\Category', 'index');
@ -236,7 +212,6 @@ uri('admin/category/edit/{id}', 'Admin\Category', 'edit');
uri('admin/category/update/{id}', 'Admin\Category', 'update', "POST"); uri('admin/category/update/{id}', 'Admin\Category', 'update', "POST");
uri('admin/category/delete/{id}', 'Admin\Category', 'delete'); uri('admin/category/delete/{id}', 'Admin\Category', 'delete');
//post //post
uri('admin/post', 'Admin\Post', 'index'); uri('admin/post', 'Admin\Post', 'index');
uri('admin/post/create', 'Admin\Post', 'create'); uri('admin/post/create', 'Admin\Post', 'create');
@ -247,7 +222,6 @@ uri('admin/post/delete/{id}', 'Admin\Post', 'delete');
uri('admin/post/breaking-news/{id}', 'Admin\Post', 'breakingNews'); uri('admin/post/breaking-news/{id}', 'Admin\Post', 'breakingNews');
uri('admin/post/selected/{id}', 'Admin\Post', 'selected'); uri('admin/post/selected/{id}', 'Admin\Post', 'selected');
// banners // banners
uri('admin/banner', 'Admin\Banner', 'index'); uri('admin/banner', 'Admin\Banner', 'index');
@ -257,8 +231,6 @@ uri('admin/banner/edit/{id}', 'Admin\Banner', 'edit');
uri('admin/banner/update/{id}', 'Admin\Banner', 'update', 'POST'); uri('admin/banner/update/{id}', 'Admin\Banner', 'update', 'POST');
uri('admin/banner/delete/{id}', 'Admin\Banner', 'delete'); uri('admin/banner/delete/{id}', 'Admin\Banner', 'delete');
// users // users
uri('admin/user', 'Admin\User', 'index'); uri('admin/user', 'Admin\User', 'index');
@ -267,13 +239,10 @@ uri('admin/user/update/{id}', 'Admin\User', 'update', 'POST');
uri('admin/user/delete/{id}', 'Admin\User', 'delete'); uri('admin/user/delete/{id}', 'Admin\User', 'delete');
uri('admin/user/permission/{id}', 'Admin\User', 'permission'); uri('admin/user/permission/{id}', 'Admin\User', 'permission');
//comments //comments
uri('admin/comment', 'Admin\Comment', 'index'); uri('admin/comment', 'Admin\Comment', 'index');
uri('admin/comment/change-status/{id}', 'Admin\Comment', 'changeStatus'); uri('admin/comment/change-status/{id}', 'Admin\Comment', 'changeStatus');
// menu // menu
uri('admin/menu', 'Admin\Menu', 'index'); uri('admin/menu', 'Admin\Menu', 'index');
@ -283,39 +252,29 @@ uri('admin/menu/edit/{id}', 'Admin\Menu', 'edit');
uri('admin/menu/update/{id}', 'Admin\Menu', 'update', 'POST'); uri('admin/menu/update/{id}', 'Admin\Menu', 'update', 'POST');
uri('admin/menu/delete/{id}', 'Admin\Menu', 'delete'); uri('admin/menu/delete/{id}', 'Admin\Menu', 'delete');
//web setting //web setting
uri('admin/web-setting','Admin\WebSetting','index'); uri('admin/web-setting', 'Admin\WebSetting', 'index');
uri('admin/web-setting/set','Admin\WebSetting','set'); uri('admin/web-setting/set', 'Admin\WebSetting', 'set');
uri('admin/web-setting/store','Admin\WebSetting','store','POST'); uri('admin/web-setting/store', 'Admin\WebSetting', 'store', 'POST');
// Auth // Auth
uri('register','Auth\Auth','register'); uri('register', 'Auth\Auth', 'register');
uri('register/store','Auth\Auth','registerStore', "POST"); uri('register/store', 'Auth\Auth', 'registerStore', "POST");
uri('activation/{verify_token}','Auth\Auth','activation'); uri('activation/{verify_token}', 'Auth\Auth', 'activation');
uri('login','Auth\Auth','login'); uri('login', 'Auth\Auth', 'login');
uri('check-login','Auth\Auth','checkLogin', "POST"); uri('check-login', 'Auth\Auth', 'checkLogin', "POST");
uri('logout','Auth\Auth','logout'); uri('logout', 'Auth\Auth', 'logout');
uri('forgot','Auth\Auth','forgot'); uri('forgot', 'Auth\Auth', 'forgot');
uri('forgot/request','Auth\Auth','forgotRequest', "POST"); uri('forgot/request', 'Auth\Auth', 'forgotRequest', "POST");
uri('reset-password-form/{forgot_token}','Auth\Auth','resetPasswordView'); uri('reset-password-form/{forgot_token}', 'Auth\Auth', 'resetPasswordView');
uri('reset-password/{forgot_token}','Auth\Auth','resetPassword', "POST"); uri('reset-password/{forgot_token}', 'Auth\Auth', 'resetPassword', "POST");
//home //home
uri('/','App\Home','index'); uri('/', 'App\Home', 'index');
uri('home','App\Home','index'); uri('home', 'App\Home', 'index');
uri('show-post/{id}','App\Home','show'); uri('show-post/{id}', 'App\Home', 'show');
uri('show-category/{id}','App\Home','category'); uri('show-category/{id}', 'App\Home', 'category');
uri('comment-store','App\Home','commentStore', 'POST'); uri('comment-store', 'App\Home', 'commentStore', 'POST');
echo '404 - not found'; echo '404 - not found';
exit; exit;