protected function map_select_component($component) { if (is_null($component)) { $component = WS::env()->adminvars->component; } return $this->where("component = :component", (string) $component)->order_by('parent_id,ord'); }
protected function load() { if (!class_exists('lessc')) { $path = !empty(WS::env()->config->less->lessphp_dir) ? WS::env()->config->less->lessphp_dir : Templates_HTML_Preprocess::option('less_php_dir'); include_once $path . '/lessc.inc.php'; } }
public function __construct(DB_ORM_Mapper $parent = null) { parent::__construct($parent); CMS_ORM_Entity::$db = $this; CMS_Controller_Base::$db = $this; $this->cache = WS::env()->cache; }
public function setup() { if (CMS::vars()->storage_type() == 'orm') { $this->orm_name = 'vars'; } if (CMS::vars()->storage_type() == 'storage') { $this->storage_name = 'vars'; } $this->merge_options(); Templates_HTML::add_scripts_settings(array('adminvars' => $this->js_config)); $this->auth_realm = CMS::$admin_realm; if (isset(CMS::$cfg->vars->use_tinymce)) { $s = trim(CMS::$cfg->vars->use_tinymce); if ($s == '' || $s == '0') { $this->use_tinymce = false; } } $this->use_views_from(CMS::views_path('admin/vars'))->use_views_from(CMS::views_path('admin/vars2')); if (CMS::vars()->storage_type() == 'orm') { $types = WS::env()->orm->vars->types(); $this->form_fields = $types->fields; $types->end(); } if (CMS::vars()->storage_type() == 'storage') { $this->form_fields = $this->storage()->make_entity()->fields(); // var_dump($this->form_fields); } $this->component = WS::env()->adminvars->component; //TODO: configure fields if (empty($this->tree_fields)) { $this->tree_fields = array('title' => array('caption' => 'Комментарий', 'flex' => 1), 'var_description' => array('caption' => 'Тип', 'flex' => 1), 'full_code' => array('caption' => 'Идентификатор', 'width' => 200)); } return parent::setup(); }
public function select_component($component) { if (is_null($component)) { $component = WS::env()->adminvars->component; } $this->current_query->eq("component", (string) $component)->order_by('parent_id')->order_by('ord'); return $this; }
public function make_url() { $args = func_get_args(); $path = CMS::admin_path() . self::$prefix . '/' . ($args[0] == 'dir' ? $args[1] : implode('/', $args)); $component = WS::env()->vars->component; $url = $path . ($component ? '?component=' . $component : ''); return $url; }
public static function db() { switch (self::$type) { case 'orm': return WS::env()->orm->vars; case 'storage': return Storage::manager()->vars; } }
public function action_prefix($name, $data, $item = false, $fields = array()) { $id = (int) WS::env()->request['id']; $item = CMS::vars()->db()->find($id); if ($item) { return $item->full_code . '.'; } return ''; }
public function __construct($name) { $this->name = $name; $this->cache = WS::env()->cache; $this->setup(); if ($this->autodump_assets()) { $this->assets_dump_all(); } //TODO: config source (file, cache, vars ...) }
static function start() { if (self::$clear_on_start && self::check_filters()) { $fh = fopen(self::$log_file, 'w'); fwrite($fh, "*** http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "\n"); fwrite($fh, "*** " . date("Y.m.d - G:i") . "\n\n"); fclose($fh); } WS::env()->db->default->listener(new CMS_DBLogger()); }
protected function get_filename() { $file = $this->request('file'); if (empty($file)) { $fdata = json_decode(WS::env()->request->content, true); if (!empty($fdata['name'])) { $file = $fdata['name']; } } return $file; }
public function setup() { $this->orm_module = $this->getp('orm_module'); $this->admin_module = $this->getp('admin_module'); $this->schema_module = $this->getp('schema_module'); $this->orm_fields = $this->getp('orm_fields'); $this->admin_fields = $this->getp('admin_fields'); $this->component = $this->getp('component'); $this->component_module = "Component.{$this->component}"; $this->admin_tabs = (bool) $this->getp('admin_tabs', 0); $this->item_name = "{$this->orm_module}.Item"; $this->urls = WS::env()->urls->cmscomponentfactory; $this->auth_realm = CMS::$admin_realm; return parent::setup()->use_views_from(CMS::views_path('admin/factory'))->render_defaults('tables', 'urls', 'table', 'fields', 'key_field'); }
protected function load() { if ($this->loaded) { return true; } $this->loaded = true; if (!class_exists('scssc')) { $path = !empty(WS::env()->config->scss->scss_dir) ? WS::env()->config->less->lessphp_dir : self::option('scss_php_dir'); @(include_once $path . '/scss.inc.php'); } if (class_exists('scssc')) { $this->setup(); return true; } return false; }
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; }
public function sql_query() { $query = reset($this->args); if (!$query) { return; } $dsn = WS::env()->db->default->dsn; $cmd = $this->sql_command($dsn); switch ($dsn->type) { case "mysql": $cmd .= " -e \"{$query}\""; break; case "pgsql": $cmd .= " -c \"{$query}\""; break; } $rc = !(bool) $this->popen($cmd); return $rc; }
protected function load_helperes_from_cache($helpers) { if (!CMS::is_lazy_components()) { return; } if ($this->is_cache_loaded) { return; } $this->is_cache_loaded = true; if ($classes = WS::env()->cache->get('cms:viwes:helpers_classes')) { foreach ($classes as $name => $class) { $helpers->append($class, $name); } } else { Events::add_once('cms.load_components', function () use($helpers) { WS::env()->cache->set('cms:viwes:helpers_classes', $helpers->classes, 0); }); CMS::load_components(); } }
protected function action_update($name, $data, $action, $item = false, $fields = array()) { $fdatas = json_decode(WS::env()->request->content, true); $single = isset($fdatas['name']); $fdatas = $single ? array($fdatas) : $fdatas; $files = $single ? $this->files_data($name, $data, $item) : array('files'); foreach ($fdatas as $fk => $fdata) { if (isset($fdata['date'])) { $fdata['date'] = date('d.m.Y', strtotime($fdata['date'])); } if ($single) { foreach ($files['files'] as $k => $f) { if ($f['name'] == $fdata['name']) { $files['files'][$k] = $fdata; } } } else { $files['files'][$fk] = $fdata; } } Events::call('admin.change'); $this->update_files_data($files, $name, $data, $item); return json_encode(array('success' => true, 'items' => $fdatas)); }
public function cloud($table, $name, $parms = array()) { if (isset($parms['cache'])) { $tags = WS::env()->cache->get($parms['cache']); if (is_array($tags)) { return $tags; } } $table_tags = self::table_tags($table, $name); $table_rels = self::table_rels($table, $name); $tags = array(); $cursor = CMS::orm()->connection->prepare("SELECT tags.id id,tags.title title, count(rels.item_id) cnt FROM {$table_rels} rels LEFT JOIN {$table_tags} tags ON tags.id=rels.tag_id GROUP BY tags.id, tags.title ORDER BY tags.title")->execute(); foreach ($cursor as $row) { $url = false; if (isset($parms['urls'])) { $url = call_user_func($parms['urls'], $row['id']); } $tags[$row['id']] = array('id' => $row['id'], 'title' => $row['title'], 'count' => $row['cnt'], 'url' => $url); } if (isset($parms['cache'])) { WS::env()->cache->set($parms['cache'], $tags); } return $tags; }
public function action_delete($name, $data, $action, $item = false, $fields = array()) { if (!$item) { return json_encode(array('success' => true)); } $r = WS::env()->request; $iname = $r['item_name']; $data['__item'] = $item; $e = $this->get_assoc_mapper($name, $data)->make_entity(); $e['id'] = $r['item_id']; $e[$data['assoc']['value_column']] = $r['item_data']; $e[$data['assoc']['key_column']] = $item->id(); $e->delete(); return json_encode(array()); }
public function cache($backend = null) { if (!is_null($backend)) { $this->cache = $backend; } if (is_null($this->cache)) { $this->cache = clone WS::env()->cache; } return $this->cache; }
/** * Запускает приложение * * @param WS_ServiceInterface $app * * @return WS_Runner */ public function run(WS_ServiceInterface $app) { $environment = WS::env(); $environment->request = $this->adapter->make_request(); $rc = Events::call('ws.run'); if (!is_null($rc)) { return $rc; } $environment->response = Net_HTTP::Response(); $body = $app->run($environment); $response = Net_HTTP::merge_response($body, $environment->response); return $this->adapter->process_response($response); }
public function flush_caches() { WS::env()->cache->flush(); return $this->redirect_to(CMS::admin_path()); }
/** * Возвращает пулл соединений с БД * * @todo сделать что-нибудь с WS * * @return array; */ public static function connections_pool() { return WS::env()->pdo_connections ? WS::env()->pdo_connections : array(); }
protected function fallback($name, $parms, $args) { $name = trim($name, '/'); $this->views_paths[] = ''; $template = $this->search_fallback_template($name); if ($template) { $args = array('env' => WS::env(), 'request' => WS::env()->request, 'args' => $parms, 'args_array' => $args, 'insertion_name' => $name); Events::call("cms.insertions.template.{$name}", $template, $args); if (isset($this->args['layout'])) { return $this->args['layout']->root->partial($template, $args); } return Templates::HTML($template)->with($args)->render(); } return null; }
public function request($index = null) { return is_null($index) ? WS::env()->request : WS::env()->request[(string) $index]; }
public static function clear_invoke_cache() { return WS::env()->cache->delete("cached_invoke"); }
public function cache() { return WS::env()->cache; }
public function __wakeup() { if (isset($this->attrs['__mapper_name'])) { $name = $this->attrs['__mapper_name']; $this->set_mapper(WS::env()->orm->{$name}); } // $this->after_find(); }
protected function tree_json() { $res = Net_HTTP::Response()->content_type('application/json'); $root = WS::env()->request['node']; // $this->page = (int) isset($this->request['page']) ? $this->request['page'] : 1; $data = $this->tree_data($root, json_decode(WS::env()->request['sort'], true)); $result = array('total' => $this->get_tree_count($root), 'children' => $data, 'success' => true); return $res->body(json_encode($result)); }
public function setup() { parent::setup(); $this->_created = 0; $this->_created_time = date('Y-m-d H:m:s'); $this->isactive = 0; $this->user_id = (int) WS::env()->auth->user->id; return $this; }