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); } }
/** * Set tags to this photo. If tag doesn't exist it will be created. * If photo hasn't tag anymore it will be removed for this photo. * Take into account stack of photos * * @param int $photo_id * @param array $tags NAMES of tags * @throws Exception */ public function set($photo_id, $tags = array()) { if (!$photo_id) { throw new Exception("Can't set tags: unkown photo id"); } $photo_model = new photosPhotoModel(); $photo = $photo_model->select('id, parent_id, stack_count')->where('id = i:photo_id', array('photo_id' => $photo_id))->fetch(); // we have photo in stack if ($photo['parent_id'] != 0) { $photo_id = $photo['parent_id']; } $children = $photo_model->select('id')->where('parent_id = i:photo_id', array('photo_id' => $photo_id))->fetchAll('id', true); if ($children) { // we have children in stack $photo_id = array_merge((array) $photo_id, array_keys($children)); } else { // we have just photo $photo_id = (array) $photo_id; } $tag_model = new photosTagModel(); $tag_ids = $tag_model->getIds($tags, true); foreach ($photo_id as $id) { $this->_set($id, $tag_ids); } }
public function execute() { $photo_id = waRequest::get('photo_id', null, waRequest::TYPE_INT); $size = waRequest::get('size', null, waRequest::TYPE_STRING); $album = null; $photo_model = new photosPhotoModel(); $photo = $photo_model->getById($photo_id); if (!$photo) { throw new waException(_w("Unknown photo")); } $photo['frontend_link'] = photosFrontendPhoto::getLink($photo, $album); $sizes = $this->getConfig()->getSizes(); $contexts = array(); foreach ($sizes as $sz) { $contexts[$sz]['html'] = photosPhoto::getEmbedImgHtml($photo, $sz); $contexts[$sz]['url'] = photosPhoto::getPhotoUrl($photo, $sz, true); } if (!$size || !isset($contexts[$size])) { $size = $sizes[0]; } $domains = photosPhoto::getDomains(null, $photo); if (count($domains) <= 1) { $domains = array(); } $this->view->assign('photo', $photo); $this->view->assign('sizes', $sizes); $this->view->assign('size', $size); $this->view->assign('contexts', $contexts); $this->view->assign('original_domain', wa()->getRootUrl(true)); $this->view->assign('domains', $domains); }
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); }
/** * @param array|int $photo photo or id of photo * @param boolean $check_edit * @return boolean */ public function checkRights($photo, $check_edit = false) { if (!is_array($photo)) { $photo_model = new photosPhotoModel(); $photo = $photo_model->getById((int) $photo); } if (!$photo) { return false; } $photo_id = $photo['id']; $user = wa()->getUser(); if ($check_edit && $photo['contact_id'] != $user->getId() && !$user->getRights('photos', 'edit')) { return false; } if (!empty($photo['app_id'])) { return !!$user->getRights($photo['app_id'], 'backend'); } if ($user->isAdmin()) { $where = "(group_id >= 0 OR group_id = -" . (int) $user->getId() . ")"; } else { $groups = $user->getGroupIds(); $where = "group_id IN ('" . implode("','", $groups) . "')"; } $sql = "SELECT count(*) FROM " . $this->table . "\n WHERE photo_id = " . (int) $photo_id . " AND " . $where . "\n LIMIT 1"; return (bool) $this->query($sql)->fetchField(); }
public function onCount() { return null; $photo_model = new photosPhotoModel(); $count = $photo_model->countAll($t = $this->getLastLoginTime(false)); return $count ? $count : null; }
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() { $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); }
/** * @param int[] $params Deleted contact_id * @see waEventHandler::execute() * @return void */ public function execute(&$params) { $contact_ids = $params; $photo_model = new photosPhotoModel(); $photo_model->updateByField(array('contact_id' => $contact_ids), array('contact_id' => 0)); wa()->event(array('photos', 'contacts_delete'), $params); }
public static function getAppAlbums($force_app_ids = array()) { $photo_model = new photosPhotoModel(); $apps = wa()->getApps(); $result = array(); $counts = $photo_model->countAllByApp(); $counts += array_fill_keys((array) $force_app_ids, 0); $force_app_ids = array_fill_keys((array) $force_app_ids, true); foreach ($counts as $app_id => $count) { // Check that app exists and check access rights, unless app is forced to be present in the result if (empty($force_app_ids[$app_id])) { if ($count <= 0 || empty($apps[$app_id]) || !wa()->getUser()->getRights($app_id, 'backend')) { continue; } } if (!empty($apps[$app_id])) { $name = $apps[$app_id]['name']; if (!empty($apps[$app_id]['icon'][16])) { $icon = $apps[$app_id]['icon'][16]; } else { $icon = reset($apps[$app_id]['icon']); } } else { $name = $app_id; $icon = $apps['photos']['icon'][16]; } if ($icon) { $icon = wa()->getConfig()->getRootUrl() . $icon; } $result[$app_id] = array('id' => $app_id, 'name' => $name, 'count' => $count, 'icon' => $icon); } return $result; }
public function execute() { $count = $this->getConfig()->getOption('photos_per_page'); $id = waRequest::post('id', 0, waRequest::TYPE_INT); $hash = waRequest::post('hash', '', waRequest::TYPE_STRING_TRIM); $offset = waRequest::post('offset', 1, waRequest::TYPE_INT); $direction = waRequest::post('direction', 1, waRequest::TYPE_INT); $this->collection = new photosCollection($hash); if (strstr($hash, 'rate>0') !== false) { $this->collection->orderBy('p.rate DESC, p.id'); } if ($id) { $photo_model = new photosPhotoModel(); $photo = $photo_model->getById($id); $offset = $this->collection->getPhotoOffset($photo); if ($direction > 0) { $offset += 1; } else { $offset -= $count; if ($offset < 0) { $count += $offset; $offset = 0; } } } $photos = array_values($this->getPhotos($offset, $count)); $photos = photosCollection::extendPhotos($photos); $loaded = count($photos) + $offset; $count = $this->collection->count(); $this->response['photos'] = $photos; $this->response['hash'] = $hash; $this->response['string'] = array('loaded' => _w('%d photo', '%d photos', $loaded), 'of' => sprintf(_w('of %d'), $count), 'chunk' => $loaded < $count ? _w('%d photo', '%d photos', min($this->getConfig()->getOption('photos_per_page'), $count - $loaded)) : false); }
public function save(waRequestFile $file, $data) { // check image if (!($image = $file->waImage())) { throw new waException(_w('Incorrect image')); } $plugin = wa()->getPlugin('publicgallery'); $min_size = $plugin->getSettings('min_size'); if ($min_size && ($image->height < $min_size || $image->width < $min_size)) { throw new waException(sprintf(_w("Image is too small. Minimum image size is %d px"), $min_size)); } $max_size = $plugin->getSettings('max_size'); if ($max_size && ($image->height > $max_size || $image->width > $max_size)) { throw new waException(sprintf(_w("Image is too big. Maximum image size is %d px"), $max_size)); } $id = $this->model->add($file, $data); if (!$id) { throw new waException(_w("Save error")); } $tag = $plugin->getSettings('assign_tag'); if ($tag) { $photos_tag_model = new photosPhotoTagsModel(); $photos_tag_model->set($id, $tag); } return array('name' => $file->name, 'type' => $file->type, 'size' => $file->size); }
public function execute() { $photo_model = new photosPhotoModel(); $config = $this->getConfig(); $last_activity_datetime = $config->getLastLoginTime(false); $this->response['count'] = $photo_model->countAll(); $this->response['rated_count'] = $photo_model->countRated(); }
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 inCollection($photo, $hash) { $parent = $this->photo_model->getStackParent($photo); $photo = $parent ? $parent : $photo; // check existing in collection $collection = new photosCollection($hash); $current_offset = $collection->getPhotoOffset($photo); $collection_photos = $collection->getPhotos("id", $current_offset, 1, false); return isset($collection_photos[$photo['id']]); }
public function execute() { $photo_id = waRequest::get('id', null, waRequest::TYPE_INT); if (!$photo_id) { throw new waException(_w('Unknown photo')); } $photo_model = new photosPhotoModel(); $photo = $photo_model->getById($photo_id); $this->view->assign('photo_name', $photo['name']); }
public function execute() { if (!$this->getUser()->getRights('photos', 'edit')) { throw new waException(_w("Access denied")); } $moderation = waRequest::post('moderation', '', waRequest::TYPE_STRING_TRIM); $id = waRequest::post('id', '', waRequest::TYPE_INT); $photo_model = new photosPhotoModel(); $photo = $photo_model->getById($id); if (!$photo) { $this->errors[] = _wp('Unknown photo'); } if ($moderation == 'approve') { $photo_model->updateById($id, array('moderation' => 1)); $photo_model->updateAccess($id, 1, array(0)); } if ($moderation == 'decline') { $photo_model->updateById($id, array('moderation' => -1)); $photo_model->updateAccess($id, 0, array(0)); } $this->response['photo'] = $photo_model->getById($id); // update for making inline-editable widget $this->response['frontend_link_template'] = photosFrontendPhoto::getLink(array('url' => '%url%')); $this->response['counters'] = array('declined' => $photo_model->countByField('moderation', -1), 'awaiting' => $photo_model->countByField('moderation', 0)); // l18n string $count = (int) waRequest::post('count'); $total_count = (int) waRequest::post('total_count'); $this->response['string'] = array('loaded' => _w('%d photo', '%d photos', $count), 'of' => sprintf(_w('of %d'), $total_count), 'chunk' => $count < $total_count ? _w('%d photo', '%d photos', min($this->getConfig()->getOption('photos_per_page'), $count - $total_count)) : false); }
public function execute() { $photo_id = waRequest::get('photo_id', null, waRequest::TYPE_INT); $photo_model = new photosPhotoModel(); $photo = $photo_model->getById($photo_id); if (!$photo) { throw new waException(_w('Photo not found'), 404); } $vote_model = new photosPublicgalleryVoteModel(); $this->view->assign(array('photo_name' => $photo['name'], 'distribution' => $vote_model->getDistribution($photo_id), 'rate' => $photo['rate'], 'votes_count' => $photo['votes_count'], 'users' => $vote_model->getVotedUsers($photo_id))); }
public function execute() { $album_id = waRequest::post('album_id', null, waRequest::TYPE_INT); if ($album_id) { $album_photos_model = new photosAlbumPhotosModel(); $this->response['photo_id'] = array_keys($album_photos_model->getByField('album_id', $album_id, 'photo_id')); } else { $photo_model = new photosPhotoModel(); $photo_id = waRequest::post('photo_id', null, waRequest::TYPE_ARRAY_INT); $this->response['photo_id'] = array_keys($photo_model->getPhotos($photo_id)); } }
public function execute() { $photo_ids = waRequest::get('photo_ids', '', waRequest::TYPE_STRING_TRIM); $size = waRequest::get('size', null, waRequest::TYPE_STRING_TRIM); $hash = waRequest::get('hash', '', waRequest::TYPE_STRING_TRIM); if (strstr($hash, 'search') !== false) { $hash = urldecode($hash); } $sizes = $this->getConfig()->getSizes(); if (!$size || in_array($size, $sizes) === false) { $size = current($sizes); } $photo_model = new photosPhotoModel(); $limit = $photo_model->countAll(); $entire_context['all']['count'] = $limit; if (strstr($hash, 'album') !== false) { $album_collection = new photosCollection($hash); $limit = $album_collection->count(); $entire_context['album']['count'] = $limit; } else { if (strstr($hash, 'tag') !== false) { $tag_collection = new photosCollection($hash); $limit = $tag_collection->count(); $tag = rtrim(end(explode('/', $hash)), '/'); $entire_context['tag'] = array('count' => $limit, 'tag' => $tag); } else { if (strstr($hash, 'rate') !== false) { $rate_collection = new photosCollection($hash); $limit = $rate_collection->count(); $entire_context['rate']['count'] = $limit; } } } if (!$photo_ids && strstr($hash, 'album') === false && strstr($hash, 'tag') === false && strstr($hash, 'rate') === false) { $hash = ''; } else { if ($photo_ids) { $hash = '/id/' . $photo_ids; } } $context = photosPhoto::getEmbedPhotoListContext($hash, $size, $limit); $domains = $context['domains']; if (count($domains) <= 1) { $domains = array(); } $this->view->assign('sizes', $sizes); $this->view->assign('size', $size); $this->view->assign('context', $context); $this->view->assign('is_entire', !$photo_ids); $this->view->assign('entire_context', $entire_context); $this->view->assign('original_domain', wa()->getRootUrl(true)); $this->view->assign('domains', $domains); }
public function execute() { $count = $this->getConfig()->getOption('photos_per_page'); $padding_count = 2; $direction = waRequest::get('direction', 1, waRequest::TYPE_INT); $album = waRequest::param('album'); $hash = waRequest::param('hash'); $url = waRequest::param('url'); $album = waRequest::param('album'); if (!$url) { throw new waException(_w('Page not found', 404)); } if ($album && $album['status'] <= 0) { $album['full_url'] = photosCollection::frontendAlbumHashToUrl($hash); } $photo_model = new photosPhotoModel(); $photo = $photo_model->getByField('url', $url); $real_count = $count; if ($photo) { $c = new photosCollection($hash); $offset = $c->getPhotoOffset($photo); if ($direction > 0) { $offset += 1; // next photos } else { $offset -= $real_count; // prev photos if ($offset < 0) { $real_count += $offset; $offset = 0; } } $photo_stream = $c->getPhotos('*,thumb,thumb_crop,tags', $offset, $real_count); $photo_stream = photosCollection::extendPhotos($photo_stream); foreach ($photo_stream as &$item) { $item['thumb_custom'] = array('url' => photosPhoto::getPhotoUrlTemplate($item)); $item['full_url'] = photosFrontendPhoto::getLink(array('url' => $item['url']), $album ? $album : $hash); } unset($item); $real_count = count($photo_stream); if ($real_count < $count) { if ($direction > 0) { $photo_stream = array_merge($photo_stream, array_pad(array(), $padding_count, null)); } else { $photo_stream = array_merge(array_pad(array(), $padding_count, null), $photo_stream); } } $renderer = new photosPhotoHtmlRenderer($this->getTheme()); echo $renderer->getPhotoStream($photo_stream, null); } exit; }
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); } }
protected function save(waRequestFile $file, $data) { $id = $this->model->add($file, $data); if (!$id) { throw new waException(_w("Save error")); } $photo = $this->model->getById($id); $parent_id = (int) waRequest::post('parent_id'); if ((int) waRequest::post('parent_id')) { $this->model->appendToStack($parent_id, array($id)); } return array('name' => $file->name, 'type' => $file->type, 'size' => $file->size, 'thumbnail_url' => photosPhoto::getPhotoUrl($photo, photosPhoto::getThumbPhotoSize()), 'url' => '#/photo/' . $id . '/'); }
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; }
protected function save(waRequestFile $file, $data = array()) { wa('photos'); $photo_model = new photosPhotoModel(); $data['groups'] = array(); $data['app_id'] = 'blog'; $data['hash'] = ''; $id = $photo_model->add($file, $data); if (!$id) { throw new waException(_w("Save error")); } $photo = $photo_model->getById($id); return array('id' => $id, 'photo' => $photo, 'name' => $file->name, 'type' => $file->type, 'size' => $file->size, 'url' => photosPhoto::getPhotoUrl($photo, null, !!waRequest::get('absolute')), 'thumbnail_url' => photosPhoto::getPhotoUrl($photo, photosPhoto::getThumbPhotoSize(), !!waRequest::get('absolute'))); }
public function filterAllowedPhotoIds($photo_id) { if (!$photo_id) { return $photo_id; } if (wa()->getEnv() == 'backend') { if (wa()->getUser()->getRights('photos', 'edit')) { return $photo_id; } $photo_model = new photosPhotoModel(); return array_keys($photo_model->select('id')->where("rate > 0 AND id IN (" . implode(',', $photo_id) . ")")->fetchAll('id')); } else { return $photo_id; } }
public function execute() { $data = waRequest::post(); if (!wa()->getUser()->getRights('photos', 'upload')) { throw new waAPIException('access_denied', 403); } $group_ids = array(0); if (!isset($data['status'])) { $data['status'] = 1; } else { if ($data['status'] == -1) { $group_ids = array(-wa()->getUser()->getId()); } } $data['groups'] = $group_ids; $data['source'] = photosPhotoModel::SOURCE_API; // work with album if (isset($data['album_id'])) { $album_id = $data['album_id']; $album_model = new photosAlbumModel(); $album = $album_model->getById($album_id); if (!$album) { throw new waAPIException('invalid_param', 'Album not found', 404); } $album_rights_model = new photosAlbumRightsModel(); if (!$album_rights_model->checkRights($album_id, true)) { throw new waAPIException('access_denied', 'Not rights to album', 403); } } $file = waRequest::file('file'); if (!$file->uploaded()) { throw new waAPIException('server_error', $file->error, 500); } $id = null; $photo_model = new photosPhotoModel(); try { $id = $photo_model->add($file, $data); } catch (Exception $e) { throw new waAPIException('server_error', $e->getMessage(), 500); } if (!$id) { throw new waAPIException('server_error', 500); } $_GET['id'] = $id; $method = new photosPhotoGetInfoMethod(); $this->response = $method->getResponse(true); }
public function execute() { if ($id = waRequest::get('id', waRequest::TYPE_INT)) { $photo_model = new photosPhotoModel(); $photo = $photo_model->getById($id); $album_photos_model = new photosAlbumPhotosModel(); $photo_albums = $album_photos_model->getByPhoto($id); } else { $photo = null; $photo_albums = array(); } $this->view->assign('photo_albums', $photo_albums); $album_model = new photosAlbumModel(); $albums = $album_model->getAlbums(false, photosAlbumModel::TYPE_STATIC, $this->getRights('edit') ? false : true, false); $this->view->assign('albums', $albums); $this->view->assign('photo', $photo); }
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; } } }