function file_get_cached_json($json_filename = '', $json_fn = null, $rebuild = false) { $php_filename = 'cache/' . $json_filename . '.php'; $json_filetime = @filemtime($json_filename); $php_filetime = @filemtime($php_filename); if ($json_filetime !== $php_filetime || $rebuild) { $json_array = @file_get_json($json_filename); if ($json_fn) { $json_array = $json_fn($json_array); } file_set_array($php_filename, $json_array, 'json_array'); touch($php_filename, $json_filetime); } else { include $php_filename; } return $json_array; }
if ($module_name != 'System') { /** * Link to the module admin page */ if (file_exists(MODULES . "/{$module_name}/admin/index.php") || file_exists(MODULES . "/{$module_name}/admin/index.json")) { $action .= h::{'a.cs-button-compact'}(h::icon('wrench'), ['href' => "admin/{$module_name}", 'data-title' => $L->module_admin_page]); $admin_link = true; } if ($module_name != $Config->core['default_module']) { $action .= h::{'a.cs-button-compact'}(h::icon($module_data['active'] == 1 ? 'minus' : 'check'), ['href' => $a->action . ($module_data['active'] == 1 ? '/disable/' : '/enable/') . $module_name, 'data-title' => $module_data['active'] == 1 ? $L->disable : $L->enable]) . h::{'a.cs-button-compact'}(h::icon('trash-o'), ['href' => "{$a->action}/uninstall/{$module_name}", 'data-title' => $L->uninstall]); } } /** * If module uninstalled or not installed yet */ } else { $action .= h::{'a.cs-button-compact'}(h::icon('download'), ['href' => "{$a->action}/install/{$module_name}", 'data-title' => $L->install]); } $module_info = false; if (file_exists(MODULES . "/{$module_name}/meta.json")) { $module_meta = file_get_json(MODULES . "/{$module_name}/meta.json"); $module_info = $L->module_info($module_meta['package'], $module_meta['version'], $module_meta['description'], $module_meta['author'], isset($module_meta['website']) ? $module_meta['website'] : $L->none, $module_meta['license'], isset($module_meta['db_support']) ? implode(', ', $module_meta['db_support']) : $L->none, isset($module_meta['storage_support']) ? implode(', ', $module_meta['storage_support']) : $L->none, isset($module_meta['provide']) ? implode(', ', (array) $module_meta['provide']) : $L->none, isset($module_meta['require']) ? implode(', ', (array) $module_meta['require']) : $L->none, isset($module_meta['conflict']) ? implode(', ', (array) $module_meta['conflict']) : $L->none, isset($module_meta['optional']) ? implode(', ', (array) $module_meta['optional']) : $L->none, isset($module_meta['multilingual']) && in_array('interface', $module_meta['multilingual']) ? $L->yes : $L->no, isset($module_meta['multilingual']) && in_array('content', $module_meta['multilingual']) ? $L->yes : $L->no, isset($module_meta['languages']) ? implode(', ', $module_meta['languages']) : $L->none); } unset($module_meta); $modules_list[] = [h::a($L->{$module_name}, ['href' => $admin_link ? "admin/{$module_name}" : false, 'data-title' => $module_info]), h::icon($module_data['active'] == 1 ? $module_name == $Config->core['default_module'] ? 'home' : 'check' : ($module_data['active'] == 0 ? 'minus' : 'times'), ['data-title' => $module_data['active'] == 1 ? $module_name == $Config->core['default_module'] ? $L->default_module : $L->enabled : ($module_data['active'] == 0 ? $L->disabled : "{$L->uninstalled} ({$L->not_installed})")]) . $addition_state, [$action, ['class' => 'cs-left-all']]]; unset($module_info); } $modules_for_removal = array_keys(array_filter($Config->components['modules'], function ($module_data) { return $module_data['active'] == '-1'; })); $a->content(h::{'table.cs-table.cs-center-all'}(h::{'thead tr th'}($L->module_name, $L->state, $L->action) . h::{'tbody tr| td'}([$modules_list])) . h::p(h::{'input[type=file][name=upload_module]'}() . h::{'button[type=submit]'}(h::icon('upload') . $L->upload_and_install_update_module, ['formaction' => "{$a->action}/install/upload"])) . h::p(h::{'input[type=file][name=upload_system]'}() . h::{'button[type=submit]'}(h::icon('upload') . $L->upload_and_update_system, ['formaction' => "{$a->action}/update_system"])) . ($modules_for_removal ? h::p(h::{'select[name=remove_module]'}($modules_for_removal) . h::{'button[type=submit]'}(h::icon('trash-o') . $L->complete_module_removal, ['formaction' => "{$a->action}/remove"])) : '') . h::{'button[type=submit]'}(h::icon('refresh') . $L->update_modules_list, ['data-title' => $L->update_modules_list_info, 'name' => 'update_modules_list']));
echo "{error:\"no second race specified.\"}"; exit; } if (!isset($_GET["s"])) { echo "{error:\"no subject specified.\"}"; exit; } else { $districts = explode(",", $_GET["d"]); } function file_get_json($json_file) { $json_string = file_get_contents($json_file); return json_decode($json_string); } $json_file = "js/data.json"; $data = file_get_json($json_file); $return = []; function getGap($district_code) { global $data; $s = $_GET["s"]; $gap = "error"; $district = $data->{$district_code}->district; // echo "district: " . $district . "<br>"; $r1 = $_GET["r1"]; $r2 = $_GET["r2"]; // echo "race: " . $r1 . "<br>"; // echo "race: " . $r2 . "<br>"; $r1_score = $data->{$district_code}->{$r1}->{$s}; $r2_score = $data->{$district_code}->{$r2}->{$s}; // echo "r1_score: " . $r1_score . "<br>";
/** * Updating of System */ if (file_exists("{$module_dir}/versions.json")) { $old_version = file_get_json("{$module_dir}/meta_old.json")['version']; foreach (file_get_json("{$module_dir}/versions.json") as $version) { if (version_compare($old_version, $version, '<')) { /** * PHP update script */ _include("{$module_dir}/meta/update/{$version}.php", true, false); /** * Database update */ if (isset($module_data['db']) && file_exists("{$module_dir}/meta/db.json")) { $db_json = file_get_json("{$module_dir}/meta/db.json"); time_limit_pause(); foreach ($db_json as $database) { if ($module_data['db'][$database] == 0) { $db_type = $Core->db_type; } else { $db_type = $Config->db[$module_data['db'][$database]]['type']; } $sql_file = "{$module_dir}/meta/update_db/{$database}/{$version}/{$db_type}.sql"; if (file_exists($sql_file)) { $db->{$module_data['db'][$database]}()->q(explode(';', file_get_contents($sql_file))); } } unset($db_json, $database, $db_type, $sql_file); time_limit_pause(false); }
} unset($tag, $file); /** * License */ if (file_exists($file = PLUGINS . "/{$plugin}/license.txt") || file_exists($file = PLUGINS . "/{$plugin}/license.html")) { if (substr($file, -3) == 'txt') { $tag = 'pre'; } else { $tag = 'div'; } $addition_state .= h::{'div.uk-modal.cs-left'}(h::{"{$tag}.uk-modal-dialog-large"}($tag == 'pre' ? prepare_attr_value(file_get_contents($file)) : file_get_contents($file)), ['id' => "{$plugin}_license", 'title' => "{$plugin} -> {$L->license}"]) . h::{'icon.cs-pointer'}('legal', ['data-title' => $L->license . h::br() . $L->click_to_view_details, 'onClick' => "\$('#{$plugin}_license').cs().modal('show');"]); } unset($tag, $file); $state = in_array($plugin, $Config->components['plugins']); $action .= h::{'a.cs-button-compact'}(h::icon($state ? 'minus' : 'check'), ['href' => $a->action . ($state ? '/disable/' : '/enable/') . $plugin, 'data-title' => $state ? $L->disable : $L->enable]); $plugin_info = false; if (file_exists(PLUGINS . "/{$plugin}/meta.json")) { $plugin_meta = file_get_json(PLUGINS . "/{$plugin}/meta.json"); $plugin_info = $L->plugin_info($plugin_meta['package'], $plugin_meta['version'], $plugin_meta['description'], $plugin_meta['author'], isset($plugin_meta['website']) ? $plugin_meta['website'] : $L->none, $plugin_meta['license'], isset($plugin_meta['provide']) ? implode(', ', (array) $plugin_meta['provide']) : $L->none, isset($plugin_meta['require']) ? implode(', ', (array) $plugin_meta['require']) : $L->none, isset($plugin_meta['conflict']) ? implode(', ', (array) $plugin_meta['conflict']) : $L->none, isset($plugin_meta['optional']) ? implode(', ', (array) $plugin_meta['optional']) : $L->none, isset($plugin_meta['multilingual']) && in_array('interface', $plugin_meta['multilingual']) ? $L->yes : $L->no, isset($plugin_meta['multilingual']) && in_array('content', $plugin_meta['multilingual']) ? $L->yes : $L->no, isset($plugin_meta['languages']) ? implode(', ', $plugin_meta['languages']) : $L->none); } unset($plugin_meta); $plugins_list[] = [h::span($L->{$plugin}, ['data-title' => $plugin_info]), h::icon($state ? 'check' : 'minus', ['data-title' => $state ? $L->enabled : $L->disabled]) . $addition_state, $action]; unset($plugin_info); } unset($plugin, $state, $addition_state, $action); } $plugins_for_removal = array_values(array_filter($plugins, function ($plugin) use($Config) { return !in_array($plugin, $Config->components['plugins']); })); $a->content(h::{'table.cs-table.cs-center-all'}(h::{'thead tr th'}($L->plugin_name, $L->state, $L->action) . h::{'tbody tr| td'}([$plugins_list ?: false])) . h::p(h::{'input[type=file][name=upload_plugin]'}(['style' => 'position: relative;']) . h::{'button[type=submit]'}(h::icon('upload') . $L->upload_and_install_update_plugin, ['formaction' => "{$a->action}/enable/upload"])) . ($plugins_for_removal ? h::p(h::{'select[name=remove_plugin]'}($plugins_for_removal) . h::{'button[type=submit]'}(h::icon('trash-o') . $L->complete_plugin_removal, ['formaction' => "{$a->action}/remove"])) : ''));
return (int) copy("{$tmp_dir}/fs/{$index}", "{$theme_dir}/{$file}"); }, $fs, array_keys($fs))); unlink($tmp_file); unset($tmp_file, $tmp_dir); if (!$extract) { $Page->warning($L->theme_files_unpacking_error); unlink("{$theme_dir}/fs_old.json"); unlink("{$theme_dir}/meta_old.json"); break; } unset($extract); file_put_json("{$theme_dir}/fs.json", $fs = array_keys($fs)); /** * Removing of old unnecessary files and directories */ foreach (array_diff(file_get_json("{$theme_dir}/fs_old.json"), $fs) as $file) { $file = "{$theme_dir}/{$file}"; if (file_exists($file) && is_writable($file)) { unlink($file); if (!get_files_list($dir = dirname($file))) { rmdir($dir); } } } unset($fs, $file, $dir); unlink("{$theme_dir}/fs_old.json"); unlink("{$theme_dir}/meta_old.json"); /** * Clean themes cache */ $Index->save(true);
/** * Getting of CSS and JavaScript includes * * @return Page */ protected function add_includes_on_page() { if (!($Config = Config::instance(true))) { return $this; } /** * If CSS and JavaScript compression enabled */ if ($Config->core['cache_compress_js_css']) { /** * Current cache checking */ if (!file_exists(PCACHE . "/{$this->pcache_basename}.json")) { $this->rebuild_cache(); } $data = file_get_json(PCACHE . "/{$this->pcache_basename}.json"); $structure = $data['structure']; $dependencies = $data['dependencies']; unset($data); /** * Narrow the dependence to current module only */ $dependencies = isset($dependencies[MODULE]) ? $dependencies[MODULE] : []; $includes['css'] = ["storage/pcache/{$this->pcache_basename}.css?{$structure['']['css']}"]; $includes['js'] = ["storage/pcache/{$this->pcache_basename}.js?{$structure['']['js']}"]; $current_url = str_replace('/', '+', $Config->server['relative_address']); foreach ($structure as $filename_prefix => $hashes) { $prefix_module = explode('+', $filename_prefix); $prefix_module = $prefix_module[0] != 'admin' ? $prefix_module[0] : $prefix_module[1]; if ($filename_prefix && mb_strpos($current_url, $filename_prefix) === 0 || $dependencies && array_search($prefix_module, $dependencies) !== false) { foreach ($hashes as $extension => $hash) { $includes[$extension][] = "storage/pcache/{$filename_prefix}{$this->pcache_basename}.{$extension}?{$hash}"; } unset($extension, $hash); } unset($prefix_module); } unset($dependencies, $structure, $filename_prefix, $hashes); $this->css_internal($includes['css'], 'file', true); $this->js_internal($includes['js'], 'file', true); } else { if ($Config) { $this->includes_dependencies_and_map($dependencies, $includes_map); /** * Add system includes */ $includes = $includes_map['']; unset($includes_map['']); $current_url = $Config->server['relative_address']; /** * Narrow the dependence to current module only */ $dependencies = isset($dependencies[MODULE]) ? $dependencies[MODULE] : []; foreach ($includes_map as $url => $local_includes) { $prefix_module = explode('+', $url); $prefix_module = $prefix_module[0] != 'admin' ? $prefix_module[0] : $prefix_module[1]; if (mb_strpos($current_url, $url) === 0 || $dependencies && array_search($prefix_module, $dependencies) !== false) { if (isset($local_includes['css'])) { $includes['css'] = array_merge($includes['css'], $local_includes['css']); } if (isset($local_includes['js'])) { $includes['js'] = array_merge($includes['js'], $local_includes['js']); } } } unset($current_url, $dependencies, $url, $local_includes, $prefix_module); $root_strlen = strlen(DIR) + 1; // +1 means slash following after root path foreach ($includes['css'] as &$file) { $file = substr($file, $root_strlen); } unset($file); foreach ($includes['js'] as &$file) { $file = substr($file, $root_strlen); } unset($root_strlen, $file); } else { $includes = $this->get_includes_list(); } /** * Including of CSS */ $this->css_internal($includes['css'], 'file', true); /** * Including of JavaScript */ $this->js_internal($includes['js'], 'file', true); } return $this; }
/** * Check backward dependencies (during uninstalling/disabling) * * @param string $name Component name * @param string $type Component type module|plugin * @param string $mode Mode of checking for modules uninstall|disable * * @return bool */ function check_backward_dependencies($name, $type = 'module', $mode = 'disable') { switch ($type) { case 'module': $dir = MODULES . "/{$name}"; break; case 'plugin': $dir = PLUGINS . "/{$name}"; break; default: return false; } if (!file_exists("{$dir}/meta.json")) { return true; } $meta = file_get_json("{$dir}/meta.json"); $return = true; $Config = Config::instance(); $L = Language::instance(); $Page = Page::instance(); /** * Checking for backward dependencies of modules */ $return_m = true; foreach ($Config->components['modules'] as $module => $module_data) { /** * If module uninstalled, disabled (in disable check mode), module name is the same as checking or meta.json file does not exists * Then skip this module */ if ($module_data['active'] == -1 || $mode == 'disable' && $module_data['active'] == 0 || $module == $name && $type == 'module' || !file_exists(MODULES . "/{$module}/meta.json")) { continue; } $module_require = file_get_json(MODULES . "/{$module}/meta.json"); if (!isset($module_require['require'])) { continue; } $module_require = dep_normal($module_require['require']); if (isset($module_require[$meta['package']]) || isset($meta['provide']) && array_intersect(array_keys($module_require), (array) $meta['provide'])) { if ($return_m) { $Page->warning($L->dependencies_not_satisfied); } $return_m = false; $Page->warning($L->this_package_is_used_by_module($module)); } } $return = $return && $return_m; unset($return_m, $module, $module_data, $module_require); /** * Checking for backward dependencies of plugins */ $return_p = true; foreach ($Config->components['plugins'] as $plugin) { if ($plugin == $name && $type == 'plugin' || !file_exists(PLUGINS . "/{$plugin}/meta.json")) { continue; } $plugin_require = file_get_json(PLUGINS . "/{$plugin}/meta.json"); if (!isset($plugin_require['require'])) { continue; } $plugin_require = dep_normal($plugin_require['require']); if (isset($plugin_require[$meta['package']]) || isset($meta['provide']) && array_intersect(array_keys($plugin_require), (array) $meta['provide'])) { if ($return_p) { $Page->warning($L->dependencies_not_satisfied); } $return_p = false; $Page->warning($L->this_package_is_used_by_plugin($plugin)); } } return $return && $return_p; }
/** * User registration * * @param string $email * @param bool $confirmation If <b>true</b> - default system option is used, if <b>false</b> - registration will be * finished without necessity of confirmation, independently from default system option * (is used for manual registration). * @param bool $auto_sign_in If <b>false</b> - no auto sign in, if <b>true</b> - according to system configuration * * @return array|bool|string <b>exists</b> - if user with such email is already registered<br> * <b>error</b> - if error occurred<br> * <b>false</b> - if email is incorrect<br> * <b>array(<br> * 'reg_key' => *,</b> //Registration confirmation key, or <b>true</b> * if confirmation is not required<br> * <b>'password' => *,</b> //Automatically generated password<br> * <b>'id' => *</b> //Id of registered user in DB<br> * <b>)</b> */ function registration($email, $confirmation = true, $auto_sign_in = true) { $email = mb_strtolower($email); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { return false; } $this->delete_unconfirmed_users(); if (!Trigger::instance()->run('System/User/registration/before', ['email' => $email])) { return false; } $email_hash = hash('sha224', $email); $login = strstr($email, '@', true); $login_hash = hash('sha224', $login); if ($login && in_array($login, file_get_json(MODULES . '/System/index.json')['profile']) || $this->get_id($login_hash) !== false) { $login = $email; $login_hash = $email_hash; } if ($this->db_prime()->qf(["SELECT `id`\n\t\t\tFROM `[prefix]users`\n\t\t\tWHERE `email_hash` = '%s'\n\t\t\tLIMIT 1", $email_hash])) { return 'exists'; } $Config = Config::instance(); $password = password_generate($Config->core['password_min_length'], $Config->core['password_min_strength']); $password_hash = hash('sha512', hash('sha512', $password) . Core::instance()->public_key); $reg_key = md5($password . $this->ip); $confirmation = $confirmation && $Config->core['require_registration_confirmation']; if ($this->db_prime()->q("INSERT INTO `[prefix]users` (\n\t\t\t\t`login`,\n\t\t\t\t`login_hash`,\n\t\t\t\t`password_hash`,\n\t\t\t\t`email`,\n\t\t\t\t`email_hash`,\n\t\t\t\t`reg_date`,\n\t\t\t\t`reg_ip`,\n\t\t\t\t`reg_key`,\n\t\t\t\t`status`\n\t\t\t) VALUES (\n\t\t\t\t'%s',\n\t\t\t\t'%s',\n\t\t\t\t'%s',\n\t\t\t\t'%s',\n\t\t\t\t'%s',\n\t\t\t\t'%s',\n\t\t\t\t'%s',\n\t\t\t\t'%s',\n\t\t\t\t'%s'\n\t\t\t)", $login, $login_hash, $password_hash, $email, $email_hash, TIME, ip2hex($this->ip), $reg_key, !$confirmation ? 1 : -1)) { $this->reg_id = $this->db_prime()->id(); if (!$confirmation) { $this->set_groups([self::USER_GROUP_ID], $this->reg_id); } if (!$confirmation && $auto_sign_in && $Config->core['auto_sign_in_after_registration']) { $this->add_session($this->reg_id); } if (!Trigger::instance()->run('System/User/registration/after', ['id' => $this->reg_id])) { $this->registration_cancel(); return false; } if (!$confirmation) { $this->set_groups([self::USER_GROUP_ID], $this->reg_id); } unset($this->cache->{$login_hash}); return ['reg_key' => !$confirmation ? true : $reg_key, 'password' => $password, 'id' => $this->reg_id]; } else { return 'error'; } }
<?php /** * @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; $rc =& Config::instance()->route; $subparts = file_get_json(MFOLDER . '/index.json')[$rc[0]]; $User = User::instance(); if (!isset($rc[1]) && $User->user() || isset($rc[1]) && !in_array($rc[1], $subparts)) { if (isset($rc[1])) { $rc[2] = $rc[1]; } else { $rc[2] = $User->login; } $rc[1] = $subparts[0]; }
<?php /** * @package HybridAuth * @category modules * @author HybridAuth authors * @author Nazar Mokrynskyi <*****@*****.**> (integration with CleverStyle CMS) * @copyright HybridAuth authors * @license MIT License, see license.txt */ namespace cs; use h; $Config = Config::instance(); $Index = Index::instance(); $L = Language::instance(); $Page = Page::instance(); $providers_config = $Config->module('HybridAuth')->providers; $providers = file_get_json(MFOLDER . '/../providers.json'); $Page->css('components/modules/HybridAuth/includes/css/admin.css'); $Page->main_sub_menu = h::{'li.uk-active a'}($L->providers_list, ['href' => 'admin/HybridAuth']); $Index->apply_button = false; $Index->content(h::{'table.cs-table-borderless.cs-left-even.cs-right-odd tr'}(h::{'th info'}('enable_contacts_detection') . h::{'td input[type=radio]'}(['name' => 'enable_contacts_detection', 'checked' => $Config->module('HybridAuth')->enable_contacts_detection, 'value' => [0, 1], 'in' => [$L->off, $L->on]])) . h::{'table.cs-hybrid-auth-providers-table.cs-table.cs-center-all'}(h::{'thead tr th'}([$L->provider, $L->settings, $L->state]) . h::{'tbody tr| td'}(array_map(function ($provider, $pdata) use($L, $providers_config, $Config) { $content = ''; if (isset($pdata['keys'])) { foreach ($pdata['keys'] as $key) { $content .= h::{'tr td'}([ucfirst($key), h::input(['name' => 'providers[' . $provider . '][keys][' . $key . ']', 'value' => isset($providers_config[$provider], $providers_config[$provider]['keys'][$key]) ? $providers_config[$provider]['keys'][$key] : ''])]); } } return [$L->{$provider}, h::{'table.cs-table-borderless.cs-left-even.cs-right-odd'}($content . (isset($pdata['scope']) ? h::{'tr td'}(['Scope', h::input(['name' => 'providers[' . $provider . '][scope]', 'value' => isset($providers_config[$provider], $providers_config[$provider]['scope']) ? $providers_config[$provider]['scope'] : $pdata['scope']])]) : '') . h::{'tr td.cs-left-all[colspan=2]'}(isset($pdata['info']) ? str_replace(['{base_url}', '{provider}'], [$Config->base_url(), $provider], $pdata['info']) : false)), h::{'input[type=radio]'}(['name' => 'providers[' . $provider . '][enabled]', 'checked' => isset($providers_config[$provider], $providers_config[$provider]['enabled']) ? $providers_config[$provider]['enabled'] : 0, 'value' => [0, 1], 'in' => [$L->off, $L->on]])]; }, array_keys($providers), $providers))));
/** * Initialization: loading of module structure, including of necessary module files, inclusion of save file */ protected function init() { $Config = Config::instance(); $L = Language::instance(); $Page = Page::instance(); $User = User::instance(); /** * Some routing preparations */ $rc_path =& $this->route_path; $rc_ids =& $this->route_ids; foreach ($Config->route as &$item) { if (is_numeric($item)) { $rc_ids[] =& $item; } else { $rc_path[] =& $item; } } unset($item, $rc_path, $rc_ids); $rc =& $this->route_path; if ($Config->core['simple_admin_mode'] && file_exists(MFOLDER . '/index_simple.json')) { $structure_file = 'index_simple.json'; } else { $structure_file = 'index.json'; } if (file_exists(MFOLDER . "/{$structure_file}")) { $this->structure = file_get_json(MFOLDER . "/{$structure_file}"); if (is_array($this->structure)) { foreach ($this->structure as $item => $value) { if (!is_array($value)) { $item = $value; } if ($User->get_permission($this->permission_group, $item)) { $this->parts[] = $item; if (isset($rc[0]) && $item == $rc[0] && is_array($value)) { foreach ($value as $subpart) { if ($User->get_permission($this->permission_group, "{$item}/{$subpart}")) { $this->subparts[] = $subpart; } elseif (isset($rc[1]) && $rc[1] == $subpart) { error_code(403); return; } } } } elseif ($rc[0] == $item) { error_code(403); return; } } unset($item, $value, $subpart); } } elseif (API && !file_exists(MFOLDER . '/index.php') && !file_exists(MFOLDER . "/index.{$this->request_method}.php")) { error_code(404); return; } unset($structure_file); _include_once(MFOLDER . '/index.php', false); if (API && $this->request_method) { _include_once(MFOLDER . "/index.{$this->request_method}.php", false); } if ($this->stop || defined('ERROR_CODE')) { return; } if ($this->parts) { if (!isset($rc[0]) || $rc[0] == '') { if (API) { return; } $rc[0] = $this->parts[0]; if (isset($this->structure[$rc[0]]) && is_array($this->structure[$rc[0]])) { $this->subparts = $this->structure[$rc[0]]; } } elseif ($rc[0] != '' && !empty($this->parts) && !in_array($rc[0], $this->parts)) { error_code(404); return; } /** * Saving of changes */ if (IN_ADMIN && !_include_once(MFOLDER . "/{$rc['0']}/{$this->savefile}.php", false)) { _include_once(MFOLDER . "/{$this->savefile}.php", false); } IN_ADMIN && $this->title_auto && $Page->title($L->administration); if (!$this->api && $this->title_auto) { $Page->title($L->{HOME ? 'home' : MODULE}); } if (!$this->api) { if (!HOME && $this->title_auto) { $Page->title($L->{$rc}[0]); } } /** * Warning if site is closed */ if (!$Config->core['site_mode']) { $Page->warning(get_core_ml_text('closed_title')); } _include_once(MFOLDER . "/{$rc['0']}.php", false); if (API && $this->request_method) { _include_once(MFOLDER . "/{$rc['0']}.{$this->request_method}.php", false); } if ($this->stop || defined('ERROR_CODE')) { return; } if ($this->subparts) { if (!isset($rc[1]) || $rc[1] == '' && !empty($this->subparts)) { if (API) { return; } $rc[1] = $this->subparts[0]; } elseif ($rc[1] != '' && !empty($this->subparts) && !in_array($rc[1], $this->subparts)) { error_code(404); return; } if (!$this->api) { if (!HOME && $this->title_auto) { $Page->title($L->{$rc}[1]); } if ($this->action === null) { $this->action = (IN_ADMIN ? 'admin/' : '') . MODULE . "/{$rc['0']}/{$rc['1']}"; } } _include_once(MFOLDER . "/{$rc['0']}/{$rc['1']}.php", false); if (API && $this->request_method) { _include_once(MFOLDER . "/{$rc['0']}/{$rc['1']}.{$this->request_method}.php", false); } if ($this->stop || defined('ERROR_CODE')) { return; } } elseif (!$this->api && $this->action === null) { $this->action = (IN_ADMIN ? 'admin/' : '') . MODULE . "/{$rc['0']}"; } unset($rc); if ($this->post_title && $this->title_auto) { $Page->title($this->post_title); } } elseif (!$this->api) { IN_ADMIN && $Page->title($L->administration); if (!$this->api && $this->title_auto) { $Page->title($L->{HOME ? 'home' : MODULE}); } if ($this->action === null) { $this->action = $Config->server['relative_address']; } _include_once(MFOLDER . "/{$this->savefile}.php", false); } }
foreach (array_diff(file_get_json("{$plugin_dir}/fs_old.json"), $fs) as $file) { $file = "{$plugin_dir}/{$file}"; if (file_exists($file) && is_writable($file)) { unlink($file); if (!get_files_list($dir = dirname($file))) { rmdir($dir); } } } unset($fs, $file, $dir); /** * Updating of plugin */ if (file_exists("{$plugin_dir}/versions.json")) { $old_version = file_get_json("{$plugin_dir}/meta_old.json")['version']; foreach (file_get_json("{$plugin_dir}/versions.json") as $version) { if (version_compare($old_version, $version, '<')) { /** * PHP update script */ _include("{$plugin_dir}/meta/update/{$version}.php", true, false); } } unset($old_version); } unlink("{$plugin_dir}/fs_old.json"); unlink("{$plugin_dir}/meta_old.json"); /** * Restore previous plugin state */ if ($active) {
/** * Checks whether specified functionality available or not * * @param string|string[] $functionality One functionality or array of them * * @return bool <i>true</i> if all functionality available, <i>false</i> otherwise */ function functionality($functionality) { if (is_array($functionality)) { $result = true; foreach ($functionality as $f) { $result = $result && functionality($f); } return $result; } $all = Cache::instance()->get("functionality", function () { $functionality = []; $components = Config::instance()->components; foreach ($components['modules'] as $module => $module_data) { if ($module_data['active'] != 1 || !file_exists(MODULES . "/{$module}/meta.json")) { continue; } $meta = file_get_json(MODULES . "/{$module}/meta.json"); if (!isset($meta['provide'])) { continue; } $functionality = array_merge($functionality, (array) $meta['provide']); } unset($module, $module_data, $meta); foreach ($components['plugins'] as $plugin) { if (!file_exists(PLUGINS . "/{$plugin}/meta.json")) { continue; } $meta = file_get_json(PLUGINS . "/{$plugin}/meta.json"); if (!isset($meta['provide'])) { continue; } $functionality = array_merge($functionality, (array) $meta['provide']); } return $functionality; }); return array_search($functionality, $all) !== false; }
* @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]); } } unset($engine, $parameters, $paremeter, $description, $table); Index::instance()->content(h::{'p.lead.cs-center'}(FIXED_LANGUAGE ? $L->language_fixed_as . ' ' . Core::instance()->language : false) . h::{'table.cs-table-borderless.cs-left-even.cs-right-odd tr| td'}(core_select($Config->core['active_languages'], 'language', 'change_language', 'current_language'), core_select($Config->core['languages'], 'active_languages', 'change_active_languages', null, true), [h::info('multilingual'), h::{'input[type=radio]'}(['name' => 'core[multilingual]', 'checked' => $Config->core['multilingual'], 'value' => [0, 1], 'in' => [$L->off, $L->on], 'OnClick' => ["\$('.cs-multilingual').hide(); \$('.cs-auto-translation').hide();", "\$('.cs-multilingual').show(); if (\$('#auto_translation [value=1]').prop('checked')) \$('.cs-auto-translation').show();"]])], [[h::info('auto_translation'), h::{'input[type=radio]'}(['name' => 'core[auto_translation]', 'checked' => $Config->core['auto_translation'], 'value' => [0, 1], 'in' => [$L->off, $L->on], 'OnClick' => ["\$('.cs-auto-translation').hide();", "\$('.cs-auto-translation').show();"]])], ['style' => !$Config->core['multilingual'] ? 'display: none; ' : '', 'id' => 'auto_translation', 'class' => 'cs-multilingual']], [[h::info('auto_translation_engine'), h::select($translate_engines, ['name' => 'core[auto_translation_engine][name]', 'selected' => $Config->core['auto_translation_engine']['name'], 'data-settings' => $translate_engines_settings, 'size' => 5])], ['style' => !$Config->core['multilingual'] || !$Config->core['auto_translation'] ? 'display: none; ' : '', 'id' => 'auto_translation_engine', 'class' => 'cs-auto-translation']], [[$L->auto_translation_engine_settings, ['style' => !$Config->core['multilingual'] || !$Config->core['auto_translation'] ? 'display: none; ' : '', 'class' => 'cs-auto-translation cs-multilingual']], [$current_engine_settings, ['style' => !$Config->core['multilingual'] || !$Config->core['auto_translation'] ? 'display: none; ' : '', 'id' => 'auto_translation_engine_settings', 'class' => 'cs-auto-translation']]]));
private function _crawl() { $this->_init(); //preload existing json $files = array(); if (is_dir($this->cache_path)) { $jsons = scandir($this->cache_path); foreach ($jsons as $json_filename) { if (substr($json_filename, -5) != '.json') { continue; } list($file, $type) = explode('.', substr($json_filename, 0, -5)); if ($type != 'updated' && $type != 'log') { continue; } list($project, $lang, $id) = explode('-', $file); $files[$project][$lang][$id][$type] = file_get_json($this->cache_path . $json_filename); unset($file, $type, $project, $lang, $id); } } unset($jsons, $json_filename); //crawl repos and build update $devices_path = $this->repo_path; $devices = @scandir($devices_path); if (!empty($devices)) { foreach ($devices as $device_index => $device) { if (substr($device, 0, 1) == '.' || !is_dir($devices_path . $device . '/')) { unset($devices[$device_index]); continue; } $projects_path = $devices_path . $device . '/'; $projects = scandir($projects_path); if (!empty($projects)) { foreach ($projects as $project_index => $project_filename) { if (substr($project_filename, 0, 3) != 'uw-' || !is_dir($projects_path . $project_filename . '/')) { unset($projects[$project_index]); continue; } list($project, $lang) = explode('-', substr($project_filename, 3)); $ids_path = $projects_path . $project_filename . '/'; $ids = scandir($ids_path); if (!empty($ids)) { foreach ($ids as $id_index => $id) { if (substr($id, 0, 1) == '.' || !is_dir($ids_path . $id . '/')) { unset($ids[$id_index]); continue; } $data =& $files[$project][$lang][$id]; $frames_path = $ids_path . $id . '/'; $frames = scandir($frames_path); if (!empty($frames)) { foreach ($frames as $frame_index => $frame_filename) { if (substr($frame_filename, -4) != '.txt') { unset($frames[$frame_index]); continue; } $frame = substr($frame_filename, 0, -4); $updated = date('Y-m-d H:i:s', filemtime($frames_path . $frame_filename)); if ($data['log'][$device][$frame]['time'] < $updated) { $data['updated']['devices'][$device][$frame] = $updated; $data['updated']['frames'][$frame][] = $device; $data['log'][$device][$frame] = array('time' => $updated, 'action' => 'updated'); } } } unset($frame_index, $frame_filename, $frame, $updated); } } unset($id_index, $id); } } unset($project_index, $project); } } unset($device_index, $device); //update json foreach ($files as $project => $langs) { foreach ($langs as $lang => $ids) { foreach ($ids as $id => $content) { file_put_json($this->cache_path . $this->_get_log_filename($project, $lang, $id, 'updated'), $content['updated']); file_put_json($this->cache_path . $this->_get_log_filename($project, $lang, $id, 'log'), $content['log']); } } } unset($files, $project, $langs, $lang, $ids, $id, $content); }
<?php /** * @package Download * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs; if (!file_exists(DIR . '/downloads')) { $downloads = 0; } else { $downloads = file_get_json(DIR . '/downloads'); } $downloads++; file_put_json(DIR . '/downloads', $downloads); header('Location: https://opir.org/storage/public/opir.org.apk', true, 301); interface_off(); Index::instance()->stop = true;