private function workup($photo) { $photo['edit_rights'] = $this->photo_rights_model->checkRights($photo, true); $photo['private_url'] = photosPhotoModel::getPrivateUrl($photo); $photo['thumb_big'] = photosPhoto::getThumbInfo($photo, photosPhoto::getBigPhotoSize()); $photo['thumb_middle'] = photosPhoto::getThumbInfo($photo, photosPhoto::getMiddlePhotoSize()); $photo['thumb_crop'] = photosPhoto::getThumbInfo($photo, photosPhoto::getCropPhotoSize()); $photo['thumb'] = photosPhoto::getThumbInfo($photo, photosPhoto::getThumbPhotoSize()); return $photo; }
public function execute() { $photo_id = waRequest::get('photo_id', array(), waRequest::TYPE_ARRAY_INT); if (!$photo_id) { throw new waException(_w('Empty photo list')); } $photo_model = new photosPhotoModel(); // dialog for one photo if (count($photo_id) == 1) { $photo_id = current($photo_id); $photo = $photo_model->getById($photo_id); $photo_right_model = new photosPhotoRightsModel(); if (!$photo_right_model->checkRights($photo, true)) { $rights = array(0 => array('group_id' => 0, 'photo_id' => null)); } else { $rights = $photo_right_model->getByField('photo_id', $photo_id, 'group_id'); } } else { // dialog for several selected photos // dummies for correct template randering $photo = array('status' => 1); $rights = array(0 => array('group_id' => 0, 'photo_id' => null)); $allowed_photo_id = (array) $photo_model->filterByField($photo_id, 'status', 1); $this->view->assign('photo_count', count($photo_id)); $this->view->assign('disable_submit', count($allowed_photo_id) != count($photo_id)); } $groups_model = new waGroupModel(); $groups = $groups_model->getAll('id', true); $this->view->assign('groups', $groups); $this->view->assign('photo', $photo); $this->view->assign('rights', $rights); }
public function execute() { $path = null; $photo_rights_model = new photosPhotoRightsModel(); $photo_id = waRequest::get('photo_id', null, waRequest::TYPE_INT); if ($photo_rights_model->checkRights($photo_id, true)) { $photo_model = new photosPhotoModel(); if ($photo = $photo_model->getById($photo_id)) { if (waRequest::get('original')) { $path = photosPhoto::getOriginalPhotoPath($photo); } else { $path = photosPhoto::getPhotoPath($photo); } } } if ($path) { if ($attach = waRequest::get('attach') ? true : false) { $response = $this->getResponse(); $response->addHeader('Expires', 'tomorrow'); $response->addHeader('Cache-Control', ($photo['status'] == 1 ? 'public' : 'private') . ', max-age=' . 86400 * 30); } waFiles::readFile($path, $attach ? null : basename($photo['name'] . '.' . $photo['ext']), true, !$attach); } else { throw new waException(_w("Photo not found"), 404); } }
public function execute() { $stack = array(); $parent_id = waRequest::post('parent_id', null, waRequest::TYPE_INT); $photo_id = (array) waRequest::post('photo_id', array(), waRequest::TYPE_ARRAY_INT); $prev_denied_photo_id = waRequest::post('denied_photo_id', array(), waRequest::TYPE_ARRAY_INT); $photo_model = new photosPhotoModel(); $photo_rights_model = new photosPhotoRightsModel(); if (!$photo_rights_model->checkRights($parent_id, true)) { throw new waException(_w("You don't have sufficient access rights")); } $allowed_photo_id = $photo_rights_model->filterAllowedPhotoIds($photo_id, true); $denied_photo_ids = array_diff($photo_id, $allowed_photo_id); if ($allowed_photo_id) { $parent = $photo_model->getById($parent_id); $stack[$parent_id] = $allowed_photo_id; if ($parent['stack_count'] > 0) { $photo_model->appendToStack($parent_id, $allowed_photo_id); } else { $photo_model->makeStack($parent_id, $allowed_photo_id); } } $denied_parent_ids = array(); if ($denied_photo_ids) { foreach ($photo_model->getByField('id', $denied_photo_ids, 'id') as $photo) { $denied_parent_ids[] = $photo['parent_id'] > 0 ? $photo['parent_id'] : $photo['id']; } } $denied_photo_id = array_values(array_unique(array_merge($prev_denied_photo_id, $denied_parent_ids))); $this->response['denied_photo_ids'] = $denied_photo_id; $all_photos_length = waRequest::post('photos_length', 0, waRequest::TYPE_INT); if (!$all_photos_length) { $all_photos_length = count($photo_id); } $all_photos_length += 1; // plus parent photo $denied_photos_length = count($denied_photo_id); if ($denied_photos_length > 0 && $all_photos_length > 0) { $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)", $denied_photos_length, _w("out of %d selected", "out of %d selected", $all_photos_length)) . ', ' . _w("because you don't have sufficient access rights") . '.'; } if ($stack) { /** * Extra actions after making stack * @event make_stack * @params array[int][int]int $stack[%parent_id%][] */ wa()->event('make_stack', $stack); $this->log('photos_stack', 1); } $this->response['parent_id'] = $parent_id; $this->response['photo'] = $photo_model->getById($parent_id); }
public function execute() { $id = waRequest::get('id', null, waRequest::TYPE_INT); if ($id) { $photo_rights_model = new photosPhotoRightsModel(); if (!$photo_rights_model->checkRights($id, true)) { throw new waException(_w("You don't have sufficient access rights")); } $photo_model = new photosPhotoModel(); $photo_model->unstack($id); $this->log('photos_unstack', 1); } }
public function execute() { $id = waRequest::post('id', null, waRequest::TYPE_INT); $before_id = waRequest::post('before_id', 0, waRequest::TYPE_INT); if ($id) { $photo_rights_model = new photosPhotoRightsModel(); if (!$photo_rights_model->checkRights($id, true)) { throw new waException(_w("You don't have sufficient access rights")); } $photo_model = new photosPhotoModel(); $photo_model->moveStackSort($id, $before_id); $photo = $photo_model->getById($id); if ($stack = $photo_model->getStack($id, array('thumb' => true))) { $this->response['stack'] = $stack; } } }
public function execute() { $this->photo_ids = waRequest::post('photo_id', array(), waRequest::TYPE_ARRAY_INT); $album_id = waRequest::post('album_id', array(), waRequest::TYPE_ARRAY_INT); $copy = waRequest::post('copy', 1, waRequest::TYPE_INT); $this->album_photos_model = new photosAlbumPhotosModel(); $photo_rights_model = new photosPhotoRightsModel(); if (!$copy) { // it means manage with one photo $photo_id = $this->photo_ids[0]; if (!$photo_rights_model->checkRights($photo_id, true)) { throw new waException("You don't have sufficient access rights"); } $early_albums = array_keys($this->album_photos_model->getByField('photo_id', $photo_id, 'album_id')); // TODO: check rights for editing (take into account deleting!) $this->album_photos_model->set($photo_id, $album_id); $this->log('photos_move', 1); $albums = $this->getAlbumsCounters(); $old_albums = array(); foreach ($early_albums as $a_id) { if (!isset($albums[$a_id])) { $collection = new photosCollection('/album/' . $a_id); $album = array('id' => $a_id, 'count' => $collection->count(), 'count_new' => 0); $old_albums[] = $album; } } $this->response['albums'] = array_values($albums); $this->response['old_albums'] = $old_albums; } else { // otherwise coping photos to albums $allowed_photo_id = $photo_rights_model->filterAllowedPhotoIds($this->photo_ids, true); $denied_photo_id = array_values(array_diff($this->photo_ids, $allowed_photo_id)); $album_rights_model = new photosAlbumRightsModel(); $allowed_album_id = $album_rights_model->filterAllowedAlbumIds($album_id, true); $denied_album_id = array_values(array_diff($album_id, $allowed_album_id)); if ($allowed_album_id && $allowed_photo_id) { $this->album_photos_model->add($allowed_photo_id, $allowed_album_id); $this->response['albums'] = array_values($this->getAlbumsCounters()); $this->log('photos_move', 1); } 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($this->photo_ids))) . ', ' . _w("because you don't have sufficient access rights") . '.'; } } }
public function execute() { //TODO: delete this class $name = waRequest::post('name', '', waRequest::TYPE_STRING_TRIM); if (in_array($name, $this->availableParams) === false) { throw new Exception("Can't set param: unknown param"); } $id = waRequest::post('id', null, waRequest::TYPE_INT); if (!$id) { throw new Exception("Can't set param"); } $photo_rights_model = new photosPhotoRightsModel(); if (!$photo_rights_model->checkRights($id, true)) { throw new waException(_w("You don't have sufficient access rights")); } $value = waRequest::post('value', false, waRequest::TYPE_STRING_TRIM) ? 1 : 0; $app = $this->getApp(); $user = waSystem::getInstance()->getUser(); $user->setSettings($app, $name, $value); }
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); } }
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; } } }
public function execute() { $name = waRequest::post('name', '', waRequest::TYPE_STRING_TRIM); if (in_array($name, $this->availableFields) === false) { throw new waException("Can't update photo: unknown field"); } $photo_id = waRequest::post('id', null, waRequest::TYPE_ARRAY_INT); $value = waRequest::post('value', '', waRequest::TYPE_STRING_TRIM); if ($photo_id) { $photo_rights_model = new photosPhotoRightsModel(); if (count($photo_id) == 1) { // editing only one photo if (!$photo_rights_model->checkRights(current($photo_id), true)) { throw new waException(_w("You don't have sufficient access rights")); } // validations for one photo if ($name == 'url') { if (!$this->validateUrl($value, current($photo_id))) { // $photo_id is array of ids, so make current() $this->errors['url'] = _w('URL is in use'); return; } } $allowed_photo_id = $photo_id; $denied_photo_id = array(); } else { $allowed_photo_id = $photo_rights_model->filterAllowedPhotoIds($photo_id, true); $denied_photo_id = array_diff($photo_id, $allowed_photo_id); } if ($allowed_photo_id) { if ($name == 'rate') { $value = (int) $value; if ($value < 0 || $value > 5) { $value = 0; } } $data[$name] = $value; $this->photo_model = new photosPhotoModel(); if ($name == 'description' || $name == 'rate') { $this->photo_model->update($allowed_photo_id, $data); if (count($photo_id) == 1 && $allowed_photo_id) { // means that we edit field in one-photo page $photo_id = current($photo_id); if ($parent_id = $this->photo_model->getStackParentId($photo_id)) { $this->response['parent_id'] = $parent_id; } } // change count of rated if ($name == 'rate') { $this->response['count'] = $this->photo_model->countRated(); $this->log('photos_rate', 1); } } else { // update only parent photo(s) $this->photo_model->updateById($allowed_photo_id, $data); } if ($name == 'name') { $this->response['value'] = photosPhoto::escape($value); } } if (count($denied_photo_id) > 0 && count($photo_id) > 0) { $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") . '.'; } $allowed_photo_id_map = array(); foreach ($allowed_photo_id as $id) { $allowed_photo_id_map[$id] = true; } $this->response['allowed_photo_id'] = $allowed_photo_id_map; } }
public function execute() { $id = waRequest::post('id', null, waRequest::TYPE_INT); if (!$id) { throw new waException("Can't restore photo"); } $photo_model = new photosPhotoModel(); $photo_rights_model = new photosPhotoRightsModel(); $photo = $photo_model->getById($id); if (!$photo_rights_model->checkRights($photo, true)) { throw new waException("You don't have sufficient access rights"); } $original_photo_path = photosPhoto::getOriginalPhotoPath($photo); if (!wa('photos')->getConfig()->getOption('save_original') || !file_exists($original_photo_path)) { throw new waException("Can't restore photo. Original photo doesn't exist"); } $paths = array(); try { $photo_path = photosPhoto::getPhotoPath($photo); $backup_photo_path = preg_replace('/(\\.[^\\.]+)$/', '.backup$1', $photo_path); if (waFiles::move($photo_path, $backup_photo_path)) { if (!waFiles::move($original_photo_path, $photo_path)) { if (!waFiles::move($backup_photo_path, $photo_path)) { throw new waException("Error while restore. Current file corupted but backuped"); } $paths[] = $backup_photo_path; throw new waException("Error while restore. Operation canceled"); } else { $image = new photosImage($photo_path); $edit_datetime = date('Y-m-d H:i:s'); $data = array('edit_datetime' => $edit_datetime, 'width' => $image->width, 'height' => $image->height); $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); // old backups if (!waFiles::move($thumb_dir, $back_thumb_dir) && !waFiles::delete($thumb_dir)) { throw new waException("Error while rebuild thumbnails"); } $photo['original_exists'] = false; $photo['thumb'] = photosPhoto::getThumbInfo($photo, photosPhoto::getThumbPhotoSize()); $photo['thumb_big'] = photosPhoto::getThumbInfo($photo, photosPhoto::getBigPhotoSize()); $photo['thumb_middle'] = photosPhoto::getThumbInfo($photo, photosPhoto::getMiddlePhotoSize()); $sizes = $this->getConfig()->getSizes(); try { photosPhoto::generateThumbs($photo, $sizes); } catch (Exception $e) { waLog::log($e->getMessage()); } $this->response['photo'] = $photo; $this->log('photo_reverttooriginal', 1); } } else { throw new waException("Error while restore. Operation canceled"); } foreach ($paths as $path) { waFiles::delete($path); } } catch (Exception $e) { foreach ($paths as $path) { waFiles::delete($path); } throw $e; } }
public function execute() { $this->photo_ids = waRequest::post('photo_id', array(), waRequest::TYPE_ARRAY_INT); $album_id = waRequest::post('album_id', array(), waRequest::TYPE_ARRAY_INT); $copy = waRequest::post('copy', 1, waRequest::TYPE_INT); $this->album_photos_model = new photosAlbumPhotosModel(); $photo_rights_model = new photosPhotoRightsModel(); if (!$copy) { // it means manage with one photo $photo_id = $this->photo_ids[0]; if (!$photo_rights_model->checkRights($photo_id, true)) { throw new waException("You don't have sufficient access rights"); } $early_albums = array_keys($this->album_photos_model->getByField('photo_id', $photo_id, 'album_id')); // TODO: check rights for editing (take into account deleting!) $this->album_photos_model->set($photo_id, $album_id); $this->log('photos_move', 1); $albums = $this->getAlbumsCounters(); $old_albums = array(); foreach ($early_albums as $a_id) { if (!isset($albums[$a_id])) { $collection = new photosCollection('/album/' . $a_id); $album = array('id' => $a_id, 'count' => $collection->count(), 'count_new' => 0); $old_albums[] = $album; } } $this->response['albums'] = array_values($albums); $this->response['old_albums'] = $old_albums; } else { // otherwise copy photos to albums $allowed_photo_id = $photo_rights_model->filterAllowedPhotoIds($this->photo_ids, true); $denied_photo_id = array_values(array_diff($this->photo_ids, $allowed_photo_id)); $album_rights_model = new photosAlbumRightsModel(); $allowed_album_id = $album_rights_model->filterAllowedAlbumIds($album_id, true); $denied_album_id = array_values(array_diff($album_id, $allowed_album_id)); if ($allowed_album_id && $allowed_photo_id) { $this->album_photos_model->add($allowed_photo_id, $allowed_album_id); $this->log('photos_move', 1); } $albums = $this->getAlbumsCounters(); $this->response['albums'] = array_values($albums); 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($this->photo_ids))) . ', ' . _w("because you don't have sufficient access rights") . '.'; } } // Set cover photos for albums if first photo just been added to it $photo_model = new photosPhotoModel(); $album_model = new photosAlbumModel(); $allowed_photo_id = isset($allowed_photo_id) ? $allowed_photo_id : array($photo_id); $no_cover_album_ids = array(); foreach (ifset($allowed_album_id, $album_id) as $album_id) { if (!empty($albums[$album_id]) && empty($albums[$album_id]['key_photo_id'])) { $no_cover_album_ids[] = $album_id; } } $photos = array(); while ($allowed_photo_id && $no_cover_album_ids) { // Get random photo from added and make sure it exists shuffle($allowed_photo_id); $photo_id = array_pop($allowed_photo_id); if (!empty($photos[$photo_id])) { $photo = $photos[$photo_id]; } else { $photos[$photo_id] = $photo = $photo_model->getById($photo_id); } if (!$photo) { continue; } // Photo exists, so add it back $allowed_photo_id[] = $photo_id; // Set cover for one album $album_id = array_pop($no_cover_album_ids); $album_model->updateById($album_id, array('key_photo_id' => $photo_id)); photosPhoto::generateThumbs($photo, array('192x192')); } }
public function rotate($id, $clockwise = true) { $photo_rights_model = new photosPhotoRightsModel(); $photo = $this->getById($id); if (!$photo || !$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; $angle = $clockwise ? '90' : '-90'; $result = $image->rotate($angle)->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']); $this->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"); } } $obligatory_sizes = wa('photos')->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; } }
public function execute() { $id = waRequest::post('id', 0, waRequest::TYPE_INT); $in_stack = waRequest::post('in_stack', 0, waRequest::TYPE_INT); $hash = waRequest::post('hash', null, waRequest::TYPE_STRING_TRIM); $hash = urldecode($hash); // get photo $this->photo_model = new photosPhotoModel(); $this->photo = $this->photo_model->getById($id); if (!$this->photo) { throw new waException(_w("Photo doesn't exists"), 404); } $photo_rights_model = new photosPhotoRightsModel(); if (!$photo_rights_model->checkRights($this->photo)) { throw new waRightsException(_w("You don't have sufficient access rights")); } $this->photo['name_not_escaped'] = $this->photo['name']; $this->photo = photosPhoto::escapeFields($this->photo); $this->photo['upload_datetime_formatted'] = waDateTime::format('humandate', $this->photo['upload_datetime']); $this->photo['upload_timestamp'] = strtotime($this->photo['upload_datetime']); $this->photo['edit_rights'] = $photo_rights_model->checkRights($this->photo, true); $this->photo['private_url'] = photosPhotoModel::getPrivateUrl($this->photo); $this->photo['thumb'] = photosPhoto::getThumbInfo($this->photo, photosPhoto::getThumbPhotoSize()); $this->photo['thumb_big'] = photosPhoto::getThumbInfo($this->photo, photosPhoto::getBigPhotoSize()); $this->photo['thumb_middle'] = photosPhoto::getThumbInfo($this->photo, photosPhoto::getMiddlePhotoSize()); $original_photo_path = photosPhoto::getOriginalPhotoPath($this->photo); if (wa('photos')->getConfig()->getOption('save_original') && file_exists($original_photo_path)) { $this->photo['original_exists'] = true; } else { $this->photo['original_exists'] = false; } $photo_tags_model = new photosPhotoTagsModel(); $tags = $photo_tags_model->getTags($id); $this->photo['tags'] = $tags; $this->response['photo'] = $this->photo; // get stack if it's possible if (!$in_stack && ($stack = $this->photo_model->getStack($id, array('thumb' => true, 'thumb_crop' => true, 'thumb_big' => true, 'thumb_middle' => true)))) { $this->response['stack'] = $stack; } // get albums $album_photos_model = new photosAlbumPhotosModel(); $albums = $album_photos_model->getAlbums($id, array('id', 'name')); $this->response['albums'] = isset($albums[$id]) ? array_values($albums[$id]) : array(); // exif info $exif_model = new photosPhotoExifModel(); $exif = $exif_model->getByPhoto($this->photo['id']); if (isset($exif['DateTimeOriginal'])) { $exif['DateTimeOriginal'] = waDateTime::format('humandatetime', $exif['DateTimeOriginal'], date_default_timezone_get()); } $this->response['exif'] = $exif; // get author $contact = new waContact($this->photo['contact_id']); $this->response['author'] = array('id' => $contact['id'], 'name' => photosPhoto::escape($contact['name']), 'photo_url' => $contact->getPhoto(photosPhoto::AUTHOR_PHOTO_SIZE), 'backend_url' => $this->getConfig()->getBackendUrl(true) . 'contacts/#/contact/' . $contact['id']); // for making inline-editable widget $this->response['frontend_link_template'] = photosFrontendPhoto::getLink(array('url' => '%url%')); $hooks = array(); $parent_id = $this->photo_model->getStackParentId($this->photo); $photo_id = $parent_id ? $parent_id : $id; /** * Extend photo page * Add extra widget(s) * @event backend_photo * @return array[string][string]string $return[%plugin_id%]['bottom'] In bottom, under photo any widget */ $hooks['backend_photo'] = wa()->event('backend_photo', $photo_id); $this->response['hooks'] = $hooks; if ($hash !== null) { $collection = new photosCollection($hash); if (strstr($hash, 'rate>0') !== false) { $collection->orderBy('p.rate DESC, p.id'); } $this->response['photo_stream'] = $this->getPhotoStream($collection); if ($collection->getAlbum()) { $this->response['album'] = $collection->getAlbum(); } } }