protected function action_imagelist($name, $data, $action, $item = false, $fields = array()) { $image_fields = array(); if (!empty($data['images fields'])) { $image_fields = $data['images fields']; } else { foreach ($fields as $name => $f) { if (in_array($f['type'], $this->allow_images_field_types($name, $data))) { $image_fields[] = $name; } } } $res = array(); foreach ($image_fields as $name) { $field = $fields[$name]; $type_object = CMS_Fields::type($field); if (method_exists($this, $method = 'imagelist_from_' . $field['type'])) { $this->{$method}($res, $name, $field, $type_object, $item); } } foreach ($res as &$f) { $f = trim($f, ' .'); } if (!empty($data['add images'])) { $res = array_merge($res, $data['add images']); } return $this->get_editor($name, $data)->image_list_to_js($res); }
public function discover($entity, $flavor = array()) { $ckey = $this->cache_key($entity); if ($this->enable_cache && $this->cache()->has($ckey)) { return $this->cache()->get($ckey); } $data = $entity->mapper ? $entity->mapper->schema_fields() : null; if (!empty($data) && !$this->force_inspect) { $data = CMS_Fields::fields_to_schema($data, $entity->mapper->options['table'][0]); } else { $data = $entity->mapper ? $entity->mapper->inspect() : null; } if (!empty($data)) { $res = $this->from_schema($data); if ($this->enable_cache) { $this->cache()->set($ckey, $res, 0); } return $res; } }
public function action_add($name, $data, $action, $item = false, $fields = array()) { //TODO: refactoring $iname = WS::env()->request['last_name']; if (!empty($iname)) { if (!$this->is_item_name($iname, $name, $data)) { return json_encode(array('status' => false, 'message' => '')); } preg_match("!{$name}_([\\d]+)!", $iname, $m); $num = (int) $m[1] + 1; } else { $num = 0; } $form = $this->create_form($item); $item = $this->get_assoc_mapper($name, $data)->make_entity(); $item_name = $name . '_' . $num; $item_data = $this->get_item_data($name, $data); $this->add_item_to_form($form, $item, $item_name, $item_data, $type_object = CMS_Fields::type($item_data)); $template = $this->create_layout($name, $data, 'empty', 'item', array('iitem' => $item, 'item_name' => $item_name, 'item_data' => $item_data, 'form' => $form)); $html = $template->render(); return json_encode(array('status' => true, 'data' => $html, 'eval' => trim($template['js']), 'js' => $template->js_agregator->files_list(), 'css' => $template->css_agregator->files_list())); }
public function process_schema($name, $data, $table) { $table_tags = self::table_tags($table, $name); $fields_tags = array('id' => array('sqltype' => 'serial'), 'title' => array('sqltype' => 'varchar(100) index')); CMS_Fields::process_schema($table_tags, $fields_tags); $table_rels = self::table_rels($table, $name); $fields_rels = array('tag_id' => array('sqltype' => 'int index'), 'item_id' => array('sqltype' => 'int index')); CMS_Fields::process_schema($table_rels, $fields_rels); }
public function field_in_layout($view, $name, $data, $layout = false) { $type = CMS_Fields::type($data); $type->view = $view; return $type->draw_in_layout($name, $data, $layout); }
public static function field($name) { $data = static::$fields[$name]; $type_object = CMS_Fields::type(isset($data['type']) ? $data['type'] : ''); return $type_object->container($name, $data, $this); }
public function process_schema() { // process schema modules $modules = $this->schema_modules(); if (!empty($modules)) { foreach ($modules as $name => $module) { CMS::cached_run($module); } } // get data from config $schema = $this->config('schema'); $fields = $this->config('fields'); $tmp1 = (array) $schema; $tmp2 = (array) $fields; if (empty($tmp1) && empty($tmp2)) { return; } if (empty($fields)) { $fields = Core::hash(); } $schema = clone $schema; // some time we have fields without info in schema // fix it $schema_keys = array_keys((array) $schema); $fields_keys = array_keys((array) $fields); $diff = array_diff($fields_keys, $schema_keys); foreach ($diff as $name) { $schema->{$name} = array(); } //fields to schema Core::load('DB.Schema'); Core::load('CMS.Fields'); foreach ($schema as $name => &$table) { if (!empty($fields->{$name})) { $table_fields = $fields->{$name}; $table_name = $name; CMS_Fields::fields_to_schema($fields->{$name}, $name, $table); Events::add_once('db.schema.after_execute.' . $name, function ($tf_schema) use($table_fields, $table_name) { foreach ($table_fields as $tf_name => $tf_data) { $tf_type = CMS_Fields::type($tf_data); $tf_type->process_schema($tf_name, $tf_data, $table_name, $table_fields); } }); } } // remove empty values foreach ($schema as $name => $ttable) { if (empty($ttable)) { unset($schema->{$name}); } } // cache $cname = strtolower($this->get_name()); if (!empty($cname)) { $cache_key = 'cms:component:' . $cname . ':schema:' . md5(serialize($schema)); if ($this->cache->has($cache_key)) { return $this; } $this->cache->set($cache_key, 1, 0); } // run DB_Schema::process_cache($schema); }
public function template($data = array(), $name = 'template') { static $template = array(); if (Templates::is_absolute_path($name)) { return $name; } if (isset($data['template'])) { $data_templates = is_string($data['template']) ? array('template' => $data['template']) : $data['template']; if (isset($data_templates[$name]) && IO_FS::exists($data_templates[$name])) { return $data_templates[$name]; } } $type = isset($data['type']) ? $data['type'] : 'input'; $key = $type . '_' . $name; if (isset($template[$key])) { return $template[$key]; } /*if ($name == 'template' && isset($data['template name'])) $name = $data['template name'];*/ $file = $this->dir() . "/{$name}.phtml"; if (IO_FS::exists($file)) { return $template[$key] = $file; } $types = array($type); $parents = Core_Types::class_hierarchy_for($this); if (count($parents) >= 3) { foreach (array_slice($parents, 1, count($parents) - 2) as $p) { $type = CMS_Fields::type_by_class($p); if (empty($type)) { $type = CMS_Fields::type_by_class(Core_Types::module_name_for($p)); } $types[] = $type; } } foreach ($types as $t) { if (empty($t)) { continue; } $view = Templates_HTML::Template('fields/' . $t . '/' . $name); if ($view->exists()) { return $template[$key] = $view->path; } } $view = Templates_HTML::Template('fields/' . $name); if ($view->exists()) { return $template[$key] = $view->path; } return $template[$key] = $name; }
protected function process_inserted_item($item) { $rc = false; foreach ($this->filtered_form_fields as $name => $data) { $type = CMS_Fields::type($data); $r = $type->process_inserted($name, $data, $item); if ($r) { $rc = true; } } return $rc; }
public function serialized() { $out = array(); foreach ($this->fields() as $name => $data) { $type = CMS_Fields::type($data); $out += $type->serialized($name, $data); } return $out; }
protected function serialized() { $out = array(); foreach ($this->all_fields() as $name => $data) { $type = CMS_Fields::type($data); $out = array_merge($out, $type->serialized($name, $data)); } return $out; }
public function get_formats($name, $data) { $key = md5(serialize($name) . serialize(isset($data['formats']) ? $data['formats'] : null)); if (isset($this->formats_cache[$key])) { return $this->formats_cache[$name]; } $formats = isset($data['formats']) ? $data['formats'] : $this->default_formats($name, $data); $formats = array_merge($formats, isset($data['extra_formats']) ? $data['extra_formats'] : array()); foreach ($formats as $code => $format) { $fdata = $formats[$code]['__data'] = CMS_Fields::validate_parms(isset($format['widget']) ? $format['widget'] : 'textarea'); $formats[$code]['__data']['tagparms'] = array_merge(isset($formats[$code]['__data']['tagparms']) && is_array($formats[$code]['__data']['tagparms']) ? $formats[$code]['__data']['tagparms'] : array(), $this->tagparms($name, $data)); if ($code == 'html' && method_exists(CMS::$current_controller, 'field_action_url') && isset($data['__item'])) { $formats[$code]['__data']['imagelist'] = CMS::$current_controller->field_action_url($name, 'imagelist', $data['__item']); } $fname = $formats[$code]['__name'] = $this->get_format_name($name, $code); $ftype = $formats[$code]['__type'] = CMS_Fields::type($fdata); if ($langs = $this->data_langs($data)) { foreach ($langs as $lang => $ldata) { $formats[$code]['__langs_name'][$lang] = $this->name_lang($fname, $lang); } } } return $this->formats_cache[$name] = $formats; }
static function run() { CMS_Fields::process_schema('tao_cli_calls', self::fields()); }
protected function form_field_exists($name, $parms, $action) { $res = parent::form_field_exists($name, $parms, $action); if (!$res) { return false; } $tabs = $this->get_form_tabs($action); if (!empty($tabs) && !isset($tabs[$parms['tab']])) { return false; } $type = CMS_Fields::type($parms); if ($type && !$type->access($name, $parms, 'render_in_layout')) { return false; } return true; }
public function process_inserted($name, $data, $item) { if (isset($data['fields'])) { foreach ($data['fields'] as $field => $fdata) { $fdata = array_merge($data, $fdata); $type = CMS_Fields::type($fdata); $type->process_inserted($field, $fdata, $item); } } return parent::process_inserted($name, $data, $item); }