diff --git a/.php_cs b/.php_cs index 894a283..b754750 100644 --- a/.php_cs +++ b/.php_cs @@ -37,7 +37,11 @@ return PhpCsFixer\Config::create() 'visibility_required' => true, 'native_function_casing' => true, 'no_empty_comment' => true, - 'single_line_comment_style' => true + 'single_line_comment_style' => true, + 'phpdoc_add_missing_param_annotation' => true, + 'no_spaces_after_function_name' => true, + 'no_spaces_around_offset' => true, + 'no_spaces_inside_parenthesis' => true, ]) ->setFinder($finder) ->setIndent(" ") diff --git a/admin/Masmak/admin_check_update.html b/admin/Masmak/admin_check_update.html index 6634806..f9ded86 100755 --- a/admin/Masmak/admin_check_update.html +++ b/admin/Masmak/admin_check_update.html @@ -1,52 +1,137 @@ - - -
- +
+
+

+ {lang.LOADING} +

+ +
+
+

+ + + + + - - - - - - - -
    -
  • {lang.HOW_UPDATE_KLEEJA_STEP1}
  • -
  • {lang.HOW_UPDATE_KLEEJA_STEP2}
  • -
  • {lang.HOW_UPDATE_KLEEJA_STEP3} - -
  • -
- - - diff --git a/admin/Masmak/admin_plugins.html b/admin/Masmak/admin_plugins.html index bfcf248..8420bb7 100755 --- a/admin/Masmak/admin_plugins.html +++ b/admin/Masmak/admin_plugins.html @@ -98,6 +98,7 @@
{{name}}
+
@@ -196,4 +197,4 @@ -
\ No newline at end of file + diff --git a/includes/adm/j_plugins.php b/includes/adm/j_plugins.php index 8cf06c8..dffff94 100755 --- a/includes/adm/j_plugins.php +++ b/includes/adm/j_plugins.php @@ -34,10 +34,11 @@ $plugin_enable_link = ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&am $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_delete_folder_link = ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=delete_folder&' . $GET_FORM_KEY . '&plg='; //check _GET Csrf token -if (! empty($case) && in_array($case, ['install', 'uninstall', 'enable', 'disable' , 'download' , 'update'])) +if (! empty($case) && in_array($case, ['install', 'uninstall', 'enable', 'disable' , 'download' , 'update' , 'delete_folder'])) { if (! kleeja_check_form_key_get('PLUGINS_FORM_KEY')) { @@ -151,7 +152,7 @@ switch ($case): break; } - // plugins avilable in kleeja remote catalog + // plugins avilable in kleeja remote catalog if (! ($catalog_plugins = $cache->get('catalog_plugins'))) { $store_link = 'https://raw.githubusercontent.com/kleeja-official/store-catalog/master/catalog.json'; @@ -179,7 +180,7 @@ switch ($case): } // is there a new version of this in the store - elseif ($case == 'check' && (! empty($installed_plugins[$plugin_info['name']]) && + elseif ($case == 'check' && (! empty($installed_plugins[$plugin_info['name']]) && version_compare( strtolower($installed_plugins[$plugin_info['name']]['extra_info']['plugin_version']), strtolower($plugin_info['file']['version']), @@ -552,7 +553,7 @@ switch ($case): exit; } - // plugins avilable in kleeja store + // plugins avilable in kleeja store $store_link = 'https://raw.githubusercontent.com/kleeja-official/store-catalog/master/catalog.json'; $catalog_plugins = fetch_remote_file($store_link); @@ -581,7 +582,7 @@ 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_max_version']), KLEEJA_VERSION, '>=') ) { $download_plugin_link = $store_plugins[$download_plugin]['url']; @@ -610,14 +611,14 @@ switch ($case): // download or update msg kleeja_admin_info( sprintf($lang[ig('update') ? 'PLUGIN_UPDATED' : 'PLUGIN_DOWNLOADED'], $download_plugin), - ADMIN_PATH . '?cp=' . basename(__file__, '.php') + ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=local' ); exit; } else { - kleeja_admin_err($lang['EXTRACT_ZIP_FAILED']); + kleeja_admin_err(sprintf($lang['EXTRACT_ZIP_FAILED'], KLEEJA_PLUGINS_FOLDER)); } } } @@ -656,11 +657,29 @@ switch ($case): if (is_dir($plugin_folder_name)) { - delete_plugin_folder($plugin_folder_name); + kleeja_unlink($plugin_folder_name); } redirect($plugin_download_link . $update_plugin . '&update' ); break; + case 'delete_folder': + + $plugin_folder = g('plg'); + + $plugin_folder_name = PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_folder; + + if (is_dir($plugin_folder_name)) + { + kleeja_unlink($plugin_folder_name); + } + + kleeja_admin_info( + sprintf($lang['PLG_SUCSS_DEL'] , $plugin_folder), + ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=local' + ); + + break; + endswitch; diff --git a/includes/adm/p_check_update.php b/includes/adm/p_check_update.php index b72b236..344b6e1 100755 --- a/includes/adm/p_check_update.php +++ b/includes/adm/p_check_update.php @@ -13,56 +13,97 @@ if (! defined('IN_ADMIN')) exit(); } +set_time_limit(0); + +$current_version = KLEEJA_VERSION; +$new_version = unserialize($config['new_version']); +$new_version = empty($new_version['version_number']) + ? KLEEJA_VERSION + : $new_version['version_number']; +$backup_archive_path = PATH . 'cache/backup.zip'; +$GET_FORM_KEY = kleeja_add_form_key_get('UPDATER_FORM_KEY'); + +define('KLEEJA_VERSION_CHECK_LINK', 'https://api.github.com/repos/kleeja-official/kleeja/releases/latest'); +define('KLEEJA_LATEST_PACKAGE_LINK', 'https://api.github.com/repos/kleeja-official/kleeja/zipball/'); + $stylee = 'admin_check_update'; -$current_smt = preg_replace('/[^a-z0-9_]/i', '', g('smt', 'str', 'general')); +$current_smt = preg_replace('/[^a-z0-9_]/i', '', g('smt', 'str', 'general')); $update_link = $config['siteurl'] . 'install/update.php?lang=' . $config['language']; -//to prevent getting the url data for all cats -if ($current_smt == 'check'): +if (in_array($current_smt, ['update1', 'update2', 'update3'])) +{ + //only founders can do the upgrade process ... + if (intval($userinfo['founder']) !== 1) + { + header('HTTP/1.0 401 Unauthorized'); + kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS']); + } + + if (! kleeja_check_form_key_get('UPDATER_FORM_KEY')) + { + header('HTTP/1.0 401 Unauthorized'); + + kleeja_admin_err($lang['INVALID_GET_KEY']); + } +} + +//check latest version +if ($current_smt == 'check') +{ //get data from kleeja github repo if (! ($version_data = $cache->get('kleeja_repo_version'))) { - $github_data = fetch_remote_file('https://raw.githubusercontent.com/awssat/kleeja/master/includes/version.php', false, 6); + $github_data = fetch_remote_file(KLEEJA_VERSION_CHECK_LINK, false, 100); if (! empty($github_data)) { - preg_match_all('/define\(\'KLEEJA_VERSION\',\s{1,4}\'([^\']+)\'\);/', $github_data, $matches, PREG_SET_ORDER, 0); - $version_data = trim(htmlspecialchars($matches[0][1])); - $cache->save('kleeja_repo_version', $version_data, 3600 * 2); + $latest_release = json_decode($github_data, true); + $version_data = null; + + if (json_last_error() === JSON_ERROR_NONE) + { + $version_data = [ + 'version' => trim(htmlspecialchars($latest_release['tag_name'])), + 'info' => trim(htmlspecialchars($latest_release['body'])), + 'date' => trim(htmlspecialchars($latest_release['created_at'])), + ]; + $cache->save('kleeja_repo_version', $version_data, 3600 * 2); + } } } $error = 0; - if (empty($version_data)) + if (empty($version_data['version'])) { $text = $lang['ERROR_CHECK_VER']; $error = 1; } else { - if (version_compare(strtolower(KLEEJA_VERSION), strtolower($version_data), '<')) + if (version_compare(strtolower($current_version), strtolower($version_data['version']), '<')) { - $text = sprintf($lang['UPDATE_NOW_S'], KLEEJA_VERSION, strtolower($version_data)) . '

' . $lang['UPDATE_KLJ_NOW']; - $error = 1; + $text = sprintf($lang['UPDATE_NOW_S'], $current_version, strtolower($version_data['version'])) . + '::--x--::' . $version_data['info'] . '::--x--::' . $version_data['date']; + $error = 2; } - elseif (version_compare(strtolower(KLEEJA_VERSION), strtolower($version_data), '=')) + elseif (version_compare(strtolower($current_version), strtolower($version_data['version']), '=')) { $text = $lang['U_LAST_VER_KLJ']; } - elseif (version_compare(strtolower(KLEEJA_VERSION), strtolower($version_data), '>')) + elseif (version_compare(strtolower($current_version), strtolower($version_data['version']), '>')) { $text = $lang['U_USE_PRE_RE']; } else { - $text = $lang['ERROR_CHECK_VER'] . ' [code: ' . htmlspecialchars($version_data) . ']'; + $text = $lang['ERROR_CHECK_VER'] . ' [code: ' . htmlspecialchars($version_data['version']) . ']'; } } $data = [ - 'version_number' => $version_data, + 'version_number' => $version_data['version'], 'last_check' => time() ]; @@ -72,14 +113,10 @@ if ($current_smt == 'check'): delete_cache('data_config'); $adminAjaxContent = $error . ':::' . $text; - -elseif ($current_smt == 'general'): - -// if(!$error) -// { - - - +} +// home of update page +elseif ($current_smt == 'general') +{ //To prevent expected error [ infinit loop ] if (ig('show_msg')) { @@ -98,18 +135,265 @@ elseif ($current_smt == 'general'): } } + $showMessage = ig('show_msg'); +} +//1. download latest kleeja version +elseif ($current_smt == 'update1') +{ + if (! class_exists('ZipArchive')) + { + $adminAjaxContent = '930:::' . $lang['NO_ZIP_ARCHIVE']; + } + elseif (! version_compare(strtolower($current_version), strtolower($new_version), '<=')) + { + $adminAjaxContent = '940:::' . $lang['U_LAST_VER_KLJ']; + } + else + { + // downloaded the last package to cache folder + fetch_remote_file(KLEEJA_LATEST_PACKAGE_LINK . $new_version , PATH . "cache/kleeja-{$new_version}.zip", 60, false, 10, true); -// } + if (file_exists(PATH . "cache/kleeja-{$new_version}.zip")) + { + $adminAjaxContent = '1:::'; + file_put_contents(PATH . 'cache/step1.done', time()); + } + else + { + $adminAjaxContent = '2:::' . $lang['UPDATE_ERR_FETCH_PACKAGE']; + } + } +} +//2. extract new kleeja package, create backup zip file +elseif ($current_smt == 'update2') +{ + if (! file_exists(PATH . 'cache/step1.done')) + { + header('HTTP/1.0 401 Unauthorized'); + kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS']); + } -$showMessage = ig('show_msg'); + kleeja_unlink(PATH . 'cache/step1.done'); + + // let's extract the zip to cache + $zip = new ZipArchive; + + if ($zip->open(PATH . "cache/kleeja-{$new_version}.zip") == true) + { + // the name of folder after extracting it + // and we are sure that there is only one folder in the zip file + $ex_folder = trim($zip->getNameIndex(0), '/'); + $zip->extractTo(PATH . 'cache/'); + $zip->close(); + if(rename( + PATH . "cache/{$ex_folder}", + PATH . "cache/kleeja-{$new_version}" + ) === false) + { + copy( + PATH . "cache/{$ex_folder}", + PATH . "cache/kleeja-{$new_version}" + ); + + kleeja_unlink(PATH . "cache/{$ex_folder}"); + } + } + + // let's check if there any update files in install folder + $update_file = PATH . "cache/kleeja-{$new_version}/install/includes/update_schema.php"; + + if (file_exists($update_file)) + { + // move the update file from install folder to cache folder to include it later and delete install folder + // becuse if install folder is exists , it can make some problems if dev mode is not active + if(rename($update_file, PATH . 'cache/update_schema.php') === false) + { + copy($update_file, PATH . 'cache/update_schema.php'); + } + } + + // skip some folders + foreach (['cache', 'plugins', 'uploads', 'styles', 'install'] as $folder_name) + { + kleeja_unlink(PATH . "cache/kleeja-{$new_version}/{$folder_name}"); + } + + if (file_exists($backup_archive_path)) + { + kleeja_unlink($backup_archive_path); + } + + file_put_contents(PATH . 'cache/step2.done', time()); + + $adminAjaxContent = '1:::'; +} +//3. update, or rollback on failure +elseif ($current_smt == 'update3') +{ + if (! file_exists(PATH . 'cache/step2.done')) + { + header('HTTP/1.0 401 Unauthorized'); + kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS']); + } + + kleeja_unlink(PATH . 'cache/step2.done'); + + $backup = new ZipArchive; + + if ($backup->open($backup_archive_path, ZipArchive::CREATE) !== true) + { + header('HTTP/1.0 401 Unauthorized'); + kleeja_admin_err($lang['UPDATE_BACKUP_CREATE_FAILED']); + } + + // delete plugin folder function with some changes :) + $it = new RecursiveDirectoryIterator(PATH . "cache/kleeja-{$new_version}/", RecursiveDirectoryIterator::SKIP_DOTS); + $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); + + $update_failed = false; + $failed_files = $new_folders = []; + + //maintenance mode on + update_config('siteclose', 1); + + foreach ($files as $file) + { + if ($file->isFile()) + { + $file_path = str_replace("cache/kleeja-{$new_version}/", '', $file->getPathname()); + $file_dir = str_replace("cache/kleeja-{$new_version}/", '', $file->getPath()); + + // same, no need to replace + if (file_exists($file_path) && md5_file($file_path) == md5_file($file->getPathname())) + { + continue; + } + + //no folder? + if (! file_exists($file_dir)) + { + mkdir($file_dir, K_DIR_CHMOD, true); + array_push($new_folders, $file_dir); + } + + if (! is_writable($file_path)) + { + chmod($file_path, K_FILE_CHMOD); + } + + //back up current file + $backup->addFromString( + $file_path, + file_get_contents($file_path) + ); + + //copy file + if (file_put_contents( + $file_path, + file_get_contents($file->getPathname()) + ) === false) + { + + if (copy($file->getPathname(), $file_path) === false) + { + $update_failed = true; + array_push($failed_files, $file_path); + + break; + } + } + } + elseif ($file->isDir()) + { + // here is folder , when we finish update , we will delete all folders and files + if (! file_exists($file_path)) + { + mkdir($file_path, K_DIR_CHMOD, true); + array_push($new_folders, $file_path); + } + + continue; + } + } + + $backup->close(); + + if ($update_failed) + { + //rollback to backup + $zip = new ZipArchive; + $zip->open($backup_archive_path); + $zip->extractTo(PATH); + $zip->close(); + + foreach ($new_folders as $folder) + { + kleeja_unlink($folder); + } + + //maintenance mode off + update_config('siteclose', 0); + + $adminAjaxContent = '1002:::' . $lang['UPDATE_PROCESS_FAILED'] . (defined('DEV_STAGE') ? '[failed files: ' . implode(', ', $failed_files) . ']' : ''); + } + else + { + // we will include what we want to do in this file , and kleeja will done + if (file_exists($db_update_file = PATH . 'cache/update_schema.php')) + { + require_once $db_update_file; + + $all_db_updates = array_keys($update_schema); + + $available_db_updates = array_filter($all_db_updates, function ($v) use ($config) { + return $v > $config['db_version']; + }); + + sort($available_db_updates); + + if (sizeof($available_db_updates)) + { + foreach ($available_db_updates as $db_update_version) + { + $SQL->show_errors = false; + + if (isset($update_schema[$db_update_version]['sql']) + && sizeof($update_schema[$db_update_version]['sql']) > 0) + { + foreach ($update_schema[$db_update_version]['sql'] as $name=>$sql_content) + { + $SQL->query($sql_content); + } + } + + if (isset($update_schema[$db_update_version]['functions']) + && sizeof($update_schema[$db_update_version]['functions']) > 0) + { + foreach ($update_schema[$db_update_version]['functions'] as $n) + { + if (is_callable($n)) + { + $n(); + } + } + } -//end current_smt == general -endif; + $SQL->query( + "UPDATE `{$dbprefix}config` SET `value` = '" . $db_update_version . "' WHERE `name` = 'db_version'" + ); + } + } + } -//secondary menu -$go_menu = [ - 'general' => ['name'=>$lang['R_CHECK_UPDATE'], 'link'=> basename(ADMIN_PATH) . '?cp=p_check_update&smt=general', 'goto'=>'general', 'current'=> $current_smt == 'general'], - 'howto' => ['name'=>$lang['HOW_UPDATE_KLEEJA'], 'link'=> basename(ADMIN_PATH) . '?cp=p_check_update&smt=howto', 'goto'=>'howto', 'current'=> $current_smt == 'howto'], - 'site' => ['name'=>'Kleeja.com', 'link'=> 'http://www.kleeja.com', 'goto'=>'site', 'current'=> $current_smt == 'site'], -]; + //maintenance mode off + update_config('siteclose', 0); + + // after a success update, delete files and folders in cache + kleeja_unlink(PATH . "cache/kleeja-{$new_version}"); + kleeja_unlink(PATH . "cache/kleeja-{$new_version}.zip"); + delete_cache('', true); + + $adminAjaxContent = '1:::' . sprintf($lang['UPDATE_PROCESS_DONE'], $new_version); + } +} diff --git a/includes/common.php b/includes/common.php index 6da6ab9..57def01 100755 --- a/includes/common.php +++ b/includes/common.php @@ -37,7 +37,7 @@ if (! defined('PATH')) { define('__DIR__', dirname(__FILE__)); } - define('PATH', str_replace(DIRECTORY_SEPARATOR . 'includes', '', __DIR__) . DIRECTORY_SEPARATOR); + define('PATH', str_replace('/includes', '', __DIR__) . '/'); } //no config @@ -57,11 +57,15 @@ require_once PATH . KLEEJA_CONFIG_FILE; define('ADM_FILES_PATH', PATH . 'includes/adm'); //Report all errors, except notices -error_reporting( defined('DEV_STAGE') ? E_ALL : E_ALL ^ E_NOTICE); +error_reporting(defined('DEV_STAGE') ? E_ALL : E_ALL ^ E_NOTICE); /** * functions for start +* @param mixed $error_number +* @param mixed $error_string +* @param mixed $error_file +* @param mixed $error_line */ function kleeja_show_error($error_number, $error_string = '', $error_file = '', $error_line = '') { @@ -129,9 +133,9 @@ if (empty($dbname) || empty($dbuser)) exit; } -//include files .. & classes .. -$root_path = PATH; -// $db_type = isset($db_type) ? $db_type : 'mysqli'; +// solutions for hosts running under suexec, add define('HAS_SUEXEC', true) to config.php. +define('K_FILE_CHMOD', defined('HAS_SUEXEC') ? (0644 & ~umask()) : 0644); +define('K_DIR_CHMOD', defined('HAS_SUEXEC') ? (0755 & ~umask()) : 0755); include PATH . 'includes/functions_alternative.php'; include PATH . 'includes/version.php'; @@ -163,7 +167,7 @@ unset($dbpass); -$tpl = new kleeja_style; +$tpl = new kleeja_style; $usrcp = new usrcp; //then get caches @@ -310,10 +314,10 @@ if ( file_exists(PATH . 'install') && ! defined('IN_ADMIN') && ! defined('IN_LOGIN') && - ! defined('DEV_STAGE') && + ! defined('DEV_STAGE') && ! (defined('IN_GO') && in_array(g('go'), ['queue'])) && ! (defined('IN_UCP') && in_array(g('go'), ['captcha', 'login'])) - ) { +) { //Different message for admins! delete install folder kleeja_info((user_can('enter_acp') ? $lang['DELETE_INSTALL_FOLDER'] : $lang['WE_UPDATING_KLEEJA_NOW']), $lang['SITE_CLOSED']); } @@ -323,16 +327,16 @@ if ( $login_page = ''; if ( - $config['siteclose'] == '1' && - ! user_can('enter_acp') && - ! defined('IN_LOGIN') && - ! defined('IN_ADMIN') && + $config['siteclose'] == '1' && + ! user_can('enter_acp') && + ! defined('IN_LOGIN') && + ! defined('IN_ADMIN') && ! (defined('IN_GO') && in_array(g('go'), ['queue'])) && ! (defined('IN_UCP') && in_array(g('go'), ['captcha', 'login', 'register', 'logout'])) ) { //if download, images ? if ( - ( defined('IN_DOWNLOAD') && (ig('img') || ig('thmb') || ig('thmbf') || ig('imgf')) ) + (defined('IN_DOWNLOAD') && (ig('img') || ig('thmb') || ig('thmbf') || ig('imgf'))) || g('go', 'str', '') == 'queue' ) { @$SQL->close(); @@ -352,7 +356,8 @@ if ( //exceed total size if (($stat_sizes >= ($config['total_size'] *(1048576))) && ! defined('IN_LOGIN') && ! defined('IN_ADMIN')) -{// convert megabytes to bytes +{ + // convert megabytes to bytes // Send a 503 HTTP response code to prevent search bots from indexing the maintenace message header('HTTP/1.1 503 Service Temporarily Unavailable'); kleeja_info($lang['SIZES_EXCCEDED'], $lang['STOP_FOR_SIZE']); diff --git a/includes/functions.php b/includes/functions.php index ce9aaa7..9fdff49 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -22,7 +22,7 @@ if (! defined('IN_COMMON')) */ function kleeja_detecting_bots() { - global $SQL, $usrcp, $dbprefix, $config, $klj_session; + global $SQL, $dbprefix, $config; // get information .. $agent = $SQL->escape($_SERVER['HTTP_USER_AGENT']); @@ -97,7 +97,7 @@ function get_ban() // if the request is an image // if ( - ( defined('IN_DOWNLOAD') && (ig('img') || ig('thmb') || ig('thmbf') || ig('imgf')) ) + (defined('IN_DOWNLOAD') && (ig('img') || ig('thmb') || ig('thmbf') || ig('imgf'))) || g('go', 'str', '') == 'queue' ) { @$SQL->close(); @@ -271,8 +271,8 @@ function fetch_remote_file($url, $save_in = false, $timeout = 20, $head_only = f { @ini_set('default_socket_timeout', $timeout); } - $allow_url_fopen = function_exists('ini_get') - ? strtolower(@ini_get('allow_url_fopen')) + $allow_url_fopen = function_exists('ini_get') + ? strtolower(@ini_get('allow_url_fopen')) : strtolower(@get_cfg_var('allow_url_fopen')); if (function_exists('curl_init')) @@ -302,7 +302,7 @@ function fetch_remote_file($url, $save_in = false, $timeout = 20, $head_only = f @curl_exec($ch); curl_close($ch); fclose($out); - } + } if ($head_only) { @@ -548,7 +548,7 @@ function delete_cache($name, $all=false) if (file_exists($path_to_cache . '/' . $name)) { - $del = kleeja_unlink ($path_to_cache . '/' . $name, true); + $del = kleeja_unlink($path_to_cache . '/' . $name, true); } } @@ -577,23 +577,29 @@ function kleeja_unlink($filePath, $cache_file = false) //99.9% who use this if (function_exists('unlink')) { - return unlink($filePath); + if (is_dir($filePath)) + { + $it = new RecursiveDirectoryIterator($filePath, RecursiveDirectoryIterator::SKIP_DOTS); + $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); + + foreach ($files as $file) + { + if ($file->isDir()) + { + rmdir($file->getPathname()); + } + else + { + unlink($file->getPathname()); + } + } + return rmdir($filePath); + } + else + { + return unlink($filePath); + } } - //5% only who use this - //else if (function_exists('exec')) - //{ - // $out = array(); - // $return = null; - // exec('del ' . escapeshellarg(realpath($filepath)) . ' /q', $out, $return); - // return $return; - //} - //5% only who use this - //else if (function_exists('system')) - //{ - // $return = null; - // system ('del ' . escapeshellarg(realpath($filepath)) . ' /q', $return); - // return $return; - //} //just rename cache file if there is new thing elseif (function_exists('rename') && $cache_file) { @@ -1301,12 +1307,12 @@ function klj_clean_old_files($from = 0) //delete from folder .. if (file_exists($row['folder'] . '/' . $row['name'])) { - @kleeja_unlink ($row['folder'] . '/' . $row['name']); + @kleeja_unlink($row['folder'] . '/' . $row['name']); } //delete thumb - if (file_exists($row['folder'] . '/thumbs/' . $row['name'] )) + if (file_exists($row['folder'] . '/thumbs/' . $row['name'])) { - @kleeja_unlink ($row['folder'] . '/thumbs/' . $row['name'] ); + @kleeja_unlink($row['folder'] . '/thumbs/' . $row['name']); } $ids[] = $row['id']; @@ -1496,11 +1502,11 @@ function kleeja_log($text) return; } - $log_file = PATH . 'cache/kleeja_log.log'; - $l_c = @file_get_contents($log_file); - $fp = @fopen($log_file, 'w'); - @fwrite($fp, $text . ' [time : ' . date('H:i a, d-m-Y') . "] \r\n" . $l_c); - @fclose($fp); + file_put_contents( + PATH . 'cache/kleeja_log.log', + date_format(date_create(), 'Y-m-d h:i:s.ua') . ' | INFO | ' . $text . PHP_EOL, + FILE_APPEND | LOCK_EX + ); } @@ -1717,11 +1723,11 @@ function parse_serve_rule($regex, $args, $is_unicode = false) foreach ($parsed_args as $arg_key => $arg_value) { - if ( preg_match('/^\$/', $arg_value)) + if (preg_match('/^\$/', $arg_value)) { $match_number = ltrim($arg_value, '$'); - if ( isset($matches[$match_number])) + if (isset($matches[$match_number])) { $_GET[$arg_key] = $matches[$match_number]; } diff --git a/includes/functions_adm.php b/includes/functions_adm.php index cd51fdb..f6298c8 100755 --- a/includes/functions_adm.php +++ b/includes/functions_adm.php @@ -18,6 +18,13 @@ if (! defined('IN_COMMON')) * Print cp error function handler * * For admin +* @param mixed $msg +* @param mixed $navigation +* @param mixed $title +* @param mixed $exit +* @param mixed $redirect +* @param mixed $rs +* @param mixed $style */ function kleeja_admin_err($msg, $navigation = true, $title='', $exit = true, $redirect = false, $rs = 3, $style = 'admin_err') { @@ -237,7 +244,7 @@ function build_search_query($search) global $SQL; - $search['filename'] = ! isset($search['filename']) ? '' : $search['filename']; + $search['filename'] = ! isset($search['filename']) ? '' : $search['filename']; $search['username'] = ! isset($search['username']) ? '' : $search['username']; $search['than'] = ! isset($search['than']) ? '' : $search['than']; $search['size'] = ! isset($search['size']) ? '' : $search['size']; @@ -249,8 +256,8 @@ function build_search_query($search) $search['ext'] = ! isset($search['ext']) ? '' : $search['ext']; $search['user_ip'] = ! isset($search['user_ip']) ? '' : $search['user_ip']; - $file_namee = $search['filename'] != '' ? 'AND (f.real_filename LIKE \'%' . $SQL->escape($search['filename']) . '%\' OR f.name LIKE \'%' . $SQL->escape($search['filename']) . '%\')' : ''; - $usernamee = $search['username'] != '' ? 'AND u.name LIKE \'%' . $SQL->escape($search['username']) . '%\'' : ''; + $file_namee = $search['filename'] != '' ? 'AND (f.real_filename LIKE \'%' . $SQL->escape($search['filename']) . '%\' OR f.name LIKE \'%' . $SQL->escape($search['filename']) . '%\')' : ''; + $usernamee = $search['username'] != '' ? 'AND u.name LIKE \'%' . $SQL->escape($search['username']) . '%\'' : ''; $size_than = ' f.size ' . ($search['than']!=1 ? '<=' : '>=') . (intval($search['size']) * 1024) . ' '; $ups_than = $search['ups'] != '' ? 'AND f.uploads ' . ($search['uthan']!=1 ? '<' : '>') . intval($search['ups']) . ' ' : ''; $rep_than = $search['rep'] != '' ? 'AND f.report ' . ($search['rthan']!=1 ? '<' : '>') . intval($search['rep']) . ' ' : ''; @@ -296,7 +303,7 @@ function sync_total_files($files = true, $start = false) $start = ! $start ? $min_id : $start; $end = $start + $batch_size; - //now lets get this step's files number + //now lets get this step's files number unset($v, $result); $query['SELECT'] = 'COUNT(f.id) as num_files'; @@ -322,7 +329,7 @@ function sync_total_files($files = true, $start = false) //make it zero, firstly if ($first_loop) { - $update_query['SET'] = ($files ? 'files' : 'imgs') . '= 0'; + $update_query['SET'] = ($files ? 'files' : 'imgs') . '= 0'; $SQL->build($update_query); } @@ -358,7 +365,7 @@ function get_actual_stats($name) } /** - * check wether a start box is hidden or not + * check wether a start box is hidden or not * @param string $name box name * @return bool */ @@ -386,31 +393,3 @@ function adm_is_start_box_hidden($name) return in_array($name, $boxes); } - -/** - * delete plugin folder - * @param string $dir plugin folder path - * @return void - */ -function delete_plugin_folder($dir) -{ - $it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS); - $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); - - foreach ($files as $file) - { - if ($file->isLink()) - { - unlink($file->getPathname()); - } - elseif ($file->isDir()) - { - rmdir($file->getPathname()); - } - else - { - unlink($file->getPathname()); - } - } - rmdir($dir); -} diff --git a/includes/plugins.php b/includes/plugins.php index d0eec1d..233bc3a 100755 --- a/includes/plugins.php +++ b/includes/plugins.php @@ -36,7 +36,7 @@ class Plugins private $installed_plugins_info = []; - private $plugin_path = ''; + private $plugin_path = PATH . 'plugins'; private static $instance; @@ -55,7 +55,11 @@ class Plugins } - $this->plugin_path = PATH . KLEEJA_PLUGINS_FOLDER; + + if (defined('KLEEJA_PLUGINS_FOLDER')) + { + $this->plugin_path = PATH . KLEEJA_PLUGINS_FOLDER; + } // Get installed plugins $query = [ @@ -85,7 +89,7 @@ class Plugins { $dh = opendir($this->plugin_path); - while (false !== ($folder_name = readdir($dh))) + while ($dh !== false and false !== ($folder_name = readdir($dh))) { if (is_dir($this->plugin_path . '/' . $folder_name) && preg_match('/[a-z0-9_.]{3,}/', $folder_name)) { diff --git a/includes/style.php b/includes/style.php index 12f410c..bd1a1d5 100755 --- a/includes/style.php +++ b/includes/style.php @@ -140,7 +140,7 @@ class kleeja_style $html = preg_replace_callback('//i', ['kleeja_style', '_loop_callback'], $html); $html = preg_replace_callback(kleeja_style::reg('var'), ['kleeja_style', '_vars_callback'], $html); - $rep = + $rep = [ '/<\/(LOOP|IF|END|IS_BROWSER|UNLESS)>/i' => '', '//iU' => 'display("\\2"); ?>', @@ -364,8 +364,24 @@ class kleeja_style { $this->vars = &$GLOBALS; + $eval_on = false; + eval('$eval_on = true;'); + + $parsed_html = trim($this->_parse($html)); + ob_start(); - eval(' ?' . '>' . trim($this->_parse($html)) . '<' . '?php '); + + if($eval_on) + { + eval(' ?' . '>' . $parsed_html . '<' . '?php '); + } + else + { + $path = PATH . 'cache/tpl_' . md5($parsed_html) . '.php'; + file_put_contents($path, $parsed_html); + include_once $path; + } + $page = ob_get_contents(); ob_end_clean(); diff --git a/includes/version.php b/includes/version.php index 4f52189..49ec318 100755 --- a/includes/version.php +++ b/includes/version.php @@ -19,3 +19,7 @@ if (! defined('IN_COMMON')) define('KLEEJA_VERSION', '3.0.2'); define('KLEEJA_DB_VERSION', '9'); + +// Kleeja min requirements +define('MIN_PHP_VERSION', '7.0'); +define('MIN_MYSQL_VERSION', '4.2.2'); diff --git a/install/includes/default_values.php b/install/includes/default_values.php index b46d1dd..a573111 100755 --- a/install/includes/default_values.php +++ b/install/includes/default_values.php @@ -20,7 +20,7 @@ if (! defined('IN_COMMON')) $config_values = []; -// do it like this : +// do it like this : //$config_values = array('name', 'value', 'option', 'display_order', 'type', 'plg_id', 'dynamic'); // General settings @@ -45,7 +45,7 @@ $config_values[] = ['cookie_path', $cookie_data['cookie_path'], '', '15', 'advanced', 0, 0]; $config_values[] = ['cookie_secure', ($cookie_data['cookie_secure'] ? '1' : '0'), '\r\n ', '16', 'advanced', 0, 0]; -// Upload settings +// Upload settings $config_values[] = ['total_size', '10000000000', '', 17, 'upload', 0, 0]; $config_values[] = ['foldername', 'uploads', '', 18, 'upload', 0, 0]; $config_values[] = ['prefixname', '', '', 19, 'upload', 0, 0]; @@ -68,7 +68,7 @@ $config_values[] = ['filesnum_show', '1', '