/** * Running triggers for some actions * * @param string $trigger For example <i>admin/System/components/plugins/disable</i> * @param mixed $data For example ['name' => <i>plugin_name</i>] * * @return bool */ function run($trigger, $data = null) { if (!is_string($trigger)) { return true; } if (!$this->initialized) { $modules = array_keys(Config::instance()->components['modules']); foreach ($modules as $module) { _include_once(MODULES . '/' . $module . '/trigger.php', false); } unset($modules, $module); $plugins = get_files_list(PLUGINS, false, 'd'); if (!empty($plugins)) { foreach ($plugins as $plugin) { _include_once(PLUGINS . '/' . $plugin . '/trigger.php', false); } } unset($plugins, $plugin); $this->initialized = true; } if (!isset($this->triggers[$trigger]) || empty($this->triggers[$trigger])) { return true; } $return = true; foreach ($this->triggers[$trigger] as $closure) { if ($data === null) { $return = $return && ($closure() === false ? false : true); } else { $return = $return && ($closure($data) === false ? false : true); } } return $return; }
Trigger::instance()->run('admin/System/components/modules/enable', ['name' => $module_name]); unset($Cache->functionality, $Cache->languages); break; case 'disable': $module_data['active'] = 0; $a->save(); clean_pcache(); Trigger::instance()->run('admin/System/components/modules/disable', ['name' => $module_name]); unset($Cache->functionality, $Cache->languages); break; case 'remove': if ($module_name == 'System' || $module_data['active'] != '-1') { break; } $ok = true; get_files_list(MODULES . "/{$module_name}", false, 'fd', true, true, false, false, true, function ($item) use(&$ok) { if (is_writable($item)) { is_dir($item) ? @rmdir($item) : @unlink($item); } else { $ok = false; } }); if ($ok && @rmdir(MODULES . "/{$module_name}")) { unset($Config->components['modules'][$module_name]); $a->save(); } else { $a->save(false); } break; } }
/** * Recursively remove directory * * @param string $dirname Path to directory * * @return bool */ function rmdir_recursive($dirname) { if (!is_dir($dirname)) { return true; } get_files_list($dirname, false, 'fd', true, true, false, false, true, function ($item) { if (is_dir($item)) { @rmdir($item); } else { @unlink($item); } }); return @rmdir($dirname); }
* @package CleverStyle CMS * @subpackage System module * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2011-2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\System; use h, cs\Config, cs\Core, cs\Index, cs\Language, cs\Page, cs\User; $Config = Config::instance(); $L = Language::instance(); $Page = Page::instance(); $a = Index::instance(); $rc = $Config->route; $plugins = get_files_list(PLUGINS, false, 'd'); $a->buttons = false; if (isset($rc[2]) && !empty($rc[2]) && (isset($rc[3]) && !empty($rc[3]) || $rc[2] == 'remove')) { switch ($rc[2]) { case 'enable': if ($rc[3] == 'upload' && isset($_FILES['upload_plugin']) && $_FILES['upload_plugin']['tmp_name']) { switch ($_FILES['upload_plugin']['error']) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: $Page->warning($L->file_too_large); break; case UPLOAD_ERR_NO_TMP_DIR: $Page->warning($L->temporary_folder_is_missing); break; case UPLOAD_ERR_CANT_WRITE: $Page->warning($L->cant_write_file_to_disk);
$Index->cancel_button_back = true; $Index->content(h::{'button[type=submit][name=action][value=remove_confirmed]'}($L->yes) . h::{'input[type=hidden]'}(['name' => 'remove_theme_confirmed', 'value' => $_POST['remove_theme']])); return; break; case 'remove_confirmed': $theme = $_POST['remove_theme_confirmed']; if ($theme == 'CleverStyle' || $theme == $Config->core['theme']) { break; } $ok = true; get_files_list(THEMES . "/{$theme}", false, 'fd', true, true, false, false, true, function ($item) use(&$ok) { if (is_writable($item)) { is_dir($item) ? @rmdir($item) : @unlink($item); } else { $ok = false; } }); if ($ok && @rmdir(THEMES . "/{$theme}")) { $Index->save(); } else { $Index->save(false); } break; } } $Config->reload_themes(); $themes_for_removal = array_values(array_filter(get_files_list(THEMES, '/[^CleverStyle)]/', 'd'), function ($theme) use($Config) { return $theme != $Config->core['theme']; })); $Index->file_upload = true; $Index->content(h::{'table.cs-table-borderless.cs-left-even.cs-right-odd tr| td'}(core_select($Config->core['themes'], 'theme', 'change_theme', 'current_theme'), core_select($Config->core['color_schemes'][$Config->core['theme']], 'color_scheme', 'change_color_scheme')) . h::p(h::{'input[type=file][name=upload_theme]'}() . h::{'button[type=submit][name=action][value=upload]'}(h::icon('upload') . $L->upload_and_install_update_theme, ['formaction' => $Index->action])) . ($themes_for_removal ? h::p(h::{'select[name=remove_theme]'}($themes_for_removal) . h::{'button[type=submit][name=action][value=remove]'}(h::icon('trash-o') . $L->complete_theme_removal, ['formaction' => $Index->action])) : ''));
/** * Getting of JavaScript and CSS files list to be included * * @param bool $absolute If <i>true</i> - absolute paths to files will be returned * * @return array */ protected function get_includes_list($absolute = false) { $theme_dir = THEMES . "/{$this->theme}"; $scheme_dir = "{$theme_dir}/schemes/{$this->color_scheme}"; $theme_pdir = "themes/{$this->theme}"; $scheme_pdir = "{$theme_pdir}/schemes/{$this->color_scheme}"; $get_files = function ($dir, $prefix_path) { $extension = explode('/', $dir); $extension = array_pop($extension); $list = get_files_list($dir, "/(.*)\\.{$extension}/i", 'f', $prefix_path, true, false, '!include') ?: []; sort($list); return $list; }; /** * Get includes of system and theme + color scheme */ $includes = ['css' => array_merge($get_files(CSS, $absolute ? true : 'includes/css'), $get_files("{$theme_dir}/css", $absolute ? true : "{$theme_pdir}/css"), $get_files("{$scheme_dir}/css", $absolute ? true : "{$scheme_pdir}/css")), 'js' => array_merge($get_files(JS, $absolute ? true : 'includes/js'), $get_files("{$theme_dir}/js", $absolute ? true : "{$theme_pdir}/js"), $get_files("{$scheme_dir}/js", $absolute ? true : "{$scheme_pdir}/js"))]; unset($theme_dir, $scheme_dir, $theme_pdir, $scheme_pdir); $Config = Config::instance(); foreach ($Config->components['modules'] as $module_name => $module_data) { if ($module_data['active'] == -1) { continue; } $includes['css'] = array_merge($includes['css'], $get_files(MODULES . "/{$module_name}/includes/css", $absolute ? true : "components/modules/{$module_name}/includes/css")); $includes['js'] = array_merge($includes['js'], $get_files(MODULES . "/{$module_name}/includes/js", $absolute ? true : "components/modules/{$module_name}/includes/js")); } unset($module_name, $module_data); foreach ($Config->components['plugins'] as $plugin_name) { $includes['css'] = array_merge($includes['css'], $get_files(PLUGINS . "/{$plugin_name}/includes/css", $absolute ? true : "components/plugins/{$plugin_name}/includes/css")); $includes['js'] = array_merge($includes['js'], $get_files(PLUGINS . "/{$plugin_name}/includes/js", $absolute ? true : "components/plugins/{$plugin_name}/includes/js")); } unset($plugin_name); return $includes; }
/** * Change language * * @param string $language * * @return bool */ function change($language) { static $changed_once = false; if ($this->fixed_language && $changed_once) { return false; } $changed_once = true; if ($language == $this->clanguage) { return true; } $Config = Config::instance(true); if (empty($language)) { if ($Config && $Config->core['multilingual']) { $language = $this->scan_aliases($Config->core['active_languages']) ?: $language; } } if (!$Config || $language == $Config->core['language'] || $Config->core['multilingual'] && in_array($language, $Config->core['active_languages'])) { $this->clanguage = $language; $return = false; $Cache = Cache::instance(); /** * If translations in cache */ if ($translate = $Cache->{"languages/{$this->clanguage}"}) { $this->set($translate); $return = true; /** * Otherwise check for system translations */ } elseif (file_exists(LANGUAGES . "/{$this->clanguage}.json")) { /** * Set system translations */ $this->set(file_get_json_nocomments(LANGUAGES . "/{$this->clanguage}.json")); $translate =& $this->translate; $translate['clanguage'] = $this->clanguage; if (!isset($translate['clang'])) { $translate['clang'] = mb_strtolower(mb_substr($this->clanguage, 0, 2)); } if (!isset($translate['clanguage_en'])) { $translate['clanguage_en'] = $this->clanguage; } if (!isset($translate['locale'])) { $translate['locale'] = $this->clang . '_' . strtoupper($this->clang); } /** * Set modules' translations */ foreach (get_files_list(MODULES, false, 'd') as $module) { if (file_exists(MODULES . "/{$module}/languages/{$this->clanguage}.json")) { $this->set(file_get_json_nocomments(MODULES . "/{$module}/languages/{$this->clanguage}.json") ?: []); } } unset($module); /** * Set plugins' translations */ foreach (get_files_list(PLUGINS, false, 'd') as $plugin) { if (file_exists(PLUGINS . "/{$plugin}/languages/{$this->clanguage}.json")) { $this->set(file_get_json_nocomments(PLUGINS . "/{$plugin}/languages/{$this->clanguage}.json") ?: []); } } unset($plugin); Trigger::instance()->run('System/general/languages/load', ['clanguage' => $this->clanguage, 'clang' => $this->clang, 'cregion' => $this->cregion, 'clanguage_en' => $this->clanguage_en]); $Cache->{"languages/{$this->clanguage}"} = $translate; $return = true; } _include(LANGUAGES . "/{$this->clanguage}.php", false, false); header("Content-Language: {$translate['content_language']}"); return $return; } return false; }
/** * @package CleverStyle CMS * @subpackage System module * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2011-2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\System; use h, cs\Config, cs\Core, cs\Index, cs\Language; $Config = Config::instance(); $L = Language::instance(); $Config->reload_languages(); $translate_engines = _mb_substr(get_files_list(ENGINES . '/Text', '/^[^_].*?\\.php$/i', 'f'), 0, -4); $translate_engines_settings = []; $current_engine_settings = ''; foreach ($translate_engines as $engine) { $parameters = file_get_json(ENGINES . '/Text/' . $engine . '.json'); if (is_array($parameters) && !empty($parameters)) { $table = ''; foreach ($parameters as $paremeter => $description) { $table .= h::{'tr td'}([$description, h::input(['name' => 'core[auto_translation_engine][' . $paremeter . ']', 'value' => isset($Config->core['auto_translation_engine'][$paremeter]) ? $Config->core['auto_translation_engine'][$paremeter] : ''])]); } $translate_engines_settings[] = base64_encode(h::table($table)); } else { $translate_engines_settings[] = base64_encode($parameters ?: $L->no_settings_found); } if ($engine == $Config->core['auto_translation_engine']['name']) { $current_engine_settings = base64_decode(array_slice($translate_engines_settings, -1)[0]);
/** * @param $dir * @param $error_msg * @param $hide_php_warnings * @param int $retry * @return bool */ function check_php_syntax(&$dir, &$error_msg, $hide_php_warnings, $retry = 10) { global $phpCommand; $checkPhpCommand = $phpCommand . (ERROR_REPORTING_LEVEL > 0 ? ' -d error_reporting=' . (int) ERROR_REPORTING_LEVEL : ''); $entries = array(); get_files_list($dir, $entries, '/\\.php$/'); $nbEntries = count($entries); for ($i = 0; $i < $nbEntries; $i++) { display_progress_percentage($i, $nbEntries, '%d%% of files passed the PHP syntax check'); $return_var = 0; $output = null; exec("{$checkPhpCommand} -l {$entries[$i]} 2>&1", $output, $return_var); $fullOutput = implode("\n", $output); if (strpos($fullOutput, 'Segmentation fault') !== false) { // If php -l command segfaults, wait and retry (it seems to happen quite often on some environments for this command) echo "\r[Retrying due to a Segfault...]"; sleep(1); $i--; } elseif ($return_var !== 0) { // Handle PHP errors $fullOutput = trim($fullOutput); $error_msg = $fullOutput == '' ? "\nPHP Parsing error in '{$entries[$i]}' ({$return_var})\n" : "\n{$fullOutput}"; return false; } elseif (!$hide_php_warnings && ($nb_lines = count($output)) > 1 && !preg_match(THIRD_PARTY_LIBS_PATTERN, $entries[$i])) { // Handle PHP warnings / notices (this just displays a yellow warning, it doesn't return false or an error_msg) // and exclude some third party libs when displaying warnings from the PHP syntax check, because we can't fix it directly by the way. echo "\r"; foreach ($output as $k => $line) { // Remove empty lines and last line (because in case of a simple warning, the last line simply says 'No syntax errors...') if (trim($line) == '' || $k == $nb_lines - 1) { continue; } echo color("{$line}\n", 'yellow'); } display_progress_percentage($i, $nbEntries, '%d%% of files passed the PHP syntax check'); } unset($output, $return_var); } echo "\n"; return true; }
* Restore previous plugin state */ if ($active) { $Config->components['plugins'][] = $plugin; $Config->save(); clean_pcache(); Trigger::instance()->run('admin/System/components/plugins/enable', ['name' => $plugin]); } $Index->save(); unset($Cache->functionality); break; case 'remove': if (in_array($plugin, $Config->components['plugins'])) { break; } $ok = true; get_files_list(PLUGINS . "/{$plugin}", false, 'fd', true, true, false, false, true, function ($item) use(&$ok) { if (is_writable($item)) { is_dir($item) ? @rmdir($item) : @unlink($item); } else { $ok = false; } }); if ($ok && @rmdir(PLUGINS . "/{$plugin}")) { $Index->save(); } else { $Index->save(false); } break; } }
/** * Public cache cleaning * * @return bool */ function clean_pcache() { $ok = true; $list = get_files_list(PCACHE, false, 'fd', true, true, 'name|desc'); foreach ($list as $item) { if (is_writable($item)) { is_dir($item) ? @rmdir($item) : @unlink($item); } else { $ok = false; } } unset($list, $item); return $ok; }
/** * Function for getting content of a directory * * @param string $dir Directory for searching * @param bool|string $mask Regexp for items * @param string $mode Mode of searching<br> * <b>f</b> - files only (default)<br> * <b>d</b> - directories only<br> * <b>fd</b> - both files and directories * @param bool|string $prefix_path Path to be added to the beginning of every found item. If <b>true</b> - prefix will * be absolute path to item on server. * @param bool $subfolders Search in subdirectories or not * @param bool $sort Sort mode in format <b>mode|order</b>:<br> * Possible values for mode: <b>name</b> (default), <b>date</b>, <b>size</b> * Possible values for mode: <b>asc</b> (default), <b>desc</b> * @param bool|string $exclusion If specified file exists in scanned directory - it will be excluded from scanning * @param bool $system_files Show system files: .htaccess .htpasswd .gitignore * @param Closure $apply Apply function to each found item, return nothing (sorting will not work, items will be processed as they found) * @param int|null $limit If specified - limits total number of found items (if $limit items found - stop further searching) * * @return array|bool */ function get_files_list($dir, $mask = false, $mode = 'f', $prefix_path = false, $subfolders = false, $sort = false, $exclusion = false, $system_files = false, $apply = null, $limit = null) { /** * Wrapped in internal closure in order to use &$limit */ static $func; !isset($func) && ($func = function ($dir, $mask, $mode, $prefix_path, $subfolders, $sort, $exclusion, $system_files, $apply, &$limit) { if ($mode == 'df') { $mode = 'fd'; } $dir = rtrim($dir, '/') . '/'; if (!is_dir($dir) || $exclusion !== false && file_exists($dir . $exclusion)) { return false; } if ($sort === false) { $sort = 'name'; $sort_x = ['name', 'asc']; } else { $sort = mb_strtolower($sort); $sort_x = explode('|', $sort); if (!isset($sort_x[1]) || $sort_x[1] != 'desc') { $sort_x[1] = 'asc'; } } if (isset($sort_x) && $sort_x[0] == 'date') { $prepare = function (&$list, $tmp, $link) { $list[fileatime($link) ?: filemtime($link)] = $tmp; }; } elseif (isset($sort_x) && $sort_x[0] == 'size') { $prepare = function (&$list, $tmp, $link) { $list[filesize($link)] = $tmp; }; } else { $prepare = function (&$list, $tmp) { $list[] = $tmp; }; } $list = []; if ($prefix_path !== true && $prefix_path) { $prefix_path = rtrim($prefix_path, '/') . '/'; } $dirc = opendir($dir); if (!is_resource($dirc)) { return false; } while (($file = readdir($dirc)) !== false) { if ($limit < 0) { break; } if ($mask && !preg_match($mask, $file) && (!$subfolders || !is_dir($dir . $file)) || $file == '.' || $file == '..' || !$system_files && ($file == '.htaccess' || $file == '.htpasswd' || $file == '.gitignore')) { continue; } if ($mode == 'fd' || is_file($dir . $file) && $mode == 'f' || is_dir($dir . $file) && $mode == 'd') { --$limit; $item = $prefix_path === true ? $dir . $file : ($prefix_path ? $prefix_path . $file : $file); if (!$apply instanceof Closure) { $prepare($list, $item, $dir . $file); } } if ($limit >= 0) { if ($subfolders && is_dir($dir . $file)) { $list = array_merge($list, get_files_list($dir . $file, $mask, $mode, $prefix_path === true || $prefix_path === false ? $prefix_path : $prefix_path . $file, $subfolders, $sort, $exclusion, $system_files, $apply, $limit) ?: []); } } if (isset($item) && $apply instanceof Closure) { $apply($item); } unset($item); if ($limit < 0) { break; } } closedir($dirc); unset($prepare); if (!empty($list) && isset($sort_x)) { switch ($sort_x[0]) { case 'date': case 'size': if ($sort_x[1] == 'desc') { krsort($list); } else { ksort($list); } break; case 'name': natcasesort($list); if ($sort_x[1] == 'desc') { $list = array_reverse($list); } break; } } return array_values($list); }); return $func($dir, $mask, $mode, $prefix_path, $subfolders, $sort, $exclusion, $system_files, $apply, $limit); }
switch ($rc[2]) { case 'add': case 'edit': if ($rc[2] == 'edit' && isset($rc[3])) { $storage =& $Config->storage[$rc[3]]; } /** * @var array $storage */ $a->action = "admin/System/{$rc['0']}/{$rc['1']}"; $Page->title($rc[2] == 'edit' ? $L->editing_of_storage($Config->storage[$rc[3]]['host'] . '/' . $Config->storage[$rc[3]]['connection']) : $L->adding_of_storage); $a->content(h::{'p.lead.cs-center'}($rc[2] == 'edit' ? $L->editing_of_storage($Config->storage[$rc[3]]['host'] . '/' . $Config->storage[$rc[3]]['connection']) : $L->adding_of_storage) . h::{'table.cs-table-borderless.cs-center-all tr'}(\cs\modules\System\form_rows_to_cols([array_map(function ($in) { return h::{'th info'}($in); }, ['storage_url', 'storage_host', 'storage_connection', 'storage_user', 'storage_pass']), array_map(function ($in) { return h::td($in); }, [h::input(['name' => 'storage[url]', 'value' => $rc[2] == 'edit' ? $storage['url'] : '']), h::input(['name' => 'storage[host]', 'value' => $rc[2] == 'edit' ? $storage['host'] : '']), h::select(['in' => _mb_substr(get_files_list(ENGINES . '/Storage', '/^[^_].*?\\.php$/i', 'f'), 0, -4)], ['name' => 'storage[connection]', 'selected' => $rc[2] == 'edit' ? $storage['connection'] : '', 'size' => 5]), h::input(['name' => 'storage[user]', 'value' => $rc[2] == 'edit' ? $storage['user'] : '']), h::input(['name' => 'storage[password]', 'value' => $rc[2] == 'edit' ? $storage['password'] : '']) . h::{'input[type=hidden]'}(['name' => 'mode', 'value' => $rc[2] == 'edit' ? 'edit' : 'add']) . (isset($rc[3]) ? h::{'input[type=hidden]'}(['name' => 'storage_id', 'value' => $rc[3]]) : '')])])) . h::button($L->test_connection, ['onMouseDown' => "cs.storage_test('{$a->action}/test');"])); break; case 'delete': $a->buttons = false; $modules = []; foreach ($Config->components['modules'] as $module => &$mdata) { if (isset($mdata['storage']) && is_array($mdata['storage'])) { foreach ($mdata['storage'] as $storage_name) { if ($storage_name == $rc[3]) { $modules[] = h::b($module); break; } } } } unset($module, $mdata, $storage_name);
break; case 'edit': if (!isset($rc[3], $Config->components['blocks'][$rc[3]])) { break; } $form = false; $a->apply_button = false; $a->cancel_button_back = true; $a->form_atributes[] = 'formnovalidate'; $block =& $Config->components['blocks'][$rc[3]]; $Page->title($L->editing_a_block(get_block_title($rc[3]))); $a->content(h::{'p.lead.cs-center'}($L->editing_a_block(get_block_title($rc[3]))) . h::{'table.cs-table-borderless.cs-center-all tr'}(\cs\modules\System\form_rows_to_cols([array_map(function ($in) { return h::{'th info'}($in); }, ['block_title', 'block_active', 'block_template', 'block_start', 'block_expire']), array_map(function ($in) { return h::td($in); }, [h::input(['name' => 'block[title]', 'value' => get_block_title($rc[3])]), h::{'div input[type=radio]'}(['name' => 'block[active]', 'checked' => $block['active'], 'value' => [1, 0], 'in' => [$L->yes, $L->no]]), h::select(['in' => _mb_substr(get_files_list(TEMPLATES . '/blocks', '/^block\\..*?\\.(php|html)$/i', 'f'), 6)], ['name' => 'block[template]', 'selected' => $block['template'], 'size' => 5]), h::{'input[type=datetime-local]'}(['name' => 'block[start]', 'value' => date('Y-m-d\\TH:i', $block['start'] ?: TIME)]), h::{'input[type=radio]'}(['name' => 'block[expire][state]', 'checked' => $block['expire'] != 0, 'value' => [0, 1], 'in' => [$L->never, $L->as_specified]]) . h::br(2) . h::{'input[type=datetime-local]'}(['name' => 'block[expire][date]', 'value' => date('Y-m-d\\TH:i', $block['expire'] ?: TIME)])])]), $block['type'] == 'html' ? h::{'td[colspan=5] textarea.EDITOR'}(get_block_content($rc[3]), ['name' => 'block[html]']) : ($block['type'] == 'raw_html' ? h::{'td[colspan=5] textarea'}(get_block_content($rc[3]), ['name' => 'block[raw_html]']) : '')) . h::{'input[type=hidden]'}([[['name' => 'block[id]', 'value' => $rc[3]]], [['name' => 'mode', 'value' => $rc[2]]]])); break; case 'permissions': if (!isset($rc[3], $Config->components['blocks'][$rc[3]])) { break; } $form = false; $a->apply_button = false; $a->cancel_button_back = true; $permission = Permission::instance()->get(null, 'Block', $Config->components['blocks'][$rc[3]]['index'])[0]['id']; $groups = Group::instance()->get_all(); $groups_content = []; foreach ($groups as $group) { $group_permission = $User->db()->qfs(["SELECT `value`\n\t\t\t\t\tFROM `[prefix]groups_permissions`\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`id`\t\t\t= '%s' AND\n\t\t\t\t\t\t`permission`\t= '%s'", $group['id'], $permission]); $groups_content[] = h::th($group['title'], ['data-title' => $group['description']]) . h::{'td input[type=radio]'}(['name' => "groups[{$group['id']}]", 'checked' => $group_permission === false ? -1 : $group_permission, 'value' => [-1, 0, 1], 'in' => [$L->inherited, $L->deny, $L->allow]]); }
private function _execute_services() { if (is_dir(SERVICES_DIR)) { $services = get_files_list(SERVICES_DIR, ['php']); if (array_count($services) > 0) { ksort($services); foreach ($services as $key => $val) { $service_name = str_replace('.php', '', $key); $service_class = '\\App\\Services\\' . studly_case($service_name); try { $tmp = new $service_class(); } catch (AppException $e) { wasp_error($e->getMessage()); } if ($tmp instanceof Service) { $tmp->execute(); } else { wasp_error('Incorrect instance of service class ' . $tmp->className()); } unset($tmp); } } } }
function get_files_from_folder($folder_id, $sorting = 'objekt.pealkiri asc', $page = 1) { global $site; $objekt = new Objekt(array('objekt_id' => $folder_id)); if ($objekt->objekt_id == $folder_id && $objekt->all['tyyp_id'] == 22) { $list_sql = new AlamlistSQL(array('parent' => $folder_id, 'klass' => 'file', 'order' => $sorting)); $list_sql->add_select("obj_file.profile_id, obj_file.relative_path, obj_file.filename, obj_file.mimetype, obj_file.size"); $list_sql->add_from("LEFT JOIN obj_file ON objekt.objekt_id=obj_file.objekt_id"); $list = new Alamlist(array('alamlistSQL' => $list_sql, 'start' => ($page - 1) * 100, 'limit' => 100)); $count_sql = new AlamlistSQL(array('parent' => $folder_id, 'klass' => 'file')); $count = new Alamlist(array('alamlistSQL' => $count_sql, 'on_counter' => 1)); return array('total_files' => (int) $count->rows, 'files' => get_files_list($list)); } else { return 'no_such_folder_object'; } }
} unset($i, $db); } $a->action = "admin/System/{$rc['0']}/{$rc['1']}"; /** * @var array $dbsname * @var array $dbs * @var array $database * @var string $name */ $Page->title($rc[2] == 'edit' ? $L->editing_the_database($name) : $L->addition_of_db); $a->content(h::{'p.lead.cs-center'}($rc[2] == 'edit' ? $L->editing_the_database($name) : $L->addition_of_db) . h::{'table.cs-table.cs-center-all tr'}(\cs\modules\System\form_rows_to_cols([array_map(function ($in) { return h::{'th info'}($in); }, [$rc[2] == 'add' ? 'db_mirror' : false, 'db_host', 'db_type', 'db_prefix', 'db_name', 'db_user', 'db_password', 'db_charset']), array_map(function ($in) { return h::td($in); }, [$rc[2] == 'add' ? h::select(['in' => $dbsname, 'value' => $dbs], ['name' => 'db[mirror]', 'selected' => isset($rc[3]) ? $rc[3] : -1, 'size' => 5]) : false, h::input(['name' => 'db[host]', 'value' => $rc[2] == 'edit' ? $database['host'] : $Core->db_host]), h::select(['in' => _mb_substr(get_files_list(ENGINES . '/DB', '/^[^_].*?\\.php$/i', 'f'), 0, -4)], ['name' => 'db[type]', 'selected' => $rc[2] == 'edit' ? $database['type'] : $Core->db_type, 'size' => 5]), h::input(['name' => 'db[prefix]', 'value' => $rc[2] == 'edit' ? $database['prefix'] : $Core->db_prefix]), h::input(['name' => 'db[name]', 'value' => $rc[2] == 'edit' ? $database['name'] : '']), h::input(['name' => 'db[user]', 'value' => $rc[2] == 'edit' ? $database['user'] : '']), h::input(['name' => 'db[password]', 'value' => $rc[2] == 'edit' ? $database['password'] : '']), h::input(['name' => 'db[charset]', 'value' => $rc[2] == 'edit' ? $database['charset'] : $Core->db_charset]) . h::{'input[type=hidden]'}(['name' => 'mode', 'value' => $rc[2] == 'edit' ? 'edit' : 'add']) . (isset($rc[3]) ? h::{'input[type=hidden]'}(['name' => 'database', 'value' => $rc[3]]) : '') . (isset($rc[4]) ? h::{'input[type=hidden]'}(['name' => 'mirror', 'value' => $rc[4]]) : '')])])) . h::{'p button'}($L->test_connection, ['onMouseDown' => "cs.db_test('{$a->action}/test');"])); break; case 'delete': $a->buttons = false; $content = []; if (!isset($rc[4])) { foreach ($Config->components['modules'] as $module => &$mdata) { if (isset($mdata['db']) && is_array($mdata['db'])) { foreach ($mdata['db'] as $db_name) { if ($db_name == $rc[3]) { $content[] = h::b($module); break; } } } }
global $STORAGE_USER, $STORAGE_PASSWORD; $data = _json_decode(urldecode($_POST['data'])); $KEY = substr($data['key'], 0, 32); unset($data['key']); if (md5(_json_encode($data) . $STORAGE_USER . $STORAGE_PASSWORD) !== $KEY) { exit; } unset($GLOBALS['STORAGE_USER'], $GLOBALS['STORAGE_PASSWORD'], $KEY); } else { exit; } switch ($data['function']) { default: exit; case 'get_files_list': exit(_json_encode(get_files_list($data['dir'], $data['mask'], $data['mode'], $data['prefix_path'], $data['subfolders'], $data['sort'], $data['exclusion'], $data['system_files'], null, $data['limit']))); case 'file': exit(_json_encode(file($data['filename'], $data['flags']))); case 'file_get_contents': exit(file_get_contents($data['filename'], $data['flags'], null, $data['offset'], $data['maxlen'])); case 'file_put_contents': exit(file_put_contents($data['filename'], $data['data'], $data['flags'])); case 'copy': exit(copy($data['source'], $data['dest'])); case 'unlink': exit(unlink($data['filename'])); case 'file_exists': exit(file_exists($data['filename'])); case 'move_uploaded_file': exit(copy($data['filename'], $data['destination'])); case 'rename':
/** * Clean cache by deleting all items * * @return bool */ function clean() { $ok = true; $cache_old = CACHE . '_old'; rename(CACHE, $cache_old); get_files_list($cache_old, false, 'fd', true, true, false, false, true, function ($item) use(&$ok) { if (is_writable($item)) { is_dir($item) ? @rmdir($item) : @unlink($item); } else { $ok = false; } }); return $ok && @rmdir($cache_old); }