コード例 #1
0
 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);
     }
 }
コード例 #2
0
 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);
     }
 }
コード例 #3
0
 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()
 {
     $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);
 }
コード例 #5
0
 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;
     }
 }
コード例 #6
0
 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);
 }
コード例 #7
0
 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") . '.';
         }
     }
 }
コード例 #9
0
 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();
 }
コード例 #10
0
 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;
     }
 }
コード例 #11
0
 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;
         }
     }
 }
コード例 #12
0
 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;
     }
 }
コード例 #13
0
 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'));
     }
 }
コード例 #14
0
 /**
  * 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;
 }