public function execute()
 {
     $name = rtrim(waRequest::post('name'), '/');
     $domain_model = new siteDomainModel();
     $data = array();
     if (!preg_match('!^[a-z0-9/\\._-]+$!i', $name)) {
         $data['title'] = $name;
         $idna = new waIdna();
         $name = $idna->encode($name);
     }
     $data['name'] = $name;
     $this->response['id'] = $domain_model->insert($data);
     $this->log('site_add');
     // add default routing
     $path = $this->getConfig()->getPath('config', 'routing');
     if (file_exists($path)) {
         $routes = (include $path);
     } else {
         $routes = array();
     }
     if (!isset($routes[$name])) {
         $routes[$name]['site'] = array('url' => '*', 'app' => 'site');
         waUtils::varExportToFile($routes, $path);
     }
 }
 public function execute()
 {
     $path = $this->getConfig()->getPath('config', 'routing');
     $all_routes = file_exists($path) ? include $path : array();
     $domain = siteHelper::getDomain();
     $route = waRequest::post('route');
     $pos = waRequest::post('pos');
     $result = array();
     $i = 0;
     $routes = wa()->getRouting()->getRoutes($domain);
     $apps = wa()->getApps();
     foreach ($routes as $k => $v) {
         if ($pos == $i) {
             $result[$route] = $routes[$route];
         }
         if ($route != $k) {
             if (isset($v['app']) && isset($apps[$v['app']]) || isset($v['redirect'])) {
                 $i++;
             }
             $result[$k] = $v;
         }
     }
     if ($pos == $i) {
         $result[$route] = $routes[$route];
     }
     $all_routes[$domain] = $result;
     waUtils::varExportToFile($all_routes, $path);
 }
 public function execute()
 {
     $name = mb_strtolower(rtrim(waRequest::post('name'), '/'));
     $domain_model = new siteDomainModel();
     $data = array();
     if (!preg_match('!^[a-z0-9/\\._-]+$!i', $name)) {
         $data['title'] = $name;
         $idna = new waIdna();
         $name = $idna->encode($name);
     }
     $data['name'] = $name;
     if ($domain_model->getByName($name)) {
         $this->errors = sprintf(_w("Website with a domain name %s is already registered in this Webasyst installation. Delete %s website (Site app > Settings > %s) to be able to use it's domain name for another website."), $name, $name, $name);
         return;
     }
     $this->response['id'] = $domain_model->insert($data);
     $this->log('site_add');
     // add default routing
     $path = $this->getConfig()->getPath('config', 'routing');
     if (file_exists($path)) {
         $routes = (include $path);
     } else {
         $routes = array();
     }
     if (!isset($routes[$name])) {
         $routes[$name]['site'] = array('url' => '*', 'app' => 'site');
         waUtils::varExportToFile($routes, $path);
     }
 }
 public function load($locale, $locale_path, $domain, $textdomain = true)
 {
     $file = $locale_path . '/' . $locale . '/LC_MESSAGES/' . $domain . '.po';
     $cache_file = waSystem::getInstance()->getConfig()->getPath('cache') . '/apps/' . $domain . '/locale/' . $locale . '.php';
     if (isset(self::$cache[$locale][$domain])) {
     } elseif (!file_exists($file)) {
         self::$cache[$locale][$domain] = array();
     } elseif (file_exists($cache_file) && filemtime($cache_file) > filemtime($file)) {
         self::$cache[$locale][$domain] = (include $cache_file);
     } else {
         if (file_exists($file)) {
             $gettext = new waGettext($file);
             self::$cache[$locale][$domain] = $gettext->read();
         } else {
             self::$cache[$locale][$domain] = array();
         }
         waFiles::create($cache_file);
         waUtils::varExportToFile(self::$cache[$locale][$domain], $cache_file);
     }
     if (isset(self::$cache[$locale][$domain]['meta']['Plural-Forms']['plural']) && self::$cache[$locale][$domain]['meta']['Plural-Forms']['plural']) {
         self::$cache[$locale][$domain]['meta']['f'] = create_function('$n', self::$cache[$locale][$domain]['meta']['Plural-Forms']['plural']);
     }
     if ($textdomain) {
         self::$domain = $domain;
         self::$locale = $locale;
     }
     if (!self::$locale) {
         self::$locale = $locale;
     }
 }
 public function execute()
 {
     /**
      * @var shopConfig $config
      */
     $config = $this->getConfig();
     $settings = $config->getOption(null);
     $settings['search_weights'] = waRequest::post('weights');
     $settings['search_ignore'] = waRequest::post('ignore');
     $settings['search_by_part'] = waRequest::post('by_part', 0, 'int');
     $config_file = $config->getConfigPath('config.php');
     waUtils::varExportToFile($settings, $config_file);
 }
 public function execute()
 {
     $path = $this->getConfig()->getPath('config', 'routing');
     if (file_exists($path)) {
         $routes = (include $path);
     } else {
         $routes = array();
     }
     $domain = siteHelper::getDomain();
     $route_id = waRequest::get('route');
     $other_params = waRequest::post('other_params', '');
     $other_params = explode("\n", $other_params);
     $app_id = $routes[$domain][$route_id]['app'];
     if ($app_id == 'site') {
         if ($title = siteHelper::getDomain('title')) {
             $name = $title;
         } else {
             $app_settings_model = new waAppSettingsModel();
             $name = $app_settings_model->get('webasyst', 'name', 'Webasyst');
         }
     } else {
         $app = wa()->getAppInfo($app_id);
         $name = $app['name'];
     }
     $t = array('url' => $routes[$domain][$route_id]['url'], 'app' => $routes[$domain][$route_id]['app']);
     foreach ($routes[$domain][$route_id] as $k => $v) {
         if (substr($k, 0, 1) == '_') {
             $t[$k] = $routes[$domain][$route_id][$k];
         }
     }
     $routes[$domain][$route_id] = $t;
     foreach ($other_params as $string) {
         $string = trim($string);
         if ($string && strpos($string, '=') !== false) {
             $string = explode('=', $string, 2);
             if ($string[0]) {
                 $routes[$domain][$route_id][$string[0]] = $string[1];
             }
         }
     }
     $params = waRequest::post('params', array());
     foreach ($params as $key => $value) {
         if ($key != '_name' || $value != $name || isset($routes[$domain][$route_id]['_name']) && $value != $routes[$domain][$route_id]['_name']) {
             $routes[$domain][$route_id][$key] = $value;
         }
     }
     if (!$routes[$domain][$route_id]['locale']) {
         unset($routes[$domain][$route_id]['locale']);
     }
     waUtils::varExportToFile($routes, $path);
 }
 public function execute()
 {
     $app_id = waRequest::post('app_id');
     $enable = waRequest::post('enable');
     $domain = siteHelper::getDomain();
     $domain_config_path = wa('site')->getConfig()->getConfigPath('domains/' . $domain . '.php');
     if (file_exists($domain_config_path)) {
         $domain_config = (include $domain_config_path);
     } else {
         $domain_config = array();
     }
     $domain_config['personal'][$app_id] = $enable ? true : false;
     waUtils::varExportToFile($domain_config, $domain_config_path);
 }
 public function execute()
 {
     $domain = siteHelper::getDomain();
     $routes = wa()->getRouting()->getRoutes($domain);
     $route_id = waRequest::post('route');
     if (isset($routes[$route_id])) {
         unset($routes[$route_id]);
         // save
         $path = $this->getConfig()->getPath('config', 'routing');
         $all_routes = file_exists($path) ? include $path : array();
         $all_routes[$domain] = $routes;
         waUtils::varExportToFile($all_routes, $path);
         $this->log('route_delete');
     }
 }
 public function execute()
 {
     $fields = waRequest::post('personal_fields');
     $domain = waRequest::post('domain');
     $domain_config_path = wa('site')->getConfig()->getConfigPath('domains/' . $domain . '.php');
     if (file_exists($domain_config_path)) {
         $domain_config = (include $domain_config_path);
     } else {
         $domain_config = array();
     }
     $domain_config['personal_fields'] = array();
     foreach ($fields as $field) {
         $domain_config['personal_fields'][$field] = true;
     }
     waUtils::varExportToFile($domain_config, $domain_config_path);
 }
 private function generateConfig($state, $plugins)
 {
     $app_config = wa()->getConfig()->getAppConfig('shop');
     $path = $app_config->getConfigPath('plugins.php', true);
     $plugin_php = (include $path);
     if ($state) {
         $state = true;
     } else {
         $state = false;
     }
     foreach ($plugins as $plugin) {
         $plugin_php[$plugin] = $state;
     }
     unset($plugin);
     waUtils::varExportToFile($plugin_php, $path, true);
 }
 public function execute()
 {
     if (waRequest::post()) {
         $app_settings = new waAppSettingsModel();
         foreach ($this->getData() as $name => $value) {
             $app_settings->set('shop', $name, $value);
         }
         $sms = waRequest::post('sms', array());
         $path = $this->getConfig()->getPath('config', 'sms');
         $save = array();
         foreach ($sms as $s) {
             $from = $s['from'];
             $adapter = $s['adapter'];
             unset($s['from']);
             unset($s['adapter']);
             $empty = true;
             foreach ($s as $v) {
                 if ($v) {
                     $empty = false;
                     break;
                 }
             }
             if (!$empty) {
                 if (!$from) {
                     $from = '*';
                 }
                 foreach (explode("\n", $from) as $from) {
                     $from = trim($from);
                     $save[$from] = $s;
                     $save[$from]['adapter'] = $adapter;
                 }
             }
         }
         waUtils::varExportToFile($save, $path);
     }
     $cm = new waCountryModel();
     $this->view->assign('countries', $cm->all());
     $this->view->assign($this->getConfig()->getGeneralSettings());
     $workhours = wa()->getSetting('workhours', null);
     if ($workhours) {
         $workhours = json_decode($workhours, true);
     }
     $this->view->assign('workhours', $workhours);
     $sms_adapters = $this->getSMSAdapters();
     $this->view->assign('sms_adapters', $sms_adapters);
     $this->view->assign('saved', waRequest::post());
 }
Esempio n. 12
0
 protected function generateSchema($app_id, $tables = array())
 {
     $plugin_id = false;
     if (strpos($app_id, '/') !== false) {
         list($app_id, $plugin_id) = explode('/', $app_id, 2);
         $path = wa()->getConfig()->getAppsPath($app_id, 'plugins/' . $plugin_id . '/lib/config/db.php');
     } else {
         $path = wa()->getConfig()->getAppsPath($app_id, 'lib/config/db.php');
     }
     if (waRequest::param('update') !== null) {
         $schema = (include $path);
         if (!$tables) {
             $tables = array_keys($schema);
         }
     } elseif ($tables) {
         if (!is_array($tables)) {
             $tables = array($tables);
         }
     } else {
         $prefix = $app_id == 'webasyst' ? 'wa' : $app_id;
         if ($plugin_id) {
             $prefix .= '_' . $plugin_id;
         }
         // @todo: use db adapter to get tables
         $sql = "SHOW TABLES LIKE '" . $prefix . "\\_%'";
         $tables = $this->model->query($sql)->fetchAll(null, true);
         $sql = "SHOW TABLES LIKE '" . $prefix . "'";
         $tables = array_merge($tables, $this->model->query($sql)->fetchAll(null, true));
     }
     $schema = array();
     foreach ($tables as $t) {
         echo $t . "\n";
         try {
             $schema[$t] = $this->model->describe($t, 1);
         } catch (waDbException $ex) {
             print "\tError: " . $ex->getMessage() . "\n";
         }
     }
     if ($schema) {
         // save schema to lib/config/db.php of the app
         waUtils::varExportToFile($this->schemaToString($schema), $path, false);
     }
 }
 public function execute()
 {
     if (!$this->getUser()->isAdmin($this->getApp())) {
         throw new waRightsException(_w('Access denied'));
     }
     $plugin_slug = waRequest::post('slug');
     $new_pos = waRequest::post('pos', 0, 'int');
     $response = 'fail';
     $plugins_config = $this->getConfig()->getConfigPath('plugins.php', true);
     if (file_exists($plugins_config)) {
         $plugins = (include $plugins_config);
         if (isset($plugins[$plugin_slug]) && $plugins[$plugin_slug]) {
             $result = array();
             $pos = 0;
             foreach ($plugins as $name => $plugin) {
                 if ($new_pos === $pos) {
                     $result[$plugin_slug] = $plugins[$plugin_slug];
                     $new_pos = false;
                 }
                 if ($name != $plugin_slug) {
                     $result[$name] = $plugin;
                     if ($plugin) {
                         ++$pos;
                     }
                 }
             }
             if (!isset($result[$plugin_slug])) {
                 $result[$plugin_slug] = $plugins[$plugin_slug];
             }
             if (waUtils::varExportToFile($result, $plugins_config)) {
                 $response = 'ok';
             } else {
                 $response = 'io error';
             }
         }
     }
     $this->response = $response;
     $this->getResponse()->addHeader('Content-type', 'application/json');
 }
 public function execute()
 {
     $domain = siteHelper::getDomain();
     $routes = wa()->getRouting()->getRoutes($domain);
     $route_id = waRequest::post('route');
     if (isset($routes[$route_id])) {
         if (isset($routes[$route_id]['app'])) {
             $robots = new siteRobots($domain);
             $robots->delete($routes[$route_id]['app'], $routes[$route_id]['url']);
         }
         unset($routes[$route_id]);
         // save
         $path = $this->getConfig()->getPath('config', 'routing');
         $all_routes = file_exists($path) ? include $path : array();
         $all_routes[$domain] = $routes;
         if (!waUtils::varExportToFile($all_routes, $path)) {
             $this->errors = sprintf(_w('Settings could not be saved due to the insufficient file write permissions for the file "%s".'), 'wa-config/routing.php');
         } else {
             $this->logAction('route_delete');
         }
     }
 }
 public function execute()
 {
     $domain_id = waRequest::post('domain_id');
     if ($domain_id) {
         // check domain
         $domain_model = new siteDomainModel();
         $domain = $domain_model->getById($domain_id);
         $route = waRequest::post('route');
         if ($domain) {
             // delete from routing
             $path = $this->getConfig()->getPath('config', 'routing');
             if (file_exists($path)) {
                 $routes = (include $path);
                 if (isset($routes[$domain['name']])) {
                     // delete route
                     if ($route && isset($routes[$domain['name']][$route])) {
                         unset($routes[$domain['name']][$route]);
                         // save new routing config
                         waUtils::varExportToFile($routes, $path);
                     } elseif (!$route) {
                         unset($routes[$domain['name']]);
                         // save new routing config
                         waUtils::varExportToFile($routes, $path);
                     }
                 }
             }
             if (!$route) {
                 // delete site files (favicon, etc.)
                 waFiles::delete(wa()->getDataPath('data/' . $domain['name']), true);
                 // delete site from db
                 $domain_model->deleteById($domain_id);
                 $this->logAction('site_delete');
             }
         }
     }
 }
Esempio n. 16
0
 public function setAuth($data)
 {
     $path = $this->getPath('config', 'auth');
     if (waUtils::varExportToFile($data, $path)) {
         $cache = new waRuntimeCache('wa-config/auth');
         $cache->set($data);
         return true;
     }
     return false;
 }
 /**
  * Trigger event with given $name from current active application.
  *
  * @param  string    $name        Event name.
  * @param  mixed     $params      Parameters passed to event handlers.
  * @param  string[]  $array_keys  Array of expected template items for UI events.
  * @return  array  app_id or plugin_id => data returned from handler (unless null is returned)
  */
 public function event($name, &$params = null, $array_keys = null)
 {
     $result = array();
     if (is_array($name)) {
         $event_app_id = $name[0];
         $event_system = self::getInstance($event_app_id);
         $name = $name[1];
     } else {
         $event_app_id = $this->getConfig()->getApplication();
         $event_system = $this;
     }
     $event_prefix = wa($event_app_id)->getConfig()->getPrefix();
     if (!isset(self::$handlers['apps'])) {
         self::$handlers['apps'] = array();
         $cache_file = $this->config->getPath('cache', 'config/handlers');
         if (!waSystemConfig::isDebug() && file_exists($cache_file)) {
             self::$handlers['apps'] = (include $cache_file);
         }
         if (!self::$handlers['apps'] || !is_array(self::$handlers['apps'])) {
             $apps = $this->getApps();
             $path = $this->getConfig()->getPath('apps');
             foreach ($apps as $app_id => $app_info) {
                 $files = waFiles::listdir($path . '/' . $app_id . '/lib/handlers/');
                 foreach ($files as $file) {
                     if (substr($file, -12) == '.handler.php') {
                         $file = explode('.', substr($file, 0, -12), 2);
                         self::$handlers['apps'][$file[0]][$file[1]][] = $app_id;
                     }
                 }
             }
             if (!waSystemConfig::isDebug()) {
                 waUtils::varExportToFile(self::$handlers['apps'], $cache_file);
             }
         }
     }
     if (!isset(self::$handlers['plugins'][$event_app_id])) {
         self::$handlers['plugins'][$event_app_id] = array();
         $plugins = $event_system->getConfig()->getPlugins();
         foreach ($plugins as $plugin_id => $plugin) {
             if (!empty($plugin['handlers'])) {
                 foreach ($plugin['handlers'] as $handler_event => $handler_method) {
                     self::$handlers['plugins'][$event_app_id][$handler_event][$plugin_id] = $handler_method;
                 }
             }
         }
     }
     if (isset(self::$handlers['apps'][$event_app_id][$name])) {
         $path = $this->getConfig()->getPath('apps');
         foreach (self::$handlers['apps'][$event_app_id][$name] as $app_id) {
             $file_path = $path . '/' . $app_id . '/lib/handlers/' . $event_prefix . "." . $name . ".handler.php";
             if (!file_exists($file_path)) {
                 continue;
             }
             wa($app_id);
             include_once $file_path;
             $class_name = $name;
             if (strpos($name, '.') !== false) {
                 $class_name = strtok($class_name, '.') . ucfirst(strtok(''));
             }
             $class_name = $app_id . ucfirst($event_prefix) . ucfirst($class_name) . "Handler";
             /**
              * @var $handler waEventHandler
              */
             $handler = new $class_name();
             try {
                 $r = $handler->execute($params);
                 if ($r !== null) {
                     $result[$app_id] = $r;
                 }
             } catch (Exception $e) {
                 waLog::log('Event handling error in ' . $file_path . ': ' . $e->getMessage());
             }
         }
     }
     if (isset(self::$handlers['plugins'][$event_app_id][$name])) {
         $plugins = $event_system->getConfig()->getPlugins();
         foreach (self::$handlers['plugins'][$event_app_id][$name] as $plugin_id => $method) {
             if (!isset($plugins[$plugin_id])) {
                 continue;
             }
             $plugin = $plugins[$plugin_id];
             self::pushActivePlugin($plugin_id, $event_prefix);
             $class_name = $event_app_id . ucfirst($plugin_id) . 'Plugin';
             try {
                 $class = new $class_name($plugin);
                 // Load plugin locale if it exists
                 $locale_path = $this->getAppPath('plugins/' . $plugin_id . '/locale', $event_app_id);
                 if (is_dir($locale_path)) {
                     waLocale::load($this->getLocale(), $locale_path, self::getActiveLocaleDomain(), false);
                 }
                 if (method_exists($class, $method) && null !== ($r = $class->{$method}($params))) {
                     if ($array_keys && is_array($r)) {
                         foreach ($array_keys as $k) {
                             if (!isset($r[$k])) {
                                 $r[$k] = '';
                             }
                         }
                     }
                     $result[$plugin_id . '-plugin'] = $r;
                 }
             } catch (Exception $e) {
                 waLog::log('Event handling error in ' . $class_name . '->' . $name . '(): ' . $e->getMessage());
             }
             self::popActivePlugin();
         }
     }
     return $result;
 }
Esempio n. 18
0
 public function getApps($system = false)
 {
     if (self::$apps === null) {
         $locale = $this->getUser()->getLocale();
         $file = $this->config->getPath('cache', 'config/apps' . $locale);
         if (!file_exists($this->getConfig()->getPath('config', 'apps'))) {
             self::$apps = array();
             throw new waException('File wa-config/apps.php not found.', 600);
         }
         if (!file_exists($file) || filemtime($file) < filemtime($this->getConfig()->getPath('config', 'apps')) || waSystemConfig::isDebug()) {
             waFiles::create($this->getConfig()->getPath('cache') . '/config');
             $all_apps = (include $this->getConfig()->getPath('config', 'apps'));
             $all_apps['webasyst'] = true;
             self::$apps = array();
             foreach ($all_apps as $app => $enabled) {
                 if ($enabled) {
                     waLocale::loadByDomain($app, $locale);
                     $app_config = $this->getAppPath('lib/config/app.php', $app);
                     if (!file_exists($app_config)) {
                         if (false && SystemConfig::isDebug()) {
                             throw new waException("Config not found. Create config by path " . $app_config);
                         }
                         continue;
                     }
                     $app_info = (include $app_config);
                     $build_file = $app_config = $this->getAppPath('lib/config/build.php', $app);
                     if (file_exists($build_file)) {
                         $app_info['build'] = (include $build_file);
                     } else {
                         if (SystemConfig::isDebug()) {
                             $app_info['build'] = time();
                         } else {
                             $app_info['build'] = 0;
                         }
                     }
                     $app_info['id'] = $app;
                     $app_info['name'] = _wd($app, $app_info['name']);
                     if (isset($app_info['icon'])) {
                         if (is_array($app_info['icon'])) {
                             foreach ($app_info['icon'] as $size => $url) {
                                 $app_info['icon'][$size] = 'wa-apps/' . $app . '/' . $url;
                             }
                         } else {
                             $app_info['icon'] = array(48 => 'wa-apps/' . $app . '/' . $app_info['icon']);
                         }
                     } else {
                         $app_info['icon'] = array();
                     }
                     if (isset($app_info['img'])) {
                         $app_info['img'] = 'wa-apps/' . $app . '/' . $app_info['img'];
                     } else {
                         $app_info['img'] = isset($app_info['icon'][48]) ? $app_info['icon'][48] : 'wa-apps/' . $app . '/img/' . $app . ".png";
                     }
                     if (!isset($app_info['icon'][48])) {
                         $app_info['icon'][48] = $app_info['img'];
                     }
                     if (!isset($app_info['icon'][24])) {
                         $app_info['icon'][24] = $app_info['icon'][48];
                     }
                     if (!isset($app_info['icon'][16])) {
                         $app_info['icon'][16] = $app_info['icon'][24];
                     }
                     self::$apps[$app] = $app_info;
                 }
             }
             if (!file_exists($file) || filemtime($file) < filemtime($this->getConfig()->getPath('config', 'apps'))) {
                 waUtils::varExportToFile(self::$apps, $file);
             }
         } else {
             self::$apps = (include $file);
             waLocale::loadByDomain('webasyst');
         }
     }
     if ($system) {
         return self::$apps;
     } else {
         $apps = self::$apps;
         unset($apps['webasyst']);
         return $apps;
     }
 }
 public function execute()
 {
     if (file_exists($this->getConfig()->getPath('config', 'db'))) {
         $this->redirect($this->getConfig()->getBackendUrl(true));
     }
     if ($config = waRequest::post()) {
         $database = $config['database'];
         $error = false;
         try {
             $config['database'] = null;
             $model = new waModel($config);
         } catch (waDbException $e) {
             $error = _w('Failed to connect to specified MySQL database server.');
         }
         $config['database'] = $database;
         if (!$error) {
             if (!$model->database($database)) {
                 try {
                     // try create database
                     $sql = "CREATE DATABASE " . $model->escape($database);
                     $model->exec($sql);
                 } catch (waDbException $e) {
                     $error = sprintf(_w('Failed to connect to the “%s” database.'), $database);
                 }
             }
         }
         if (!$error) {
             // try save config
             $file = $this->getConfig()->getPath('config');
             if (!is_writable($file)) {
                 $error = sprintf(_w("Not enough access permissions to write in the folder %s"), $file);
             } else {
                 $data = array('default' => $config);
                 if (!waUtils::varExportToFile($data, $file . '/db.php')) {
                     $error = sprintf(_w("Error creating file %s"), $file . '/routing.php');
                 } else {
                     // check routing.php
                     if (!file_exists($file . '/routing.php')) {
                         $apps = wa()->getApps();
                         $data = array();
                         $domain = $this->getConfig()->getDomain();
                         $site = false;
                         foreach ($apps as $app_id => $app) {
                             if ($app_id == 'site') {
                                 $site = true;
                             } elseif (!empty($app['frontend'])) {
                                 $data[$domain][] = array('url' => $app_id . '/', 'app' => $app_id);
                             }
                         }
                         if ($site) {
                             $data[$domain][] = array('url' => '*', 'app' => 'site');
                         }
                         waUtils::varExportToFile($data, $file . '/routing.php');
                     }
                     // redirect to backend
                     $this->redirect($this->getConfig()->getBackendUrl(true));
                 }
             }
         }
         if ($error) {
             $this->view->assign('error', $error);
         }
     }
 }
 /**
  * @param bool $validate
  * @return bool|array
  */
 public function save($validate = false)
 {
     $res = null;
     if (!$this->readonly && $this->changed && $this->path) {
         if ($this->path_original && !$this->path_custom) {
             $this->copy();
         }
         $path = $this->path . '/' . self::PATH;
         $extension = pathinfo($path, PATHINFO_EXTENSION);
         switch ($extension) {
             case 'xml':
                 $dom = $this->getXML(true);
                 /**
                  * @var DOMDocument $dom
                  */
                 $xpath = new DOMXPath($dom);
                 $theme = $xpath->query('/theme')->item(0);
                 /**
                  * @var DOMElement $theme
                  */
                 $ml_fields = array('name', 'description', 'about');
                 foreach ($ml_fields as $field) {
                     if (isset($this->changed[$field]) && $this->info[$field]) {
                         $this->addLocalizedField($dom, $xpath, $theme, $field, $this->info[$field]);
                     }
                     unset($this->changed[$field]);
                 }
                 if (isset($this->changed['files'])) {
                     //files workaround
                     $query = "/theme/files";
                     if (!($files = $xpath->query($query)->item(0))) {
                         $files = $this->addNode($dom, $xpath, $theme, 'files');
                     }
                     foreach ($this->changed['files'] as $file_path => $changed) {
                         if (isset($this->info['files'][$file_path]) && $this->info['files'][$file_path]) {
                             $info = $this->info['files'][$file_path];
                             $query = "/theme/files/file[@path='{$file_path}']";
                             if (!($file = $xpath->query($query)->item(0))) {
                                 $file = $this->addNode($dom, $xpath, $files, 'file');
                                 $file->setAttribute('path', $file_path);
                             }
                             $file->setAttribute('custom', !empty($info['custom']) ? '1' : '0');
                             if (!empty($info['modified']) || (string) $file->getAttribute('modified')) {
                                 $file->setAttribute('modified', $info['modified'] ? '1' : '0');
                             }
                             if (!empty($info['parent'])) {
                                 $file->setAttribute('parent', $info['parent'] ? '1' : '0');
                             }
                             if (!empty($info['description'])) {
                                 $this->addLocalizedField($dom, $xpath, $file, 'description', $info['description']);
                             }
                         } else {
                             $query = "/theme/files/file[@path='{$file_path}']";
                             if ($file = $xpath->query($query)->item(0)) {
                                 $files->removeChild($file);
                             }
                         }
                     }
                     unset($this->changed['files']);
                 }
                 if (!empty($this->changed['settings'])) {
                     //settings workaround
                     $query = "/theme/settings";
                     $settings = $xpath->query($query)->item(0);
                     if (!$settings) {
                         $settings = $this->addNode($dom, $xpath, $theme, 'settings');
                     }
                     foreach ($this->changed['settings'] as $var => $changed) {
                         $query = "/theme/settings/setting[@var='{$var}']/value";
                         $value_items = $xpath->query($query);
                         if (!$value_items->length) {
                             $setting = $this->addNode($dom, $xpath, $settings, 'setting');
                             $setting->setAttribute('var', $var);
                             $this->addNode($dom, $xpath, $setting, 'value');
                             if (!empty($this->info['settings'][$var])) {
                                 $this->updateSetting($dom, $xpath, $setting, $this->info['settings'][$var]);
                             }
                             $value_items = $xpath->query($query);
                         } elseif (!empty($this->info['settings'][$var]['changed'])) {
                             $setting = $value_items->item(0)->parentNode;
                             /**
                              * @var DOMElement $setting
                              */
                             $this->updateSetting($dom, $xpath, $setting, $this->info['settings'][$var]);
                             unset($this->info['settings'][$var]['changed']);
                         }
                         $length = $value_items->length;
                         if ($length && ($value = $value_items->item(0))) {
                             /**
                              * @var DOMElement $value
                              */
                             if (ifset($this->settings[$var]['control_type']) == 'text') {
                                 $value->nodeValue = '';
                                 $value->appendChild(new DOMCdataSection(self::prepareField(ifempty($this->settings[$var]['value'], ''))));
                             } else {
                                 $value->nodeValue = self::prepareField(ifempty($this->settings[$var]['value'], ''));
                             }
                             if ($value->hasAttribute('locale')) {
                                 $value->removeAttribute('locale');
                             }
                             $parent = $value->parentNode;
                             for ($index = 1; $index < $length; $index++) {
                                 $parent->removeChild($value_items->item($index));
                             }
                         }
                     }
                     unset($this->changed['settings']);
                 }
                 //todo add save locales support
                 if ($this->changed) {
                     foreach ($this->changed as $field => $changed) {
                         if ($changed) {
                             $value = ifset($this->info[$field], '');
                             if (in_array($field, array('system'))) {
                                 $value = sprintf('%d', $value);
                             }
                             $theme->setAttribute($field, $value);
                         }
                         unset($this->changed[$field]);
                     }
                 }
                 $dom->preserveWhiteSpace = false;
                 $dom->formatOutput = true;
                 if (($res = $dom->save($path, LIBXML_COMPACT)) && $validate) {
                     $res = $this->validate($dom, true);
                 }
                 break;
             case 'php':
                 $res = waUtils::varExportToFile($this->info, $path);
                 break;
             default:
                 //nothing todo
                 break;
         }
         if ($res) {
             self::protect($this->app, $this->path_custom ? true : false);
         }
     }
     return $res;
 }
 /**
  *
  * Update general plugin sort
  * @param string $plugin plugin id
  * @param int $sort 0 is first
  */
 public function setPluginSort($plugin, $sort)
 {
     $path = $this->getConfigPath('plugins.php', true);
     if (file_exists($path) && ($plugins = (include $path)) && !empty($plugins[$plugin])) {
         $sort = max(0, min(intval($sort), count($plugins) - 1));
         $order = array_flip(array_keys($plugins));
         if ($order[$plugin] != $sort) {
             $b = array($plugin => $plugins[$plugin]);
             unset($plugins[$plugin]);
             $a = array_slice($plugins, 0, $sort, true);
             $c = array_slice($plugins, $sort, null, true);
             $plugins = array_merge($a, $b, $c);
             if (waUtils::varExportToFile($plugins, $path)) {
                 waFiles::delete(waConfig::get('wa_path_cache') . "/apps/" . $this->application . '/config', true);
             } else {
                 throw new waException("Fail while update plugins sort order");
             }
         }
     }
 }
 /**
  * Remove given field from person or company order list.
  * @param $type string person|company
  * @param $id waContactField|int field ID or field instance.
  * @param boolean $delete delete values from db or not
  * @throws waException
  */
 public static function disableField($id, $type, $delete = false)
 {
     self::ensureStaticVars();
     if (is_object($id) && $id instanceof waContactField) {
         $id = $id->getId();
     }
     if (null === self::isSystemField($id)) {
         throw new waException('Unknown field: ' . $id);
     }
     switch ($type) {
         case 'person':
             if (!isset(self::$personFields[$id])) {
                 return;
             }
             $f = self::$personFields[$id];
             unset(self::$personFields[$id]);
             self::$personDisabled[$id] = $f;
             $file = wa()->getConfig()->getConfigPath('person_fields_order.php', true, 'contacts');
             break;
         case 'company':
             if (!isset(self::$companyFields[$id])) {
                 return;
             }
             $f = self::$companyFields[$id];
             unset(self::$companyFields[$id]);
             self::$companyDisabled[$id] = $f;
             $file = wa()->getConfig()->getConfigPath('company_fields_order.php', true, 'contacts');
             break;
         default:
             throw new waException('Unknown contact type: ' . $type);
     }
     /**
      * @var waContactField $f
      */
     if ($delete) {
         // Remove data from DB
         $f->getStorage()->deleteAll($id, $type);
     }
     // Remove field from order file
     if (!is_readable($file)) {
         return;
     }
     $contactOrder = (include $file);
     unset($contactOrder[$id]);
     if (empty($contactOrder) || !is_array($contactOrder)) {
         $contactOrder = array();
     }
     waUtils::varExportToFile($contactOrder, $file, true);
 }
 public function themeUseAction()
 {
     $theme_id = waRequest::post('theme');
     $route = waRequest::post('route');
     $path = $this->getConfig()->getPath('config', 'routing');
     if (file_exists($path)) {
         $routes = (include $path);
         if (!is_writable($path)) {
             $this->displayJson(array(), sprintf(_w('Settings could not be saved due to the insufficient file write permissions for the file "%s".'), 'wa-config/routing.php'));
             return;
         }
     } else {
         $routes = array();
     }
     if ($route == 'new') {
         $domain = waRequest::post('domain');
         $url = waRequest::post('url');
         if (!$url) {
             $url = '*';
         }
         $route_id = 0;
         foreach ($routes[$domain] as $r_id => $r) {
             if (is_numeric($r_id) && $r_id > $route_id) {
                 $route_id = $r_id;
             }
         }
         $route_id++;
         $route = array('url' => $url, 'app' => $this->getAppId(), 'theme' => $theme_id, 'theme_mobile' => $theme_id);
         if ($route['url'] == '*') {
             $routes[$domain][$route_id] = $route;
         } else {
             if (strpos($route['url'], '*') === false) {
                 if (substr($route['url'], -1) == '/') {
                     $route['url'] .= '*';
                 } elseif (substr($route['url'], -1) != '*' && strpos(substr($route['url'], -5), '.') === false) {
                     $route['url'] .= '/*';
                 }
             }
             $routes[$domain] = array($route_id => $route) + $routes[$domain];
         }
     } else {
         list($domain, $route_id) = explode('|', $route);
         if (!waRequest::post('mobile_only')) {
             $routes[$domain][$route_id]['theme'] = $theme_id;
         }
         $routes[$domain][$route_id]['theme_mobile'] = $theme_id;
     }
     waUtils::varExportToFile($routes, $path);
     $this->displayJson(array('domain' => $domain, 'route' => $route_id, 'theme' => $theme_id));
 }
Esempio n. 24
0
                        $sql .= " AND id NOT IN (i:ids)";
                        $pages = $data['ids'] = $route['_exclude'];
                    } else {
                        $data['ids'] = array_diff($pages, $route['_exclude']);
                        $sql .= " AND id IN (i:ids)";
                        $pages = array_diff($pages, $data['ids']);
                        if (!$pages) {
                            break 2;
                        }
                    }
                    if (!isset($data['ids']) || $data['ids']) {
                        $model->exec($sql, $data);
                    }
                }
            }
        }
    }
    // remove _exclude from routing
    $save = false;
    foreach ($routing as $domain => $domain_routes) {
        foreach ($domain_routes as $route_id => $route) {
            if (isset($route['app']) && $route['app'] == 'blog' && isset($route['_exclude'])) {
                unset($routing[$domain][$route_id]['_exclude']);
                $save = true;
            }
        }
    }
    if ($save) {
        waUtils::varExportToFile($routing, $routing_path);
    }
}
 public function execute()
 {
     $path = $this->getConfig()->getPath('config', 'routing');
     if (file_exists($path)) {
         $routes = (include $path);
     } else {
         $routes = array();
     }
     $domain = siteHelper::getDomain();
     $url = mb_strtolower(rtrim(waRequest::post('url'), '/'));
     if ($url != $domain) {
         $domain_model = new siteDomainModel();
         // domain already exists
         if ($domain_model->getByName($url)) {
             $this->errors = sprintf(_w("Website with a domain name %s is already registered in this Webasyst installation. Delete %s website (Site app > %s > Settings) to be able to use it's domain name for another website."), $url, $url, $url);
             return;
         }
         $domain_model->updateById(siteHelper::getDomainId(), array('name' => $url));
         $routes[$url] = $routes[$domain];
         unset($routes[$domain]);
         // move configs
         $old = $this->getConfig()->getConfigPath('domains/' . $domain . '.php');
         if (file_exists($old)) {
             waFiles::move($old, $this->getConfig()->getConfigPath('domains/' . $url . '.php'));
         }
         $old = wa()->getDataPath('data/' . $domain . '/', true, 'site', false);
         if (file_exists($old)) {
             waFiles::move($old, wa()->getDataPath('data/' . $url . '/', true));
             clearstatcache();
             try {
                 waFiles::delete($old, true);
             } catch (waException $e) {
             }
         }
         $domain = $url;
         siteHelper::setDomain(siteHelper::getDomainId(), $domain);
     }
     // save wa_apps
     $domain_config_path = $this->getConfig()->getConfigPath('domains/' . $domain . '.php');
     if (file_exists($domain_config_path)) {
         $domain_config = (include $domain_config_path);
     } else {
         $domain_config = array();
     }
     $title = waRequest::post('title');
     $style = waRequest::post('background');
     if (!$style || substr($style, 0, 1) == '.') {
         if ($s = $this->saveBackground()) {
             $style = '.' . $s;
         }
     }
     $domain_model = new siteDomainModel();
     $domain_model->updateById(siteHelper::getDomainId(), array('title' => $title, 'style' => $style));
     $save_config = false;
     if ($title) {
         $domain_config['name'] = $title;
         $save_config = true;
     } else {
         if (isset($domain_config['name'])) {
             unset($domain_config['name']);
             $save_config = true;
         }
     }
     waUtils::varExportToFile($routes, $path);
     if (waRequest::post('wa_apps_type')) {
         $apps = waRequest::post('apps');
         if (!$domain_config) {
             // create directory
             waFiles::create($domain_config_path);
         }
         $domain_config['apps'] = array();
         foreach ($apps['url'] as $i => $u) {
             $domain_config['apps'][] = array('url' => $u, 'name' => $apps['name'][$i]);
         }
         $save_config = true;
     } else {
         if (isset($domain_config['apps'])) {
             unset($domain_config['apps']);
             $save_config = true;
         }
     }
     if (waRequest::post('cdn')) {
         $domain_config['cdn'] = waRequest::post('cdn');
         $save_config = true;
     } elseif (!empty($domain_config['cdn'])) {
         unset($domain_config['cdn']);
         $save_config = true;
     }
     // save other settings
     foreach (array('head_js', 'google_analytics') as $key) {
         if (!empty($domain_config[$key]) || waRequest::post($key)) {
             $domain_config[$key] = waRequest::post($key);
             $save_config = true;
         }
     }
     if ($save_config && !waUtils::varExportToFile($domain_config, $domain_config_path)) {
         $this->errors = sprintf(_w('Settings could not be saved due to the insufficient file write permissions for the "%s" folder.'), 'wa-config/apps/site/domains');
     }
     $this->saveFavicon();
     $this->saveTouchicon();
     $this->saveRobots();
     $this->logAction('site_edit');
 }
Esempio n. 26
0
 /**
  * @todo complete code - it's not work properly
  * Enter description here ...
  */
 public function save()
 {
     $res = null;
     if ($this->changed && $this->path) {
         $path = $this->path . '/' . self::PATH;
         $extension = pathinfo($path, PATHINFO_EXTENSION);
         switch ($extension) {
             case 'xml':
                 $dom = $this->getXML(true);
                 $xpath = new DOMXPath($dom);
                 $theme = $xpath->query('/theme')->item(0);
                 $ml_fields = array('name', 'description', 'about');
                 foreach ($ml_fields as $field) {
                     if (isset($this->changed[$field]) && $this->info[$field]) {
                         foreach ($this->info[$field] as $locale => $value) {
                             $query = "/theme/{$field}[@locale='{$locale}']";
                             if (!($node = $xpath->query($query)->item(0))) {
                                 $node = new DOMElement($field, $value);
                                 //$xml_node->setAttribute('locale', $locale);
                                 $theme->appendChild($node);
                                 $node->setAttribute('locale', $locale);
                             } else {
                                 $node->nodeValue = $value;
                             }
                         }
                     }
                     unset($this->changed[$field]);
                 }
                 if (isset($this->changed['files'])) {
                     //files workaround
                     $query = "/theme/files";
                     if (!($files = $xpath->query($query)->item(0))) {
                         $files = new DOMElement('files');
                         $dom->appendChild($files);
                     }
                     foreach ($this->changed['files'] as $file_path => $changed) {
                         if (isset($this->info['files'][$file_path]) && $this->info['files'][$file_path]) {
                             $info = $this->info['files'][$file_path];
                             $query = "/theme/files/file[@path='{$file_path}']";
                             if (!($file = $xpath->query($query)->item(0))) {
                                 $file = new DOMElement('file');
                                 $files->appendChild($file);
                                 $file->setAttribute('path', $file_path);
                             }
                             $file->setAttribute('custom', $info['custom'] ? '1' : '0');
                             if (isset($info['parent'])) {
                                 $file->setAttribute('parent', $info['parent'] ? '1' : '0');
                             }
                             foreach ($info['description'] as $locale => $value) {
                                 $query_description = "{$query}/description[@locale='{$locale}']";
                                 if (!($description = $xpath->query($query_description)->item(0))) {
                                     if ($value) {
                                         $description = new DOMElement('description', $value);
                                         $file->appendChild($description);
                                         $description->setAttribute('locale', $locale);
                                     }
                                 } else {
                                     if ($value === null) {
                                         $file->removeChild($description);
                                     } else {
                                         $description->nodeValue = $value;
                                     }
                                 }
                             }
                         } else {
                             $query = "/theme/files/file[@path='{$file_path}']";
                             if ($file = $xpath->query($query)->item(0)) {
                                 $files->removeChild($file);
                             }
                         }
                     }
                     unset($this->changed['files']);
                 }
                 if ($this->changed) {
                     foreach ($this->changed as $field => $changed) {
                         if ($changed) {
                             $theme->setAttribute($field, $this->info[$field]);
                         }
                         unset($this->changed[$field]);
                     }
                 }
                 $res = $dom->save($path, LIBXML_COMPACT);
                 break;
             case 'php':
                 $res = waUtils::varExportToFile($this->info, $path);
                 break;
             default:
                 //nothing todo
                 break;
         }
     }
     return $res;
 }
 public function execute()
 {
     $contact_model = new waContactModel();
     if ($contact_model->countAll()) {
         $this->redirect($this->getConfig()->getBackendUrl(true));
     }
     if (($locale = waRequest::get('lang')) && waLocale::getInfo($locale)) {
         // set locale
         wa()->setLocale($locale);
         // save to database default locale
         $app_settings_model = new waAppSettingsModel();
         $app_settings_model->set('webasyst', 'locale', $locale);
     }
     if (file_exists($this->getConfig()->getRootPath() . '/install.php')) {
         @unlink($this->getConfig()->getRootPath() . '/install.php');
     }
     if (waRequest::getMethod() == 'post') {
         $errors = array();
         $login = waRequest::post('login');
         $validator = new waLoginValidator();
         if (!$validator->isValid($login)) {
             $errors['login'] = implode("<br />", $validator->getErrors());
         }
         $password = waRequest::post('password');
         $password_confirm = waRequest::post('password_confirm');
         if ($password !== $password_confirm) {
             $errors['password'] = _w('Passwords do not match');
         }
         $email = waRequest::post('email');
         $validator = new waEmailValidator();
         if (!$validator->isValid($email)) {
             $errors['email'] = implode("<br />", $validator->getErrors());
         }
         if ($errors) {
             $this->view->assign('errors', $errors);
         } else {
             // save account name
             $app_settings_model = new waAppSettingsModel();
             $app_settings_model->set('webasyst', 'name', waRequest::post('account_name'));
             if ($email) {
                 $app_settings_model->set('webasyst', 'email', $email);
                 $app_settings_model->set('webasyst', 'sender', $email);
             }
             // create user
             $user = new waUser();
             $firstname = waRequest::post('firstname');
             $user['firstname'] = $firstname ? $firstname : $login;
             $user['lastname'] = waRequest::post('lastname');
             $user['is_user'] = 1;
             $user['login'] = $login;
             $user['password'] = $password;
             $user['email'] = $email;
             $user['locale'] = wa()->getLocale();
             $user['create_method'] = 'install';
             if ($errors = $user->save()) {
                 $result = array();
                 foreach ($errors as $k => $v) {
                     $result['all'][] = $k . ": " . (is_array($v) ? implode(', ', $v) : $v);
                 }
                 $result['all'] = implode("\r\n", $result['all']);
                 $this->view->assign('errors', $result);
             } else {
                 $user->setRight('webasyst', 'backend', 1);
                 waSystem::getInstance()->getAuth()->auth(array('login' => $login, 'password' => $password));
                 $path = $this->getConfig()->getPath('config');
                 // check routing.php
                 if (!file_exists($path . '/routing.php')) {
                     $apps = wa()->getApps();
                     $data = array();
                     $domain = $this->getConfig()->getDomain();
                     $site = false;
                     foreach ($apps as $app_id => $app) {
                         if ($app_id == 'site') {
                             $site = true;
                         } elseif (!empty($app['frontend'])) {
                             $routing = array('url' => $app_id . '/*', 'app' => $app_id);
                             if (!empty($app['routing_params']) && is_array($app['routing_params'])) {
                                 $routing = array_merge($routing, $app['routing_params']);
                             }
                             $data[$domain][] = $routing;
                         }
                     }
                     if ($site) {
                         $data[$domain][] = array('url' => '*', 'app' => 'site');
                     }
                     waUtils::varExportToFile($data, $path . '/routing.php');
                 }
                 // redirect to backend
                 $this->redirect($this->getConfig()->getBackendUrl(true));
             }
         }
     }
 }
 public function save(&$settings)
 {
     $config = $this->getConfig();
     $settings['image_sharpen'] = waRequest::post('image_sharpen') ? 1 : 0;
     $settings['image_save_original'] = waRequest::post('image_save_original') ? 1 : 0;
     $settings['image_thumbs_on_demand'] = waRequest::post('image_thumbs_on_demand') ? 1 : 0;
     if ($settings['image_thumbs_on_demand']) {
         $settings['image_max_size'] = waRequest::post('image_max_size', 1000, waRequest::TYPE_INT);
         $big_size = $config->getImageSize('big');
         if ($settings['image_max_size'] < $big_size) {
             $settings['image_max_size'] = $big_size;
         }
     }
     // delete sizes
     if ($delete = waRequest::post('delete', array(), waRequest::TYPE_ARRAY_INT)) {
         foreach ($delete as $k) {
             if (isset($settings['image_sizes'][$k])) {
                 unset($settings['image_sizes'][$k]);
             }
         }
     }
     // sizes
     if ($types = waRequest::post('size_type', array())) {
         $sizes = waRequest::post('size', array());
         $width = waRequest::post('width', array());
         $height = waRequest::post('height', array());
         foreach ($types as $k => $type) {
             if ($type == 'rectangle') {
                 $w = $this->checkSize($width[$k]);
                 $h = $this->checkSize($height[$k]);
                 if ($w && $h) {
                     $settings['image_sizes'][] = $w . 'x' . $h;
                 }
             } else {
                 $size = $this->checkSize($sizes[$k]);
                 if (!$size) {
                     continue;
                 }
                 switch ($type) {
                     case 'crop':
                         $settings['image_sizes'][] = $size . 'x' . $size;
                         break;
                     case 'height':
                         $settings['image_sizes'][] = '0x' . $size;
                         break;
                     case 'width':
                         $settings['image_sizes'][] = $size . 'x0';
                         break;
                     case 'max':
                         $settings['image_sizes'][] = $size;
                         break;
                 }
             }
         }
     }
     $settings['image_sizes'] = array_values((array) $settings['image_sizes']);
     $config_file = $config->getConfigPath('config.php');
     $settings['enable_2x'] = waRequest::post('enable_2x') ? 1 : 0;
     foreach (array('image_save_quality', 'image_save_quality_2x') as $k) {
         $settings[$k] = waRequest::post($k, '', waRequest::TYPE_STRING_TRIM);
         if ($settings[$k] == '') {
             $settings[$k] = $k == 'image_save_quality_2x' ? 70 : 90;
         } else {
             $settings[$k] = (double) $settings[$k];
             if ($settings[$k] < 0) {
                 $settings[$k] = 0;
             }
             if ($settings[$k] > 100) {
                 $settings[$k] = 100;
             }
             $settings[$k] = str_replace(',', '.', $settings[$k]);
         }
     }
     waUtils::varExportToFile($settings, $config_file);
 }
Esempio n. 29
0
 public static function getAllTimeZones()
 {
     $file = dirname(__FILE__) . "/data/timezones.php";
     if (file_exists($file)) {
         return include $file;
     }
     $data = DateTimeZone::listIdentifiers();
     $time_zones = array();
     foreach ($data as $time_zone_id) {
         $t = explode('/', $time_zone_id, 2);
         $date_time = new DateTime('now');
         $tz = new DateTimeZone($time_zone_id);
         $date_time->setTimezone($tz);
         $offset = (double) $date_time->getOffset() / 3600;
         $group = count($tz->getTransitions(strtotime('-1 year'), time()));
         if (isset($t[1])) {
             $time_zones[$offset][$group][$t[0]][] = $t[1];
         } else {
             $time_zones[$offset][$group][''][] = $t[0];
         }
     }
     ksort($time_zones);
     $result = array();
     foreach ($time_zones as $offset => $group_offset_zones) {
         foreach ($group_offset_zones as $group => $offset_zones) {
             if ($offset >= 10) {
                 $str_offset = '+' . $offset;
             } elseif ($offset >= 0 && $offset < 10) {
                 $str_offset = '+0' . $offset;
             } elseif ($offset < 0 && $offset > -10) {
                 $str_offset = '−0' . abs($offset);
             } elseif ($offset <= -10) {
                 $str_offset = '−' . abs($offset);
             }
             foreach ($offset_zones as $continent => $zones) {
                 if (count($zones) <= 5) {
                     $result[($continent ? $continent . "/" : '') . $zones[0]] = array($str_offset, $zones);
                 } else {
                     $i = 0;
                     $n = count($zones);
                     while ($i < $n) {
                         $tmp = array();
                         for ($j = 0; $j < 5 && $i + $j < $n; $j++) {
                             $z = $zones[$i + $j];
                             if (($k = strpos($z, '/')) !== false) {
                                 $z = substr($z, $k + 1);
                             }
                             $tmp[] = $z;
                         }
                         $result[$continent . "/" . $zones[$i]] = array($str_offset, $tmp);
                         $i += 5;
                     }
                 }
             }
         }
     }
     waUtils::varExportToFile($result, dirname(__FILE__) . "/data/timezones.php");
     return $result;
 }
 /**
  * @param array $settings
  */
 protected function save(&$settings)
 {
     $settings['sharpen'] = waRequest::post('sharpen') ? 1 : 0;
     $settings['save_original'] = waRequest::post('save_original') ? 1 : 0;
     $settings['thumbs_on_demand'] = waRequest::post('thumbs_on_demand') ? 1 : 0;
     if ($settings['thumbs_on_demand']) {
         $settings['max_size'] = waRequest::post('max_size', 1000, 'int');
         $big_size = $this->getConfig()->getSize('big');
         if ($settings['max_size'] < $big_size) {
             $settings['max_size'] = $big_size;
         }
     } elseif (isset($settings['max_size'])) {
         unset($settings['max_size']);
     }
     // delete sizes
     if ($delete = waRequest::post('delete', array(), waRequest::TYPE_ARRAY_INT)) {
         foreach ($delete as $k) {
             if (isset($settings['sizes'][$k])) {
                 unset($settings['sizes'][$k]);
             }
         }
     }
     // sizes
     if ($types = waRequest::post('size_type', array())) {
         $sizes = waRequest::post('size', array());
         $width = waRequest::post('width', array());
         $height = waRequest::post('height', array());
         foreach ($types as $k => $type) {
             if ($type == 'rectangle') {
                 $w = $this->checkSize($width[$k], $settings);
                 $h = $this->checkSize($height[$k], $settings);
                 if ($w && $h) {
                     $settings['sizes'][] = $w . 'x' . $h;
                 }
             } else {
                 $size = $this->checkSize($sizes[$k], $settings);
                 if (!$size) {
                     continue;
                 }
                 switch ($type) {
                     case 'crop':
                         $settings['sizes'][] = $size . 'x' . $size;
                         break;
                     case 'height':
                         $settings['sizes'][] = '0x' . $size;
                         break;
                     case 'width':
                         $settings['sizes'][] = $size . 'x0';
                         break;
                     case 'max':
                         $settings['sizes'][] = $size;
                         break;
                 }
             }
         }
     }
     $settings['sizes'] = array_values($settings['sizes']);
     $config_file = $this->getConfig()->getConfigPath('config.php');
     waUtils::varExportToFile($settings, $config_file);
 }