2022-08-27 11:30:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Auth\Auth;
|
|
|
|
use Parsidev\Jalali\jDate;
|
|
|
|
|
|
|
|
session_start();
|
|
|
|
|
|
|
|
//configuration
|
|
|
|
define('BASE_PATH', __DIR__);
|
2023-06-12 19:28:54 +00:00
|
|
|
define('CURRENT_DOMAIN', current_domain() . '/OnlineNewsSite/');
|
2022-08-27 11:30:06 +00:00
|
|
|
define('DB_HOST', 'localhost');
|
2022-08-27 11:58:26 +00:00
|
|
|
define('DB_NAME', 'news-project');
|
2023-06-12 20:38:14 +00:00
|
|
|
define('DB_USERNAME', 'root');
|
|
|
|
define('DB_PASSWORD', '');
|
2022-08-27 11:30:06 +00:00
|
|
|
define('DISPLAY_ERROR', true);
|
|
|
|
|
|
|
|
//mail config
|
|
|
|
define('MAIL_HOST', 'smtp.gmail.com');
|
|
|
|
define('SMTP_AUTH', true);
|
2022-08-27 11:58:26 +00:00
|
|
|
define('MAIL_USERNAME', '');
|
|
|
|
define('MAIL_PASSWORD', '');
|
2022-08-27 11:30:06 +00:00
|
|
|
define('MAIL_PORT', 587);
|
2022-08-27 11:58:26 +00:00
|
|
|
define('SENDER_MAIL', '');
|
|
|
|
define('SENDER_NAME', 'Mobina nj');
|
2022-08-27 11:30:06 +00:00
|
|
|
|
|
|
|
//database
|
2023-06-12 19:28:54 +00:00
|
|
|
require_once 'database/DataBase.php';
|
|
|
|
require_once 'database/createDB.php';
|
2022-08-27 11:30:06 +00:00
|
|
|
|
|
|
|
//admin
|
|
|
|
require_once 'activities/Admin/Admin.php';
|
|
|
|
require_once 'activities/Admin/Category.php';
|
2022-09-09 11:07:26 +00:00
|
|
|
require_once 'activities/Admin/Dashboard.php';
|
2022-08-27 11:30:06 +00:00
|
|
|
require_once 'activities/Admin/Post.php';
|
|
|
|
require_once 'activities/Admin/Banner.php';
|
|
|
|
require_once 'activities/Admin/User.php';
|
|
|
|
require_once 'activities/Admin/Comment.php';
|
|
|
|
require_once 'activities/Admin/Menu.php';
|
2022-09-09 11:07:26 +00:00
|
|
|
require_once 'activities/Admin/WebSetting.php';
|
2022-08-27 11:30:06 +00:00
|
|
|
|
|
|
|
//auth
|
|
|
|
require_once 'activities/Auth/Auth.php';
|
|
|
|
|
|
|
|
//Home
|
2023-06-12 19:28:54 +00:00
|
|
|
require_once "activities/Home.php";
|
2022-08-27 11:30:06 +00:00
|
|
|
|
|
|
|
//helpers
|
|
|
|
|
2023-06-12 19:28:54 +00:00
|
|
|
spl_autoload_register(function ($className) {
|
|
|
|
$path = BASE_PATH . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR;
|
|
|
|
$className = str_replace('\\', DIRECTORY_SEPARATOR, $className);
|
|
|
|
include $path . $className . '.php';
|
2022-08-27 11:30:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function jalaliDate($date)
|
|
|
|
{
|
2023-06-12 19:28:54 +00:00
|
|
|
return jDate::forge($date)->format('%A, %d %B %Y');
|
2022-08-27 11:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// uri('admin/category', 'Admin\Category', 'index');
|
|
|
|
function uri($reservedUrl, $class, $method, $requestMethod = "GET")
|
|
|
|
{
|
2023-06-12 19:28:54 +00:00
|
|
|
// 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);
|
|
|
|
|
|
|
|
// admin/category/create
|
|
|
|
// admin/category/create
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
// Category
|
|
|
|
// $category = new Category;
|
|
|
|
// $category->index();
|
|
|
|
exit;
|
2022-08-27 11:30:06 +00:00
|
|
|
}
|
|
|
|
|
2023-06-12 19:28:54 +00:00
|
|
|
function asset($src)
|
|
|
|
{
|
|
|
|
$domain = trim(CURRENT_DOMAIN, '/ ');
|
|
|
|
$src = $domain . '/' . trim($src, '/ ');
|
|
|
|
return $src;
|
2022-08-27 11:30:06 +00:00
|
|
|
}
|
|
|
|
|
2023-06-12 19:28:54 +00:00
|
|
|
function url($url)
|
|
|
|
{
|
|
|
|
$domain = trim(CURRENT_DOMAIN, '/ ');
|
|
|
|
$url = $domain . '/' . trim($url, '/ ');
|
|
|
|
return $url;
|
2022-08-27 11:30:06 +00:00
|
|
|
}
|
|
|
|
|
2023-06-12 19:28:54 +00:00
|
|
|
function protocol()
|
2022-08-27 11:30:06 +00:00
|
|
|
{
|
2023-06-12 19:28:54 +00:00
|
|
|
return stripos($_SERVER['SERVER_PROTOCOL'], 'https') === true ? 'https://' : 'http://';
|
2022-08-27 11:30:06 +00:00
|
|
|
}
|
|
|
|
|
2023-06-12 19:28:54 +00:00
|
|
|
function current_domain()
|
|
|
|
{
|
|
|
|
return protocol() . $_SERVER['HTTP_HOST'];
|
2022-08-27 11:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// echo current_domain();
|
|
|
|
|
2023-06-12 19:28:54 +00:00
|
|
|
function currentUrl()
|
|
|
|
{
|
|
|
|
return current_domain() . $_SERVER['REQUEST_URI'];
|
2022-08-27 11:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// echo currentUrl();
|
|
|
|
|
2023-06-12 19:28:54 +00:00
|
|
|
function methodField()
|
|
|
|
{
|
|
|
|
return $_SERVER['REQUEST_METHOD'];
|
2022-08-27 11:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// echo methodField();
|
|
|
|
|
2023-06-12 19:28:54 +00:00
|
|
|
function dd($vars)
|
|
|
|
{
|
2022-08-27 11:30:06 +00:00
|
|
|
|
2023-06-12 19:28:54 +00:00
|
|
|
echo '<pre>';
|
|
|
|
var_dump($vars);
|
|
|
|
exit;
|
2022-08-27 11:30:06 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-06-12 19:28:54 +00:00
|
|
|
function displayError($displayError)
|
|
|
|
{
|
2022-09-09 11:07:26 +00:00
|
|
|
|
2023-06-12 19:28:54 +00:00
|
|
|
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);
|
|
|
|
}
|
2022-08-27 11:30:06 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
displayError(DISPLAY_ERROR);
|
|
|
|
|
|
|
|
global $flashMessage;
|
|
|
|
|
2023-06-12 19:28:54 +00:00
|
|
|
if (isset($_SESSION['flash_message'])) {
|
|
|
|
$flashMessage = $_SESSION['flash_message'];
|
|
|
|
unset($_SESSION['flash_message']);
|
2022-08-27 11:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function flash($name, $value = null)
|
|
|
|
{
|
|
|
|
|
2023-06-12 19:28:54 +00:00
|
|
|
if ($value === null) {
|
2022-08-27 11:30:06 +00:00
|
|
|
|
2023-06-12 19:28:54 +00:00
|
|
|
global $flashMessage;
|
|
|
|
$message = isset($flashMessage[$name]) ? $flashMessage[$name] : '';
|
|
|
|
return $message;
|
|
|
|
} else {
|
|
|
|
$_SESSION['flash_message'][$name] = $value;
|
|
|
|
}
|
2022-08-27 11:30:06 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//dashboard
|
2023-06-12 19:28:54 +00:00
|
|
|
uri('admin', 'Admin\Dashboard', 'index');
|
2022-08-27 11:30:06 +00:00
|
|
|
|
|
|
|
//category
|
|
|
|
uri('admin/category', 'Admin\Category', 'index');
|
|
|
|
uri('admin/category/create', 'Admin\Category', 'create');
|
|
|
|
uri('admin/category/store', 'Admin\Category', 'store', "POST");
|
|
|
|
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');
|
|
|
|
uri('admin/post/store', 'Admin\Post', 'store', "POST");
|
|
|
|
uri('admin/post/edit/{id}', 'Admin\Post', 'edit');
|
|
|
|
uri('admin/post/update/{id}', 'Admin\Post', 'update', "POST");
|
|
|
|
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');
|
|
|
|
uri('admin/banner/create', 'Admin\Banner', 'create');
|
|
|
|
uri('admin/banner/store', 'Admin\Banner', 'store', 'POST');
|
|
|
|
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');
|
|
|
|
uri('admin/user/edit/{id}', 'Admin\User', 'edit');
|
|
|
|
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');
|
|
|
|
uri('admin/menu/create', 'Admin\Menu', 'create');
|
|
|
|
uri('admin/menu/store', 'Admin\Menu', 'store', 'POST');
|
|
|
|
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
|
2023-06-12 19:28:54 +00:00
|
|
|
uri('admin/web-setting', 'Admin\WebSetting', 'index');
|
|
|
|
uri('admin/web-setting/set', 'Admin\WebSetting', 'set');
|
|
|
|
uri('admin/web-setting/store', 'Admin\WebSetting', 'store', 'POST');
|
2022-08-27 11:30:06 +00:00
|
|
|
|
|
|
|
// Auth
|
2023-06-12 19:28:54 +00:00
|
|
|
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");
|
2022-08-27 11:30:06 +00:00
|
|
|
|
|
|
|
//home
|
2023-06-12 19:28:54 +00:00
|
|
|
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');
|
2022-08-27 11:30:06 +00:00
|
|
|
|
|
|
|
echo '404 - not found';
|
2023-06-12 19:28:54 +00:00
|
|
|
exit;
|