Exemple #1
0
 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 '';
 }
Exemple #2
0
 protected function struct()
 {
     if (is_callable(CMS::$navigation_struct)) {
         return call_user_func(CMS::$navigation_struct);
     }
     if (is_string(self::$var)) {
         return CMS::vars()->get(self::$var);
     }
     return array();
 }
Exemple #3
0
 public function setup()
 {
     if (CMS::vars()->storage_type() == 'orm') {
         $this->orm_name = 'vars';
     }
     if (CMS::vars()->storage_type() == 'storage') {
         $this->storage_name = 'vars';
     }
     return parent::setup();
 }
Exemple #4
0
 protected function get_var_value($name)
 {
     $site = false;
     if ($m = Core_Regexps::match_with_results('{^(.+)/([^/]+)$}', $name)) {
         $name = trim($m[1]);
         $site = trim($m[2]);
         if ($site == '*') {
             $site = CMS_Admin::site();
         }
     }
     return CMS::vars()->get($name, $site);
 }
Exemple #5
0
 static function run()
 {
     if (!CMS::vars()->exists('admin')) {
         CMS::vars()->storage()->create_dir('admin', array('_title' => 'Настройки системы администрирования', '_access' => 'full'));
     }
     if (!CMS::vars()->exists('admin.title')) {
         $var = CMS::vars()->entity('string');
         $var['_name'] = 'admin.title';
         $var['_access'] = 'full';
         $var['_title'] = 'Заголовок';
         $var['value'] = 'Система управления сайтом';
         CMS::vars()->storage()->save($var);
     }
     if (!CMS::vars()->exists('admin.navigation')) {
         $var = CMS::vars()->entity('array');
         $var['_name'] = 'admin.navigation';
         $var['_access'] = 'full';
         $var['_title'] = 'Структура навигации';
         $var['array'] = array('Настройки' => '/admin/vars/');
         $var['array_src'] = "Настройки = /admin/vars/";
         CMS::vars()->storage()->save($var);
     }
     if (!CMS::vars()->exists('navigation')) {
         $var = CMS::vars()->entity('array');
         $var['_name'] = 'navigation';
         $var['_access'] = 'full';
         $var['_title'] = 'Структура навигации';
         $var['array'] = array();
         $var['array_src'] = '';
         CMS::vars()->storage()->save($var);
     }
     if (!CMS::vars()->exists('head')) {
         $var = CMS::vars()->entity('array');
         $var['_name'] = 'head';
         $var['_access'] = '';
         $var['_title'] = 'Мета-теги по умолчанию';
         $var['array'] = array();
         $var['array_src'] = '';
         CMS::vars()->storage()->save($var);
     }
 }
Exemple #6
0
 public function change($parms)
 {
     $id = (int) $parms['id'];
     $item = CMS::vars()->db()->find($id);
     $rc = CMS::vars()->type($item->vartype)->change($id, $this->request, $item);
     Events::call('admin.change', $item);
     if (is_string($rc)) {
         $component = $parms['component'];
         $this->component = $component;
         return $this->render('index', array('title' => $this->get_title($item), 'id' => $id, 'error' => $rc, 'item' => $item, '_change' => $this->make_uri('change', $id), '_addfile' => $this->make_uri('addfile', $id), '_up' => $this->make_uri('dir', $item->parent_id)));
     } else {
         return $this->redirect_to($this->make_uri('dir', $item->parent_id));
     }
 }
Exemple #7
0
 public function get_var_description()
 {
     return Core::make('Text.Process')->process(CMS::vars()->type($this->vartype)->list_value($this), 'plaintext');
 }
Exemple #8
0
 public function change($id, $data, $item)
 {
     if (is_object($item)) {
         $item->id = $id;
     }
     $file = $_FILES['value'];
     $name = trim($file['name']);
     $tmp_name = trim($file['tmp_name']);
     if ($tmp_name != '') {
         $dir = "./" . Core::option('files_name') . "/vars/{$id}";
         CMS::mkdirs($dir, 0775);
         foreach (IO_FS::Dir($dir) as $f) {
             @IO_FS::rm($f->path);
         }
         $name = CMS::translit(mb_strtolower($name));
         $name = preg_replace('{\\s+}', '_', $name);
         $name = trim(preg_replace('{[^a-z0-9_\\.\\-]}', '', $name));
         if ($name == '') {
             $name = 'noname';
         }
         if ($name[0] == '.') {
             $name = "noname.{$name}";
         }
         move_uploaded_file($tmp_name, "{$dir}/{$name}");
         chmod("{$dir}/{$name}", 0775);
         $rc = CMS::vars()->on_change_call($id, $value, $data);
         if (is_string($rc)) {
             $item->valuesrc = $data['valuesrc'];
             return $rc;
         }
         $item->value = "{$dir}/{$name}";
         $item->update_value();
     }
 }
Exemple #9
0
 static function MAPS($parms = false)
 {
     if (!CMS::layout_view()) {
         return '';
     }
     Core::load('Templates.HTML.Helpers.Maps');
     $parms = explode(';', $parms);
     $type = trim($parms[0]);
     $map_id = trim($parms[1]);
     $name = trim($parms[2]);
     $options = CMS::vars()->get($name);
     return CMS::layout_view()->maps->map($type, $map_id, $name, $options);
 }
Exemple #10
0
 public function info()
 {
     $info = $this->attributes;
     $info['_type'] = $this->_type;
     $info['_name'] = $this->_name;
     foreach (CMS::vars()->config_fields() as $field => $data) {
         $info[$field] = $this->{$field};
     }
     return $info;
 }
Exemple #11
0
 protected function branch($dir_path, $prefix = '')
 {
     $vars = array();
     $dirs = array();
     foreach (IO_FS::Dir($dir_path) as $entry) {
         $filename = $entry->name;
         if (Core_Regexps::match('{^[a-z0-9_-]+$}i', $filename)) {
             $path = $entry->path;
             $name = $prefix . $filename;
             if (is_dir($path)) {
                 if (IO_FS::exists("{$path}/.info")) {
                     $info = $this->load_info("{$path}/.info");
                     if ($info) {
                         $var = CMS::vars()->entity('dir', $info);
                         $var->vars = $this->branch($path, "{$name}.");
                         $dirs[$name] = $var;
                     }
                 }
             } else {
                 $var = $this->load($name);
                 if ($var) {
                     $vars[$name] = $var;
                 }
             }
         }
     }
     ksort($vars);
     ksort($dirs);
     $out = array();
     $out += $vars;
     $out += $dirs;
     return $out;
 }
Exemple #12
0
 protected function form_fields($action)
 {
     $fields = array();
     if ($action == 'list') {
     } elseif ($action == 'add') {
         $fields = array();
         if ($this->is_admin()) {
             $fields['_name'] = array('type' => 'input', 'style' => 'width: 200px;', 'tab' => 'config', 'caption' => CMS::lang('%LANG{en}Name%LANG{ru}Мнемокод'));
             if (isset($_GET['chapter'])) {
                 $pchapter = trim($_GET['chapter']);
                 if ($pchapter != '') {
                     $pchapter .= '.';
                 }
                 $fields['_name']['obligatory_prefix'] = $pchapter;
                 $fields['_type'] = array('type' => 'select', 'items' => CMS::vars()->types_list(), 'caption' => CMS::lang('%LANG{en}Type%LANG{ru}Тип'), 'tab' => 'config');
             }
         }
     } else {
         $var = $this->edit_item;
         if (!$var->is_dir()) {
             $fields = array('vname' => array('type' => 'subheader', 'tab' => 'default', 'caption' => $var->id() . ': ' . $var->title()));
             $fields += $var->fields($var);
         }
     }
     if ($this->is_admin()) {
         $fields['_title'] = array('type' => 'input', 'style' => 'width: 100%;', 'tab' => 'config', 'caption' => CMS::lang('%LANG{en}Title%LANG{ru}Название'));
         $fields['_access'] = array('type' => 'input', 'style' => 'width: 200px;', 'tab' => 'config', 'caption' => CMS::lang('%LANG{en}Access%LANG{ru}Доступ'));
         $fields['_delsubheader'] = array('type' => 'subheader', 'style' => 'width: 200px;', 'tab' => 'config', 'caption' => CMS::lang(' '));
         static $ev = false;
         if (!$ev) {
             Events::add_listener('cms.fields.admin.mainform._delsubheader.after', function ($parms) {
                 $var = $parms['item'];
                 $url = WS::env()->urls->adminvars->delete_url($var->name());
                 if ($url == '#') {
                     return;
                 }
                 $title = 'Удалить';
                 $confirm = 'Вы уверены?';
                 print "<a href='{$url}' onClick='return confirm(\"{$confirm}\")' class='icon-button'><em style='background-image: url(/tao/images/del.png);'>{$title}</em></a>";
             });
             $ev = true;
         }
     }
     return $fields;
 }
Exemple #13
0
 /**
  * @param WebKit_Environment   $env
  * @param WebKit_HTTP_Response $response
  *
  * @return Iterator
  */
 public function process_app(WS_Environment $env, $response)
 {
     $uri = $env->request->urn;
     $original_uri = $uri;
     CMS::$original_uri = $uri;
     CMS::$site = CMS::$defsite;
     if (isset(CMS::$sites[CMS::$defsite]['page_main'])) {
         CMS::$page_main = CMS::$sites[CMS::$defsite]['page_main'];
     }
     $_defdata = false;
     if (isset(CMS::$sites[CMS::$defsite])) {
         $_defdata = CMS::$sites[CMS::$defsite];
     }
     if (isset(CMS::$sites)) {
         foreach (CMS::$sites as $site => $data) {
             $_host = isset($data['host']) ? trim($data['host']) : '';
             $_prefix = isset($data['prefix']) ? trim($data['prefix']) : '';
             if ($_host != '' || $_prefix != '') {
                 $_bhost = false;
                 $_bprefix = false;
                 $_uri = $uri;
                 if ($_prefix != '') {
                     if ($m = Core_Regexps::match_with_results('{^/' . $_prefix . '/(.*)$}', $uri)) {
                         $_uri = '/' . $m[1];
                         $_bprefix = true;
                     } else {
                         continue;
                     }
                 }
                 if ($_host != '') {
                     if ($env->request->host == $_host) {
                         $_bhost = true;
                     } else {
                         if ($_host[0] == '{') {
                             if (Core_Regexps::match($_host, $env->request->host)) {
                                 $_bhost = true;
                             } else {
                                 continue;
                             }
                         } else {
                             continue;
                         }
                     }
                 }
                 if ($_bprefix || $_bhost) {
                     CMS::$site = $site;
                     if ($_bprefix) {
                         CMS::$site_prefix = '/' . $_prefix;
                     }
                     $uri = $_uri;
                     $env->request->uri($uri);
                     $_defdata = $data;
                     break;
                 }
             }
         }
     }
     if ($_defdata) {
         if (isset($_defdata['page_main'])) {
             CMS::$page_main = $_defdata['page_main'];
         }
         if (isset($_defdata['page_404'])) {
             CMS::$page_404 = $_defdata['page_404'];
         }
         if (isset($_defdata['layout'])) {
             CMS::$force_layout = $_defdata['layout'];
         }
     }
     if (CMS::$db) {
         $head = CMS::vars()->get('head');
         if (isset($head['meta.title'])) {
             $env->meta->title($head['meta.title']);
         }
         if (isset($head['meta.description'])) {
             $env->meta->description($head['meta.description']);
         }
         if (isset($head['meta.keywords'])) {
             $env->meta->keywords($head['meta.keywords']);
         }
     }
     $curi = $uri;
     if ($m = Core_Regexps::match_with_results('/^([^\\?]+)\\?/', $curi)) {
         $curi = $m[1];
     }
     $use_layout = false;
     // Просмотр всех мапперов зарегистрированных в системе
     foreach (CMS::mappers() as $name => $mapper) {
         // Если срабатывает маппер
         if ($route = $mapper->route($env->request)) {
             CMS::$current_mapper = $mapper;
             CMS::$current_component_name = $name;
             CMS::$current_route = $route;
             try {
                 Core::load('Component.' . $name);
             } catch (Core_ModuleNotFoundException $e) {
                 // hush
             }
             if ($route instanceof Net_HTTP_Response) {
                 return $route;
             }
             // Имя подключаемого модуля
             $controller_module_name = 'Component.' . $name . '.Controller';
             // Имя контроллера по умолчанию
             $controller_name = Core_Strings::replace($controller_module_name, '.', '_');
             // Имя действитя по умолчанию
             $action_name = 'index';
             $do_load_controllers = true;
             if ($route === true) {
                 $route = array('controller' => $controller_name, 'action' => 'index');
             }
             if (is_array($route)) {
                 $_route = WebKit_Controller::Route();
                 $_route->merge($route);
                 $route = $_route;
             }
             if (!isset($route['action'])) {
                 $route['action'] = 'index';
             }
             // Если маппер вернул нестандартное имя контроллера
             if (isset($route['controller'])) {
                 $controller_name = $route['controller'];
             }
             // Если маппер вернул нестандартное имя действия
             if (isset($route['action'])) {
                 $action_name = $route['action'];
             }
             // Если маппер не велел загружать модуль с конроллером (загрузит сам)
             if (isset($route['no_load'])) {
                 $do_load_controllers = false;
             }
             // Загружаем модуль с контроллером
             if ($do_load_controllers) {
                 if (strpos($controller_name, '.') === false && strpos($controller_name, '_') === false) {
                     $controller_name = 'Component.' . $name . '.' . $controller_name;
                 }
                 if (strpos($controller_name, '.') !== false) {
                     $controller_module_name = $controller_name;
                 }
                 Core::autoload($controller_module_name);
             }
             // Получаем экземпляр контроллера
             CMS::$current_controller_name = $controller_name;
             //$controller = Core_Types::reflection_for($controller_name)->newInstance($env, $response);
             $controller = Core::make($controller_name, $env, $response);
             if ($use_layout) {
                 if (!property_exists($controller, 'layout')) {
                     $controller->use_layout($use_layout);
                 } else {
                     if (!$controller->layout) {
                         $controller->use_layout($use_layout);
                     }
                 }
             }
             if (!CMS::$print_version && is_string(CMS::$force_layout)) {
                 $controller->use_layout(CMS::$force_layout);
             }
             CMS::$current_controller = $controller;
             CMS::$current_route = $route;
             // Запускаем контроллер с переданными аргументами
             $rc = $controller->dispatch($route);
             return $rc;
         }
     }
     if (md5($uri) == 'b0b94791138ef54aeb161e403329f827') {
         die('cms');
     }
     return Net_HTTP::not_found();
 }
Exemple #14
0
 public function action_chparms()
 {
     $id = (int) $this->args[0];
     $item = CMS::vars()->db()->find($id);
     $item->chparms($this->request);
     //CMS_Var::chparms($id,$this->request);
     $uri = $this->make_uri('dir', $item->parent_id);
     Events::call('admin.change', $item);
     return $this->redirect_to($uri);
 }