mirror of
https://github.com/djav1985/v-wordpress-plugin-updater.git
synced 2025-10-04 16:31:05 +08:00
Refactor to basic MVC structure
This commit is contained in:
parent
cad654596a
commit
96fb672d99
27 changed files with 206 additions and 117 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,7 +1,6 @@
|
|||
vendor/
|
||||
phpcs.xml
|
||||
composer.lock
|
||||
composer.json
|
||||
.vscode/
|
||||
*.code-workspace
|
||||
.history/
|
||||
|
|
|
@ -67,12 +67,15 @@ The v-wordpress-plugin-updater project is designed to streamline the management
|
|||
│ └── v-sys-theme-updater.php
|
||||
├── update-api
|
||||
│ ├── HOSTS
|
||||
│ ├── classes
|
||||
│ ├── app
|
||||
│ │ ├── Core
|
||||
│ │ ├── Controllers
|
||||
│ │ ├── Models
|
||||
│ │ ├── Views
|
||||
│ │ └── Lib
|
||||
│ ├── config.php
|
||||
│ ├── lib
|
||||
│ ├── public
|
||||
│ ├── storage
|
||||
│ └── views
|
||||
└── v-wordpress-plugin-updater.png
|
||||
```
|
||||
|
||||
|
|
12
composer.json
Normal file
12
composer.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "vontainment/v-wordpress-plugin-updater",
|
||||
"description": "WordPress Plugin Updater",
|
||||
"require": {
|
||||
"php": ">=7.4"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "update-api/app/"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,12 +7,16 @@
|
|||
* @link https://vontainment.com
|
||||
* @version 3.0.0
|
||||
*
|
||||
* File: HomeHelper.php
|
||||
* File: HomeController.php
|
||||
* Description: WordPress Update API
|
||||
*/
|
||||
|
||||
|
||||
class HomeHelper // @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Core\UtilityHandler;
|
||||
|
||||
class HomeController // @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
|
||||
{
|
||||
/**
|
||||
* Handles the incoming request for managing hosts.
|
|
@ -7,11 +7,15 @@
|
|||
* @link https://vontainment.com
|
||||
* @version 3.0.0
|
||||
*
|
||||
* File: LogHelper.php
|
||||
* File: LogsController.php
|
||||
* Description: WordPress Update API
|
||||
*/
|
||||
|
||||
class LogsHelper // @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Core\UtilityHandler;
|
||||
|
||||
class LogsController // @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
|
||||
{
|
||||
/**
|
||||
* Processes a log file and generates HTML output.
|
|
@ -7,11 +7,15 @@
|
|||
* @link https://vontainment.com
|
||||
* @version 3.0.0
|
||||
*
|
||||
* File: PlHelper.php
|
||||
* File: PluginsController.php
|
||||
* Description: WordPress Update API
|
||||
*/
|
||||
|
||||
class PlHelper // @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Core\UtilityHandler;
|
||||
|
||||
class PluginsController // @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
|
||||
{
|
||||
/**
|
||||
* Handles the incoming request for plugin-related actions.
|
|
@ -7,11 +7,15 @@
|
|||
* @link https://vontainment.com
|
||||
* @version 3.0.0
|
||||
*
|
||||
* File: ThHelper.php
|
||||
* File: ThemesController.php
|
||||
* Description: WordPress Update API
|
||||
*/
|
||||
|
||||
class ThHelper // @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Core\UtilityHandler;
|
||||
|
||||
class ThemesController // @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
|
||||
{
|
||||
/**
|
||||
* Handles the incoming request for theme-related actions.
|
11
update-api/app/Core/Controller.php
Normal file
11
update-api/app/Core/Controller.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
namespace App\Core;
|
||||
|
||||
class Controller
|
||||
{
|
||||
protected function render(string $view, array $data = []): void
|
||||
{
|
||||
extract($data);
|
||||
require __DIR__ . '/../Views/' . $view . '.php';
|
||||
}
|
||||
}
|
|
@ -8,7 +8,9 @@
|
|||
*
|
||||
* File: ErrorHandler.php
|
||||
* Description: WordPress Update API
|
||||
*/
|
||||
*/
|
||||
|
||||
namespace App\Core;
|
||||
|
||||
class ErrorHandler // @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
|
||||
{
|
25
update-api/app/Core/Router.php
Normal file
25
update-api/app/Core/Router.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
namespace App\Core;
|
||||
|
||||
class Router
|
||||
{
|
||||
public function dispatch(string $uri): void
|
||||
{
|
||||
$route = strtok($uri, '?');
|
||||
switch ($route) {
|
||||
case '/plupdate':
|
||||
\App\Controllers\PluginsController::handleRequest();
|
||||
break;
|
||||
case '/thupdate':
|
||||
\App\Controllers\ThemesController::handleRequest();
|
||||
break;
|
||||
case '/logs':
|
||||
\App\Controllers\LogsController::handleRequest();
|
||||
break;
|
||||
case '/':
|
||||
case '/home':
|
||||
default:
|
||||
\App\Controllers\HomeController::handleRequest();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,6 +11,8 @@
|
|||
* Description: WordPress Update API
|
||||
*/
|
||||
|
||||
namespace App\Core;
|
||||
|
||||
class UtilityHandler // @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
|
||||
{
|
||||
/**
|
|
@ -7,10 +7,15 @@
|
|||
* @link https://vontainment.com
|
||||
* @version 3.0.0
|
||||
*
|
||||
* File: auth-lib.php
|
||||
* File: Auth.php
|
||||
* Description: WordPress Update API
|
||||
*/
|
||||
|
||||
namespace App\Lib;
|
||||
|
||||
use App\Core\UtilityHandler;
|
||||
use App\Core\ErrorHandler;
|
||||
|
||||
if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true) {
|
||||
if (isset($_POST["logout"])) {
|
||||
session_destroy();
|
|
@ -7,13 +7,17 @@
|
|||
* @link https://vontainment.com
|
||||
* @version 3.0.0
|
||||
*
|
||||
* File: class-lib.php
|
||||
* File: ClassLoader.php
|
||||
* Description: WordPress Update API
|
||||
*/
|
||||
|
||||
namespace App\Lib;
|
||||
|
||||
use App\Core\ErrorHandler;
|
||||
|
||||
// Autoload function to include class files without namespaces
|
||||
spl_autoload_register(function ($class_name) {
|
||||
$base = dirname(__DIR__) . '/classes/';
|
||||
$base = dirname(__DIR__) . '/Controllers/';
|
||||
$target = strtolower($class_name);
|
||||
foreach (glob($base . '*.php') as $file) {
|
||||
if (strtolower(basename($file, '.php')) === $target) {
|
|
@ -7,10 +7,15 @@
|
|||
* @link https://vontainment.com
|
||||
* @version 3.0.0
|
||||
*
|
||||
* File: load-lib.php
|
||||
* File: Loader.php
|
||||
* Description: WordPress Update API
|
||||
*/
|
||||
|
||||
namespace App\Lib;
|
||||
|
||||
use App\Core\UtilityHandler;
|
||||
use App\Core\ErrorHandler;
|
||||
|
||||
// Validate and sanitize the IP address
|
||||
$ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP);
|
||||
|
7
update-api/app/Models/HostsModel.php
Normal file
7
update-api/app/Models/HostsModel.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
class HostsModel
|
||||
{
|
||||
public static string $file = __DIR__ . '/../../HOSTS';
|
||||
}
|
7
update-api/app/Models/LogModel.php
Normal file
7
update-api/app/Models/LogModel.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
class LogModel
|
||||
{
|
||||
public static string $dir = STORAGE_LOGS_DIR;
|
||||
}
|
7
update-api/app/Models/PluginModel.php
Normal file
7
update-api/app/Models/PluginModel.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
class PluginModel
|
||||
{
|
||||
public static string $dir = STORAGE_PLUGINS_DIR;
|
||||
}
|
7
update-api/app/Models/ThemeModel.php
Normal file
7
update-api/app/Models/ThemeModel.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
class ThemeModel
|
||||
{
|
||||
public static string $dir = STORAGE_THEMES_DIR;
|
||||
}
|
|
@ -11,8 +11,10 @@
|
|||
* Description: WordPress Update API
|
||||
*/
|
||||
|
||||
HomeHelper::handleRequest();
|
||||
$hostsTableHtml = HomeHelper::getHostsTableHtml();
|
||||
use App\Controllers\HomeController;
|
||||
require_once __DIR__ . '/layouts/header.php';
|
||||
HomeController::handleRequest();
|
||||
$hostsTableHtml = HomeController::getHostsTableHtml();
|
||||
?>
|
||||
|
||||
<div class="content-box">
|
||||
|
@ -39,3 +41,4 @@ $hostsTableHtml = HomeHelper::getHostsTableHtml();
|
|||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php require_once __DIR__ . '/layouts/footer.php'; ?>
|
8
update-api/app/Views/layouts/footer.php
Normal file
8
update-api/app/Views/layouts/footer.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
</div>
|
||||
<footer>
|
||||
<p>© <?php echo date("Y"); ?> Vontainment. All Rights Reserved.</p>
|
||||
</footer>
|
||||
<script src="/assets/js/footer-scripts.js"></script>
|
||||
<?php echo App\Core\ErrorHandler::displayAndClearMessages(); ?>
|
||||
</body>
|
||||
</html>
|
34
update-api/app/Views/layouts/header.php
Normal file
34
update-api/app/Views/layouts/header.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en-US">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no" />
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title>API Admin Page</title>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.7.0/min/dropzone.min.js"></script>
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.7.0/min/dropzone.min.css" rel="stylesheet" />
|
||||
<script src="/assets/js/header-scripts.js"></script>
|
||||
<link rel="stylesheet" href="/assets/css/styles.css">
|
||||
<link rel="stylesheet" href="/assets/css/mobile.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<div class="logo">
|
||||
<a href="/">
|
||||
<img src="/assets/images/logo.png" alt="Logo">
|
||||
</a>
|
||||
</div>
|
||||
<div class="logout-button">
|
||||
<form action="/login.php" method="POST">
|
||||
<button class="orange-button" type="submit" name="logout">Logout</button>
|
||||
</form>
|
||||
</div>
|
||||
</header>
|
||||
<div class="tab">
|
||||
<a href="/"><button class="tablinks <?php if ($_SERVER['REQUEST_URI'] === '/') { echo 'active'; } ?>">Manage Hosts</button></a>
|
||||
<a href="/plupdate"><button class="tablinks <?php if ($_SERVER['REQUEST_URI'] === '/plupdate') { echo 'active'; } ?>">Manage Plugins</button></a>
|
||||
<a href="/thupdate"><button class="tablinks <?php if ($_SERVER['REQUEST_URI'] === '/thupdate') { echo 'active'; } ?>">Manage Themes</button></a>
|
||||
<a href="/logs"><button class="tablinks <?php if ($_SERVER['REQUEST_URI'] === '/logs') { echo 'active'; } ?>">View Logs</button></a>
|
||||
</div>
|
||||
<div class="content">
|
|
@ -11,8 +11,10 @@
|
|||
* Description: WordPress Update API
|
||||
*/
|
||||
|
||||
$ploutput = LogsHelper::processLogFile('plugin.log');
|
||||
$thoutput = LogsHelper::processLogFile('theme.log');
|
||||
use App\Controllers\LogsController;
|
||||
require_once __DIR__ . '/layouts/header.php';
|
||||
$ploutput = LogsController::processLogFile('plugin.log');
|
||||
$thoutput = LogsController::processLogFile('theme.log');
|
||||
|
||||
?>
|
||||
<div class="content-box">
|
||||
|
@ -21,3 +23,4 @@ $thoutput = LogsHelper::processLogFile('theme.log');
|
|||
<h2>Theme Log</h2>
|
||||
<?php echo $thoutput; ?>
|
||||
</div>
|
||||
<?php require_once __DIR__ . '/layouts/footer.php'; ?>
|
|
@ -11,8 +11,10 @@
|
|||
* Description: WordPress Update API
|
||||
*/
|
||||
|
||||
PlHelper::handleRequest();
|
||||
$pluginsTableHtml = PlHelper::getPluginsTableHtml();
|
||||
use App\Controllers\PluginsController;
|
||||
require_once __DIR__ . '/layouts/header.php';
|
||||
PluginsController::handleRequest();
|
||||
$pluginsTableHtml = PluginsController::getPluginsTableHtml();
|
||||
?>
|
||||
|
||||
<div class="content-box">
|
||||
|
@ -77,3 +79,4 @@ $pluginsTableHtml = PlHelper::getPluginsTableHtml();
|
|||
});
|
||||
});
|
||||
</script>
|
||||
<?php require_once __DIR__ . '/layouts/footer.php'; ?>
|
|
@ -11,8 +11,10 @@
|
|||
* Description: WordPress Update API
|
||||
*/
|
||||
|
||||
ThHelper::handleRequest();
|
||||
$themesTableHtml = ThHelper::getThemesTableHtml();
|
||||
use App\Controllers\ThemesController;
|
||||
require_once __DIR__ . '/layouts/header.php';
|
||||
ThemesController::handleRequest();
|
||||
$themesTableHtml = ThemesController::getThemesTableHtml();
|
||||
?>
|
||||
|
||||
<div class="content-box">
|
||||
|
@ -76,3 +78,4 @@ $themesTableHtml = ThHelper::getThemesTableHtml();
|
|||
});
|
||||
});
|
||||
</script>
|
||||
<?php require_once __DIR__ . '/layouts/footer.php'; ?>
|
|
@ -12,7 +12,7 @@
|
|||
*/
|
||||
|
||||
require_once '../config.php';
|
||||
require_once '../lib/class-lib.php';
|
||||
require_once '../../vendor/autoload.php';
|
||||
|
||||
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
|
|
|
@ -1,96 +1,19 @@
|
|||
<?php
|
||||
use App\Lib\Loader;
|
||||
use App\Core\Router;
|
||||
|
||||
/**
|
||||
* @package UpdateAPI
|
||||
* @author Vontainment <services@vontainment.com>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://vontainment.com
|
||||
* @version 3.0.0
|
||||
*
|
||||
* File: index.php
|
||||
* Description: WordPress Update API
|
||||
*/
|
||||
|
||||
// Set secure session cookie parameters before starting the session
|
||||
$secureFlag = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
|
||||
session_set_cookie_params(
|
||||
[
|
||||
'httponly' => true,
|
||||
'secure' => $secureFlag,
|
||||
'samesite' => 'Lax',
|
||||
]
|
||||
);
|
||||
session_set_cookie_params([
|
||||
'httponly' => true,
|
||||
'secure' => $secureFlag,
|
||||
'samesite' => 'Lax',
|
||||
]);
|
||||
session_start();
|
||||
session_regenerate_id(true); // Regenerate session ID to prevent session fixation attacks
|
||||
session_regenerate_id(true);
|
||||
|
||||
require_once '../config.php';
|
||||
require_once '../lib/class-lib.php';
|
||||
require_once '../lib/load-lib.php';
|
||||
?>
|
||||
require_once '../../vendor/autoload.php';
|
||||
require_once '../app/Lib/Loader.php';
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en-US">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no" />
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title>API Admin Page</title>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.7.0/min/dropzone.min.js"></script>
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.7.0/min/dropzone.min.css" rel="stylesheet" />
|
||||
<script src="/assets/js/header-scripts.js"></script>
|
||||
<link rel="stylesheet" href="/assets/css/styles.css">
|
||||
<link rel="stylesheet" href="/assets/css/mobile.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<div class="logo">
|
||||
<a href="/">
|
||||
<img src="/assets/images/logo.png" alt="Logo">
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="logout-button">
|
||||
<form action="/login.php" method="POST">
|
||||
<button class="orange-button" type="submit" name="logout">Logout</button>
|
||||
</form>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- Tab links -->
|
||||
<div class="tab">
|
||||
<a href="/"><button class="tablinks <?php if ($_SERVER['REQUEST_URI'] === '/') {
|
||||
echo 'active';
|
||||
} ?>">Manage Hosts</button></a>
|
||||
<a href="/plupdate"><button class="tablinks <?php if ($_SERVER['REQUEST_URI'] === '/plupdate') {
|
||||
echo 'active';
|
||||
} ?>">Manage Plugins</button></a>
|
||||
<a href="/thupdate"><button class="tablinks <?php if ($_SERVER['REQUEST_URI'] === '/thupdate') {
|
||||
echo 'active';
|
||||
} ?>">Manage Themes</button></a>
|
||||
<a href="/logs"><button class="tablinks <?php if ($_SERVER['REQUEST_URI'] === '/logs') {
|
||||
echo 'active';
|
||||
} ?>">View Logs</button></a>
|
||||
</div>
|
||||
|
||||
<!-- Tab links -->
|
||||
<!-- Tab content -->
|
||||
<?php
|
||||
if (isset($pageOutput)) {
|
||||
include_once $pageOutput;
|
||||
}
|
||||
?>
|
||||
<!-- Tab content -->
|
||||
<footer>
|
||||
<p>©
|
||||
<?php echo date("Y"); ?> Vontainment. All Rights Reserved.
|
||||
</p>
|
||||
</footer>
|
||||
<script src="/assets/js/footer-scripts.js"></script>
|
||||
<?php echo ErrorHandler::displayAndClearMessages(); ?>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
$router = new Router();
|
||||
$router->dispatch($_SERVER['REQUEST_URI']);
|
||||
|
|
|
@ -22,8 +22,8 @@ session_set_cookie_params(
|
|||
);
|
||||
session_start();
|
||||
require_once '../config.php';
|
||||
require_once '../lib/class-lib.php';
|
||||
require_once '../lib/auth-lib.php';
|
||||
require_once '../../vendor/autoload.php';
|
||||
require_once '../app/Lib/Auth.php';
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue