public function paginated($mode = 'sidebar') { if ($limit = $this->page->blueprint()->pages()->limit()) { $hash = sha1($this->page->id()); switch ($mode) { case 'sidebar': $id = 'pages.' . $hash; $var = 'page'; break; case 'subpages/visible': $id = 'subpages.visible.' . $hash; $var = 'visible'; break; case 'subpages/invisible': $id = 'subpages.invisible.' . $hash; $var = 'invisible'; break; } $children = $this->paginate($limit, array('page' => get($var, s::get($id)), 'omitFirstPage' => false, 'variable' => $var, 'method' => 'query')); // store the last page s::set($id, $children->pagination()->page()); return $children; } else { return $this; } }
/** * Remove old values from the Session’s flash data. */ public static function flush() { // Make sure the session is started s::start(); // Retrieve the flash data $registry = s::get(self::$namespace); // Clean up registry if (!empty($registry)) { foreach ($registry as $key => $expiry) { $expiry++; // Remove all old values from the session if ($expiry > 1) { s::remove($key); unset($registry[$key]); } else { $registry[$key] = $expiry; } } // Write registry back to session if (!empty($registry)) { s::set(self::$namespace, $registry); } else { s::remove(self::$namespace); } } }
/** * Set flash data * * @param string $key * @param mixed $value * @return void */ public static function set($key, $value) { if (!isset($data[$key])) { static::$data[$key] = $value; } Session::set(self::sessionKey(), static::$data); }
function edit() { events::observe('save', 'templates', 'apps', '_save'); events::observer(); $tmpl_file = events::get('tmpl_file'); $app = events::get('app'); if (events::detect('restore')) { self::restoreVersion($app, $tmpl_file, events::get('restore')); } admin::components('tabs', 'validator'); f::set('app', $app); f::set('tmpl_file', $tmpl_file); s::set('app', $app); s::set('tmpl_file', $tmpl_file); $file = SYS_ROOT . 'tmpls/' . ADMIN_SITE . '/' . $app . '/' . $tmpl_file; $code = files::get($file); f::set('tmpl_code', $code); self::getApps(); /* Load versions */ db::table('templates_versions'); db::where('app', $app); db::where('tmpl_file', $tmpl_file); db::order('version_date', 'DESC'); $res = db::select(); while ($row = mysql_fetch_assoc($res)) { $row['version_date'] = dt::date2print('%H:%i %d.%m.%Y', $row['version_date']); $row['version_code'] = '{non}' . htmlspecialchars($row['version_code']) . '{/non}'; s::roll('versions', $row); } }
public static function login($redirect = '/') { if (self::user()) { go(url($redirect)); } self::kill(); $password = get('password'); $username = get('username'); if (empty($username) || empty($password)) { return false; } // try to find the user $account = self::load($username); if (!$account) { return array('status' => 'error', 'msg' => l::get('auth.error', 'Invalid username or password')); } // check for matching usernames if (str::lower($account->username()) != str::lower($username)) { return array('status' => 'error', 'msg' => l::get('auth.error', 'Invalid username or password')); } // check for a matching password if (!self::checkPassword($account, $password)) { return array('status' => 'error', 'msg' => l::get('auth.error', 'Invalid username or password')); } // generate a random token $token = str::random(); // add the username. $account->token = $token; // store the token in the cookie // and the user data in the session cookie::set('authFrontend', $token, 60 * 60 * 24); s::set('authFrontend.' . $token, $account->username()); go(url($redirect)); }
function login() { s::restart(); $password = get('password'); $username = get('username'); if (empty($username) || empty($password)) { return array('status' => 'error', 'msg' => l::get('login.error')); } $account = self::load($username); if (!$account) { return array('status' => 'error', 'msg' => l::get('login.error')); } // check for matching usernames if (str::lower($account['username']) != str::lower($username)) { return array('status' => 'error', 'msg' => l::get('login.error')); } // check for a matching password if (!self::checkPassword($account, $password)) { return array('status' => 'error', 'msg' => l::get('login.error')); } // generate a random token $token = str::random(); // add the username. // It's only the key of the array so far. $account['token'] = $token; // store the token in the cookie // and the user data in the session cookie::set('auth', $token, 60 * 60 * 24); s::set($token, $account); // assign the user data to this obj $this->_ = $account; return array('status' => 'success', 'msg' => l::get('login.success')); }
function show($name) { foreach (self::$errors as $k => $v) { $show .= '<li>' . $v . '</li>'; } s::set($name, '<ul>' . $show . '</ul>'); }
protected function signup() { $self = $this; $form = $this->form('installation/signup', array(), function ($form) use($self) { $form->validate(); if (!$form->isValid()) { return false; } try { // fetch all the form data $data = $form->serialize(); // make sure that the first user is an admin $data['role'] = 'admin'; // try to create the new user $user = site()->users()->create($data); // store the new username for the login screen s::set('username', $user->username()); // try to login the user automatically if ($user->hasPanelAccess()) { $user->login($data['password']); } // redirect to the login $self->redirect('login'); } catch (Exception $e) { $form->alert($e->getMessage()); } }); return $this->modal('index', compact('form')); }
public function index() { if (site()->users()->count() > 0) { go(panel()->urls()->login()); } if ($problems = installation::check()) { $content = view('installation/check', array('problems' => $problems)); } else { $form = panel()->form('installation', array('language' => kirby()->option('panel.language', 'en'))); $form->cancel = false; $form->save = l('installation.signup.button'); $form->centered = true; foreach (panel()->languages() as $lang) { $form->fields()->get('language')->options[$lang->code()] = $lang->title(); } $form->on('submit', function ($form) { try { // fetch all the form data $data = $form->serialize(); // make sure that the first user is an admin $data['role'] = 'admin'; // try to create the new user $user = panel()->site()->users()->create($data); // store the new username for the login screen s::set('username', $user->username()); // redirect to the login go(panel()->urls()->login() . '/welcome'); } catch (Exception $e) { $form->alert($e->getMessage()); } }); $content = view('installation/signup', array('form' => $form)); } return layout('installation', array('meta' => new Snippet('meta'), 'content' => $content)); }
public function delete($id) { if (!array_key_exists($id, $this->data)) { return; } unset($this->data[$id]); s::set('cart', $this->data); }
public static function set($name, $value, $type = 'plain') { $messages = s::get('messages') ? s::get('messages') : array(); $message = new stdClass(); $message->name = $name; $message->value = $value; $message->type = $type; $messages[$name] = $message; s::set('messages', $messages); }
function add_to_visited_links($url) { $url = rtrim($url, '/'); $visited_links = s::get('visited_links'); if (!$visited_links) { $visited_links = array(); } array_push($visited_links, $url); s::set('visited_links', array_unique($visited_links)); }
function show() { $event = web::getEvent(); if ($event === false) { $year = date('Y'); } else { $year = $event; } s::set('info_date_select', htmlspecialchars($year)); $sql = "SELECT `section_year` as date FROM `info_sections` WHERE `section_view`='0' GROUP BY `date` ORDER BY `date` DESC"; $res = db::query($sql); $rows = mysql_num_rows($res); if ($rows > 1) { s::add('info_date_selector', '<ul class="years">'); while ($row = mysql_fetch_assoc($res)) { if ($row['date'] == $year) { $row['date'] = '<li><span>' . $row['date'] . '</span></li>'; } else { $row['date'] = '<li><a href="' . web::get('page_folder') . '' . $row['date'] . '/">' . $row['date'] . '</a></li>'; } s::add('info_date_selector', $row['date']); } s::add('info_date_selector', '</ul>'); } $files = array(); db::table('info_files'); $r = db::select(); while ($a = mysql_fetch_assoc($r)) { $files[$a['section_id']][] = $a; } db::table('info_sections'); db::order('section_order', 'DESC'); db::where('section_year', $year); $r = db::select(); if (db::rows() == 0) { web::error404(); } while ($a = mysql_fetch_assoc($r)) { if ($a['section_view'] == '0') { s::roll('sections', $a); } else { s::roll('sections_view', $a); } if (isset($files[$a['section_id']])) { foreach ($files[$a['section_id']] as $v) { $v['file_icon'] = files::getFileIco($v['file_type']); $v['file_size'] = files::parseSizeSmart($v['file_size']); s::roll('items' . $a['section_id'], $v); } } } }
public static function configure() { if (is_null(static::$site)) { static::$site = kirby::panelsetup(); } // load all available routes static::$routes = array_merge(static::$routes, require root('panel.app.routes') . DS . 'api.php'); static::$routes = array_merge(static::$routes, require root('panel.app.routes') . DS . 'views.php'); // setup the blueprint root blueprint::$root = c::get('root.site') . DS . 'blueprints'; // start the router static::$router = new Router(); static::$router->register(static::$routes); // content language switcher variable if (static::$site->multilang()) { if ($language = server::get('http_language') or $language = s::get('lang')) { static::$site->visit('/', $language); } app::$language = static::$site->language()->code(); s::set('lang', app::$language); } // load the interface language file if (static::$site->user()) { $languageCode = static::$site->user()->language(); } else { $languageCode = c::get('panel.language', 'en'); } // validate the language code if (!in_array($languageCode, static::languages()->keys())) { $languageCode = 'en'; } // store the interface language app::$interfaceLanguage = $languageCode; $language = (require root('panel.app.languages') . DS . $languageCode . '.php'); // set all language variables l::$data = $language['data']; // register router filters static::$router->filter('auth', function () { if (!app::$site->user()) { go('panel/login'); } }); // check for a completed installation static::$router->filter('isInstalled', function () { if (app::$site->users()->count() == 0) { go('panel/install'); } }); // only use the fragments of the path without params static::$path = implode('/', (array) url::fragments(detect::path())); }
function start() { db::connect(); if (!router::get(1)) { return true; } self::$map = array('mode' => router::get(0), 'app' => router::get(1), 'module' => 'main', 'action' => router::get(2), 'id' => router::get(4)); s::set('SYS_PATH', 'http://' . SERVER . SYS_DIR); define('APP', APPS . self::get('app') . '/'); s::set('APP', APP); define('MODULE', APP . self::get('module') . '/'); s::set('MODULE', MODULE); if (stristr(self::$map['mode'], 'admin')) { self::$map['mode'] = 'admin'; } else { self::$map['mode'] = 'web'; } if (self::$map['mode'] == 'admin') { if (defined('ADMIN_USER_SITE_ID')) { admin::observer(); define('ADMIN_SITE_ID', ADMIN_USER_SITE_ID); s::set('ADMIN_SITE_ID', ADMIN_USER_SITE_ID); db::table('admin_sites'); db::where('site_id', ADMIN_USER_SITE_ID); db::limit(1); $row = db::select(); define('ADMIN_SITE', db::get('site_domain')); s::set('ADMIN_SITE', ADMIN_SITE); } } else { web::getSite(); $lang = lang::gets(LANG_INDEX, SITE_ID); /* Authentification webUser */ web::observer(); } /* Set params */ params::send(); if (router::get(0) == 'feed' || router::get(0) == 'rss') { self::$map['module'] = 'feed'; } if (self::$map['mode'] == 'admin') { load::module(self::get('app'), self::get('module'), self::get('action')); } else { load::handler(self::get('app'), self::get('module'), self::get('action')); } }
function showOne() { $news_id = web::getThis(); db::table('news'); db::where('news_pub', '1'); $news = db::assoc(); if (db::rows() == 0) { web::error404(); } $news['news_date'] = dt::date2print('%d %F %Y', $news['news_date']); s::set('page_title', $news['news_title']); s::set('page_header', $news['news_title']); s::set($news); }
function installApp() { if ($_FILES['app']['name']) { if ($_FILES['app']['type'] != 'application/zip') { s::set('ERRORS', '<ul><li>Неверный формат архива приложения.</li></ul>'); } else { $arr = explode('.', $_FILES['app']['name']); if (count($arr) < 5) { s::set('ERRORS', '<ul><li>Неверный формат архива приложения.</li></ul>'); } else { define('INSTALL_APP', $arr[0]); define('INSTALL_APP_VERSION', $arr[1] . '.' . $arr[2] . '.' . $arr[3]); files::fullRemoveDir(SYS_ROOT . 'var/tmp/apps/'); $path = SYS_ROOT . 'var/tmp/apps/'; zipfile::read($_FILES['app']['tmp_name']); zipfile::extract($path); $install_file = $path . 'install.php'; if (!file_exists($install_file)) { s::set('ERRORS', '<ul><li>Не найден инсталляционый файл приложения.</li></ul>'); } else { include $install_file; // copy lang files $tmp_lang_dir = SYS_ROOT . 'var/tmp/apps/langs/'; $lang_dir = SYS_ROOT . 'langs/admin/'; if (file_exists($lang_dir)) { $array = files::getFiles($tmp_lang_dir); foreach ($array as $v) { if (!file_exists($lang_dir . $v)) { copy($tmp_lang_dir . $v, $lang_dir . $v); } else { $lang = ini::parse($tmp_lang_dir . $v); ini::parse($lang_dir . $v); ini::add($lang); ini::write(); } } } // copy app files $dir = SYS_ROOT . 'var/tmp/apps/' . INSTALL_APP . '/'; $new_dir = SYS_ROOT . 'apps/' . INSTALL_APP . '/'; files::copyDir($dir, $new_dir); // clear tmp files::fullRemoveDir(SYS_ROOT . 'var/tmp/apps/'); headers::app('manage'); } } } } }
public static final function parametrosPostUserPass() { $username = f::request('post', 'normal', 'username'); $password = f::request('post', 'normal', 'password'); $username = '******'; $password = '******'; if (f::isEmpty(f::getSession('NENTI_CODIGO')) or !f::isEmpty($username)) { $return = false; if (f::isEmpty(v::getError())) { v::valida($username, 'Usuario', 'required,minSize[8],maxSize[10]'); } if (f::isEmpty(v::getError())) { v::valida($password, 'Clave', 'required,minSize[4],maxSize[10]'); } if (f::isEmpty(v::getError())) { $row = DAO_DGENCA_USUARIO::validaUsuarioPassword($username, $password); if (f::isEmpty($row)) { v::setError('El Usuario o Clave es incorrecto'); } else { $entidad = $row[0]['NENTI_CODIGO']; $nombre = $row[0]['CENTI_NOMBRECOMPLETO']; $nombre = str_replace(',', ' ', $nombre); $nombre = ucwords(strtolower($nombre)); $nombre = utf8_encode($nombre); } } if (f::isEmpty(v::getError())) { $return = true; f::setSession('NENTI_CODIGO', $entidad); f::setSession('CUSER_USERNAME', $username); s::set('CENTI_NOMBRECOMPLETO', $nombre); } else { $return = false; self::resetSessionSystem(); if (s::get('typeResponse') == 'json') { v::validaErrorJSON(); } else { v::validaErrorUL(true); } } } else { $return = true; } return $return; }
function cart_logic($cart) { if (isset($_REQUEST['action'])) { $action = $_REQUEST['action']; $id = $_REQUEST['id']; switch ($action) { case 'add': if (isset($cart[$id])) { $cart[$id]++; } else { $cart[$id] = 1; } break; case 'remove': if (isset($cart[$id])) { $cart[$id]--; } else { $cart[$id] = 1; } break; case 'update': if (isset($_REQUEST['quantity'])) { $quantity = intval($_REQUEST['quantity']); if ($quantity < 1) { unset($cart[$id]); } else { $cart[$id] = $quantity; } } break; case 'delete': if (isset($cart[$id])) { unset($cart[$id]); } break; } s::set('cart', $cart); } // if (count($cart) == 0) { // go(url('products')); // } return $cart; }
function load($user_id) { if (self::$user) { return true; } db::table('admin_users'); db::where('user_id', $user_id); db::where('user_pub', 1); db::limit(1); self::$user = db::assoc(); if (db::rows() == 0) { admin::logout(); } define("ADMIN_USER_ID", $user_id); define("ADMIN_USER_SITE_ID", self::get('site_id')); define("ADMIN_USER_GROUP_ID", self::get('group_id')); s::set('ADMIN_USER_LOGIN', self::get('user_login')); s::set('ADMIN_USER_ID', $user_id); return true; }
function loadPage($page_id = false, $page_folder = false) { db::table('pages'); db::join('templates', 'pages', 'tmpl_id'); if ($page_id) { db::where('page_id', $page_id); } if ($page_folder) { db::where('page_folder', $page_folder); } db::where('site_id', SITE_ID, '=', 'pages'); db::limit(1); $res = db::select(); if (db::rows() == 1) { $row = mysql_fetch_assoc($res); $row = web::pageSettings($row); web::$page = $row; s::set($row); } }
function view() { events::observe('clear_pages_versions', 'system', 'base', 'clear_pages_versions'); events::observe('clear_templates_versions', 'system', 'base', 'clear_templates_versions'); events::observe('delete_dump', 'system', 'base', 'delete_dump'); events::observe('restore', 'system', 'base', 'restore'); events::observe('reserve', 'system', 'base', 'reserve'); events::observe('optimize', 'system', 'base', 'optimize'); events::observe('repair', 'system', 'base', 'repair'); events::observer(); $sql = "SHOW TABLE STATUS"; $res = db::query($sql); $data_length = 0; while ($row = mysql_fetch_array($res)) { $vol = $row['Data_length'] + $row['Index_length']; $data_length += $vol; } if ($data_length > 1000000) { s::set('base_volume', round($data_length / 1000000, 2) . ' MB'); } else { s::set('base_volume', round($data_length / 1024, 2) . ' KB'); } if ($data_length > 1000000) { s::set('base_damp_need', round($data_length / 1000000 / 4.6) . ' MB'); } else { s::set('base_damp_need', round($data_length / 1024 / 4.6) . ' KB'); } $files = files::listDir(SYS_ROOT . 'var/backup/'); if (count($files)) { foreach ($files as $v) { s::roll('restore_files', array('value' => $v, 'file' => $v)); } } else { s::roll('restore_files', array('value' => 0, 'file' => 'нет файла'), 0); } }
public function switchLanguage(Language $language) { s::set('language', $language->code()); if ($this->language()->code() != $language->code()) { go($this->page()->url($language->code())); } }
/** * Generates a new token for this form and session. */ private function generateToken() { $this->token = str::random(SendForm::TOKEN_LENGTH); s::set($this->id, $this->token); }
/** * Starts the router, renders the page and returns the response * * @return mixed */ public function launch() { // this will trigger the configuration $site = $this->site(); // force secure connections if enabled if ($this->option('ssl') and !r::secure()) { // rebuild the current url with https go(url::build(array('scheme' => 'https'))); } // set the timezone for all date functions date_default_timezone_set($this->options['timezone']); // load all extensions $this->extensions(); // load all plugins $this->plugins(); // load all models $this->models(); // start the router $this->router = new Router($this->routes()); $this->route = $this->router->run($this->path()); // check for a valid route if (is_null($this->route)) { header::status('500'); header::type('json'); die(json_encode(array('status' => 'error', 'message' => 'Invalid route or request method'))); } // call the router action with all arguments from the pattern $response = call($this->route->action(), $this->route->arguments()); // load all language variables // this can only be loaded once the router action has been called // otherwise the current language is not yet available $this->localize(); // build the response $this->response = $this->component('response')->make($response); // store the current language in the session if ($this->site()->multilang() && ($language = $this->site()->language())) { s::set('language', $language->code()); } return $this->response; }
/** * @todo rework */ static function current() { if (s::get('language')) { return s::get('language'); } $lang = str::split(server::get('http_accept_language'), '-'); $lang = str::trim(a::get($lang, 0)); $lang = l::sanitize($lang); s::set('language', $lang); return $lang; }
public function login($password) { static::logout(); if (!password::match($password, $this->password)) { return false; } $key = $this->generateKey(); $secret = $this->generateSecret($key); // http only cookie cookie::set('kirby', $key, 0, '/', null, false, true); s::set('auth.created', time()); s::set('auth.updated', time()); s::set('auth.key', $key); s::set('auth.secret', $secret); s::set('auth.username', $this->username()); s::set('auth.ip', visitor::ip()); s::set('auth.ua', visitor::ua()); return true; }
/** * Checks / returns a csrf token * * @param string $check Pass a token here to compare it to the one in the session * @return mixed Either the token or a boolean check result */ function csrf($check = null) { // make sure a session is started s::start(); if (is_null($check)) { $token = str::random(64); s::set('csrf', $token); return $token; } return $check === s::get('csrf') ? true : false; }
/** * Generates a new captcha for the 'calc' guard. */ private function generateCaptcha() { list($a, $b) = array(rand(0, 9), rand(0, 9)); s::set($this->id . '-captcha-result', $a + $b); s::set($this->id . '-captcha-label', $a . ' ' . l::get('uniform-calc-plus') . ' ' . $b); }
public function eliminar() { if (f::isEmpty(v::getError())) { $this->validaCredencial(); } if (f::isEmpty(v::getError())) { $codEvacuacion = f::request('post', 'decode', f::id('codEvacuacion')); v::valida($codEvacuacion, 'codEvacuacion', 'required,maxSize[11],custom[integer]'); } //v::setError('sape!'); if (!f::isEmpty(v::getError())) { v::validaErrorJSON('#divMasterPageRightContent', 'up'); } else { $resultado = DAO_Evacuacion::eliminar($codEvacuacion); if ($resultado >= 0) { v::setTrueJSON(); v::setJSON('tag', '#divMasterPageRightContent'); v::setJSON('ubicacion', 'up'); v::setJSON('descripcion', 'Se realizó correctamente'); s::set('codEvacuacion', $codEvacuacion); v::setJSON('tagdata', '#divMasterPageCenterContent'); v::setJSON('data', c::getViewSystem('modulos/misevacuaciones/index.php', false)); } else { v::setFalseJSON(); v::setJSON('tag', '#divMasterPageRightContent'); v::setJSON('ubicacion', 'up'); v::setJSON('descripcion', 'No se puedo realizar'); } v::printJSON(); } }