* @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']]]));
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]]); }
$a->buttons = true; $a->apply_button = false; $a->cancel_button_back = true; module_storage_settings: if (file_exists(MODULES . "/{$rc['3']}/meta/storage.json")) { $storages = [0 => $L->core_storage]; foreach ($Config->storage as $i => &$storage_data) { if ($i) { $storages[$i] = "{$storage_data['host']} ({$storage_data['connection']})"; } } unset($i, $storage_data); $storage_list = []; $storage_json = file_get_json(MODULES . "/{$rc['3']}/meta/storage.json"); foreach ($storage_json as $storage) { $storage_list[] = [$L->{"{$rc['3']}_storage_{$storage}"}, h::select(['in' => array_values($storages), 'value' => array_keys($storages)], ['name' => "storage[{$storage}]", 'selected' => isset($Config->components['modules'][$rc[3]]['storage'][$storage]) ? $Config->components['modules'][$rc[3]]['storage'][$storage] : 0, 'size' => 5])]; } unset($storage_json, $storages, $storage); $a->content(h::{'table.cs-table'}(h::{'thead tr th'}([h::info('appointment_of_storage'), h::info('system_storage')]) . h::{'tbody tr| td'}($storage_list))); unset($storage_list); } if ($rc[2] == 'install') { goto back_to_module_installation_2; } } break; case 'enable': $show_modules = false; $check_dependencies = check_dependencies($rc[3], 'module', null, 'enable'); if (!$check_dependencies && $Config->core['simple_admin_mode']) { break;
if (isset($user_data['reg_ip'])) { $user_data['reg_ip'] = hex2ip($user_data['reg_ip'], 10); if ($user_data['reg_ip'][1]) { $user_data['reg_ip'] = $user_data['reg_ip'][0] . h::br() . $user_data['reg_ip'][1]; } else { $user_data['reg_ip'] = $user_data['reg_ip'][0]; } } if (isset($user_data['last_ip'])) { $user_data['last_ip'] = hex2ip($user_data['last_ip'], 10); if ($user_data['last_ip'][1]) { $user_data['last_ip'] = $user_data['last_ip'][0] . h::br() . $user_data['last_ip'][1]; } else { $user_data['last_ip'] = $user_data['last_ip'][0]; } } if (in_array(User::ADMIN_GROUP_ID, $groups)) { $type = h::info('a'); } elseif (in_array(User::USER_GROUP_ID, $groups)) { $type = h::info('u'); } elseif ($is_bot) { $type = h::info('b'); } else { $type = h::info('g'); } $users_list[] = array_values([$buttons, $type] + $user_data); } } unset($id, $buttons, $user_data, $users_ids, $is_guest, $is_root, $is_bot); $a->content(h::{'ul.cs-tabs li'}($L->search, h::info('show_columns')) . h::div(h::div(h::select(['in' => array_merge([$L->all_columns], $search_columns), 'value' => array_merge([''], $search_columns)], ['selected' => $search_column ?: '', 'name' => 'search_column']) . $L->search_mode . ' ' . h::select($search_modes, ['selected' => $search_mode ?: 'LIKE', 'name' => 'search_mode']) . h::{'input.uk-form-width-medium'}(['value' => $search_text, 'name' => 'search_text', 'placeholder' => $L->search_text]) . $L->page . ' ' . h::{'input[type=number]'}(['value' => $start + 1, 'min' => 1, 'name' => 'search_start']) . $L->items . ' ' . h::{'input[type=number]'}(['value' => $limit, 'min' => 1, 'name' => 'search_limit']), ['style' => 'text-align: left;']) . h::{'ul#cs-users-search-columns.uk-padding-remove'}($columns_list)) . h::{'input#cs-users-search-selected-columns[name=columns][type=hidden]'}() . h::hr() . h::{'p.cs-left'}(h::{'button[type=submit]'}($L->search), $L->found_users($results_count) . ($results_count > $limit ? ' / ' . $L->page_from($start + 1, ceil($results_count / $limit)) : '')) . h::{'table.cs-table.cs-center-all'}(h::{'thead tr th'}(array_merge([$L->action, ''], $columns)) . h::{'tbody tr| td'}($users_list)) . h::{'p.cs-left'}($L->found_users($results_count) . ($results_count > $limit ? ' / ' . $L->page_from($start + 1, ceil($results_count / $limit)) : ''), h::{'a.cs-button'}($L->add_user, ['href' => 'admin/System/users/users/add/0']) . h::{'a.cs-button'}($L->add_bot, ['href' => 'admin/System/users/users/add_bot/0']))); }
<?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\modules\System; use h, cs\Config, cs\Index; $Config = Config::instance(); $timezones = get_timezones_list(); $sa = $Config->core['simple_admin_mode']; Index::instance()->content(h::{'table.cs-table-borderless.cs-left-even.cs-right-odd tr| td'}(core_input('name', 'text', 'site_name'), !$sa ? core_textarea('url') : false, !$sa ? core_textarea('cookie_domain') : false, !$sa ? core_textarea('cookie_path') : false, !$sa ? core_input('cookie_prefix') : false, [h::info('timezone'), h::select(['in' => array_keys($timezones), 'value' => array_values($timezones)], ['name' => 'core[timezone]', 'selected' => $Config->core['timezone'], 'size' => 7])], core_input('admin_email', 'email')));
} 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; } } } }
function core_select($items_array, $item, $id = null, $info_item = null, $multiple = false, $size = 5) { return [h::info($info_item ?: $item), h::select($items_array, ['name' => "core[{$item}]" . ($multiple ? '[]' : ''), 'selected' => Config::instance()->core[$item], 'size' => $size, 'id' => $id ?: false, $multiple ? 'multiple' : false])]; }
/** * Generate header * * @param array $options * @return string */ private function header($options) { $result = ''; $result .= '<table cellpadding="2" cellspacing="0" width="100%" class="editor footer top">'; $result .= '<tr>'; $result .= '<td><span>Displaying:</span> '; $result .= h::select(array('options' => array(20 => array('name' => 20), 30 => array('name' => 30), 50 => array('name' => 50), 100 => array('name' => 100), 200 => array('name' => 200), 500 => array('name' => 500)), 'value' => $options['limit'], 'no_choose' => true, 'onchange' => 'document.getElementById(\'offset\').value = 0; document.getElementById(\'limit\').value = this.value; this.form.submit();')); $result .= '</td>'; // separator $result .= '<td class="editor separator">|</td>'; $result .= '<td>'; $result .= ' <span>Fetched: ' . $options['num_rows'] . (@$options['count_rows'] ? ' of ' . $options['count_rows'] : '') . '</span>'; $result .= '</td>'; // separator $result .= '<td class="editor separator">|</td>'; // time $result .= '<td><span>Query took:</span> ' . $options['took'] . ' seconds</td>'; // separator $result .= '<td class="editor separator">|</td>'; // building pages $result .= '<td align="right">'; $result_pages = array(); $current_page = intval($options['offset'] / $options['limit']); if ($current_page >= 2) { $result_pages[] = h::button2(array('value' => '<span class="ui-icon ui-icon-seek-first"></span>', 'class' => 'button button_short', 'onclick' => 'document.getElementById(\'offset\').value = 0;this.form.submit();')); } if ($current_page >= 1) { $result_pages[] = h::button2(array('value' => '<span class="ui-icon ui-icon-seek-prev"></span>', 'class' => 'button button_short', 'onclick' => 'document.getElementById(\'offset\').value = ' . ($current_page - 1) * $options['limit'] . ';this.form.submit();')); } // select with number of pages if (isset($options['count_rows'])) { $pages = ceil($options['count_rows'] / $options['limit']); $temp = array(); for ($i = 0; $i < $pages; $i++) { $temp[$i * $options['limit']] = array('name' => $i + 1); } $result_pages[] = '<span>Page:</span> ' . h::select(array('options' => $temp, 'value' => $options['offset'], 'no_choose' => true, 'onchange' => 'document.getElementById(\'offset\').value = this.value; this.form.submit();')); // checking for next and last pages $options['flag_next_row_exists'] = $pages - $current_page - 2 > 0 ? true : false; $options['flag_last_row_exists'] = $pages - $current_page - 1 > 0 ? true : false; } else { // showing hidden element $result_pages[] = 'Page: ' . ($current_page + 1); } if (@$options['flag_next_row_exists']) { $result_pages[] = h::button2(array('value' => '<span class="ui-icon ui-icon-seek-next"></span>', 'class' => 'button button_short', 'onclick' => '$(\'#offset\').val(' . ($current_page + 1) * $options['limit'] . '); this.form.submit();')); } if (@$options['flag_last_row_exists']) { $result_pages[] = h::button2(array('value' => '<span class="ui-icon ui-icon-seek-end"></span>', 'class' => 'button button_short', 'onclick' => '$(\'#offset\').val(' . ($pages - 1) * $options['limit'] . '); this.form.submit();')); } $result .= implode(' | ', $result_pages); $result .= '</td>'; $result .= '</tr>'; $result .= '</table>'; return $result; }
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);
$Page->title($L->my_profile); $Page->title($L->settings); $Index->action = path($L->profile) . '/' . path($L->settings); switch (isset($Config->route[2]) ? $Config->route[2] : '') { default: $Index->content(h::p(h::{'a.cs-button'}($L->general, ['href' => "{$Index->action}/" . path($L->general)]) . h::{'a.cs-button'}($L->change_password, ['href' => "{$Index->action}/" . path($L->change_password)]))); Trigger::instance()->run('System/profile/settings'); break; case 'general': $user_data = $User->get($columns); unset($columns); $timezones = get_timezones_list(); $row = function ($col1, $col2) { return h::th($col1) . h::td($col2); }; $Index->form = true; $Index->form_atributes['class'] = 'cs-center'; $Index->apply_button = false; $Index->cancel_button_back = true; $Page->title($L->general); $Index->content(h::{'p.lead.cs-center'}($L->general_settings) . h::{'table.cs-table-borderless.cs-left-even.cs-right-odd tr'}($row($L->login, h::input(['name' => 'user[login]', 'value' => $user_data['login']])), $row($L->username, h::input(['name' => 'user[username]', 'value' => $user_data['username']])), $row($L->language, h::select(['in' => array_merge([$L->system_default], $Config->core['active_languages']), 'value' => array_merge([''], $Config->core['active_languages'])], ['name' => 'user[language]', 'selected' => $user_data['language'], 'size' => 5])), $row($L->timezone, h::select(['in' => array_merge(["{$L->system_default} ({$Config->core['timezone']})"], array_keys($timezones)), 'value' => array_merge([''], array_values($timezones))], ['name' => 'user[timezone]', 'selected' => $user_data['timezone'], 'size' => 5])), $row($L->avatar, h::input(['name' => 'user[avatar]', 'value' => $user_data['avatar']])))); break; case 'change_password': $Index->form = true; $Index->form_atributes['class'] = 'cs-center'; $Index->buttons = false; $Index->cancel_button_back = true; $Page->title($L->password_changing); $Index->content(h::{'p.lead.cs-center'}($L->password_changing) . h::{'table.cs-table-borderless.cs-left-even.cs-right-odd tr'}(h::th("{$L->current_password} " . h::{'icon#current_password.cs-pointer'}('lock')) . h::td(h::{'input.cs-profile-current-password[type=password]'}()), h::th("{$L->new_password} " . h::{'icon#new_password.cs-pointer'}('lock')) . h::td(h::{'input.cs-profile-new-password[type=password]'}())) . h::{'button.cs-profile-change-password'}($L->change_password)); break; }