public function execute()
 {
     $filter = array();
     $filter['enabled'] = true;
     $filter['extras'] = 'themes';
     $options = array('installed' => true);
     $applications = installerHelper::getInstaller()->getApps($options, $filter);
     $search = array();
     $search['slug'] = waRequest::get('slug');
     $search['vendor'] = waRequest::get('vendor', 'webasyst');
     $search['vendor'] = waRequest::get('theme_vendor', 'webasyst');
     if (!empty($search['slug'])) {
         $options = array('action' => true, 'requirements' => true, 'inherited' => array_keys($applications));
         if ($theme = installerHelper::getInstaller()->getItemInfo('*/themes/' . $search['slug'], $options)) {
             $theme['app'] = preg_replace('@/.+$@', '', $theme['slug']);
         }
         $this->view->assign('identity_hash', installerHelper::getHash());
         $this->view->assign('promo_id', installerHelper::getPromoId());
         $this->view->assign('domain', installerHelper::getDomain());
         $this->view->assign('theme', $theme);
         $this->view->assign('query', waRequest::get('query', '', waRequest::TYPE_STRING_TRIM) . '/');
     } else {
         throw new waException(_w('Theme not found'), 404);
     }
 }
 private function install()
 {
     $this->model->ping();
     $apps = installerHelper::getInstaller();
     $this->model->ping();
     $user = $this->getUser();
     $set_rights = false;
     if (!$user->isAdmin()) {
         $set_rights = true;
     }
     foreach ($this->urls as $target => &$url) {
         //TODO workaround exceptions
         if (empty($url['skipped']) && preg_match('@^wa-apps/@', $target)) {
             try {
                 $apps->installWebAsystItem(preg_replace('@^wa-apps/@', '', $target), null, isset($url['edition']) ? $url['edition'] : true);
             } catch (Exception $e) {
                 waLog::log($e->getMessage());
                 $url['skipped'] = true;
             }
             $this->model->ping();
             if ($set_rights) {
                 $user->setRight($url['slug'], 'backend', 2);
             }
         } else {
             $url['update'] = true;
         }
         unset($url);
     }
 }
 public function execute()
 {
     $filter = array();
     $filter['enabled'] = true;
     $filter['extras'] = 'plugins';
     $options = array('installed' => true);
     $search = array();
     $search['slug'] = preg_replace('@^(wa-plugins/)?([^/]+)/.+$@', '$1$2', waRequest::get('slug'));
     if (strpos($search['slug'], 'wa-plugins/') === 0) {
         $options['system'] = true;
     }
     $applications = installerHelper::getInstaller()->getApps($options, $filter);
     $plugin_search = array();
     $plugin_search['id'] = preg_replace('@^.+/@', '', waRequest::get('slug'));
     if (array_filter($search, 'strlen') && ($app = installerHelper::search($applications, $search))) {
         $plugin_search['slug'] = $search['slug'] . "/plugins/" . $plugin_search['id'];
         $options = array('action' => true, 'requirements' => true);
         $plugin = installerHelper::getInstaller()->getItemInfo($plugin_search['slug'], $options);
         if (!$plugin) {
             $options['local'] = true;
             $plugin = installerHelper::getInstaller()->getItemInfo($plugin_search['slug'], $options);
         }
         if ($plugin) {
             $plugin['app'] = preg_replace('@^(wa-plugins/)?([^/]+)/.+$@', '$1$2', $plugin['slug']);
             $plugin['slug'] = preg_replace('@^wa-plugins/([^/]+)/plugins/(.+)$@', 'wa-plugins/$1/$2', $plugin['slug']);
         }
         $this->view->assign('identity_hash', installerHelper::getHash());
         $this->view->assign('promo_id', installerHelper::getPromoId());
         $this->view->assign('domain', installerHelper::getDomain());
         $this->view->assign('plugin', $plugin);
         $this->view->assign('query', waRequest::get('query', '', waRequest::TYPE_STRING_TRIM) . '/');
     } else {
         throw new waException(_w('Plugin not found'), 404);
     }
 }
 public function execute()
 {
     if (!waRequest::get('_')) {
         $this->setLayout(new installerBackendLayout());
     }
     $this->view->assign('action', 'update');
     $this->view->assign('error', false);
     try {
         $slug = waRequest::get('slug');
         $options = array('vendor' => waRequest::get('vendor', '', waRequest::TYPE_STRING_TRIM), 'edition' => waRequest::get('edition', '', waRequest::TYPE_STRING_TRIM), 'action' => true, 'requirements' => true);
         $this->view->assign('app', $app = installerHelper::getInstaller()->getItemInfo($slug, $options));
         $this->view->assign('title', sprintf(_w('Application "%s"'), $app['name']));
     } catch (Exception $ex) {
         $this->view->assign('error', $ex->getMessage());
     }
     $this->view->assign('identity_hash', installerHelper::getHash());
     $this->view->assign('promo_id', installerHelper::getPromoId());
     $this->view->assign('domain', installerHelper::getDomain());
     if (!empty($app['is_premium']) && $app['theme'] == 'premium') {
         $this->setTemplate(preg_replace('@(\\.html)$@', 'Premium$1', $this->getTemplate()));
     }
 }
Example #5
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()
 {
     $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()
 {
     $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()
 {
     $filter = array();
     $filter['enabled'] = true;
     $filter['extras'] = 'themes';
     $options = array('installed' => true);
     $applications = installerHelper::getInstaller()->getApps($options, $filter);
     $search = array();
     $search['slug'] = array($app_id = waRequest::get('slug'));
     $search['slug'] = array_unique($search['slug']);
     $search['vendor'] = waRequest::get('vendor', 'webasyst');
     $installer = installerHelper::getInstaller();
     $options = array('local' => true, 'apps' => true, 'filter' => (array) waRequest::get('filter'), 'inherited' => array_keys($applications));
     $list = $installer->getExtras($search['slug'], 'themes', $options);
     /**
      * @var $themes waTheme[]
      */
     $themes = array();
     $inherited = array();
     foreach ($list as $id => $item_list) {
         if (!empty($item_list['themes'])) {
             foreach ($item_list['themes'] as $theme_id => $theme) {
                 if ($id == $app_id || !empty($theme['inherited'][$app_id])) {
                     $themes[$theme_id] = new waTheme($theme_id, $app_id, true, true);
                     $themes[$theme_id]['name'] = empty($theme['name']) ? $theme_id : $theme['name'];
                     $themes[$theme_id]['description'] = empty($theme['description']) ? '' : $theme['description'];
                     if (!empty($theme['price'])) {
                         $themes[$theme_id]['price'] = $theme['price'];
                     }
                     if (!empty($theme['compare_price'])) {
                         $themes[$theme_id]['compare_price'] = $theme['compare_price'];
                     }
                     if (isset($theme['commercial'])) {
                         $themes[$theme_id]['commercial'] = $theme['commercial'];
                     }
                     if (!empty($theme['icon'])) {
                         $themes[$theme_id]['cover'] = $theme['icon'];
                     }
                     if (!isset($inherited[$theme_id])) {
                         $inherited[$theme_id] = array();
                     }
                     if (!empty($theme['inherited'])) {
                         $inherited[$theme_id] = array_merge($inherited[$theme_id], $theme['inherited']);
                     }
                     if (!isset($inherited[$theme_id][$id])) {
                         $inherited[$theme_id][$id] = array('slug' => $id . '/themes/' . $theme_id);
                     }
                 } else {
                     if (!isset($inherited[$theme_id])) {
                         $inherited[$theme_id] = array();
                     }
                     if (!empty($theme['inherited'])) {
                         $inherited[$theme_id] = array_merge($inherited[$theme_id], $theme['inherited']);
                     }
                 }
             }
         }
     }
     foreach ($themes as $theme_id => &$theme) {
         $theme['inherited'] = $inherited[$theme_id];
         unset($theme);
     }
     $app = $installer->getItemInfo($app_id);
     $this->view->assign('themes', $themes);
     $this->view->assign('app_id', $app_id);
     $this->view->assign('app', $app);
     $this->view->assign('slug', $search['slug']);
     $this->view->assign('vendor', $search['vendor']);
     $return_url = waRequest::get('return_url', waRequest::server('HTTP_REFERER'));
     if ($return_hash = waRequest::get('return_hash')) {
         if ($return_hash = preg_replace('@^#@', '', $return_hash)) {
             $return_url .= '#' . $return_hash;
         }
     }
     $this->view->assign('return_url', $return_url);
 }
 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'));
 }