public function execute()
 {
     $messages = installerMessage::getInstance()->handle(waRequest::get('msg'));
     installerHelper::checkUpdates($messages);
     if ($m = $this->view->getVars('messages')) {
         $messages = array_merge($m, $messages);
     }
     $this->view->assign('messages', $messages);
     $plugins = 'wa-plugins/payment';
     $apps = wa()->getApps();
     if (isset($apps['shop'])) {
         $plugins = 'shop';
     } else {
         ksort($apps);
         foreach ($apps as $app => $info) {
             if (!empty($info['plugins'])) {
                 $plugins = $app;
                 break;
             }
         }
     }
     $model = new waAppSettingsModel();
     $this->view->assign('update_counter', $model->get($this->getApp(), 'update_counter'));
     $this->view->assign('module', waRequest::get('module', 'backend'));
     $this->view->assign('default_query', array('plugins' => $plugins));
 }
 public function execute()
 {
     $extended = false;
     $this->view->assign('action', 'update');
     $update_counter = 0;
     $messages = installerMessage::getInstance()->handle(waRequest::get('msg'));
     $this->view->assign('error', false);
     $app = null;
     try {
         $app_list = installerHelper::getApps($messages, $update_counter);
         $slug = waRequest::get('slug');
         $vendor = waRequest::get('vendor');
         $edition = waRequest::get('edition');
         foreach ($app_list as $info) {
             if ($info['slug'] == $slug && $info['vendor'] == $vendor && $info['edition'] == $edition) {
                 $app = $info;
                 break;
             }
         }
         if (!$app) {
             throw new waException(_w('Application not found'));
         }
     } catch (Exception $ex) {
         $msg = installerMessage::getInstance()->raiseMessage($ex->getMessage(), installerMessage::R_FAIL);
         $this->redirect(array('module' => 'apps', 'msg' => $msg));
     }
     $this->view->assign('identity_hash', installerHelper::getHash());
     $this->view->assign('messages', $messages);
     $this->view->assign('update_counter', $update_counter);
     $this->view->assign('app', $app);
     $this->view->assign('title', sprintf(_w('Application "%s"'), $app['name']));
 }
 /**
  *
  * @return installerMessage
  */
 public static function getInstance()
 {
     if (!self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
 public function execute()
 {
     $this->view->assign('action', 'update');
     $counter = array('total' => 0, 'applicable' => 0, 'payware' => 0);
     $app_list = array();
     $this->view->assign('error', false);
     $messages = installerMessage::getInstance()->handle(waRequest::get('msg'));
     try {
         $app_list = installerHelper::getApps($messages, $counter);
         foreach ($app_list as &$info) {
             if ($info['slug'] == 'installer') {
                 $info['name'] = _w('Webasyst Framework');
                 break;
             }
         }
         unset($info);
         $plugin_list = installerHelper::getSystemPlugins($messages, $counter);
     } catch (Exception $ex) {
         $messages[] = array('text' => $ex->getMessage(), 'result' => 'fail');
     }
     installerHelper::checkUpdates($messages);
     $this->view->assign('messages', $messages);
     //$this->view->assign('install_counter', $model->get($this->getApp(), 'install_counter'));
     $this->getConfig()->setCount($counter['total'] ? $counter['total'] : null);
     $this->view->assign('update_counter', $counter['total']);
     $this->view->assign('update_counter_applicable', $counter['applicable']);
     $this->view->assign('apps', $app_list);
     $this->view->assign('plugins', $plugin_list);
     $this->view->assign('identity_hash', installerHelper::getHash());
     $this->view->assign('title', _w('Updates'));
 }
Esempio n. 5
0
 public function execute()
 {
     $messages = installerMessage::getInstance()->handle(waRequest::get('msg'));
     $counter = array('total' => 0, 'applicable' => 0, 'payware' => 0);
     $items = array();
     try {
         $items = installerHelper::getUpdates();
         $counter = installerHelper::getUpdatesCounter(null);
         if (isset($items['installer'])) {
             $items['installer']['name'] = _w('Webasyst Framework');
         }
     } catch (Exception $ex) {
         $messages[] = array('text' => $ex->getMessage(), 'result' => 'fail');
     }
     installerHelper::checkUpdates($messages);
     if (!waRequest::get('_')) {
         $this->setLayout(new installerBackendLayout());
         if ($messages) {
             $this->getLayout()->assign('messages', $messages);
         }
         $this->getLayout()->assign('update_counter', $counter['total']);
         $this->getLayout()->assign('no_ajax', true);
     } else {
         $this->view->assign('messages', $messages);
     }
     $this->view->assign('error', false);
     $this->view->assign('update_counter', $counter['total']);
     $this->view->assign('update_counter_applicable', $counter['applicable']);
     $this->view->assign('items', $items);
     $this->view->assign('domain', installerHelper::getDomain());
     $this->view->assign('title', _w('Updates'));
 }
 function execute()
 {
     try {
         $message = array();
         $settings = waRequest::get('setting');
         if ($settings) {
             $model = new waAppSettingsModel();
             $changed = false;
             foreach ((array) $settings as $setting) {
                 if (in_array($setting, array('auth_form_background'))) {
                     if ($value = $model->get('webasyst', $setting)) {
                         waFiles::delete(wa()->getDataPath($value, true, 'webasyst'));
                         $message[] = _w('Image deleted');
                     }
                 } else {
                     $changed = true;
                 }
                 $model->set('webasyst', $setting, false);
             }
             if ($changed) {
                 $message[] = _w('Settings saved');
             }
         }
         $params = array('module' => 'settings', 'msg' => installerMessage::getInstance()->raiseMessage(implode(', ', $message)));
         $this->redirect($params);
     } catch (waException $ex) {
         $msg = installerMessage::getInstance()->raiseMessage($ex->getMessage(), installerMessage::R_FAIL);
         $params = array('module' => 'settings', 'msg' => $msg);
         $this->redirect($params);
     }
 }
 public function execute()
 {
     $extended = false;
     $this->view->assign('action', 'update');
     $this->view->assign('error', false);
     $messages = installerMessage::getInstance()->handle(waRequest::get('msg'));
     $update_counter = null;
     $this->view->assign('apps', installerHelper::getApps($messages, $update_counter));
     installerHelper::checkUpdates($messages);
     $this->view->assign('identity_hash', installerHelper::getHash());
     $this->view->assign('messages', $messages);
     $model = new waAppSettingsModel();
     $this->view->assign('update_counter', $model->get($this->getApp(), 'update_counter'));
     $this->view->assign('extended', $extended);
     $this->view->assign('title', _w('Installer'));
 }
 public function execute()
 {
     $extended = false;
     $this->view->assign('action', 'update');
     $this->view->assign('error', false);
     $messages = installerMessage::getInstance()->handle(waRequest::get('msg'));
     $filter = array();
     $filter['enabled'] = true;
     if ($this->module) {
         $filter['extras'] = $this->module;
     }
     $applications = installerHelper::getApps($messages, $this->update_counter, $filter);
     $app = false;
     try {
         $subject = waRequest::get('subject');
         if (empty($subject)) {
             $storage = wa()->getStorage();
             $search = array();
             $extras = preg_replace('/s$/', '', $this->module);
             $slug_id = "installer_select_{$extras}";
             $vendor_id = "installer_select_{$extras}_vendor";
             $search['slug'] = waRequest::get('slug', $storage->read($slug_id));
             $search['vendor'] = waRequest::get('vendor', $storage->read($vendor_id));
             if ((!$this->redirect || array_filter($search, 'strlen')) && ($app = installerHelper::search($applications, $search))) {
                 $storage->write($slug_id, $search['slug'] = $app['slug']);
                 $storage->write($vendor_id, $search['vendor'] = $app['vendor']);
             } else {
                 reset($applications);
                 if ($app = current($applications)) {
                     $this->redirect(array('module' => $this->module, 'slug' => $app['slug'], 'vendor' => $app['vendor']));
                 }
             }
             $this->view->assign('slug', $search['slug']);
             $this->view->assign('vendor', $search['vendor']);
             $this->view->assign('selected_app', $app);
         }
     } catch (Exception $ex) {
         $messages[] = array('text' => $ex->getMessage(), 'result' => 'fail');
     }
     installerHelper::checkUpdates($messages);
     $model = new waAppSettingsModel();
     $this->view->assign('update_counter', $model->get($this->getApp(), 'update_counter'));
     $this->view->assign('messages', $messages);
     $this->view->assign('apps', $applications);
     $this->view->assign('extended', $extended);
     $this->view->assign('title', _w('Installer'));
 }
 public function execute()
 {
     //TODO use POST
     $app_ids = waRequest::request('app_id');
     try {
         if (installerHelper::isDeveloper()) {
             throw new waException(_w('Unable to delete application (developer version is on)'));
         }
         if (!$app_ids || !is_array($app_ids)) {
             throw new waException(_w('Application not found'));
         }
         foreach ($app_ids as &$info) {
             if (!is_array($info)) {
                 $info = array('vendor' => $info);
             }
         }
         unset($info);
         $this->apps = new waInstallerApps();
         $app_list = $this->apps->getApps(array('installed' => true));
         $deleted_apps = array();
         foreach ($app_list as $info) {
             $app_id = $info['slug'];
             if (isset($app_ids[$app_id]) && $app_ids[$app_id]['vendor'] == $info['vendor']) {
                 if (!empty($info['installed']['system'])) {
                     throw new waException(sprintf(_w('Can not delete system application "%s"'), $info['name']));
                 }
                 $deleted_apps[] = $this->deleteApp($app_id);
             }
         }
         wa()->setActive('installer');
         if (!$deleted_apps) {
             throw new waException(_w('Application not found'));
         }
         $message = _w('Application %s has been deleted', 'Applications %s have been deleted', min(2, count($deleted_apps)), false);
         $message = sprintf($message, implode(', ', $deleted_apps));
         $msg = installerMessage::getInstance()->raiseMessage($message);
     } catch (Exception $ex) {
         wa()->setActive('installer');
         $msg = installerMessage::getInstance()->raiseMessage($ex->getMessage(), installerMessage::R_FAIL);
     }
     //'module' => installerHelper::getModule(),
     $this->redirect(array('msg' => $msg));
 }
Esempio n. 10
0
 public function execute()
 {
     if (!waRequest::get('_')) {
         $this->setLayout(new installerBackendLayout());
     }
     $options = array('local' => false, 'filter' => (array) waRequest::get('filter'));
     try {
         $messages = installerMessage::getInstance()->handle(waRequest::get('msg'));
         $this->view->assign('apps', $apps = installerHelper::getInstaller()->getApps($options));
         $vendor_name = null;
         if (!empty($options['filter']['vendor']) && empty($vendor_name)) {
             foreach ($apps as $app) {
                 if (!empty($app['vendor_name'])) {
                     $vendor_name = $app['vendor_name'];
                     break;
                 }
             }
         }
         $this->view->assign('vendor_name', $vendor_name);
     } catch (Exception $ex) {
         $messages[] = array('text' => $ex->getMessage(), 'result' => 'fail');
         $this->view->assign('messages', $messages);
     }
 }
 public function execute()
 {
     try {
         $message = array();
         $settings = waRequest::get('setting');
         if ($settings) {
             $model = new waAppSettingsModel();
             $changed = false;
             foreach ((array) $settings as $setting) {
                 if (in_array($setting, array('auth_form_background'))) {
                     $images_path = wa()->getDataPath(null, true, 'webasyst');
                     if ($images = waFiles::listdir($images_path)) {
                         foreach ($images as $image) {
                             if (is_file($images_path . '/' . $image) && !preg_match('@\\.(jpe?g|png|gif|bmp)$@', $image)) {
                                 waFiles::delete($images_path . "/" . $image);
                             }
                         }
                         $message[] = _w('Image deleted');
                     }
                 } else {
                     $changed = true;
                 }
                 $model->del('webasyst', $setting);
             }
             if ($changed) {
                 $message[] = _w('Settings saved');
             }
         }
         $params = array('module' => 'settings', 'msg' => installerMessage::getInstance()->raiseMessage(implode(', ', $message)));
         $this->redirect($params);
     } catch (waException $ex) {
         $msg = installerMessage::getInstance()->raiseMessage($ex->getMessage(), installerMessage::R_FAIL);
         $params = array('module' => 'settings', 'msg' => $msg);
         $this->redirect($params);
     }
 }
 public function execute()
 {
     $module = 'update';
     $url = parse_url(waRequest::server('HTTP_REFERER'), PHP_URL_QUERY);
     if (preg_match('/(^|&)module=(update|apps|plugins)($|&)/', $url, $matches)) {
         $module = $matches[2];
     }
     try {
         $updater = new waInstaller(waInstaller::LOG_TRACE);
         $state = $updater->getState();
         if (!isset($state['stage_status']) || $state['stage_name'] != waInstaller::STAGE_NONE && $state['heartbeat'] > waInstaller::TIMEOUT_RESUME + 5 || $state['stage_name'] == waInstaller::STAGE_UPDATE && $state['heartbeat'] || $state['stage_status'] == waInstaller::STATE_ERROR && $state['heartbeat'] || $state['stage_name'] == waInstaller::STAGE_NONE && $state['heartbeat'] === false) {
             $updater->setState();
             $this->view->assign('action', 'update');
             $app_ids = waRequest::request('app_id');
             $default_info = array('vendor' => waInstallerApps::VENDOR_SELF, 'edition' => '');
             $vendors = array();
             if ($app_ids && is_array($app_ids)) {
                 foreach ($app_ids as $app_id => &$info) {
                     if (!is_array($info)) {
                         if (strpos($info, ':') === false) {
                             $vendor = $info;
                             $edition = '';
                         } else {
                             list($vendor, $edition) = explode(':', $info, 2);
                         }
                         $info = array('vendor' => $vendor, 'edition' => $edition);
                     } else {
                         $info = array_merge($info, $default_info);
                     }
                     $vendors[] = $info['vendor'];
                     unset($info);
                 }
             } else {
                 $app_ids = array();
             }
             $vendors = array_unique($vendors);
             if (!$vendors) {
                 $vendors = array();
             }
             $model = new waAppSettingsModel();
             $license = $model->get('webasyst', 'license', false);
             $locale = wa()->getLocale();
             $apps = new waInstallerApps($license, $locale);
             $app_list = $vendors ? $apps->getApplicationsList(false, $vendors) : array();
             $model->ping();
             $queue_apps = array();
             foreach ($app_list as &$info) {
                 $app_id = $info['slug'];
                 if ($app_id == 'installer') {
                     $info['name'] = _w('Webasyst Framework');
                 }
                 if (isset($app_ids[$app_id])) {
                     if (installerHelper::equals($app_ids[$app_id], $info)) {
                         $queue_apps[] = $info;
                     }
                 }
                 if (!empty($info['extras'])) {
                     foreach ($info['extras'] as $type => &$extras) {
                         foreach ($extras as $extra_id => &$extras_info) {
                             $extras_id = $extras_info['slug'];
                             $extras_info['name'] .= " ({$info['name']})";
                             if (isset($app_ids[$extras_id]) && installerHelper::equals($app_ids[$extras_id], $extras_info)) {
                                 $queue_apps[] = $extras_info;
                             }
                         }
                         unset($extras_info);
                     }
                     unset($extras);
                 }
                 unset($info);
             }
             $system_list = $apps->getSystemList();
             foreach ($system_list as $item) {
                 if (!empty($item['subject']) && $item['subject'] == 'systemplugins' && isset($app_ids[$item['slug']])) {
                     $queue_apps[] = $item;
                 }
             }
             if (!$queue_apps) {
                 throw new waException(_w('Please select items for update'));
             }
             $this->view->assign('queue_apps', $queue_apps);
             $this->view->assign('apps', $app_list);
             $this->view->assign('install', waRequest::request('install'));
             $this->view->assign('title', _w('Updates'));
         } else {
             $this->redirect(array('module' => $module, 'msg' => installerMessage::getInstance()->raiseMessage(_w('Update is already in progress. Please wait while previous update session is finished before starting update session again.'), 'fail')));
         }
     } catch (Exception $ex) {
         $this->redirect(array('module' => $module, 'msg' => installerMessage::getInstance()->raiseMessage($ex->getMessage(), installerMessage::R_FAIL)));
     }
 }
 function execute()
 {
     $module = 'apps';
     $url = parse_url(waRequest::server('HTTP_REFERER'), PHP_URL_QUERY);
     if (preg_match('/(^|&)module=(update|apps|plugins)($|&)/', $url, $matches)) {
         $module = $matches[2];
     }
     $app_ids = waRequest::get('app_id');
     try {
         if (!$app_ids || !is_array($app_ids)) {
             throw new waException(_w('Application not found'));
         }
         $vendors = array();
         foreach ($app_ids as $app_id => &$info) {
             if (!is_array($info)) {
                 $info = array('vendor' => $info);
             }
             $vendors[] = $info['vendor'];
             unset($info);
         }
         $vendors = array_unique($vendors);
         $apps = new waInstallerApps();
         $app_list = $apps->getApplicationsList(true, $vendors);
         $deleted_apps = array();
         if (installerHelper::isDeveloper()) {
             throw new waException(_w('Unable to delete application (developer version is on)'));
         }
         foreach ($app_list as $info) {
             $app_id = $info['slug'];
             if (isset($app_ids[$app_id]) && $app_ids[$app_id]['vendor'] == $info['vendor']) {
                 if (isset($info['system']) && $info['system']) {
                     throw new waException(sprintf(_w('Can not delete system application "%s"'), $info['name']));
                 }
                 $apps->updateRoutingConfig($app_id, false);
                 $apps->updateAppConfig($app_id, null);
                 //remove db tables and etc
                 $paths = array();
                 $app_instance = waSystem::getInstance($app_id);
                 $plugins = $app_instance->getConfig()->getPlugins();
                 foreach ($plugins as $plugin_id => $plugin) {
                     if ($plugin && ($plugin_instance = $app_instance->getPlugin($plugin_id))) {
                         $plugin_instance->uninstall();
                     }
                     $apps->updateAppPluginsConfig($app_id, $plugin_id, null);
                     //wa-apps/$app_id/plugins/$slug
                     $paths[] = wa()->getAppPath("plugins/{$plugin_id}", $app_id);
                     foreach ($paths as $path) {
                         waFiles::delete($path, true);
                     }
                     $paths = array();
                 }
                 $app_instance->getConfig()->uninstall();
                 //XXX called at uninstall
                 //$paths[] = wa()->getAppCachePath(null, $app_id);//wa-cache/apps/$app_id/
                 $paths[] = wa()->getTempPath(null, $app_id);
                 //wa-cache/temp/$app_id/
                 $paths[] = wa()->getAppCachePath(null, $app_id);
                 //wa-cache/apps/$app_id/
                 $paths[] = wa()->getDataPath(null, true, $app_id);
                 //wa-data/public/$app_id/
                 $paths[] = wa()->getDataPath(null, false, $app_id);
                 //wa-data/protected/$app_id/
                 //XXX uncomplete code
                 //$paths[] = wa()->   null, false, $app_id);//wa-log/$app_id/
                 //XXX uncomplete code
                 //$paths[] = wa()->getAppPath(null, $app_id);//wa-config/$app_id/
                 $paths[] = wa()->getAppPath(null, $app_id);
                 //wa-apps/$app_id/
                 foreach ($paths as $path) {
                     waFiles::delete($path, true);
                 }
                 $deleted_apps[] = $info['name'];
             }
         }
         if (!$deleted_apps) {
             throw new waException(_w('Application not found'));
         }
         $message = _w('Application %s has been deleted', 'Applications %s have been deleted', min(2, count($deleted_apps)), false);
         $message = sprintf($message, implode(', ', $deleted_apps));
         $msg = installerMessage::getInstance()->raiseMessage($message);
         $this->redirect(array('module' => $module, 'msg' => $msg));
     } catch (Exception $ex) {
         $msg = installerMessage::getInstance()->raiseMessage($ex->getMessage(), installerMessage::R_FAIL);
         $this->redirect(array('module' => $module, 'msg' => $msg));
     }
 }
 public function execute()
 {
     $this->init();
     try {
         $updater = new waInstaller(waInstaller::LOG_TRACE);
         $state = $updater->getState();
         if (!isset($state['stage_status']) || $state['stage_name'] != waInstaller::STAGE_NONE && $state['heartbeat'] > waInstaller::TIMEOUT_RESUME + 5 || $state['stage_name'] == waInstaller::STAGE_UPDATE && $state['heartbeat'] || $state['stage_status'] == waInstaller::STATE_ERROR && $state['heartbeat'] || $state['stage_name'] == waInstaller::STAGE_NONE && $state['heartbeat'] === false) {
             $updater->setState();
             $state = $updater->getState();
             $apps = installerHelper::getInstaller();
             $items = $apps->getUpdates(null, $this->getItemsList());
             $queue_apps = array();
             $execute_actions = array(waInstallerApps::ACTION_INSTALL, waInstallerApps::ACTION_CRITICAL_UPDATE, waInstallerApps::ACTION_UPDATE);
             foreach ($items as $app_id => $info) {
                 if (!empty($info['download_url']) && in_array($info['action'], $execute_actions)) {
                     $info['subject'] = 'app';
                     if ($app_id == 'installer') {
                         foreach ($info['download_url'] as $target => $url) {
                             $_info = $info;
                             $_info['download_url'] = $url;
                             $_info['name'] = _w('Webasyst Framework') . ' (' . $target . ')';
                             $this->add($target, $_info);
                             $queue_apps[$target] = $_info;
                             unset($_info);
                         }
                     } else {
                         $target = 'wa-apps/' . $app_id;
                         $this->add($target, $info, $app_id);
                         $queue_apps[$target] = $info;
                     }
                 }
                 foreach (array('themes', 'plugins') as $type) {
                     if (!empty($info[$type]) && is_array($info[$type])) {
                         foreach ($info[$type] as $extra_id => $extras_info) {
                             if (!empty($extras_info['download_url']) && in_array($extras_info['action'], $execute_actions)) {
                                 $extras_info['subject'] = 'app_' . $type;
                                 if ($type == 'themes' && is_array($extras_info['download_url'])) {
                                     foreach ($extras_info['download_url'] as $target => $url) {
                                         $__info = $extras_info;
                                         $__info['download_url'] = $url;
                                         $__info['slug'] = preg_replace('@^wa-apps/@', '', $target);
                                         $__info['app'] = preg_replace('@^wa-apps/([^/]+)/.+$@', '$1', $target);
                                         if (!isset($queue_apps[$target])) {
                                             if ($__info['app'] == $app_id || empty($items[$__info['app']][$type][$extra_id])) {
                                                 if (!empty($items[$__info['app']][$type][$extra_id]['name'])) {
                                                     $__info['name'] .= " ({$info['name']})";
                                                 } elseif ($app_info = wa()->getAppInfo($__info['app'])) {
                                                     $__info['name'] .= " ({$app_info['name']})";
                                                 } else {
                                                     $__info['name'] .= " ({$__info['app']})";
                                                 }
                                                 $this->add($target, $__info);
                                                 $queue_apps[$target] = $__info;
                                             }
                                         }
                                     }
                                 } else {
                                     if (!empty($info['name'])) {
                                         $extras_info['name'] .= " ({$info['name']})";
                                     }
                                     if (strpos($app_id, '/')) {
                                         //system plugins
                                         $target = $app_id . '/' . $extra_id;
                                     } else {
                                         $target = 'wa-apps/' . $app_id . '/' . $type . '/' . $extra_id;
                                     }
                                     $this->add($target, $extras_info, $target);
                                     $queue_apps[$target] = $extras_info;
                                 }
                             }
                         }
                     }
                 }
                 unset($info);
             }
             if (!$queue_apps) {
                 throw new waException(_w('Please select items for update'));
             }
             if (!waRequest::get('_')) {
                 $this->setLayout(new installerBackendLayout());
                 $this->getLayout()->assign('no_ajax', true);
             }
             $this->view->assign('action', 'update');
             $this->view->assign('queue_apps', $queue_apps);
             $install = waRequest::request('install');
             $this->view->assign('install', !empty($install) ? 'install' : '');
             $this->view->assign('title', _w('Updates'));
             $this->view->assign('thread_id', $state['thread_id']);
             $this->view->assign('return_url', waRequest::post('return_url'));
             $cache = new waSerializeCache($this->getApp() . '.' . $state['thread_id']);
             $cache->set($this->urls);
         } else {
             $msg = _w('Update is already in progress. Please wait while previous update session is finished before starting update session again.');
             $this->redirect(array('module' => $this->module, 'msg' => installerMessage::getInstance()->raiseMessage($msg, installerMessage::R_FAIL)));
         }
     } catch (Exception $ex) {
         $this->redirect(array('module' => $this->module, 'msg' => installerMessage::getInstance()->raiseMessage($ex->getMessage(), installerMessage::R_FAIL)));
     }
 }
 public function execute()
 {
     $model = new waAppSettingsModel();
     $settings = array('name' => 'Webasyst', 'url' => wa()->getRootUrl(true), 'auth_form_background' => null, 'auth_form_background_stretch' => 1, 'locale' => 'ru_RU', 'email' => '', 'rememberme' => 1);
     $config_settings = array('debug' => 'boolean');
     $flush_settings = array('debug');
     $config_path = waSystem::getInstance()->getConfigPath() . '/config.php';
     $config = file_exists($config_path) ? include $config_path : array();
     if (!is_array($config)) {
         $config = array();
     }
     $changed = false;
     $flush = false;
     $message = array();
     try {
         $messages = installerMessage::getInstance()->handle(waRequest::get('msg'));
         foreach ($settings as $setting => &$value) {
             if (waRequest::post() && !in_array($setting, array('auth_form_background'))) {
                 $post_value = waRequest::post($setting, '', 'string_trim');
                 if (!is_null($post_value)) {
                     $model->set('webasyst', $setting, $post_value);
                     $changed = true;
                 } elseif (!is_null($value)) {
                     $model->set('webasyst', $setting, '');
                 }
                 $value = $model->get('webasyst', $setting, $value);
             } else {
                 $value = $model->get('webasyst', $setting, $value);
             }
             unset($value);
         }
         $config_changed = false;
         if (waRequest::post()) {
             $config_values = waRequest::post('config');
             if (!is_array($config_values)) {
                 $config_values = array();
             }
             foreach ($config_settings as $setting => $type) {
                 $value = isset($config_values[$setting]) ? $config_values[$setting] : false;
                 switch ($type) {
                     case 'boolean':
                         $value = $value ? true : false;
                         break;
                 }
                 if (!isset($config[$setting]) || $config[$setting] !== $value) {
                     $config[$setting] = $value;
                     $config_changed = true;
                     if (in_array($setting, $flush_settings)) {
                         $flush = true;
                     }
                 }
             }
             if ($config_changed) {
                 waUtils::varExportToFile($config, $config_path);
             }
             if ($flush) {
                 $path_cache = waConfig::get('wa_path_cache');
                 waFiles::delete($path_cache, true);
                 waFiles::protect($path_cache);
             }
             $model->ping();
         }
         if ($changed || $config_changed) {
             $message[] = '[`Settings saved`]';
         }
         $name = preg_replace('/\\?.*$/', '', $settings['auth_form_background']);
         $path = wa()->getDataPath($name, true, 'webasyst');
         $file = waRequest::file('auth_form_background');
         if ($file->uploaded()) {
             if ($name) {
                 waFiles::delete(wa()->getDataPath($name, true, 'webasyst'));
                 $model->set('webasyst', 'auth_form_background', false);
                 $settings['auth_form_background'] = false;
             }
             $ext = 'png';
             if (preg_match('/\\.(png|gif|jpg|jpeg|bmp|tif)$/i', $file->name, $matches)) {
                 $ext = $matches[1];
             }
             $name = 'auth_form_background.' . $ext;
             $path = wa()->getDataPath($name, true, 'webasyst');
             try {
                 $image = $file->waImage();
             } catch (waException $ex) {
                 $message = $ex->getMessage();
                 $tmp_name = $file->tmp_name;
                 if (!preg_match('//u', $tmp_name)) {
                     $tmp_name = iconv('windows-1251', 'utf-8', $tmp_name);
                 }
                 if (strpos($message, $tmp_name) !== false) {
                     throw new waException(preg_replace('/:\\s*$/', '', str_replace($tmp_name, '', $message)));
                 }
                 throw $ex;
             }
             $file->copyTo($path);
             //$image->save($path);
             $name .= '?' . time();
             $model->set('webasyst', 'auth_form_background', $name);
             $settings['auth_form_background'] = $name;
             $message[] = '[`Image uploaded`]';
             $image_info = get_object_vars($image);
             $image_info['file_size'] = filesize($path);
             $image_info['file_name'] = basename($path);
             $this->view->assign('image', $image_info);
         }
         if ($settings['auth_form_background'] && file_exists($path)) {
             $image = new waImage($path);
             $image_info = get_object_vars($image);
             $image_info['file_size'] = filesize($path);
             $image_info['file_name'] = basename($path);
             $this->view->assign('image', $image_info);
             unset($image);
         }
         if ($message) {
             $params = array();
             $params['module'] = 'settings';
             $params['msg'] = installerMessage::getInstance()->raiseMessage(implode(', ', $message));
             $this->redirect($params);
         }
     } catch (waException $ex) {
         $msg = installerMessage::getInstance()->raiseMessage($ex->getMessage(), installerMessage::R_FAIL);
         $params = array('module' => 'settings', 'msg' => $msg);
         if ($message) {
             //$params['success'] = base64_encode(implode(', ', $message));
         }
         $this->redirect($params);
     }
     $this->view->assign('update_counter', $model->get($this->getApp(), 'update_counter'));
     //$this->view->assign('install_counter', $model->get($this->getApp(), 'install_counter'));
     $apps = wa()->getApps();
     $version = $apps['installer']['version'];
     if (abs(time() - $apps['installer']['build']) > 2) {
         $version .= '.' . $apps['installer']['build'];
     }
     $this->view->assign('version', $version);
     $this->view->assign('settings', $settings);
     $this->view->assign('config', $config);
     $this->view->assign('action', 'settings');
     $this->view->assign('messages', $messages);
     $locales = waSystem::getInstance()->getConfig()->getLocales('name');
     $this->view->assign('locales', $locales);
     $this->view->assign('title', _w('Settings'));
 }
 function execute()
 {
     if (!$this->extras_type && preg_match('/^installer(\\w+)RemoveAction$/', get_class($this), $matches)) {
         $this->extras_type = strtolower($matches[1]);
     }
     $module = $this->extras_type;
     $url = parse_url(waRequest::server('HTTP_REFERER'), PHP_URL_QUERY);
     if (preg_match("/(^|&)module=(update|apps| {\n            {$this->extras_type}})(\$|&)/", $url, $matches)) {
         $module = $matches[2];
     }
     $extras_ids = waRequest::get('extras_id');
     try {
         /*
         _w('Application themes not found');
         _w('Application plugins not found');
         */
         //$message =  sprintf('Application %s not found', $this->extras_type);
         //throw new waException(_w($message));
         if (installerHelper::isDeveloper()) {
             /*
             _w("Unable to delete application's themes (developer version is on)");
             _w("Unable to delete application's plugins (developer version is on)");
             */
             $message = "Unable to delete application's {$this->extras_type} (developer version is on)";
             throw new waException(_w($message));
         }
         $vendors = array();
         foreach ($extras_ids as $extras_id => &$info) {
             if (!is_array($info)) {
                 $info = array('vendor' => $info);
             }
             $vendors[] = $info['vendor'];
             unset($info);
         }
         $vendors = array_unique($vendors);
         $locale = wa()->getLocale();
         $this->installer = new waInstallerApps(null, $locale);
         $app_list = $this->installer->getApplicationsList(true);
         $deleted_extras = array();
         foreach ($app_list as $app) {
             if (isset($app['extras']) && $app['extras'] && isset($app['extras'][$this->extras_type]) && $app['extras'][$this->extras_type]) {
                 foreach ($app['extras'][$this->extras_type] as $extras_id => $info) {
                     $slug = $info['slug'];
                     if (isset($extras_ids[$slug]) && $extras_ids[$slug]['vendor'] == $info['current']['vendor']) {
                         if (isset($info['system']) && $info['system']) {
                             /*
                             _w("Can not delete system application's themes \"%s\"");
                             _w("Can not delete system application's plugins \"%s\"");
                             */
                             $message = "Can not delete system application's {$this->extras_type} \"%s\"";
                             throw new waException(sprintf(_w($message), $info['name']));
                         }
                         if ($this->removeExtras($app['slug'], $extras_id, $info)) {
                             $deleted_extras[] = "{$info['name']} ({$app['name']})";
                         }
                         unset($extras_ids[$slug]);
                     }
                 }
             }
         }
         foreach ($extras_ids as $slug => $data) {
             if (preg_match('@^wa-plugins/([^/]+/[^/]+)$@', $slug, $matches)) {
                 $path = wa()->getConfig()->getPath('plugins') . '/' . $matches[1];
                 $info_path = $path . '/lib/config/plugin.php';
                 if (file_exists($info_path) && ($info = (include $info_path))) {
                     waFiles::delete($path, true);
                     $deleted_extras[] = empty($info['name']) ? $matches[1] : $info['name'];
                 }
             }
         }
         if (!$deleted_extras) {
             $message = sprintf('Application %s not found', $this->extras_type);
             throw new waException(_w($message));
         }
         /*
         _w('Application plugin %s has been deleted', 'Applications plugins %s have been deleted');
         _w('Application theme %s has been deleted', 'Applications themes %s have been deleted');
         */
         $message_singular = sprintf('Application %s %%s has been deleted', preg_replace('/s$/', '', $this->extras_type));
         $message_plural = sprintf('Applications %a %%s have been deleted', $this->extras_type);
         $message = sprintf(_w($message_singular, $message_plural, count($deleted_extras), false), implode(', ', $deleted_extras));
         $msg = installerMessage::getInstance()->raiseMessage($message);
         $this->redirect(array('module' => $module, 'msg' => $msg));
     } catch (Exception $ex) {
         $msg = installerMessage::getInstance()->raiseMessage($ex->getMessage(), installerMessage::R_FAIL);
         $this->redirect(array('module' => $module, 'msg' => $msg));
     }
 }
 public function execute()
 {
     $this->init();
     $extras_ids = waRequest::post('extras_id');
     try {
         /*
         _w('Application themes not found');
         _w('Application plugins not found');
         */
         foreach ($extras_ids as &$info) {
             if (!is_array($info)) {
                 $info = array('vendor' => $info);
             }
             unset($info);
         }
         $options = array('installed' => true, 'local' => true);
         if ($this->extras_type == 'plugins') {
             $options['system'] = true;
         }
         $this->installer = installerHelper::getInstaller();
         $app_list = $this->installer->getItems($options);
         $queue = array();
         foreach ($extras_ids as $slug => $info) {
             $slug_chunks = explode('/', $slug);
             if ($slug_chunks[0] == 'wa-plugins') {
                 $app_id = $slug_chunks[0] . '/' . $slug_chunks[1];
             } else {
                 $app_id = reset($slug_chunks);
             }
             if (isset($app_list[$app_id]) || $slug_chunks == 'wa-plugins') {
                 $app = $app_list[$app_id];
                 if (($installed = $this->installer->getItemInfo($slug, $options)) && $info['vendor'] == $installed['vendor']) {
                     if (!empty($installed['installed']['system'])) {
                         /*
                         _w("Can not delete system application's themes \"%s\"");
                         _w("Can not delete system application's plugins \"%s\"");
                         */
                         $message = "Can not delete system application's {$this->extras_type} \"%s\"";
                         throw new waException(sprintf(_w($message), _wd($slug, isset($info['name']) ? $info['name'] : '???')));
                     }
                     $queue[] = array('app_slug' => $app_id, 'ext_id' => $installed['id'], 'name' => sprintf("%s (%s)", _wd($slug, $installed['installed']['name']), _wd($app_id, $app['name'])));
                     unset($extras_ids[$slug]);
                 }
             }
         }
         $deleted_extras = array();
         foreach ($queue as $q) {
             if ($this->removeExtras($q['app_slug'], $q['ext_id'])) {
                 $deleted_extras[] = $q['name'];
             }
         }
         if (!$deleted_extras) {
             $message = sprintf('Application %s not found', $this->extras_type);
             throw new waException(_w($message));
         }
         /*
         _w('Application plugin %s has been deleted', 'Applications plugins %s have been deleted');
         _w('Application theme %s has been deleted', 'Applications themes %s have been deleted');
         */
         $message_singular = sprintf('Application %s %%s has been deleted', preg_replace('/s$/', '', $this->extras_type));
         $message_plural = sprintf('Applications %a %%s have been deleted', $this->extras_type);
         $message = sprintf(_w($message_singular, $message_plural, count($deleted_extras), false), implode(', ', $deleted_extras));
         $msg = installerMessage::getInstance()->raiseMessage($message);
         $this->redirect('?msg=' . $msg . '#/' . $this->extras_type . '/');
     } catch (Exception $ex) {
         $msg = installerMessage::getInstance()->raiseMessage($ex->getMessage(), installerMessage::R_FAIL);
         $this->redirect('?msg=' . $msg . '#/' . $this->extras_type . '/');
     }
 }
 public function execute()
 {
     if (!waRequest::get('_') && false) {
         $this->setLayout(new installerBackendLayout());
     }
     $this->view->assign('action', 'update');
     $this->view->assign('error', false);
     $messages = installerMessage::getInstance()->handle(waRequest::get('msg'));
     $filter = array();
     if ($this->module) {
         $filter['extras'] = $this->module;
     }
     $app_options = $this->getAppOptions();
     try {
         $applications = installerHelper::getInstaller()->getApps($app_options, $filter);
         $this->extendApplications($applications);
         $subject = waRequest::get('subject');
         if (empty($subject)) {
             $extras = array();
             $search = array();
             $options = $this->getExtrasOptions();
             $slug = waRequest::get('slug');
             if (!empty($options['filter']['slug'])) {
                 $slug = $options['filter']['slug'];
                 unset($options['filter']['slug']);
             }
             $search['slug'] = array_filter(array_map('trim', explode(',', $slug)), 'strlen');
             if ($this->module == 'themes') {
                 if (empty($search['slug'])) {
                     $search['slug'] = array_keys($applications);
                 }
             } else {
                 foreach ($search['slug'] as $id) {
                     if (isset($applications[$id]) && !empty($applications[$id]['system_plugins'])) {
                         $search['slug'] = array_unique(array_merge($search['slug'], $applications[$id]['system_plugins']));
                     }
                 }
             }
             if ((!$this->redirect || !empty($search['slug'])) && ($keys = installerHelper::search($applications, $search, true)) !== null) {
                 $slug = array();
                 foreach ($keys as $id => $key) {
                     $slug[$id] = $applications[$key]['slug'];
                 }
                 $extras = installerHelper::getInstaller()->getExtras($slug, $this->module, $options);
                 $vendor_name = null;
                 foreach ($extras as $app_id => $app_item) {
                     if (!empty($app_item[$this->module])) {
                         foreach ($app_item[$this->module] as $extras_id => $extras_item) {
                             if (!empty($extras_item['vendor_name']) && !empty($options['filter']['vendor']) && empty($vendor_name)) {
                                 $vendor_name = $extras_item['vendor_name'];
                             }
                             if (in_array($app_id, $keys) !== false) {
                                 $app =& $applications[$app_id];
                                 if (!isset($app[$this->module])) {
                                     $app[$this->module] = array();
                                 }
                                 $app[$this->module][$extras_id] = $extras_item;
                                 unset($app);
                             } elseif (!empty($extras_item['inherited'])) {
                                 foreach (array_keys($extras_item['inherited']) as $app_id) {
                                     if (in_array($app_id, $keys) !== false) {
                                         $app =& $applications[$app_id];
                                         if (!isset($app[$this->module])) {
                                             $app[$this->module] = array();
                                         }
                                         $app[$this->module][$extras_id] = $extras_item;
                                         unset($app);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 foreach ($keys as $id => $key) {
                     if (empty($applications[$key][$this->module])) {
                         unset($slug[$id]);
                     }
                 }
                 $this->view->assign('vendor_name', $vendor_name);
             } else {
                 reset($applications);
                 if ($app = current($applications)) {
                     $this->redirect(array('module' => $this->module, 'slug' => $app['slug'], 'vendor' => $app['vendor']));
                 }
             }
             $this->view->assign('slug', $search['slug']);
             //$this->view->assign('vendor', $search['vendor']);
             $this->view->assign('extras', $extras);
         }
         $this->view->assign('apps', $applications);
     } catch (Exception $ex) {
         $messages[] = array('text' => $ex->getMessage(), 'result' => 'fail');
     }
     installerHelper::checkUpdates($messages);
     $model = new waAppSettingsModel();
     $this->view->assign('update_counter', $model->get($this->getApp(), 'update_counter'));
     $this->view->assign('messages', $messages);
     $this->view->assign('title', _w('Installer'));
 }
Esempio n. 19
0
 public function execute()
 {
     $model = new waAppSettingsModel();
     $settings = array('name' => 'Webasyst', 'url' => wa()->getRootUrl(true), 'auth_form_background' => 'stock:bokeh_vivid.jpg', 'auth_form_background_stretch' => 1, 'locale' => 'ru_RU', 'email' => '', 'sender' => '', 'rememberme' => 1);
     $config_settings = array('debug' => 'boolean');
     $flush_settings = array('debug');
     $config_path = waSystem::getInstance()->getConfigPath() . '/config.php';
     $images_path = wa()->getDataPath(null, true, 'webasyst');
     $config = file_exists($config_path) ? include $config_path : array();
     if (!is_array($config)) {
         $config = array();
     }
     $images = array();
     $changed = false;
     $flush = false;
     $message = array();
     try {
         foreach ($settings as $setting => &$value) {
             if (waRequest::post() && !in_array($setting, array('auth_form_background'))) {
                 $post_value = waRequest::post($setting, '', waRequest::TYPE_STRING_TRIM);
                 if (!is_null($post_value)) {
                     $model->set('webasyst', $setting, $post_value);
                     $changed = true;
                 } elseif (!is_null($value)) {
                     $model->set('webasyst', $setting, '');
                 }
                 $value = $model->get('webasyst', $setting, $value);
             } else {
                 $value = $model->get('webasyst', $setting, $value);
             }
             unset($value);
         }
         $config_changed = false;
         if (waRequest::post()) {
             $config_values = waRequest::post('config');
             if (!is_array($config_values)) {
                 $config_values = array();
             }
             foreach ($config_settings as $setting => $type) {
                 $value = isset($config_values[$setting]) ? $config_values[$setting] : false;
                 switch ($type) {
                     case 'boolean':
                         $value = $value ? true : false;
                         break;
                 }
                 if (!isset($config[$setting]) || $config[$setting] !== $value) {
                     $config[$setting] = $value;
                     $config_changed = true;
                     if (in_array($setting, $flush_settings)) {
                         $flush = true;
                     }
                 }
             }
             if ($config_changed) {
                 waUtils::varExportToFile($config, $config_path);
             }
             if ($flush) {
                 $path_cache = waConfig::get('wa_path_cache');
                 waFiles::delete($path_cache, true);
                 waFiles::protect($path_cache);
             }
             $model->ping();
         }
         if ($changed || $config_changed) {
             $message[] = '[`Settings saved`]';
         }
         $name = preg_replace('/\\?.*$/', '', $settings['auth_form_background']);
         $path = wa()->getDataPath($name, true, 'webasyst');
         $file = waRequest::file('auth_form_background');
         $images = $this->getImages($images_path);
         if ($file->uploaded()) {
             if ($name) {
                 //waFiles::delete(wa()->getDataPath($name, true, 'webasyst'));
                 $model->set('webasyst', 'auth_form_background', false);
                 $settings['auth_form_background'] = false;
             }
             $ext = 'png';
             if (preg_match('/\\.(png|gif|jpg|jpeg|bmp|tif)$/i', $file->name, $matches)) {
                 $ext = $matches[1];
             }
             $name = 'auth_form_background.' . $ext;
             $path = wa()->getDataPath($name, true, 'webasyst');
             try {
                 $image = $file->waImage();
             } catch (waException $ex) {
                 $message = $ex->getMessage();
                 $tmp_name = $file->tmp_name;
                 if (!preg_match('//u', $tmp_name)) {
                     $tmp_name = iconv('windows-1251', 'utf-8', $tmp_name);
                 }
                 if (strpos($message, $tmp_name) !== false) {
                     throw new waException(preg_replace('/:\\s*$/', '', str_replace($tmp_name, '', $message)));
                 }
                 throw $ex;
             }
             foreach ($images as $i) {
                 waFiles::delete($images_path . '/' . $i);
             }
             $file->copyTo($path);
             clearstatcache();
             $images = $this->getImages($images_path);
             //$image->save($path);
             $name .= '?' . time();
             $model->set('webasyst', 'auth_form_background', $name);
             $settings['auth_form_background'] = $name;
             $message[] = '[`Image uploaded`]';
             $image_info = get_object_vars($image);
             $image_info['file_size'] = filesize($path);
             $image_info['file_mtime'] = filemtime($path);
             $image_info['file_name'] = basename($path);
             $this->view->assign('image', $image_info);
         } elseif ($thumb = waRequest::post('auth_form_background_thumb')) {
             $settings['auth_form_background'] = $thumb;
             $model->set('webasyst', 'auth_form_background', $settings['auth_form_background']);
         }
         if (strpos($settings['auth_form_background'], 'stock:') === 0) {
             $this->view->assign('image', false);
         } elseif ($settings['auth_form_background'] && file_exists($path)) {
             $settings['auth_form_background'] = preg_replace('@\\?\\d+$@', '', $settings['auth_form_background']);
             $image = new waImage($path);
             $image_info = get_object_vars($image);
             $image_info['file_size'] = filesize($path);
             $image_info['file_mtime'] = filemtime($path);
             $image_info['file_name'] = basename($path);
             $this->view->assign('image', $image_info);
             unset($image);
         } elseif ($settings['auth_form_background']) {
             $this->view->assign('image', null);
         }
         if (empty($image) && $images && file_exists($images_path . '/' . reset($images))) {
             $image = new waImage($path = $images_path . '/' . reset($images));
             $image_info = get_object_vars($image);
             $image_info['file_size'] = filesize($path);
             $image_info['file_mtime'] = filemtime($path);
             $image_info['file_name'] = basename($path);
             $this->view->assign('image', $image_info);
         }
         if ($message) {
             $params = array();
             $params['module'] = 'settings';
             $params['msg'] = installerMessage::getInstance()->raiseMessage(implode(', ', $message));
             if ($t = waRequest::get('_')) {
                 $params['_'] = $t;
             }
             $this->redirect($params);
         }
     } catch (waException $ex) {
         $msg = installerMessage::getInstance()->raiseMessage($ex->getMessage(), installerMessage::R_FAIL);
         $params = array('module' => 'settings', 'msg' => $msg);
         if ($message) {
             //$params['success'] = base64_encode(implode(', ', $message));
         }
         $this->redirect($params);
     }
     if (!waRequest::get('_')) {
         $this->setLayout(new installerBackendLayout());
         $this->getLayout()->assign('no_ajax', true);
     } else {
         $messages = installerMessage::getInstance()->handle(waRequest::get('msg'));
         $this->view->assign('messages', $messages);
     }
     $this->view->assign('version', wa()->getVersion('webasyst'));
     $backgrounds_path = wa()->getConfig()->getPath('content') . '/img/backgrounds/thumbs';
     $this->view->assign('backgrounds', $this->getImages($backgrounds_path));
     $images_url = wa()->getDataUrl(null, true, 'webasyst');
     $this->view->assign('images_url', $images_url);
     $this->view->assign('images_path', $images_path);
     $this->view->assign('images', $images);
     //auth_form_background
     $this->view->assign('settings', $settings);
     $this->view->assign('config', $config);
     $this->view->assign('action', 'settings');
     $locales = waSystem::getInstance()->getConfig()->getLocales('name');
     $this->view->assign('locales', $locales);
     $this->view->assign('title', _w('Settings'));
 }