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; }
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); }
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; }