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()
 {
     $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;
 }
 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']);
 }