public function getPhotos($offset, $limit)
 {
     $fields = "*,thumb,thumb_crop,thumb_middle,thumb_big,tags,edit_rights";
     if ($this->getRequest()->isMobile()) {
         $fields = "*,thumb_mobile";
     }
     return $this->collection->getPhotos($fields, $offset, $limit);
 }
 public function execute()
 {
     $album_id = waRequest::post('id', null, waRequest::TYPE_INT);
     $status = waRequest::post('status', 0, waRequest::TYPE_INT);
     $groups = waRequest::post('groups', array(), waRequest::TYPE_ARRAY_INT);
     $count = waRequest::post('count', 0, waRequest::TYPE_INT);
     $offset = waRequest::post('offset', 0, waRequest::TYPE_INT);
     $collection = new photosCollection('album/' . $album_id);
     $this->response['offset'] = $offset;
     $photos = $collection->getPhotos('*', $offset, $count, false);
     $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 = new photosPhotoModel();
     $photo_model->updateAccess($allowed_photo_ids, $status, $groups);
 }
Ejemplo n.º 3
0
 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));
 }
Ejemplo n.º 5
0
 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);
 }
Ejemplo n.º 6
0
 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);
 }
 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']]);
 }
Ejemplo n.º 8
0
 public static function loadAlbums(&$posts)
 {
     $album_ids = array();
     foreach ($posts as &$p) {
         $p['album'] = null;
         if ($p['album_id']) {
             $album_ids[$p['album_id']] = $p['album_id'];
         }
     }
     unset($p);
     if (!$album_ids || !self::isAvailable()) {
         return $posts;
     }
     wa('photos');
     // Albums
     $album_model = new photosAlbumModel();
     $albums = $album_model->getById($album_ids);
     $albums[0] = $album_model->getEmptyRow();
     // Album photos and additional fields
     foreach ($albums as &$a) {
         $a['params'] = array();
         $a['photos'] = array();
         $a['frontend_link'] = photosFrontendAlbum::getLink($a);
         if (wa()->getEnv() == 'backend') {
             $a['backend_link'] = wa()->getAppUrl('photos') . '#/album/' . $a['id'] . '/';
         }
         if ($a['id']) {
             $collection = new photosCollection('album/' . $a['id']);
             $collection->setCheckRights(false);
             $a['photos'] = $collection->getPhotos("*,thumb,thumb_crop,thumb_big,frontend_link,tags", 0, 100500);
             if ($a['photos']) {
                 $a['photos'] = photosCollection::extendPhotos($a['photos']);
             }
         }
     }
     unset($a);
     // Album params
     $album_params_model = new photosAlbumParamsModel();
     foreach ($album_params_model->get(array_keys($albums)) as $album_id => $params) {
         $albums[$album_id] += $params;
         $albums[$album_id]['params'] = $params;
     }
     // Attach albums to posts
     foreach ($posts as &$p) {
         if ($p['album_id']) {
             if (!empty($albums[$p['album_id']])) {
                 $p['album'] = $albums[$p['album_id']];
             } else {
                 $p['album'] = $albums[0];
             }
         }
     }
     unset($p);
     return $posts;
 }
Ejemplo n.º 9
0
 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()
 {
     $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;
 }
 /**
  *
  * Get data array from photos collection
  * @param string $hash selector hash
  * @param int|string|null $size numerical size or size name
  * @param int $offset optional parameter
  * @param int $limit optional parameter
  *
  * If $limit is omitted but $offset is not than $offset is interpreted as 'limit' and method returns first 'limit' items
  * If $limit and $offset are omitted that method returns first 500 items
  *
  * @return array
  */
 public function photos($hash = '', $size = null, $offset = null, $limit = null)
 {
     $size = !is_null($size) ? $size : photosPhoto::getThumbPhotoSize();
     $collection = new photosCollection($hash);
     if (!$limit && $offset) {
         $limit = $offset;
         $offset = 0;
     }
     if (!$offset && !$limit) {
         $offset = 0;
         $limit = 500;
     }
     return $collection->getPhotos("*,frontend_link,thumb_" . $size, $offset, $limit, true);
 }
Ejemplo n.º 12
0
 public function execute()
 {
     $id = $this->get('id', true);
     $collection = new photosCollection('id/' . $id);
     $data = $collection->getPhotos('*,thumb_big');
     if (!isset($data[$id])) {
         throw new waAPIException('invalid_param', 'Photo not found', 404);
     }
     $data = $data[$id];
     if (isset($data['thumb_big']['url'])) {
         $data['image_url'] = $data['thumb_big']['url'];
         unset($data['thumb_big']);
     }
     $this->response = $data;
 }
 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);
 }
 /**
  *
  * Get data array from photos collection
  * @param string $hash selector hash
  * @param int|string|null $size numerical size or size name
  * @param int $offset optional parameter
  * @param int $limit optional parameter
  *
  * If $limit is omitted but $offset is not than $offset is interpreted as 'limit' and method returns first 'limit' items
  * If $limit and $offset are omitted that method returns first 500 items
  *
  * @return array
  */
 public function photos($hash = '', $size = null, $offset = null, $limit = null)
 {
     $size = !is_null($size) ? $size : photosPhoto::getThumbPhotoSize();
     $sizes = array();
     foreach (explode(',', $size) as $s) {
         $sizes[] = 'thumb_' . trim($s);
     }
     $sizes = implode(',', $sizes);
     $collection = new photosCollection($hash);
     if (!$limit && $offset) {
         $limit = $offset;
         $offset = 0;
     }
     if (!$offset && !$limit) {
         $offset = 0;
         $limit = 500;
     }
     return $collection->getPhotos("*,frontend_link,tags," . $sizes, $offset, $limit, true);
 }
 public function execute()
 {
     $collection = new photosCollection();
     $hash = '';
     // Specific album?
     if ($id = waRequest::request('album_id', null, 'int')) {
         $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);
         $hash = '/album/' . $id;
     } else {
         if ($app_id = waRequest::request('app_id', '', 'string')) {
             if (wa()->appExists($app_id) && wa()->getUser()->getRights($app_id, 'backend')) {
                 $hash = 'app/' . $app_id;
             } else {
                 throw new waRightsException(_w("You don't have sufficient access rights"));
             }
         }
     }
     // Photos
     $collection = new photosCollection($hash);
     $photos = $collection->getPhotos("*,thumb,thumb_crop,thumb_middle,thumb_big,tags,edit_rights", 0, 100500);
     $photos = photosCollection::extendPhotos($photos);
     // Album tree
     $album_model = new photosAlbumModel();
     $albums = $album_model->getAlbums();
     $albums_tree = new photosViewTree($albums);
     $this->view->assign(array('title' => $collection->getTitle(), 'photos' => $photos, 'albums_tree_html' => $albums_tree->display(), 'app_albums' => photosDefaultLayout::getAppAlbums('blog'), 'hash' => '#/' . trim($hash, '/#') . '/'));
 }
 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;
         }
     }
 }
 public function keyPhotos(&$albums)
 {
     $key_photo_ids = array();
     foreach ($albums as $aid => $a) {
         if ($a['key_photo_id']) {
             $key_photo_ids[] = $a['key_photo_id'];
         }
     }
     $collection = new photosCollection($key_photo_ids);
     $photos = $collection->getPhotos('*,thumb_96x96,thumb_192x192', 0, count($key_photo_ids));
     foreach ($albums as &$a) {
         if ($a['key_photo_id'] && !empty($photos[$a['key_photo_id']])) {
             $a['key_photo'] = $photos[$a['key_photo_id']];
             $a['key_photo']['thumb'] = $a['key_photo']['thumb_192x192'];
         } else {
             if ($a['key_photo_id']) {
                 $this->updateById($a['id'], array('key_photo_id' => null));
             }
             $a['key_photo'] = null;
         }
     }
     unset($a);
     return $albums;
 }
 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;
 }
Ejemplo n.º 21
0
 public static function getEmbedPhotoListContext($hash, $size, $limit = null, $context = null)
 {
     $link = photosCollection::getFrontendLink($hash);
     $collection = new photosCollection($hash);
     $thumb_key = 'thumb_' . $size;
     $photos = $collection->getPhotos('*, ' . $thumb_key, 0, $limit == null ? 500 : $limit);
     $photo_ids = array_keys($photos);
     $photo_model = new photosPhotoModel();
     $public_photo_ids = $photo_model->filterByField($photo_ids, 'status', 1);
     $all_public = count($photo_ids) == count($public_photo_ids);
     // change default collection sort if hash looks like id/1,2,3,4
     if (strstr($hash, 'id/') !== false) {
         $photo_ids = explode(',', preg_replace('/\\/*id\\//', '', $hash));
         $old_photos = $photos;
         $photos = array();
         foreach ($photo_ids as $photo_id) {
             $photo_id = intval($photo_id);
             // need in case of private photo (cause of hash suffix)
             if (isset($old_photos[$photo_id])) {
                 $photos[$photo_id] = $old_photos[$photo_id];
             }
         }
     }
     $urls = '';
     $html = '';
     $html_with_descriptions = '';
     foreach ($photos as $photo) {
         $urls .= $photo[$thumb_key]['url'] . PHP_EOL;
         $img_html = photosPhoto::getEmbedImgHtml($photo, $size);
         $html_with_descriptions .= '<p>' . ($photo['description'] ? $photo['description'] . '<br>' : '') . $img_html . '</p>' . PHP_EOL;
         $html .= $img_html . '<br>' . PHP_EOL;
     }
     $params_string = '"' . $hash . '", "' . $size . '"';
     $smarty_code = '{if $wa->photos}' . PHP_EOL;
     $smarty_code .= '    {$photos = $wa->photos->photos(' . $params_string . ')}' . PHP_EOL;
     $smarty_code .= '    {foreach $photos as $photo}' . PHP_EOL;
     $smarty_code .= '        <p>{if $photo.description}{$photo.description}<br>{/if}' . PHP_EOL;
     $smarty_code .= '            <img src=\'{$photo.' . $thumb_key . '.url}\' alt=\'{$photo.name}.{$photo.ext}\'>' . PHP_EOL;
     $smarty_code .= '        </p>' . PHP_EOL;
     $smarty_code .= '    {/foreach}' . PHP_EOL;
     $smarty_code .= '{/if}' . PHP_EOL;
     return array('urls' => $urls, 'html' => $html, 'html_with_descriptions' => $html_with_descriptions, 'link' => $link, 'smarty_code' => $smarty_code, 'count' => count($photos), 'all_public' => $all_public, 'domains' => self::getDomains($hash));
 }
 public function defaultAction()
 {
     $collection = new photosCollection();
     $photos = array_values($collection->getPhotos("*,thumb_mobile", 0, 100));
     $this->display(array('photos' => $photos, 'uniqid' => uniqid(), 'widget_id' => $this->id, 'widget_url' => $this->getStaticUrl(), 'photo_on_widget' => $this->getPhotoCountOnWidget(), 'json_photos' => $this->getJSONPhotos($photos)));
 }
Ejemplo n.º 23
0
<?php

$model = new waModel();
try {
    $model->query("SELECT key_photo_id FROM photos_album WHERE 0");
} catch (waException $e) {
    $model->exec("ALTER TABLE `photos_album` ADD `key_photo_id` INT(11) NULL DEFAULT NULL");
}
// Set cover photo for all static albums
$sql = "SELECT a.id AS album_id,\n            (SELECT ap.photo_id FROM photos_album_photos AS ap WHERE ap.album_id=a.id ORDER BY RAND() LIMIT 1)\n                AS photo_id\n        FROM photos_album AS a\n        WHERE a.type=0\n            AND key_photo_id IS NULL";
foreach ($model->query($sql) as $row) {
    if ($row['photo_id']) {
        $sql = "UPDATE photos_album SET key_photo_id=? WHERE id=?";
        $model->query($sql, array($row['photo_id'], $row['album_id']));
    }
}
// Set cover photo for the first 50 dynamic albums
$sql = "SELECT id FROM photos_album WHERE type=1 AND key_photo_id IS NULL LIMIT 50";
foreach ($model->query($sql) as $album) {
    $collection = new photosCollection('album/' . $album['id']);
    $collection->orderBy('RAND(), p.id');
    $photos = $collection->getPhotos("id", 0, 1, false);
    if ($photos) {
        $photo = reset($photos);
        $sql = "UPDATE photos_album SET key_photo_id=? WHERE id=?";
        $model->query($sql, array($photo['id'], $album['id']));
    }
}
 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']);
 }