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