coding style fixes

This commit is contained in:
Abdulrahman
2019-05-03 23:52:08 +03:00
parent 87c5631b40
commit f142da94f3
62 changed files with 12149 additions and 11750 deletions

View File

@@ -7,13 +7,13 @@
*
*/
//no for directly open
if (!defined('IN_COMMON'))
if (! defined('IN_COMMON'))
{
exit();
}
# We are in the plugin system, plugins files won't work outside here
// We are in the plugin system, plugins files won't work outside here
define('IN_PLUGINS_SYSTEM', true);
@@ -26,14 +26,14 @@ class Plugins
/**
* List of loaded plugins
*/
private $plugins = array();
private $plugins = [];
/**
* All hooks from all plugins listed in this variable
*/
private $all_plugins_hooks = array();
private $installed_plugins = array();
private $installed_plugins_info = array();
private $all_plugins_hooks = [];
private $installed_plugins = [];
private $installed_plugins_info = [];
private $plugin_path = '';
@@ -48,7 +48,7 @@ class Plugins
{
global $SQL, $dbprefix;
#if plugins system is turned off, then stop right now!
//if plugins system is turned off, then stop right now!
if (defined('STOP_PLUGINS'))
{
return;
@@ -57,12 +57,12 @@ class Plugins
$this->plugin_path = PATH . KLEEJA_PLUGINS_FOLDER;
# Get installed plugins
$query = array(
'SELECT' => "plg_name, plg_ver",
'FROM' => "{$dbprefix}plugins",
'WHERE' => "plg_disabled = 0"
);
// Get installed plugins
$query = [
'SELECT' => 'plg_name, plg_ver',
'FROM' => "{$dbprefix}plugins",
'WHERE' => 'plg_disabled = 0'
];
$result = $SQL->build($query);
@@ -88,8 +88,7 @@ class Plugins
{
if (is_dir($this->plugin_path . '/' . $folder_name) && preg_match('/[a-z0-9_.]{3,}/', $folder_name))
{
if (!empty($this->installed_plugins[$folder_name]))
if (! empty($this->installed_plugins[$folder_name]))
{
if ($this->fetch_plugin($folder_name))
{
@@ -99,18 +98,18 @@ class Plugins
}
}
#sort the plugins from high to low priority
//sort the plugins from high to low priority
krsort($this->plugins);
}
/**
* Get the plugin information and other things
* @param string $plugin_name
* @param string $plugin_name
* @return bool
*/
private function fetch_plugin($plugin_name)
{
#load the plugin
//load the plugin
@include_once $this->plugin_path . '/' . $plugin_name . '/init.php';
if (empty($kleeja_plugin))
@@ -118,45 +117,47 @@ class Plugins
return false;
}
$priority = $kleeja_plugin[$plugin_name]['information']['plugin_priority'];
$priority = $kleeja_plugin[$plugin_name]['information']['plugin_priority'];
$this->installed_plugins_info[$plugin_name] = $kleeja_plugin[$plugin_name]['information'];
#bring the real priority of plugin and replace current one
//bring the real priority of plugin and replace current one
$plugin_current_priority = array_search($plugin_name, $this->plugins);
unset($this->plugins[$plugin_current_priority]);
$this->plugins[$priority] = $plugin_name;
//update plugin if current loaded version is > than installed one
if ($this->installed_plugins[$plugin_name])
{
if (version_compare($this->installed_plugins[$plugin_name], $kleeja_plugin[$plugin_name]['information']['plugin_version'], '<'))
{
if (is_callable($kleeja_plugin[$plugin_name]['update']))
{
global $SQL, $dbprefix;
#update plugin
//update plugin
$kleeja_plugin[$plugin_name]['update']($this->installed_plugins[$plugin_name], $kleeja_plugin[$plugin_name]['information']['plugin_version']);
#update current plugin version
$update_query = array(
//update current plugin version
$update_query = [
'UPDATE' => "{$dbprefix}plugins",
'SET' => "plg_ver='" . $SQL->escape($kleeja_plugin[$plugin_name]['information']['plugin_version']) . "'",
'WHERE' => "plg_name='" . $SQL->escape($plugin_name) . "'"
);
'SET' => "plg_ver='" . $SQL->escape($kleeja_plugin[$plugin_name]['information']['plugin_version']) . "'",
'WHERE' => "plg_name='" . $SQL->escape($plugin_name) . "'"
];
$SQL->build($update_query);
}
}
}
#add plugin hooks to global hooks, depend on its priority
if (!empty($kleeja_plugin[$plugin_name]['functions']))
//add plugin hooks to global hooks, depend on its priority
if (! empty($kleeja_plugin[$plugin_name]['functions']))
{
foreach ($kleeja_plugin[$plugin_name]['functions'] as $hook_name => $hook_value)
{
if (empty($this->all_plugins_hooks[$hook_name][$priority]))
{
$this->all_plugins_hooks[$hook_name][$priority] = array();
$this->all_plugins_hooks[$hook_name][$priority] = [];
}
array_push($this->all_plugins_hooks[$hook_name][$priority], $hook_value);
krsort($this->all_plugins_hooks[$hook_name]);
@@ -169,12 +170,12 @@ class Plugins
/**
* get an installed plugin information
* @param string $plugin_name
* @param string $plugin_name
* @return mixed|null
*/
public function installed_plugin_info($plugin_name)
{
if (!empty($this->installed_plugins_info[$plugin_name]))
if (! empty($this->installed_plugins_info[$plugin_name]))
{
return $this->installed_plugins_info[$plugin_name];
}
@@ -186,15 +187,15 @@ class Plugins
/**
* Bring all codes of this hook
* This function scattered all over kleeja files
* @param string $hook_name
* @param array $args
* @param string $hook_name
* @param array $args
* @return array|null
*/
public function run($hook_name, $args = array())
public function run($hook_name, $args = [])
{
$return_value = $to_be_returned = array();
$return_value = $to_be_returned = [];
if (!empty($this->all_plugins_hooks[$hook_name]))
if (! empty($this->all_plugins_hooks[$hook_name]))
{
foreach ($this->all_plugins_hooks[$hook_name] as $order => $functions)
{
@@ -204,9 +205,9 @@ class Plugins
{
$return_value = $function($args);
if(is_array($return_value))
if (is_array($return_value))
{
$args = array_merge($args, $return_value);
$args = array_merge($args, $return_value);
$to_be_returned = array_merge($to_be_returned, $return_value);
}
}
@@ -234,15 +235,16 @@ class Plugins
* return debug info about plugins system
* @return array
*/
public function getDebugInfo(){
if(!defined('DEV_STAGE'))
public function getDebugInfo()
{
if (! defined('DEV_STAGE'))
{
return array();
return [];
}
return array(
return [
'all_plugins_hooks' => $this->all_plugins_hooks,
'installed_plugins' => $this->installed_plugins,
);
];
}
}