public function execute()
 {
     $product_id = $this->get('product_id', true);
     $this->getProduct($product_id);
     $file = waRequest::file('file');
     $image = $file->waImage();
     if ($file->uploaded()) {
         $data = array('product_id' => $product_id, 'upload_datetime' => date('Y-m-d H:i:s'), 'width' => $image->width, 'height' => $image->height, 'size' => $file->size, 'original_filename' => basename($file->name), 'ext' => $file->extension, 'description' => waRequest::post('description'));
         $product_images_model = new shopProductImagesModel();
         $image_id = $data['id'] = $product_images_model->add($data);
         if (!$image_id) {
             throw new waAPIException('server_error', 500);
         }
         /**
          * @var shopConfig $config
          */
         $config = wa('shop')->getConfig();
         $image_path = shopImage::getPath($data);
         if (file_exists($image_path) && !is_writable($image_path) || !file_exists($image_path) && !waFiles::create($image_path)) {
             $product_images_model->deleteById($image_id);
             throw new waAPIException(sprintf("The insufficient file write permissions for the %s folder.", substr($image_path, strlen($config->getRootPath()))));
         }
         $file->moveTo($image_path);
         unset($image);
         shopImage::generateThumbs($data, $config->getImageSizes());
         $method = new shopProductImagesGetInfoMethod();
         $_GET['id'] = $image_id;
         $this->response = $method->getResponse(true);
     } else {
         throw new waAPIException('server_error', $file->error);
     }
 }
 public function execute()
 {
     $plugin_id = waRequest::get('id');
     if (!$plugin_id) {
         throw new waException(_ws("Can't save plugin settings: unknown plugin id"));
     }
     $namespace = 'photos_' . $plugin_id;
     /**
      * @var photosPlugin $plugin
      */
     $plugin = waSystem::getInstance()->getPlugin($plugin_id);
     $settings = (array) $this->getRequest()->post($namespace);
     $files = waRequest::file($namespace);
     $settings_defenitions = $plugin->getSettings();
     foreach ($files as $name => $file) {
         if (isset($settings_defenitions[$name])) {
             $settings[$name] = $file;
         }
     }
     try {
         $plugin->saveSettings($settings);
     } catch (Exception $e) {
         $this->errors = $e->getMessage();
     }
 }
 public function saveAction()
 {
     $plugin_id = waRequest::get('id');
     if (!$plugin_id) {
         throw new waException(_ws("Can't save plugin settings: unknown plugin id"));
     }
     $namespace = $this->getAppId() . '_' . $plugin_id;
     /**
      * @var shopPlugin $plugin
      */
     $plugin = waSystem::getInstance()->getPlugin($plugin_id);
     $settings = (array) $this->getRequest()->post($namespace);
     $files = waRequest::file($namespace);
     $settings_defenitions = $plugin->getSettings();
     foreach ($files as $name => $file) {
         if (isset($settings_defenitions[$name])) {
             $settings[$name] = $file;
         }
     }
     try {
         $response = $plugin->saveSettings($settings);
         $response['message'] = _w('Saved');
         $this->displayJson($response);
     } catch (Exception $e) {
         $this->setError($e->getMessage());
         $this->displayJson(array(), $e->getMessage());
     }
 }
 public function execute()
 {
     $this->response['files'] = array();
     $this->getStorage()->close();
     if (waRequest::server('HTTP_X_FILENAME')) {
         $name = waRequest::server('HTTP_X_FILE_NAME');
         $size = waRequest::server('HTTP_X_FILE_SIZE');
         $file_path = wa()->getTempPath('shop/upload/') . $name;
         $append_file = is_file($file_path) && $size > filesize($file_path);
         clearstatcache();
         file_put_contents($file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0);
         $file = new waRequestFile(array('name' => $name, 'type' => waRequest::server('HTTP_X_FILE_TYPE'), 'size' => $size, 'tmp_name' => $file_path, 'error' => 0));
         try {
             $this->response['files'][] = $this->save($file);
         } catch (Exception $e) {
             $this->response['files'][] = array('error' => $e->getMessage());
         }
     } else {
         $files = waRequest::file($this->name);
         foreach ($files as $file) {
             if ($file->error_code != UPLOAD_ERR_OK) {
                 $this->response['files'][] = array('error' => $file->error);
             } else {
                 try {
                     $this->response['files'][] = $this->save($file);
                 } catch (Exception $e) {
                     $this->response['files'][] = array('name' => $file->name, 'error' => $e->getMessage());
                 }
             }
         }
     }
 }
 public function execute()
 {
     if (!$this->getUser()->getRights('shop', 'settings')) {
         throw new waException(_w('Access denied'));
     }
     $plugin_id = waRequest::get('id');
     if (!$plugin_id) {
         throw new waException(_ws("Can't save plugin settings: unknown plugin id"));
     }
     $namespace = 'shop_' . $plugin_id;
     /**
      * @var shopPlugin $plugin
      */
     $plugin = waSystem::getInstance()->getPlugin($plugin_id);
     $settings = (array) $this->getRequest()->post($namespace);
     $files = waRequest::file($namespace);
     $settings_defenitions = $plugin->getSettings();
     foreach ($files as $name => $file) {
         if (isset($settings_defenitions[$name])) {
             $settings[$name] = $file;
         }
     }
     try {
         $this->response = $plugin->saveSettings($settings);
         $this->response['message'] = _w('Saved');
     } catch (Exception $e) {
         $this->setError($e->getMessage());
     }
 }
예제 #6
0
 protected function process()
 {
     $f = waRequest::file('file');
     $this->name = $f->name;
     if ($this->processFile($f)) {
         $this->response = wa()->getDataUrl('img/' . $this->name, true, null, true);
     }
 }
 public function execute()
 {
     if (!$this->getRights('upload')) {
         throw new waRightsException(_w("You don't have sufficient access rights"));
     }
     $this->response['files'] = array();
     $this->model = new photosPhotoModel();
     $album_rights_model = new photosAlbumRightsModel();
     // rights for photos
     $this->status = waRequest::post('status', 0, 'int');
     $this->groups = waRequest::post('groups', array(), waRequest::TYPE_ARRAY_INT);
     if (!$this->groups) {
         $this->status = -1;
         // only author have access to this photo
         $this->groups = array(-$this->getUser()->getId());
     }
     // work with album
     $this->album_id = waRequest::post('album_id');
     $this->album_id = (int) $this->album_id;
     if ($this->album_id > 0 && !$album_rights_model->checkRights($this->album_id, true)) {
         $this->response['files'][] = array('error' => _w("You don't have sufficient access rights"));
         return;
     }
     $this->getStorage()->close();
     if (waRequest::server('HTTP_X_FILE_NAME')) {
         $name = waRequest::server('HTTP_X_FILE_NAME');
         $size = waRequest::server('HTTP_X_FILE_SIZE');
         $file_path = wa()->getTempPath('photos/upload/') . $name;
         $append_file = is_file($file_path) && $size > filesize($file_path);
         clearstatcache();
         file_put_contents($file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0);
         $file = new waRequestFile(array('name' => $name, 'type' => waRequest::server('HTTP_X_FILE_TYPE'), 'size' => $size, 'tmp_name' => $file_path, 'error' => 0));
         try {
             $this->response['files'][] = $this->save($file);
         } catch (Exception $e) {
             $this->response['files'][] = array('error' => $e->getMessage());
         }
     } else {
         $files = waRequest::file('files');
         foreach ($files as $file) {
             if ($file->error_code != UPLOAD_ERR_OK) {
                 $this->response['files'][] = array('error' => $file->error);
             } else {
                 try {
                     $this->response['files'][] = $this->save($file);
                 } catch (Exception $e) {
                     $this->response['files'][] = array('name' => $file->name, 'error' => $e->getMessage());
                 }
             }
         }
     }
 }
 public function execute()
 {
     try {
         $file = waRequest::file('files');
         if ($file->uploaded()) {
             $filepath = wa()->getCachePath('plugins/discountcards/import-discountcards.csv', 'shop');
             $file->moveTo($filepath);
         } else {
             throw new waException('Ошибка загрузки файла');
         }
     } catch (Exception $ex) {
         $this->setError($ex->getMessage());
     }
 }
예제 #9
0
 public function sendForm($form_id)
 {
     $form_model = new wformsFormModel();
     $field_model = new wformsFieldModel();
     $field_values_model = new wformsFieldValuesModel();
     $form = $form_model->getById($form_id);
     if (!$form) {
         throw new waException('Форма #' . $form_id . ' не найдена');
     }
     $fields = $field_model->getFormFields($form_id);
     foreach ($fields as $field) {
         if ($field['type'] != 'file') {
             $value = waRequest::post('field_' . $field['id']);
             if ($field['required'] && empty($value)) {
                 throw new waException('Ошибка отправки формы. Заполните обязательные поля');
             }
             if (is_array($value)) {
                 $data[$field['name']] = implode(', ', $value);
             } else {
                 $data[$field['name']] = $value;
             }
         }
     }
     if (!wa()->getCaptcha()->isValid()) {
         throw new waException('Капча введена неверно');
     }
     $view = wa()->getView();
     $view->assign('data', $data);
     $template_path = wa()->getAppPath('templates/actions/frontend/Message.html', 'wforms');
     $html = $view->fetch($template_path);
     $message = new waMailMessage($form['title'], $html);
     $message->setTo($form['to']);
     foreach ($fields as $field) {
         if ($field['type'] == 'file') {
             $file = waRequest::file('field_' . $field['id']);
             if ($file->uploaded()) {
                 $message->addAttachment($file->tmp_name, $field['name'] . '.' . $file->extension);
             }
         }
     }
     if ($form['from']) {
         $message->setFrom($form['from']);
     }
     if ($message->send()) {
         return true;
     }
     return false;
 }
예제 #10
0
 public function execute()
 {
     $data = waRequest::post();
     if (!wa()->getUser()->getRights('photos', 'upload')) {
         throw new waAPIException('access_denied', 403);
     }
     $group_ids = array(0);
     if (!isset($data['status'])) {
         $data['status'] = 1;
     } else {
         if ($data['status'] == -1) {
             $group_ids = array(-wa()->getUser()->getId());
         }
     }
     $data['groups'] = $group_ids;
     $data['source'] = photosPhotoModel::SOURCE_API;
     // work with album
     if (isset($data['album_id'])) {
         $album_id = $data['album_id'];
         $album_model = new photosAlbumModel();
         $album = $album_model->getById($album_id);
         if (!$album) {
             throw new waAPIException('invalid_param', 'Album not found', 404);
         }
         $album_rights_model = new photosAlbumRightsModel();
         if (!$album_rights_model->checkRights($album_id, true)) {
             throw new waAPIException('access_denied', 'Not rights to album', 403);
         }
     }
     $file = waRequest::file('file');
     if (!$file->uploaded()) {
         throw new waAPIException('server_error', $file->error, 500);
     }
     $id = null;
     $photo_model = new photosPhotoModel();
     try {
         $id = $photo_model->add($file, $data);
     } catch (Exception $e) {
         throw new waAPIException('server_error', $e->getMessage(), 500);
     }
     if (!$id) {
         throw new waAPIException('server_error', 500);
     }
     $_GET['id'] = $id;
     $method = new photosPhotoGetInfoMethod();
     $this->response = $method->getResponse(true);
 }
 public static function getFilesFromPost()
 {
     if (waRequest::server('HTTP_X_FILE_NAME')) {
         $name = waRequest::server('HTTP_X_FILE_NAME');
         $size = waRequest::server('HTTP_X_FILE_SIZE');
         $safe_name = trim(preg_replace('~[^a-z\\.]~', '', waLocale::transliterate($name)), ". \n\t\r");
         $safe_name || ($safe_name = uniqid('p'));
         $file_path = wa()->getTempPath('photos/upload/') . $safe_name;
         $append_file = is_file($file_path) && $size > filesize($file_path);
         clearstatcache();
         file_put_contents($file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0);
         $file = new waRequestFile(array('name' => $name, 'type' => waRequest::server('HTTP_X_FILE_TYPE'), 'size' => $size, 'tmp_name' => $file_path, 'error' => 0));
         return array($file);
     } else {
         return waRequest::file('files');
     }
 }
 public function execute()
 {
     $this->response['files'] = array();
     $this->model = new photosPhotoModel();
     $data = array('contact_id' => wa()->getUser()->getId(), 'status' => 1, 'groups' => array(0), 'source' => 'publicgallery');
     $plugin = wa()->getPlugin('publicgallery');
     if ($plugin->getSettings('need_moderation')) {
         $data['moderation'] = 0;
     } else {
         $data['moderation'] = 1;
     }
     if ($data['moderation'] <= 0) {
         $data['status'] = 0;
     }
     $this->getStorage()->close();
     if (waRequest::server('HTTP_X_FILE_NAME')) {
         $name = waRequest::server('HTTP_X_FILE_NAME');
         $size = waRequest::server('HTTP_X_FILE_SIZE');
         $file_path = wa()->getTempPath('photos/upload/') . $name;
         $append_file = is_file($file_path) && $size > filesize($file_path);
         clearstatcache();
         file_put_contents($file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0);
         $file = new waRequestFile(array('name' => $name, 'type' => waRequest::server('HTTP_X_FILE_TYPE'), 'size' => $size, 'tmp_name' => $file_path, 'error' => 0));
         try {
             $this->response['files'][] = $this->save($file, $data);
         } catch (Exception $e) {
             $this->response['files'][] = array('error' => $e->getMessage());
         }
     } else {
         $files = waRequest::file('files');
         foreach ($files as $file) {
             if ($file->error_code != UPLOAD_ERR_OK) {
                 $this->response['files'][] = array('error' => $file->error);
             } else {
                 try {
                     $this->response['files'][] = $this->save($file, $data);
                 } catch (Exception $e) {
                     $this->response['files'][] = array('name' => $file->name, 'error' => $e->getMessage());
                 }
             }
         }
     }
 }
 public function execute()
 {
     $id = $this->getId();
     $file = waRequest::file('photo');
     if (!$file->uploaded()) {
         $this->sendResponse('error:No file uploaded.');
         return;
     }
     try {
         $img = $file->waImage();
     } catch (Exception $e) {
         // Nope... it's not an image.
         $this->sendResponse('error:File is not an image (' . $e->getMessage() . ').');
         return;
     }
     // save it to a temporary directory (well... less temporary than /tmp)
     // in .jpg format
     $temp_dir = wa()->getTempPath('photo');
     $fname = uniqid($id . '_') . '.jpg';
     $img->save($temp_dir . '/' . $fname, 90);
     $photoEditors = $this->getStorage()->read('photoEditors');
     if (!$photoEditors) {
         $photoEditors = array();
     }
     if (isset($photoEditors[$id]) && file_exists($photoEditors[$id])) {
         // If there was another photo editor session for this contact,
         // assume it closed and delete old temp file
         if (!unlink($photoEditors[$id])) {
             throw new waException('Unable to delete photo temp file: ' + $photoEditors[$id]);
         }
     }
     $photoEditors[$id] = $temp_dir . '/' . $fname;
     // Save file name in session (race condition possible)
     $this->getStorage()->write('photoEditors', $photoEditors);
     // Return temporary file url to browser
     $temp_file_url = $this->getPreviewUrl($fname);
     $this->sendResponse($temp_file_url);
 }
 protected function saveTouchicon()
 {
     $touchicon = waRequest::file('touchicon');
     if ($touchicon->uploaded()) {
         if ($touchicon->extension !== 'png') {
             $this->errors = _w('Files with extension *.png are allowed only.');
         } else {
             $path = wa()->getDataPath('data/' . siteHelper::getDomain() . '/', true);
             if (!file_exists($path) || !is_writable($path)) {
                 $this->errors = sprintf(_w('File could not be saved due to the insufficient file write permissions for the "%s" folder.'), 'wa-data/public/site/data/' . siteHelper::getDomain());
             } elseif (!$touchicon->moveTo($path, 'apple-touch-icon.png')) {
                 $this->errors = _w('Failed to upload file.');
             }
         }
     } elseif ($touchicon->error_code != UPLOAD_ERR_NO_FILE) {
         $this->errors = $touchicon->error;
     }
 }
 public function widgetSaveAction()
 {
     $id = waRequest::get('id');
     if (!$id) {
         throw new waException(_ws("Can't save plugin settings: unknown plugin id"));
     }
     $namespace = 'widget_' . $id;
     /**
      * @var shopPlugin $plugin
      */
     $widget = waSystem::getInstance()->getWidget($id);
     $settings = waRequest::post($namespace, array());
     $files = waRequest::file($namespace);
     $settings_defenitions = $widget->getSettings();
     foreach ($files as $name => $file) {
         if (isset($settings_defenitions[$name])) {
             $settings[$name] = $file;
         }
     }
     $response = $widget->setSettings($settings);
     $response['message'] = _w('Saved');
     $this->displayJson($response);
 }
 public function uploadimageAction()
 {
     $path = wa()->getDataPath('img', true);
     $response = '';
     if (!is_writable($path)) {
         $p = substr($path, strlen(wa()->getDataPath('', true)));
         $errors = sprintf(_w("File could not bet saved due to the insufficient file write permissions for the %s folder."), $p);
     } else {
         $errors = array();
         $f = waRequest::file('file');
         $name = $f->name;
         if ($this->processFile($f, $path, $name, $errors)) {
             $response = wa()->getDataUrl('img/' . $name, true, null, !!waRequest::get('absolute'));
         }
         $errors = implode(" \r\n", $errors);
     }
     if (waRequest::get('filelink')) {
         $this->getResponse()->sendHeaders();
         if ($errors) {
             echo json_encode(array('error' => $errors));
         } else {
             echo stripslashes(json_encode(array('filelink' => $response)));
         }
     } else {
         $this->displayJson($response, $errors);
     }
 }
 protected function getIterableFiles()
 {
     // Read file from global $_FILES
     // Don't bother with html5-style uploads for now...
     return waRequest::file('file');
 }
예제 #18
0
 public function uploadimageAction()
 {
     $path = wa()->getDataPath('img', true);
     $response = array();
     if (!is_writable($path)) {
         $p = substr($path, strlen(wa()->getDataPath('', true)));
         $errors = sprintf(_w("File could not bet saved due to the insufficient file write permissions for the %s folder."), $p);
     } else {
         $errors = array();
         $f = waRequest::file('file');
         $name = $f->name;
         if ($this->processFile($f, $path, $name, $errors)) {
             $response = wa()->getDataUrl('img/' . $name, true);
         }
         $errors = implode(" \r\n", $errors);
     }
     $this->displayJson($response, $errors);
 }
 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'));
 }
 protected function process()
 {
     foreach (waRequest::file('files') as $f) {
         $this->processFile($f);
     }
 }
예제 #21
0
 protected function themeUploadAction()
 {
     if ($file = waRequest::file('theme_files')) {
         /**
          * @var waRequestFile
          */
         if ($file->uploaded()) {
             try {
                 $theme = waTheme::extract($file->tmp_name);
                 $this->logAction('theme_upload', $theme->id);
                 $this->displayJson(array('theme' => $theme->id));
             } catch (Exception $e) {
                 waFiles::delete($file->tmp_name);
                 $this->displayJson(array(), $e->getMessage());
             }
         } else {
             $message = $file->error;
             if (!$message) {
                 $message = 'Error while file upload';
             }
             $this->displayJson(array(), $message);
         }
     } else {
         $this->displayJson(array(), 'Error while file upload');
     }
 }
예제 #22
0
 /**
  *
  * Инициализация значений настроек модуля доставки
  */
 public function saveSettings($settings = array())
 {
     $settings_config = $this->config();
     foreach ($settings_config as $name => $row) {
         if (!isset($settings[$name])) {
             switch (ifset($row['control_type'])) {
                 case waHtmlControl::CHECKBOX:
                     $settings[$name] = false;
                     break;
                 case waHtmlControl::GROUPBOX:
                     $settings[$name] = array();
                     break;
                 default:
                     $settings[$name] = isset($row['value']) ? $row['value'] : null;
                     break;
             }
         } else {
             switch (ifset($row['control_type'])) {
                 case waHtmlControl::FILE:
                     $file = waRequest::file($name);
                     break;
             }
         }
     }
     foreach ($settings as $name => $value) {
         $this->settings[$name] = $value;
         $this->getAdapter()->setSettings($this->id, $this->key, $name, $value);
     }
     return $settings;
 }
 public function widgetSaveAction()
 {
     $id = waRequest::get('id');
     $widget = wa()->getWidget($id);
     if (!$widget->isAllowed()) {
         throw new waException(_ws('Widget not found'), 404);
     }
     $namespace = 'widget_' . $id;
     $settings = waRequest::post($namespace, array());
     $settings_defenitions = $widget->getSettings();
     foreach (waRequest::file($namespace) as $name => $file) {
         if (isset($settings_defenitions[$name])) {
             $settings[$name] = $file;
         }
     }
     $response = $widget->setSettings($settings);
     $response['message'] = _w('Saved');
     $this->displayJson($response);
 }
예제 #24
0
 protected function themeUploadAction()
 {
     if ($file = waRequest::file('theme_files')) {
         /**
          * @var waRequestFile
          */
         if ($file->uploaded()) {
             try {
                 $theme = waTheme::extract($file->tmp_name);
                 $this->log('theme_upload');
                 $this->displayJson(array('theme' => $theme['id']));
             } catch (Exception $e) {
                 waFiles::delete($file->tmp_name);
                 $this->displayJson(array(), $e->getMessage());
             }
         } else {
             $this->displayJson(array(), $file->error);
         }
     }
 }
예제 #25
0
 /**
  * @return bool
  */
 protected function saveFromPost($form, $contact)
 {
     $data = $form->post();
     if (!$data || !is_array($data)) {
         return false;
     }
     // save photo before all
     $photo_file = waRequest::file('photo_file');
     if (array_key_exists('photo', $data)) {
         if ($photo_file->uploaded() && ($avatar = $photo_file->waImage())) {
             // add/update photo
             $square = min($avatar->height, $avatar->width);
             // setPhoto with crop
             $rand = mt_rand();
             $path = wa()->getDataPath(waContact::getPhotoDir($contact->getId()), true, 'contacts', false);
             // delete old image
             if (file_exists($path)) {
                 waFiles::delete($path);
             }
             waFiles::create($path);
             $filename = $path . $rand . ".original.jpg";
             waFiles::create($filename);
             waImage::factory($photo_file)->save($filename, 90);
             $filename = $path . $rand . ".jpg";
             waFiles::create($filename);
             waImage::factory($photo_file)->crop($square, $square)->save($filename, 90);
             waContactFields::getStorage('waContactInfoStorage')->set($contact, array('photo' => $rand));
         } elseif (empty($data['photo'])) {
             // remove photo
             $contact->set('photo', "");
         }
         $this->form->values['photo'] = $data['photo'] = $contact->get('photo');
     }
     // Validation
     if (!$form->isValid($contact)) {
         return false;
     }
     // Password validation
     if (!empty($data['password']) && $data['password'] !== $data['password_confirm']) {
         $form->errors('password', _ws('Passwords do not match'));
         return false;
     } elseif (empty($data['password']) || empty($data['password_confirm'])) {
         unset($data['password']);
     }
     unset($data['password_confirm']);
     // get old data for logging
     if ($this->contact) {
         $old_data = array();
         foreach ($data as $field_id => $field_value) {
             $old_data[$field_id] = $this->contact->get($field_id);
         }
     }
     foreach ($data as $field => $value) {
         $contact->set($field, $value);
     }
     $errors = $contact->save();
     // If something went wrong during save for any reason,
     // show it to user. In theory it shouldn't but better be safe.
     if ($errors) {
         foreach ($errors as $field => $errs) {
             foreach ($errs as $e) {
                 $form->errors($field, $e);
             }
         }
         return false;
     }
     // get new data for logging
     $new_data = array();
     foreach ($data as $field_id => $field_value) {
         if (!isset($errors[$field_id])) {
             $new_data[$field_id] = $this->contact->get($field_id);
         }
     }
     $this->logProfileEdit($old_data, $new_data);
     return true;
 }
예제 #26
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'));
 }