Files
thetempusproject/app/controllers/admin/plugins.php
Joey Kimsey d7e8b586d7 various updates
remove dependence on jQuery
add image delete
Admin ui fix for mobile
image updates to new style
update comments
2025-02-05 06:36:29 -05:00

137 lines
4.7 KiB
PHP

<?php
/**
* app/controllers/admin/installed.php
*
* This is the installed plugins controller.
*
* @version 5.0.1
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Controllers\Admin;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Houdini\Classes\Components;
use TheTempusProject\Houdini\Classes\Navigation;
use TheTempusProject\Classes\AdminController;
use TheTempusProject\Classes\Installer;
use TheTempusProject\Classes\Plugin;
use TheTempusProject\Hermes\Functions\Redirect;
use TheTempusProject\Bedrock\Functions\Session;
class Plugins extends AdminController {
public $installer;
public $plugins;
public function __construct() {
parent::__construct();
self::$title = 'Admin - Installed Plugins';
$this->installer = new Installer;
$this->plugins = $this->installer->getAvailablePlugins();
}
public function index() {
Views::view( 'admin.modules.plugins.list', $this->plugins );
}
public function disable( $name = null ) {
if ( empty( $name ) ) {
Session::flash( 'error', 'Unknown Plugin.' );
Redirect::to( 'admin/plugins' );
}
Components::set( 'PLUGIN', $name );
self::$title = 'Admin - Disable ' . $name;
if ( !Input::exists( 'installHash' ) ) {
return Views::view( 'admin.modules.plugins.disable' );
}
if ( !Plugin::disable( $name ) ) {
Session::flash( 'error', 'There was an error disabling the plugin.' );
} else {
Session::flash( 'success', 'Plugin has been disabled.' );
}
Redirect::to( 'admin/plugins' );
}
public function enable( $name = null ) {
if ( empty( $name ) ) {
Session::flash( 'error', 'Unknown Plugin.' );
Redirect::to( 'admin/plugins' );
}
Components::set( 'PLUGIN', $name );
self::$title = 'Admin - Enable ' . $name;
if ( !Input::exists( 'installHash' ) ) {
return Views::view( 'admin.modules.plugins.enable' );
}
if ( ! Plugin::enable( $name ) ) {
Session::flash( 'error', 'There was an error enabling the plugin.' );
} else {
Session::flash( 'success', 'Plugin has been enabled.' );
}
Redirect::to( 'admin/plugins' );
}
public function install( $name = null ) {
if ( empty( $name ) ) {
Session::flash( 'error', 'Unknown Plugin.' );
Redirect::to( 'admin/plugins' );
}
$name = strtolower( $name );
Components::set( 'PLUGIN', $name );
self::$title = 'Admin - Install ' . $name;
if ( ! Input::exists( 'installHash' ) ) {
return Views::view( 'admin.modules.plugins.install' );
}
if ( empty( $this->plugins[$name] ) ) {
Session::flash( 'error', 'Unknown Plugin.' );
} else {
$result = $this->installer->installPlugin( $this->plugins[$name] );
if ( empty( $result ) ) {
Session::flash( 'error', [ 'There was an error with the install.' => $this->installer->getErrors() ] );
} else {
Session::flash( 'success', 'Plugin has been installed.' );
}
}
Redirect::to( 'admin/plugins' );
}
public function uninstall( $name = null ) {
if ( empty($name)) {
Session::flash( 'error', 'Unknown Plugin.' );
Redirect::to( 'admin/plugins' );
}
$name = strtolower($name);
Components::set( 'PLUGIN', $name );
self::$title = 'Admin - Uninstall ' . $name;
if ( !Input::exists( 'uninstallHash' ) ) {
return Views::view( 'admin.modules.plugins.uninstall' );
}
if ( empty( $this->plugins[$name] ) ) {
Session::flash( 'error', 'Unknown Plugin.' );
} else {
$result = $this->installer->uninstallPlugin( $this->plugins[$name] );
if ( empty($result) ) {
Session::flash( 'error', [ 'There was an error with the uninstall.' => $this->installer->getErrors() ] );
} else {
Session::flash( 'success', 'Plugin has been uninstalled.' );
}
}
Redirect::to( 'admin/plugins' );
}
public function view( $name = null ) {
$name = strtolower($name);
if ( empty( $this->plugins[$name] ) ) {
Session::flash( 'error', 'Unknown Plugin.' );
Redirect::to( 'admin/plugins' );
} else {
Views::view( 'admin.modules.plugins.view', $this->plugins[$name] );
}
}
}