protected function process_format($code, $value, $format) { if (empty($format['output'])) { return $value; } if (Core_Types::is_callable($format['output'])) { return Core::invoke($format['output'], array($value)); } if (is_string($format['output']) || is_array($format['output'])) { Core::load('Text.Process'); return Text_Process::process($value, $format['output']); } return $value; }
public function tree_generation(&$out, &$flat_out, $tree_items, $options, $data) { $exclude = null; if (isset($data['exclude_current']) && $data['exclude_current'] && isset($data['__item'])) { $exclude = $data['__item']->id(); } foreach ($tree_items as $key => $item) { if ($exclude && $exclude == $key) { continue; } if (is_string($item)) { $out[$key] = $item; $flat_out[$key] = $item; } else { // !empty -> isset if (isset($item[$options['title_name']])) { $out[$key][$options['title_name']] = $item[$options['title_name']]; $flat_out[$key] = $item[$options['title_name']]; } else { $out[$key][$options['title_name']] = (string) $item; $flat_out[$key] = (string) $item; } if (!empty($item[$options['disabled_name']])) { $out[$key][$options['disabled_name']] = $item[$options['disabled_name']]; } if (!empty($item[$options['childs_name']])) { if (Core_Types::is_callable($item[$options['childs_name']])) { $item[$options['childs_name']] = Core::invoke($item[$options['childs_name']]); } $out[$key][$options['childs_name']] = array(); $this->tree_generation($out[$key][$options['childs_name']], $flat_out, $item[$options['childs_name']], $options, $data); } } } return $out; }
protected function create_element() { if (Core_Types::is_callable($this->type)) { $this->element = Core::invoke($this->type, array($this->reader, $this->name)); return $this; } $method = "element_" . $this->type; if (method_exists($this, $method)) { $this->{$method}(); } else { $this->element = null; } return $this; }
public function map($name, $callback) { if (Core_Types::is_callable($callback)) { if ($callback instanceof Closure && method_exists($callback, 'bindTo')) { $callback = $callback->bindTo($m = $this->spawn(), $m); } $this->maps[$name] = $callback; } return $this; }
public function access($name, $data, $action, $item = null) { $args = array_slice(func_get_args(), 4); if (Core_Types::is_callable($data['access'])) { return Core::invoke($data['access'], array($this, $name, $data, $action, $item, $args)); } return $this->access_default($name, $data, $action, $item, $args); }
/** * Вызов метода * * Если в расширении есть callback, то используем его, иначе пробрасываем вызов в искомый объект * * @param string $method * @param array $args */ public function __call($method, $args) { if (Core_Types::is_callable($c = $this->__get($method))) { return call_user_func_array($c, $args); } return call_user_func_array(array($this->object, $method), $args); }
static function items_for_select_generate($s) { if (Core_Types::is_callable($s)) { $s = Core::invoke($s); } if (is_string($s)) { if ($m = Core_Regexps::match_with_results('/^:(.+)$/', $s)) { $method = trim($m[1]); $s = CMS::$current_controller->{$method}(); } } if (Core_Types::is_iterable($s)) { $items = array(); foreach ($s as $k => $v) { if ($v == '' && (is_string($k) && Core_Regexps::match('/^(var|db|orm)/', $k))) { $items += self::items_for_select($k); } elseif ($v instanceof DB_ORM_Mapper) { $items += self::items_for_select($v->select()); } else { if ($v instanceof DB_ORM_Entity) { $items[$v->id()] = $v; } else { if (is_int($k) && (Core_Types::is_callable($v) || is_string($v) && Core_Regexps::match('/^(var|db|orm)/', $v))) { $items += self::items_for_select($v); } else { $items[$k] = $v; } } } } return $items; } else { if ($m = Core_Regexps::match_with_results('/^var:(.+)$/', $s)) { return self::get_var_value($m[1]); } else { if ($m = Core_Regexps::match_with_results('/^orm:(.+)$/', $s)) { $items = array(); foreach (self::orm()->downto($m[1]) as $row) { $items[$row->id] = $row; } return $items; } else { if ($m = Core_Regexps::match_with_results('/^(.+)::(.+)$/', $s)) { $class = str_replace('.', '_', trim($m[1])); $method = trim($m[2]); $ref = new ReflectionMethod($class, $method); return $ref->invoke(null); } else { if ($m = Core_Regexps::match_with_results('/^db:([a-z0-9_]+)(.*)$/i', $s)) { $table = $m[1]; $s = $m[2]; $value = 'id'; $title = 'title'; $query = 'select'; if ($m = Core_Regexps::match_with_results('/^->([a-z0-9_]+)(.*)$/', $s)) { $query = $m[1]; $s = $m[2]; } if ($m = Core_Regexps::match_with_results('/^\\((.+),(.+)\\)$/', $s)) { $value = $m[1]; $title = $m[2]; } $rows = DB_SQL::db()->{$table}->{$query}->run(); $items = array(); foreach ($rows as $row) { $items[$row->{$value}] = $row->{$title}; } return $items; } else { return array(); } } } } } }
public static function access($realm, $extra_auth_callback = null) { if (!$realm) { return array(); } if (isset(self::$realms[$realm]) && self::$realms[$realm]) { return self::$realms[$realm]; } $data = false; $cfg_name = "{$realm}_realm"; $cfg = WS::env()->config; if (isset($cfg->{$cfg_name})) { $data = (array) $cfg->{$cfg_name}; } elseif (isset(CMS::$restricted_realms[$realm])) { $data = CMS::$restricted_realms[$realm]; } else { return self::$realms[$realm] = false; } if (!$data) { return self::$realms[$realm] = false; } if ($realm == CMS::$admin_realm) { CMS::$in_admin = true; } if (isset($data['page_404'])) { CMS::$page_404 = $data['page_404']; } if (isset($data['navigation_var'])) { Core::load(CMS::$nav_module); Core_Types::reflection_for(CMS::$nav_module)->setStaticPropertyValue('var', $data['navigation_var']); } $user = false; if (isset($data['auth_type']) && $data['auth_type'] == 'basic' || !isset($data['auth_type'])) { $user = WS::env()->admin_auth->user; } if ($user) { $client = false; $access = false; $mp = false; self::passwords($data, $user, $client, $access, $mp); Core::load('Net.HTTP.Session'); $session = Net_HTTP_Session::Store(); if (!$access && isset($session['auth_url_access']) && $session['auth_url_access']) { $access = true; $mp = $session['auth_url_parms']; } if (!$access && isset($data['auth_url'])) { Core::load('Net.Agents.HTTP'); $url = $data['auth_url']; $agent = Net_HTTP::Agent(); $res = $agent->with_credentials($user->login, $user->password)->send(Net_HTTP::Request($url)); if ($res->status->code == '200') { $r = trim($res->body); if ($r == 'ok' || $r == 'ok:') { $access = true; } else { if ($m = Core_Regexps::match_with_results('{^ok:(.+)$}', $r)) { $access = true; $mp = trim($m[1]); } } } if ($access) { $session['auth_url_access'] = true; $session['auth_url_parms'] = $mp; } } if (!$access) { $args = array($user->login, $user->password, $realm); if (Core_Types::is_callable($extra_auth_callback)) { $extra_auth = Core::invoke($extra_auth_callback, $args); } else { $extra_auth = self::extra_auth($args[0], $args[1], $args[2]); } if ($extra_auth || Core_Types::is_iterable($extra_auth)) { $mp = $extra_auth; $access = true; } else { return self::$realms[$realm] = false; } } $auth_parms = self::auth_parms($mp, $client); $user->parms = $auth_parms; if ($access) { return self::$realms[$realm] = array('data' => $data, 'auth_parms' => $auth_parms); } } else { return self::$realms[$realm] = false; } return self::$realms[$realm] = false; }