public function save(waRequestFile $file, $data)
 {
     // check image
     if (!($image = $file->waImage())) {
         throw new waException(_w('Incorrect image'));
     }
     $plugin = wa()->getPlugin('publicgallery');
     $min_size = $plugin->getSettings('min_size');
     if ($min_size && ($image->height < $min_size || $image->width < $min_size)) {
         throw new waException(sprintf(_w("Image is too small. Minimum image size is %d px"), $min_size));
     }
     $max_size = $plugin->getSettings('max_size');
     if ($max_size && ($image->height > $max_size || $image->width > $max_size)) {
         throw new waException(sprintf(_w("Image is too big. Maximum image size is %d px"), $max_size));
     }
     $id = $this->model->add($file, $data);
     if (!$id) {
         throw new waException(_w("Save error"));
     }
     $tag = $plugin->getSettings('assign_tag');
     if ($tag) {
         $photos_tag_model = new photosPhotoTagsModel();
         $photos_tag_model->set($id, $tag);
     }
     return array('name' => $file->name, 'type' => $file->type, 'size' => $file->size);
 }
 public function execute()
 {
     $photo_id = waRequest::post('photo_id', array(), waRequest::TYPE_ARRAY_INT);
     $one_photo = waRequest::post('one_photo', 0, waRequest::TYPE_INT);
     $tags = waRequest::post('tags', '', waRequest::TYPE_STRING_TRIM);
     $tags = $tags ? explode(',', $tags) : array();
     $delete_tags = waRequest::post('delete_tags', array(), waRequest::TYPE_ARRAY_INT);
     $tag_model = new photosTagModel();
     $photo_tag_model = new photosPhotoTagsModel();
     $photo_rights_model = new photosPhotoRightsModel();
     $allowed_photo_id = $photo_rights_model->filterAllowedPhotoIds($photo_id, true);
     $denied_photo_id = array_values(array_diff($photo_id, $allowed_photo_id));
     if ($allowed_photo_id) {
         if ($one_photo) {
             $allowed_photo_id = $allowed_photo_id[0];
             $photo_tag_model->set($allowed_photo_id, $tags);
             $photo_model = new photosPhotoModel();
             if ($parent_id = $photo_model->getStackParentId($allowed_photo_id)) {
                 $this->response['parent_id'] = $parent_id;
             }
         } else {
             if ($delete_tags) {
                 $photo_tag_model->delete($allowed_photo_id, $delete_tags);
             }
             $photo_tag_model->assign($allowed_photo_id, $tag_model->getIds($tags, true));
         }
         $allowed_photo_id = (array) $allowed_photo_id;
         $tags = $photo_tag_model->getTags($allowed_photo_id);
         if (!$tags && $allowed_photo_id) {
             $tags = array_fill_keys($allowed_photo_id, array());
         }
         $this->response['tags'] = $tags;
     }
     if ($denied_photo_id) {
         $this->response['alert_msg'] = photosPhoto::sprintf_wplural("The operation was not performed to %d photo (%%s)", "The operation was not performed to %d photos (%%s)", count($denied_photo_id), _w("out of %d selected", "out of %d selected", count($photo_id))) . ', ' . _w("because you don't have sufficient access rights") . '.';
     }
     $this->response['cloud'] = $tag_model->getCloud();
 }