Example #1
0
 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;
 }
Example #2
0
 protected function real_uploaded_filename($name, $data, $file)
 {
     if (Core_Types::is_string($file)) {
         $file = array('name' => $file);
     }
     $path = parent::real_uploaded_filename($name, $data, $file);
     return $this->last_upload_files[] = $path;
 }
Example #3
0
 public function link($name, $url, $title, $arg1 = null, $arg2 = null)
 {
     $this->links[(string) $name] = new WebKit_Navigation_Link($url, $title, Core_Types::is_array($arg1) ? $arg1 : array());
     if ($sublinks = $arg1 instanceof WebKit_Navigation_LinkSet ? $arg1 : ($arg2 instanceof WebKit_Navigation_LinkSet ? $arg2 : null)) {
         $this->links[(string) $name]->sublinks($sublinks);
     }
     return $this;
 }
Example #4
0
 /**
  * @return string
  */
 public function make_uri()
 {
     $args = func_get_args();
     if (!$this->make_uri_method) {
         $this->make_uri_method = Core_Types::reflection_for(CMS::$current_mapper)->getMethod('make_uri');
     }
     return $this->make_uri_method->invokeArgs(CMS::$current_mapper, $args);
 }
Example #5
0
 /**
  * @return string
  */
 public function javascript_include_tag($t)
 {
     $result = '';
     foreach ($args = Core_Types::is_array(func_get_arg(1)) ? func_get_arg(1) : array_slice(func_get_args(), 1) as $src) {
         $result .= $t->tags->content_tag('script', '', array('type' => 'text/javascript', 'src' => $this->javascript_path_for($t, $src))) . "\n";
     }
     return $result;
 }
Example #6
0
File: CLI.php Project: techart/tao
 /**
  * Запускает CLI-приложение
  *
  * @param array $argv
  */
 public static function run_module(array $argv)
 {
     Core::load($argv[0]);
     if (Core_Types::reflection_for($module = Core_Types::real_class_name_for($argv[0]))->implementsInterface('CLI_RunInterface')) {
         return call_user_func(array($module, 'main'), $argv);
     } else {
         throw new CLI_NotRunnableModuleException($argv[0]);
     }
 }
Example #7
0
 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;
 }
Example #8
0
 protected function get_items_keys($name, $parms)
 {
     $keys = isset($parms['__items_keys']) ? $parms['__items_keys'] : array();
     if (!empty($keys)) {
         return $keys;
     }
     $items = isset($parms['__items']) ? $parms['__items'] : CMS::items_for_select($parms['items']);
     foreach ($items as $key => $data) {
         if (!$data instanceof DB_ORM_Entity && Core_Types::is_iterable($data)) {
             foreach ($data as $key => $value) {
                 $keys[] = $this->checkbox_name($name, $key);
             }
         } else {
             $keys[] = $this->checkbox_name($name, $key);
         }
     }
     return $keys;
 }
Example #9
0
 /**
  * @return string
  */
 protected function unparse_array($src, $prefix)
 {
     if (Core_Types::is_iterable($src)) {
         $out = '';
         foreach ($src as $key => $value) {
             if (Core_Types::is_iterable($value)) {
                 $value = $this->unparse_array($value, "\t{$prefix}");
                 $out .= "{$prefix}{$key} = {\n{$value}{$prefix}}\n";
             } else {
                 $value = (string) $value;
                 $out .= "{$prefix}{$key} = {$value}\n";
             }
         }
         return $out;
     } else {
         return (string) $src;
     }
 }
Example #10
0
 protected function get_title($item)
 {
     $title = false;
     if (!$this->component) {
         return false;
     }
     $component_class_name = CMS::component_class_name($this->component);
     if ($component_class_name) {
         $title = Core_Types::reflection_for($component_class_name)->getStaticPropertyValue('admin_vars_title', false);
         if (!$title) {
             $title = "Настройки: {$component_class_name}";
         }
         if ($item->id > 0 && trim($item->title) != '') {
             $title .= ': ' . $item->title;
         }
     }
     return $title;
 }
Example #11
0
File: BB.php Project: techart/tao
 static function transform($src, $config = false)
 {
     if (Core_Types::is_iterable($config)) {
         foreach ($config as $key => $value) {
             self::${$key} = $value;
         }
     }
     $out = '';
     $src = strip_tags($src);
     $src = str_replace("[quote]", "\n[quote]\n", $src);
     $src = str_replace("[/quote]", "\n[/quote]\n", $src);
     $lines = explode("\n", $src);
     foreach ($lines as $line) {
         $line = trim($line);
         if ($line != '') {
             $out .= self::$lclass->line($line);
         }
     }
     return self::process_codes($out);
 }
Example #12
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;
 }
Example #13
0
 /**
  * Преобразует значение в пригодный вид для вставки в sql запрос
  *
  * @param  $value
  *
  * @return mixed
  */
 public function cast_parameter($value)
 {
     switch (true) {
         case $value instanceof Time_DateTime:
             return $value->format(Time::FMT_DEFAULT);
         case Core_Types::is_array($value):
             $str = '{';
             foreach ($value as $e) {
                 $str .= ($str == '{' ? '' : ',') . '"' . ($this->is_castable_parameter($e) ? $this->cast_parameter($e) : $e) . '"';
             }
             return $str . '}';
         case !is_object($value) && (string) (int) $value === (string) $value:
             return (int) $value;
         default:
             return $value;
     }
 }
Example #14
0
 /**
  * @param DSL_Script_Action $action
  *
  * @return DSL_Builder
  */
 protected function builder_for(DSL_Script_Action $action, $class = '')
 {
     return Core::make($class ? $class : Core_Types::real_class_name_for($this), $this->actions($action), $action);
 }
Example #15
0
File: Core.php Project: techart/tao
 /**
  * Возвращает reflection для заданного объекта или класса
  *
  * @param  $object
  *
  * @return mixed
  */
 public static function reflection_for($object)
 {
     if (Core_Types::is_string($object)) {
         return new ReflectionClass(self::real_class_name_for($object));
     }
     if (Core_Types::is_object($object)) {
         return new ReflectionObject($object);
     }
     throw new Core_InvalidArgumentTypeException('object', $object);
 }
Example #16
0
File: Data.php Project: techart/tao
 public function branch($name, array $items = array())
 {
     $name = (string) $name;
     if (!isset($this->data[$name])) {
         $class_name = Core_Types::real_class_name_for($this);
         $this->data[$name] = new $class_name();
         foreach ($items as $k => &$v) {
             $this->data[$name]->{$k} = $v;
         }
         return $this->data[$name];
     }
     throw new Core_ReadOnlyPropertyException($name);
 }
Example #17
0
 /**
  * Конструктор
  *
  */
 public function __construct()
 {
     $this->options = CLI_GetOpt::Parser()->boolean_option('show_usage', '-h', '--help', 'Shows help message');
     $this->log = Log::logger()->context(array('module' => Core_Types::module_name_for($this)));
     $this->config = Core::object(array('log' => Log::logger(), 'show_usage' => false));
 }
Example #18
0
File: Proc.php Project: techart/tao
 /**
  * Добавляет/устанавливает переменный окружения
  *
  * @param array $env
  *
  * @return Proc_Process
  */
 public function environment(array $env)
 {
     if (!Core_Types::is_array($this->environment)) {
         $this->environment = array();
     }
     foreach ($env as $k => $v) {
         $this->environment[$k] = (string) $v;
     }
     return $this;
 }
Example #19
0
 public function add($title, $item)
 {
     if (!Core_Types::is_iterable($item)) {
         $item = array('uri' => $item, 'url' => $item);
     }
     if (isset($item['title'])) {
         $title = $item['title'];
     }
     $title = CMS::lang($title);
     //Events::dispatch('cms.navigation.add', $ev = Events::Event(array('title' => $title, 'data' => $item, 'url' => $item['url'])));
     //$title = $ev['title'];
     //$item = $ev['data'];
     //$item['url'] = $ev['url'];
     $url = $item['url'];
     Events::call('cms.navigation.add', $title, $item, $url);
     $item['url'] = $url;
     $access = isset($item['access']) ? trim($item['access']) : '';
     if ($access != '' && !CMS::check_globals_or($access)) {
         return $this;
     }
     if (isset($item['disabled'])) {
         if (CMS::check_yes($item['disabled'])) {
             return $this;
         }
     }
     $uri = '';
     if (isset($item['uri'])) {
         $uri = $item['uri'];
     }
     if (isset($item['url'])) {
         $uri = $item['url'];
     }
     $id = isset($item['id']) ? $item['id'] : md5($title . $uri);
     if (isset($item['navigation_id'])) {
         $id = trim($item['navigation_id']);
     }
     $selected = false;
     $disabled = false;
     if (isset($item['match'])) {
         if (preg_match($item['match'], CMS_Navigation3::$uri)) {
             $selected = true;
         }
     }
     if (isset($item['flag'])) {
         if (CMS::$navigation->is_flag($item['flag'])) {
             $selected = true;
         }
     }
     if ($uri == CMS_Navigation3::$uri) {
         $selected = true;
     }
     $item['selected'] = $selected;
     $item['disabled'] = $disabled;
     $sub = isset($item['sub']) ? $item['sub'] : null;
     if (is_string($sub)) {
         $sub = trim($sub);
         $_component = $sub;
         $_parms = $uri;
         if ($m = Core_Regexps::match_with_results('{^([^\\s]+)\\s+(.+)$}', $sub)) {
             $_component = trim($m[1]);
             $_parms = trim($m[2]);
         }
         if (CMS::component_exists($_component)) {
             $_class = CMS::$component_names[$_component];
             $_classref = Core_Types::reflection_for($_class);
             $sub = $_classref->hasMethod('navigation_tree') ? $_classref->getMethod('navigation_tree')->invokeArgs(NULL, array($_parms, $item)) : false;
         }
     }
     if (Core_Types::is_iterable($sub)) {
         $set = new CMS_Navigation3_LinkSet();
         $set->level_num = $this->level_num + 1;
         $set->process($sub);
         $this->link($id, $uri, $title, $item, $set);
     } else {
         $this->link($id, $uri, $title, $item);
     }
     return $this;
 }
Example #20
0
File: Curl.php Project: techart/tao
 protected function encode_parameters(&$parms)
 {
     $result = '';
     if ($parms && (Core_Types::is_array($parms) || $parms instanceof Traversable)) {
         foreach ($parms as $k => $v) {
             $result .= ($result ? '&' : '') . urlencode($k) . '=' . urlencode($v);
         }
     }
     return $result;
 }
Example #21
0
 public function form_field($form, $name, $parms)
 {
     $items = CMS::items_for_select($parms['items']);
     foreach ($items as $key => $data) {
         if (Core_Types::is_iterable($data)) {
             foreach ($data as $key => $value) {
                 $form->checkbox($name . $key);
             }
         } else {
             $form->checkbox($name . $key);
         }
     }
 }
Example #22
0
 public function add_item($link, $level, $parent = null)
 {
     $access = isset($link->access) ? trim($link->access) : '';
     if ($access != '' && !CMS::check_globals_or($access)) {
         return $this;
     }
     if (empty($link->url) && empty($link->id) && ($m = Core_Regexps::match_with_results('{^\\%(.+)$}', trim($link->title)))) {
         $_component = trim($m[1]);
         $_parms = false;
         if ($m = Core_Regexps::match_with_results('{^([^\\s]+)\\s+(.+)$}', $_component)) {
             $_component = $m[1];
             $_parms = trim($m[2]);
         }
         if (CMS::component_exists($_component)) {
             $_class = CMS::$component_names[$_component];
             $_classref = Core_Types::reflection_for($_class);
             $links = $_classref->hasMethod('navigation_tree') ? $_classref->getMethod('navigation_tree')->invokeArgs(NULL, array($_parms)) : array();
             foreach ($links as $k => &$v) {
                 $v["from-{$_component}"] = 1;
             }
             return $this->load_data($links, $level, $parent);
         }
         return $this;
     }
     return parent::add_item($link, $level, $parent);
 }
Example #23
0
File: JSON.php Project: techart/tao
 /**
  * @param array                     $json
  * @param Object_AttrsListInterface $object
  * @param Object_Attribute          $attr
  * @param                           $flavor
  * @param                           $columns
  *
  * @return object
  */
 protected function decode_collection($json, Object_AttrListInterface $object, Object_Attribute $attr, $flavor = null, $columns = array())
 {
     $operation = isset($attr->operation) ? $attr->operation : 'append';
     foreach ($json->{$attr->name} as $v) {
         if (Core_Types::is_subclass_of('Object_AttrListInterface', $attr->items)) {
             $item = $this->decode_object($v, Core::make($attr->items));
         } else {
             $item = $this->decode_scalar($v, $attr->items);
         }
         if (is_string($operation) && method_exists($object->{$attr->name}, $operation)) {
             $object->{$attr->name}->{$operation}($item);
         } else {
             if (is_array($operation)) {
                 call_user_func($operation, $item);
             }
         }
     }
     return $object;
 }
Example #24
0
File: SQL.php Project: techart/tao
 protected function row_get_type()
 {
     return Core_Types::real_class_name_for($this);
 }
Example #25
0
File: WS.php Project: techart/tao
 /**
  * @param Net_HTTP_Response $response
  */
 public function process_response(Net_HTTP_Response $response, $quiet = false)
 {
     ob_start();
     $body = $response->body;
     if (Core_Types::is_iterable($body)) {
         foreach ($body as $line) {
             print $line;
         }
     } else {
         print $body instanceof Core_StringifyInterface ? $body->as_string() : (string) $body;
     }
     $response->body = ob_get_contents();
     ob_end_clean();
     if (!$quiet) {
         Events::call('ws.response', $response);
     }
     if ((int) $response->status->code != 200) {
         header('HTTP/1.0 ' . $response->status);
     }
     foreach ($response->headers->as_array(true) as $v) {
         header($v);
     }
     print $response->body;
 }
Example #26
0
 public function process($data)
 {
     foreach ($data as $title => $item) {
         if (is_string($item) && trim($item) == '' && ($m = Core_Regexps::match_with_results('{^\\%(.+)$}', trim($title)))) {
             $_component = trim($m[1]);
             $_parms = false;
             if ($m = Core_Regexps::match_with_results('{^([^\\s]+)\\s+(.+)$}', $_component)) {
                 $_component = $m[1];
                 $_parms = trim($m[2]);
             }
             if (CMS::component_exists($_component)) {
                 $_class = CMS::$component_names[$_component];
                 $_classref = Core_Types::reflection_for($_class);
                 $links = $_classref->hasMethod('navigation_tree') ? $_classref->getMethod('navigation_tree')->invokeArgs(NULL, array($_parms)) : array();
                 foreach ($links as $k => $v) {
                     if (is_string($v)) {
                         $v = array('url' => $v);
                     }
                     $v["from-{$_component}"] = 1;
                     $links[$k] = $v;
                 }
                 $this->process($links);
             }
         } else {
             $this->add($title, $item);
         }
     }
 }
Example #27
0
File: ORM.php Project: techart/tao
 /**
  * @param string $index
  *
  * @return mixed
  */
 public function offsetGet($index)
 {
     switch (true) {
         case method_exists($this, $name = "row_get_{$index}"):
             return $this->{$name}();
         case $index === '__class':
             return Core_Types::real_class_name_for($this);
         default:
             return $this->get($index, $name);
     }
 }
Example #28
0
File: XML.php Project: 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;
 }
Example #29
0
 public function get($var, $values = false)
 {
     Core::load('Mail');
     if (!Core_Types::is_iterable($values)) {
         $values = array();
     }
     $mailtext = $var->value;
     if (Core_Types::is_iterable($values)) {
         foreach ($values as $key => $val) {
             $mailtext = str_replace("%{{$key}}", $val, $mailtext);
         }
     }
     $body = CMS::render_mail('empty', array('content' => $mailtext));
     $this->multipart = false;
     $this->attaches = array();
     $body = preg_replace_callback('{(src)="(/[^"]+)"}', array($this, 'attaches_cb'), $body);
     $parms = unserialize($var->parms);
     $mail = Mail::Message()->subject($parms['subject'])->from($parms['from'])->to($parms['to']);
     if (!$this->multipart) {
         $mail->html($body);
     } else {
         if ($this->multipart == 'mixed') {
             $mail->multipart_mixed();
         }
         if ($this->multipart == 'related') {
             $mail->multipart_related();
         }
         $mail->html_part($body);
         foreach ($this->attaches as $id => $part) {
             $mail->part($part);
         }
     }
     return $mail;
 }
Example #30
0
 public static function encode_value($value)
 {
     $enc = '';
     if (is_null($value)) {
         return 'e:1';
     } else {
         if (is_numeric($value)) {
             $enc = 'n:' . $value;
         } else {
             if (is_bool($value)) {
                 $enc = 'b:' . ($value ? '1' : '0');
             } else {
                 if ($value instanceof Time_DateTime) {
                     $enc = 'd:' . $value->format('%D, %d %M %Y %H:%M:%S %e');
                 } else {
                     if (Core_Types::is_iterable($value)) {
                         $is_array = true;
                         foreach (array_keys($value) as $key) {
                             $is_array = is_numeric($key) && $is_array;
                         }
                         if ($is_array) {
                             $flat = array();
                             foreach ($value as $i => $v) {
                                 $flat[] = self::encode_value($v);
                             }
                             $enc = 'a:' . implode('^', $flat);
                         } else {
                             $flat = array();
                             foreach ($value as $k => $v) {
                                 $flat[] = $k . '=' . self::encode_value($v);
                             }
                             $enc = 'o:' . implode('^', $flat);
                         }
                     } else {
                         $enc = 's:' . $value;
                     }
                 }
             }
         }
     }
     return rawurlencode($enc);
 }