mirror of
https://github.com/kleeja-official/kleeja.git
synced 2025-12-16 04:59:42 +01:00
fix
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
*/
|
||||
|
||||
// not for directly open
|
||||
if (! defined('IN_ADMIN')) {
|
||||
if (! defined('IN_ADMIN'))
|
||||
{
|
||||
exit();
|
||||
}
|
||||
|
||||
@@ -20,28 +21,32 @@ $case = g('case', 'str', 'installed');
|
||||
|
||||
//set _get form key
|
||||
$GET_FORM_KEY = kleeja_add_form_key_get('adm_plugins_get');
|
||||
$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');
|
||||
$action = ADMIN_PATH . '?cp=' . basename(__FILE__, '.php');
|
||||
|
||||
$plugin_install_link = $action.'&case=install&'.$GET_FORM_KEY.'&plg=';
|
||||
$plugin_uninstall_link = $action.'&case=uninstall&'.$GET_FORM_KEY.'&plg=';
|
||||
$plugin_enable_link = $action.'&case=enable&'.$GET_FORM_KEY.'&plg=';
|
||||
$plugin_disable_link = $action.'&case=disable&'.$GET_FORM_KEY.'&plg=';
|
||||
$plugin_download_link = $action.'&case=download&'.$GET_FORM_KEY.'&plg=';
|
||||
$plugin_delete_folder_link = $action.'&case=dfolder&'.$GET_FORM_KEY.'&plg=';
|
||||
$plugin_install_link = $action . '&case=install&' . $GET_FORM_KEY . '&plg=';
|
||||
$plugin_uninstall_link = $action . '&case=uninstall&' . $GET_FORM_KEY . '&plg=';
|
||||
$plugin_enable_link = $action . '&case=enable&' . $GET_FORM_KEY . '&plg=';
|
||||
$plugin_disable_link = $action . '&case=disable&' . $GET_FORM_KEY . '&plg=';
|
||||
$plugin_download_link = $action . '&case=download&' . $GET_FORM_KEY . '&plg=';
|
||||
$plugin_delete_folder_link = $action . '&case=dfolder&' . $GET_FORM_KEY . '&plg=';
|
||||
|
||||
//check _GET Csrf token
|
||||
if (! empty($case) && in_array($case, ['install', 'uninstall', 'enable', 'disable', 'download', 'dfolder'])) {
|
||||
if (! kleeja_check_form_key_get('adm_plugins_get')) {
|
||||
if (! empty($case) && in_array($case, ['install', 'uninstall', 'enable', 'disable', 'download', 'dfolder']))
|
||||
{
|
||||
if (! kleeja_check_form_key_get('adm_plugins_get'))
|
||||
{
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
kleeja_admin_err($lang['INVALID_GET_KEY']);
|
||||
}
|
||||
}
|
||||
|
||||
//check _POST Csrf token
|
||||
if (ip('newplugin')) {
|
||||
if (! kleeja_check_form_key('adm_plugins')) {
|
||||
if (ip('newplugin'))
|
||||
{
|
||||
if (! kleeja_check_form_key('adm_plugins'))
|
||||
{
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
kleeja_admin_err($lang['INVALID_FORM_KEY'], true, $lang['ERROR'], true, $action);
|
||||
}
|
||||
@@ -58,8 +63,8 @@ switch ($case):
|
||||
|
||||
// Get installed plugins
|
||||
$query = [
|
||||
'SELECT' => 'plg_id, plg_name, plg_ver, plg_disabled, plg_author, plg_dsc',
|
||||
'FROM' => "{$dbprefix}plugins",
|
||||
'SELECT' => 'plg_id, plg_name, plg_ver, plg_disabled, plg_author, plg_dsc',
|
||||
'FROM' => "{$dbprefix}plugins",
|
||||
'ORDER BY' => 'plg_id ASC',
|
||||
];
|
||||
|
||||
@@ -67,26 +72,34 @@ switch ($case):
|
||||
|
||||
$installed_plugins = [];
|
||||
|
||||
while ($row = $SQL->fetch($result)) {
|
||||
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'
|
||||
: $STYLE_PATH_ADMIN.'images/plugin.png';
|
||||
? PATH . KLEEJA_PLUGINS_FOLDER . '/' . $row['plg_name'] . '/icon.png'
|
||||
: $STYLE_PATH_ADMIN . 'images/plugin.png';
|
||||
|
||||
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']])) {
|
||||
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']]))
|
||||
{
|
||||
$installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo] =
|
||||
shorten_text($installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo][$config['language']], 100);
|
||||
} elseif (! 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);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo] =
|
||||
shorten_text($installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo][0], 100);
|
||||
}
|
||||
@@ -96,51 +109,59 @@ switch ($case):
|
||||
$SQL->free($result);
|
||||
|
||||
//get available plugins
|
||||
$dh = opendir(PATH.KLEEJA_PLUGINS_FOLDER);
|
||||
$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 (empty($installed_plugins[$folder_name])) {
|
||||
while (false !== ($folder_name = readdir($dh)))
|
||||
{
|
||||
if (file_exists(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $folder_name) && preg_match('/[a-z0-9_.]{3,}/', $folder_name))
|
||||
{
|
||||
if (empty($installed_plugins[$folder_name]))
|
||||
{
|
||||
array_push($available_plugins, [
|
||||
'name' => $folder_name,
|
||||
'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',
|
||||
'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',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@closedir($dh);
|
||||
|
||||
$no_plugins = sizeof($available_plugins) == 0 && sizeof($installed_plugins) == 0;
|
||||
$no_plugins = sizeof($available_plugins) == 0 && sizeof($installed_plugins) == 0;
|
||||
$no_installed_plugins = sizeof($installed_plugins) == 0;
|
||||
|
||||
$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 (! ($store_catalog = $cache->get('store_catalog'))) {
|
||||
if (! ($store_catalog = $cache->get('store_catalog')))
|
||||
{
|
||||
$store_link = 'https://raw.githubusercontent.com/kleeja-official/store-catalog/master/catalog.json';
|
||||
|
||||
$store_catalog = fetch_remote_file($store_link);
|
||||
$store_catalog = json_decode($store_catalog, true);
|
||||
|
||||
if (json_last_error() == JSON_ERROR_NONE) {
|
||||
if (json_last_error() == JSON_ERROR_NONE)
|
||||
{
|
||||
$cache->save('store_catalog', $store_catalog);
|
||||
}
|
||||
}
|
||||
|
||||
// make an array for all plugins in kleeja remote catalog
|
||||
// that are not exsisted locally.
|
||||
$store_plugins = [];
|
||||
$store_plugins = [];
|
||||
$available_plugins_names = array_column($available_plugins, 'name');
|
||||
|
||||
foreach ($store_catalog as $plugin_info) {
|
||||
if ($plugin_info['type'] != 'plugin') {
|
||||
foreach ($store_catalog as $plugin_info)
|
||||
{
|
||||
if ($plugin_info['type'] != 'plugin')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -162,17 +183,17 @@ switch ($case):
|
||||
}
|
||||
|
||||
$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'],
|
||||
'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_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, '<=')
|
||||
'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,
|
||||
];
|
||||
@@ -187,41 +208,55 @@ switch ($case):
|
||||
case 'upload':
|
||||
$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'])) {
|
||||
if (empty($_FILES['plugin_file']['tmp_name']))
|
||||
{
|
||||
$ERRORS[] = $lang['CHOSE_F'];
|
||||
}
|
||||
|
||||
//extract it to plugins folder
|
||||
if (! sizeof($ERRORS)) {
|
||||
if (class_exists('ZipArchive')) {
|
||||
if (! sizeof($ERRORS))
|
||||
{
|
||||
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->open($_FILES['plugin_file']['tmp_name']) === true)
|
||||
{
|
||||
if (! $zip->extractTo(PATH . KLEEJA_PLUGINS_FOLDER))
|
||||
{
|
||||
$ERRORS[] = sprintf($lang['EXTRACT_ZIP_FAILED'], KLEEJA_PLUGINS_FOLDER);
|
||||
}
|
||||
$zip->close();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$ERRORS[] = sprintf($lang['EXTRACT_ZIP_FAILED'], KLEEJA_PLUGINS_FOLDER);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$ERRORS[] = $lang['NO_ZIP_ARCHIVE'];
|
||||
}
|
||||
}
|
||||
|
||||
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'], $action);
|
||||
} else {
|
||||
kleeja_admin_err('- '.implode('<br>- ', $ERRORS), $action);
|
||||
}
|
||||
else
|
||||
{
|
||||
kleeja_admin_err('- ' . implode('<br>- ', $ERRORS), $action);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -230,48 +265,59 @@ switch ($case):
|
||||
//
|
||||
case 'install':
|
||||
|
||||
if (intval($userinfo['founder']) !== 1) {
|
||||
if (intval($userinfo['founder']) !== 1)
|
||||
{
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS'], $action);
|
||||
}
|
||||
|
||||
$plg_name = g('plg', 'str');
|
||||
|
||||
if (empty($plg_name)) {
|
||||
if (defined('DEBUG')) {
|
||||
if (empty($plg_name))
|
||||
{
|
||||
if (defined('DEBUG'))
|
||||
{
|
||||
exit('empty($plg_name)');
|
||||
}
|
||||
//no plugin selected? back
|
||||
redirect(ADMIN_PATH.'?cp='.basename(__FILE__, '.php'));
|
||||
} else {
|
||||
if (! file_exists(PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plg_name.'/init.php')) {
|
||||
if (defined('DEBUG')) {
|
||||
redirect(ADMIN_PATH . '?cp=' . basename(__FILE__, '.php'));
|
||||
}
|
||||
else
|
||||
{
|
||||
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))) {
|
||||
kleeja_admin_info($lang['PLUGIN_EXISTS_BEFORE'], true, '', true, ADMIN_PATH.'?cp='.basename(__FILE__, '.php'));
|
||||
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 = [];
|
||||
|
||||
include PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plg_name.'/init.php';
|
||||
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']];
|
||||
} elseif (! 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'];
|
||||
}
|
||||
|
||||
@@ -280,26 +326,29 @@ switch ($case):
|
||||
// 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'], '<')) {
|
||||
if (version_compare(KLEEJA_VERSION, $plugin_info['plugin_kleeja_version_min'], '<'))
|
||||
{
|
||||
kleeja_admin_info(
|
||||
$lang['PACKAGE_N_CMPT_KLJ'].'<br>k:'.KLEEJA_VERSION.'|<|p.min:'.$plugin_info['plugin_kleeja_version_min'],
|
||||
$lang['PACKAGE_N_CMPT_KLJ'] . '<br>k:' . KLEEJA_VERSION . '|<|p.min:' . $plugin_info['plugin_kleeja_version_min'],
|
||||
true,
|
||||
'',
|
||||
true,
|
||||
ADMIN_PATH.'?cp='.basename(__FILE__, '.php')
|
||||
ADMIN_PATH . '?cp=' . basename(__FILE__, '.php')
|
||||
);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($plugin_info['plugin_kleeja_version_max'] != '0') {
|
||||
if (version_compare(KLEEJA_VERSION, $plugin_info['plugin_kleeja_version_max'], '>')) {
|
||||
if ($plugin_info['plugin_kleeja_version_max'] != '0')
|
||||
{
|
||||
if (version_compare(KLEEJA_VERSION, $plugin_info['plugin_kleeja_version_max'], '>'))
|
||||
{
|
||||
kleeja_admin_info(
|
||||
$lang['PACKAGE_N_CMPT_KLJ'].'<br>k:'.KLEEJA_VERSION.'|>|p.max:'.$plugin_info['plugin_kleeja_version_max'],
|
||||
$lang['PACKAGE_N_CMPT_KLJ'] . '<br>k:' . KLEEJA_VERSION . '|>|p.max:' . $plugin_info['plugin_kleeja_version_max'],
|
||||
true,
|
||||
'',
|
||||
true,
|
||||
ADMIN_PATH.'?cp='.basename(__FILE__, '.php')
|
||||
ADMIN_PATH . '?cp=' . basename(__FILE__, '.php')
|
||||
);
|
||||
|
||||
exit;
|
||||
@@ -308,32 +357,37 @@ switch ($case):
|
||||
|
||||
delete_cache('', true);
|
||||
|
||||
if (is_array($plugin_info['plugin_description'])) {
|
||||
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];
|
||||
}
|
||||
|
||||
//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",
|
||||
'VALUES' => "'".$SQL->escape($plg_name)."','".$SQL->escape($plugin_info['plugin_version'])."', '".$SQL->escape($plugin_info['plugin_developer'])."','".$SQL->escape($plugin_info['plugin_description'])."', '', '', '', '', ''",
|
||||
'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)) {
|
||||
if (is_callable($install_callback))
|
||||
{
|
||||
$install_callback($SQL->insert_id());
|
||||
}
|
||||
|
||||
//show done, msg
|
||||
$text = '<h3>'.$lang['NEW_PLUGIN_ADDED'].'</h3>';
|
||||
$text = '<h3>' . $lang['NEW_PLUGIN_ADDED'] . '</h3>';
|
||||
|
||||
if ($plugin_first_run) {
|
||||
if ($plugin_first_run)
|
||||
{
|
||||
$text .= $plugin_first_run;
|
||||
$text .= '<br><hr><a href="'.ADMIN_PATH.'?cp='.basename(__FILE__, '.php').'" class="btn btn-primary btn-lg">'.$lang['GO_BACK_BROWSER'].'</a>';
|
||||
} else {
|
||||
$text .= '<script type="text/javascript"> setTimeout("get_kleeja_link(\''.ADMIN_PATH.'?cp='.basename(__FILE__, '.php').'\');", 2000);</script>'."\n";
|
||||
$text .= '<br><hr><a href="' . ADMIN_PATH . '?cp=' . basename(__FILE__, '.php') . '" class="btn btn-primary btn-lg">' . $lang['GO_BACK_BROWSER'] . '</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$text .= '<script type="text/javascript"> setTimeout("get_kleeja_link(\'' . ADMIN_PATH . '?cp=' . basename(__FILE__, '.php') . '\');", 2000);</script>' . "\n";
|
||||
}
|
||||
|
||||
$stylee = 'admin_info';
|
||||
@@ -345,47 +399,55 @@ switch ($case):
|
||||
//
|
||||
case 'uninstall':
|
||||
|
||||
if (intval($userinfo['founder']) !== 1) {
|
||||
if (intval($userinfo['founder']) !== 1)
|
||||
{
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS'], $action);
|
||||
}
|
||||
|
||||
$plg_name = g('plg', 'str');
|
||||
|
||||
if (empty($plg_name)) {
|
||||
if (defined('DEV_STAGE')) {
|
||||
if (empty($plg_name))
|
||||
{
|
||||
if (defined('DEV_STAGE'))
|
||||
{
|
||||
exit('empty($plg_name)');
|
||||
}
|
||||
|
||||
//no plugin selected? back
|
||||
redirect(ADMIN_PATH.'?cp='.basename(__FILE__, '.php'));
|
||||
} else {
|
||||
if (! file_exists(PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plg_name.'/init.php')) {
|
||||
if (defined('DEV_STAGE')) {
|
||||
redirect(ADMIN_PATH . '?cp=' . basename(__FILE__, '.php'));
|
||||
}
|
||||
else
|
||||
{
|
||||
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 = [];
|
||||
|
||||
include PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plg_name.'/init.php';
|
||||
include PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plg_name . '/init.php';
|
||||
|
||||
$uninstall_callback = $kleeja_plugin[$plg_name]['uninstall'];
|
||||
|
||||
if (! is_callable($uninstall_callback)) {
|
||||
redirect(ADMIN_PATH.'?cp='.basename(__FILE__, '.php'));
|
||||
if (! is_callable($uninstall_callback))
|
||||
{
|
||||
redirect(ADMIN_PATH . '?cp=' . basename(__FILE__, '.php'));
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = [
|
||||
'SELECT' => 'plg_id',
|
||||
'FROM' => "{$dbprefix}plugins",
|
||||
'WHERE' => "plg_name='".$SQL->escape($plg_name)."'"
|
||||
'FROM' => "{$dbprefix}plugins",
|
||||
'WHERE' => "plg_name='" . $SQL->escape($plg_name) . "'"
|
||||
];
|
||||
|
||||
$result = $SQL->build($query);
|
||||
@@ -400,14 +462,14 @@ switch ($case):
|
||||
//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
|
||||
$text = '<h3>'.sprintf($lang['ITEM_DELETED'], $plg_name).'</h3>';
|
||||
$text .= '<script type="text/javascript"> setTimeout("get_kleeja_link(\''.ADMIN_PATH.'?cp='.basename(__FILE__, '.php').'\');", 2000);</script>'."\n";
|
||||
$text = '<h3>' . sprintf($lang['ITEM_DELETED'], $plg_name) . '</h3>';
|
||||
$text .= '<script type="text/javascript"> setTimeout("get_kleeja_link(\'' . ADMIN_PATH . '?cp=' . basename(__FILE__, '.php') . '\');", 2000);</script>' . "\n";
|
||||
|
||||
$stylee = 'admin_info';
|
||||
}
|
||||
@@ -419,25 +481,30 @@ switch ($case):
|
||||
case 'disable':
|
||||
case 'enable':
|
||||
|
||||
if (intval($userinfo['founder']) !== 1) {
|
||||
if (intval($userinfo['founder']) !== 1)
|
||||
{
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS'], $action);
|
||||
}
|
||||
|
||||
$plg_name = g('plg', 'str');
|
||||
|
||||
if (empty($plg_name)) {
|
||||
if (defined('DEV_STAGE')) {
|
||||
if (empty($plg_name))
|
||||
{
|
||||
if (defined('DEV_STAGE'))
|
||||
{
|
||||
exit('empty($plg_name)');
|
||||
}
|
||||
//no plugin selected? back
|
||||
redirect(ADMIN_PATH.'?cp='.basename(__FILE__, '.php'));
|
||||
} else {
|
||||
redirect(ADMIN_PATH . '?cp=' . basename(__FILE__, '.php'));
|
||||
}
|
||||
else
|
||||
{
|
||||
//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);
|
||||
@@ -445,16 +512,18 @@ switch ($case):
|
||||
delete_cache('', true);
|
||||
|
||||
//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";
|
||||
$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";
|
||||
|
||||
$stylee = 'admin_info';
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'download':
|
||||
|
||||
if (intval($userinfo['founder']) !== 1) {
|
||||
if (intval($userinfo['founder']) !== 1)
|
||||
{
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS']);
|
||||
}
|
||||
@@ -464,15 +533,18 @@ switch ($case):
|
||||
$is_update = false;
|
||||
|
||||
//if plugin exists before, then trigger update action. rename folder to rollback in case of failure
|
||||
if (file_exists(PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name.'/init.php')) {
|
||||
if (file_exists(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name . '/init.php'))
|
||||
{
|
||||
$is_update = true;
|
||||
|
||||
if (! rename(
|
||||
PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name,
|
||||
PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name.'_backup'
|
||||
)) {
|
||||
if (is_dir(PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name)) {
|
||||
kleeja_unlink(PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name);
|
||||
PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name,
|
||||
PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name . '_backup'
|
||||
))
|
||||
{
|
||||
if (file_exists(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name))
|
||||
{
|
||||
kleeja_unlink(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -482,28 +554,32 @@ switch ($case):
|
||||
|
||||
$catalog_plugins = fetch_remote_file($store_link);
|
||||
|
||||
if ($catalog_plugins) {
|
||||
if ($catalog_plugins)
|
||||
{
|
||||
$catalog_plugins = json_decode($catalog_plugins, true);
|
||||
|
||||
$store_plugins = [];
|
||||
|
||||
// make an arry for all plugins in kleeja store that not included in our server
|
||||
foreach ($catalog_plugins as $plugin_info) {
|
||||
if ($plugin_info['type'] != 'plugin') {
|
||||
foreach ($catalog_plugins as $plugin_info)
|
||||
{
|
||||
if ($plugin_info['type'] != 'plugin')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$store_plugins[$plugin_info['name']] = [
|
||||
'name' => $plugin_info['name'],
|
||||
'plg_version' => $plugin_info['file']['version'],
|
||||
'url' => $plugin_info['file']['url'],
|
||||
'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
|
||||
if (isset($store_plugins[$plugin_name])) {
|
||||
if (isset($store_plugins[$plugin_name]))
|
||||
{
|
||||
// check if the version of the plugin is compatible with our kleeja version or not
|
||||
if (
|
||||
version_compare(strtolower($store_plugins[$plugin_name]['kj_min_version']), KLEEJA_VERSION, '<=')
|
||||
@@ -511,79 +587,102 @@ switch ($case):
|
||||
) {
|
||||
$plugin_name_link = $store_plugins[$plugin_name]['url'];
|
||||
|
||||
$plugin_archive = fetch_remote_file($plugin_name_link, PATH.'cache/'.$plugin_name.'.zip', 60, false, 10, true);
|
||||
$plugin_archive = fetch_remote_file($plugin_name_link, PATH . 'cache/' . $plugin_name . '.zip', 60, false, 10, true);
|
||||
|
||||
if ($plugin_archive) {
|
||||
if (file_exists(PATH.'cache/'.$plugin_name.'.zip')) {
|
||||
if ($plugin_archive)
|
||||
{
|
||||
if (file_exists(PATH . 'cache/' . $plugin_name . '.zip'))
|
||||
{
|
||||
$zip = new ZipArchive();
|
||||
|
||||
if ($zip->open(PATH.'cache/'.$plugin_name.'.zip') === true) {
|
||||
if ($zip->extractTo(PATH.KLEEJA_PLUGINS_FOLDER)) {
|
||||
if ($zip->open(PATH . 'cache/' . $plugin_name . '.zip') === true)
|
||||
{
|
||||
if ($zip->extractTo(PATH . KLEEJA_PLUGINS_FOLDER))
|
||||
{
|
||||
// we dont need the zip file anymore
|
||||
kleeja_unlink(PATH.'cache/'.$plugin_name.'.zip');
|
||||
kleeja_unlink(PATH . 'cache/' . $plugin_name . '.zip');
|
||||
|
||||
// uploaded plugin's archive has different name, so we change it
|
||||
rename(
|
||||
PATH.KLEEJA_PLUGINS_FOLDER.'/'.trim($zip->getNameIndex(0), '/'),
|
||||
PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name
|
||||
PATH . KLEEJA_PLUGINS_FOLDER . '/' . trim($zip->getNameIndex(0), '/'),
|
||||
PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name
|
||||
);
|
||||
|
||||
$zip->close();
|
||||
|
||||
// download or update msg
|
||||
$adminAjaxContent = '1:::'.sprintf($lang[$is_update ? 'ITEM_UPDATED' : 'ITEM_DOWNLOADED'], $plugin_name);
|
||||
$adminAjaxContent = '1:::' . sprintf($lang[$is_update ? 'ITEM_UPDATED' : 'ITEM_DOWNLOADED'], $plugin_name);
|
||||
|
||||
//in case of update, delete back up version
|
||||
if (is_dir(PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name.'_backup')) {
|
||||
kleeja_unlink(PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name.'_backup');
|
||||
if (file_exists(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name . '_backup'))
|
||||
{
|
||||
kleeja_unlink(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name . '_backup');
|
||||
}
|
||||
} else {
|
||||
$adminAjaxContent = '1003:::'.sprintf($lang['EXTRACT_ZIP_FAILED'], KLEEJA_PLUGINS_FOLDER);
|
||||
}
|
||||
else
|
||||
{
|
||||
$adminAjaxContent = '1003:::' . sprintf($lang['EXTRACT_ZIP_FAILED'], KLEEJA_PLUGINS_FOLDER);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$adminAjaxContent = '1004:::'.$lang['DOWNLOADED_FILE_NOT_FOUND'];
|
||||
}
|
||||
} else {
|
||||
$adminAjaxContent = '1005:::'.$lang['STORE_SERVER_ERROR'];
|
||||
else
|
||||
{
|
||||
$adminAjaxContent = '1004:::' . $lang['DOWNLOADED_FILE_NOT_FOUND'];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$adminAjaxContent = '1005:::' . $lang['STORE_SERVER_ERROR'];
|
||||
}
|
||||
} else {
|
||||
$adminAjaxContent = '1006:::'.$lang['PACKAGE_N_CMPT_KLJ'];
|
||||
}
|
||||
} else {
|
||||
$adminAjaxContent = '1007:::'.sprintf($lang['PACKAGE_REMOTE_FILE_MISSING'], $plugin_name);
|
||||
else
|
||||
{
|
||||
$adminAjaxContent = '1006:::' . $lang['PACKAGE_N_CMPT_KLJ'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$adminAjaxContent = '1008:::'.$lang['STORE_SERVER_ERROR'];
|
||||
else
|
||||
{
|
||||
$adminAjaxContent = '1007:::' . sprintf($lang['PACKAGE_REMOTE_FILE_MISSING'], $plugin_name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$adminAjaxContent = '1008:::' . $lang['STORE_SERVER_ERROR'];
|
||||
}
|
||||
|
||||
//in case of update failure, rollback to current plugin version
|
||||
if (strpos($adminAjaxContent, '1:::') === false) {
|
||||
if (is_dir(PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name.'_backup')) {
|
||||
if (strpos($adminAjaxContent, '1:::') === false)
|
||||
{
|
||||
if (file_exists(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name . '_backup'))
|
||||
{
|
||||
rename(
|
||||
PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name.'_backup',
|
||||
PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name
|
||||
PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name . '_backup',
|
||||
PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'dfolder':
|
||||
|
||||
$plugin_name = preg_replace('/[^a-z0-9_\-\.]/i', '', g('plg'));
|
||||
|
||||
$plugin_folder_path = PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name;
|
||||
$plugin_folder_path = PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name;
|
||||
|
||||
if (is_dir($plugin_folder_path)) {
|
||||
if (! is_writable($plugin_folder_path)) {
|
||||
if (file_exists($plugin_folder_path))
|
||||
{
|
||||
if (! is_writable($plugin_folder_path))
|
||||
{
|
||||
@chmod($plugin_folder_path, K_DIR_CHMOD);
|
||||
}
|
||||
|
||||
kleeja_unlink($plugin_folder_path);
|
||||
}
|
||||
|
||||
if (! is_dir($plugin_folder_path)) {
|
||||
kleeja_admin_info(sprintf($lang['ITEM_DELETED'], $plugin_name), $action.'&case=local');
|
||||
if (! file_exists($plugin_folder_path))
|
||||
{
|
||||
kleeja_admin_info(sprintf($lang['ITEM_DELETED'], $plugin_name), $action . '&case=local');
|
||||
}
|
||||
|
||||
kleeja_admin_err($lang['ERROR_TRY_AGAIN'], $action);
|
||||
|
||||
@@ -61,7 +61,7 @@ case 'store':
|
||||
{
|
||||
while (false !== ($folder_name = readdir($dh)))
|
||||
{
|
||||
if (is_dir(PATH . 'styles/' . $folder_name) && preg_match('/[a-z0-9_.]{3,}/', $folder_name))
|
||||
if (file_exists(PATH . 'styles/' . $folder_name) && preg_match('/[a-z0-9_.]{3,}/', $folder_name))
|
||||
{
|
||||
|
||||
//info
|
||||
@@ -325,7 +325,7 @@ case 'upload':
|
||||
|
||||
$style_folder_path = PATH . 'styles/' . $style_name;
|
||||
|
||||
if (is_dir($style_folder_path))
|
||||
if (file_exists($style_folder_path))
|
||||
{
|
||||
if (! is_writable($style_folder_path))
|
||||
{
|
||||
@@ -336,7 +336,7 @@ case 'upload':
|
||||
}
|
||||
|
||||
|
||||
if (! is_dir($style_folder_path))
|
||||
if (! file_exists($style_folder_path))
|
||||
{
|
||||
kleeja_admin_info(sprintf($lang['ITEM_DELETED'], $style_name), $action);
|
||||
}
|
||||
@@ -365,7 +365,7 @@ case 'download':
|
||||
}
|
||||
|
||||
//if style exists before, then trigger update action. rename folder to rollback in case of failure
|
||||
if (file_exists(PATH . 'styles/' . $style_name . '/init.php'))
|
||||
if (file_exists(PATH . 'styles/' . $style_name))
|
||||
{
|
||||
$is_update = true;
|
||||
|
||||
@@ -374,7 +374,7 @@ case 'download':
|
||||
PATH . 'styles/' . $style_name . '_backup'
|
||||
))
|
||||
{
|
||||
if (is_dir(PATH . 'styles/' . $style_name))
|
||||
if (file_exists(PATH . 'styles/' . $style_name))
|
||||
{
|
||||
kleeja_unlink(PATH . 'styles/' . $style_name);
|
||||
}
|
||||
@@ -446,7 +446,7 @@ case 'download':
|
||||
$adminAjaxContent = '1:::' . sprintf($lang[$is_update ? 'ITEM_UPDATED' : 'ITEM_DOWNLOADED'], $style_name);
|
||||
|
||||
//in case of update, delete back up version
|
||||
if (is_dir(PATH . 'styles/' . $style_name . '_backup'))
|
||||
if (file_exists(PATH . 'styles/' . $style_name . '_backup'))
|
||||
{
|
||||
kleeja_unlink(PATH . 'styles/' . $style_name . '_backup');
|
||||
}
|
||||
@@ -486,7 +486,7 @@ case 'download':
|
||||
//in case of update failure, rollback to current plugin version
|
||||
if (strpos($adminAjaxContent, '1:::') === false)
|
||||
{
|
||||
if (is_dir(PATH . 'styles/' . $style_name . '_backup'))
|
||||
if (file_exists(PATH . 'styles/' . $style_name . '_backup'))
|
||||
{
|
||||
rename(
|
||||
PATH . 'styles/' . $style_name . '_backup',
|
||||
|
||||
Reference in New Issue
Block a user