Example #1
0
 public static function options(array $options = array())
 {
     if (count($options)) {
         Core_Arrays::update(self::$options, $options);
     }
     return self::$options;
 }
Example #2
0
 public function process_items($items, $data)
 {
     $tree_items = isset($data['flat']) && $data['flat'] === false ? $items : Core_Arrays::create_tree($items, $data['create_tree']);
     $out = array();
     $flat_out = array();
     $options = isset($data['create_tree']) ? $data['create_tree'] : array();
     $options['id_name'] = isset($options['id_name']) ? $options['id_name'] : 'id';
     $options['title_name'] = isset($options['title_name']) ? $options['title_name'] : 'title';
     $options['childs_name'] = isset($options['childs_name']) ? $options['childs_name'] : 'childs';
     $options['disabled_name'] = isset($options['disabled_name']) ? $options['disabled_name'] : 'disabled';
     $this->tree_generation($out, $flat_out, $tree_items, $options, $data);
     $outs = array($out, $flat_out);
     return $outs;
 }
Example #3
0
File: HTML.php Project: techart/tao
 protected function http_to_string($name, $content)
 {
     return sprintf("<meta http-equiv=\"%s\" content=\"%s\" />\n", htmlspecialchars(Core_Arrays::join_with('-', Core_Arrays::map('return ucfirst(strtolower($x));', Core_Strings::split_by('_', $name)))), htmlspecialchars($content));
 }
Example #4
0
 public function create_table($table, $defs)
 {
     Core_Arrays::expand($table, array('mysql_engine' => 'InnoDB', 'mysql_character_set' => 'utf8'));
     $sql = sprintf("CREATE TABLE `%s` (%s)", $table['name'], implode(', ', $defs));
     $sql .= 'ENGINE = ' . $table['mysql_engine'] . ' DEFAULT CHARACTER SET ' . $table['mysql_character_set'];
     if (!empty($table['collation'])) {
         $sql .= ' COLLATE ' . $table['collation'];
     }
     return $sql;
 }
Example #5
0
File: SQL.php Project: techart/tao
 public function run()
 {
     $binds = count($args = func_get_args()) > 1 ? $args : $args[0];
     $run_callbacks = $binds instanceof DB_SQL_Entity && $this->view && $binds instanceof $this->view->prototype;
     $sql = 'DELETE FROM ' . ($this->table ? $this->table : $this->view->table->name) . "\n";
     if (count($where = Core_Arrays::merge($this->view ? $this->view->__get('where') : array(), $this->where))) {
         $sql .= 'WHERE (' . Core_Arrays::join_with(') AND (', $where) . ')';
     }
     if ($run_callbacks ? $binds->before_delete() : true) {
         $rc = DB_SQL::db()->connection->prepare($sql)->bind($binds)->execute();
     }
     if ($run_callbacks && $rc) {
         $binds->after_delete();
     }
     return $rc;
 }
Example #6
0
 public function add_file_array($file, $options = array())
 {
     $options = (array) $options;
     $file = (string) $file;
     $exist = isset($this->files[$file]) ? $this->files[$file] : null;
     if (!empty($exist) && $exist['immutable']) {
         return $this;
     }
     if (empty($exist)) {
         $this->add($file, empty($options['weight']) ? 0 : $options['weight'], empty($options['type']) ? 'app' : $options['type'], !isset($options['join']) ? true : $options['join'], !isset($options['immutable']) ? false : $options['immutable'], isset($options['attrs']) ? $options['attrs'] : array(), isset($options['add_timestamp']) ? $options['add_timestamp'] : null, isset($options['minify']) ? $options['minify'] : false, isset($options['absolute']) ? $options['absolute'] : null, isset($options['place']) ? $options['place'] : null);
     } else {
         $exist_options = $exist->getArrayCopy();
         $exist_options = Core_Arrays::deep_merge_update($exist_options, $options);
         $this->files[$file] = new ArrayObject($exist_options);
     }
     return $this;
 }
Example #7
0
File: Core.php Project: techart/tao
 /**
  * Устанавливает значения списка опций, возвращает список значений всех опций
  *
  * @param array $options
  *
  * @return mixed
  */
 public static function options(array $options = array())
 {
     Core_Arrays::deep_merge_update_inplace(self::$options, $options);
     return self::$options;
 }
Example #8
0
 public function test_contains()
 {
     $array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
     $this->assertTrue(Core_Arrays::contains($array, 'red'));
     $this->assertFalse(Core_Arrays::contains($array, 'black'));
 }
Example #9
0
 public function submit_image($t, $src, array $attributes = array())
 {
     return $t->tags->tag('input', Core_Arrays::merge(array('type' => 'image', 'src' => Templates_HTML::helper('assets')->image_path_for($src), 'id' => "{$this->form->name}_form_submit"), $attributes)) . "\n";
 }
Example #10
0
 protected function preprocess($template, $name, $data)
 {
     $t = parent::preprocess($template, $name, $data);
     $options = Core_Arrays::deep_merge_update($this->default_options, (array) $data['options']);
     $format = 'decimal';
     if (isset($data['format'])) {
         $format = $data['format'];
     }
     switch (count($this->check_schema($data))) {
         case 0:
             $values = $this->parse_field($data['__item']->{$name});
             if ($values['zoom']) {
                 $options['properties']['zoom'] = $values['zoom'];
             }
             break;
         case 1:
             $field_name = $this->schema[0];
             $values = $this->parse_field($data['__item']->{$field_name});
             if ($values['zoom']) {
                 $options['properties']['zoom'] = $values['zoom'];
             }
             break;
         case 3:
             $zoom_name = $this->schema[2];
             $zoom = $data['__item']->{$zoom_name};
             if (!is_null($zoom)) {
                 $options['properties']['zoom'] = $zoom;
             }
             break;
     }
     $use_zoom = $this->use_zoom_check($data);
     $show_zoom = $use_zoom && isset($data['show_zoom']);
     return $t->with(array('service' => $data['service'], 'options' => $options, 'format' => $format, 'use_zoom' => $use_zoom, 'show_zoom' => $show_zoom));
 }
Example #11
0
 public function __construct($url, $title, array $options = array())
 {
     $this->url = $url;
     $this->title = $title;
     $this->is_disabled = (bool) Core_Arrays::pick($options, 'disabled', false);
     $this->is_selected = (bool) Core_Arrays::pick($options, 'selected', false);
     $this->options = Data::Hash($options);
 }
Example #12
0
File: Rest.php Project: techart/tao
 /**
  * @param string $name
  * @param array  $args
  *
  * @return mixed
  */
 public function __call($name, $args)
 {
     if (!Core_Regexps::match('{_url$}', $name)) {
         throw new Core_MissingMethodException($name);
     }
     $name = Core_Strings::replace($name, 'single_', 'single-');
     $url = '';
     $args = Core_Arrays::reverse($args);
     $parms = Core_Types::is_array($args[0]) ? Core_Arrays::shift($args) : array();
     $parts = Core_Arrays::reverse(Core_Strings::split_by('_', Core_Regexps::replace('{_url$}', '', $name)));
     $last_idx = count($parts) - 1;
     $target = false;
     foreach ($parts as $idx => $part) {
         $part = Core_Strings::replace($part, '-', '_');
         if ($target) {
             if (isset($this->single_names[$part])) {
                 $url = '/' . $this->single_names[$part] . '/' . (Core_Types::is_object($arg = Core_Arrays::shift($args)) ? $arg->id : (string) $arg) . $url;
             } elseif ($idx == $last_idx && (isset($this->resources[$target]) && isset($this->resources[$target]['collection']) && isset($this->resources[$target]['collection'][$part])) || isset($this->single_names[$target]) && isset($this->resources[$this->single_names[$target]]['instance']) && isset($this->resources[$this->single_names[$target]]['instance'][$part])) {
                 $url .= "/{$part}";
             } else {
                 throw new Core_MissingMethodException($name);
             }
         } else {
             if (isset($this->resources[$part])) {
                 $url = "/{$part}{$url}";
                 $target = $part;
             } elseif (isset($this->single_names[$part])) {
                 $id = Core_Arrays::shift($args);
                 $url = '/' . $this->single_names[$part] . '/' . (Core_Types::is_object($id) ? $id->id : (string) $id) . $url;
                 $target = $part;
             } else {
                 throw new Core_MissingMethodException($name);
             }
         }
     }
     return $this->add_keyword_parameters($this->add_path($url) . (isset($args[0]) ? '.' . $args[0] : ".{$this->default_format}"), $parms);
 }
Example #13
0
 public static function initialize($opts = array())
 {
     self::$options['base_paths'] = array(Core::tao_config_dir(), '../app/config/', '../config/');
     self::$options = Core_Arrays::deep_merge_update(self::$options, $opts);
 }
Example #14
0
 /**
  * Получение настроек редактора
  *
  * @return array
  */
 public function settings()
 {
     return Core_Arrays::deep_merge_update($this->default_settings(), $this->settings);
 }
Example #15
0
 /**
  * @param string $method
  * @param array  $args
  *
  * @return mixed
  */
 public function __call($method, $args)
 {
     if (Core_Strings::ends_with($method, '_url')) {
         $redirect = false;
         // TODO: Ugly hack, needs refactoring
         if (Core_Strings::starts_with($method, 'redirect_to_')) {
             $redirect = true;
             $method = Core_Strings::substr($method, 12);
         }
         $parms = array();
         foreach ($this->completion_parms as $name) {
             if (isset($this->request[$name])) {
                 $parms[$name] = $this->request[$name];
             }
         }
         if (count($args) && is_array($args[count($args) - 1])) {
             if (count($parms)) {
                 $args[count($args) - 1] = Core_Arrays::merge($parms, $args[count($args) - 1]);
             }
         } else {
             if (count($parms)) {
                 $args[] = $parms;
             }
         }
         $url = method_exists($this->urls, $method) ? Core_Types::reflection_for($this->urls)->getMethod($method)->invokeArgs($this->urls, $args) : $this->urls->__call($method, $args);
         return $redirect ? $this->redirect_to($url) : $url;
     } else {
         throw new Core_MissingMethodException($method);
     }
 }
Example #16
0
File: Data.php Project: techart/tao
 public function assign_from($source)
 {
     Core_Arrays::update($this->values, $source);
     return $this;
 }
Example #17
0
 /**
  * Конструктор
  *
  * @param array $options
  */
 public function __construct(array $options = array())
 {
     $this->options = Mail_Transport_Sendmail::options();
     Core_Arrays::update($this->options, $options);
 }
Example #18
0
 /**
  * Приводит имя к виду соответствующему почтовому стандарту
  *
  * @param string $name
  *
  * @return string
  */
 protected function canonicalize($name)
 {
     $parts = Core_Arrays::map('return strtolower($x);', Core_Strings::split_by('-', trim($name)));
     foreach ($parts as &$part) {
         $part = isset(self::$acronyms[$part]) ? self::$acronyms[$part] : (preg_match('{[aeiouyAEIOUY]}', $part) ? ucfirst($part) : strtoupper($part));
     }
     return Core_Arrays::join_with('-', $parts);
 }
Example #19
0
File: ORM.php Project: techart/tao
 /**
  * Возвращет массив установленных опций с учетом радительских опций
  * 
  * @return array
  */
 public function all_options()
 {
     $item = $this;
     $result = array();
     do {
         foreach ($item->options as $key => $value) {
             if (is_array($value)) {
                 $result[$key] = Core_Arrays::merge((array) $result[$key], $value);
             } else {
                 $result[$key] = $value;
             }
         }
     } while ($item = $item->parent);
     return $result;
 }
Example #20
0
File: HTTP.php Project: techart/tao
 /**
  * @param array $options
  */
 public static function default_curl_options(array $options)
 {
     Core_Arrays::merge(self::$options['curl_options'], $options);
 }
Example #21
0
File: Auth.php Project: techart/tao
 /**
  */
 public function parameters(array $parameters)
 {
     Core_Arrays::update($this->parameters, $parameters);
     return $this;
 }
Example #22
0
File: HTTP.php Project: techart/tao
 /**
  * Возвращает значение свойства
  *
  * @param string $property
  *
  * @return mixed
  */
 public function __get($property)
 {
     switch ($property) {
         case 'scheme':
         case 'host':
         case 'path':
         case 'port':
         case 'user':
         case 'pass':
             return $this->uri[$property];
         case 'query':
             return $this->urlencode($this->query);
         case 'headers':
         case 'session':
         case 'meta':
         case 'body':
             return $this->{$property};
         case 'content':
             return $this->{$property} ? $this->{$property} : ($this->{$property} = @file_get_contents('php://input'));
         case 'parameters':
             return Core_Arrays::merge($this->query, $this->parameters);
         case 'post_data':
             return $this->urlencode($this->parameters);
         case 'url':
             return $this->compose_url();
         case 'uri':
             return $this->compose_uri();
         case 'urn':
             return $this->compose_urn();
         case 'method_name':
         case 'method':
             return Net_HTTP::method_name_for($this->method);
         case 'method_code':
             return $this->method;
         case 'id':
             if ($this->id) {
                 return $this->id;
             }
             Core::load('Text.Process');
             $id = Text_Process::process($this->path, 'translit');
             $id = trim(preg_replace('{[^a-zA-Z0-9]+}ui', '_', $id), '_');
             return $this->id = $id;
         default:
             return parent::__get($property);
     }
 }
Example #23
0
 static function options($options = array())
 {
     self::$options = Core_Arrays::deep_merge_update(self::$options, $options);
 }
Example #24
0
 /**
  * Конструктор
  *
  * @param string  $attribute имя атрибута
  * @param mixed[] $values    начало интервала
  * @param string  $message   сообщение об ошибке
  * @param array   $options   массив атрибутов
  */
 public function __construct($attribute, $values, $message, array $options = array())
 {
     $this->values = $values;
     Core_Arrays::update($this->options, $options);
     parent::__construct($attribute, $message);
 }
Example #25
0
File: WS.php Project: techart/tao
 /**
  */
 protected function current_uploads()
 {
     $files = array();
     foreach ($_FILES as $name => $file) {
         if (is_array($file['error'])) {
             $files[$name] = array_shift($file);
             foreach ($file as $v) {
                 $files[$name] = Core_Arrays::deep_merge_append($files[$name], $v);
             }
         } else {
             $files[$name] = array_values($file);
         }
     }
     $this->create_objects($files);
     return $files;
 }
Example #26
0
 public function config($name)
 {
     if (!empty($this->cconfig[$name])) {
         return $this->cconfig[$name];
     }
     $config = array();
     $file = $this->dir() . "/{$this->config_dir}/{$name}.php";
     if (is_file($file)) {
         $config = (array) Config_DSL::Builder()->load($file)->object;
     }
     $file = $this->dir() . "/{$this->user_config_dir}/{$name}.php";
     if (is_file($file)) {
         $user_data = Config_DSL::Builder()->load($file)->object;
         $config = Core_Arrays::deep_merge_update($config, (array) $user_data);
     }
     $result = (object) $config;
     $method = "config_{$name}";
     if (method_exists($this, $method)) {
         $result = $this->{$method}($result);
     }
     return $this->cconfig[$name] = $result;
 }
Example #27
0
 public static function add_path($path, $position = 1)
 {
     $paths = self::option('templates_root');
     Core_Arrays::put($paths, $path, $position);
     $paths = array_unique($paths);
     self::option('templates_root', $paths);
     return $paths;
 }
Example #28
0
 /**
  * @param Templates_HTML_Template $t
  * @param int $from
  * @param int $to
  * @param stirng $name
  * @param string $type
  * @param Time_DateTime $value
  * @param array $attributes
  * @param string $tag
  */
 private function datetime_tag($t, $from, $to, $name, $type, Time_DateTime $value, $attributes, $tag = 'select')
 {
     $res = $t->tag($tag, Core_Arrays::merge(array('name' => $this->field_name_for($name) . "[{$type}]", 'id' => $this->field_id_for($name) . "_{$type}"), isset($attributes[$type]) ? Core_Arrays::merge($attributes, (array) $attributes[$type]) : $attributes), false);
     if ($from !== null && $to !== null) {
         for ($i = $from; $i <= $to; $i++) {
             $res .= $t->content_tag('option', sprintf('%02d', $i), array('value' => $i, 'selected' => $value ? $value->{$type} == $i : false));
         }
     }
     $res .= "</{$tag}>";
     return $res;
 }
Example #29
0
 /**
  * @param string $url
  * @param array  $attributes
  *
  * @return string
  */
 public function image_tag($t, $url, array $attributes = array())
 {
     return $t->tags->tag('img', Core_Arrays::merge($attributes, array('src' => $this->image_path_for($url))));
 }
Example #30
0
 protected function list_fields()
 {
     $fields = $this->schema_fields();
     if ($fields) {
         $fields = $this->search_fields($fields, array(), 'in_list', 'weight_in_list', 'caption_in_list');
         return Core_Arrays::merge($this->list_fields, $fields);
     } else {
         return $this->list_fields;
     }
 }