2018-01-09 02:09:07 +03:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @package adm
|
|
|
|
|
* @copyright (c) 2007 Kleeja.com
|
|
|
|
|
* @license http://www.kleeja.com/license
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// not for directly open
|
2019-05-16 01:34:48 +03:00
|
|
|
if (! defined('IN_ADMIN')) {
|
2018-01-09 02:09:07 +03:00
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//turn time-limit off
|
2018-01-09 02:09:07 +03:00
|
|
|
@set_time_limit(0);
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//get current case
|
2019-04-19 23:54:23 +03:00
|
|
|
$case = g('case', 'str', 'installed');
|
2018-01-09 02:09:07 +03:00
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//set _get form key
|
2019-05-16 01:34:48 +03:00
|
|
|
$GET_FORM_KEY = kleeja_add_form_key_get('adm_plugins_get');
|
|
|
|
|
$H_FORM_KEYS = kleeja_add_form_key('adm_plugins');
|
2018-01-09 02:09:07 +03:00
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
$action = ADMIN_PATH.'?cp='.basename(__FILE__, '.php');
|
2018-01-09 02:09:07 +03:00
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
$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=';
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
//check _GET Csrf token
|
2019-05-16 01:34:48 +03:00
|
|
|
if (! empty($case) && in_array($case, ['install', 'uninstall', 'enable', 'disable', 'download', 'dfolder'])) {
|
|
|
|
|
if (! kleeja_check_form_key_get('adm_plugins_get')) {
|
2019-05-15 00:48:58 +03:00
|
|
|
header('HTTP/1.0 401 Unauthorized');
|
|
|
|
|
kleeja_admin_err($lang['INVALID_GET_KEY']);
|
2019-04-16 22:54:33 +03:00
|
|
|
}
|
2018-01-09 02:09:07 +03:00
|
|
|
}
|
|
|
|
|
|
2019-05-16 00:41:21 +03:00
|
|
|
//check _POST Csrf token
|
2019-05-16 01:34:48 +03:00
|
|
|
if (ip('newplugin')) {
|
|
|
|
|
if (! kleeja_check_form_key('adm_plugins')) {
|
2019-05-15 00:48:58 +03:00
|
|
|
header('HTTP/1.0 401 Unauthorized');
|
2018-01-09 02:09:07 +03:00
|
|
|
kleeja_admin_err($lang['INVALID_FORM_KEY'], true, $lang['ERROR'], true, $action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$case = 'upload';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch ($case):
|
|
|
|
|
|
|
|
|
|
default:
|
2019-04-19 23:54:23 +03:00
|
|
|
case 'local':
|
|
|
|
|
case 'store':
|
2019-05-02 19:51:46 +03:00
|
|
|
case 'check':
|
2018-01-09 02:09:07 +03:00
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
// Get installed plugins
|
|
|
|
|
$query = [
|
2019-05-16 01:34:48 +03:00
|
|
|
'SELECT' => 'plg_id, plg_name, plg_ver, plg_disabled, plg_author, plg_dsc',
|
|
|
|
|
'FROM' => "{$dbprefix}plugins",
|
2019-05-03 23:52:08 +03:00
|
|
|
'ORDER BY' => 'plg_id ASC',
|
|
|
|
|
];
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
$result = $SQL->build($query);
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
$installed_plugins = [];
|
2018-01-09 02:09:07 +03:00
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
while ($row = $SQL->fetch($result)) {
|
2018-01-09 02:09:07 +03:00
|
|
|
$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(
|
2019-05-16 01:34:48 +03:00
|
|
|
PATH.KLEEJA_PLUGINS_FOLDER.'/'.$row['plg_name'].'/icon.png'
|
2018-01-09 02:09:07 +03:00
|
|
|
)
|
2019-05-16 01:34:48 +03:00
|
|
|
? PATH.KLEEJA_PLUGINS_FOLDER.'/'.$row['plg_name'].'/icon.png'
|
|
|
|
|
: $STYLE_PATH_ADMIN.'images/plugin.png';
|
2018-01-09 02:09:07 +03:00
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
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']])) {
|
2018-01-09 02:09:07 +03:00
|
|
|
$installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo] =
|
|
|
|
|
shorten_text($installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo][$config['language']], 100);
|
2019-05-16 01:34:48 +03:00
|
|
|
} elseif (! empty($installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo]['en'])) {
|
2018-01-09 02:09:07 +03:00
|
|
|
$installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo] =
|
|
|
|
|
shorten_text($installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo]['en'], 100);
|
2019-05-16 01:34:48 +03:00
|
|
|
} else {
|
2018-01-09 02:09:07 +03:00
|
|
|
$installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo] =
|
|
|
|
|
shorten_text($installed_plugins[$row['plg_name']]['extra_info'][$localizedInfo][0], 100);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$SQL->free($result);
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//get available plugins
|
2019-05-16 01:34:48 +03:00
|
|
|
$dh = opendir(PATH.KLEEJA_PLUGINS_FOLDER);
|
2019-05-03 23:52:08 +03:00
|
|
|
$available_plugins = [];
|
2019-05-16 01:34:48 +03:00
|
|
|
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])) {
|
2019-05-16 00:41:21 +03:00
|
|
|
array_push($available_plugins, [
|
|
|
|
|
'name' => $folder_name,
|
2019-05-16 01:34:48 +03:00
|
|
|
'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',
|
2019-05-16 00:41:21 +03:00
|
|
|
]);
|
2018-01-09 02:09:07 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@closedir($dh);
|
|
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
$no_plugins = sizeof($available_plugins) == 0 && sizeof($installed_plugins) == 0;
|
2019-05-15 00:48:58 +03:00
|
|
|
$no_installed_plugins = sizeof($installed_plugins) == 0;
|
2019-04-19 23:54:23 +03:00
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
$stylee = 'admin_plugins';
|
2019-04-19 23:54:23 +03:00
|
|
|
|
|
|
|
|
//do not proceed if not store case
|
2019-05-16 01:34:48 +03:00
|
|
|
if (! in_array($case, ['store', 'check'])) {
|
2019-04-19 23:54:23 +03:00
|
|
|
break;
|
|
|
|
|
}
|
2018-01-09 02:09:07 +03:00
|
|
|
|
2019-05-05 20:12:32 +03:00
|
|
|
// plugins avilable in kleeja remote catalog
|
2019-05-16 01:34:48 +03:00
|
|
|
if (! ($store_catalog = $cache->get('store_catalog'))) {
|
2019-05-03 14:56:46 +03:00
|
|
|
$store_link = 'https://raw.githubusercontent.com/kleeja-official/store-catalog/master/catalog.json';
|
2019-04-16 20:25:20 +02:00
|
|
|
|
2019-05-16 00:41:21 +03:00
|
|
|
$store_catalog = fetch_remote_file($store_link);
|
|
|
|
|
$store_catalog = json_decode($store_catalog, true);
|
2019-04-16 20:25:20 +02:00
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if (json_last_error() == JSON_ERROR_NONE) {
|
2019-05-16 00:41:21 +03:00
|
|
|
$cache->save('store_catalog', $store_catalog);
|
2019-04-16 22:54:33 +03:00
|
|
|
}
|
2019-04-16 20:25:20 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-16 22:54:33 +03:00
|
|
|
// make an array for all plugins in kleeja remote catalog
|
|
|
|
|
// that are not exsisted locally.
|
2019-05-16 01:34:48 +03:00
|
|
|
$store_plugins = [];
|
2019-04-16 22:54:33 +03:00
|
|
|
$available_plugins_names = array_column($available_plugins, 'name');
|
2019-05-03 23:52:08 +03:00
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
foreach ($store_catalog as $plugin_info) {
|
|
|
|
|
if ($plugin_info['type'] != 'plugin') {
|
2019-05-16 00:41:21 +03:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
if ($case == 'store' && (in_array($plugin_info['name'], $available_plugins_names) ||
|
2019-05-15 00:48:58 +03:00
|
|
|
! empty($installed_plugins[$plugin_info['name']]))
|
2019-05-03 23:52:08 +03:00
|
|
|
) {
|
2019-05-02 19:51:46 +03:00
|
|
|
continue;
|
2019-04-16 20:25:20 +02:00
|
|
|
}
|
2019-05-02 19:51:46 +03:00
|
|
|
|
|
|
|
|
// is there a new version of this in the store
|
2019-05-05 20:12:32 +03:00
|
|
|
elseif ($case == 'check' && (! empty($installed_plugins[$plugin_info['name']]) &&
|
2019-05-02 19:51:46 +03:00
|
|
|
version_compare(
|
2019-05-03 00:07:56 +03:00
|
|
|
strtolower($installed_plugins[$plugin_info['name']]['extra_info']['plugin_version']),
|
|
|
|
|
strtolower($plugin_info['file']['version']),
|
2019-05-16 01:34:48 +03:00
|
|
|
'>='
|
|
|
|
|
) || empty($installed_plugins[$plugin_info['name']]))
|
2019-05-03 23:52:08 +03:00
|
|
|
) {
|
2019-05-02 19:51:46 +03:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
$store_plugins[$plugin_info['name']] = [
|
2019-05-16 01:34:48 +03:00
|
|
|
'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, '<=')
|
2019-05-03 23:52:08 +03:00
|
|
|
&& version_compare(strtolower($plugin_info['kleeja_version']['max']), KLEEJA_VERSION, '>=')
|
|
|
|
|
? false : true,
|
|
|
|
|
];
|
2019-05-02 19:51:46 +03:00
|
|
|
}
|
|
|
|
|
|
2019-05-15 22:24:45 +03:00
|
|
|
$store_plugins_count = sizeof($store_plugins);
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
//
|
|
|
|
|
//upload a plugin
|
|
|
|
|
//
|
|
|
|
|
case 'upload':
|
2019-05-03 23:52:08 +03:00
|
|
|
$ERRORS = [];
|
2018-01-09 02:09:07 +03:00
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if (intval($userinfo['founder']) !== 1) {
|
2018-01-09 02:09:07 +03:00
|
|
|
$ERRORS[] = $lang['HV_NOT_PRVLG_ACCESS'];
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//is uploaded?
|
2019-05-16 01:34:48 +03:00
|
|
|
if (empty($_FILES['plugin_file']['tmp_name'])) {
|
2018-01-09 02:09:07 +03:00
|
|
|
$ERRORS[] = $lang['CHOSE_F'];
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//extract it to plugins folder
|
2019-05-16 01:34:48 +03:00
|
|
|
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)) {
|
2018-01-09 02:09:07 +03:00
|
|
|
$ERRORS[] = sprintf($lang['EXTRACT_ZIP_FAILED'], KLEEJA_PLUGINS_FOLDER);
|
|
|
|
|
}
|
|
|
|
|
$zip->close();
|
2019-05-16 01:34:48 +03:00
|
|
|
} else {
|
2018-01-09 02:09:07 +03:00
|
|
|
$ERRORS[] = sprintf($lang['EXTRACT_ZIP_FAILED'], KLEEJA_PLUGINS_FOLDER);
|
|
|
|
|
}
|
2019-05-16 01:34:48 +03:00
|
|
|
} else {
|
2018-01-09 02:09:07 +03:00
|
|
|
$ERRORS[] = $lang['NO_ZIP_ARCHIVE'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if (! empty($_FILES['plugin_file']['tmp_name'])) {
|
2018-01-09 02:09:07 +03:00
|
|
|
@unlink($_FILES['plugin_file']['tmp_name']);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if (! sizeof($ERRORS)) {
|
2019-05-15 00:48:58 +03:00
|
|
|
kleeja_admin_info($lang['NO_PROBLEM_AFTER_ZIP'], $action);
|
2019-05-16 01:34:48 +03:00
|
|
|
} else {
|
|
|
|
|
kleeja_admin_err('- '.implode('<br>- ', $ERRORS), $action);
|
2018-01-09 02:09:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
//
|
|
|
|
|
//install a plugin
|
|
|
|
|
//
|
|
|
|
|
case 'install':
|
|
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if (intval($userinfo['founder']) !== 1) {
|
2019-05-15 00:48:58 +03:00
|
|
|
header('HTTP/1.0 401 Unauthorized');
|
|
|
|
|
kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS'], $action);
|
2018-01-09 02:09:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$plg_name = g('plg', 'str');
|
|
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if (empty($plg_name)) {
|
|
|
|
|
if (defined('DEBUG')) {
|
2018-01-09 02:09:07 +03:00
|
|
|
exit('empty($plg_name)');
|
|
|
|
|
}
|
|
|
|
|
//no plugin selected? back
|
2019-05-16 01:34:48 +03:00
|
|
|
redirect(ADMIN_PATH.'?cp='.basename(__FILE__, '.php'));
|
|
|
|
|
} else {
|
|
|
|
|
if (! file_exists(PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plg_name.'/init.php')) {
|
|
|
|
|
if (defined('DEBUG')) {
|
2018-01-09 02:09:07 +03:00
|
|
|
exit('!file_exists($plg_name)');
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
redirect(ADMIN_PATH.'?cp='.basename(__FILE__, '.php'));
|
2019-05-03 23:52:08 +03:00
|
|
|
|
2018-01-09 02:09:07 +03:00
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//if already installed, show a message
|
2019-05-16 01:34:48 +03:00
|
|
|
if (! empty(Plugins::getInstance()->installed_plugin_info($plg_name))) {
|
|
|
|
|
kleeja_admin_info($lang['PLUGIN_EXISTS_BEFORE'], true, '', true, ADMIN_PATH.'?cp='.basename(__FILE__, '.php'));
|
2019-05-03 23:52:08 +03:00
|
|
|
|
2018-01-09 02:09:07 +03:00
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
$kleeja_plugin = [];
|
2018-01-09 02:09:07 +03:00
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
include PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plg_name.'/init.php';
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
$install_callback = $kleeja_plugin[$plg_name]['install'];
|
2019-05-16 01:34:48 +03:00
|
|
|
$plugin_info = $kleeja_plugin[$plg_name]['information'];
|
2018-01-09 02:09:07 +03:00
|
|
|
$plugin_first_run = false;
|
|
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if (! empty($kleeja_plugin[$plg_name]['first_run'][$config['language']])) {
|
2018-01-09 02:09:07 +03:00
|
|
|
$plugin_first_run = $kleeja_plugin[$plg_name]['first_run'][$config['language']];
|
2019-05-16 01:34:48 +03:00
|
|
|
} elseif (! empty($kleeja_plugin[$plg_name]['first_run']['en'])) {
|
2018-01-09 02:09:07 +03:00
|
|
|
$plugin_first_run = $kleeja_plugin[$plg_name]['first_run']['en'];
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//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',
|
2018-01-09 02:09:07 +03:00
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if (version_compare(KLEEJA_VERSION, $plugin_info['plugin_kleeja_version_min'], '<')) {
|
2019-04-19 23:08:22 +03:00
|
|
|
kleeja_admin_info(
|
2019-05-16 01:34:48 +03:00
|
|
|
$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')
|
2019-04-19 23:08:22 +03:00
|
|
|
);
|
2019-05-03 23:52:08 +03:00
|
|
|
|
2018-01-09 02:09:07 +03:00
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if ($plugin_info['plugin_kleeja_version_max'] != '0') {
|
|
|
|
|
if (version_compare(KLEEJA_VERSION, $plugin_info['plugin_kleeja_version_max'], '>')) {
|
2019-04-19 23:08:22 +03:00
|
|
|
kleeja_admin_info(
|
2019-05-16 01:34:48 +03:00
|
|
|
$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')
|
2019-04-19 23:08:22 +03:00
|
|
|
);
|
2019-05-03 23:52:08 +03:00
|
|
|
|
2018-01-09 02:09:07 +03:00
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete_cache('', true);
|
|
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if (is_array($plugin_info['plugin_description'])) {
|
2019-05-03 23:52:08 +03:00
|
|
|
$plugin_info['plugin_description'] = ! empty($plugin_info['plugin_description']['en']) ? $plugin_info['plugin_description']['en'] : $plugin_info['plugin_description'][0];
|
2018-01-09 02:09:07 +03:00
|
|
|
}
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//add to database
|
|
|
|
|
$insert_query = [
|
2018-01-09 02:09:07 +03:00
|
|
|
'INSERT' => '`plg_name` ,`plg_ver`, `plg_author`, `plg_dsc`, `plg_icon`, `plg_uninstall`, `plg_instructions`, `plg_store`, `plg_files`',
|
2019-05-16 01:34:48 +03:00
|
|
|
'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'])."', '', '', '', '', ''",
|
2019-05-03 23:52:08 +03:00
|
|
|
];
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
$SQL->build($insert_query);
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//may God protect you brother.
|
2019-05-16 01:34:48 +03:00
|
|
|
if (is_callable($install_callback)) {
|
2018-01-09 02:09:07 +03:00
|
|
|
$install_callback($SQL->insert_id());
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//show done, msg
|
2019-05-16 01:34:48 +03:00
|
|
|
$text = '<h3>'.$lang['NEW_PLUGIN_ADDED'].'</h3>';
|
2019-05-03 23:52:08 +03:00
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if ($plugin_first_run) {
|
2018-01-09 02:09:07 +03:00
|
|
|
$text .= $plugin_first_run;
|
2019-05-16 01:34:48 +03:00
|
|
|
$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";
|
2018-01-09 02:09:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$stylee = 'admin_info';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
//
|
|
|
|
|
//uninstall a plugin
|
|
|
|
|
//
|
|
|
|
|
case 'uninstall':
|
|
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if (intval($userinfo['founder']) !== 1) {
|
2019-05-15 00:48:58 +03:00
|
|
|
header('HTTP/1.0 401 Unauthorized');
|
|
|
|
|
kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS'], $action);
|
2018-01-09 02:09:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$plg_name = g('plg', 'str');
|
|
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if (empty($plg_name)) {
|
|
|
|
|
if (defined('DEV_STAGE')) {
|
2018-01-09 02:09:07 +03:00
|
|
|
exit('empty($plg_name)');
|
|
|
|
|
}
|
2019-04-19 23:08:22 +03:00
|
|
|
|
2018-01-09 02:09:07 +03:00
|
|
|
//no plugin selected? back
|
2019-05-16 01:34:48 +03:00
|
|
|
redirect(ADMIN_PATH.'?cp='.basename(__FILE__, '.php'));
|
|
|
|
|
} else {
|
|
|
|
|
if (! file_exists(PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plg_name.'/init.php')) {
|
|
|
|
|
if (defined('DEV_STAGE')) {
|
2018-01-09 02:09:07 +03:00
|
|
|
exit('!file_exists($plg_name)');
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
redirect(ADMIN_PATH.'?cp='.basename(__FILE__, '.php'));
|
2019-05-03 23:52:08 +03:00
|
|
|
|
2018-01-09 02:09:07 +03:00
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
$kleeja_plugin = [];
|
2018-01-09 02:09:07 +03:00
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
include PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plg_name.'/init.php';
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
$uninstall_callback = $kleeja_plugin[$plg_name]['uninstall'];
|
|
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if (! is_callable($uninstall_callback)) {
|
|
|
|
|
redirect(ADMIN_PATH.'?cp='.basename(__FILE__, '.php'));
|
2019-05-03 23:52:08 +03:00
|
|
|
|
2018-01-09 02:09:07 +03:00
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
$query = [
|
|
|
|
|
'SELECT' => 'plg_id',
|
2019-05-16 01:34:48 +03:00
|
|
|
'FROM' => "{$dbprefix}plugins",
|
|
|
|
|
'WHERE' => "plg_name='".$SQL->escape($plg_name)."'"
|
2019-05-03 23:52:08 +03:00
|
|
|
];
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
$result = $SQL->build($query);
|
|
|
|
|
|
|
|
|
|
$pluginDatabaseInfo = $SQL->fetch($result);
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//sad to see you go, brother
|
|
|
|
|
$uninstall_callback(! empty($pluginDatabaseInfo) ? $pluginDatabaseInfo['plg_id'] : 0);
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
delete_cache('', true);
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//remove from database
|
|
|
|
|
$query_del = [
|
2018-01-09 02:09:07 +03:00
|
|
|
'DELETE' => "`{$dbprefix}plugins`",
|
2019-05-16 01:34:48 +03:00
|
|
|
'WHERE' => "plg_name='".$SQL->escape($plg_name)."'"
|
2019-05-03 23:52:08 +03:00
|
|
|
];
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
$SQL->build($query_del);
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//show done, msg
|
2019-05-16 01:34:48 +03:00
|
|
|
$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";
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
$stylee = 'admin_info';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
//
|
2019-04-16 22:54:33 +03:00
|
|
|
// disable a plugin
|
2018-01-09 02:09:07 +03:00
|
|
|
//
|
|
|
|
|
case 'disable':
|
|
|
|
|
case 'enable':
|
|
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if (intval($userinfo['founder']) !== 1) {
|
2019-05-15 00:48:58 +03:00
|
|
|
header('HTTP/1.0 401 Unauthorized');
|
|
|
|
|
kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS'], $action);
|
2018-01-09 02:09:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$plg_name = g('plg', 'str');
|
|
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if (empty($plg_name)) {
|
|
|
|
|
if (defined('DEV_STAGE')) {
|
2018-01-09 02:09:07 +03:00
|
|
|
exit('empty($plg_name)');
|
|
|
|
|
}
|
|
|
|
|
//no plugin selected? back
|
2019-05-16 01:34:48 +03:00
|
|
|
redirect(ADMIN_PATH.'?cp='.basename(__FILE__, '.php'));
|
|
|
|
|
} else {
|
2019-05-03 23:52:08 +03:00
|
|
|
//update database
|
|
|
|
|
$update_query = [
|
2018-01-09 02:09:07 +03:00
|
|
|
'UPDATE' => "{$dbprefix}plugins",
|
2019-05-16 01:34:48 +03:00
|
|
|
'SET' => 'plg_disabled='.($case == 'disable' ? 1 : 0),
|
|
|
|
|
'WHERE' => "plg_name='".$SQL->escape($plg_name)."'"
|
2019-05-03 23:52:08 +03:00
|
|
|
];
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
$SQL->build($update_query);
|
|
|
|
|
|
|
|
|
|
delete_cache('', true);
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//show done, msg
|
2019-05-16 01:34:48 +03:00
|
|
|
$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";
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
$stylee = 'admin_info';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
2019-04-16 22:54:33 +03:00
|
|
|
case 'download':
|
2019-04-16 20:25:20 +02:00
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if (intval($userinfo['founder']) !== 1) {
|
2019-05-15 00:48:58 +03:00
|
|
|
header('HTTP/1.0 401 Unauthorized');
|
|
|
|
|
kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS']);
|
2019-04-16 20:25:20 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-16 00:41:21 +03:00
|
|
|
$plugin_name = g('plg');
|
2019-05-02 22:57:44 +02:00
|
|
|
|
2019-05-15 00:48:58 +03:00
|
|
|
$is_update = false;
|
|
|
|
|
|
|
|
|
|
//if plugin exists before, then trigger update action. rename folder to rollback in case of failure
|
2019-05-16 01:34:48 +03:00
|
|
|
if (file_exists(PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name.'/init.php')) {
|
2019-05-15 00:48:58 +03:00
|
|
|
$is_update = true;
|
2019-05-03 23:52:08 +03:00
|
|
|
|
2019-05-15 00:48:58 +03:00
|
|
|
if (! rename(
|
2019-05-16 01:34:48 +03:00
|
|
|
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);
|
2019-05-15 00:48:58 +03:00
|
|
|
}
|
|
|
|
|
}
|
2019-05-02 22:57:44 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-05 20:12:32 +03:00
|
|
|
// plugins avilable in kleeja store
|
2019-05-03 14:56:46 +03:00
|
|
|
$store_link = 'https://raw.githubusercontent.com/kleeja-official/store-catalog/master/catalog.json';
|
2019-04-16 20:25:20 +02:00
|
|
|
|
2019-04-16 22:54:33 +03:00
|
|
|
$catalog_plugins = fetch_remote_file($store_link);
|
2019-04-16 20:25:20 +02:00
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if ($catalog_plugins) {
|
2019-05-03 23:52:08 +03:00
|
|
|
$catalog_plugins = json_decode($catalog_plugins, true);
|
|
|
|
|
|
|
|
|
|
$store_plugins = [];
|
2019-04-16 22:54:33 +03:00
|
|
|
|
2019-04-16 20:25:20 +02:00
|
|
|
// make an arry for all plugins in kleeja store that not included in our server
|
2019-05-16 01:34:48 +03:00
|
|
|
foreach ($catalog_plugins as $plugin_info) {
|
|
|
|
|
if ($plugin_info['type'] != 'plugin') {
|
2019-05-16 00:41:21 +03:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
$store_plugins[$plugin_info['name']] = [
|
2019-05-16 01:34:48 +03:00
|
|
|
'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'],
|
2019-05-03 23:52:08 +03:00
|
|
|
];
|
2019-04-16 20:25:20 +02:00
|
|
|
}
|
2019-04-16 22:54:33 +03:00
|
|
|
|
2019-05-16 00:41:21 +03:00
|
|
|
// this plugin is hosted in our store
|
2019-05-16 01:34:48 +03:00
|
|
|
if (isset($store_plugins[$plugin_name])) {
|
2019-04-16 20:25:20 +02:00
|
|
|
// check if the version of the plugin is compatible with our kleeja version or not
|
|
|
|
|
if (
|
2019-05-16 00:41:21 +03:00
|
|
|
version_compare(strtolower($store_plugins[$plugin_name]['kj_min_version']), KLEEJA_VERSION, '<=')
|
|
|
|
|
&& version_compare(strtolower($store_plugins[$plugin_name]['kj_max_version']), KLEEJA_VERSION, '>=')
|
2019-05-03 23:52:08 +03:00
|
|
|
) {
|
2019-05-16 00:41:21 +03:00
|
|
|
$plugin_name_link = $store_plugins[$plugin_name]['url'];
|
2019-04-16 22:54:33 +03:00
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
$plugin_archive = fetch_remote_file($plugin_name_link, PATH.'cache/'.$plugin_name.'.zip', 60, false, 10, true);
|
2019-04-16 22:54:33 +03:00
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if ($plugin_archive) {
|
|
|
|
|
if (file_exists(PATH.'cache/'.$plugin_name.'.zip')) {
|
2019-04-16 20:25:20 +02:00
|
|
|
$zip = new ZipArchive();
|
2019-05-03 23:52:08 +03:00
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if ($zip->open(PATH.'cache/'.$plugin_name.'.zip') === true) {
|
|
|
|
|
if ($zip->extractTo(PATH.KLEEJA_PLUGINS_FOLDER)) {
|
2019-04-16 20:25:20 +02:00
|
|
|
// we dont need the zip file anymore
|
2019-05-16 01:34:48 +03:00
|
|
|
kleeja_unlink(PATH.'cache/'.$plugin_name.'.zip');
|
2019-04-16 22:54:33 +03:00
|
|
|
|
2019-05-15 00:48:58 +03:00
|
|
|
// uploaded plugin's archive has different name, so we change it
|
|
|
|
|
rename(
|
2019-05-16 01:34:48 +03:00
|
|
|
PATH.KLEEJA_PLUGINS_FOLDER.'/'.trim($zip->getNameIndex(0), '/'),
|
|
|
|
|
PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name
|
2019-05-15 00:48:58 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$zip->close();
|
2019-04-16 22:54:33 +03:00
|
|
|
|
2019-04-16 20:25:20 +02:00
|
|
|
// download or update msg
|
2019-05-16 01:34:48 +03:00
|
|
|
$adminAjaxContent = '1:::'.sprintf($lang[$is_update ? 'ITEM_UPDATED' : 'ITEM_DOWNLOADED'], $plugin_name);
|
2019-05-03 23:52:08 +03:00
|
|
|
|
2019-05-15 00:48:58 +03:00
|
|
|
//in case of update, delete back up version
|
2019-05-16 01:34:48 +03:00
|
|
|
if (is_dir(PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name.'_backup')) {
|
|
|
|
|
kleeja_unlink(PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name.'_backup');
|
2019-05-15 00:48:58 +03:00
|
|
|
}
|
2019-05-16 01:34:48 +03:00
|
|
|
} else {
|
|
|
|
|
$adminAjaxContent = '1003:::'.sprintf($lang['EXTRACT_ZIP_FAILED'], KLEEJA_PLUGINS_FOLDER);
|
2019-04-16 20:25:20 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-05-16 01:34:48 +03:00
|
|
|
} else {
|
|
|
|
|
$adminAjaxContent = '1004:::'.$lang['DOWNLOADED_FILE_NOT_FOUND'];
|
2019-04-16 20:25:20 +02:00
|
|
|
}
|
2019-05-16 01:34:48 +03:00
|
|
|
} else {
|
|
|
|
|
$adminAjaxContent = '1005:::'.$lang['STORE_SERVER_ERROR'];
|
2019-04-16 20:25:20 +02:00
|
|
|
}
|
2019-05-16 01:34:48 +03:00
|
|
|
} else {
|
|
|
|
|
$adminAjaxContent = '1006:::'.$lang['PACKAGE_N_CMPT_KLJ'];
|
2019-04-16 20:25:20 +02:00
|
|
|
}
|
2019-05-16 01:34:48 +03:00
|
|
|
} else {
|
|
|
|
|
$adminAjaxContent = '1007:::'.sprintf($lang['PACKAGE_REMOTE_FILE_MISSING'], $plugin_name);
|
2019-04-16 20:25:20 +02:00
|
|
|
}
|
2019-05-16 01:34:48 +03:00
|
|
|
} else {
|
|
|
|
|
$adminAjaxContent = '1008:::'.$lang['STORE_SERVER_ERROR'];
|
2019-04-16 20:25:20 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-15 00:48:58 +03:00
|
|
|
//in case of update failure, rollback to current plugin version
|
2019-05-16 01:34:48 +03:00
|
|
|
if (strpos($adminAjaxContent, '1:::') === false) {
|
|
|
|
|
if (is_dir(PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name.'_backup')) {
|
2019-05-15 00:48:58 +03:00
|
|
|
rename(
|
2019-05-16 01:34:48 +03:00
|
|
|
PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name.'_backup',
|
|
|
|
|
PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name
|
2019-05-15 00:48:58 +03:00
|
|
|
);
|
|
|
|
|
}
|
2019-04-16 22:54:33 +03:00
|
|
|
}
|
2019-04-16 20:25:20 +02:00
|
|
|
|
2019-04-16 22:54:33 +03:00
|
|
|
break;
|
2019-05-16 00:41:21 +03:00
|
|
|
case 'dfolder':
|
|
|
|
|
|
|
|
|
|
$plugin_name = preg_replace('/[^a-z0-9_\-\.]/i', '', g('plg'));
|
|
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
$plugin_folder_path = PATH.KLEEJA_PLUGINS_FOLDER.'/'.$plugin_name;
|
2019-05-10 15:29:16 +02:00
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if (is_dir($plugin_folder_path)) {
|
|
|
|
|
if (! is_writable($plugin_folder_path)) {
|
|
|
|
|
@chmod($plugin_folder_path, K_DIR_CHMOD);
|
2019-05-16 00:41:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kleeja_unlink($plugin_folder_path);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-16 01:34:48 +03:00
|
|
|
if (! is_dir($plugin_folder_path)) {
|
|
|
|
|
kleeja_admin_info(sprintf($lang['ITEM_DELETED'], $plugin_name), $action.'&case=local');
|
2019-05-10 15:29:16 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-16 00:41:21 +03:00
|
|
|
kleeja_admin_err($lang['ERROR_TRY_AGAIN'], $action);
|
2019-05-10 15:29:16 +02:00
|
|
|
|
|
|
|
|
break;
|
2018-01-09 02:09:07 +03:00
|
|
|
endswitch;
|