public function execute() { $available_fields = array_merge($this->generic_fields, $this->stack_fields); $data = waRequest::post('data'); $photo_id = array(); foreach ($data as &$item_data) { if (isset($item_data['id']) && ($id = array_unique(array_map('intval', explode(',', $item_data['id']))))) { unset($item_data['id']); $fields = array_diff_key(array_keys($item_data), $available_fields); if ($fields) { throw new waException("Invalid request format: unexpected field(s) " . implode(', ', $fields)); } $photo_id = array_merge($photo_id, $id); $item_data['id'] = $id; } else { throw new waException("Invalid request format: missed or invalid item ID"); } } unset($item_data); $this->response['update'] = array(); if ($photo_id) { $photo_rights_model = new photosPhotoRightsModel(); $allowed_photo_id = $photo_rights_model->filterAllowedPhotoIds($photo_id, true); $denied_photo_id = array_diff($photo_id, $allowed_photo_id); if ($allowed_photo_id) { $photo_model = new photosPhotoModel(); $generic_fields = array_fill_keys($this->generic_fields, true); $stack_fields = array_fill_keys($this->stack_fields, true); foreach ($data as $item_data) { if ($item_data_id = array_intersect($item_data['id'], $allowed_photo_id)) { unset($item_data['id']); foreach ($item_data as $field => &$value) { $value = $this->validateField($field, $value); } unset($value); if ($data = array_intersect_key($item_data, $stack_fields)) { $photo_model->update($item_data_id, $data); $this->response['update'][] = array('id' => $item_data_id, 'data' => $data); } if ($data = array_intersect_key($item_data, $generic_fields)) { $photo_model->updateById($item_data_id, $data); $this->response['update'][] = array('id' => $item_data_id, 'data' => $data); } } } } 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() { $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() { $photo_id = waRequest::post('photo_id', null, 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(); $allowed_photo_id = $photo_rights_model->filterAllowedPhotoIds($photo_id, true); $denied_photo_id = array_diff($photo_id, $allowed_photo_id); if ($allowed_photo_id) { // before deleting define if is it children photo in stack (one photo page) if (count($allowed_photo_id) == 1 && count($photo_id) == 1) { $photo = $photo_model->getById($allowed_photo_id); if ($photo) { $photo = reset($photo); if ($photo['parent_id'] > 0) { $this->response['parent_id'] = $photo['parent_id']; } } } foreach ($allowed_photo_id as $id) { $photo_model->delete($id); /** * Extend delete process * Make extra workup * @event photo_delete */ wa()->event('photo_delete', $id); } $this->log('photos_delete', 1); } $denied_parent_id = array(); if ($denied_photo_id) { foreach ($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; $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 ($denied_photos_length == $all_photos_length) { $this->response['denied_all'] = true; } else { $this->response['denied_all'] = false; } }
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() { $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(); }
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() { $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() { $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')); } }