コード例 #1
0
 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);
     }
 }
コード例 #2
0
 public function execute()
 {
     $p = $path = rtrim(waRequest::post('path'), ' /');
     $file = waRequest::post('file');
     try {
         if ($file) {
             if (!is_array($file)) {
                 $file = array($file);
             }
             foreach ($file as $f) {
                 $f = $path . '/' . $f;
                 waFiles::delete(wa()->getDataPath($f, true, null, false));
             }
             $this->log('file_delete', count($file));
         } else {
             $path = wa()->getDataPath($path, true, null, false);
             if (!is_writable($path)) {
                 $this->errors = sprintf(_w("Folder could not bet deleted due to the insufficient permissions."), $p);
             } else {
                 waFiles::delete($path);
                 $this->log('file_delete', 1);
             }
         }
     } catch (Exception $e) {
         $this->errors = $e->getMessage();
     }
 }
コード例 #3
0
 protected function step()
 {
     $image_model = new shopProductImagesModel();
     $create_thumbnails = waRequest::post('create_thumbnails');
     $chunk_size = 50;
     if ($create_thumbnails) {
         $chunk_size = 10;
     }
     $sizes = wa('shop')->getConfig()->getImageSizes();
     $images = $image_model->getAvailableImages($this->data['offset'], $chunk_size);
     foreach ($images as $i) {
         if ($this->data['product_id'] != $i['product_id']) {
             sleep(0.2);
             $this->data['product_id'] = $i['product_id'];
             $this->data['product_count'] += 1;
         }
         try {
             $path = shopImage::getThumbsPath($i);
             if (!waFiles::delete($path)) {
                 throw new waException(sprintf(_w('Error when delete thumbnails for image %d'), $i['id']));
             }
             if ($create_thumbnails) {
                 shopImage::generateThumbs($i, $sizes);
             }
             $this->data['image_count'] += 1;
             // image count - count of successful progessed images
         } catch (Exception $e) {
             $this->error($e->getMessage());
         }
         $this->data['offset'] += 1;
     }
 }
 protected function flushCache()
 {
     $config = wa()->getConfig();
     $path_cache = $config->getPath('cache');
     waFiles::protect($path_cache);
     $caches = array();
     $paths = waFiles::listdir($path_cache);
     foreach ($paths as $path) {
         #skip long action & data path
         if ($path != 'temp') {
             $path = $path_cache . '/' . $path;
             if (is_dir($path)) {
                 $caches[] = $path;
             }
         }
     }
     $root_path = $config->getRootPath();
     $errors = array();
     foreach ($caches as $path) {
         try {
             waFiles::delete($path);
         } catch (Exception $ex) {
             $errors[] = str_replace($root_path . DIRECTORY_SEPARATOR, '', $ex->getMessage());
             waFiles::delete($path, true);
         }
     }
     waFiles::protect($path_cache);
     return $errors;
 }
コード例 #5
0
 protected function removeExtras($app_id, $extras_id, $info)
 {
     try {
         $paths = array();
         $plugin_instance = waSystem::getInstance($app_id)->getPlugin($extras_id);
         if (!$plugin_instance) {
             return false;
         }
         $plugin_instance->uninstall();
         $this->installer->updateAppPluginsConfig($app_id, $extras_id, null);
         //wa-apps/$app_id/plugins/$slug
         $paths[] = wa()->getAppPath("{$this->extras_type}/{$extras_id}", $app_id);
         $paths[] = wa()->getTempPath(null, $app_id);
         //wa-cache/temp/$app_id/
         $paths[] = wa()->getAppCachePath(null, $app_id);
         //wa-cache/apps/$app_id/
         foreach ($paths as $path) {
             waFiles::delete($path, true);
         }
         return true;
     } catch (Exception $ex) {
         //TODO check config
         $this->installer->updateAppPluginsConfig($app_id, $extras_id, true);
         throw $ex;
     }
 }
コード例 #6
0
 public static function delete($file)
 {
     self::loadPath();
     $file = preg_replace('!\\.\\.[/\\\\]!', '', $file);
     $file = self::$path . $file;
     if (file_exists($file)) {
         waFiles::delete($file);
     }
 }
コード例 #7
0
 public function execute()
 {
     $contact = wa()->getUser();
     $contact['photo'] = 0;
     $contact->save();
     $oldDir = wa()->getDataPath(waContact::getPhotoDir($contact->getId()), true, 'contacts', false);
     if (file_exists($oldDir)) {
         waFiles::delete($oldDir);
     }
     $this->response = array('done' => 1);
 }
 public function execute()
 {
     $id = waRequest::post('id');
     if (is_numeric($id)) {
         $modelNotifierTemplate = new shopNotifierTemplateModel();
         $path = shopNotifierPlugin::path($id);
         waFiles::delete($path);
         $modelNotifierTemplate->deleteById($id);
         $this->response['message'] = 'ok';
     } else {
         $this->response['message'] = 'fail';
     }
 }
コード例 #9
0
 protected function removeExtras($app_id, $extras_id, $info)
 {
     $paths = array();
     $paths[] = wa()->getTempPath(null, $app_id);
     //wa-cache/temp/$app_id/
     //wa-apps/$app_id/extrass/$slug
     $paths[] = wa()->getAppPath("{$this->extras_type}/{$extras_id}", $app_id);
     $paths[] = wa()->getAppCachePath(null, $app_id);
     //wa-cache/apps/$app_id/
     foreach ($paths as $path) {
         waFiles::delete($path, true);
     }
     return true;
 }
コード例 #10
0
 public function execute()
 {
     $id = $this->getId();
     // Delete the old photos if they exist
     $oldDir = wa()->getDataPath(waContact::getPhotoDir($id), TRUE);
     if (file_exists($oldDir)) {
         waFiles::delete($oldDir);
     }
     // Update record in DB for this user
     $contact = new waContact($id);
     $contact['photo'] = 0;
     $contact->save();
     // Update recent history to reload thumbnail correctly (if not called from personal account)
     if (wa()->getUser()->get('is_user')) {
         $history = new contactsHistoryModel();
         $history->save('/contact/' . $id, null, null, '--');
     }
     $this->response = array('done' => 1, 'url' => $contact->getPhoto());
 }
コード例 #11
0
 protected function removeExtras($app_id, $extras_id)
 {
     try {
         $paths = array();
         if (strpos($app_id, 'wa-plugins/') !== 0) {
             try {
                 $plugin_instance = waSystem::getInstance($app_id)->getPlugin($extras_id);
                 if (!$plugin_instance) {
                     return false;
                 }
                 $plugin_instance->uninstall();
             } catch (Exception $ex) {
                 waLog::log($ex->getMessage(), 'installer.log');
             }
             $this->installer->updateAppPluginsConfig($app_id, $extras_id, null);
             //wa-apps/$app_id/plugins/$slug
             $paths[] = wa()->getAppPath("{$this->extras_type}/{$extras_id}", $app_id);
             $paths[] = wa()->getTempPath(null, $app_id);
             //wa-cache/temp/$app_id/
             $paths[] = wa()->getAppCachePath(null, $app_id);
             //wa-cache/apps/$app_id/
         } else {
             $type = str_replace('wa-plugins/', '', $app_id);
             $paths[] = wa()->getConfig()->getPath('plugins') . '/' . $type . '/' . $extras_id;
             //wa-plugins/$type/$extras_id
             $paths[] = wa()->getAppCachePath(null, $type . '_' . $extras_id);
             //wa-cache/apps/$app_id/
         }
         foreach ($paths as $path) {
             waFiles::delete($path, true);
         }
         return true;
     } catch (Exception $ex) {
         //TODO check config
         if (strpos($app_id, 'wa-plugins/') !== 0) {
             if (file_exists(reset($paths) . '/lib/plugin.php')) {
                 $this->installer->updateAppPluginsConfig($app_id, $extras_id, true);
             }
         }
         throw $ex;
     }
 }
コード例 #12
0
ファイル: shopProduct.model.php プロジェクト: Lazary/webasyst
 public function delete(array $product_ids)
 {
     if (wa()->getEnv() !== 'cli') {
         $delete_ids = $this->filterAllowedProductIds($product_ids);
     } else {
         $delete_ids = $product_ids;
     }
     // remove files
     foreach ($delete_ids as $product_id) {
         try {
             waFiles::delete(shopProduct::getPath($product_id, null, false));
             waFiles::delete(shopProduct::getPath($product_id, null, true));
         } catch (waException $e) {
         }
     }
     if (empty($delete_ids)) {
         return false;
     }
     $params = array('ids' => $delete_ids);
     /**
      * @event product_delete
      * @param array [string]mixed $params
      * @param array [string]array $params['ids'] Array of IDs of deleted product entries
      * @return void
      */
     wa()->event('product_delete', $params);
     // remove from related models
     foreach (array(new shopProductFeaturesModel(), new shopProductImagesModel(), new shopProductReviewsModel(), new shopProductServicesModel(), new shopProductSkusModel(), new shopProductStocksModel(), new shopProductStocksLogModel(), new shopProductTagsModel(), new shopCategoryProductsModel(), new shopSetProductsModel(), new shopSearchIndexModel(), new shopProductFeaturesSelectableModel(), new shopProductParamsModel(), new shopCartItemsModel()) as $model) {
         $model->deleteByProducts($delete_ids);
     }
     $type_ids = $this->select('DISTINCT `type_id`')->where($this->getWhereByField($this->id, $delete_ids))->fetchAll('type_id');
     // remove records
     if ($this->deleteById($delete_ids)) {
         $type_model = new shopTypeModel();
         $type_model->recount(array_keys($type_ids));
         if ($cache = wa('shop')->getCache()) {
             $cache->deleteGroup('sets');
         }
         return $delete_ids;
     }
     return false;
 }
コード例 #13
0
 public function execute()
 {
     try {
         $path_cache = waConfig::get('wa_path_cache');
         waFiles::delete($path_cache, true);
         waFiles::protect($path_cache);
         $app_path = waConfig::get('wa_path_apps');
         $apps = new waInstallerApps();
         $app_list = $apps->getApplicationsList(true);
         foreach ($app_list as $app) {
             if (isset($app['enabled']) && $app['enabled']) {
                 $path_cache = $app_path . '/' . $app['slug'] . '/js/compiled';
                 waFiles::delete($path_cache, true);
             }
         }
         $this->response['message'] = _w('Cache cleared');
     } catch (Exception $ex) {
         $this->setError($ex->getMessage());
     }
 }
コード例 #14
0
 public function execute()
 {
     $deleted = false;
     if ($this->getRights('delete_files')) {
         $path = waRequest::post('path');
         if ($path) {
             $full_path = logsHelper::getAbsolutePath($path);
             if (!is_dir($full_path)) {
                 $available = logsHelper::checkPath($full_path, false);
                 if ($available) {
                     $deleted = waFiles::delete($full_path);
                 }
             }
         }
     }
     if ($deleted) {
         $update_total_size = waRequest::get('update_size', 0, waRequest::TYPE_INT) == 1;
         $this->response['total_size'] = $update_total_size ? logsHelper::getTotalLogsSize() : '';
     } else {
         $this->errors[] = _wp('File cannot be deleted');
     }
 }
 public function execute()
 {
     $id = waRequest::post('id', null, waRequest::TYPE_INT);
     $filter = waRequest::post('filter', 'grayscale', waRequest::TYPE_STRING_TRIM);
     if (!$id) {
         throw new waException(_w("Can't apply a filter to photo: unknown photo id"));
     }
     if (!isset($this->filters[$filter])) {
         throw new waException(_w("Can't apply a filter to photo: unknown filter"));
     }
     $plugin = wa('photos')->getPlugin('imageeffects');
     $filter_params = $plugin->getSettings($filter);
     $filter_params = $filter_params ? $filter_params : array();
     $filter = $this->filters[$filter];
     $photo_model = new photosPhotoModel();
     $photo_rights_model = new photosPhotoRightsModel();
     $photo = $photo_model->getById($id);
     $photo_rights_model = new photosPhotoRightsModel();
     if (!$photo_rights_model->checkRights($photo, true)) {
         throw new waException(_w("You don't have sufficient access rights"));
     }
     $photo_path = photosPhoto::getPhotoPath($photo);
     $image = new photosImage($photo_path);
     if ($image->filter($filter, $filter_params)->save()) {
         waFiles::delete(photosPhoto::getPhotoThumbDir($photo));
         $edit_datetime = date('Y-m-d H:i:s');
         $photo_model->updateById($id, array('edit_datetime' => $edit_datetime));
         $photo['edit_datetime'] = $edit_datetime;
         $original_photo_path = photosPhoto::getOriginalPhotoPath($photo);
         if (wa('photos')->getConfig()->getOption('save_original') && file_exists($original_photo_path)) {
             $photo['original_exists'] = true;
         } else {
             $photo['original_exists'] = false;
         }
         $this->response['photo'] = $photo;
         $this->log('photo_edit', 1);
     }
 }
コード例 #16
0
 public function execute()
 {
     $domain_id = waRequest::post('domain_id');
     if ($domain_id) {
         // check domain
         $domain_model = new siteDomainModel();
         $domain = $domain_model->getById($domain_id);
         $route = waRequest::post('route');
         if ($domain) {
             // delete from routing
             $path = $this->getConfig()->getPath('config', 'routing');
             if (file_exists($path)) {
                 $routes = (include $path);
                 if (isset($routes[$domain['name']])) {
                     // delete route
                     if ($route && isset($routes[$domain['name']][$route])) {
                         unset($routes[$domain['name']][$route]);
                         // save new routing config
                         waUtils::varExportToFile($routes, $path);
                     } elseif (!$route) {
                         unset($routes[$domain['name']]);
                         // save new routing config
                         waUtils::varExportToFile($routes, $path);
                     }
                 }
             }
             if (!$route) {
                 // delete site files (favicon, etc.)
                 waFiles::delete(wa()->getDataPath('data/' . $domain['name']), true);
                 // delete site from db
                 $domain_model->deleteById($domain_id);
                 $this->logAction('site_delete');
             }
         }
     }
 }
コード例 #17
0
 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);
     }
 }
コード例 #18
0
 /**
  *
  * Compress theme into archive file
  * @param string $path target archive path
  * @param string $name archive filename
  * @return string arcive path
  */
 public function compress($path, $name = null)
 {
     if (!$name) {
         $name = "webasyst.{$this->app}.theme.{$this->id}.tar.gz";
     }
     $target_file = "{$path}/{$this->app}/{$name}";
     $autoload = waAutoload::getInstance();
     $autoload->add('Archive_Tar', 'wa-installer/lib/vendors/PEAR/Tar.php');
     $autoload->add('PEAR', 'wa-installer/lib/vendors/PEAR/PEAR.php');
     if (file_exists($this->path) && class_exists('Archive_Tar', true)) {
         waFiles::create($target_file);
         $tar_object = new Archive_Tar($target_file, true);
         $tar_object->setIgnoreRegexp('@(\\.(php\\d?|svn|git|fw_|files\\.md5$))@');
         $path = getcwd();
         chdir(dirname($this->path));
         if (!$tar_object->create('./' . basename($this->path))) {
             waFiles::delete($target_file);
         }
         chdir($path);
     }
     return $target_file;
 }
コード例 #19
0
 private function stepImportImage()
 {
     /**
      * @var shopProductImagesModel $model
      */
     static $model;
     if (!is_array($this->data['map'][self::STAGE_IMAGE]) && $this->data['map'][self::STAGE_IMAGE]) {
         $this->data['map'][self::STAGE_IMAGE] = array($this->data['map'][self::STAGE_IMAGE]);
     }
     if ($file = reset($this->data['map'][self::STAGE_IMAGE])) {
         if (!$model) {
             $model = new shopProductImagesModel();
         }
         //TODO store image id & if repeated - skip it
         $target = 'new';
         $u = @parse_url($file);
         $_is_url = false;
         if (!$u || !(isset($u['scheme']) && isset($u['host']) && isset($u['path']))) {
         } elseif (in_array($u['scheme'], array('http', 'https', 'ftp', 'ftps'))) {
             $_is_url = true;
         } else {
             $target = 'skip';
             $file = null;
             $this->error(sprintf('Unsupported file source protocol', $u['scheme']));
         }
         $search = array('product_id' => $this->data['map'][self::STAGE_PRODUCT], 'ext' => pathinfo($file, PATHINFO_EXTENSION));
         try {
             $name = preg_replace('@[^a-zA-Zа-яА-Я0-9\\._\\-]+@', '', basename(urldecode($file)));
             if ($_is_url) {
                 $pattern = sprintf('@/(%d)/images/(\\d+)/\\2\\.(\\d+(x\\d+)?)\\.([^\\.]+)$@', $search['product_id']);
                 if (preg_match($pattern, $file, $matches)) {
                     $image = array('product_id' => $matches[1], 'id' => $matches[2], 'ext' => $matches[5]);
                     if (strpos($file, shopImage::getUrl($image, $matches[3])) !== false && $model->getByField($image)) {
                         #skip local file
                         $target = 'skip';
                         $file = null;
                     }
                 }
                 if ($file) {
                     waFiles::upload($file, $file = wa()->getTempPath('csv/upload/images/' . waLocale::transliterate($name, 'en_US')));
                 }
             } elseif ($file) {
                 $file = $this->data['upload_path'] . $file;
             }
             if ($file && file_exists($file)) {
                 if ($image = waImage::factory($file)) {
                     $search['original_filename'] = $name;
                     $data = array('product_id' => $this->data['map'][self::STAGE_PRODUCT], 'upload_datetime' => date('Y-m-d H:i:s'), 'width' => $image->width, 'height' => $image->height, 'size' => filesize($file), 'original_filename' => $name, 'ext' => pathinfo($file, PATHINFO_EXTENSION));
                     if ($exists = $model->getByField($search)) {
                         $data = array_merge($exists, $data);
                         $thumb_dir = shopImage::getThumbsPath($data);
                         $back_thumb_dir = preg_replace('@(/$|$)@', '.back$1', $thumb_dir, 1);
                         $paths[] = $back_thumb_dir;
                         waFiles::delete($back_thumb_dir);
                         // old backups
                         if (file_exists($thumb_dir)) {
                             if (!(waFiles::move($thumb_dir, $back_thumb_dir) || waFiles::delete($back_thumb_dir)) && !waFiles::delete($thumb_dir)) {
                                 throw new waException(_w("Error while rebuild thumbnails"));
                             }
                         }
                     }
                     $image_changed = false;
                     /**
                      * TODO move it code into product core method
                      */
                     /**
                      * Extend add/update product images
                      * Make extra workup
                      * @event image_upload
                      */
                     $event = wa()->event('image_upload', $image);
                     if ($event) {
                         foreach ($event as $result) {
                             if ($result) {
                                 $image_changed = true;
                                 break;
                             }
                         }
                     }
                     if (empty($data['id'])) {
                         $image_id = $data['id'] = $model->add($data);
                     } else {
                         $image_id = $data['id'];
                         $target = 'update';
                         $model->updateById($image_id, $data);
                     }
                     if (!$image_id) {
                         throw new waException("Database error");
                     }
                     $image_path = shopImage::getPath($data);
                     if (file_exists($image_path) && !is_writable($image_path) || !file_exists($image_path) && !waFiles::create($image_path)) {
                         $model->deleteById($image_id);
                         throw new waException(sprintf("The insufficient file write permissions for the %s folder.", substr($image_path, strlen($this->getConfig()->getRootPath()))));
                     }
                     if ($image_changed) {
                         $image->save($image_path);
                         /**
                          * @var shopConfig $config
                          */
                         $config = $this->getConfig();
                         if ($config->getOption('image_save_original') && ($original_file = shopImage::getOriginalPath($data))) {
                             waFiles::copy($file, $original_file);
                         }
                     } else {
                         waFiles::copy($file, $image_path);
                     }
                     $this->data['processed_count'][self::STAGE_IMAGE][$target]++;
                 } else {
                     $this->error(sprintf('Invalid image file', $file));
                 }
             } elseif ($file) {
                 $this->error(sprintf('File %s not found', $file));
                 $target = 'skip';
                 $this->data['processed_count'][self::STAGE_IMAGE][$target]++;
             } else {
                 $this->data['processed_count'][self::STAGE_IMAGE][$target]++;
             }
         } catch (Exception $e) {
             $this->error($e->getMessage());
             //TODO skip on repeated error
         }
         array_shift($this->data['map'][self::STAGE_IMAGE]);
         ++$this->data['current'][self::STAGE_IMAGE];
         if ($_is_url) {
             waFiles::delete($file);
         }
     }
     return true;
 }
コード例 #20
0
 /**
  * @param int $id
  * @param array $data
  * @param bool $correct
  * @param shopProduct $product
  * @return array
  */
 protected function updateSku($id = 0, $data, $correct = true, shopProduct $product = null)
 {
     /**
      * @var shopProductStocksModel $stocks_model
      */
     static $stocks_model;
     /**
      * @var bool $multi_stock
      */
     static $multi_stock = null;
     /**
      * @var shopFeatureModel $feature_model
      */
     static $feature_model;
     /**
      * @var shopProductFeaturesModel $product_features_model
      */
     static $product_features_model;
     if (isset($data['price'])) {
         $data['price'] = $this->castValue('double', $data['price']);
     }
     if (isset($data['purchase_price'])) {
         $data['purchase_price'] = $this->castValue('double', $data['purchase_price']);
     }
     if (isset($data['compare_price'])) {
         $data['compare_price'] = $this->castValue('double', $data['compare_price']);
     }
     if ($id > 0) {
         if ($product && (!isset($data['virtual']) || !empty($data['virtual']))) {
             #check changes for virtual SKU
             $virtual_sku_defaults = array('price' => $product->base_price_selectable, 'purchase_price' => $product->purchase_price_selectable, 'compare_price' => $product->compare_price_selectable, 'count' => 0);
             $virtual = null;
             foreach ($virtual_sku_defaults as $field => $default) {
                 if (isset($data[$field])) {
                     $value = $data[$field];
                     if (is_array($value)) {
                         $value = max($value);
                     }
                     if ($value != $default) {
                         if ($virtual === null) {
                             $virtual = isset($product->skus[$id]) && !empty($product->skus[$id]['virtual']);
                         }
                         if ($virtual) {
                             $data['virtual'] = 0;
                             $virtual = false;
                         }
                         if (!$virtual) {
                             break;
                         }
                     }
                 }
             }
         }
         if (empty($data['eproduct']) && !empty($data['file_name'])) {
             $file_path = shopProduct::getPath($data['product_id'], "sku_file/{$id}." . pathinfo($data['file_name'], PATHINFO_EXTENSION));
             waFiles::delete($file_path);
             $data['file_name'] = '';
             $data['file_description'] = '';
         } elseif (isset($data['file_name'])) {
             unset($data['file_name']);
         }
         $this->updateById($id, $data);
     } else {
         if (!isset($data['sku'])) {
             $data['sku'] = '';
         }
         $id = $this->insert($data);
     }
     $data['id'] = $id;
     $sku_count = false;
     // if stocking for this sku
     if (isset($data['stock']) && count($data['stock'])) {
         if ($multi_stock === null) {
             $stock_model = new shopStockModel();
             $stocks = $stock_model->getAll($stock_model->getTableId());
             $multi_stock = $stocks ? array_keys($stocks) : false;
         }
         // not multistocking
         if (!$multi_stock || isset($data['stock'][0])) {
             $sku_count = self::castStock($data['stock'][0]);
             unset($data['stock']);
             $this->logCount($data['product_id'], $id, $sku_count);
             // multistocking
         } else {
             $sku_count = 0;
             $missed = array_combine($multi_stock, $multi_stock);
             if (!$stocks_model) {
                 $stocks_model = new shopProductStocksModel();
             }
             // need for track transition from aggregating mode to multistocking mode
             $has_any_stocks = $stocks_model->hasAnyStocks($id);
             if (!$has_any_stocks) {
                 $this->writeOffCount($data['product_id'], $id);
             }
             foreach ($data['stock'] as $stock_id => $count) {
                 if ($stock_id > 0 && isset($missed[$stock_id])) {
                     unset($missed[$stock_id]);
                     $field = array('sku_id' => $id, 'stock_id' => $stock_id, 'product_id' => $data['product_id']);
                     $count = self::castStock($count);
                     $stock = array('count' => $count);
                     if ($count === null) {
                         $sku_count = null;
                     } else {
                         // Once turned into NULL value is not changed
                         if ($sku_count !== null) {
                             $sku_count += $count;
                         }
                     }
                     // there is taking into account stocks log inside this method
                     $stocks_model->set(array_merge($field, $stock));
                     $data['stock'][$stock_id] = $count;
                 }
             }
             //get stock_count for missed stocks
             if ($sku_count !== null && !empty($missed)) {
                 $search = array('stock_id' => $missed, 'sku_id' => $id, 'product_id' => $data['product_id']);
                 foreach ($stocks_model->getByField($search, 'stock_id') as $stock_id => $row) {
                     $count = $row['count'];
                     $data['stock'][$stock_id] = $count;
                     if ($count === null) {
                         $sku_count = null;
                     } else {
                         // Once turned into NULL value is not changed
                         if ($sku_count !== null) {
                             $sku_count += $count;
                         }
                     }
                 }
             }
         }
     }
     if ($sku_count !== false) {
         $data['count'] = $sku_count;
         $this->updateById($id, array('count' => $sku_count));
     }
     if (isset($data['features'])) {
         if (!$feature_model) {
             $feature_model = new shopFeatureModel();
         }
         if (!$product_features_model) {
             $product_features_model = new shopProductFeaturesModel();
         }
         $features = $data['features'];
         $data['features'] = array();
         $skip_values = array('', false, null);
         foreach ($features as $code => $value) {
             if ($feature = $feature_model->getByField('code', $code)) {
                 $model = shopFeatureModel::getValuesModel($feature['type']);
                 $field = array('product_id' => $data['product_id'], 'sku_id' => $id, 'feature_id' => $feature['id']);
                 $product_features_model->deleteByField($field);
                 if (is_array($value)) {
                     if (!empty($value['id'])) {
                         $field['feature_value_id'] = $value['id'];
                     } elseif (isset($value['value']) && !in_array($value['value'], $skip_values, true)) {
                         $field['feature_value_id'] = $model->getId($feature['id'], $code == 'weight' ? $value : $value['value'], $feature['type']);
                     }
                 } elseif (!in_array($value, $skip_values, true)) {
                     $field['feature_value_id'] = $model->getId($feature['id'], $value, $feature['type']);
                     $value = array('value' => $value, 'id' => $field['feature_value_id']);
                 }
                 if (!empty($field['feature_value_id'])) {
                     $product_features_model->insert($field);
                     $data['features'][$code] = $value;
                 }
             } elseif (is_numeric($code) && is_numeric($value)) {
                 if ($feature = $feature_model->getById($code)) {
                     $field = array('product_id' => $data['product_id'], 'sku_id' => $id, 'feature_id' => $code);
                     $product_features_model->deleteByField($field);
                     if (empty($value)) {
                         continue;
                     }
                     $field['feature_value_id'] = $value;
                     $product_features_model->insert($field);
                     $data['features'][$feature['code']] = $feature_model->getValuesModel($feature['type'])->getFeatureValue($value);
                 }
             }
         }
     }
     if ($correct) {
         $product_model = new shopProductModel();
         $product_model->correct($data['product_id']);
     }
     return $data;
 }
コード例 #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
 /**
  * Merge given contacts into master contact, save, send merge event, then delete slaves.
  *
  * !!! Probably should move it into something like contactsHelper
  *
  * @param array $merge_ids list of contact ids
  * @param int $master_id contact id to merge others into
  * @return array
  */
 public static function merge($merge_ids, $master_id)
 {
     $merge_ids[] = $master_id;
     // List of contacts to merge
     $collection = new contactsCollection('id/' . implode(',', $merge_ids));
     $contacts_data = $collection->getContacts('*');
     // Master contact data
     if (!$master_id || !isset($contacts_data[$master_id])) {
         throw new waException('No contact to merge into.');
     }
     $master_data = $contacts_data[$master_id];
     unset($contacts_data[$master_id]);
     $master = new waContact($master_id);
     $result = array('total_requested' => count($contacts_data) + 1, 'total_merged' => 0, 'error' => '', 'users' => 0);
     if ($master_data['photo']) {
         $filename = wa()->getDataPath(waContact::getPhotoDir($master_data['id']) . "{$master_data['photo']}.original.jpg", true, 'contacts');
         if (!file_exists($filename)) {
             $master_data['photo'] = null;
         }
     }
     $data_fields = waContactFields::getAll('enabled');
     $check_duplicates = array();
     // field_id => true
     $update_photo = null;
     // if need to update photo here it is file paths
     // merge loop
     foreach ($contacts_data as $id => $info) {
         if ($info['is_user'] > 0) {
             $result['users']++;
             unset($contacts_data[$id]);
             continue;
         }
         foreach ($data_fields as $f => $field) {
             if (!empty($info[$f])) {
                 if ($field->isMulti()) {
                     $master->add($f, $info[$f]);
                     $check_duplicates[$f] = true;
                 } else {
                     // Field does not allow multiple values.
                     // Set value if no value yet.
                     if (empty($master_data[$f])) {
                         $master[$f] = $master_data[$f] = $info[$f];
                     }
                 }
             }
         }
         // photo
         if (!$master_data['photo'] && $info['photo'] && !$update_photo) {
             $filename_original = wa()->getDataPath(waContact::getPhotoDir($info['id']) . "{$info['photo']}.original.jpg", true, 'contacts');
             if (file_exists($filename_original)) {
                 $update_photo = array('original' => $filename_original);
                 $filename_crop = wa()->getDataPath(waContact::getPhotoDir($info['id']) . "{$info['photo']}.jpg", true, 'contacts');
                 if (file_exists($filename_crop)) {
                     $update_photo['crop'] = $filename_crop;
                 }
             }
         }
         // birthday parts
         if (!empty($data_fields['birthday'])) {
             foreach (array('birth_day', 'birth_month', 'birth_year') as $f) {
                 if (empty($master_data[$f]) && !empty($info[$f])) {
                     $master[$f] = $master_data[$f] = $info[$f];
                 }
             }
         }
     }
     // Remove duplicates
     foreach (array_keys($check_duplicates) as $f) {
         $values = $master[$f];
         if (!is_array($values) || count($values) <= 1) {
             continue;
         }
         $unique_values = array();
         // md5 => true
         foreach ($values as $k => $v) {
             if (is_array($v)) {
                 if (isset($v['value']) && is_string($v['value'])) {
                     $v = $v['value'];
                 } else {
                     unset($v['ext'], $v['status']);
                     ksort($v);
                     $v = serialize($v);
                 }
             }
             $hash = md5(mb_strtolower($v));
             if (!empty($unique_values[$hash])) {
                 unset($values[$k]);
                 continue;
             }
             $unique_values[$hash] = true;
         }
         $master[$f] = array_values($values);
     }
     // Save master contact
     $errors = $master->save(array(), 42);
     // 42 == do not validate anything at all
     if ($errors) {
         $errormsg = array();
         foreach ($errors as $field => $err) {
             if (!is_array($err)) {
                 $err = array($err);
             }
             foreach ($err as $str) {
                 $errormsg[] = $field . ': ' . $str;
             }
         }
         $result['error'] = implode("\n<br>", $errormsg);
         return $result;
     }
     // Merge categories
     $category_ids = array();
     $ccm = new waContactCategoriesModel();
     foreach ($ccm->getContactsCategories($merge_ids) as $cid => $cats) {
         $category_ids += array_flip($cats);
     }
     $category_ids = array_keys($category_ids);
     $ccm->add($master_id, $category_ids);
     // update photo
     if ($update_photo) {
         $rand = mt_rand();
         $path = wa()->getDataPath(waContact::getPhotoDir($master['id']), 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($update_photo['original'])->save($filename, 90);
         if (!empty($update_photo['crop'])) {
             $filename = $path . "/" . $rand . ".jpg";
             waFiles::create($filename);
             waImage::factory($update_photo['crop'])->save($filename, 90);
         } else {
             waFiles::copy($filename, $path . "/" . $rand . ".jpg");
         }
         $master->save(array('photo' => $rand));
     }
     $result['total_merged'] = count($contacts_data) + 1;
     $contact_ids = array_keys($contacts_data);
     // wa_log
     $log_model = new waLogModel();
     $log_model->updateByField('contact_id', $contact_ids, array('contact_id' => $master_id));
     // wa_login_log
     $login_log_model = new waLoginLogModel();
     $login_log_model->updateByField('contact_id', $contact_ids, array('contact_id' => $master_id));
     // Merge event
     $params = array('contacts' => $contact_ids, 'id' => $master_data['id']);
     wa()->event(array('contacts', 'merge'), $params);
     // Delete all merged contacts
     $contact_model = new waContactModel();
     $contact_model->delete($contact_ids, false);
     // false == do not trigger event
     $history_model = new contactsHistoryModel();
     foreach ($contact_ids as $contact_id) {
         $history_model->deleteByField(array('type' => 'add', 'hash' => '/contact/' . $contact_id));
     }
     return $result;
 }
コード例 #23
0
 protected function saveRobots()
 {
     $path = wa()->getDataPath('data/' . siteHelper::getDomain() . '/', true);
     if ($robots = waRequest::post('robots')) {
         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());
         } else {
             file_put_contents($path . 'robots.txt', $robots);
         }
     } elseif (file_exists($path . 'robots.txt')) {
         waFiles::delete($path . 'robots.txt');
     }
 }
コード例 #24
0
ファイル: 1348756602.php プロジェクト: Lazary/webasyst
<?php

/**
 * Rename snippets to blocks
 */
// remove old files
$path = $this->getAppPath('lib/actions/snippets/');
if (file_exists($path)) {
    waFiles::delete($path);
}
$path = $this->getAppPath('templates/actions/snippets/');
if (file_exists($path)) {
    waFiles::delete($path);
}
// rename table
$model = new waModel();
$exists = false;
try {
    $model->exec("SELECT 1 FROM site_snippet WHERE 0");
    $exists = true;
} catch (waDbException $e) {
}
if ($exists) {
    $model->exec("RENAME TABLE `site_snippet` TO  `site_block`");
}
// change rights key
$sql = "UPDATE wa_contact_rights SET name = 'blocks' WHERE app_id = 'site' AND name = 'snippets'";
$model->exec($sql);
コード例 #25
0
 /**
  *
  * Update general plugin sort
  * @param string $plugin plugin id
  * @param int $sort 0 is first
  */
 public function setPluginSort($plugin, $sort)
 {
     $path = $this->getConfigPath('plugins.php', true);
     if (file_exists($path) && ($plugins = (include $path)) && !empty($plugins[$plugin])) {
         $sort = max(0, min(intval($sort), count($plugins) - 1));
         $order = array_flip(array_keys($plugins));
         if ($order[$plugin] != $sort) {
             $b = array($plugin => $plugins[$plugin]);
             unset($plugins[$plugin]);
             $a = array_slice($plugins, 0, $sort, true);
             $c = array_slice($plugins, $sort, null, true);
             $plugins = array_merge($a, $b, $c);
             if (waUtils::varExportToFile($plugins, $path)) {
                 waFiles::delete(waConfig::get('wa_path_cache') . "/apps/" . $this->application . '/config', true);
             } else {
                 throw new waException("Fail while update plugins sort order");
             }
         }
     }
 }
コード例 #26
0
 public function execute()
 {
     $this->response = array();
     // Initialize all needed post vars as $vars in current namespace
     foreach (array('x1', 'y1', 'x2', 'y2', 'w', 'h', 'ww', 'orig') as $var) {
         if (null === (${$var} = (int) waRequest::post($var))) {
             // $$ black magic...
             $this->response['error'] = 'wrong parameters';
             return;
         }
     }
     $id = $this->getId();
     $contact = new waContact($id);
     // Path to file we need to crop
     $rand = mt_rand();
     $dir = waContact::getPhotoDir($id, true);
     $filename = wa()->getDataPath("{$dir}{$rand}.original.jpg", true, 'contacts');
     $oldDir = wa()->getDataPath("{$dir}", true, 'contacts');
     $no_old_photo = false;
     if (!$orig) {
         // Delete the old photos if they exist
         if (file_exists($oldDir)) {
             waFiles::delete($oldDir);
             $no_old_photo = true;
         }
         waFiles::create($oldDir);
         // Is there an uploaded file in session?
         $photoEditors = $this->getStorage()->read('photoEditors');
         if (!isset($photoEditors[$id]) || !file_exists($photoEditors[$id])) {
             $this->response['error'] = 'Photo editor session is not found or already expired.';
             return;
         }
         $newFile = $photoEditors[$id];
         // Save the original image in jpeg for future use
         try {
             $img = waImage::factory($newFile)->save($filename);
         } catch (Exception $e) {
             $this->response['error'] = 'Unable to save new file ' . $filename . ' (' . pathinfo($filename, PATHINFO_EXTENSION) . ') as jpeg: ' . $e->getMessage();
             return;
         }
         // Remove uploaded file
         unset($photoEditors[$id]);
         $this->getStorage()->write('photoEditors', $photoEditors);
         unlink($newFile);
     } else {
         // cropping an old file. Move it temporarily to temp dir to delete all cached thumbnails
         $oldFile = wa()->getDataPath("{$dir}{$contact['photo']}.original.jpg", TRUE, 'contacts');
         $tempOldFile = wa()->getTempPath("{$id}/{$rand}.original.jpg", 'contacts');
         waFiles::move($oldFile, $tempOldFile);
         // Delete thumbnails
         if (file_exists($oldDir)) {
             waFiles::delete($oldDir);
         }
         waFiles::create($oldDir);
         // return original image to its proper place
         waFiles::move($tempOldFile, $filename);
     }
     if (!file_exists($filename)) {
         $this->response['error'] = 'Image to crop not found (check directory access rights).';
         return;
     }
     // Crop and save selected area
     $croppedFilename = wa()->getDataPath("{$dir}{$rand}.jpg", TRUE, 'contacts');
     try {
         $img = waImage::factory($filename);
         $scale = $img->width / $ww;
         $img->crop(floor($w * $scale), floor($h * $scale), floor($x1 * $scale), floor($y1 * $scale))->save($croppedFilename);
     } catch (Exception $e) {
         $this->response['error'] = 'Unable to crop an image: ' . $e->getMessage();
         return;
     }
     // Update record in DB for this user
     $contact['photo'] = $rand;
     $contact->save();
     if ($no_old_photo) {
         $old_app = null;
         if (wa()->getApp() !== 'contacts') {
             $old_app = wa()->getApp();
             waSystem::setActive('contacts');
         }
         $this->logAction('photo_add', null, $contact->getId());
         if ($old_app) {
             waSystem::setActive($old_app);
         }
     }
     // Update recent history to reload thumbnail correctly (if not called from personal account)
     if (wa()->getUser()->get('is_user')) {
         $history = new contactsHistoryModel();
         $history->save('/contact/' . $id, null, null, '--');
     }
     $this->response = array('url' => $contact->getPhoto());
 }
コード例 #27
0
 public function execute()
 {
     $id = waRequest::post('id', null, waRequest::TYPE_INT);
     if (!$id) {
         throw new waException("Can't rotate photo");
     }
     $direction = waRequest::post('direction', 'left', waRequest::TYPE_STRING_TRIM);
     if (isset($this->derection_angles[$direction])) {
         $photo_model = new photosPhotoModel();
         $photo_rights_model = new photosPhotoRightsModel();
         $photo = $photo_model->getById($id);
         if (!$photo_rights_model->checkRights($photo, true)) {
             throw new waException(_w("You don't have sufficient access rights"));
         }
         $photo_path = photosPhoto::getPhotoPath($photo);
         $paths = array();
         try {
             $image = new photosImage($photo_path);
             $result_photo_path = preg_replace('/(\\.[^\\.]+)$/', '.result$1', $photo_path);
             $backup_photo_path = preg_replace('/(\\.[^\\.]+)$/', '.backup$1', $photo_path);
             $paths[] = $result_photo_path;
             $result = $image->rotate($this->derection_angles[$direction])->save($result_photo_path);
             if ($result) {
                 $count = 0;
                 while (!file_exists($result_photo_path) && ++$count < 5) {
                     sleep(1);
                 }
                 if (!file_exists($result_photo_path)) {
                     throw new waException("Error while rotate. I/O error");
                 }
                 $paths[] = $backup_photo_path;
                 if (waFiles::move($photo_path, $backup_photo_path)) {
                     if (!waFiles::move($result_photo_path, $photo_path)) {
                         if (!waFiles::move($backup_photo_path, $photo_path)) {
                             throw new waException("Error while rotate. Original file corupted but backuped");
                         }
                         throw new waException("Error while rotate. Operation canceled");
                     } else {
                         $edit_datetime = date('Y-m-d H:i:s');
                         $data = array('edit_datetime' => $edit_datetime, 'width' => $photo['height'], 'height' => $photo['width']);
                         $photo_model->updateById($id, $data);
                         $photo = array_merge($photo, $data);
                         $thumb_dir = photosPhoto::getPhotoThumbDir($photo);
                         $back_thumb_dir = preg_replace('@(/$|$)@', '.back$1', $thumb_dir, 1);
                         $paths[] = $back_thumb_dir;
                         waFiles::delete($back_thumb_dir);
                         if (!(waFiles::move($thumb_dir, $back_thumb_dir) || waFiles::delete($back_thumb_dir)) && !waFiles::delete($thumb_dir)) {
                             throw new waException("Error while rebuild thumbnails");
                         }
                     }
                     $photo['thumb'] = photosPhoto::getThumbInfo($photo, photosPhoto::getThumbPhotoSize());
                     $photo['thumb_big'] = photosPhoto::getThumbInfo($photo, photosPhoto::getBigPhotoSize());
                     $photo['thumb_middle'] = photosPhoto::getThumbInfo($photo, photosPhoto::getMiddlePhotoSize());
                     $original_photo_path = photosPhoto::getOriginalPhotoPath($photo);
                     if (wa('photos')->getConfig()->getOption('save_original') && file_exists($original_photo_path)) {
                         $photo['original_exists'] = true;
                     } else {
                         $photo['original_exists'] = false;
                     }
                     $this->response['photo'] = $photo;
                     $this->log('photo_edit', 1);
                     $obligatory_sizes = $this->getConfig()->getSizes();
                     try {
                         photosPhoto::generateThumbs($photo, $obligatory_sizes);
                     } catch (Exception $e) {
                         waLog::log($e->getMessage());
                     }
                 } else {
                     throw new waException("Error while rotate. Operation canceled");
                 }
             }
             foreach ($paths as $path) {
                 waFiles::delete($path);
             }
         } catch (Exception $e) {
             foreach ($paths as $path) {
                 waFiles::delete($path);
             }
             throw $e;
         }
     }
 }
コード例 #28
0
 public function execute()
 {
     $id = waRequest::get('id', null, waRequest::TYPE_INT);
     if (!$id) {
         throw new waException("Unknown image");
     }
     $direction = waRequest::post('direction', 'left', waRequest::TYPE_STRING_TRIM);
     if (!isset($this->angles[$direction])) {
         throw new waException("Can't rotate image");
     }
     $product_images_model = new shopProductImagesModel();
     $image = $product_images_model->getById($id);
     if (!$image) {
         throw new waException("Unknown image");
     }
     // check rights
     $product_model = new shopProductModel();
     if (!$product_model->checkRights($image['product_id'])) {
         throw new waException(_w("Access denied"));
     }
     $image_path = shopImage::getPath($image);
     $paths = array();
     try {
         $result_image_path = preg_replace('/(\\.[^\\.]+)$/', '.result$1', $image_path);
         $backup_image_path = preg_replace('/(\\.[^\\.]+)$/', '.backup$1', $image_path);
         $paths[] = $result_image_path;
         if ($this->rotate($image_path, $result_image_path, $this->angles[$direction])) {
             $count = 0;
             while (!file_exists($result_image_path) && ++$count < 5) {
                 sleep(1);
             }
             if (!file_exists($result_image_path)) {
                 throw new waException(_w("Error while rotate. I/O error"));
             }
             if (!waFiles::move($image_path, $backup_image_path)) {
                 throw new waException(_w("Error while rotate. Operation canceled"));
             }
             $paths[] = $backup_image_path;
             if (!waFiles::move($result_image_path, $image_path)) {
                 if (!waFiles::move($backup_image_path, $image_path)) {
                     throw new waException(_w("Error while rotate. Original file corupted but backuped"));
                 }
                 throw new waException(_w("Error while rotate. Operation canceled"));
             }
             $datetime = date('Y-m-d H:i:s');
             $data = array('edit_datetime' => $datetime, 'width' => $image['height'], 'height' => $image['width']);
             $product_images_model->updateById($id, $data);
             $image = array_merge($image, $data);
             $thumb_dir = shopImage::getThumbsPath($image);
             $back_thumb_dir = preg_replace('@(/$|$)@', '.back$1', $thumb_dir, 1);
             $paths[] = $back_thumb_dir;
             waFiles::delete($back_thumb_dir);
             if (!(waFiles::move($thumb_dir, $back_thumb_dir) || waFiles::delete($back_thumb_dir)) && !waFiles::delete($thumb_dir)) {
                 throw new waException(_w("Error while rebuild thumbnails"));
             }
             $config = $this->getConfig();
             try {
                 shopImage::generateThumbs($image, $config->getImageSizes());
             } catch (Exception $e) {
                 waLog::log($e->getMessage());
             }
             $this->response = $image;
             $edit_datetime_ts = strtotime($image['edit_datetime']);
             $this->response['url_big'] = shopImage::getUrl($image, $config->getImageSize('big')) . '?' . $edit_datetime_ts;
             $this->response['url_crop'] = shopImage::getUrl($image, $config->getImageSize('crop')) . '?' . $edit_datetime_ts;
         }
         foreach ($paths as $path) {
             waFiles::delete($path);
         }
     } catch (Exception $e) {
         foreach ($paths as $path) {
             waFiles::delete($path);
         }
         throw $e;
     }
 }
コード例 #29
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;
 }
コード例 #30
0
ファイル: 1364917682.php プロジェクト: Lazary/webasyst
<?php

waFiles::delete($this->getAppPath('lib/actions/product/shopProductDeleteImage.controller.php'), true);
waFiles::delete($this->getAppPath('lib/actions/product/shopProductDeletePage.controller.php'), true);
waFiles::delete($this->getAppPath('lib/actions/product/shopProductDownloadImage.controller.php'), true);