示例#1
0
文件: Process.php 项目: techart/tao
 public static function process($source, $process = array())
 {
     $args = func_get_args();
     if (count($args) > 2) {
         $process = array_slice($args, 1);
     }
     if (empty($process)) {
         return $source;
     }
     $process = (array) $process;
     foreach ($process as $name => $config) {
         if (is_int($name) && is_string($config)) {
             $name = $config;
             $config = array();
         } else {
             if (is_int($name) && is_array($config)) {
                 $source = self::process($source, $config);
             }
         }
         if (!isset(self::$process[$name])) {
             continue;
         }
         if (!is_string(self::$process[$name])) {
             $source = Core::invoke(self::$process[$name], array($source));
         } else {
             $p = Core::make(self::$process[$name]);
             if (!Core_Types::is_subclass_of('Text.Process.ProcessInterface', $p)) {
                 continue;
             }
             $p->configure($config);
             $source = $p->process($source);
         }
     }
     return $source;
 }
示例#2
0
文件: Utils.php 项目: techart/tao
 public function tao_cache()
 {
     if (count($this->args) < 2) {
         print "no args\n";
         return;
     }
     $command = array_shift($this->args);
     $args = $this->args;
     $result = var_export(Core::invoke(array(WS::env()->cache, $command), $args), true);
     print "{$result}\n";
 }
示例#3
0
文件: Content.php 项目: techart/tao
 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;
 }
示例#4
0
 public function action($name, $data, $action, $item = false, $fields = array())
 {
     $args = func_get_args();
     $res = Net_HTTP::Response();
     $res->content_type('application/json');
     $query = WS::env()->request['query'];
     $ents = CMS::items_for_select(Core::invoke($data['search'], array($query)));
     $values = array();
     $empty = $this->get_empty($data);
     if ($empty && empty($query)) {
         $values[] = $empty;
     }
     foreach ($ents as $k => $e) {
         $values[] = array('id' => (int) $k, 'title' => (string) $e);
     }
     $res->body(json_encode(array('data' => $values)));
     return $res;
 }
示例#5
0
文件: Vars.php 项目: techart/tao
 public static function on_change_call($id, $value, $data)
 {
     $fc = self::db()->full_code($id);
     if (!empty(CMS_Vars::$plugins_on_change[$fc])) {
         $rc = true;
         foreach (CMS_Vars::$plugins_on_change[$fc] as $m) {
             $class = trim($m[0]);
             $method = trim($m[1]);
             if ($class != '' && $method != '') {
                 $r = Core::invoke(array($class, $method), array($value, $fc));
                 if (is_string($r)) {
                     return $r;
                 }
                 $rc = $rc && $r;
             }
         }
         return $rc;
     }
 }
示例#6
0
文件: ORM.php 项目: techart/tao
 public function save()
 {
     $args = func_get_args();
     array_unshift($args, $this);
     return Core::invoke(array($this->get_mapper(), 'save'), $args);
 }
示例#7
0
文件: Storage.php 项目: techart/tao
 public function delete()
 {
     $args = func_get_args();
     array_unshift($args, $this);
     return Core::invoke(array($this->get_storage(), 'delete'), $args);
 }
示例#8
0
文件: Handlers.php 项目: techart/tao
 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;
 }
示例#9
0
文件: WS.php 项目: techart/tao
 public static function adapter($fallback = false)
 {
     $class = self::adapter_module($fallback);
     $adapter = Core::invoke(array($class, 'adapter'));
     if (!$fallback && !$adapter->validate()) {
         return self::adapter(true);
     }
     return $adapter;
 }
示例#10
0
文件: Vars1.php 项目: techart/tao
 public function __call($method, $args = array())
 {
     return Core::invoke(array($this->db, $method), $args);
 }
示例#11
0
文件: Tree.php 项目: techart/tao
 public static function create_tree($flat, $options = array(), &$childs = array())
 {
     $rows = array();
     $id_name = isset($options['id_name']) ? $options['id_name'] : 'id';
     $title_name = isset($options['title_name']) ? $options['title_name'] : 'title';
     $parent_name = isset($options['parent_name']) ? $options['parent_name'] : 'parent_id';
     $childs_name = isset($options['childs_name']) ? $options['childs_name'] : 'childs';
     $flat_keys = isset($options['flat_keys']) ? $options['flat_keys'] : false;
     $childs_limit = isset($options['childs_limit']) ? $options['childs_limit'] : false;
     $missing_callback = isset($options['missing_callback']) ? $options['missing_callback'] : false;
     $count = 0;
     $missing_ids = array();
     foreach ($flat as $k => $row) {
         if (isset($options['process_callback'])) {
             $row = Core::invoke($options['process_callback'], array($row));
         }
         if (empty($row)) {
             continue;
         }
         if (is_string($row)) {
             $row = array($title_name => $row);
         }
         $id = (int) isset($row[$id_name]) ? $row[$id_name] : $k;
         $rows[$id] = $row;
         if (!isset($childs[$id])) {
             $childs[$id] = array();
         }
         if (isset($row[$childs_name])) {
             $childs[$id] += self::create_tree($row[$childs_name], $options, $childs);
         }
         $pid = $row[$parent_name];
         if (!is_null($pid) && $pid >= 0) {
             $pid = (int) $pid;
             if (!isset($childs[$pid])) {
                 $childs[$pid] = array();
             }
             $childs[$pid][$id] = $row;
         }
     }
     foreach (array_keys($childs) as $pid) {
         if (!isset($rows[$pid]) && $pid > 0) {
             $missing_ids[] = $pid;
         }
     }
     if (!empty($missing_ids) && $missing_callback) {
         foreach ($missing_ids as $id) {
             if ($id > 0) {
                 Core::invoke($missing_callback, array($id, &$childs, &$rows));
             }
         }
     }
     foreach ($rows as $id => &$row) {
         $count++;
         self::tree_row_childs($row, $id, $childs, $childs_name, $count, $childs_limit);
         if ($childs_limit && $count >= $childs_limit) {
             continue;
         }
     }
     unset($row);
     $root = array();
     $root_exists = in_array(0, array_keys($rows), true);
     foreach ($rows as $id => $row) {
         if (intval($row[$parent_name]) == 0 && !$root_exists || is_null($row[$parent_name]) || $id == 0) {
             $root[$id] = $row;
         }
     }
     if (empty($root) && !$root_exists) {
         $root = $rows;
     }
     if ($flat_keys) {
         $root = array_values($root);
         array_walk($root, 'self::tree_row_flat', $childs_name);
     }
     return $root;
 }
示例#12
0
文件: LESS.php 项目: techart/tao
 protected function compile($less_fname, $css_fname)
 {
     self::load();
     $options = self::option('options');
     // generate source map
     if (self::option('sourse_map')) {
         $map_file = str_replace('styles/', '', $css_fname);
         $map_file = trim(str_replace('.less.css', '.map', $map_file), '/.');
         $map_dir = './styles/less-maps/';
         $map_path = "{$map_dir}{$map_file}";
         IO_FS::mkdir(dirname($map_path));
         $options = array_merge($options, array('sourceMap' => true, 'sourceMapWriteTo' => $map_path, 'sourceMapURL' => trim($map_path, '.')));
         // if is out of docroot
         if ($less_fname[0] == '/' || Core_Strings::starts_with($less_fname, '..') || Core_Strings::starts_with($less_fname, './..')) {
             $less_fname = "file://{$less_fname}";
             $less_fname = '.' . Templates_HTML::extern_filepath($less_fname);
         }
     }
     $options['import_dirs'] = self::option('less_import_dirs');
     $dir = dirname($css_fname);
     $url = 'http://' . WS::env()->request->host . '/';
     $args = array(array($less_fname => $url), $options);
     $css_file_name = Core::invoke(self::option('less_callback'), $args);
     $cached_file = rtrim($options['cache_dir'], '/') . '/' . $css_file_name;
     if (is_file($cached_file) && !(WS::env()->request['less_compile'] && self::option('debug'))) {
         $less_ftime = filemtime($cached_file);
         $css_ftime = false;
         if (IO_FS::exists($css_fname)) {
             $css_ftime = filemtime($css_fname);
         }
         if ($css_ftime && $css_ftime >= $less_ftime) {
             return false;
         }
     }
     $css = file_get_contents($cached_file);
     IO_FS::File($css_fname)->update($css);
 }
示例#13
0
文件: CMS.php 项目: techart/tao
 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();
                     }
                 }
             }
         }
     }
 }
示例#14
0
文件: Digest.php 项目: techart/tao
 /**
  * Кодирует строку пароля
  *
  * @param  string $str  пароль
  * @param  string $salt соль
  *
  * @return string       закодированная строка
  */
 public function encode($str, $salt = null)
 {
     $salt = is_null($salt) ? $this->salt : $salt;
     return Core::invoke($this->callback, array($str, $salt));
 }
示例#15
0
文件: XML.php 项目: techart/tao
 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;
 }
示例#16
0
文件: Fields.php 项目: techart/tao
 protected function layout_preprocess($l, $name, $data)
 {
     $form_name = $l->helpers['forms']->form->name;
     $this->attach($l, $name, $data);
     if (!isset($data['caption'])) {
         $data['caption'] = '';
     }
     $caption = trim(CMS::lang($data['caption']));
     $rcaption = '';
     if (isset($data['rcaption'])) {
         $caption = '';
         $rcaption = trim(CMS::lang($data['rcaption']));
     }
     if ($caption == '') {
         $caption = '&nbsp;';
     } else {
         $caption .= ':';
     }
     Events::call("cms.fields.{$form_name}.{$name}.caption", $caption, $rcaption);
     Events::call("cms.fields.{$form_name}.caption", $caption, $rcaption);
     $ccont = $this->caption_content($name, $data);
     if (!$ccont) {
         $ccont = $l->forms->label($name, $caption, array('class' => "label-{$name} left"));
     }
     if (isset($data['allow select format']) && $data['allow select format'] && isset($data['input formats'])) {
         $select_formats = array();
         foreach ($data['input formats'] as $name => $f) {
             $select_formats[$name] = $f['display name'];
         }
         $l->update_parm('selected_formats', $select_formats);
     }
     $l->with(array('caption' => $caption, 'rcaption' => $rcaption, 'current_lang' => $this->current_lang(), 'ccont' => $ccont));
     if (isset($data['layout preprocess'])) {
         Core::invoke($data['layout preprocess'], array($l, $name, $data));
     }
     return $l;
 }
示例#17
0
文件: AdminVars.php 项目: techart/tao
 public function make_uri()
 {
     $args = func_get_args();
     return Core::invoke(array($this, 'make_url'), $args);
 }
示例#18
0
文件: Events.php 项目: techart/tao
 public function dispatch_res($name, $default = null, $e = null, &$arg1 = null, &$arg2 = null, &$arg3 = null, &$arg4 = null, &$arg5 = null, &$arg6 = null)
 {
     if (!$this->enable_dispatch) {
         return $default;
     }
     if (!$this->dispatcher->has_listeners($name)) {
         return $default;
     }
     $args = array($name, $e, &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6);
     $fargs = func_get_args();
     $num_args = count($fargs);
     if ($num_args > 1) {
         $num_args--;
     }
     $res = Core::invoke(array($this, 'dispatch'), array_slice($args, 0, $num_args));
     if (is_null($res)) {
         return $default;
     }
     return $res;
 }
示例#19
0
 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;
 }
示例#20
0
文件: Cache.php 项目: techart/tao
 public function set_if_not($key, $value, $timeout = null)
 {
     $g = $this->get($key);
     if (!empty($g)) {
         return $g;
     }
     $this->set($key, Core::invoke($value), $timeout);
     return $value;
 }