private function getPhoto($url)
 {
     $photo = $this->photo_model->getByField('url', $url);
     if (!$photo) {
         $this->private_hash = photosPhotoModel::parsePrivateUrl($url);
         $photo = $this->photo_model->getByField('hash', $this->private_hash);
         $parent = $this->photo_model->getStackParent($photo);
         $this->hash = photosPhotoModel::getPrivateHash($parent ? $parent : $photo);
     }
     return $photo;
 }
 public function execute()
 {
     $url = waRequest::param('url');
     if (!$url) {
         throw new waException(_w('Page not found', 404));
     }
     $this->hash = 'publicgallery/myphotos';
     $this->photo_model = new photosPhotoModel();
     $this->photo = $this->photo_model->getByField('url', $url);
     if (!$this->photo) {
         throw new waException(_w('Page not found'), 404);
     }
     $this->photo = photosPhoto::escapeFields($this->photo);
     // delegate work to special render helper
     $render_helper = new photosPhotoRenderHelper($this->photo);
     $result = $render_helper->workUp(array('hash' => $this->hash));
     waRequest::setParam('title', $this->photo['name']);
     waRequest::setParam('nofollow', true);
     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']);
     /**
      * 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()
 {
     $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;
     }
 }
 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);
 }
 public function execute()
 {
     $photo_id = waRequest::post('photo_id', array(), waRequest::TYPE_ARRAY_INT);
     $status = waRequest::post('status', 0, waRequest::TYPE_INT);
     $groups = waRequest::post('groups', array(), waRequest::TYPE_ARRAY_INT);
     if (!$groups) {
         $status = -1;
         // only author have access to this photo
         $groups = array(-$this->getUser()->getId());
     }
     // necessary when manage access rights for one photo. When in one photo extra info is needed in response
     $is_one_photo = waRequest::post('one_photo', 0, waRequest::TYPE_INT);
     // necessary only when manage access rights for several photos
     $prev_allowed_photo_id = waRequest::post('allowed_photo_id', array(), waRequest::TYPE_ARRAY_INT);
     $prev_denied_photo_id = waRequest::post('denied_photo_id', array(), waRequest::TYPE_ARRAY_INT);
     $this->photo_model = new photosPhotoModel();
     $this->photo_rights_model = new photosPhotoRightsModel();
     $allowed_photo_id = $this->photo_rights_model->filterAllowedPhotoIds($photo_id, true);
     $denied_photo_id = array_diff($photo_id, $allowed_photo_id);
     $this->photo_model->updateAccess($allowed_photo_id, $status, $groups);
     // leave only id of parents
     $denied_parent_id = array();
     if ($denied_photo_id) {
         foreach ($this->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;
     // leave only id of parents
     $allowed_parent_id = array();
     if ($allowed_photo_id) {
         foreach ($this->photo_model->getByField('id', $allowed_photo_id, 'id') as $photo) {
             $allowed_parent_id[] = $photo['parent_id'] > 0 ? $photo['parent_id'] : $photo['id'];
         }
     }
     $allowed_photo_id = array_values(array_unique(array_merge($prev_allowed_photo_id, $allowed_parent_id)));
     $this->response['allowed_photo_id'] = $allowed_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 one photo send extra info for update cache and widget
     if ($is_one_photo && $allowed_photo_id) {
         $frontend_link_template = photosFrontendPhoto::getLink(array('url' => '%url%'));
         if (count($photo_id) > 1) {
             // stack
             $stack = $this->photo_model->getStack($photo_id[0]);
             foreach ($stack as &$photo) {
                 $photo = $this->workup($photo);
             }
             unset($photo);
             $this->response['stack'] = array_values($stack);
         } else {
             // just photo
             $photo_id = $photo_id[0];
             $photo = $this->photo_model->getById($photo_id);
             $photo = $this->workup($photo);
             $this->response['photo'] = $photo;
         }
         $this->response['frontend_link_template'] = $frontend_link_template;
     }
 }