/** * Вспомнить пользователя * @return Entity */ protected static function remind() { self::$user = null; if (!empty(self::$input['COOKIE']['ID'])) { $ID = explode('|', self::$input['COOKIE']['ID']); } else { $ID = ''; } // Период запоминания пользователя $duration = empty($ID[0]) ? 0 : $ID[0]; // не больше месяца (примерно) // Хэш пользователя для поиска (авторизации) $hash = empty($ID[1]) ? '' : $ID[1]; // Если есть кука, то ищем пользователя в БД if ($hash) { $result = Data::find(array('from' => self::$config['users-list'], 'select' => 'children', 'depth' => 'max', 'where' => array(array('value', '=', $hash)), 'key' => false, 'limit' => array(0, 1), 'comment' => 'auth user by cookie'), false); // Пользователь найден и не истекло время его запоминания if (!empty($result)) { self::$user = $result[0]; } } else { $hash = self::get_unique_hash(); } // Новый гость if (!self::$user) { self::$user = Data::create(self::$config['user'], self::$config['users-list']); self::$user->value($hash); $duration = 0; } self::remember($duration); }
function show($v, Request $request) { $v['active'] = $request['REQUEST']['object']->uri(); $v['items'] = Data::find(['from' => '', 'select' => 'children', 'depth' => 1, 'order' => ['order', 'asc']]); $v['active'] = $request['REQUEST']['object']; // array_unshift($v['items'], Data::read('')); return parent::show($v, $request); }
private function searchUser($confirm) { self::$config = Config::read('auth'); $search_result = Data::find(array('from' => self::$config['users-list'], 'select' => 'children', 'depth' => 'max', 'where' => array(['child', 'confirm', array('value', '=', $confirm)]), 'key' => false, 'limit' => array(0, 1), 'comment' => 'search user by confirm property'), false); if (!empty($search_result)) { $user = $search_result[0]; } else { $user = false; } return $user; }
function getList(Request $request, &$cond = []) { $count_per_page = $this->count_per_page->is_exists() ? max(1, $this->count_per_page->value()) : 10; $cond['limit'] = [($request['REQUEST']['page'] - 1) * $count_per_page, $count_per_page]; $result = parent::getList($request, $cond); if (count($result) < $count_per_page) { $count = $request['REQUEST']['page']; } else { $count = ceil(Data::find(Data::unionCond(['calc' => 'count'], $cond)) / $count_per_page); } $request->mix(['REQUEST' => ['page_count' => $count]]); return $result; }
function checkChild(user $user) { self::$config = Config::read('auth'); $where = [['child', 'email', ['value', '=', $user->email->value()]]]; if ($user->is_exists()) { $where[] = ['uri', '!=', $user->uri()]; } $result = Data::find(array('from' => self::$config['users-list'], 'select' => 'children', 'depth' => 'max', 'where' => $where, 'key' => false, 'limit' => array(0, 1), 'comment' => 'search if user already exist'), false); if (!empty($result)) { $user->errors()->_children->email->_attributes->value->dublicate = 'Email не уникален'; return false; } else { return true; } }
function show($v, Request $request) { $v['active'] = $request['REQUEST']['object']->uri(); $from = trim($v['active'], '/ '); if ($from) { $paths = explode('/', $from); $from = ''; $cnt = min(1, count($paths)); for ($i = 0; $i < $cnt; $i++) { $from .= '/' . $paths[$i]; } $v['from'] = $from; $v['items'] = Data::find(['from' => $from, 'select' => 'children', 'depth' => 10, 'struct' => 'tree', 'order' => ['order', 'asc']]); } else { return false; } return parent::show($v, $request); }
function work(Request $request) { if ($request['REQUEST']['form']) { $session = array(); try { self::$config = Config::read('auth'); $result = Data::find(array('from' => self::$config['users-list'], 'select' => 'children', 'depth' => 'max', 'where' => array(['child', 'email', array('value', '=', $request['REQUEST']['email'])], ['child', 'password', array('value', '=', $request['REQUEST']['password'])]), 'key' => false, 'limit' => array(0, 1), 'comment' => 'sign-in user by email and password'), false); if (!empty($result)) { $user = $result[0]; Auth::set_user($user); if ($request['REQUEST']['remember-me']) { Auth::set_user($user, 1234565); } $request->redirect(self::$config['redirect']); } else { $this->_result = 0; } } catch (\Exception $error) { $this->_result = 0; } $session['result'] = $this->_result; Session::set('form', array($this->uri() . $this->getToken() => $session)); setcookie('token', $this->getToken(), 0, '/'); return $session; } else { // Отображение формы $v = array(); if (isset($request['COOKIE']['token']) && Session::is_exist('form')) { $form = Session::get('form'); if (isset($form[$this->uri() . $request['COOKIE']['token']])) { $form = $form[$this->uri() . $request['COOKIE']['token']]; Session::remove('form'); } if (isset($form['result'])) { $this->_result = $form['result']; } } $this->res->start($request); return $this->show($v, $request); } }
function getList(Request $request, &$cond = []) { $cond = Data::unionCond($cond, ['from' => $request['REQUEST']['object'], 'select' => 'children', 'depth' => 1]); return Data::find($cond); }
function getList(Request $request, &$cond = []) { $cond = Data::unionCond($cond, ['from' => $request['REQUEST']['object'], 'select' => 'properties', 'depth' => 1, 'key' => 'name']); return Data::find($cond); }
/** * Выбор дерева объектов для пунктов меню * @param array $cond Услвоие выборки * @return array|Entity|mixed|null */ function getItems($cond = array()) { // $is_list = $this->is->find(array('where'=>array('is_link','!=',0), 'group'=>true)); // foreach ($is_list as $key => $is){ // $is_list[$key] = $is->linked()->id(); // } $cond['select'] = 'children'; $cond['struct'] = 'tree'; //$cond['from'] = $request['REQUEST']['object']->linked(); //$cond['depth'] = array(1, 'max'); // выбрать из хранилища всё дерево меню $cond['where'] = array('all', array(array('attr', 'is_hidden', '=', 0), array('attr', 'is_draft', '=', 0), array('child', 'menu', ['value', '=', true]))); $cond['order'] = ['order', 'asc']; // $cond['group'] = true; // Для выбранных объектов выполнять подвыборки // $cond['cache'] = 2; // Кэшировать сущности $items = Data::find($cond); if ($cond['from']->menu->value()) { array_unshift($items, ['object' => $cond['from'], 'sub' => []]); } return $items; }
function getCihildrenControllers($cond = [], Request $request) { $cond = Data::unionCond($cond, ['select' => 'children', 'from' => $this, 'order' => ['order', 'asc']]); return Data::find($cond); }
function show($v, Request $request) { $v['parent'] = $request['REQUEST']['object']; $v['items'] = Data::find(['from' => '/library/contents', 'select' => 'children']); return parent::show($v, $request); }
/** * Дополнить объект свойствами прототипа * Используется для создания полного объекта или его обновления * @param bool $only_mandatory Дополнять только обязательными или всеми свойствами? * @param bool $only_property Дополнять только свойствами или всеми объектами? */ function complete($only_mandatory = true, $only_property = true) { // Выбор подчиненных объектов $proto = $this->proto(null, true); $cond = ['from' => $proto, 'select' => 'properties', 'key' => 'name']; if ($only_mandatory) { $cond['where'] = [['is_mandatory', '=', true]]; } $props_children = Data::find($cond); if (!$only_property) { // Выбор подчиненных объектов $cond['select'] = 'children'; $props_children = array_merge($props_children, Data::find($cond)); } // Прототипирование отсутствующих подчиненных foreach ($props_children as $name => $child) { $this->{$name}->complete($only_mandatory, $only_property); if ($this->{$name}->order() == Entity::MAX_ORDER) { $this->{$name}->order($props_children[$name]->order()); } } }
function getList(Request $request, $cond = []) { /** @var Entity $obj */ $obj = $request['REQUEST']['object']; if ($obj->is_exists()) { $cond = Data::unionCond($cond, ['from' => $request['REQUEST']['object'], 'select' => 'properties', 'depth' => 1]); $props = Data::find($cond); } else { $props = $obj->children(); } foreach ($props as $p) { $request['REQUEST']['object']->__set($p->name(), $p); } return $props; }
function work(Request $request) { $uri = ''; // $s = C::read(); // C::writeln(mb_detect_encoding($s,['utf-8','cp866'])); do { try { C::write(C::style($uri, [C::COLOR_GRAY_DARK]) . '> '); $commands = preg_split('/\\s/ui', trim(C::read())); $cmd_count = count($commands); if ($commands[0] == 'show') { $new_uri = !empty($commands[1]) ? $uri . '/' . trim($commands[1], ' \\/') : $uri; $obj = Data::read($new_uri); C::writeln(C::style(Trace::format($obj, false))); } else { if (mb_strlen($commands[0]) > 1 && ($commands[0][0] == '/' || mb_substr($commands[0], 0, 2) == '..')) { $new_uri = !empty($commands[0]) ? $uri . '/' . trim($commands[0], ' \\/') : $uri; $obj = Data::read($new_uri, false, true); if ($obj && $obj->is_exists()) { $uri = $obj->uri(); } else { C::writeln(C::style('Object does not exist', C::COLOR_RED)); } } else { if ($commands[0] == 'ls' || $commands[0] == 'children') { $list = Data::find(['from' => $uri, 'select' => empty($commands[1]) || $commands[1] != '-p' ? 'children' : 'properties', 'struct' => 'list', 'limit' => [0, 50]]); foreach ($list as $obj) { C::writeln(C::style($obj->name(), C::COLOR_BLUE)); } } else { if (preg_match('/^\\s*select(\\(|=)/ui', $commands[0])) { $cond = Data::normalizeCond($commands[0], false); if (!isset($cond['from'])) { $cond['from'] = $uri; } $result = Data::find($cond); C::writeln(C::style(Trace::format($result, false))); } else { if ($commands[0] == 'color') { if (!empty($commands[1])) { C::use_style($commands[1] == 'off' ? false : null); } else { C::use_style(true); } } else { if ($cmd_count > 1 && $commands[0] == 'attr') { $obj = Data::read($uri); $attr = $commands[1]; if ($obj instanceof Entity && $obj->is_exists() && $obj->is_attr($attr)) { if ($cmd_count > 2) { if ($commands[2] === "null") { $commands[2] = null; } else { if ($commands[2] === "false") { $commands[2] = false; } else { $commands[2] = trim(trim($commands[2], '"')); } } $obj->{$attr}($commands[2]); Data::write($obj); C::writeln(Trace::format($obj, false)); } else { C::writeln(C::style($obj->attr($attr)), C::COLOR_PURPLE); } } } else { if ($cmd_count > 2 && $commands[0] == 'new') { $new_uri = !empty($commands[1]) ? $uri . '/' . trim($commands[1], ' \\/') : $uri; list($parent, $name) = F::splitRight('/', $new_uri); if (!$parent) { $parent = ''; } $proto = $commands[2]; $obj = Data::create($proto, $parent, ['name' => $name]); $signs = array_flip($commands); if (isset($signs['-m'])) { $obj->is_mandatory(true); } if (isset($signs['-p'])) { $obj->is_property(true); } if (isset($signs['-d'])) { $obj->is_draft(true); } if (isset($signs['-h'])) { $obj->is_hidden(true); } if (isset($signs['-l'])) { $obj->is_link(true); } if (isset($signs['-r'])) { $obj->is_relative(true); } $obj->complete(); Data::write($obj); C::writeln(Trace::format($obj, false)); } else { if ($commands[0] == 'complete') { $obj = Data::read($uri); $signs = array_flip($commands); $only_mandatory = !isset($signs['-all']) && !isset($signs['-not-mandatory']); $only_property = !isset($signs['-all']) && !isset($signs['-not-property']); $obj->complete($only_mandatory, $only_property); Data::write($obj); C::writeln(Trace::format($obj, false)); } else { C::writeln(C::style('Unknown command', C::COLOR_RED)); } } } } } } } } } catch (Error $e) { C::writeln(C::style($e->getMessage(), C::COLOR_RED)); } catch (\Exception $e) { C::writeln(C::style((string) $e, C::COLOR_RED)); } Buffer::clear(); } while ($commands[0] !== 'exit'); C::writeln("\nby!"); // if (!empty($request['ARG'][2])) { // if ($request['ARG'][2] == 'read') { // $uri = empty($request['ARG'][3]) ? '' : '/' . trim($request['ARG'][3], '/'); // $obj = Data::read($uri); // C::writeln(C::style(Trace::style($obj, false))); // } else // if ($request['ARG'][2] == 'find') { // $cond = empty($request['ARG'][3]) ? '' : trim($request['ARG'][3], '/'); // $result = Data::find($cond); // C::write(C::style(Trace::style($result, false))); // } else // if ($request['ARG'][2] == 'edit') { // $object = Data::read(empty($request['ARG'][3]) ? '' : '/'.trim($request['ARG'][3], '/')); // $attr = empty($request['ARG'][4]) ? null : $request['ARG'][4]; // $value = empty($request['ARG'][5]) ? null : $request['ARG'][5]; // if ($object instanceof Entity && $object->is_exists() && $attr){ // $object->{$attr}($value); // Data::write($object); // C::write(C::style(Trace::style($object, false))); // } // }else // { //// phpinfo(); //// C::writeln(Trace::style($_ENV, false)); //// C::writeln(getenv('ANSICON')); // C::writeln( // C::style(json_encode($request['ARG']), [C::STYLE_BOLD, C::STYLE_UNDERLINE, C::COLOR_BLUE])); // //$a = C::read(); // //C::writeln($a); // //// fwrite(STDOUT, $colors->getColoredString("Testing Colors class, this is purple string on yellow background.", "purple", "yellow") . "\n"); //// $line = fgets(STDIN); //// if(trim($line) != 'yes'){ //// echo "ABORTING!\n"; //// exit; //// } //// echo "\n"; //// echo "Thank you, continuing...\n"; //// return true; // } // } }