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); }
protected function save(waRequestFile $file, $data) { $id = $this->model->add($file, $data); if (!$id) { throw new waException(_w("Save error")); } $photo = $this->model->getById($id); $parent_id = (int) waRequest::post('parent_id'); if ((int) waRequest::post('parent_id')) { $this->model->appendToStack($parent_id, array($id)); } return array('name' => $file->name, 'type' => $file->type, 'size' => $file->size, 'thumbnail_url' => photosPhoto::getPhotoUrl($photo, photosPhoto::getThumbPhotoSize()), 'url' => '#/photo/' . $id . '/'); }
protected function save(waRequestFile $file, $data = array()) { wa('photos'); $photo_model = new photosPhotoModel(); $data['groups'] = array(); $data['app_id'] = 'blog'; $data['hash'] = ''; $id = $photo_model->add($file, $data); if (!$id) { throw new waException(_w("Save error")); } $photo = $photo_model->getById($id); return array('id' => $id, 'photo' => $photo, 'name' => $file->name, 'type' => $file->type, 'size' => $file->size, 'url' => photosPhoto::getPhotoUrl($photo, null, !!waRequest::get('absolute')), 'thumbnail_url' => photosPhoto::getPhotoUrl($photo, photosPhoto::getThumbPhotoSize(), !!waRequest::get('absolute'))); }
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); }