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; } } }
protected function workupPhotos(&$photos) { $renderer = new photosPhotoHtmlRenderer($this->getTheme()); $photo_model = new photosPhotoModel(); // parent of current photo (that stacked, i.e. in stack) $parent_id = null; if ($this->photo_url) { $stacked_photo = $photo_model->getByField('url', $this->photo_url); if (!$stacked_photo) { throw new waException(_w('Page not found', 404)); } $parent_id = $photo_model->getStackParentId($stacked_photo); } // During going over all photos we also look if some photo is a parent of current stacked photo foreach ($photos as &$photo) { $photo['stack_nav'] = ''; $stack = (array) $photo_model->getStack($photo['id'], array('tags' => true)); if ($stack) { foreach ($stack as &$item) { $item['thumb_custom'] = array('url' => photosPhoto::getPhotoUrlTemplate($item)); $item['full_url'] = photosFrontendAlbum::getLink($this->album) . $item['url'] . '/'; } unset($item); // iterable photo is parent of current stacked photo - replace if ($parent_id == $photo['id']) { $photo = $stacked_photo; $photo['full_url'] = photosFrontendAlbum::getLink($this->album) . $photo['url'] . '/'; $photo['stack_nav'] = $renderer->getStackNavigationPanel($stack, $photo); } else { $photo['stack_nav'] = $renderer->getStackNavigationPanel($stack, $photo); } } $photo['frontend_link'] = photosFrontendPhoto::getLink($photo, array('full_url' => $this->album_url)); } unset($photo); }
public function execute() { $photo_id = waRequest::post('photo_id', array(), waRequest::TYPE_ARRAY_INT); $status = waRequest::post('status', 0, waRequest::TYPE_INT); $groups = waRequest::post('groups', array(), waRequest::TYPE_ARRAY_INT); if (!$groups) { $status = -1; // only author have access to this photo $groups = array(-$this->getUser()->getId()); } // necessary when manage access rights for one photo. When in one photo extra info is needed in response $is_one_photo = waRequest::post('one_photo', 0, waRequest::TYPE_INT); // necessary only when manage access rights for several photos $prev_allowed_photo_id = waRequest::post('allowed_photo_id', array(), waRequest::TYPE_ARRAY_INT); $prev_denied_photo_id = waRequest::post('denied_photo_id', array(), waRequest::TYPE_ARRAY_INT); $this->photo_model = new photosPhotoModel(); $this->photo_rights_model = new photosPhotoRightsModel(); $allowed_photo_id = $this->photo_rights_model->filterAllowedPhotoIds($photo_id, true); $denied_photo_id = array_diff($photo_id, $allowed_photo_id); $this->photo_model->updateAccess($allowed_photo_id, $status, $groups); // leave only id of parents $denied_parent_id = array(); if ($denied_photo_id) { foreach ($this->photo_model->getByField('id', $denied_photo_id, 'id') as $photo) { $denied_parent_id[] = $photo['parent_id'] > 0 ? $photo['parent_id'] : $photo['id']; } } $denied_photo_id = array_values(array_unique(array_merge($prev_denied_photo_id, $denied_parent_id))); $this->response['denied_photo_id'] = $denied_photo_id; // leave only id of parents $allowed_parent_id = array(); if ($allowed_photo_id) { foreach ($this->photo_model->getByField('id', $allowed_photo_id, 'id') as $photo) { $allowed_parent_id[] = $photo['parent_id'] > 0 ? $photo['parent_id'] : $photo['id']; } } $allowed_photo_id = array_values(array_unique(array_merge($prev_allowed_photo_id, $allowed_parent_id))); $this->response['allowed_photo_id'] = $allowed_photo_id; $all_photos_length = waRequest::post('photos_length', 0, waRequest::TYPE_INT); if (!$all_photos_length) { $all_photos_length = count($photo_id); } $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 one photo send extra info for update cache and widget if ($is_one_photo && $allowed_photo_id) { $frontend_link_template = photosFrontendPhoto::getLink(array('url' => '%url%')); if (count($photo_id) > 1) { // stack $stack = $this->photo_model->getStack($photo_id[0]); foreach ($stack as &$photo) { $photo = $this->workup($photo); } unset($photo); $this->response['stack'] = array_values($stack); } else { // just photo $photo_id = $photo_id[0]; $photo = $this->photo_model->getById($photo_id); $photo = $this->workup($photo); $this->response['photo'] = $photo; } $this->response['frontend_link_template'] = $frontend_link_template; } }
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(); } } }