function get_pages_rows() { $L = Language::instance(); $Static_pages = Static_pages::instance(); $categories = array_slice(Config::instance()->route, 2); $structure = $Static_pages->get_structure(); $path = []; if (!empty($categories)) { foreach ($categories as $category) { $category = $Static_pages->get_category($category)['path']; if (isset($structure['categories'][$category])) { $structure = $structure['categories'][$category]; $path[] = $structure['path']; } } unset($category); } Page::instance()->title($structure['id'] == 0 ? $L->root_category : $structure['title']); $path = !empty($path) ? implode('/', $path) . '/' : ''; $content = []; if (!empty($structure['pages'])) { foreach ($structure['pages'] as &$page) { $page = $Static_pages->get($page); $content[] = [[h::a($page['title'], ['href' => $path . $page['path']]), ['class' => 'cs-static-pages-padding-left-0']], h::{'a.cs-button-compact'}([h::icon('file-text'), ['href' => "admin/Static_pages/edit_page/{$page['id']}", 'data-title' => $L->edit]], [h::icon('trash-o'), ['href' => "admin/Static_pages/delete_page/{$page['id']}", 'data-title' => $L->delete]])]; } } return [$content]; }
<?php /** * @package Static Pages * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2011-2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\Static_pages; use h, cs\Config, cs\Index, cs\Language, cs\Page; $Index = Index::instance(); $L = Language::instance(); $id = (int) Config::instance()->route[1]; $title = Static_pages::instance()->get_category($id)['title']; Page::instance()->title($L->deletion_of_page_category($title)); $Index->buttons = false; $Index->cancel_button_back = true; $Index->action = 'admin/Static_pages'; $Index->content(h::{'p.lead.cs-center'}($L->sure_to_delete_page_category($title)) . h::{'button[type=submit]'}($L->yes) . h::{'input[type=hidden][name=id]'}(['value' => $id]) . h::{'input[type=hidden][name=mode][value=delete_category]'}());
} unset($regions, $region); $Precincts->db_prime()->q("INSERT INTO `[prefix]precincts` (`id`, `number`, `address_uk`, `address_en`, `address_ru`, `lat`, `lng`, `district`, `violations`) VALUES (NULL, '0', '01196, м.Київ, площа Лесі Українки, 1, 2-й поверх, хол прес-центру ЦВК', '1196, Kyiv, Lesi Ukrainky square 1, 2nd Floor, Hall Press Center CEC', '01196, г.Киев, площадь Леси Украинки, 1, 2-й этаж, холл пресс-центра ЦИК', '50.428073', '30.541399', '0', '0')"); } if (isset($_POST['update_addresses'])) { time_limit_pause(); $Precincts = Precincts::instance(); $all_precincts = $Precincts->get_all(); $cdb = $Precincts->db_prime(); foreach ($all_precincts as $p) { if ($cdb->qfs("SELECT `address_en` FROM `[prefix]precincts` WHERE `id` = {$p}")) { continue; } $p = $Precincts->get($p); $en_address = _json_decode(file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . rawurlencode($p['address']) . '&sensor=false&language=en')); if ($en_address['status'] == 'OK') { $cdb->q("UPDATE `[prefix]precincts`\n\t\t\t\tSET `address_en` = '%s'\n\t\t\t\tWHERE `id` = '%s'", $en_address['results'][0]['formatted_address'], $p['id']); } unset($en_address); $ru_address = _json_decode(file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . rawurlencode($p['address']) . '&sensor=false&language=ru')); if ($ru_address['status'] == 'OK') { $cdb->q("UPDATE `[prefix]precincts`\n\t\t\t\tSET `address_ru` = '%s'\n\t\t\t\tWHERE `id` = '%s'", $ru_address['results'][0]['formatted_address'], $p['id']); } unset($ru_address); } } $Index = Index::instance(); $Index->buttons = false; $Index->content(h::{'button[type=submit][name=update]'}('Оновити список дільниць з офіційного сайту виборів') . h::{'button[type=submit][name=update_districts]'}('Оновити список округів з офіційного сайту виборів') . h::{'button[type=submit][name=update_addresses]'}('Уточнити адреси дільниць російською та англійською')); Page::instance()->warning('Оновлення призведе до видалення дільниць, дані пов’язані з ними буде втрачено');
* @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\Home; use cs\Index, cs\Page, cs\User; $Index = Index::instance(); if (!isset($Index->route_ids[0], $_POST['driver'])) { error_code(400); return; } $User = User::instance(); if (!in_array(AUTOMAIDAN_COORD_GROUP, $User->get_groups())) { error_code(403); return; } $Events = Events::instance(); $event = $Events->get($Index->route_ids[0]); if (!$event) { error_code(404); return; } if ($event['user'] == $_POST['driver']) { error_code(400); Page::instance()->error('Цей той самий водій, який додав подію на карту, оберіть іншого для підтвердження.'); } if (!Events::instance()->check_assign($Index->route_ids[0], $_POST['driver'])) { error_code(500); }
* @package Precincts * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\Precincts; use cs\Index, cs\Page, cs\User; $Index = Index::instance(); $User = User::instance(); if (!$User->user()) { error_code(403); return; } if (!isset($Index->route_ids[0]) || (!isset($_POST['text']) || empty($_POST['text'])) && (!isset($_POST['images']) || empty($_POST['images'])) && (!isset($_POST['video']) || empty($_POST['video']))) { error_code(400); return; } $Precincts = Precincts::instance(); if (!$Precincts->get($Index->route_ids[0])) { error_code(404); return; } $Violations = Violations::instance(); $id = $Violations->add($Index->route_ids[0], $User->id, isset($_POST['text']) ? $_POST['text'] : '', isset($_POST['images']) ? (array) $_POST['images'] : [], isset($_POST['video']) ? $_POST['video'] : '', isset($_POST['location']) ? $_POST['location'] : [], isset($_POST['device_model']) ? $_POST['device_model'] : ''); if (!$id) { error_code(500); } Page::instance()->json($id);
<?php /** * @package Moderation * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\Precincts; use cs\Page; $Violations = Violations::instance(); Page::instance()->json($Violations->get($Violations->get_declined()));
<?php /** * @package Static Pages * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2011-2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\Static_pages; use h, cs\Config, cs\Index, cs\Language, cs\Page; $Index = Index::instance(); $L = Language::instance(); $id = (int) Config::instance()->route[1]; $data = Static_pages::instance()->get_category($id); Page::instance()->title($L->editing_of_page_category($data['title'])); $Index->apply_button = false; $Index->cancel_button_back = true; $Index->action = 'admin/Static_pages'; $Index->content(h::{'p.lead.cs-center'}($L->editing_of_page_category($data['title'])) . h::{'table.cs-table-borderless.cs-center-all'}(h::{'thead tr th'}($L->parent_category, $L->category_title, h::info('category_path')), h::{'tbody tr td'}(h::{'select[name=parent][size=5]'}(get_categories_list($id), ['selected' => $data['parent']]), h::{'input[name=title]'}(['value' => $data['title']]), h::{'input[name=path]'}(['value' => $data['path']]))) . h::{'input[type=hidden][name=id]'}(['value' => $id]) . h::{'input[type=hidden][name=mode][value=edit_category]'}());
<?php /** * @package Plupload * @category modules * @author Moxiecode Systems AB * @author Nazar Mokrynskyi <*****@*****.**> (integration with CleverStyle CMS) * @copyright Moxiecode Systems AB * @license GNU GPL v2, see license.txt */ namespace cs; use h; if (isset($_POST['edit_settings'], $_POST['max_file_size']) && $_POST['edit_settings'] == 'save') { $module_data = Config::instance()->module('Plupload'); $module_data->max_file_size = xap($_POST['max_file_size']); $module_data->confirmation_time = (int) $_POST['confirmation_time']; Index::instance()->save(true); } Page::instance()->main_sub_menu = h::{'li.uk-active a'}('Plupload', ['href' => 'admin/Plupload']);
<?php /** * @package Static Pages * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2011-2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\Static_pages; use h, cs\Config, cs\Index, cs\Language, cs\Page; $Index = Index::instance(); $L = Language::instance(); $id = (int) Config::instance()->route[1]; $title = Static_pages::instance()->get($id)['title']; Page::instance()->title($L->deletion_of_page($title)); $Index->buttons = false; $Index->cancel_button_back = true; $Index->action = 'admin/Static_pages'; $Index->content(h::{'p.lead.cs-center'}($L->sure_to_delete_page($title)) . h::{'button[type=submit]'}($L->yes) . h::{'input[type=hidden][name=id]'}(['value' => $id]) . h::{'input[type=hidden][name=mode][value=delete_page]'}());
<?php /** * @package OAuth2 * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2011-2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\OAuth2; use h, cs\Index, cs\Language\Prefix, cs\Page; $Index = Index::instance(); $L = new Prefix('oauth2_'); Page::instance()->title($L->addition_of_client); $Index->apply_button = false; $Index->cancel_button_back = true; $Index->action = 'admin/OAuth2/clients/list'; $Index->content(h::{'p.lead.cs-center'}($L->addition_of_client) . h::{'table.cs-table-borderless.cs-left-even.cs-right-odd tr'}(h::th($L->client_name) . h::{'td input[name=name]'}(), h::th($L->client_domain) . h::{'td input[name=domain]'}(), h::th($L->active) . h::{'td input[type=radio][name=active][checked=1]'}(['value' => [0, 1], 'in' => [$L->no, $L->yes]])) . h::{'input[type=hidden][name=mode][value=add]'}());
<?php /** * @package Moderation * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\Precincts; use cs\Page; $Violations = Violations::instance(); Page::instance()->json($Violations->get($Violations->get_new()));
/** * Pages navigation based on links * * @param int $page Current page * @param int $total Total pages number * @param Closure|string $url if string - it will be formatted with sprintf with one parameter - page number<br> * if Closure - one parameter will be given, Closure should return url string * @param bool $head_links If <b>true</b> - links with rel="prev" and rel="next" will be added * * @return bool|string <b>false</b> if single page, otherwise string, set of navigation links */ function pages($page, $total, $url, $head_links = false) { if ($total == 1) { return false; } $Page = Page::instance(); $output = []; if ($url instanceof Closure) { $url_func = $url; } else { $original_url = $url; $url_func = function ($page) use($original_url) { return sprintf($original_url, $page); }; } $base_url = Config::instance()->base_url(); $url = function ($page) use($url_func, $base_url) { $url = $url_func($page); if (is_string($url) && strpos($url, 'http') !== 0) { $url = $base_url . '/' . ltrim($url, '/'); } return $url; }; if ($total <= 11) { for ($i = 1; $i <= $total; ++$i) { $output[] = [$i, ['href' => $i == $page ? false : $url($i), 'class' => $i == $page ? 'cs-button uk-button-primary uk-frozen' : 'cs-button']]; if ($head_links && ($i == $page - 1 || $i == $page + 1)) { $Page->link(['href' => $url instanceof Closure ? $url($i) : sprintf($url, $i), 'rel' => $i == $page - 1 ? 'prev' : ($i == $page + 1 ? 'next' : false)]); } } } else { if ($page <= 5) { for ($i = 1; $i <= 7; ++$i) { $output[] = [$i, ['href' => $i == $page ? false : $url($i), 'class' => $i == $page ? 'cs-button uk-button-primary uk-frozen' : 'cs-button']]; if ($head_links && ($i == $page - 1 || $i == $page + 1)) { $Page->link(['href' => $url instanceof Closure ? $url($i) : sprintf($url, $i), 'rel' => $i == $page - 1 ? 'prev' : ($i == $page + 1 ? 'next' : false)]); } } $output[] = ['...', ['class' => 'cs-button uk-frozen']]; for ($i = $total - 2; $i <= $total; ++$i) { $output[] = [$i, ['href' => $url instanceof Closure ? $url($i) : sprintf($url, $i), 'class' => 'cs-button']]; } } elseif ($page >= $total - 4) { for ($i = 1; $i <= 3; ++$i) { $output[] = [$i, ['href' => $url instanceof Closure ? $url($i) : sprintf($url, $i), 'class' => 'cs-button']]; } $output[] = ['...', ['class' => 'cs-button uk-frozen']]; for ($i = $total - 6; $i <= $total; ++$i) { $output[] = [$i, ['href' => $i == $page ? false : $url($i), 'class' => $i == $page ? 'cs-button uk-button-primary uk-frozen' : 'cs-button']]; if ($head_links && ($i == $page - 1 || $i == $page + 1)) { $Page->link(['href' => $url instanceof Closure ? $url($i) : sprintf($url, $i), 'rel' => $i == $page - 1 ? 'prev' : ($i == $page + 1 ? 'next' : false)]); } } } else { for ($i = 1; $i <= 2; ++$i) { $output[] = [$i, ['href' => $url instanceof Closure ? $url($i) : sprintf($url, $i), 'class' => 'cs-button']]; } $output[] = ['...', ['class' => 'cs-button uk-frozen']]; for ($i = $page - 1; $i <= $page + 3; ++$i) { $output[] = [$i, ['href' => $i == $page ? false : $url($i), 'class' => $i == $page ? 'cs-button uk-button-primary uk-frozen' : 'cs-button']]; if ($head_links && ($i == $page - 1 || $i == $page + 1)) { $Page->link(['href' => $url instanceof Closure ? $url($i) : sprintf($url, $i), 'rel' => $i == $page - 1 ? 'prev' : ($i == $page + 1 ? 'next' : false)]); } } $output[] = ['...', ['class' => 'cs-button uk-frozen']]; for ($i = $total - 1; $i <= $total; ++$i) { $output[] = [$i, ['href' => $url instanceof Closure ? $url($i) : sprintf($url, $i), 'class' => 'cs-button']]; } } } return h::a($output); }
/** * 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; }
<?php /** * @package Home * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\Home; use cs\Page, cs\User; $User = User::instance(); if (!in_array(AUTOMAIDAN_GROUP, $User->get_groups())) { error_code(403); return; } $event = Events::instance()->check_is_assigned(); if (!$event) { error_code(404); } else { Page::instance()->json($event); }
<?php /** * @package Moderation * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\Precincts; use cs\Index, cs\Page, cs\User; $Index = Index::instance(); if (!isset($_POST['status'], $Index->route_ids[0])) { error_code(400); return; } $Violations = Violations::instance(); $action = $_POST['status'] ? 'approve' : 'decline'; $violation = $Violations->get($Index->route_ids[0]); if (!$Violations->{$action}($violation['id'])) { error_code(500); return; } Page::instance()->json(['user' => (int) $violation['user'], 'rating' => (int) $Violations->user_rating($violation['user']), 'username' => User::instance()->username($violation['user'])]);
<?php /** * @package Help * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\Help; use cs\Page; Page::instance()->json(Help::get());
<?php /** * @package Precincts * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\Precincts; use cs\Index, cs\Page, cs\User; $Index = Index::instance(); $User = User::instance(); if (!$User->user()) { error_code(403); return; } if (!isset($Index->route_ids[0]) || !in_array($_POST['value'], [-1, 1])) { error_code(400); return; } if (Violations_feedback::instance()->add($Index->route_ids[0], $User->id, $_POST['value'])) { Page::instance()->json('ok'); }
/** * Executes plugins processing, blocks and module page generation */ function __finish() { static $finished = false; if ($finished) { return; } $finished = true; $Config = Config::instance(); $Page = Page::instance(); /** * If site is closed, user is not admin, and it is not request for sign in */ if (!$Config->core['site_mode'] && !(User::instance()->admin() || API && $Config->route === ['user', 'sign_in'])) { code_header(503); return; } if (defined('ERROR_CODE')) { $Page->error(); } Trigger::instance()->run('System/Index/preload'); if (!IN_ADMIN && !$this->api && file_exists(MODULES . '/' . MODULE . '/index.html')) { ob_start(); _include(MODULES . '/' . MODULE . '/index.html', false, false); $Page->content(ob_get_clean()); if ($this->title_auto) { $Page->title(Language::instance()->{HOME ? 'home' : MODULE}); } } elseif (!defined('ERROR_CODE') && !$this->stop) { $this->init_auto && $this->init(); } if ($this->generate_auto) { $this->generate(); } if ($this->stop) { if (_getcookie('sign_out') && !(API && MODULE == 'System' && $Config->route == ['user', 'sign_out'])) { _setcookie('sign_out', ''); } return; } if (defined('ERROR_CODE')) { $Page->error(); } elseif (_getcookie('sign_out') && !(API && MODULE == 'System' && $Config->route == ['user', 'sign_out'])) { _setcookie('sign_out', ''); } Trigger::instance()->run('System/Index/postload'); }
<?php /** * @package Moderation * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\Precincts; use cs\Page; $Streams = Streams::instance(); Page::instance()->json($Streams->get($Streams->get_approved()));
<?php /** * @package Static Pages * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2011-2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\Static_pages; use h, cs\Config, cs\Index, cs\Language, cs\Page; $Config = Config::instance(); $Index = Index::instance(); $L = Language::instance(); Page::instance()->title($L->addition_of_page_category); $Index->apply_button = false; $Index->cancel_button_back = true; $Index->action = 'admin/Static_pages'; $Index->content(h::{'p.lead.cs-center'}($L->addition_of_page_category) . h::{'table.cs-table-borderless.cs-center-all'}(h::{'thead tr th'}($L->parent_category, $L->category_title, h::info('category_path')), h::{'tbody tr td'}(h::{'select[name=parent][size=5]'}(get_categories_list(), ['selected' => isset($Config->route[1]) ? (int) $Config->route[1] : 0]), h::{'input[name=title]'}(), h::{'input[name=path]'}())) . h::{'input[type=hidden][name=mode][value=add_category]'}());
<?php /** * @package Home * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\Home; use cs\Page; Page::instance()->json(Events_categories_groups::instance()->get_all());
<?php /** * @package Moderation * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\Precincts; use cs\Page; $Streams = Streams::instance(); Page::instance()->json($Streams->get($Streams->get_declined()));
* @copyright Copyright (c) 2013-2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs; use h; /** * Multilingual functionality: redirects and necessary meta-tags */ Trigger::instance()->register('System/User/construct/after', function () { $Config = Config::instance(); if (!$Config->core['multilingual']) { return; } $relative_address = $Config->server['relative_address']; $Cache = Cache::instance(); if (!FIXED_LANGUAGE && $_SERVER['REQUEST_METHOD'] == 'GET' && $Cache->cache_state() && Core::instance()->cache_engine != 'BlackHole') { $clang = Language::instance()->clang; if (!HOME) { header("Location: /{$clang}/{$relative_address}", true, 301); } else { header("Location: /{$clang}", true, 301); } } $base_url = substr($Config->base_url(), 0, -3); Page::instance()->Head .= h::{'link[rel=alternate]'}(['hreflang' => 'x-default', 'href' => !HOME ? "{$base_url}/{$relative_address}" : "{$base_url}"]) . h::{'link[rel=alternate]|'}(array_map(function ($lang) use($base_url, $relative_address) { return ['hreflang' => $lang, 'href' => "{$base_url}/{$lang}/{$relative_address}"]; }, array_values($Cache->get('languages/clangs', function () use($Config) { return $Config->update_clangs(); })) ?: [])); });
/** * Create the session for the user with specified id * * @param bool|int $user * @param bool $delete_current_session * * @return bool */ function add_session($user = false, $delete_current_session = true) { $user = (int) $user ?: self::GUEST_ID; if ($delete_current_session && is_md5($this->current['session'])) { $this->del_session_internal(null, false); } /** * Load user data * Return point, runs if user is blocked, inactive, or disabled */ getting_user_data: $data = $this->get(['login', 'username', 'language', 'timezone', 'status', 'block_until', 'avatar'], $user); if (is_array($data)) { $L = Language::instance(); $Page = Page::instance(); if ($data['status'] != self::STATUS_ACTIVE) { /** * If user is disabled */ if ($data['status'] == self::STATUS_INACTIVE) { $Page->warning($L->your_account_disabled); /** * Mark user as guest, load data again */ $user = self::GUEST_ID; goto getting_user_data; /** * If user is not active */ } else { $Page->warning($L->your_account_is_not_active); /** * Mark user as guest, load data again */ $user = self::GUEST_ID; goto getting_user_data; } /** * If user if blocked */ } elseif ($data['block_until'] > TIME) { $Page->warning($L->your_account_blocked_until . ' ' . date($L->_datetime, $data['block_until'])); /** * Mark user as guest, load data again */ $user = self::GUEST_ID; goto getting_user_data; } } elseif ($this->id != self::GUEST_ID) { /** * If data was not loaded - mark user as guest, load data again */ $user = self::GUEST_ID; goto getting_user_data; } unset($data); $Config = Config::instance(); /** * Generate hash in cycle, to obtain unique value */ for ($i = 0; $hash = md5(MICROTIME . uniqid($i, true)); ++$i) { if ($this->db_prime()->qf("SELECT `id`\n\t\t\t\tFROM `[prefix]sessions`\n\t\t\t\tWHERE `id` = '{$hash}'\n\t\t\t\tLIMIT 1")) { continue; } $this->db_prime()->q("INSERT INTO `[prefix]sessions`\n\t\t\t\t\t(\n\t\t\t\t\t\t`id`,\n\t\t\t\t\t\t`user`,\n\t\t\t\t\t\t`created`,\n\t\t\t\t\t\t`expire`,\n\t\t\t\t\t\t`user_agent`,\n\t\t\t\t\t\t`ip`,\n\t\t\t\t\t\t`forwarded_for`,\n\t\t\t\t\t\t`client_ip`\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'%s',\n\t\t\t\t\t\t'%s',\n\t\t\t\t\t\t'%s',\n\t\t\t\t\t\t'%s',\n\t\t\t\t\t\t'%s',\n\t\t\t\t\t\t'%s',\n\t\t\t\t\t\t'%s',\n\t\t\t\t\t\t'%s'\n\t\t\t\t\t)", $hash, $user, TIME, TIME + ($user != self::GUEST_ID || $Config->core['session_expire'] < 300 ? $Config->core['session_expire'] : 300), $this->user_agent, $ip = ip2hex($this->ip), $forwarded_for = ip2hex($this->forwarded_for), $client_ip = ip2hex($this->client_ip)); $time = TIME; if ($user != self::GUEST_ID) { $this->db_prime()->q("UPDATE `[prefix]users` SET `last_sign_in` = {$time}, `last_online` = {$time}, `last_ip` = '{$ip}.' WHERE `id` ='{$user}'"); } $this->current['session'] = $hash; $this->cache->{"sessions/{$hash}"} = ['user' => $user, 'expire' => TIME + $Config->core['session_expire'], 'user_agent' => $this->user_agent, 'ip' => $ip, 'forwarded_for' => $forwarded_for, 'client_ip' => $client_ip]; _setcookie('session', $hash, TIME + $Config->core['session_expire']); $this->id = $this->get_session_user(); $this->update_user_is(); if ($this->db()->qfs("SELECT COUNT(`id`)\n\t\t\t\t\t FROM `[prefix]sessions`") % $Config->core['inserts_limit'] == 0) { $this->db_prime()->aq("DELETE FROM `[prefix]sessions`\n\t\t\t\t\tWHERE `expire` < {$time}"); } return true; } return false; }
/** * Sometimes HTML code can be intended * * This function allows to store inner text of tags, that are sensitive to this operation (textarea, pre, code), and return some identifier. * Later, at page generation, this identifier will be replaced by original text again. * * @param string $text * * @return string */ protected static function indentation_protection($text) { $uniqid = uniqid('html_replace_'); Page::instance()->replace($uniqid, $text); return $uniqid; }
<?php /** * @package Streams * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\Streams; use cs\Page; Page::instance()->json(Streams::instance()->get(Streams::instance()->get_all()) ?: []);
<?php /** * @package Home * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\Home; use cs\Page; $Page = Page::instance(); if (!isset($_GET['title']) || !$_GET['title']) { error_code(400); $Page->error('non-empty "title" parameter required'); return; } $Tags = Tags::instance(); Page::instance()->json($Tags->get($Tags->search($_GET['title']) ?: []));
$Page->error(['access_denied', 'client_secret do not corresponds client_id']); } $token_data = $OAuth2->get_token($access_token, $client_id, $client['secret']); } else { $token_data = $OAuth2->get_token($access_token, $client_id, $client['secret']); if ($token_data['type'] == 'code') { error_code(403); $Page->error(['invalid_request', "This access_token can't be used without client_secret"]); } } if (!$token_data) { error_code(403); $Page->error(['access_denied', 'access_token expired']); } $_POST['session'] = $_REQUEST['session'] = $token_data['session']; _setcookie('session', $token_data['session']); if (!Config::instance()->module('OAuth2')->guest_tokens) { Trigger::instance()->register('System/User/construct/after', function () { if (!User::instance()->user()) { error_code(403); Page::instance()->error(['access_denied', 'Guest tokens disabled']); } }); } })->register('System/Index/mainmenu', function ($data) { if ($data['path'] == 'OAuth2') { $data['hide'] = true; return false; } return true; });
* * admin/System/components/modules/storage/prepare<br> * ['name' => <i>module_name</i>]<br> * * admin/System/components/modules/enable<br> * ['name' => <i>module_name</i>]<br> * * admin/System/components/modules/disable<br> * ['name' => <i>module_name</i>] */ namespace cs\modules\System; use h, cs\Config, cs\Core, cs\Index, cs\Language, cs\Page, cs\Trigger, cs\User; $Config = Config::instance(); $L = Language::instance(); $Page = Page::instance(); $User = User::instance(); $a = Index::instance(); $rc = $Config->route; $a->buttons = false; $show_modules = true; if (isset($rc[2]) && !empty($rc[2]) && (in_array($rc[2], ['update_system', 'remove']) || (isset($rc[3], $Config->components['modules'][$rc[3]]) || isset($rc[3]) && $rc[2] == 'install' && $rc[3] == 'upload'))) { switch ($rc[2]) { case 'install': if ($rc[3] == 'upload' && isset($_FILES['upload_module']) && $_FILES['upload_module']['tmp_name']) { switch ($_FILES['upload_module']['error']) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: $Page->warning($L->file_too_large); break; case UPLOAD_ERR_NO_TMP_DIR:
<?php /** * @package Info * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\Info; use cs\Page; Page::instance()->json(Info::get());