public function execute() { $name = waRequest::post('name', '', waRequest::TYPE_STRING_TRIM); if (in_array($name, $this->availableFields) === false) { throw new waException(_w("Can't update album: unknown field")); } $album_rights_model = new photosAlbumRightsModel(); $id = waRequest::post('id', null, waRequest::TYPE_ARRAY_INT); if (is_array($id)) { $id = current($id); } if ($id) { $album_model = new photosAlbumModel(); $album = $album_model->getById($id); if (!$album) { throw new waException(_w('Unknown album')); } if (!$album_rights_model->checkRights($album, true)) { throw new waException(_w("You don't have sufficient access rights")); } $value = waRequest::post('value', '', waRequest::TYPE_STRING_TRIM); $album_model->updateById($id, array($name => $value)); $album['not_escaped_name'] = $value; $album['name'] = photosPhoto::escape($value); $this->response['album'] = $album; } }
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 = 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() { $action = waRequest::param('action', 'default'); $disable_sidebar = waRequest::param('disable_sidebar', false); $this->view->assign('action', $action); $this->view->assign('breadcrumbs', waRequest::param('breadcrumbs', array())); if (!$this->getResponse()->getTitle()) { $title = waRequest::param('title') ? photosPhoto::escape(waRequest::param('title')) : wa()->accountName(); $this->getResponse()->setTitle($title); } $this->view->assign('nofollow', waRequest::param('nofollow', false)); $this->view->assign('disable_sidebar', $disable_sidebar); /** * Include plugins js and css * @event frontend_assets * @return array[string][string]string $return[%plugin_id%] Extra header data (css/js/meta) */ $this->view->assign('frontend_assets', wa()->event('frontend_assets')); /** * @event frontend_layout * @return array[string][string]string $return[%plugin_id%]['header'] Header menu section * @return array[string][string]string $return[%plugin_id%]['footer'] Footer section */ $this->view->assign('frontend_layout', wa()->event('frontend_layout')); /** * @event frontend_sidebar * @return array[string][string]string $return[%plugin_id%]['menu'] Sidebar menu item * @return array[string][string]string $return[%plugin_id%]['section'] Sidebar section item */ $this->view->assign('frontend_sidebar', wa()->event('frontend_sidebar')); $this->setThemeTemplate('index.html'); }
protected function workupPhotos(&$photos) { foreach ($photos as &$photo) { $photo['name'] = photosPhoto::escape($photo['name']); } unset($photo); return $photos; }
public function execute() { $available_fields = array_merge($this->generic_fields, $this->stack_fields); $data = waRequest::post('data'); $photo_id = array(); foreach ($data as &$item_data) { if (isset($item_data['id']) && ($id = array_unique(array_map('intval', explode(',', $item_data['id']))))) { unset($item_data['id']); $fields = array_diff_key(array_keys($item_data), $available_fields); if ($fields) { throw new waException("Invalid request format: unexpected field(s) " . implode(', ', $fields)); } $photo_id = array_merge($photo_id, $id); $item_data['id'] = $id; } else { throw new waException("Invalid request format: missed or invalid item ID"); } } unset($item_data); $this->response['update'] = array(); if ($photo_id) { $photo_rights_model = new photosPhotoRightsModel(); $allowed_photo_id = $photo_rights_model->filterAllowedPhotoIds($photo_id, true); $denied_photo_id = array_diff($photo_id, $allowed_photo_id); if ($allowed_photo_id) { $photo_model = new photosPhotoModel(); $generic_fields = array_fill_keys($this->generic_fields, true); $stack_fields = array_fill_keys($this->stack_fields, true); foreach ($data as $item_data) { if ($item_data_id = array_intersect($item_data['id'], $allowed_photo_id)) { unset($item_data['id']); foreach ($item_data as $field => &$value) { $value = $this->validateField($field, $value); } unset($value); if ($data = array_intersect_key($item_data, $stack_fields)) { $photo_model->update($item_data_id, $data); $this->response['update'][] = array('id' => $item_data_id, 'data' => $data); } if ($data = array_intersect_key($item_data, $generic_fields)) { $photo_model->updateById($item_data_id, $data); $this->response['update'][] = array('id' => $item_data_id, 'data' => $data); } } } } if (count($denied_photo_id) > 0 && count($photo_id) > 0) { $this->response['alert_msg'] = photosPhoto::sprintf_wplural("The operation was not performed to %d photo (%%s)", "The operation was not performed to %d photos (%%s)", count($denied_photo_id), _w("out of %d selected", "out of %d selected", count($photo_id))) . ', ' . _w("because you don't have sufficient access rights") . '.'; } $allowed_photo_id_map = array(); foreach ($allowed_photo_id as $id) { $allowed_photo_id_map[$id] = true; } $this->response['allowed_photo_id'] = $allowed_photo_id_map; } }
public function execute() { if (!wa()->getUser()->getRights('photos', 'upload')) { throw new waAPIException('access_denied', 403); } $data = waRequest::post(); // check required param name $this->post('name', true); $album_model = new photosAlbumModel(); $group_ids = array(0); if (!isset($data['status'])) { $data['status'] = 1; } else { if ($data['status'] == -1) { $group_ids = array(-wa()->getUser()->getId()); } } if ($data['status'] <= 0) { $data['hash'] = md5(uniqid(time(), true)); } else { $data['url'] = $album_model->suggestUniqueUrl(photosPhoto::suggestUrl($data['name'])); } if (!isset($data['type'])) { $data['type'] == photosAlbumModel::TYPE_STATIC; } $parent_id = waRequest::post('parent_id', 0, 'int'); $parent = $album_model->getById($parent_id); if ($parent_id) { if (!$parent) { throw new waAPIException('invalid_request', 'Parent album not found', 404); } if ($data['type'] == photosAlbumModel::TYPE_STATIC && $parent['type'] == photosAlbumModel::TYPE_DYNAMIC) { throw new waAPIException('invalid_request', 'Inserted album is static but parent album is dynamic', 404); } if ($data['status'] > 0 && $parent['status'] <= 0) { throw new waAPIException('invalid_request', 'Inserted album is public but parent album is private', 404); } } if ($id = $album_model->add($data, $parent_id)) { // return info of the new album $_GET['id'] = $id; if ($parent_id) { $child = $album_model->getFirstChild($parent_id); $album_model->move($id, $child ? $child['id'] : 0, $parent_id); } $album_rights_model = new photosAlbumRightsModel(); $album_rights_model->setRights($id, $group_ids); $method = new photosAlbumGetInfoMethod(); $this->response = $method->getResponse(true); } else { throw new waAPIException('server_error', 500); } }
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() { $query = waRequest::request('q', '', waRequest::TYPE_STRING_TRIM); $tag_model = new photosTagModel(); $tags = $tag_model->select('name')->where("name LIKE '" . $tag_model->escape($query, 'like') . "%'")->fetchAll('name', true); $tags = array_keys($tags); foreach ($tags as &$tag) { $tag = photosPhoto::escape($tag); } unset($tag); echo implode("\n", $tags); }
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() { $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; } }
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 . '/'); }
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 execute() { $url = waRequest::param('url'); $this->album = waRequest::param('album'); $this->hash = waRequest::param('hash'); if (!$url) { throw new waException(_w('Page not found', 404)); } $this->photo_model = new photosPhotoModel(); $this->photo = $this->getPhoto($url); if (!$this->photo) { throw new waException(_w('Page not found'), 404); } $this->photo = photosPhoto::escapeFields($this->photo); if ($this->album && $this->album['status'] <= 0) { $this->album['full_url'] = photosCollection::frontendAlbumHashToUrl($this->hash); } // delegate work to special render helper $render_helper = new photosPhotoRenderHelper($this->photo, $this->private_hash); $result = $render_helper->workUp(array('album' => $this->album, 'hash' => $this->hash)); waRequest::setParam('title', $this->photo['name']); waRequest::setParam('nofollow', $this->isNeedNofollow()); waRequest::setParam('breadcrumbs', $this->getBreadcrumbs()); waRequest::setParam('disable_sidebar', true); // pull out work's up result $this->view->assign('photo', $result['photo']); $this->view->assign('albums', $result['blocks']['albums']); $this->view->assign('tags', $result['blocks']['tags']); $this->view->assign('exif', $result['blocks']['exif']); $this->view->assign('author', $result['blocks']['author']); $this->view->assign('stack_nav', $result['blocks']['stack_nav']); $this->view->assign('photo_stream', $result['blocks']['photo_stream']); // if we are not in album, than $album is null $this->view->assign('album', $this->album); /** * Add extra widgets to photo page * @event frontend_photo * @param string[array]mixed $photo photo data * @return array[string][string]string $return[%plugin_id%]['bottom'] In bottom, under photo - any widget * @return array[string][string]string $return[%plugin_id%]['sidebar'] * @return array[string][string]string $return[%plugin_id%]['top_left'] * @return array[string][string]string $return[%plugin_id%]['top_right'] */ $this->view->assign('frontend_photo', wa()->event('frontend_photo', $this->photo)); $version = wa()->getVersion(); $this->getResponse()->addJs('js/common.js?v=' . $version, true); $this->getResponse()->addJs('js/photo.stream.slider.js?v=' . $version, true); $this->getResponse()->addJs('js/frontend.photo.js?v=' . $version, true); }
public function execute() { $url = waRequest::param('url'); $album = waRequest::param('album'); $this->hash = waRequest::param('hash'); if (!$url) { throw new waException(_w('Page not found', 404)); } $this->photo_model = new photosPhotoModel(); $photo = $this->getPhoto($url); if (!$photo) { throw new waException(_w('Page not found'), 404); } if (!$this->private_hash && !$this->inCollection($photo, $this->hash)) { throw new waException(_w('Page not found'), 404); } $photo = photosPhoto::escapeFields($photo); $size = waRequest::get('size', null, waRequest::TYPE_STRING); $is_mini = waRequest::get('mini', 0, waRequest::TYPE_INT); if ($is_mini) { $size = $size ? $size : photosPhoto::getBigPhotoSize(); // mini version of loading photo (in albums loading photo in stack) $photo['thumb_custom'] = photosPhoto::getThumbInfo($photo, $size); $this->response['photo'] = $photo; return; } // delegate work to special render helper $render_helper = new photosPhotoRenderHelper($photo, $this->private_hash); $result = $render_helper->workUp(array('album' => $album, 'hash' => $this->hash, 'need_photo_stream' => false)); if ($size) { $result['photo']['thumb_custom'] = photosPhoto::getThumbInfo($result['photo'], $size); } // pull out result of working up $this->response['photo'] = $result['photo']; $this->response['tags'] = $result['blocks']['tags']; $this->response['exif'] = $result['blocks']['exif']; $this->response['albums'] = $result['blocks']['albums']; $this->response['author'] = $result['blocks']['author']; $this->response['stack_nav'] = $result['blocks']['stack_nav']; /** * Add extra widgets to photo page * @event frontend_photo * @param string[array]mixed $photo photo data * @return array[string][string]string $return[%plugin_id%]['bottom'] In bottom, under photo - any widget */ $this->response['frontend_photo'] = wa()->event('frontend_photo', $photo); }
public function finite() { $collection = new photosCollection($this->hash); $photos = $collection->getPhotos("*,thumb,frontend_link,tags", $this->offset, $this->photos_per_page); $photos = photosCollection::extendPhotos($photos); if ($this->hash) { $title = $collection->getTitle(); if (!$title) { $this->getResponse()->setTitle(waRequest::param('title') ? waRequest::param('title') : wa()->accountName()); } else { $this->getResponse()->setTitle($title); } $this->view->assign('title', photosPhoto::escape($title)); } else { $this->getResponse()->setTitle(waRequest::param('title') ? waRequest::param('title') : wa()->accountName()); $this->getResponse()->setMeta('keywords', waRequest::param('meta_keywords')); $this->getResponse()->setMeta('description', waRequest::param('meta_description')); $this->view->assign('title', ''); } $this->workupPhotos($photos); $total_count = $collection->count(); $this->view->assign('photos_per_page', $this->photos_per_page); $this->view->assign('pages_count', floor($total_count / $this->photos_per_page) + 1); $this->view->assign('total_photos_count', $total_count); $this->view->assign('offset', $this->offset); $this->view->assign('photos', $photos); $is_xhr = waRequest::isXMLHttpRequest(); $this->view->assign('is_xhr', $is_xhr); if ($is_xhr) { $this->view->assign('frontend_collection', array()); } else { /** * @event frontend_collection * @return array[string][string]string $return[%plugin_id%]['name'] Extra name info * @return array[string][string]string $return[%plugin_id%]['content'] Extra album description and etc * @return array[string][string]string $return[%plugin_id%]['footer'] Footer section * @return array[string][string]string $return[%plugin_id%]['sidebar'] Footer section * @return array[string][string]string $return[%plugin_id%]['footer'] Footer section */ $this->view->assign('frontend_collection', wa()->event('frontend_collection')); } $this->view->assign('lazy_load', !is_null(waRequest::get('lazy'))); $v = wa()->getVersion(); $this->getResponse()->addJs('js/lazy.load.js?v=' . $v, true); $this->getResponse()->addJs('js/frontend.photos.js?v=' . $v, true); }
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 photoUpload(waImage $photo) { $settings = $this->getSettings(); $opacity = $settings['opacity']; $result = null; if ($opacity && !empty($settings['text'])) { $font_path = realpath(dirname(__FILE__) . '/config/data/arial.ttf'); $photo->watermark(array('watermark' => $settings['text'], 'opacity' => $opacity, 'font_file' => $font_path, 'font_size' => $settings['text_size'] * max($photo->width, $photo->height) / photosPhoto::getBigPhotoSize(), 'font_color' => $settings['text_color'], 'text_orientation' => $this->_orientation($settings['text_orientation']), 'align' => $this->_align($settings['text_align']))); $result = true; } if ($opacity && !empty($settings['image'])) { $watermark_path = wa()->getDataPath('data/', true) . $settings['image']; $watermark = waImage::factory($watermark_path); $photo->watermark(array('watermark' => $watermark, 'opacity' => $opacity, 'align' => $this->_align($settings['image_align']))); $result = true; } return $result; }
public function save($file = null, $quality = null) { $config = wa('photos')->getConfig(); if ($quality === null) { $quality = $config->getSaveQuality(); } // check save_original option if ($config->getOption('save_original')) { // get original file name $original_file = photosPhoto::getOriginalPhotoPath($this->file); // save original file if it not exists if (!file_exists($original_file)) { copy($this->file, $original_file); } } // save image return $this->image->save($file, $quality); }
protected function formatSizes($sizes) { $result = array(); foreach ($sizes as $size) { $size_info = photosPhoto::parseSize((string) $size); $type = $size_info['type']; $width = $size_info['width']; $height = $size_info['height']; if ($type == 'max' || $type == 'crop' || $type == 'width') { $result[] = array($type => $width); } else { if ($type == 'height') { $result[] = array($type => $height); } elseif ($type == 'rectangle') { $result[] = array('rectangle' => array($width, $height)); } } } return $result; }
public function execute() { $enabled = wa()->getSetting('enabled', 0, array('photos', 'fotorss')); if (!$enabled) { return null; } $url = wa()->getRouting(); $url = $url->getRouteParam('url_type'); $route = ''; if ($url == 0) { $route = 'photo/'; } $author_on = wa()->getSetting('author_tag', 0, array('photos', 'fotorss')); $max_entries = max(1, wa()->getSetting('posts_number', 0, array('photos', 'fotorss'))); $link = wa()->getRouteUrl('photos/frontend', array(), true); $rss_link = wa()->getRouteUrl('photos/frontend/fotorss', array(), true); $title = waRequest::param('title') ? waRequest::param('title') : wa()->accountName(); $collection = new photosCollection(); $fields = "*,"; $thumbs = wa()->getSetting('thumb', 'default', array('photos', 'fotorss')); if ($thumbs == 'big' || $thumbs == 'middle' || $thumbs == 'mobile' || $thumbs == 'crop') { $thumbs = "thumb_" . $thumbs; } elseif ($thumbs == 'default' || empty($thumbs)) { $thumbs = 'thumb'; } $fields .= $thumbs; $posts = $collection->getphotos($fields, 0, $max_entries); foreach ($posts as &$post) { if ($author_on) { $contact = new waContact($post['contact_id']); $post['author'] = $contact->get('name'); } $post['thumb'] = $post[$thumbs]; if ($thumbs == 'vk') { $post['thumb'] = photosPhoto::getThumbInfo($post, '590x0'); } } wa()->getResponse()->addHeader('Content-type', 'application/rss+xml; charset=utf-8', true); $this->view->assign('posts', $posts); $this->view->assign('info', array('title' => $title, 'link' => $link, 'description' => '', 'language' => 'ru', 'pubDate' => date(DATE_RSS), 'lastBuildDate' => date(DATE_RSS), 'photourl' => $route, 'self' => $rss_link)); }
public function execute() { $album_id = waRequest::post('album_id', 0, 'int'); $photo_id = waRequest::post('photo_id', 0, 'int'); if (!$album_id || !$photo_id) { throw new waException('Bad parameters', 404); } $album_rights_model = new photosAlbumRightsModel(); if (!$album_rights_model->checkRights($album_id, true)) { throw new waException(_w("You don't have sufficient access rights")); } $photo_model = new photosPhotoModel(); $photo = $photo_model->getById($photo_id); if (!$photo) { $this->errors[] = _w('Photo not found'); return; } $album_model = new photosAlbumModel(); $album_model->updateById($album_id, array('key_photo_id' => $photo_id)); photosPhoto::generateThumbs($photo, array('192x192')); }
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); $photo_model = new photosPhotoModel(); $photo_model->rotate($id, $direction == 'right'); $photo = $photo_model->getById($id); $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->log('photo_edit', 1); $this->response['photo'] = $photo; }
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(); }
protected function workupPhotos(&$photos) { $renderer = new photosPhotoHtmlRenderer($this->getTheme()); $photo_model = new photosPhotoModel(); // parent of current photo (that stacked, i.e. in stack) $parent_id = null; if ($this->photo_url) { $stacked_photo = $photo_model->getByField('url', $this->photo_url); if (!$stacked_photo) { throw new waException(_w('Page not found', 404)); } $parent_id = $photo_model->getStackParentId($stacked_photo); } // During going over all photos we also look if some photo is a parent of current stacked photo foreach ($photos as &$photo) { $photo['stack_nav'] = ''; $stack = (array) $photo_model->getStack($photo['id'], array('tags' => true)); if ($stack) { foreach ($stack as &$item) { $item['thumb_custom'] = array('url' => photosPhoto::getPhotoUrlTemplate($item)); $item['full_url'] = photosFrontendAlbum::getLink($this->album) . $item['url'] . '/'; } unset($item); // iterable photo is parent of current stacked photo - replace if ($parent_id == $photo['id']) { $photo = $stacked_photo; $photo['full_url'] = photosFrontendAlbum::getLink($this->album) . $photo['url'] . '/'; $photo['stack_nav'] = $renderer->getStackNavigationPanel($stack, $photo); } else { $photo['stack_nav'] = $renderer->getStackNavigationPanel($stack, $photo); } } $photo['frontend_link'] = photosFrontendPhoto::getLink($photo, array('full_url' => $this->album_url)); } unset($photo); }
public function execute() { $photo_ids = waRequest::post('photo_ids', '', waRequest::TYPE_STRING_TRIM); $size = waRequest::post('size', null, waRequest::TYPE_STRING_TRIM); $hash = waRequest::post('hash', '', waRequest::TYPE_STRING_TRIM); if (strstr($hash, 'search') !== false) { $hash = urldecode($hash); } if (!$photo_ids && strstr($hash, 'album') === false && strstr($hash, 'tag') === false && strstr($hash, 'rate') === false) { $hash = ''; } else { if ($photo_ids) { $hash = '/id/' . $photo_ids; } } if (!$size) { throw new waException(_w('Unknown size')); } $sizes = $this->getConfig()->getSizes(); if (in_array($size, $sizes) === false) { throw new waException(_w('Unknown size')); } $this->response['context'] = photosPhoto::getEmbedPhotoListContext($hash, $size); }
public function display($view_type = 'backend') { $result = $view_type == 'backend' ? '<li class="dr ' . $this->getClass() . '" rel="' . $this->data['id'] . '"><span class="count">' . (!is_null($this->data['count']) ? $this->data['count'] : '') . '</span>' : '<li>'; if ($this->childs) { $result .= $view_type == 'backend' ? '<i class="icon16 darr overhanging collapse-handler" id="album-' . $this->data['id'] . '-handler"></i>' : ''; } $result .= $view_type == 'backend' ? '<a href="' . $this->getHash() . '"><i class="icon16 ' . $this->getIcon() . '"></i>' . photosPhoto::escape($this->data['name']) . ' ' . $this->getStatusIcon() . ' <strong class="small highlighted count-new">' . (!empty($this->data['count_new']) ? '+' . $this->data['count_new'] : '') . '</strong></a>' : '<a href="' . photosFrontendAlbum::getLink($this->data) . '">' . photosPhoto::escape($this->data['name']) . '</a>'; if ($this->childs) { $result .= $view_type == 'backend' ? '<ul class="menu-v with-icons"><li class="drag-newposition"></li>' : '<ul class="menu-v">'; foreach ($this->childs as $e) { $result .= $e->display($view_type); } $result .= '</ul>'; } $result .= $view_type == 'backend' ? '</li><li class="drag-newposition"></li>' : '</li>'; return $result; }
foreach ($size as &$s) { $s *= 2; } unset($s); $size = implode('x', $size); } } wa()->getStorage()->close(); if ($file && file_exists($protected_path . $file) && !file_exists($public_path . $request_file)) { $main_thumb_file_path = $public_path . $main_thumb_file; $target_dir_path = dirname($public_path . $request_file); if (!file_exists($target_dir_path)) { waFiles::create($target_dir_path . '/'); } $max_size = $app_config->getOption('max_size'); $image = photosPhoto::generateThumb(array('path' => $main_thumb_file_path, 'size' => $main_thumbnail_size), $protected_path . $file, $size, $app_config->getOption('sharpen'), $max_size ? $enable_2x ? 2 * $max_size : $max_size : false); if ($image) { $quality = $app_config->getSaveQuality($enable_2x); $image->save($public_path . $request_file, $quality); clearstatcache(); } } if ($file && file_exists($public_path . $request_file)) { waFiles::readFile($public_path . $request_file); } else { /* $url = wa()->getRootUrl(); $url = substr($url, 0, -strlen('/wa-data/public/photo/')); header("Location: ".$url."wa-apps/photos/img/image-not-found.png"); */ header("HTTP/1.0 404 Not Found");