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() { $photo_id = $this->post('id', true); if (!is_array($photo_id)) { if (strpos($photo_id, ',') !== false) { $photo_id = array_map('intval', explode(',', $photo_id)); } else { $photo_id = array($photo_id); } } $tag = waRequest::post('tag', ''); if (!$tag) { $tag = array(); } if (!is_array($tag)) { if (strpos($tag, ',') !== false) { $tag = explode(',', $tag); } else { $tag = array($tag); } } $tag = array_map('trim', $tag); $tag_model = new photosTagModel(); $photo_tag_model = new photosPhotoTagsModel(); $photo_rights_model = new photosPhotoRightsModel(); $allowed_photo_id = $photo_rights_model->filterAllowedPhotoIds($photo_id, true); if ($allowed_photo_id) { $photo_tag_model->assign($allowed_photo_id, $tag_model->getIds($tag, true)); $this->response = true; } else { throw new waAPIException('access_denied', 403); } }
public function execute() { $photo_id = $this->post('id', true); if (!is_array($photo_id)) { if (strpos($photo_id, ',') !== false) { $photo_id = array_map('intval', explode(',', $photo_id)); } else { $photo_id = array($photo_id); } } $photo_model = new photosPhotoModel(); $photo_rights_model = new photosPhotoRightsModel(); $allowed_photo_id = $photo_rights_model->filterAllowedPhotoIds($photo_id, true); if ($allowed_photo_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->response = true; } else { throw new waAPIException('access_denied', 403); } }
public function execute() { $album_id = waRequest::post('id', null, waRequest::TYPE_INT); $status = waRequest::post('status', 0, waRequest::TYPE_INT); $groups = waRequest::post('groups', array(), waRequest::TYPE_ARRAY_INT); $count = waRequest::post('count', 0, waRequest::TYPE_INT); $offset = waRequest::post('offset', 0, waRequest::TYPE_INT); $collection = new photosCollection('album/' . $album_id); $this->response['offset'] = $offset; $photos = $collection->getPhotos('*', $offset, $count, false); $photo_ids = array(); foreach ($photos as $photo) { if ($photo['status'] == 1 && $status == 1) { continue; } if ($photo['stack_count'] > 0) { $photo_ids = array_merge($photo_ids, $photo_model->getIdsByParent($photo['id'])); } else { $photo_ids[] = $photo['id']; } } $photo_rights_model = new photosPhotoRightsModel(); $allowed_photo_ids = $photo_rights_model->filterAllowedPhotoIds($photo_ids, true); $photo_model = new photosPhotoModel(); $photo_model->updateAccess($allowed_photo_ids, $status, $groups); }
public function execute() { $photo_id = $this->post('id', true); if (!is_array($photo_id)) { if (strpos($photo_id, ',') !== false) { $photo_id = array_map('intval', explode(',', $photo_id)); } else { $photo_id = array($photo_id); } } $album_id = waRequest::post('album_id', ''); if (!$album_id) { $album_id = array(); } if (!is_array($album_id)) { if (strpos($album_id, ',') !== false) { $album_id = explode(',', $album_id); } else { $album_id = array($album_id); } } $album_id = array_map('trim', $album_id); $album_photos_model = new photosAlbumPhotosModel(); $photo_rights_model = new photosPhotoRightsModel(); $allowed_photo_id = $photo_rights_model->filterAllowedPhotoIds($photo_id, true); if ($allowed_photo_id) { $album_photos_model->deletePhotos($album_id, $allowed_photo_id); $this->response = true; } else { throw new waAPIException('access_denied', 403); } }
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; } }
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() { $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() { $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() { $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 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; } }
private function _makeStack($parent_id, $photo_ids, $op = 'make') { $photo_ids = (array) $photo_ids; if ($op == 'make') { $where = $this->getWhereByField('id', $photo_ids); // get description - first not empty description but description of parent is first-priority $sql = "SELECT description FROM {$this->table} WHERE id = i:parent_id AND description IS NOT NULL\n UNION\n SELECT description FROM {$this->table} WHERE {$where} AND description IS NOT NULL LIMIT 0,1"; $description = $this->query($sql, array('parent_id' => $parent_id))->fetchField('description'); // get max rate of all photos $sql = "SELECT MAX(rate) rate FROM {$this->table} WHERE id = i:parent_id OR {$where}"; $rate = $this->query($sql, array('parent_id' => $parent_id))->fetchField('rate'); // get status $sql = "SELECT status FROM {$this->table} WHERE id = i:parent_id"; $status = $this->query($sql, array('parent_id' => $parent_id))->fetchField('status'); $stack_count = 1; $sort = 1; } else { $parent = $this->getById($parent_id); $rate = $parent['rate']; $description = $parent['description']; $status = $parent['status']; $stack_count = $parent['stack_count']; // get last sort value of stack plus 1 $sql = "SELECT sort FROM {$this->table} WHERE parent_id = i:parent_id ORDER BY sort DESC LIMIT 1"; $sort = $this->query($sql, array('parent_id' => $parent_id))->fetchField('sort') + 1; } // get groups $photo_rights_model = new photosPhotoRightsModel(); $groups = array_keys($photo_rights_model->getByField('photo_id', $parent_id, 'group_id')); // make first of all operations connected with file-manipulations foreach ($photo_ids as $id) { // update access $this->upAccess($id, array('status' => $status, 'groups' => $groups)); } // make children of stack foreach ($photo_ids as $id) { $this->updateById($id, array('parent_id' => $parent_id, 'description' => $description, 'rate' => $rate, 'sort' => $sort++, 'stack_count' => 0)); } // make parent of stack $this->updateById($parent_id, array('parent_id' => 0, 'description' => $description, 'rate' => $rate, 'stack_count' => $stack_count + count($photo_ids), 'sort' => 0)); if ($op == 'make') { $photo_ids[] = $parent_id; } else { $photo_ids = array_keys($this->getByField('parent_id', $parent_id, 'id')); $photo_ids[] = $parent_id; } // merge tags for stack $photo_tags_model = new photosPhotoTagsModel(); $tag_ids = array_keys($photo_tags_model->getByField('photo_id', $photo_ids, 'tag_id')); $photo_tags_model->assign($photo_ids, $tag_ids); // merge albums for stack $album_photos_model = new photosAlbumPhotosModel(); $album_ids = array_keys($album_photos_model->getByField('photo_id', $photo_ids, 'album_id')); $album_photos_model->add($photo_ids, $album_ids, false); }
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(); } } }
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; } }
/** * Returns photos in this collection. * * @param string|array $fields * @param int $offset * @param int $limit * @param bool $escape * @return array [photo_id][field] = field value in appropriate field format * @throws waException */ public function getPhotos($fields = "*,thumb,tags", $offset = 0, $limit = 50, $escape = true) { $sql = $this->getSQL(); $sql = "SELECT " . ($this->joins ? 'DISTINCT ' : '') . $this->getFields($fields) . " " . $sql; //$sql .= $this->getGroupBy(); $sql .= $this->getOrderBy(); $sql .= " LIMIT " . ($offset ? $offset . ',' : '') . (int) $limit; $data = $this->getModel()->query($sql)->fetchAll('id'); if (!$data) { return array(); } if ($this->post_fields) { $ids = array_keys($data); foreach ($this->post_fields as $table => $fields) { if ($table == '_internal') { foreach ($fields as $i => $f) { if ($f == 'thumb' || substr($f, 0, 6) == 'thumb_') { if ($f == 'thumb') { $size = photosPhoto::getThumbPhotoSize(); } else { $size = substr($f, 6); switch ($size) { case 'crop': $size = photosPhoto::getCropPhotoSize(); break; case 'middle': $size = photosPhoto::getMiddlePhotoSize(); break; case 'big': $size = photosPhoto::getBigPhotoSize(); break; case 'mobile': $size = photosPhoto::getMobilePhotoSize(); break; } } foreach ($data as $id => &$v) { $v[$f] = photosPhoto::getThumbInfo($v, $size); } unset($v); } if ($f == 'frontend_link') { foreach ($data as $id => &$v) { $v['frontend_link'] = photosFrontendPhoto::getLink(array('url' => $this->frontend_base_url ? $this->frontend_base_url . '/' . $v['url'] : $v['url'])); } unset($v); } if ($f == 'edit_rights') { $photo_model_rights = new photosPhotoRightsModel(); $photo_ids = array(); foreach ($data as $id => &$v) { $photo_ids[] = $id; $v['edit_rights'] = false; } unset($v); foreach ($photo_model_rights->filterAllowedPhotoIds($photo_ids, true) as $photo_id) { $data[$photo_id]['edit_rights'] = true; } } } } elseif ($table == 'tags') { $model = $this->getModel('photo_tags'); $tags = $model->getTags($ids); foreach ($data as $id => &$v) { $v['tags'] = isset($tags[$id]) ? $tags[$id] : array(); } unset($v); } } } if ($escape) { self::escapePhotoFields($data); } return $data; }
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() { $this->id = waRequest::post('id', null, waRequest::TYPE_INT); $group_ids = null; $status = waRequest::post('status', 0, waRequest::TYPE_INT); if (!$status) { $group_ids = waRequest::post('groups', array(), waRequest::TYPE_ARRAY_INT); if (!$group_ids) { // visible only for creator $status = -1; $group_ids = array(-$this->getUser()->getId()); } } $this->album_model = new photosAlbumModel(); if (!$this->id) { if (!$this->getRights('upload')) { throw new waException(_w("You don't have sufficient access rights")); } $name = waRequest::post('name', '', waRequest::TYPE_STRING_TRIM); $type = waRequest::post('type', 0, waRequest::TYPE_INT); $data = array('name' => $name, 'status' => $status, 'type' => $type, 'group_ids' => $group_ids); if ($status <= 0) { $data['hash'] = md5(uniqid(time(), true)); } else { $data['url'] = $this->album_model->suggestUniqueUrl(photosPhoto::suggestUrl($name)); } if ($type == photosAlbumModel::TYPE_DYNAMIC) { $data['conditions'] = $this->getPrepareConditions(); } $this->save($data); $this->response = array('id' => $this->id, 'name' => photosPhoto::escape($name), 'type' => $type, 'status' => $status); } else { $album_rights_model = new photosAlbumRightsModel(); if (!$album_rights_model->checkRights($this->id, true)) { throw new waException(_w("You don't have sufficient access rights")); } $conditions = $this->getPrepareConditions(); $params = array(); $album_params = waRequest::post('params', '', waRequest::TYPE_STRING_TRIM); $album_params = explode(PHP_EOL, $album_params); foreach ($album_params as $param) { $param = explode('=', $param); if (count($param) < 2) { continue; } $params[$param[0]] = $param[1]; } $params = $params ? $params : null; $description = waRequest::post('description', null, waRequest::TYPE_STRING_TRIM); $name = waRequest::post('name', '', waRequest::TYPE_STRING_TRIM); $url = waRequest::post('url', null, waRequest::TYPE_STRING_TRIM); $data = array('status' => $status, 'group_ids' => $group_ids, 'conditions' => $conditions, 'url' => $url, 'description' => $description, 'params' => $params, 'name' => $name); if ($status <= 0) { $data['hash'] = md5(uniqid(time(), true)); } if (waRequest::post('order') == 'rate') { $data['params']['order'] = 'rate'; } if (!$this->validate($data)) { return; } $this->save($data); $apply_all_photos = waRequest::post('apply_all_photos', 0, waRequest::TYPE_INT); if ($apply_all_photos) { // apply to first of $count photos $count = waRequest::post('count', 50, waRequest::TYPE_INT); $collection = new photosCollection('album/' . $this->id); $total_count = $collection->count(); $photos = $collection->getPhotos('*', 0, $count, false); $photo_model = new photosPhotoModel(); $photo_ids = array(); foreach ($photos as $photo) { if ($photo['status'] == 1 && $status == 1) { continue; } if ($photo['stack_count'] > 0) { $photo_ids = array_merge($photo_ids, $photo_model->getIdsByParent($photo['id'])); } else { $photo_ids[] = $photo['id']; } } $photo_rights_model = new photosPhotoRightsModel(); $allowed_photo_ids = $photo_rights_model->filterAllowedPhotoIds($photo_ids, true); $photo_model->updateAccess($allowed_photo_ids, $status, $group_ids); $this->response['total_count'] = $total_count; $this->response['count'] = $count; $this->response['status'] = $status; $this->response['groups'] = $group_ids; } } }
protected function save(waRequestFile $file) { // check image if (!($image = $file->waImage())) { throw new waException(_w('Incorrect image')); } $exif_data = photosExif::getInfo($file->tmp_name); $image_changed = false; if (!empty($exif_data['Orientation'])) { $image_changed = $this->correctOrientation($exif_data['Orientation'], $image); } /** * Extend upload proccess * Make extra workup * @event photo_upload */ $event = wa()->event('photo_upload', $image); if ($event && !$image_changed) { foreach ($event as $plugin_id => $result) { if ($result) { $image_changed = true; break; } } } $data = array('name' => preg_replace('/\\.[^\\.]+$/', '', basename($file->name)), 'ext' => $file->extension, 'size' => $file->size, 'type' => $image->type, 'width' => $image->width, 'height' => $image->height, 'contact_id' => $this->getUser()->getId(), 'status' => $this->status, 'upload_datetime' => date('Y-m-d H:i:s')); if ($this->status <= 0) { $data['hash'] = md5(uniqid(time(), true)); } $photo_id = $data['id'] = $this->model->insert($data); if (!$photo_id) { throw new waException(_w('Database error')); } // update url $url = $this->generateUrl($data['name'], $photo_id); $this->model->updateById($photo_id, array('url' => $url)); // check rigths to upload folder $photo_path = photosPhoto::getPhotoPath($data); if (file_exists($photo_path) && !is_writable($photo_path) || !file_exists($photo_path) && !waFiles::create($photo_path)) { $this->model->deleteById($photo_id); throw new waException(sprintf(_w("The insufficient file write permissions for the %s folder."), substr($photo_path, strlen($this->getConfig()->getRootPath())))); } if ($image_changed) { $image->save($photo_path); // save original if ($this->getConfig()->getOption('save_original')) { $original_file = photosPhoto::getOriginalPhotoPath($photo_path); $file->moveTo($original_file); } } else { $file->moveTo($photo_path); } unset($image); // free variable // add to album if ($photo_id && $this->album_id) { $album_photos_model = new photosAlbumPhotosModel(); // update note if album is empty and note is yet null $r = $album_photos_model->getByField('album_id', $this->album_id); if (!$r) { $album_model = new photosAlbumModel(); $sql = "UPDATE " . $album_model->getTableName() . " SET note = IFNULL(note, s:note) WHERE id = i:album_id"; $time = !empty($exif_data['DateTimeOriginal']) ? strtotime($exif_data['DateTimeOriginal']) : time(); $album_model->query($sql, array('note' => mb_strtolower(_ws(date('F', $time))) . ' ' . _ws(date('Y', $time)), 'album_id' => $this->album_id)); } // add to album iteself $sort = (int) $album_photos_model->query("SELECT sort + 1 AS sort FROM " . $album_photos_model->getTableName() . " WHERE album_id = i:album_id ORDER BY sort DESC LIMIT 1", array('album_id' => $this->album_id))->fetchField('sort'); $album_photos_model->insert(array('photo_id' => $photo_id, 'album_id' => $this->album_id, 'sort' => $sort)); } // save rights for groups if ($this->groups) { $rights_model = new photosPhotoRightsModel(); $rights_model->multiInsert(array('photo_id' => $photo_id, 'group_id' => $this->groups)); } // save exif data if (!empty($exif_data)) { $exif_model = new photosPhotoExifModel(); $exif_model->save($photo_id, $exif_data); } $sizes = $this->getConfig()->getSizes(); photosPhoto::generateThumbs($data, $sizes); return array('name' => $file->name, 'type' => $file->type, 'size' => $file->size, 'thumbnail_url' => photosPhoto::getPhotoUrl($data, photosPhoto::getThumbPhotoSize()), 'url' => '#/photo/' . $photo_id . '/'); }
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() { $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')); } }