public function execute() { $this->collection = new photosCollection(''); $count = $this->getConfig()->getOption('photos_per_page'); $photos = $this->getPhotos(0, $count); $photos = photosCollection::extendPhotos($photos); $this->view->assign('photos', $photos); $this->view->assign('frontend_link', photosCollection::getFrontendLink('')); $this->view->assign('title', $this->collection->getTitle()); $this->view->assign('total_count', $this->collection->count()); $this->view->assign('big_size', $this->getConfig()->getSize('big')); }
public function execute() { $this->collection = new photosCollection(''); $config = $this->getConfig(); $count = $config->getOption('photos_per_page'); $photos = $this->getPhotos(0, $count); $photos = photosCollection::extendPhotos($photos); $this->view->assign('photos', $photos); $this->view->assign('sidebar_width', $config->getSidebarWidth()); $this->view->assign('frontend_link', photosCollection::getFrontendLink('')); $this->view->assign('title', $this->collection->getTitle()); $this->view->assign('total_count', $this->collection->count()); $this->view->assign('big_size', $config->getSize('big')); $this->view->assign('sort_method', 'upload_datetime'); }
public function execute() { $tag_name = waRequest::get('tag'); $tag_name = urldecode($tag_name); $tag_model = new photosTagModel(); $tag = $tag_model->getByName($tag_name); $title = _w('Tag not found'); $photos = array(); $config = $this->getConfig(); if ($tag) { $hash = '/tag/' . $tag_name; $collection = new photosCollection($hash); $count = $config->getOption('photos_per_page'); $photos = $collection->getPhotos("*,thumb,thumb_crop,thumb_middle,thumb_big,tags,edit_rights", 0, $count); $photos = photosCollection::extendPhotos($photos); $title = $collection->getTitle(); $this->view->assign('frontend_link', photosCollection::getFrontendLink($hash)); $this->view->assign('total_count', $collection->count()); } $this->view->assign('sidebar_width', $config->getSidebarWidth()); $this->view->assign('title', $title); $this->view->assign('photos', $photos); $this->view->assign('big_size', $config->getSize('big')); $this->view->assign('sort_method', 'upload_datetime'); $this->template = 'templates/actions/photo/PhotoList.html'; }
public function execute() { $lazy = !is_null(waRequest::get('lazy')); if (!$lazy) { $this->setLayout(new photosDefaultFrontendLayout()); } else { $this->setTemplate('FrontendPhotos'); } $photos_per_page = wa('photos')->getConfig()->getOption('photos_per_page'); $limit = $photos_per_page; $page = 1; if ($lazy) { $offset = max(0, waRequest::get('offset', 0, waRequest::TYPE_INT)); } else { $page = max(1, waRequest::get('page', 1, waRequest::TYPE_INT)); $offset = ($page - 1) * $photos_per_page; } $c = new photosCollection('publicgallery/myphotos'); $photos = $c->getPhotos('*', $offset, $limit); $photos = photosCollection::extendPhotos($photos); $v = wa()->getVersion(); wa('photos')->getResponse()->addJs('js/lazy.load.js?v=' . $v, true); wa('photos')->getResponse()->addJs('js/frontend.photos.js?v=' . $v, true); $storage = wa()->getStorage(); $current_auth = $storage->read('auth_user_data'); $current_auth_source = $current_auth ? $current_auth['source'] : null; $this->view->assign('current_auth', $current_auth, true); $adapters = wa()->getAuthAdapters(); $total_count = $c->count(); $this->view->assign(array('photos' => $photos, 'page' => $page, 'offset' => $offset, 'photos_per_page' => $photos_per_page, 'total_photos_count' => $total_count, 'lazy_load' => $lazy, 'image_upload_url' => wa()->getRouteUrl('photos/frontend/imageUpload'), 'pages_count' => floor($total_count / $photos_per_page) + 1, 'current_auth_source' => $current_auth_source, 'adapters' => $adapters)); }
public function execute() { $hash = $this->get('hash'); $collection = new photosCollection($hash); $offset = waRequest::get('offset', 0, 'int'); if ($offset < 0) { throw new waAPIException('invalid_param', 'Param offset must be greater than or equal to zero'); } $limit = waRequest::get('limit', 100, 'int'); if ($limit < 0) { throw new waAPIException('invalid_param', 'Param limit must be greater than or equal to zero'); } if ($limit > 1000) { throw new waAPIException('invalid_param', 'Param limit must be less or equal 1000'); } $photos = $collection->getPhotos('*,thumb', $offset, $limit); foreach ($photos as &$p) { if (isset($p['thumb']['url'])) { $p['image_url'] = $p['thumb']['url']; unset($p['thumb']); } } unset($p); $this->response['count'] = $collection->count(); $this->response['offset'] = $offset; $this->response['limit'] = $limit; $this->response['photos'] = array_values($photos); }
public function execute() { $id = waRequest::post('id', null, waRequest::TYPE_INT); $parent_id = waRequest::post('parent_id', null, waRequest::TYPE_INT); $before_id = waRequest::post('before_id', 0, waRequest::TYPE_INT); $album_model = new photosAlbumModel(); $album = $album_model->move($id, $before_id, $parent_id); $this->response['album'] = $album; if ($album['status'] == 1) { $this->response['frontend_link'] = photosFrontendAlbum::getLink($album); } // recalculate // TODO: optimaize $albums = $album_model->getDescendant($album['id']); $albums[] = $album; $counters = array(); foreach ($albums as &$item) { if ($item['type'] == photosAlbumModel::TYPE_DYNAMIC) { $c = new photosCollection('album/' . $item['id']); $counters[$item['id']] = $c->count(); } } unset($item); $this->response['counters'] = $counters; }
public function execute() { $query = trim(waRequest::post('q'), ' /'); $hash = '/search/' . $query; $collection = new photosCollection($hash); if ($query == 'rate>0') { $collection->orderBy('p.rate DESC, p.id'); } $this->template = 'templates/actions/photo/PhotoList.html'; $count = $this->getConfig()->getOption('photos_per_page'); $photos = $collection->getPhotos("*,thumb,thumb_crop,thumb_middle,thumb_big,tags,edit_rights", 0, $count); $photos = photosCollection::extendPhotos($photos); $frontend_link = $query == 'rate>0' ? photosCollection::getFrontendLink('favorites', false) : photosCollection::getFrontendLink($hash, false); /** * @event search_frontend_link * @param string $query * @return array of bool|string if false - default frontend_link isn't overridden, if string - override default frontend link */ $res = wa()->event('search_frontend_link', $query); foreach ($res as $r) { if (is_string($r)) { $frontend_link = $r; break; } } $config = $this->getConfig(); $this->view->assign('sidebar_width', $config->getSidebarWidth()); $this->view->assign('big_size', $config->getSize('big')); $this->view->assign('frontend_link', $frontend_link); $this->view->assign('photos', $photos); $this->view->assign('title', $query == 'rate>0' ? _w('Rated') : $collection->getTitle()); $this->view->assign('total_count', $collection->count()); $this->view->assign('sort_method', $query == 'rate>0' ? 'rate' : 'upload_datetime'); $this->view->assign('hash', $hash); }
public function execute() { $id = waRequest::get('id', null, waRequest::TYPE_INT); if (!$id) { throw new waException(_w('Unknown album')); } $album_model = new photosAlbumModel(); $album = $album_model->getById($id); if (!$album) { throw new waException(_w('Unknown album')); } // check rights $album_rights_model = new photosAlbumRightsModel(); if (!$album_rights_model->checkRights($album)) { throw new waRightsException(_w("You don't have sufficient access rights")); } $album['edit_rights'] = $album_rights_model->checkRights($album, true); $child_albums = $album_model->getChildren($album['id']); $album_model->keyPhotos($child_albums); $hash = '/album/' . $id; $frontend_link = photosCollection::getFrontendLink($hash); $collection = new photosCollection($hash); $config = $this->getConfig(); $count = $config->getOption('photos_per_page'); $photos = $collection->getPhotos("*,thumb,thumb_crop,thumb_middle,thumb_big,tags,edit_rights", 0, $count); $photos = photosCollection::extendPhotos($photos); $album_photos_model = new photosAlbumPhotosModel(); $album['count'] = $collection->count(); if ($album['type'] == photosAlbumModel::TYPE_DYNAMIC) { $album['conditions'] = photosCollection::parseConditions($album['conditions']); } $album['count_new'] = 0; $sort_method = 'sort'; if ($album['type'] == photosAlbumModel::TYPE_DYNAMIC) { $params_model = new photosAlbumParamsModel(); $params = $params_model->get($album['id']); if ($params && isset($params['order']) && $params['order'] == 'rate') { $sort_method = 'rate'; } else { $sort_method = 'upload_datetime'; } } $this->template = 'templates/actions/photo/PhotoList.html'; $this->view->assign('sidebar_width', $config->getSidebarWidth()); $this->view->assign('album', $album); $this->view->assign('child_albums', $child_albums); $this->view->assign('frontend_link', $frontend_link); $this->view->assign('photos', $photos); $this->view->assign('title', $collection->getTitle()); $this->view->assign('hash', $hash); $this->view->assign('big_size', $config->getSize('big')); $this->view->assign('sort_method', $sort_method); }
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() { $album_id = waRequest::get('id', null, waRequest::TYPE_INT); if (!$album_id) { throw new waException(_w('Unknown album')); } $album_model = new photosAlbumModel(); $album = $album_model->getById($album_id); $this->view->assign('album', $album); $collection = new photosCollection('/album/' . $album_id); $this->view->assign('photos_count', $collection->count()); }
public function execute() { if ($this->getRights('upload')) { $this->executeAction('upload_dialog', new photosUploadAction()); } $album_model = new photosAlbumModel(); $albums = $album_model->getAlbums(); $top_level_albums_count = 0; foreach ($albums as $a) { if (!$a['parent_id']) { $top_level_albums_count++; } } /** * Extend photo toolbar in photo-page * Add extra item to toolbar * @event backend_photo_toolbar * @return array[string][string]string $return[%plugin_id%]['edit_menu'] Extra item for edit_menu in photo_toolbar * @return array[string][string]string $return[%plugin_id%]['share_menu'] Extra item for edit_menu in photo_toolbar */ $this->view->assign('backend_photo_toolbar', wa()->event('backend_photo_toolbar')); $tree = new photosViewTree($albums); $this->view->assign('albums', $tree->display()); $this->view->assign('albums_count', count($albums)); $this->view->assign('top_level_albums_count', $top_level_albums_count); $this->view->assign('app_albums', self::getAppAlbums()); $collection = new photosCollection(); $collection_rated = new photosCollection('search/rate>0'); $this->view->assign('count', $collection->count()); $this->view->assign('rated_count', $collection_rated->count()); $this->view->assign('last_login_datetime', $this->getConfig()->getLastLoginTime()); /** * Extend sidebar * Add extra item to sidebar * @event backend_sidebar * @return array[string][string]string $return[%plugin_id%]['menu'] Extra item for menu in sidebar * @return array[string][string]string $return[%plugin_id%]['section'] Extra section in sidebar */ $this->view->assign('backend_sidebar', wa()->event('backend_sidebar')); /** * Include plugins js and css * @event backend_assets * @return array[string]string $return[%plugin_id%] Extra head tag content */ $this->view->assign('backend_assets', wa()->event('backend_assets')); $photo_tag_model = new photosTagModel(); $this->view->assign('cloud', $photo_tag_model->getCloud()); $this->view->assign('popular_tags', $photo_tag_model->popularTags()); $this->view->assign('rights', array('upload' => $this->getRights('upload'), 'edit' => $this->getRights('edit'))); $config = $this->getConfig(); $this->view->assign('big_size', $config->getSize('big')); $this->view->assign('sidebar_width', $config->getSidebarWidth()); }
public function execute() { $app_id = waRequest::request('app_id'); if ($app_id && wa()->appExists($app_id) && wa()->getUser()->getRights($app_id, 'backend')) { $hash = 'app/' . $app_id; } else { $hash = ''; } $this->collection = new photosCollection($hash); $config = $this->getConfig(); $count = $config->getOption('photos_per_page'); $photos = $this->getPhotos(0, $count); $photos = photosCollection::extendPhotos($photos); $this->view->assign('photos', $photos); $this->view->assign('sidebar_width', $config->getSidebarWidth()); $this->view->assign('frontend_link', $hash ? '' : photosCollection::getFrontendLink($hash)); $this->view->assign('title', $this->collection->getTitle()); $this->view->assign('total_count', $this->collection->count()); $this->view->assign('big_size', $config->getSize('big')); $this->view->assign('sort_method', 'upload_datetime'); $this->view->assign('hash', $hash); }
public function execute() { $album_id = waRequest::get('id', null, waRequest::TYPE_INT); $album_model = new photosAlbumModel(); $albums = $album_model->getAlbums(); $album = ifset($albums[$album_id]); if (!$album_id || !$album) { throw new waException(_w('Unknown album')); } $collection = new photosCollection('/album/' . $album_id); $this->view->assign('album', $album); $this->view->assign('photos_count', $collection->count()); $this->view->assign('offspring', $this->getOffspringIds($albums, $album_id)); }
public function execute() { $id = waRequest::get('id', null, waRequest::TYPE_INT); $album_model = new photosAlbumModel(); $album = $album_model->getById($id); if (!$album) { throw new waException(_w("Unknown album"), 404); } $album_right_model = new photosAlbumRightsModel(); if (!$album_right_model->checkRights($album, true)) { throw new waException(_w("You don't have sufficient access rights"), 403); } if ($album['type'] == photosAlbumModel::TYPE_DYNAMIC && $album['conditions']) { $album['conditions'] = photosCollection::parseConditions($album['conditions']); } if (!$album['conditions']) { $album['conditions'] = array(); } $absolute_full_url = photosFrontendAlbum::getLink($album); if ($absolute_full_url) { $pos = strrpos($absolute_full_url, $album['url']); $full_base_url = $pos !== false ? rtrim(substr($absolute_full_url, 0, $pos), '/') . '/' : ''; $album['full_base_url'] = $full_base_url; } $this->view->assign('album', $album); if ($album['parent_id']) { $this->view->assign('parent', $album_model->getById($album['parent_id'])); } $collection = new photosCollection('album/' . $id); $photos_count = $collection->count(); $this->view->assign('photos_count', $photos_count); $album_params_model = new photosAlbumParamsModel(); $this->view->assign('params', $album_params_model->get($id)); $groups_model = new waGroupModel(); $groups = $groups_model->getAll('id', true); $rights = $album_right_model->getByField('album_id', $id, 'group_id'); $photo_tag_model = new photosTagModel(); $cloud = $photo_tag_model->getCloud('name'); if (!empty($album['conditions']['tag'][1])) { foreach ($album['conditions']['tag'][1] as $tag_name) { $cloud[$tag_name]['checked'] = true; } } $this->view->assign('rights', $rights); $this->view->assign('groups', $groups); $this->view->assign('cloud', $cloud); }
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() { $query = trim(waRequest::post('q'), ' /'); $hash = '/search/' . $query; $collection = new photosCollection($hash); if ($query == 'rate>0') { $collection->orderBy('p.rate DESC, p.id'); } $this->template = 'templates/actions/photo/PhotoList.html'; $photos = $collection->getPhotos("*,thumb,thumb_crop,thumb_middle,thumb_big,tags,edit_rights"); $photos = photosCollection::extendPhotos($photos); $this->view->assign('big_size', $this->getConfig()->getSize('big')); $this->view->assign('frontend_link', $query == 'rate>0' ? photosCollection::getFrontendLink('favorites', false) : photosCollection::getFrontendLink($hash, false)); $this->view->assign('photos', $photos); $this->view->assign('title', $query == 'rate>0' ? _w('Rated') : $collection->getTitle()); $this->view->assign('total_count', $collection->count()); }
public function execute() { $status = waRequest::get('status', 'waited', waRequest::TYPE_STRING_TRIM); $offset = waRequest::get('offset', 1, waRequest::TYPE_INT); $c = new photosCollection('', array('ignore_moderation' => true)); $c->addWhere("p.moderation='" . ($status == 'waited' ? 'waited' : 'declined') . "'"); $fields = "*,thumb,thumb_crop,thumb_middle,thumb_big,tags,edit_rights"; if ($this->getRequest()->isMobile()) { $fields = "*,thumb_mobile"; } $photos = array_values($c->getPhotos($fields, $offset, $this->getConfig()->getOption('photos_per_page'))); $photos = photosCollection::extendPhotos($photos); $loaded = count($photos) + $offset; $count = $c->count(); $this->response['photos'] = $photos; $this->response['status'] = $status; $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); }
private function getAlbumsCounters() { $config = $this->getConfig(); $last_activity_datetime = $config->getLastLoginTime(); $albums = array(); $photo_albums = $this->album_photos_model->getAlbums($this->photo_ids, array('id', 'name')); foreach ($photo_albums as &$p_albums) { foreach ($p_albums as $a_id => &$album) { if (!isset($albums[$a_id])) { $collection = new photosCollection('/album/' . $a_id); $album['count'] = $collection->count(); //$album['count_new'] = XXX; $album['count_new'] = 0; $albums[$a_id] = $album; } } unset($album); } unset($p_albums); return $albums; }
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; } } }
private function _formPhotoStream($photo) { $middle_pos = round(wa()->getConfig()->getOption('photos_per_page') / 2); $middle_pos = max(10, $middle_pos); $padding_count = 2; $collection = new photosCollection($this->hash); $current_offset = $collection->getPhotoOffset($photo); $total_count = $collection->count(); // offset-bounds of stream-frame $left_bound = $current_offset - $middle_pos; $right_bound = $current_offset + $middle_pos; $head_padding_count = 0; if ($left_bound < 0) { $head_padding_count = $padding_count; } $tail_padding_count = 0; if ($right_bound > $total_count - 1) { $tail_padding_count = $padding_count; } if (!$head_padding_count) { // recalc padding count for head if need if ($left_bound < 0) { $head_padding_count = $padding_count; } } if (!$tail_padding_count) { // recalc padding count for tail if need if ($right_bound > $total_count - 1) { $tail_padding_count = $padding_count; } } $left_bound = max($left_bound, 0); $right_bound = min($right_bound, $total_count - 1); $count = $right_bound - $left_bound + 1; $contain = false; $photo_stream = $collection->getPhotos('*,thumb,thumb_crop,tags', $left_bound, $count); foreach ($photo_stream as &$item) { $item['thumb_custom'] = array('url' => photosPhoto::getPhotoUrlTemplate($item)); $item['full_url'] = photosFrontendPhoto::getLink(array('url' => $item['url']), $this->album ? $this->album : $this->hash); if (!$contain && $item['id'] == $photo['id']) { $next = current($photo_stream); if ($next) { $this->next_photo_url = photosFrontendPhoto::getLink($next, $this->album ? $this->album : $this->hash); } $contain = true; } } unset($item); if (!$contain) { throw new waException(_w('Page not found', 404)); } // padding with null head of list if need if ($head_padding_count) { $photo_stream = array_merge(array_pad(array(), $head_padding_count, null), $photo_stream); } // padding tail if need if ($tail_padding_count) { $photo_stream = array_merge($photo_stream, array_pad(array(), $tail_padding_count, null)); } return $photo_stream; }
public function getPhotoStream(photosCollection $collection) { $parent = $this->photo_model->getStackParent($this->photo); $current_photo = $parent ? $parent : $this->photo; $offset = $collection->getPhotoOffset($current_photo); $total_count = $collection->count(); $count = $this->getConfig()->getOption('photos_per_page'); $offset = max($offset - floor($count / 2), 0); $photos = array_values($collection->getPhotos('*,thumb,thumb_crop,thumb_middle,thumb_big,tags,edit_rights', $offset, $count)); return array('photos' => $photos, 'current_photo_id' => $current_photo['id']); }