enhancement to styles page

This commit is contained in:
Abdulrahman
2019-05-16 00:41:21 +03:00
parent 28e8258872
commit 7fe5cf2564
10 changed files with 645 additions and 257 deletions

View File

@@ -23,30 +23,30 @@ if (! defined('IN_ADMIN'))
$case = g('case', 'str', 'installed');
//set _get form key
$GET_FORM_KEY = kleeja_add_form_key_get('PLUGINS_FORM_KEY');
$GET_FORM_KEY = kleeja_add_form_key_get('adm_plugins_get');
$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_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_delete_folder_link = ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=delete_folder&' . $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' , 'delete_folder']))
if (! empty($case) && in_array($case, ['install', 'uninstall', 'enable', 'disable' , 'download' , 'dfolder']))
{
if (! kleeja_check_form_key_get('PLUGINS_FORM_KEY'))
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'))
@@ -125,15 +125,12 @@ switch ($case):
{
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',
]
);
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',
]);
}
}
}
@@ -151,16 +148,16 @@ switch ($case):
}
// plugins avilable in kleeja remote catalog
if (! ($catalog_plugins = $cache->get('catalog_plugins')))
if (! ($store_catalog = $cache->get('store_catalog')))
{
$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);
$store_catalog = fetch_remote_file($store_link);
$store_catalog = json_decode($store_catalog, true);
if (json_last_error() == JSON_ERROR_NONE)
{
$cache->save('catalog_plugins', $catalog_plugins);
$cache->save('store_catalog', $store_catalog);
}
}
@@ -169,8 +166,13 @@ switch ($case):
$store_plugins = [];
$available_plugins_names = array_column($available_plugins, 'name');
foreach ($catalog_plugins as $plugin_info)
foreach ($store_catalog as $plugin_info)
{
if ($plugin_info['type'] != 'plugin')
{
continue;
}
if ($case == 'store' && (in_array($plugin_info['name'], $available_plugins_names) ||
! empty($installed_plugins[$plugin_info['name']]))
) {
@@ -337,7 +339,7 @@ switch ($case):
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['PACKAGE_N_CMPT_KLJ'] . '<br>k:' . KLEEJA_VERSION . '|<|p.min:' . $plugin_info['plugin_kleeja_version_min'],
true, '', true, ADMIN_PATH . '?cp=' . basename(__file__, '.php')
);
@@ -349,7 +351,7 @@ 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['PACKAGE_N_CMPT_KLJ'] . '<br>k:' . KLEEJA_VERSION . '|>|p.max:' . $plugin_info['plugin_kleeja_version_max'],
true, '', true, ADMIN_PATH . '?cp=' . basename(__file__, '.php')
);
@@ -473,7 +475,7 @@ switch ($case):
$SQL->build($query_del);
//show done, msg
$text = '<h3>' . $lang['PLUGIN_DELETED'] . '</h3>';
$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';
@@ -537,23 +539,23 @@ switch ($case):
kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS']);
}
$download_plugin = g('plg');
$plugin_name = g('plg');
$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 . '/' . $download_plugin . '/init.php'))
if (file_exists(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name . '/init.php'))
{
$is_update = true;
if (! rename(
PATH . KLEEJA_PLUGINS_FOLDER . '/' . $download_plugin,
PATH . KLEEJA_PLUGINS_FOLDER . '/' . $download_plugin . '_backup'
PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name,
PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name . '_backup'
))
{
if (is_dir(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $download_plugin))
if (is_dir(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name))
{
kleeja_unlink(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $download_plugin);
kleeja_unlink(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name);
}
}
}
@@ -572,6 +574,11 @@ switch ($case):
// 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')
{
continue;
}
$store_plugins[$plugin_info['name']] = [
'name' => $plugin_info['name'] ,
'plg_version' => $plugin_info['file']['version'] ,
@@ -581,46 +588,46 @@ switch ($case):
];
}
// // => this plugin is hosted in our store
if (isset($store_plugins[$download_plugin]))
// this plugin is hosted in our store
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[$download_plugin]['kj_min_version']), KLEEJA_VERSION, '<=')
&& version_compare(strtolower($store_plugins[$download_plugin]['kj_max_version']), KLEEJA_VERSION, '>=')
version_compare(strtolower($store_plugins[$plugin_name]['kj_min_version']), KLEEJA_VERSION, '<=')
&& version_compare(strtolower($store_plugins[$plugin_name]['kj_max_version']), KLEEJA_VERSION, '>=')
) {
$download_plugin_link = $store_plugins[$download_plugin]['url'];
$plugin_name_link = $store_plugins[$plugin_name]['url'];
$downloaded_plugin_zip = fetch_remote_file($download_plugin_link, PATH . 'cache/' . $download_plugin . '.zip', 60, false, 10, true);
$plugin_archive = fetch_remote_file($plugin_name_link, PATH . 'cache/' . $plugin_name . '.zip', 60, false, 10, true);
if ($downloaded_plugin_zip)
if ($plugin_archive)
{
if (file_exists(PATH . 'cache/' . $download_plugin . '.zip'))
if (file_exists(PATH . 'cache/' . $plugin_name . '.zip'))
{
$zip = new ZipArchive();
if ($zip->open(PATH . 'cache/' . $download_plugin . '.zip') === true)
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/' . $download_plugin . '.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 . '/' . $download_plugin
PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name
);
$zip->close();
// download or update msg
$adminAjaxContent = '1:::' . sprintf($lang[$is_update ? 'PLUGIN_UPDATED' : 'PLUGIN_DOWNLOADED'], $download_plugin);
$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 . '/' . $download_plugin . '_backup'))
if (is_dir(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name . '_backup'))
{
kleeja_unlink(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $download_plugin . '_backup');
kleeja_unlink(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name . '_backup');
}
}
else
@@ -631,38 +638,38 @@ switch ($case):
}
else
{
$adminAjaxContent = '1004:::' . $lang['PLUGIN_FILE_NOT_FOUND'];
$adminAjaxContent = '1004:::' . $lang['DOWNLOADED_FILE_NOT_FOUND'];
}
}
else
{
$adminAjaxContent = '1005:::' . $lang['PLUGINS_SERVER_ERROR'];
$adminAjaxContent = '1005:::' . $lang['STORE_SERVER_ERROR'];
}
}
else
{
$adminAjaxContent = '1006:::' . $lang['PLUGIN_N_CMPT_KLJ'];
$adminAjaxContent = '1006:::' . $lang['PACKAGE_N_CMPT_KLJ'];
}
}
else
{
$adminAjaxContent = '1007:::' . sprintf($lang['PLUGIN_REMOTE_FILE_MISSING'], $download_plugin);
$adminAjaxContent = '1007:::' . sprintf($lang['PACKAGE_REMOTE_FILE_MISSING'], $plugin_name);
}
}
else
{
$adminAjaxContent = '1008:::' . $lang['PLUGINS_SERVER_ERROR'];
$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 . '/' . $download_plugin . '_backup'))
if (is_dir(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name . '_backup'))
{
rename(
PATH . KLEEJA_PLUGINS_FOLDER . '/' . $download_plugin . '_backup',
PATH . KLEEJA_PLUGINS_FOLDER . '/' . $download_plugin
PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name . '_backup',
PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name
);
}
}
@@ -670,21 +677,30 @@ switch ($case):
break;
case 'delete_folder':
case 'dfolder':
$plugin_folder = g('plg');
$plugin_name = preg_replace('/[^a-z0-9_\-\.]/i', '', g('plg'));
$plugin_folder_name = PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_folder;
$plugin_folder_path = PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_name;
if (is_dir($plugin_folder_name))
if (is_dir($plugin_folder_path))
{
kleeja_unlink($plugin_folder_name);
if (! is_writable($plugin_folder_path))
{
chmod($plugin_folder_path, K_DIR_CHMOD);
}
kleeja_unlink($plugin_folder_path);
}
kleeja_admin_info(
sprintf($lang['PLG_SUCSS_DEL'], $plugin_folder),
ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&amp;case=local'
);
if (! is_dir($plugin_folder_path))
{
kleeja_admin_info(sprintf($lang['ITEM_DELETED'], $plugin_name), $action . '&amp;case=local');
}
kleeja_admin_err($lang['ERROR_TRY_AGAIN'], $action);
break;

View File

@@ -13,47 +13,186 @@ if (! defined('IN_ADMIN'))
exit();
}
//current secondary menu action
$current_smt = preg_replace('/[^a-z0-9_]/i', '', g('smt', 'str', 'general'));
$action = ADMIN_PATH . '?cp=' . basename(__file__, '.php');
$H_FORM_KEYS = kleeja_add_form_key('adm_styles');
//set _get form key
$GET_FORM_KEY = kleeja_add_form_key_get('adm_styles_get');
$H_FORM_KEYS = kleeja_add_form_key('adm_styles');
//for style ..
$stylee = 'admin_styles';
$action = ADMIN_PATH . '?cp=' . basename(__file__, '.php');
$style_select_link = $action . '&amp;case=select&amp;' . $GET_FORM_KEY . '&amp;style=';
$style_download_link = $action . '&amp;case=download&amp;' . $GET_FORM_KEY . '&amp;style=';
$style_delete_link = $action . '&amp;case=dfolder&amp;' . $GET_FORM_KEY . '&amp;style=';
$style_upload_link = $action . '&amp;case=upload';
$stylee = 'admin_styles';
$case = g('case', 'str', 'local');
//after submit
if (ip('style_choose') || ig('style_choose'))
//check _GET Csrf token
if (! empty($case) && in_array($case, ['select', 'download', 'dfolder']))
{
$style_id = ip('style_choose') ? p('style_choose') : g('style_choose');
$style_id = preg_replace('/[^a-z0-9_\-\.]/i', '', $style_id);
//if empty, let's ignore it
if (empty($style_id))
if (! kleeja_check_form_key_get('adm_styles_get'))
{
redirect(basename(ADMIN_PATH) . '?cp=' . basename(__file__, '.php'));
header('HTTP/1.0 401 Unauthorized');
kleeja_admin_err($lang['INVALID_GET_KEY'], $action);
}
}
//check _POST Csrf token
if (ip('newstyle'))
{
if (! kleeja_check_form_key('adm_styles'))
{
header('HTTP/1.0 401 Unauthorized');
kleeja_admin_err($lang['INVALID_FORM_KEY'], true, $lang['ERROR'], true, $action);
}
// make style as default
$case = 'upload';
}
//check _GET Csrf token
if (isset($_REQUEST['home']) && ! kleeja_check_form_key_get('adm_start_actions'))
switch ($case):
default:
case 'local':
case 'store':
//get styles
$available_styles = [];
if ($dh = @opendir(PATH . 'styles'))
{
kleeja_admin_err($lang['INVALID_GET_KEY'], true, $lang['ERROR'], true, basename(ADMIN_PATH) . '?cp=start', 2);
while (false !== ($folder_name = readdir($dh)))
{
if (is_dir(PATH . 'styles/' . $folder_name) && preg_match('/[a-z0-9_.]{3,}/', $folder_name))
{
//info
$style_info_arr = [
'name' => $folder_name,
'desc' => '',
'copyright' => '',
'version' => ''
];
if (($style_info = kleeja_style_info($folder_name)) != false)
{
foreach (['name', 'desc', 'copyright', 'version'] as $InfoKey)
{
if (array_key_exists($InfoKey, $style_info))
{
if (is_array($style_info[$InfoKey]))
{
$style_info_arr[$InfoKey] = ! empty($style_info[$InfoKey][$config['language']])
? htmlspecialchars($style_info[$InfoKey][$config['language']])
: htmlspecialchars($style_info[$InfoKey]['en']);
}
else
{
$style_info_arr[$InfoKey] = htmlspecialchars($style_info[$InfoKey]);
}
}
}
}
$available_styles[$folder_name] = [
'name' => $folder_name,
'is_default' => $config['style'] == $folder_name ? true : false,
'link_mk_default' => basename(ADMIN_PATH) . '?cp=' . basename(__file__, '.php') . '&amp;style_choose=' . $folder_name,
'icon' => file_exists(PATH . 'styles/' . $folder_name . '/screenshot.png')
? PATH . 'styles/' . $folder_name . '/screenshot.png'
: $STYLE_PATH_ADMIN . 'images/style.png',
'info' => $style_info_arr
];
}
}
@closedir($dh);
}
//do not proceed if not store case
if (! in_array($case, ['store', 'check']))
{
break;
}
// plugins avilable in kleeja remote 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)
{
$cache->save('store_catalog', $store_catalog);
}
}
// make an array for all styles in kleeja remote catalog
// that are not exsisted locally.
$store_styles = [];
$available_styles_names = array_column($available_styles, 'name');
foreach ($store_catalog as $style_info)
{
if ($style_info['type'] != 'style')
{
continue;
}
if ($case == 'store' && ! empty($available_styles[$style_info['name']]))
{
continue;
}
// is there a new version of this in the store
elseif (
$case == 'check' && (! empty($available_styles[$style_info['name']]['version']) &&
version_compare(
strtolower($available_styles[$style_info['name']]['version']),
strtolower($style_info['file']['version']),
'>='
) || empty($available_styles[$style_info['name']]))
) {
continue;
}
$store_styles[$style_info['name']] = [
'name' => $style_info['name'],
'developer' => $style_info['developer'],
'version' => $style_info['file']['version'],
'title' => ! empty($style_info['title'][$config['language']]) ? $style_info['title'][$config['language']] : $style_info['title']['en'],
'website' => $style_info['website'],
'current_version' => ! empty($available_styles[$style_info['name']]) ? strtolower($available_styles[$style_info['name']]['version']) : '',
'kj_min_version' => $style_info['kleeja_version']['min'],
'kj_max_version' => $style_info['kleeja_version']['max'],
'kj_version_cmtp' => sprintf($lang['KLJ_VER_NO_PLUGIN'], $style_info['kleeja_version']['min'], $style_info['kleeja_version']['max']),
'icon' => $style_info['icon'],
'NotCompatible' => version_compare(strtolower($style_info['kleeja_version']['min']), KLEEJA_VERSION, '<=')
&& version_compare(strtolower($style_info['kleeja_version']['max']), KLEEJA_VERSION, '>=')
? false : true,
];
}
$store_styles_count = sizeof($store_styles);
break;
case 'select':
$style_name = preg_replace('/[^a-z0-9_\-\.]/i', '', g('style'));
//if empty, let's ignore it
if (empty($style_name))
{
redirect(basename(ADMIN_PATH) . '?cp=' . basename(__file__, '.php'));
}
//
//check if this style depend on other style and
//check kleeja version that required by this style
//
if (($style_info = kleeja_style_info($style_id)) != false)
if (($style_info = kleeja_style_info($style_name)) != false)
{
if (isset($style_info['depend_on']) && ! file_exists(PATH . 'styles/' . $style_info['depend_on']))
{
@@ -103,29 +242,25 @@ if (ip('style_choose') || ig('style_choose'))
//make it as default
update_config('style', $style_id);
update_config('style', $style_name);
update_config('style_depend_on', isset($style_info['depend_on']) ? $style_info['depend_on'] : '');
//delete all cache to get new style
delete_cache('', true);
//show msg
kleeja_admin_info(sprintf($lang['STYLE_NOW_IS_DEFAULT'], htmlspecialchars($style_id)), true, '', true, basename(ADMIN_PATH) . '?cp=' . (isset($_REQUEST['home']) ? 'start' : basename(__file__, '.php')));
}
elseif (ip('newstyle'))
{
kleeja_admin_info(sprintf($lang['STYLE_NOW_IS_DEFAULT'], $style_name), $action);
break;
case 'upload':
if (intval($userinfo['founder']) !== 1)
{
$ERRORS[] = $lang['HV_NOT_PRVLG_ACCESS'];
}
if (! kleeja_check_form_key('adm_styles'))
{
kleeja_admin_err($lang['INVALID_FORM_KEY'], true, $lang['ERROR'], true, $action);
}
$ERRORS = [];
//is uploaded?
@@ -135,7 +270,6 @@ elseif (ip('newstyle'))
}
//extract it to plugins folder
if (! sizeof($ERRORS))
{
@@ -176,61 +310,190 @@ elseif (ip('newstyle'))
{
kleeja_admin_err('- ' . implode('<br>- ', $ERRORS), $action);
}
}
break;
//get styles
$arr = [];
case 'dfolder':
if ($dh = @opendir(PATH . 'styles'))
{
while (false !== ($folder_name = readdir($dh)))
{
if (is_dir(PATH . 'styles/' . $folder_name) && preg_match('/[a-z0-9_.]{3,}/', $folder_name))
$style_name = preg_replace('/[^a-z0-9_\-\.]/i', '', g('style'));
//can not delete default style
if ($config['style'] === $style_name)
{
kleeja_admin_info($lang['CANT_DEL_DEFAULT_STYLE'], true, '', true, $action);
}
//info
$style_info_arr =
[
'name' => $folder_name,
'desc' => '',
'copyright'=> '',
'version' => ''
];
$style_folder_path = PATH . 'styles/' . $style_name;
if (($style_info = kleeja_style_info($folder_name)) != false)
if (is_dir($style_folder_path))
{
if (! is_writable($style_folder_path))
{
foreach (['name', 'desc', 'copyright', 'version'] as $InfoKey)
{
if (array_key_exists($InfoKey, $style_info))
{
if (is_array($style_info[$InfoKey]))
{
$style_info_arr[$InfoKey] = ! empty($style_info[$InfoKey][$config['language']])
? htmlspecialchars($style_info[$InfoKey][$config['language']])
: htmlspecialchars($style_info[$InfoKey]['en']);
}
else
{
$style_info_arr[$InfoKey] = htmlspecialchars($style_info[$InfoKey]);
}
}
}
chmod($style_folder_path, K_DIR_CHMOD);
}
$arr[] =
[
'style_name' => $folder_name,
'is_default' => $config['style'] == $folder_name ? true : false,
'link_mk_default' => basename(ADMIN_PATH) . '?cp=' . basename(__file__, '.php') . '&amp;style_choose=' . $folder_name,
'icon' => file_exists(PATH . 'styles/' . $folder_name . '/screenshot.png')
? PATH . 'styles/' . $folder_name . '/screenshot.png'
: $STYLE_PATH_ADMIN . 'images/style.png',
'info' => $style_info_arr
];
kleeja_unlink($style_folder_path);
}
if (! is_dir($style_folder_path))
{
kleeja_admin_info(sprintf($lang['ITEM_DELETED'], $style_name), $action);
}
kleeja_admin_err($lang['ERROR_TRY_AGAIN'], $action);
break;
case 'download':
if (intval($userinfo['founder']) !== 1)
{
header('HTTP/1.0 401 Unauthorized');
kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS']);
}
$style_name = g('style');
$is_update = false;
if (! is_writable(PATH . 'styles'))
{
chmod(PATH . 'styles', K_DIR_CHMOD);
}
//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'))
{
$is_update = true;
if (! rename(
PATH . 'styles/' . $style_name,
PATH . 'styles/' . $style_name . '_backup'
))
{
if (is_dir(PATH . 'styles/' . $style_name))
{
kleeja_unlink(PATH . 'styles/' . $style_name);
}
}
}
@closedir($dh);
}
// plugins avilable in kleeja store
$store_link = 'https://raw.githubusercontent.com/kleeja-official/store-catalog/master/catalog.json';
$catalog_styles = fetch_remote_file($store_link);
if ($catalog_styles)
{
$catalog_styles = json_decode($catalog_styles, true);
$store_styles = [];
// make an arry for all plugins in kleeja store that not included in our server
foreach ($catalog_styles as $style_info)
{
if ($style_info['type'] != 'style')
{
continue;
}
$store_styles[$style_info['name']] = [
'name' => $style_info['name'] ,
'plg_version' => $style_info['file']['version'] ,
'url' => $style_info['file']['url'] ,
'kj_min_version' => $style_info['kleeja_version']['min'] ,
'kj_max_version' => $style_info['kleeja_version']['max'] ,
];
}
// this style is hosted in our store
if (isset($store_styles[$style_name]))
{
// check if the version of the plugin is compatible with our kleeja version or not
if (
version_compare(strtolower($store_styles[$style_name]['kj_min_version']), KLEEJA_VERSION, '<=')
&& version_compare(strtolower($store_styles[$style_name]['kj_max_version']), KLEEJA_VERSION, '>=')
) {
$style_name_link = $store_styles[$style_name]['url'];
$style_archive = fetch_remote_file($style_name_link, PATH . 'cache/' . $style_name . '.zip', 60, false, 10, true);
if ($style_archive)
{
if (file_exists(PATH . 'cache/' . $style_name . '.zip'))
{
$zip = new ZipArchive();
if ($zip->open(PATH . 'cache/' . $style_name . '.zip') === true)
{
if ($zip->extractTo(PATH . 'styles'))
{
// we dont need the zip file anymore
kleeja_unlink(PATH . 'cache/' . $style_name . '.zip');
// uploaded style's archive has different name, so we change it
rename(
PATH . 'styles/' . trim($zip->getNameIndex(0), '/'),
PATH . 'styles/' . $style_name
);
$zip->close();
// download or update msg
$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'))
{
kleeja_unlink(PATH . 'styles/' . $style_name . '_backup');
}
}
else
{
$adminAjaxContent = '1003:::' . sprintf($lang['EXTRACT_ZIP_FAILED'], PATH . 'styles');
}
}
}
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'], $style_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 . 'styles/' . $style_name . '_backup'))
{
rename(
PATH . 'styles/' . $style_name . '_backup',
PATH . 'styles/' . $style_name
);
}
}
break;
endswitch;

View File

@@ -71,7 +71,7 @@ if (is_browser('ie6, ie8, ie7'))
$ADM_NOTIFICATIONS['IE6'] = ['id' => 'IE6', 'msg_type'=> 'error', 'title'=> $lang['NOTE'], 'msg'=> $lang['ADMIN_USING_IE6']];
}
//if upgrading from 1rc6 to 1.0, some files must be deleted !
//if upgrading from 1rc6 to 1.0, some files must be deleted !
if (file_exists(PATH . 'includes/adm/files.php') || file_exists(PATH . 'admin.php'))
{
$ADM_NOTIFICATIONS['old_files'] = ['id' => 'old_files', 'msg_type'=> 'info', 'title'=> $lang['NOTE'], 'msg'=> $lang['ADM_UNWANTED_FILES']];
@@ -89,8 +89,8 @@ $v = @unserialize($config['new_version']);
if (version_compare(strtolower(KLEEJA_VERSION), strtolower($v['version_number']), '<'))
{
$ADM_NOTIFICATIONS['up_ver_klj'] = [
'id' => 'up_ver_klj',//this not so important row
'msg_type'=> 'error', 'title'=> $lang['R_CHECK_UPDATE'],
'id' => 'up_ver_klj',//this not so important row
'msg_type'=> 'error', 'title'=> $lang['R_CHECK_UPDATE'],
'msg' => sprintf($lang['UPDATE_NOW_S'], KLEEJA_VERSION, $v['version_number']) . '<br />' . '<a href="http://www.kleeja.com/">www.kleeja.com</a>'
];
@@ -141,7 +141,7 @@ if (! empty($d_groups) && is_array($d_groups))
{
$ADM_NOTIFICATIONS['file_size_ini_low'] = [
'id' => 'file_size_ini_low',
'msg_type'=> 'info', 'title'=> $lang['NOTE'],
'msg_type'=> 'info', 'title'=> $lang['NOTE'],
'msg' => sprintf($lang['PHPINI_FILESIZE_SMALL'], readable_size($biggest_size), readable_size($upload_max_filesize_s))
];
}
@@ -166,7 +166,7 @@ if (! empty($d_groups) && is_array($d_groups))
{
$ADM_NOTIFICATIONS['post_m_size_ini_low'] = [
'id' => 'post_m_size_ini_low',
'msg_type'=> 'info', 'title'=> $lang['NOTE'],
'msg_type'=> 'info', 'title'=> $lang['NOTE'],
'msg' => sprintf($lang['PHPINI_MPOSTSIZE_SMALL'], $config['filesnum'], readable_size($post_max_size_s_must_be))
];
}
@@ -222,7 +222,7 @@ if (! file_exists(PATH . $config['foldername'] . '/thumbs') && (int) $config['th
//is there copyrights for translator ?
//is there copyrights for translator ?
$translator_copyrights = isset($lang['S_TRANSLATED_BY']) ? $lang['S_TRANSLATED_BY'] : false;
@@ -243,22 +243,6 @@ $image_last_visit = filter_exists('i_lastvisit', 'filter_uid', 'lastvisit', $use
//hurry, hurry section, get styles
$hurry_style_link = basename(ADMIN_PATH) . '?cp=m_styles&amp;sty_t=st&amp;method=2&amp;home=1&amp;smt=curstyle&amp;' . $GET_FORM_KEY . '&amp;style_choose=';
$hurry_styles_list = '';
if ($dh = @opendir(PATH . 'styles'))
{
while (($file = @readdir($dh)) !== false)
{
if (strpos($file, '.') === false && $file != '..' && $file != '.')
{
$hurry_styles_list .= '<option value="' . htmlspecialchars($file) . '"' . ($config['style'] == $file ? ' selected="selected"' : '') . '>' . $file . '</option>';
}
}
@closedir($dh);
}
//hurry, hurry section, get languages
$hurry_lang_link = basename(ADMIN_PATH) . '?cp=g_users&smt=general&amp;smt=group_data&' . $GET_FORM_KEY . '&amp;lang_change=';
$hurry_langs_list = '';
@@ -280,8 +264,8 @@ $hurry_groups_list .= '<option value="' . $config['default_group'] . '">' . $lan
foreach ($d_groups as $id=>$ddt)
{
$hurry_groups_list .= '<option value="' . $id . '">' .
str_replace(['{lang.ADMINS}', '{lang.USERS}', '{lang.GUESTS}'],
$hurry_groups_list .= '<option value="' . $id . '">' .
str_replace(['{lang.ADMINS}', '{lang.USERS}', '{lang.GUESTS}'],
[$lang['ADMINS'], $lang['USERS'], $lang['GUESTS']],
$d_groups[$id]['data']['group_name']) .
'</option>';
@@ -312,7 +296,7 @@ if ($cf_num > 3)
//get currently right now stats
$prv_files = get_actual_stats('files');
$prev_imgs = get_actual_stats('imgs');
$prev_date = date('d-n-Y');
$prev_date = date('d-n-Y');
$todayIsGone = false;
while ($row=$SQL->fetch_array($cf_result))