applied common formatting
This commit is contained in:
@ -7,9 +7,9 @@ use ManiaControl\ManiaControl;
|
||||
/**
|
||||
* Interface for ManiaControl Plugins
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
interface Plugin {
|
||||
/*
|
||||
@ -24,19 +24,6 @@ interface Plugin {
|
||||
*/
|
||||
public static function prepare(ManiaControl $maniaControl);
|
||||
|
||||
/**
|
||||
* Load the plugin
|
||||
*
|
||||
* @param \ManiaControl\ManiaControl $maniaControl
|
||||
* @return bool
|
||||
*/
|
||||
public function load(ManiaControl $maniaControl);
|
||||
|
||||
/**
|
||||
* Unload the plugin and its Resources
|
||||
*/
|
||||
public function unload();
|
||||
|
||||
/**
|
||||
* Get plugin id
|
||||
*
|
||||
@ -71,4 +58,17 @@ interface Plugin {
|
||||
* @return string
|
||||
*/
|
||||
public static function getDescription();
|
||||
|
||||
/**
|
||||
* Load the plugin
|
||||
*
|
||||
* @param \ManiaControl\ManiaControl $maniaControl
|
||||
* @return bool
|
||||
*/
|
||||
public function load(ManiaControl $maniaControl);
|
||||
|
||||
/**
|
||||
* Unload the plugin and its Resources
|
||||
*/
|
||||
public function unload();
|
||||
}
|
||||
|
@ -21,16 +21,16 @@ use ManiaControl\Players\Player;
|
||||
/**
|
||||
* Configurator for enabling and disabling Plugins
|
||||
*
|
||||
* @author steeffeen
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAnswerListener {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const SETTING_PERMISSION_INSTALL_PLUGINS = 'Install plugins';
|
||||
const ACTION_PREFIX_INSTALLPLUGIN = 'PluginInstallMenu.Install.';
|
||||
const SETTING_PERMISSION_INSTALL_PLUGINS = 'Install plugins';
|
||||
const ACTION_PREFIX_INSTALLPLUGIN = 'PluginInstallMenu.Install.';
|
||||
|
||||
/**
|
||||
* Create a new plugin menu instance
|
||||
@ -62,9 +62,9 @@ class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, Manialink
|
||||
* @return \FML\Controls\Frame
|
||||
*/
|
||||
public function getMenu($width, $height, Script $script, Player $player) {
|
||||
$paging = new Paging();
|
||||
$script->addFeature($paging);
|
||||
$frame = new Frame();
|
||||
$paging = new Paging();
|
||||
$script->addFeature($paging);
|
||||
$frame = new Frame();
|
||||
|
||||
// Config
|
||||
$pagerSize = 9.;
|
||||
@ -87,8 +87,8 @@ class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, Manialink
|
||||
$pagerNext->setSize($pagerSize, $pagerSize);
|
||||
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
|
||||
|
||||
$paging->addButton($pagerNext);
|
||||
$paging->addButton($pagerPrev);
|
||||
$paging->addButton($pagerNext);
|
||||
$paging->addButton($pagerPrev);
|
||||
|
||||
$pageCountLabel = new Label_Text();
|
||||
$frame->add($pageCountLabel);
|
||||
@ -97,22 +97,22 @@ class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, Manialink
|
||||
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
|
||||
$pageCountLabel->setTextSize(2);
|
||||
|
||||
$paging->setLabel($pageCountLabel);
|
||||
$paging->setLabel($pageCountLabel);
|
||||
|
||||
$url = ManiaControl::URL_WEBSERVICE . 'plugins';
|
||||
$dataJson = FileUtil::loadFile($url);
|
||||
$pluginList = json_decode($dataJson);
|
||||
$index = 0;
|
||||
$url = ManiaControl::URL_WEBSERVICE . 'plugins';
|
||||
$dataJson = FileUtil::loadFile($url);
|
||||
$pluginList = json_decode($dataJson);
|
||||
$index = 0;
|
||||
if ($pluginList && isset($pluginList[0])) {
|
||||
$pluginClasses = $this->maniaControl->pluginManager->getPluginClasses();
|
||||
$pluginIds = array();
|
||||
$pluginClasses = $this->maniaControl->pluginManager->getPluginClasses();
|
||||
$pluginIds = array();
|
||||
/** @var Plugin $class */
|
||||
foreach($pluginClasses as $class) {
|
||||
foreach ($pluginClasses as $class) {
|
||||
$pluginIds[] = $class::getId();
|
||||
}
|
||||
|
||||
foreach($pluginList as $plugin) {
|
||||
if(!in_array($plugin->id, $pluginIds)) {
|
||||
foreach ($pluginList as $plugin) {
|
||||
if (!in_array($plugin->id, $pluginIds)) {
|
||||
if (!isset($pageFrame)) {
|
||||
$pageFrame = new Frame();
|
||||
$frame->add($pageFrame);
|
||||
@ -121,7 +121,7 @@ class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, Manialink
|
||||
}
|
||||
|
||||
array_push($pageFrames, $pageFrame);
|
||||
$paging->addPage($pageFrame);
|
||||
$paging->addPage($pageFrame);
|
||||
$y = $height * 0.41;
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, Manialink
|
||||
$descriptionLabel->setMaxLines(5);
|
||||
$description = "Author: {$plugin->author}\nVersion: {$plugin->currentVersion->version}\nDesc: {$plugin->description}";
|
||||
$descriptionLabel->setText($description);
|
||||
$nameLabel->addTooltipFeature($descriptionLabel);
|
||||
$nameLabel->addTooltipFeature($descriptionLabel);
|
||||
|
||||
$installButton = new Label_Button();
|
||||
$pluginFrame->add($installButton);
|
||||
|
@ -3,24 +3,24 @@
|
||||
namespace ManiaControl\Plugins;
|
||||
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use ManiaControl\Callbacks\TimerListener;
|
||||
use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
|
||||
/**
|
||||
* Class managing Plugins
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class PluginManager {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const TABLE_PLUGINS = 'mc_plugins';
|
||||
|
||||
|
||||
/*
|
||||
* Private Properties
|
||||
*/
|
||||
@ -32,27 +32,27 @@ class PluginManager {
|
||||
|
||||
/**
|
||||
* Construct plugin manager
|
||||
*
|
||||
*
|
||||
* @param \ManiaControl\ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
$this->initTables();
|
||||
|
||||
|
||||
$this->pluginMenu = new PluginMenu($maniaControl);
|
||||
$this->maniaControl->configurator->addMenu($this->pluginMenu);
|
||||
|
||||
|
||||
$this->pluginInstallMenu = new PluginInstallMenu($maniaControl);
|
||||
$this->maniaControl->configurator->addMenu($this->pluginInstallMenu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize necessary database tables
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function initTables() {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$pluginsTableQuery = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLUGINS . "` (
|
||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`className` varchar(100) NOT NULL,
|
||||
@ -61,7 +61,7 @@ class PluginManager {
|
||||
PRIMARY KEY (`index`),
|
||||
UNIQUE KEY `className` (`className`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='ManiaControl plugin status' AUTO_INCREMENT=1;";
|
||||
$tableStatement = $mysqli->prepare($pluginsTableQuery);
|
||||
$tableStatement = $mysqli->prepare($pluginsTableQuery);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
return false;
|
||||
@ -75,95 +75,9 @@ class PluginManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the plugin is running
|
||||
*
|
||||
* @param string $pluginClass
|
||||
* @return bool
|
||||
*/
|
||||
public function isPluginActive($pluginClass) {
|
||||
$pluginClass = $this->getPluginClass($pluginClass);
|
||||
return isset($this->activePlugins[$pluginClass]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given class implements the plugin interface
|
||||
*
|
||||
* @param string $pluginClass
|
||||
* @return bool
|
||||
*/
|
||||
public static function isPluginClass($pluginClass) {
|
||||
$pluginClass = self::getClass($pluginClass);
|
||||
if (!class_exists($pluginClass, false)) {
|
||||
return false;
|
||||
}
|
||||
if (!in_array(Plugin::PLUGIN_INTERFACE, class_implements($pluginClass, false))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the class to array of loaded plugin classes
|
||||
*
|
||||
* @param string $pluginClass
|
||||
* @return bool
|
||||
*/
|
||||
public function addPluginClass($pluginClass) {
|
||||
$pluginClass = $this->getPluginClass($pluginClass);
|
||||
if (in_array($pluginClass, $this->pluginClasses)) {
|
||||
return false;
|
||||
}
|
||||
if (!$this->isPluginClass($pluginClass)) {
|
||||
return false;
|
||||
}
|
||||
array_push($this->pluginClasses, $pluginClass);
|
||||
sort($this->pluginClasses);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate and start the plugin with the given name
|
||||
*
|
||||
* @param string $pluginClass
|
||||
* @param string $adminLogin
|
||||
* @return bool
|
||||
*/
|
||||
public function activatePlugin($pluginClass, $adminLogin = null) {
|
||||
if (!is_string($pluginClass)) {
|
||||
return false;
|
||||
}
|
||||
if (!$this->isPluginClass($pluginClass)) {
|
||||
return false;
|
||||
}
|
||||
if ($this->isPluginActive($pluginClass)) {
|
||||
return false;
|
||||
}
|
||||
$plugin = new $pluginClass();
|
||||
/**
|
||||
*
|
||||
* @var Plugin $plugin
|
||||
*/
|
||||
$this->activePlugins[$pluginClass] = $plugin;
|
||||
$this->savePluginStatus($pluginClass, true);
|
||||
try {
|
||||
$plugin->load($this->maniaControl);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$this->maniaControl->chat->sendError('Error while plugin activating ' . $pluginClass . ': ' . $e->getMessage(), $adminLogin);
|
||||
$this->maniaControl->log('Error while plugin activation: ' . $pluginClass . ': ' . $e->getMessage());
|
||||
unset($this->activePlugins[$pluginClass]);
|
||||
$this->savePluginStatus($pluginClass, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->savePluginStatus($pluginClass, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate the plugin with the given class
|
||||
*
|
||||
*
|
||||
* @param string $pluginClass
|
||||
* @return bool
|
||||
*/
|
||||
@ -174,7 +88,6 @@ class PluginManager {
|
||||
}
|
||||
$plugin = $this->activePlugins[$pluginClass];
|
||||
/**
|
||||
*
|
||||
* @var Plugin $plugin
|
||||
*/
|
||||
$plugin->unload();
|
||||
@ -197,113 +110,69 @@ class PluginManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Load complete Plugins Directory and start all configured Plugins
|
||||
*
|
||||
* @return array
|
||||
* Get the Class of the Plugin
|
||||
*
|
||||
* @param mixed $pluginClass
|
||||
* @return string
|
||||
*/
|
||||
public function loadPlugins() {
|
||||
$pluginsDirectory = ManiaControlDir . '/plugins/';
|
||||
|
||||
$classesBefore = get_declared_classes();
|
||||
$this->loadPluginFiles($pluginsDirectory);
|
||||
$classesAfter = get_declared_classes();
|
||||
|
||||
$newPluginClasses = array();
|
||||
|
||||
$newClasses = array_diff($classesAfter, $classesBefore);
|
||||
foreach ($newClasses as $className) {
|
||||
if (!$this->isPluginClass($className)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$this->addPluginClass($className)) {
|
||||
continue;
|
||||
}
|
||||
array_push($newPluginClasses, $className);
|
||||
|
||||
/** @var Plugin $className */
|
||||
$className::prepare($this->maniaControl);
|
||||
|
||||
if ($this->getSavedPluginStatus($className)) {
|
||||
$this->activatePlugin($className);
|
||||
}
|
||||
public static function getPluginClass($pluginClass) {
|
||||
$pluginClass = self::getClass($pluginClass);
|
||||
if (!self::isPluginClass($pluginClass)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $newPluginClasses;
|
||||
return $pluginClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all Plugin Files from the Directory
|
||||
*
|
||||
* @param string $directory
|
||||
* Get the Class of the Object
|
||||
*
|
||||
* @param mixed $object
|
||||
* @return string
|
||||
*/
|
||||
public function loadPluginFiles($directory = '') {
|
||||
$pluginFiles = scandir($directory);
|
||||
foreach ($pluginFiles as $pluginFile) {
|
||||
if (stripos($pluginFile, '.') === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$filePath = $directory . $pluginFile;
|
||||
if (is_file($filePath)) {
|
||||
if (!stripos($pluginFile, '.php')) {
|
||||
continue;
|
||||
}
|
||||
$success = include_once $filePath;
|
||||
if (!$success) {
|
||||
trigger_error("Error loading File '{$filePath}'!");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
$dirPath = $directory . $pluginFile;
|
||||
if (is_dir($dirPath)) {
|
||||
$this->loadPluginFiles($dirPath . '/');
|
||||
continue;
|
||||
}
|
||||
private static function getClass($object) {
|
||||
if (is_object($object)) {
|
||||
return get_class($object);
|
||||
}
|
||||
return (string)$object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Plugin if it is activated
|
||||
*
|
||||
* Check if the given class implements the plugin interface
|
||||
*
|
||||
* @param string $pluginClass
|
||||
* @return Plugin
|
||||
* @return bool
|
||||
*/
|
||||
public function getPlugin($pluginClass) {
|
||||
if ($this->isPluginActive($pluginClass)) {
|
||||
return $this->activePlugins[$pluginClass];
|
||||
public static function isPluginClass($pluginClass) {
|
||||
$pluginClass = self::getClass($pluginClass);
|
||||
if (!class_exists($pluginClass, false)) {
|
||||
return false;
|
||||
}
|
||||
return null;
|
||||
if (!in_array(Plugin::PLUGIN_INTERFACE, class_implements($pluginClass, false))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all declared plugin class names
|
||||
*
|
||||
* @return array
|
||||
* Check if the plugin is running
|
||||
*
|
||||
* @param string $pluginClass
|
||||
* @return bool
|
||||
*/
|
||||
public function getPluginClasses() {
|
||||
return $this->pluginClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all active plugins
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getActivePlugins() {
|
||||
return $this->activePlugins;
|
||||
public function isPluginActive($pluginClass) {
|
||||
$pluginClass = $this->getPluginClass($pluginClass);
|
||||
return isset($this->activePlugins[$pluginClass]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save plugin status in database
|
||||
*
|
||||
*
|
||||
* @param string $className
|
||||
* @param bool $active
|
||||
* @param bool $active
|
||||
* @return bool
|
||||
*/
|
||||
private function savePluginStatus($className, $active) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$pluginStatusQuery = "INSERT INTO `" . self::TABLE_PLUGINS . "` (
|
||||
`className`,
|
||||
`active`
|
||||
@ -311,7 +180,7 @@ class PluginManager {
|
||||
?, ?
|
||||
) ON DUPLICATE KEY UPDATE
|
||||
`active` = VALUES(`active`);";
|
||||
$pluginStatement = $mysqli->prepare($pluginStatusQuery);
|
||||
$pluginStatement = $mysqli->prepare($pluginStatusQuery);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return false;
|
||||
@ -328,17 +197,104 @@ class PluginManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load complete Plugins Directory and start all configured Plugins
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function loadPlugins() {
|
||||
$pluginsDirectory = ManiaControlDir . '/plugins/';
|
||||
|
||||
$classesBefore = get_declared_classes();
|
||||
$this->loadPluginFiles($pluginsDirectory);
|
||||
$classesAfter = get_declared_classes();
|
||||
|
||||
$newPluginClasses = array();
|
||||
|
||||
$newClasses = array_diff($classesAfter, $classesBefore);
|
||||
foreach ($newClasses as $className) {
|
||||
if (!$this->isPluginClass($className)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$this->addPluginClass($className)) {
|
||||
continue;
|
||||
}
|
||||
array_push($newPluginClasses, $className);
|
||||
|
||||
/** @var Plugin $className */
|
||||
$className::prepare($this->maniaControl);
|
||||
|
||||
if ($this->getSavedPluginStatus($className)) {
|
||||
$this->activatePlugin($className);
|
||||
}
|
||||
}
|
||||
|
||||
return $newPluginClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all Plugin Files from the Directory
|
||||
*
|
||||
* @param string $directory
|
||||
*/
|
||||
public function loadPluginFiles($directory = '') {
|
||||
$pluginFiles = scandir($directory);
|
||||
foreach ($pluginFiles as $pluginFile) {
|
||||
if (stripos($pluginFile, '.') === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$filePath = $directory . $pluginFile;
|
||||
if (is_file($filePath)) {
|
||||
if (!stripos($pluginFile, '.php')) {
|
||||
continue;
|
||||
}
|
||||
$success = include_once $filePath;
|
||||
if (!$success) {
|
||||
trigger_error("Error loading File '{$filePath}'!");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
$dirPath = $directory . $pluginFile;
|
||||
if (is_dir($dirPath)) {
|
||||
$this->loadPluginFiles($dirPath . '/');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the class to array of loaded plugin classes
|
||||
*
|
||||
* @param string $pluginClass
|
||||
* @return bool
|
||||
*/
|
||||
public function addPluginClass($pluginClass) {
|
||||
$pluginClass = $this->getPluginClass($pluginClass);
|
||||
if (in_array($pluginClass, $this->pluginClasses)) {
|
||||
return false;
|
||||
}
|
||||
if (!$this->isPluginClass($pluginClass)) {
|
||||
return false;
|
||||
}
|
||||
array_push($this->pluginClasses, $pluginClass);
|
||||
sort($this->pluginClasses);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plugin status from database
|
||||
*
|
||||
*
|
||||
* @param string $className
|
||||
* @return bool
|
||||
*/
|
||||
public function getSavedPluginStatus($className) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$pluginStatusQuery = "SELECT `active` FROM `" . self::TABLE_PLUGINS . "`
|
||||
WHERE `className` = ?;";
|
||||
$pluginStatement = $mysqli->prepare($pluginStatusQuery);
|
||||
$pluginStatement = $mysqli->prepare($pluginStatusQuery);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return false;
|
||||
@ -365,44 +321,85 @@ class PluginManager {
|
||||
return $active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate and start the plugin with the given name
|
||||
*
|
||||
* @param string $pluginClass
|
||||
* @param string $adminLogin
|
||||
* @return bool
|
||||
*/
|
||||
public function activatePlugin($pluginClass, $adminLogin = null) {
|
||||
if (!is_string($pluginClass)) {
|
||||
return false;
|
||||
}
|
||||
if (!$this->isPluginClass($pluginClass)) {
|
||||
return false;
|
||||
}
|
||||
if ($this->isPluginActive($pluginClass)) {
|
||||
return false;
|
||||
}
|
||||
$plugin = new $pluginClass();
|
||||
/**
|
||||
* @var Plugin $plugin
|
||||
*/
|
||||
$this->activePlugins[$pluginClass] = $plugin;
|
||||
$this->savePluginStatus($pluginClass, true);
|
||||
try {
|
||||
$plugin->load($this->maniaControl);
|
||||
} catch (\Exception $e) {
|
||||
$this->maniaControl->chat->sendError('Error while plugin activating ' . $pluginClass . ': ' . $e->getMessage(), $adminLogin);
|
||||
$this->maniaControl->log('Error while plugin activation: ' . $pluginClass . ': ' . $e->getMessage());
|
||||
unset($this->activePlugins[$pluginClass]);
|
||||
$this->savePluginStatus($pluginClass, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->savePluginStatus($pluginClass, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Plugin if it is activated
|
||||
*
|
||||
* @param string $pluginClass
|
||||
* @return Plugin
|
||||
*/
|
||||
public function getPlugin($pluginClass) {
|
||||
if ($this->isPluginActive($pluginClass)) {
|
||||
return $this->activePlugins[$pluginClass];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all declared plugin class names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPluginClasses() {
|
||||
return $this->pluginClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all active plugins
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getActivePlugins() {
|
||||
return $this->activePlugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the Plugins List from the ManiaControl Website
|
||||
*
|
||||
*
|
||||
* @param $function
|
||||
*/
|
||||
public function fetchPluginList($function) {
|
||||
$url = ManiaControl::URL_WEBSERVICE . 'plugins';
|
||||
|
||||
$this->maniaControl->fileReader->loadFile($url, function ($dataJson, $error) use(&$function) {
|
||||
|
||||
$this->maniaControl->fileReader->loadFile($url, function ($dataJson, $error) use (&$function) {
|
||||
$data = json_decode($dataJson);
|
||||
call_user_func($function, $data, $error);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Class of the Plugin
|
||||
*
|
||||
* @param mixed $pluginClass
|
||||
* @return string
|
||||
*/
|
||||
public static function getPluginClass($pluginClass) {
|
||||
$pluginClass = self::getClass($pluginClass);
|
||||
if (!self::isPluginClass($pluginClass)) {
|
||||
return false;
|
||||
}
|
||||
return $pluginClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Class of the Object
|
||||
*
|
||||
* @param mixed $object
|
||||
* @return string
|
||||
*/
|
||||
private static function getClass($object) {
|
||||
if (is_object($object)) {
|
||||
return get_class($object);
|
||||
}
|
||||
return (string) $object;
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ use FML\Controls\Frame;
|
||||
use FML\Controls\Label;
|
||||
use FML\Controls\Labels\Label_Button;
|
||||
use FML\Controls\Labels\Label_Text;
|
||||
use FML\Controls\Quads\Quad_Icons128x32_1;
|
||||
use FML\Controls\Quads\Quad_Icons128x128_1;
|
||||
use FML\Controls\Quads\Quad_Icons128x32_1;
|
||||
use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||
use FML\Script\Features\Paging;
|
||||
use FML\Script\Script;
|
||||
@ -25,9 +25,9 @@ use ManiaControl\Players\Player;
|
||||
/**
|
||||
* Configurator for enabling and disabling Plugins
|
||||
*
|
||||
* @author ManiaControl Team
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAnswerListener {
|
||||
/*
|
||||
@ -62,13 +62,6 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
|
||||
*/
|
||||
public function getTitle() {
|
||||
return 'Plugins';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Back to the Plugins
|
||||
*/
|
||||
@ -78,13 +71,20 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
$this->maniaControl->configurator->reopenMenu($player, $menuId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
|
||||
*/
|
||||
public function getTitle() {
|
||||
return 'Plugins';
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
||||
*/
|
||||
public function getMenu($width, $height, Script $script, Player $player) {
|
||||
$paging = new Paging();
|
||||
$script->addFeature($paging);
|
||||
$frame = new Frame();
|
||||
$paging = new Paging();
|
||||
$script->addFeature($paging);
|
||||
$frame = new Frame();
|
||||
|
||||
$pluginClasses = $this->maniaControl->pluginManager->getPluginClasses();
|
||||
|
||||
@ -107,8 +107,8 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
$pagerNext->setSize($pagerSize, $pagerSize);
|
||||
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
|
||||
|
||||
$paging->addButton($pagerNext);
|
||||
$paging->addButton($pagerPrev);
|
||||
$paging->addButton($pagerNext);
|
||||
$paging->addButton($pagerPrev);
|
||||
|
||||
$pageCountLabel = new Label_Text();
|
||||
$frame->add($pageCountLabel);
|
||||
@ -117,7 +117,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
|
||||
$pageCountLabel->setTextSize(2);
|
||||
|
||||
$paging->setLabel($pageCountLabel);
|
||||
$paging->setLabel($pageCountLabel);
|
||||
|
||||
//Show Settings Menu
|
||||
if ($this->settingsClass != '') { //TODO improve
|
||||
@ -128,7 +128,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
$y = 0;
|
||||
$index = 1;
|
||||
$settingHeight = 5.;
|
||||
foreach($settings as $setting) {
|
||||
foreach ($settings as $setting) {
|
||||
if (!isset($pageFrame)) {
|
||||
$pageFrame = new Frame();
|
||||
$frame->add($pageFrame);
|
||||
@ -137,7 +137,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
}
|
||||
array_push($pageFrames, $pageFrame);
|
||||
$y = $height * 0.41;
|
||||
$paging->addPage($pageFrame);
|
||||
$paging->addPage($pageFrame);
|
||||
}
|
||||
|
||||
$settingFrame = new Frame();
|
||||
@ -166,7 +166,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
}
|
||||
array_push($pageFrames, $pageFrame);
|
||||
$y = $height * 0.41;
|
||||
$paging->addPage($pageFrame);
|
||||
$paging->addPage($pageFrame);
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,11 +244,11 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
$y = 0.;
|
||||
$pluginUpdates = $this->maniaControl->updateManager->pluginUpdateManager->getPluginsUpdates();
|
||||
|
||||
usort($pluginClasses, function($a, $b) {
|
||||
usort($pluginClasses, function ($a, $b) {
|
||||
return strcmp($a::getName(), $b::getName());
|
||||
});
|
||||
|
||||
foreach($pluginClasses as $index => $pluginClass) {
|
||||
foreach ($pluginClasses as $index => $pluginClass) {
|
||||
/** @var Plugin $pluginClass */
|
||||
if (!isset($pageFrame)) {
|
||||
$pageFrame = new Frame();
|
||||
@ -258,7 +258,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
}
|
||||
|
||||
array_push($pageFrames, $pageFrame);
|
||||
$paging->addPage($pageFrame);
|
||||
$paging->addPage($pageFrame);
|
||||
$y = $height * 0.41;
|
||||
}
|
||||
|
||||
@ -299,7 +299,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
$descriptionLabel->setMaxLines(5);
|
||||
$description = "Author: {$pluginClass::getAuthor()}\nVersion: {$pluginClass::getVersion()}\nDesc: {$pluginClass::getDescription()}";
|
||||
$descriptionLabel->setText($description);
|
||||
$nameLabel->addTooltipFeature($descriptionLabel);
|
||||
$nameLabel->addTooltipFeature($descriptionLabel);
|
||||
|
||||
$quad = new Quad_Icons128x32_1();
|
||||
$pluginFrame->add($quad);
|
||||
@ -340,7 +340,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
}
|
||||
}
|
||||
|
||||
if($pluginUpdates != false) {
|
||||
if ($pluginUpdates != false) {
|
||||
$updatePluginsButton = new Label_Button();
|
||||
$frame->add($updatePluginsButton);
|
||||
$updatePluginsButton->setHAlign(Control::RIGHT);
|
||||
@ -349,48 +349,13 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
$updatePluginsButton->setZ(2);
|
||||
$updatePluginsButton->setWidth(10);
|
||||
$updatePluginsButton->setStyle($updatePluginsButton::STYLE_CardButtonSmallS);
|
||||
$updatePluginsButton->setText(count($pluginUpdates).' update(s)');
|
||||
$updatePluginsButton->setText(count($pluginUpdates) . ' update(s)');
|
||||
$updatePluginsButton->setAction(self::ACTION_UPDATEPLUGINS);
|
||||
}
|
||||
|
||||
return $frame;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
|
||||
*/
|
||||
public function saveConfigData(array $configData, Player $player) {
|
||||
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$maniaControlSettings = $this->maniaControl->settingManager->getSettings();
|
||||
|
||||
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
||||
|
||||
foreach($configData[3] as $setting) {
|
||||
$settingName = substr($setting['Name'], $prefixLength + 1);
|
||||
|
||||
if(!isset($maniaControlSettings[$settingName]))
|
||||
continue;
|
||||
|
||||
$oldSetting = $maniaControlSettings[$settingName];
|
||||
if ($setting['Value'] == $oldSetting->value || $oldSetting->type == 'bool') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, $setting['Value']);
|
||||
}
|
||||
|
||||
//Reopen the Menu
|
||||
$menuId = $this->maniaControl->configurator->getMenuId($this->getTitle());
|
||||
$this->maniaControl->configurator->reopenMenu($player, $menuId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PlayerManialinkPageAnswer callback
|
||||
*
|
||||
@ -456,7 +421,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles a Boolean Value
|
||||
* Toggle a Boolean Value
|
||||
*
|
||||
* @param $setting
|
||||
* @param Player $player
|
||||
@ -481,4 +446,40 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, "1");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
|
||||
*/
|
||||
public function saveConfigData(array $configData, Player $player) {
|
||||
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$maniaControlSettings = $this->maniaControl->settingManager->getSettings();
|
||||
|
||||
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
||||
|
||||
foreach ($configData[3] as $setting) {
|
||||
$settingName = substr($setting['Name'], $prefixLength + 1);
|
||||
|
||||
if (!isset($maniaControlSettings[$settingName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$oldSetting = $maniaControlSettings[$settingName];
|
||||
if ($setting['Value'] == $oldSetting->value || $oldSetting->type == 'bool') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, $setting['Value']);
|
||||
}
|
||||
|
||||
//Reopen the Menu
|
||||
$menuId = $this->maniaControl->configurator->getMenuId($this->getTitle());
|
||||
$this->maniaControl->configurator->reopenMenu($player, $menuId);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user