mirror of
https://github.com/kleeja-official/kleeja.git
synced 2026-05-07 11:35:26 +02:00
coding style fixes
This commit is contained in:
@@ -9,49 +9,51 @@
|
||||
|
||||
|
||||
// not for directly open
|
||||
if (!defined('IN_ADMIN'))
|
||||
if (! defined('IN_ADMIN'))
|
||||
{
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
#turn time-limit off
|
||||
//turn time-limit off
|
||||
@set_time_limit(0);
|
||||
|
||||
|
||||
#get current case
|
||||
//get current case
|
||||
$case = g('case', 'str', 'installed');
|
||||
|
||||
#set _get form key
|
||||
//set _get form key
|
||||
$GET_FORM_KEY = kleeja_add_form_key_get('PLUGINS_FORM_KEY');
|
||||
$H_FORM_KEYS = kleeja_add_form_key('adm_plugins');
|
||||
$H_FORM_KEYS = kleeja_add_form_key('adm_plugins');
|
||||
|
||||
$action = ADMIN_PATH . '?cp=' . basename(__file__, '.php');
|
||||
|
||||
$plugin_install_link = ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=install&' . $GET_FORM_KEY . '&plg=';
|
||||
$plugin_install_link = ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=install&' . $GET_FORM_KEY . '&plg=';
|
||||
$plugin_uninstall_link = ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=uninstall&' . $GET_FORM_KEY . '&plg=';
|
||||
$plugin_enable_link = ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=enable&' . $GET_FORM_KEY . '&plg=';
|
||||
$plugin_disable_link = ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=disable&' . $GET_FORM_KEY . '&plg=';
|
||||
$plugin_download_link = ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=download&' . $GET_FORM_KEY . '&plg=';
|
||||
$plugin_update_link = ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=update&' . $GET_FORM_KEY . '&plg=';
|
||||
$plugin_enable_link = ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=enable&' . $GET_FORM_KEY . '&plg=';
|
||||
$plugin_disable_link = ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=disable&' . $GET_FORM_KEY . '&plg=';
|
||||
$plugin_download_link = ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=download&' . $GET_FORM_KEY . '&plg=';
|
||||
$plugin_update_link = ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=update&' . $GET_FORM_KEY . '&plg=';
|
||||
|
||||
|
||||
//check _GET Csrf token
|
||||
if (!empty($case) && in_array($case, array('install', 'uninstall', 'enable', 'disable' , 'download' , 'update')))
|
||||
if (! empty($case) && in_array($case, ['install', 'uninstall', 'enable', 'disable' , 'download' , 'update']))
|
||||
{
|
||||
if (!kleeja_check_form_key_get('PLUGINS_FORM_KEY'))
|
||||
if (! kleeja_check_form_key_get('PLUGINS_FORM_KEY'))
|
||||
{
|
||||
kleeja_admin_err($lang['INVALID_GET_KEY'], $action);
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(ip('newplugin'))
|
||||
if (ip('newplugin'))
|
||||
{
|
||||
if(!kleeja_check_form_key('adm_plugins'))
|
||||
if (! kleeja_check_form_key('adm_plugins'))
|
||||
{
|
||||
kleeja_admin_err($lang['INVALID_FORM_KEY'], true, $lang['ERROR'], true, $action);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -65,43 +67,42 @@ switch ($case):
|
||||
case 'store':
|
||||
case 'check':
|
||||
|
||||
# Get installed plugins
|
||||
$query = array(
|
||||
'SELECT' => "plg_id, plg_name, plg_ver, plg_disabled, plg_author, plg_dsc",
|
||||
'FROM' => "{$dbprefix}plugins",
|
||||
'ORDER BY' => "plg_id ASC",
|
||||
);
|
||||
// Get installed plugins
|
||||
$query = [
|
||||
'SELECT' => 'plg_id, plg_name, plg_ver, plg_disabled, plg_author, plg_dsc',
|
||||
'FROM' => "{$dbprefix}plugins",
|
||||
'ORDER BY' => 'plg_id ASC',
|
||||
];
|
||||
|
||||
|
||||
$result = $SQL->build($query);
|
||||
|
||||
$installed_plugins = array();
|
||||
$installed_plugins = [];
|
||||
|
||||
while ($row = $SQL->fetch($result))
|
||||
{
|
||||
|
||||
$installed_plugins[$row['plg_name']] = $row;
|
||||
|
||||
$installed_plugins[$row['plg_name']]['extra_info'] = Plugins::getInstance()->installed_plugin_info($row['plg_name']);
|
||||
|
||||
|
||||
$installed_plugins[$row['plg_name']]['icon'] = file_exists(
|
||||
PATH . KLEEJA_PLUGINS_FOLDER . '/' . $row['plg_name'] . "/icon.png"
|
||||
PATH . KLEEJA_PLUGINS_FOLDER . '/' . $row['plg_name'] . '/icon.png'
|
||||
)
|
||||
? PATH . KLEEJA_PLUGINS_FOLDER . '/' . $row['plg_name'] . "/icon.png"
|
||||
? PATH . KLEEJA_PLUGINS_FOLDER . '/' . $row['plg_name'] . '/icon.png'
|
||||
: $STYLE_PATH_ADMIN . 'images/plugin.png';
|
||||
|
||||
|
||||
foreach (array('plugin_title', 'plugin_description') as $localizedInfo)
|
||||
foreach (['plugin_title', 'plugin_description'] as $localizedInfo)
|
||||
{
|
||||
if (is_array($installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo]))
|
||||
{
|
||||
if (!empty($installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo][$config['language']]))
|
||||
if (! empty($installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo][$config['language']]))
|
||||
{
|
||||
$installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo] =
|
||||
shorten_text($installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo][$config['language']], 100);
|
||||
}
|
||||
else if (!empty($installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo]['en']))
|
||||
elseif (! empty($installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo]['en']))
|
||||
{
|
||||
$installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo] =
|
||||
shorten_text($installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo]['en'], 100);
|
||||
@@ -117,23 +118,23 @@ switch ($case):
|
||||
$SQL->free($result);
|
||||
|
||||
|
||||
#get available plugins
|
||||
$dh = opendir(PATH . KLEEJA_PLUGINS_FOLDER);
|
||||
$available_plugins = array();
|
||||
//get available plugins
|
||||
$dh = opendir(PATH . KLEEJA_PLUGINS_FOLDER);
|
||||
$available_plugins = [];
|
||||
while (false !== ($folder_name = readdir($dh)))
|
||||
{
|
||||
if (is_dir(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $folder_name) && preg_match('/[a-z0-9_.]{3,}/', $folder_name))
|
||||
if (is_dir(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $folder_name) && preg_match('/[a-z0-9_.]{3,}/', $folder_name))
|
||||
{
|
||||
if (empty($installed_plugins[$folder_name]))
|
||||
{
|
||||
array_push($available_plugins,
|
||||
array(
|
||||
[
|
||||
'name' => $folder_name,
|
||||
'icon' => file_exists(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $folder_name . "/icon.png")
|
||||
? PATH . KLEEJA_PLUGINS_FOLDER . '/' . $folder_name . "/icon.png"
|
||||
'icon' => file_exists(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $folder_name . '/icon.png')
|
||||
? PATH . KLEEJA_PLUGINS_FOLDER . '/' . $folder_name . '/icon.png'
|
||||
: $STYLE_PATH_ADMIN . 'images/plugin.png',
|
||||
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -142,23 +143,23 @@ switch ($case):
|
||||
|
||||
$no_plugins = sizeof($available_plugins) == 0 && sizeof($installed_plugins) == 0;
|
||||
|
||||
$stylee = "admin_plugins";
|
||||
$stylee = 'admin_plugins';
|
||||
|
||||
//do not proceed if not store case
|
||||
if(! in_array($case, ['store', 'check']))
|
||||
if (! in_array($case, ['store', 'check']))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// plugins avilable in kleeja remote catalog
|
||||
if (!($catalog_plugins = $cache->get('catalog_plugins')))
|
||||
if (! ($catalog_plugins = $cache->get('catalog_plugins')))
|
||||
{
|
||||
$store_link = 'https://raw.githubusercontent.com/kleeja-official/store-catalog/master/catalog.json';
|
||||
|
||||
$catalog_plugins = fetch_remote_file($store_link);
|
||||
$catalog_plugins = json_decode($catalog_plugins , true);
|
||||
$catalog_plugins = json_decode($catalog_plugins, true);
|
||||
|
||||
if(json_last_error() == JSON_ERROR_NONE)
|
||||
if (json_last_error() == JSON_ERROR_NONE)
|
||||
{
|
||||
$cache->save('catalog_plugins', $catalog_plugins);
|
||||
}
|
||||
@@ -166,14 +167,14 @@ switch ($case):
|
||||
|
||||
// make an array for all plugins in kleeja remote catalog
|
||||
// that are not exsisted locally.
|
||||
$store_plugins = array();
|
||||
$store_plugins = [];
|
||||
$available_plugins_names = array_column($available_plugins, 'name');
|
||||
foreach ($catalog_plugins as $plugin_info)
|
||||
|
||||
foreach ($catalog_plugins as $plugin_info)
|
||||
{
|
||||
if ($case == 'store' && (in_array($plugin_info['name'] , $available_plugins_names) ||
|
||||
if ($case == 'store' && (in_array($plugin_info['name'], $available_plugins_names) ||
|
||||
! empty($installed_plugins[$plugin_info['name']]) )
|
||||
)
|
||||
{
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -183,25 +184,25 @@ switch ($case):
|
||||
strtolower($installed_plugins[$plugin_info['name']]['extra_info']['plugin_version']),
|
||||
strtolower($plugin_info['file']['version']),
|
||||
'>=') || empty($installed_plugins[$plugin_info['name']]))
|
||||
) {
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$store_plugins[$plugin_info['name']] = array(
|
||||
'name' => $plugin_info['name'],
|
||||
'developer' => $plugin_info['developer'],
|
||||
'version' => $plugin_info['file']['version'],
|
||||
'title' => ! empty($plugin_info['title'][$config['language']]) ? $plugin_info['title'][$config['language']] : $plugin_info['title']['en'],
|
||||
'website' => $plugin_info['website'],
|
||||
'current_version' => ! empty($installed_plugins[$plugin_info['name']]) ? strtolower($installed_plugins[$plugin_info['name']]['extra_info']['plugin_version']) : '',
|
||||
'kj_min_version' => $plugin_info['kleeja_version']['min'],
|
||||
'kj_max_version' => $plugin_info['kleeja_version']['max'],
|
||||
$store_plugins[$plugin_info['name']] = [
|
||||
'name' => $plugin_info['name'],
|
||||
'developer' => $plugin_info['developer'],
|
||||
'version' => $plugin_info['file']['version'],
|
||||
'title' => ! empty($plugin_info['title'][$config['language']]) ? $plugin_info['title'][$config['language']] : $plugin_info['title']['en'],
|
||||
'website' => $plugin_info['website'],
|
||||
'current_version' => ! empty($installed_plugins[$plugin_info['name']]) ? strtolower($installed_plugins[$plugin_info['name']]['extra_info']['plugin_version']) : '',
|
||||
'kj_min_version' => $plugin_info['kleeja_version']['min'],
|
||||
'kj_max_version' => $plugin_info['kleeja_version']['max'],
|
||||
'kj_version_cmtp' => sprintf($lang[ 'KLJ_VER_NO_PLUGIN'], $plugin_info['kleeja_version']['min'], $plugin_info['kleeja_version']['max']),
|
||||
'icon' => $plugin_info['icon'] ,
|
||||
'NotCompatible' => version_compare(strtolower($plugin_info['kleeja_version']['min']), KLEEJA_VERSION , '<=')
|
||||
&& version_compare(strtolower($plugin_info['kleeja_version']['max']), KLEEJA_VERSION , '>=')
|
||||
? false : true,
|
||||
);
|
||||
'icon' => $plugin_info['icon'] ,
|
||||
'NotCompatible' => version_compare(strtolower($plugin_info['kleeja_version']['min']), KLEEJA_VERSION, '<=')
|
||||
&& version_compare(strtolower($plugin_info['kleeja_version']['max']), KLEEJA_VERSION, '>=')
|
||||
? false : true,
|
||||
];
|
||||
}
|
||||
|
||||
$no_store_plugins = sizeof($store_plugins) == 0;
|
||||
@@ -212,28 +213,29 @@ switch ($case):
|
||||
//upload a plugin
|
||||
//
|
||||
case 'upload':
|
||||
$ERRORS = array();
|
||||
$ERRORS = [];
|
||||
|
||||
if(intval($userinfo['founder']) !== 1)
|
||||
if (intval($userinfo['founder']) !== 1)
|
||||
{
|
||||
$ERRORS[] = $lang['HV_NOT_PRVLG_ACCESS'];
|
||||
}
|
||||
|
||||
#is uploaded?
|
||||
if(empty($_FILES['plugin_file']['tmp_name']))
|
||||
//is uploaded?
|
||||
if (empty($_FILES['plugin_file']['tmp_name']))
|
||||
{
|
||||
$ERRORS[] = $lang['CHOSE_F'];
|
||||
}
|
||||
|
||||
#extract it to plugins folder
|
||||
if(!sizeof($ERRORS))
|
||||
//extract it to plugins folder
|
||||
if (! sizeof($ERRORS))
|
||||
{
|
||||
if(class_exists('ZipArchive'))
|
||||
if (class_exists('ZipArchive'))
|
||||
{
|
||||
$zip = new ZipArchive;
|
||||
|
||||
if ($zip->open($_FILES['plugin_file']['tmp_name']) === true)
|
||||
{
|
||||
if(!$zip->extractTo(PATH . KLEEJA_PLUGINS_FOLDER))
|
||||
if (! $zip->extractTo(PATH . KLEEJA_PLUGINS_FOLDER))
|
||||
{
|
||||
$ERRORS[] = sprintf($lang['EXTRACT_ZIP_FAILED'], KLEEJA_PLUGINS_FOLDER);
|
||||
}
|
||||
@@ -250,12 +252,12 @@ switch ($case):
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($_FILES['plugin_file']['tmp_name']))
|
||||
if (! empty($_FILES['plugin_file']['tmp_name']))
|
||||
{
|
||||
@unlink($_FILES['plugin_file']['tmp_name']);
|
||||
}
|
||||
|
||||
if(!sizeof($ERRORS))
|
||||
if (! sizeof($ERRORS))
|
||||
{
|
||||
kleeja_admin_info($lang['NO_PROBLEM_AFTER_ZIP'], true, '', true, $action);
|
||||
}
|
||||
@@ -272,9 +274,10 @@ switch ($case):
|
||||
//
|
||||
case 'install':
|
||||
|
||||
if(intval($userinfo['founder']) !== 1)
|
||||
if (intval($userinfo['founder']) !== 1)
|
||||
{
|
||||
kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS'], ADMIN_PATH . '?cp=' . basename(__file__, '.php'));
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -287,56 +290,59 @@ switch ($case):
|
||||
exit('empty($plg_name)');
|
||||
}
|
||||
//no plugin selected? back
|
||||
redirect(ADMIN_PATH . "?cp=" . basename(__file__, '.php'));
|
||||
redirect(ADMIN_PATH . '?cp=' . basename(__file__, '.php'));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!file_exists(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plg_name . '/init.php'))
|
||||
if (! file_exists(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plg_name . '/init.php'))
|
||||
{
|
||||
if (defined('DEBUG'))
|
||||
{
|
||||
exit('!file_exists($plg_name)');
|
||||
}
|
||||
|
||||
redirect(ADMIN_PATH . "?cp=" . basename(__file__, '.php'));
|
||||
redirect(ADMIN_PATH . '?cp=' . basename(__file__, '.php'));
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
#if already installed, show a message
|
||||
if (!empty(Plugins::getInstance()->installed_plugin_info($plg_name)))
|
||||
//if already installed, show a message
|
||||
if (! empty(Plugins::getInstance()->installed_plugin_info($plg_name)))
|
||||
{
|
||||
kleeja_admin_info($lang['PLUGIN_EXISTS_BEFORE'], true, '', true, ADMIN_PATH . '?cp=' . basename(__file__, '.php'));
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$kleeja_plugin = array();
|
||||
$kleeja_plugin = [];
|
||||
|
||||
include PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plg_name . '/init.php';
|
||||
|
||||
$install_callback = $kleeja_plugin[$plg_name]['install'];
|
||||
$plugin_info = $kleeja_plugin[$plg_name]['information'];
|
||||
$plugin_info = $kleeja_plugin[$plg_name]['information'];
|
||||
$plugin_first_run = false;
|
||||
|
||||
if (!empty($kleeja_plugin[$plg_name]['first_run'][$config['language']]))
|
||||
if (! empty($kleeja_plugin[$plg_name]['first_run'][$config['language']]))
|
||||
{
|
||||
$plugin_first_run = $kleeja_plugin[$plg_name]['first_run'][$config['language']];
|
||||
}
|
||||
else if (!empty($kleeja_plugin[$plg_name]['first_run']['en']))
|
||||
elseif (! empty($kleeja_plugin[$plg_name]['first_run']['en']))
|
||||
{
|
||||
$plugin_first_run = $kleeja_plugin[$plg_name]['first_run']['en'];
|
||||
}
|
||||
|
||||
#check if compatible with kleeja
|
||||
#'plugin_kleeja_version_min' => '1.8',
|
||||
# Max version of Kleeja that's required to run this plugin
|
||||
#'plugin_kleeja_version_max' => '3.8',
|
||||
//check if compatible with kleeja
|
||||
//'plugin_kleeja_version_min' => '1.8',
|
||||
// Max version of Kleeja that's required to run this plugin
|
||||
//'plugin_kleeja_version_max' => '3.8',
|
||||
|
||||
if (version_compare(KLEEJA_VERSION, $plugin_info['plugin_kleeja_version_min'], '<'))
|
||||
{
|
||||
kleeja_admin_info(
|
||||
$lang['PLUGIN_N_CMPT_KLJ'] . '<br>k:' . KLEEJA_VERSION . '|<|p.min:' . $plugin_info['plugin_kleeja_version_min'],
|
||||
$lang['PLUGIN_N_CMPT_KLJ'] . '<br>k:' . KLEEJA_VERSION . '|<|p.min:' . $plugin_info['plugin_kleeja_version_min'],
|
||||
true, '', true, ADMIN_PATH . '?cp=' . basename(__file__, '.php')
|
||||
);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -345,9 +351,10 @@ switch ($case):
|
||||
if (version_compare(KLEEJA_VERSION, $plugin_info['plugin_kleeja_version_max'], '>'))
|
||||
{
|
||||
kleeja_admin_info(
|
||||
$lang['PLUGIN_N_CMPT_KLJ'] . '<br>k:' . KLEEJA_VERSION . '|>|p.max:' . $plugin_info['plugin_kleeja_version_max'],
|
||||
$lang['PLUGIN_N_CMPT_KLJ'] . '<br>k:' . KLEEJA_VERSION . '|>|p.max:' . $plugin_info['plugin_kleeja_version_max'],
|
||||
true, '', true, ADMIN_PATH . '?cp=' . basename(__file__, '.php')
|
||||
);
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -356,26 +363,27 @@ switch ($case):
|
||||
|
||||
if (is_array($plugin_info['plugin_description']))
|
||||
{
|
||||
$plugin_info['plugin_description'] = !empty($plugin_info['plugin_description']['en']) ? $plugin_info['plugin_description']['en'] : $plugin_info['plugin_description'][0];
|
||||
$plugin_info['plugin_description'] = ! empty($plugin_info['plugin_description']['en']) ? $plugin_info['plugin_description']['en'] : $plugin_info['plugin_description'][0];
|
||||
}
|
||||
|
||||
#add to database
|
||||
$insert_query = array(
|
||||
//add to database
|
||||
$insert_query = [
|
||||
'INSERT' => '`plg_name` ,`plg_ver`, `plg_author`, `plg_dsc`, `plg_icon`, `plg_uninstall`, `plg_instructions`, `plg_store`, `plg_files`',
|
||||
'INTO' => "{$dbprefix}plugins",
|
||||
'INTO' => "{$dbprefix}plugins",
|
||||
'VALUES' => "'" . $SQL->escape($plg_name) . "','" . $SQL->escape($plugin_info['plugin_version']) . "', '" . $SQL->escape($plugin_info['plugin_developer']) . "','" . $SQL->escape($plugin_info['plugin_description']) . "', '', '', '', '', ''",
|
||||
);
|
||||
];
|
||||
|
||||
$SQL->build($insert_query);
|
||||
|
||||
#may God protect you brother.
|
||||
if(is_callable($install_callback))
|
||||
//may God protect you brother.
|
||||
if (is_callable($install_callback))
|
||||
{
|
||||
$install_callback($SQL->insert_id());
|
||||
}
|
||||
|
||||
#show done, msg
|
||||
//show done, msg
|
||||
$text = '<h3>' . $lang['NEW_PLUGIN_ADDED'] . '</h3>';
|
||||
|
||||
if ($plugin_first_run)
|
||||
{
|
||||
$text .= $plugin_first_run;
|
||||
@@ -397,9 +405,10 @@ switch ($case):
|
||||
//
|
||||
case 'uninstall':
|
||||
|
||||
if(intval($userinfo['founder']) !== 1)
|
||||
if (intval($userinfo['founder']) !== 1)
|
||||
{
|
||||
kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS'], ADMIN_PATH . '?cp=' . basename(__file__, '.php'));
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -413,58 +422,60 @@ switch ($case):
|
||||
}
|
||||
|
||||
//no plugin selected? back
|
||||
redirect(ADMIN_PATH . "?cp=" . basename(__file__, '.php'));
|
||||
redirect(ADMIN_PATH . '?cp=' . basename(__file__, '.php'));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!file_exists(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plg_name . '/init.php'))
|
||||
if (! file_exists(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plg_name . '/init.php'))
|
||||
{
|
||||
if (defined('DEV_STAGE'))
|
||||
{
|
||||
exit('!file_exists($plg_name)');
|
||||
}
|
||||
|
||||
redirect(ADMIN_PATH . "?cp=" . basename(__file__, '.php'));
|
||||
redirect(ADMIN_PATH . '?cp=' . basename(__file__, '.php'));
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$kleeja_plugin = array();
|
||||
$kleeja_plugin = [];
|
||||
|
||||
include PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plg_name . '/init.php';
|
||||
|
||||
$uninstall_callback = $kleeja_plugin[$plg_name]['uninstall'];
|
||||
|
||||
if (!is_callable($uninstall_callback))
|
||||
if (! is_callable($uninstall_callback))
|
||||
{
|
||||
redirect(ADMIN_PATH . "?cp=" . basename(__file__, '.php'));
|
||||
redirect(ADMIN_PATH . '?cp=' . basename(__file__, '.php'));
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$query = array(
|
||||
'SELECT' => "plg_id",
|
||||
'FROM' => "{$dbprefix}plugins",
|
||||
'WHERE' => "plg_name='" . $SQL->escape($plg_name) . "'"
|
||||
);
|
||||
$query = [
|
||||
'SELECT' => 'plg_id',
|
||||
'FROM' => "{$dbprefix}plugins",
|
||||
'WHERE' => "plg_name='" . $SQL->escape($plg_name) . "'"
|
||||
];
|
||||
|
||||
$result = $SQL->build($query);
|
||||
|
||||
$pluginDatabaseInfo = $SQL->fetch($result);
|
||||
|
||||
#sad to see you go, brother
|
||||
$uninstall_callback(!empty($pluginDatabaseInfo) ? $pluginDatabaseInfo['plg_id'] : 0);
|
||||
//sad to see you go, brother
|
||||
$uninstall_callback(! empty($pluginDatabaseInfo) ? $pluginDatabaseInfo['plg_id'] : 0);
|
||||
|
||||
delete_cache('', true);
|
||||
|
||||
#remove from database
|
||||
$query_del = array(
|
||||
//remove from database
|
||||
$query_del = [
|
||||
'DELETE' => "`{$dbprefix}plugins`",
|
||||
'WHERE' => "plg_name='" . $SQL->escape($plg_name) . "'"
|
||||
);
|
||||
'WHERE' => "plg_name='" . $SQL->escape($plg_name) . "'"
|
||||
];
|
||||
|
||||
$SQL->build($query_del);
|
||||
|
||||
#show done, msg
|
||||
//show done, msg
|
||||
$text = '<h3>' . $lang['PLUGIN_DELETED'] . '</h3>';
|
||||
$text .= '<script type="text/javascript"> setTimeout("get_kleeja_link(\'' . ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '\');", 2000);</script>' . "\n";
|
||||
|
||||
@@ -480,9 +491,10 @@ switch ($case):
|
||||
case 'disable':
|
||||
case 'enable':
|
||||
|
||||
if(intval($userinfo['founder']) !== 1)
|
||||
if (intval($userinfo['founder']) !== 1)
|
||||
{
|
||||
kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS'], ADMIN_PATH . '?cp=' . basename(__file__, '.php'));
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -495,23 +507,23 @@ switch ($case):
|
||||
exit('empty($plg_name)');
|
||||
}
|
||||
//no plugin selected? back
|
||||
redirect(ADMIN_PATH . "?cp=" . basename(__file__, '.php'));
|
||||
redirect(ADMIN_PATH . '?cp=' . basename(__file__, '.php'));
|
||||
}
|
||||
else
|
||||
{
|
||||
#update database
|
||||
$update_query = array(
|
||||
//update database
|
||||
$update_query = [
|
||||
'UPDATE' => "{$dbprefix}plugins",
|
||||
'SET' => "plg_disabled=" . ($case == 'disable' ? 1 : 0),
|
||||
'WHERE' => "plg_name='" . $SQL->escape($plg_name) . "'"
|
||||
);
|
||||
'SET' => 'plg_disabled=' . ($case == 'disable' ? 1 : 0),
|
||||
'WHERE' => "plg_name='" . $SQL->escape($plg_name) . "'"
|
||||
];
|
||||
|
||||
|
||||
$SQL->build($update_query);
|
||||
|
||||
delete_cache('', true);
|
||||
|
||||
#show done, msg
|
||||
//show done, msg
|
||||
$text = '<h3>' . $lang['PLGUIN_DISABLED_ENABLED'] . '</h3>';
|
||||
$text .= '<script type="text/javascript"> setTimeout("get_kleeja_link(\'' . ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '\');", 2000);</script>' . "\n";
|
||||
|
||||
@@ -523,18 +535,20 @@ switch ($case):
|
||||
|
||||
case 'download':
|
||||
|
||||
if(intval($userinfo['founder']) !== 1)
|
||||
if (intval($userinfo['founder']) !== 1)
|
||||
{
|
||||
kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS'], ADMIN_PATH . '?cp=' . basename(__file__, '.php'));
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$download_plugin = g('plg');
|
||||
|
||||
// update it , rename function doesn't move the folder , if the folder is exists on the new dir
|
||||
if( file_exists( PATH . KLEEJA_PLUGINS_FOLDER. '/' . $download_plugin . '/init.php' ) )
|
||||
if ( file_exists( PATH . KLEEJA_PLUGINS_FOLDER . '/' . $download_plugin . '/init.php' ) )
|
||||
{
|
||||
redirect( $plugin_update_link . $download_plugin );
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -543,22 +557,22 @@ switch ($case):
|
||||
|
||||
$catalog_plugins = fetch_remote_file($store_link);
|
||||
|
||||
if ($catalog_plugins)
|
||||
if ($catalog_plugins)
|
||||
{
|
||||
$catalog_plugins = json_decode($catalog_plugins , true);
|
||||
$catalog_plugins = json_decode($catalog_plugins, true);
|
||||
|
||||
$store_plugins = [];
|
||||
|
||||
$store_plugins = array();
|
||||
|
||||
// make an arry for all plugins in kleeja store that not included in our server
|
||||
foreach ($catalog_plugins as $plugin_info)
|
||||
foreach ($catalog_plugins as $plugin_info)
|
||||
{
|
||||
$store_plugins[$plugin_info['name']] = array(
|
||||
'name' => $plugin_info['name'] ,
|
||||
'plg_version' => $plugin_info['file']['version'] ,
|
||||
'url' => $plugin_info['file']['url'] ,
|
||||
$store_plugins[$plugin_info['name']] = [
|
||||
'name' => $plugin_info['name'] ,
|
||||
'plg_version' => $plugin_info['file']['version'] ,
|
||||
'url' => $plugin_info['file']['url'] ,
|
||||
'kj_min_version' => $plugin_info['kleeja_version']['min'] ,
|
||||
'kj_max_version' => $plugin_info['kleeja_version']['max'] ,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// // => this plugin is hosted in our store
|
||||
@@ -566,22 +580,22 @@ switch ($case):
|
||||
{
|
||||
// check if the version of the plugin is compatible with our kleeja version or not
|
||||
if (
|
||||
version_compare(strtolower($store_plugins[$download_plugin]['kj_min_version']), KLEEJA_VERSION , '<=')
|
||||
&& version_compare(strtolower($store_plugins[$download_plugin]['kj_max_version']), KLEEJA_VERSION , '>=')
|
||||
)
|
||||
{
|
||||
version_compare(strtolower($store_plugins[$download_plugin]['kj_min_version']), KLEEJA_VERSION, '<=')
|
||||
&& version_compare(strtolower($store_plugins[$download_plugin]['kj_max_version']), KLEEJA_VERSION, '>=')
|
||||
) {
|
||||
$download_plugin_link = $store_plugins[$download_plugin]['url'];
|
||||
|
||||
$downloaded_plugin_zip = fetch_remote_file($download_plugin_link, PATH . 'cache/' . $download_plugin . '.zip', 60, false, 10, true);
|
||||
|
||||
if ($downloaded_plugin_zip)
|
||||
if ($downloaded_plugin_zip)
|
||||
{
|
||||
if (file_exists(PATH . 'cache/' . $download_plugin . '.zip' ) )
|
||||
if (file_exists(PATH . 'cache/' . $download_plugin . '.zip' ) )
|
||||
{
|
||||
$zip = new ZipArchive();
|
||||
|
||||
if ($zip->open(PATH . 'cache/' . $download_plugin . '.zip' ) === true)
|
||||
{
|
||||
if( $zip->extractTo(PATH . KLEEJA_PLUGINS_FOLDER))
|
||||
if ( $zip->extractTo(PATH . KLEEJA_PLUGINS_FOLDER))
|
||||
{
|
||||
$zip->close();
|
||||
// we dont need the zip file anymore
|
||||
@@ -590,18 +604,18 @@ switch ($case):
|
||||
// for example :: When we extract zip file , the name will be ( advanced-extras-1.0 )
|
||||
// so we need to remove the version from folder name and replace ( - ) with ( _ )
|
||||
// and done
|
||||
$plugin_folder_name = PATH . KLEEJA_PLUGINS_FOLDER. '/' . str_replace('_' , '-' , $download_plugin) . '-' . $store_plugins[$download_plugin]['plg_version'];
|
||||
rename($plugin_folder_name , PATH . KLEEJA_PLUGINS_FOLDER. '/' . $download_plugin);
|
||||
$plugin_folder_name = PATH . KLEEJA_PLUGINS_FOLDER . '/' . str_replace('_', '-', $download_plugin) . '-' . $store_plugins[$download_plugin]['plg_version'];
|
||||
rename($plugin_folder_name, PATH . KLEEJA_PLUGINS_FOLDER . '/' . $download_plugin);
|
||||
|
||||
// download or update msg
|
||||
kleeja_admin_info(
|
||||
sprintf($lang[ig('update') ? 'PLUGIN_UPDATED' : 'PLUGIN_DOWNLOADED'], $download_plugin),
|
||||
sprintf($lang[ig('update') ? 'PLUGIN_UPDATED' : 'PLUGIN_DOWNLOADED'], $download_plugin),
|
||||
ADMIN_PATH . '?cp=' . basename(__file__, '.php')
|
||||
);
|
||||
|
||||
|
||||
exit;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
kleeja_admin_err($lang['EXTRACT_ZIP_FAILED']);
|
||||
}
|
||||
@@ -612,7 +626,7 @@ switch ($case):
|
||||
kleeja_admin_err($lang['PLUGIN_FILE_NOT_FOUND']);
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
kleeja_admin_err($lang['PLUGINS_SERVER_ERROR']);
|
||||
}
|
||||
@@ -622,7 +636,7 @@ switch ($case):
|
||||
kleeja_admin_err($lang['PLUGIN_N_CMPT_KLJ']);
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
kleeja_admin_err(sprintf($lang['PLUGIN_REMOTE_FILE_MISSING'], $download_plugin));
|
||||
}
|
||||
@@ -640,12 +654,13 @@ switch ($case):
|
||||
|
||||
$plugin_folder_name = PATH . KLEEJA_PLUGINS_FOLDER . '/' . $update_plugin;
|
||||
|
||||
if (is_dir($plugin_folder_name))
|
||||
if (is_dir($plugin_folder_name))
|
||||
{
|
||||
delete_plugin_folder($plugin_folder_name);
|
||||
}
|
||||
|
||||
redirect($plugin_download_link . $update_plugin . '&update' );
|
||||
|
||||
break;
|
||||
|
||||
endswitch;
|
||||
|
||||
Reference in New Issue
Block a user