Exemple #1
0
 /**
  * Выполняет обработку запроса
  *
  * @param WS_Environment $env
  *
  * @return mixed
  */
 public function run(WS_Environment $env)
 {
     $config = Config::all();
     $env->assign_if(array('config' => $config));
     Events::call('ws.config', $config);
     return $this->application->run($env);
 }
Exemple #2
0
 protected function auth_realm()
 {
     $realm = false;
     if (Core_Regexps::match('{^/admin/}', $_SERVER['REQUEST_URI'])) {
         $realm = 'admin';
     }
     /**
      * @event cms.fspages.realm
      * @arg $realm имя области
      * Отдельные статические страницы (CMS.FSPages) могут исполняться в рамках обособленной (чаще всего - закрытой паролем) области.
      * По умолчанию страницы, чьи адреса начинаются с '''/admin/''' исполняются в области '''admin''', остальные - без указания области (в области по умолчанию).
      * Однако, это можно исправить в обработчике данного события. Проверьте REQUEST_URI и установите нужный realm.
      */
     Events::call('cms.fspages.realm', $realm);
     return $realm;
 }
Exemple #3
0
 public function route($request)
 {
     $uri = trim(strtolower($this->clean_url($request->uri)));
     if (CMS_FSPages::$with_htm_extension) {
         $uri = preg_replace('{\\.htm$}', '/', $uri);
     }
     $path = '';
     if ($uri == '/') {
         $path = '/';
     } elseif ($m = Core_Regexps::match_with_results('{^/(.+)/$}', $uri)) {
         foreach (explode('/', $m[1]) as $chunk) {
             if (Core_Regexps::match('{[a-z0-9_-]+}', $chunk)) {
                 $path .= "/{$chunk}";
             }
         }
     }
     if ($path != '') {
         $dirs = array(CMS::$taopath . '/views/pages', CMS::app_path('views/pages'));
         /**
          * @event cms.fspages.dirs
          * @arg $dirs Список каталогов
          * Событие генерируется механизмом статических страниц (CMS.FSPages) для уточнения списка каталогов, в которых ищутся шаблоны. При необходимости в список можно добавить свой каталог.
          */
         Events::call('cms.fspages.dirs', $dirs);
         if (count($dirs) > 0) {
             for ($i = count($dirs) - 1; $i >= 0; $i--) {
                 $dir = $dirs[$i];
                 $page = false;
                 $page_path = "{$dir}{$path}/index.phtml";
                 if (IO_FS::exists($page_path)) {
                     $page = $page_path;
                 } else {
                     $page_path = "{$dir}/{$path}.phtml";
                     if (IO_FS::exists($page_path)) {
                         $page = $page_path;
                     }
                 }
                 if ($page) {
                     return array('controller' => 'CMS.Controller.FSPages', 'action' => 'index', $page);
                 }
             }
         }
     }
     return false;
 }
Exemple #4
0
 public function read_item($title, $item)
 {
     $title = CMS::lang($title);
     if (is_string($item)) {
         $item = array('url' => trim($item));
     }
     if (isset($item['title'])) {
         $title = trim($item['title']);
     }
     if (isset($item['navigation_id'])) {
         $item['id'] = trim($item['navigation_id']);
     }
     $url = $item['url'];
     $url1 = $item['url'];
     Events::call('cms.navigation.add', $title, $item, $url);
     if ($url1 != $url) {
         $item['url'] = $url;
     }
     return parent::read_item($title, $item);
 }
Exemple #5
0
 protected function auth()
 {
     $enable = Core::if_null(Config::all()->apache_auth->enable, false);
     $enable_admin = Core::if_null(Config::all()->apache_auth->enable_admin, false);
     if (!$enable) {
         return true;
     }
     if (!empty(WS::env()->auth->user)) {
         return true;
     }
     $user = null;
     $login = $this->request->server('PHP_AUTH_USER');
     if (!$login) {
         $login = $this->request->server('REMOTE_USER');
     }
     if ($login) {
         $user = $this->auth_module->authenticate($login, null);
         if (!$user->isactive) {
             return false;
         }
     }
     if (!$user && !Core::is_cli()) {
         return false;
     } else {
         Events::call('ws.auth.apache.user', $user);
         WS::env()->auth->user = $user;
         WS::env()->auth->module = $this->auth_module;
         if ($enable_admin) {
             $admin_user = clone $user;
             $admin_user->password = $this->request->server('PHP_AUTH_PW');
             WS::env()->admin_auth->user = $admin_user;
         }
         $this->reset_default_auth();
         return true;
     }
 }
Exemple #6
0
function receive($name = '')
{
    return Events::call($name);
}
Exemple #7
0
 public function action_save($name, $data, $action, $item = false, $fields = array())
 {
     $files = json_decode($this->files_from_request(), true);
     if (!empty($files)) {
         $this->update_files_data($files, $name, $data, $item);
     }
     Events::call('admin.change');
     return 'ok';
 }
Exemple #8
0
 public function postprocess(&$path, &$content)
 {
     Events::call('templates.join_file', $path, $content);
     foreach ($this->postprocessors as $p) {
         $p->postprocess($path, $content);
     }
     return $this;
 }
Exemple #9
0
 /**
  * Инвалидирует кэш
  *
  */
 public function flush()
 {
     Events::call('cache.flush');
     Events::call('cache.delete', $s = '*');
     return $this->memcache->flush();
 }
Exemple #10
0
 /**
  * Инвалидирует кэш
  *
  */
 public function flush()
 {
     Events::call('cache.flush');
     Events::call('cache.delete', $s = '*');
     $rc = apcu_clear_cache('user');
     $rc = apcu_clear_cache('opcode') && $rc;
     return $rc;
 }
function recieve($area = '')
{
    return Events::call($area);
}
Exemple #12
0
 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;
 }
Exemple #13
0
 /**
  * @param        $entity
  * @param string $name
  *
  * @return mixed
  */
 protected function callback($entity, $name)
 {
     $result = true;
     $rc = Events::call("orm.mapper.callback.{$this->__name()}.{$name}", $this, $entity);
     if (!is_null($rc)) {
         $result = $rc;
     }
     $rc = Events::call("orm.mapper.callback.{$name}", $this, $entity);
     if (!is_null($rc)) {
         $result = $rc && $result;
     }
     return is_object($entity) && method_exists($entity, $name) ? $entity->{$name}($result) && $result : $result;
 }
Exemple #14
0
 public function action_left($name, $data, $action, $item = false, $fields = array())
 {
     $filename = $this->dir_path($item, false, $name, $data) . '/' . $this->request('filename');
     $file = IO_FS::File($filename);
     if (!$file->exists()) {
         Net_HTTP::not_found();
     }
     Core::load('CMS.Images');
     $method = 'turn_' . $action;
     CMS_Images::Image($file->path)->{$method}()->save($file->path);
     $file->set_permission();
     Events::call('admin.change');
     return 'ok';
 }
Exemple #15
0
 protected function action_install()
 {
     $item = $this->load_item($this->id);
     if (!$item) {
         return $this->page_not_found();
     }
     $error = false;
     foreach ($item->not_install_if_exists as $entry) {
         $entry = $this->validate_path($entry);
         if ($entry) {
             if (IO_FS::exists($entry)) {
                 $error = "<b>Файл (каталог) {$entry}</b> уже существует. Установка невозможна!";
             }
         }
     }
     if ($item['download'] == '-') {
         $error = 'Невозможно получить инсталляционный пакет!';
     }
     if ($this->env->request->method == 'post') {
         $files = $this->get_install_pack($item);
         if (is_string($files)) {
             $error = $files;
         } else {
             foreach ($files as $file => $data) {
                 $from = $data['path'];
                 $to = "../{$file}";
                 if ($m = Core_Regexps::match_with_results('{^(.+)/[^/]+$}', $to)) {
                     $dir = $m[1];
                     if (!IO_FS::exists($dir)) {
                         @CMS::mkdirs($dir);
                         if (!IO_FS::exists($dir)) {
                             $error = "Невозможно создать каталог {$dir}";
                             break;
                         }
                     }
                     copy($from, $to);
                     CMS::chmod_file($to);
                     $item->set_installed_hash($file, $data['hash']);
                 }
             }
             $item->save_info_file();
             CMS::rmdir($item->install_temp_dir());
             return $this->redirect_to($this->action_url('instok', $item));
         }
     }
     Events::call('cms.stockroom.after_install', $item, $error);
     return $this->render('install', array('item' => $item, 'error' => $error, 'list_url' => $this->action_url('list', $this->page), 'list_button_caption' => $this->button_list()));
 }
Exemple #16
0
 protected function action_delete($name, $data, $action, $item = false, $fields = array())
 {
     $res = parent::action_delete($name, $data, $action, $item, $fields);
     Events::call('admin.change');
     if ($res == 'ok') {
         return json_encode(array('success' => true));
     }
 }
Exemple #17
0
 /**
  * @param WS_Environment $env
  *
  * @return Net_HTTP_Response
  */
 public function run(WS_Environment $env)
 {
     //if ($this->disabled) return $this->application->run($env);
     $error = null;
     try {
         $body = $this->application->run($env);
         $response = Net_HTTP::merge_response($body, $env->response);
     } catch (Exception $e) {
         $error = $e;
         if ($this->disabled) {
             throw $e;
         }
         $response = Net_HTTP::Response(Net_HTTP::INTERNAL_SERVER_ERROR);
     }
     if (!$response->body && ($template = $this->find_template_name_for($response->status))) {
         if (isset($env->not_found->static_file)) {
             $response->body(IO_FS::File($env->not_found->static_file));
         } else {
             $layout = isset($env->not_found->layout) ? $env->not_found->layout : 'work';
             $view = Templates::HTML($template);
             if ($layout) {
                 $view->within_layout($layout);
             }
             $view->root->with(array('env' => $env, 'response' => $response, 'error' => $error));
             if ($view->exists()) {
                 $response->body($view);
             } else {
                 if (IO_FS::exists($static_name = $template . '.html')) {
                     $response->body(IO_FS::File($static_name));
                 }
             }
         }
     }
     Events::call('ws.status', $response);
     return $response;
 }
Exemple #18
0
 public function save_var($var)
 {
     $var_name = $var->name();
     /**
      * @event cms.vars.change
      * @alias cms.vars.change.{$var_name}
      * @arg $var объект перед сохранением
      * Вызывается непосредственно перед сохранением отдельной настройки (CMS.Vars).
      * Возможно обработать данные прежде чем они будут сохранены, сбросить кеш, сгенерировать еще что-то и т.п.
      * Для обработки данных какой-то конкретной настройки вешайте обработчик на событие вида '''cms.vars.change.{$var_name}'''.
      */
     Events::call("cms.vars.change", $var);
     Events::call("cms.vars.change.{$var_name}", $var);
     return $this->storage()->save($var);
 }
Exemple #19
0
 protected function action_addgallery($id)
 {
     $item = $this->load($id);
     if (!$item) {
         return $this->page_not_found();
     }
     $files = $item[$this->gallery_field];
     if (is_string($files)) {
         $files = unserialize($files);
     }
     if (!is_array($files)) {
         $files = array();
     }
     $name = trim($this->request['name']);
     if ($name == '') {
         $name = 'noname';
     }
     $ord = trim($this->request['ord']);
     $alias = trim($this->request['alias']);
     $file = $_FILES['up'];
     $preview = $_FILES['pr'];
     if (trim($file['tmp_name']) != '') {
         $inc = $item[$this->gallery_field . '_autoinc'] + 1;
         $item[$this->gallery_field . '_autoinc'] = $inc;
         $dir = "/{$this->gallery_dir}/" . $this->iddir($id);
         $this->mkdirs(".{$dir}", 0775);
         $file_name = $file['name'];
         $ext = '';
         if ($m = Core_Regexps::match_with_results('/\\.([a-z0-9_-]+)$/i', $file_name, $m)) {
             $ext = strtolower($m[1]);
         }
         $_ext = $ext == '' ? '' : ".{$ext}";
         $file_name_save = "{$inc}{$_ext}";
         $path_name_save = "{$dir}/{$file_name_save}";
         move_uploaded_file($file['tmp_name'], ".{$path_name_save}");
         $this->chmod_file(".{$path_name_save}");
         $files[$inc]['name'] = $name;
         $files[$inc]['ord'] = $ord;
         $files[$inc]['alias'] = $alias;
         $files[$inc]['file_ext'] = $ext;
         $files[$inc]['file_name_original'] = $file_name;
         $files[$inc]['file_name'] = $file_name_save;
         $files[$inc]['file_path'] = ".{$path_name_save}";
         $files[$inc]['file_uri'] = $path_name_save;
         if (trim($preview['tmp_name']) != '') {
             $file_name = $preview['name'];
             $ext = '';
             if (preg_match('/\\.([a-z0-9_-]+)$/i', $file_name, $m)) {
                 $ext = strtolower($m[1]);
             }
             $_ext = $ext == '' ? '' : ".{$ext}";
             $file_name_save = "p{$inc}{$_ext}";
             $path_name_save = "{$dir}/{$file_name_save}";
             move_uploaded_file($preview['tmp_name'], ".{$path_name_save}");
             $this->chmod_file(".{$path_name_save}");
             $files[$inc]['preview_ext'] = $ext;
             $files[$inc]['preview_name_original'] = $file_name;
             $files[$inc]['preview_name'] = $file_name_save;
             $files[$inc]['preview_path'] = ".{$path_name_save}";
             $files[$inc]['preview_uri'] = $path_name_save;
         }
         $item[$this->gallery_field] = $files;
         $this->update($item);
         Events::call('admin.change', $item);
     }
     return $this->redirect_to($this->admin_url('gallery', $id));
 }
Exemple #20
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 #21
0
 public function add($title, $item)
 {
     if (isset($item['title'])) {
         $title = trim($item['title']);
         $item['title'] = CMS::lang($title);
     }
     $title = CMS::lang($title);
     if (!$this['sub']) {
         $this['sub'] = new ArrayObject();
     }
     if ($item instanceof CMS_Navigation_Node) {
         $this['sub'][$title] = $item;
     } else {
         if (is_string($item)) {
             $item = array('url' => $item);
         }
         $url = $item['url'];
         Events::call('cms.navigation.add', $title, $item, $url);
         $item['url'] = $url;
         if (!isset($item['disabled']) || !$item['disabled'] && CMS::check_no($item['disabled'])) {
             $this['sub'][$title] = new CMS_Navigation_Node($title, $item);
         }
     }
 }
Exemple #22
0
 /**
  * Запускает приложение
  *
  * @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);
 }
Exemple #23
0
 public static function find_all_modules()
 {
     $dir = __DIR__;
     Core::load('IO.FS');
     $q = IO_FS::Query()->glob('*.php')->recursive(true);
     $result = array();
     foreach ($q->apply_to(IO_FS::Dir($dir)) as $name => $file) {
         $real_path = realpath($file);
         $path_to_file = trim(str_replace($dir, '', $name), '/ ');
         $module = str_replace('.php', '', $path_to_file);
         $module = str_replace('/', '.', $module);
         $result[$module] = $real_path;
     }
     Core::load('Events');
     Events::call('core.find_all_modules', $result);
     return $result;
 }
Exemple #24
0
 /**
  * Инвалидирует кэш
  *
  */
 public function flush()
 {
     Events::call('cache.flush');
     Events::call('cache.delete', $s = '*');
     $res = IO_FS::clear_dir($this->path);
     if ($this->use_array_cache) {
         $this->timestamps = array();
         $this->values = array();
     }
     return $res;
 }
Exemple #25
0
 public function process($uri, $data)
 {
     //$this->data = $data;
     $this->uri = $uri;
     $this->search_urls = array($uri);
     Events::call('tao.navigation.search_urls', $this->search_urls);
     $this->load_data($data);
     return $this;
 }
Exemple #26
0
 protected function layout_preprocess($l, $name, $data)
 {
     $form_name = $l->helpers['forms']->form->name;
     $this->attach($l, $name, $data);
     if (!isset($data['caption'])) {
         $data['caption'] = '';
     }
     $caption = trim(CMS::lang($data['caption']));
     $rcaption = '';
     if (isset($data['rcaption'])) {
         $caption = '';
         $rcaption = trim(CMS::lang($data['rcaption']));
     }
     if ($caption == '') {
         $caption = '&nbsp;';
     } else {
         $caption .= ':';
     }
     Events::call("cms.fields.{$form_name}.{$name}.caption", $caption, $rcaption);
     Events::call("cms.fields.{$form_name}.caption", $caption, $rcaption);
     $ccont = $this->caption_content($name, $data);
     if (!$ccont) {
         $ccont = $l->forms->label($name, $caption, array('class' => "label-{$name} left"));
     }
     if (isset($data['allow select format']) && $data['allow select format'] && isset($data['input formats'])) {
         $select_formats = array();
         foreach ($data['input formats'] as $name => $f) {
             $select_formats[$name] = $f['display name'];
         }
         $l->update_parm('selected_formats', $select_formats);
     }
     $l->with(array('caption' => $caption, 'rcaption' => $rcaption, 'current_lang' => $this->current_lang(), 'ccont' => $ccont));
     if (isset($data['layout preprocess'])) {
         Core::invoke($data['layout preprocess'], array($l, $name, $data));
     }
     return $l;
 }
Exemple #27
0
 public function postprocess($path, $data, $content = null)
 {
     Events::call('templates.assets.postprocess', $path, $data, $content);
     foreach ($this->postprocessors as $k => $p) {
         if (is_string($p)) {
             $p = Core::make($p);
             $this->postprocessors[$k] = $p;
         }
         list($path, $content) = $p->postprocess($path, $data, $content);
     }
     if (!empty($content)) {
         $this->write($path, $content);
     }
     return $path;
 }
Exemple #28
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;
 }
Exemple #29
0
 /**
  * Инвалидирует кэш
  *
  */
 public function flush()
 {
     Events::call('cache.flush');
     Events::call('cache.delete', $s = '*');
     return true;
 }
Exemple #30
0
 public function execute($force_update = false)
 {
     $this->data_canonicalize();
     Events::call('db.schema.execute', $this->data);
     Events::call('db.schema.execute.' . $this->data['name'], $this->data);
     $this->data_canonicalize();
     $this->db->listeners['schema_query']->reset();
     if ($this->exists()) {
         $rc = $this->update($force_update);
     } else {
         $rc = $this->create();
     }
     Events::call('db.schema.after_execute', $this->data);
     Events::call('db.schema.after_execute.' . $this->data['name'], $this->data);
     $this->clear();
     return $rc;
 }