public function execute() { $this->init(); $url = trim(waRequest::param('url', '', waRequest::TYPE_STRING_TRIM), '/'); if (!$url) { throw new waException(_w('Page not found', 404)); } $this->route($url); if (!$this->album) { throw new waException(_w('Page not found', 404)); } $this->album = photosFrontendAlbum::escapeFields($this->album); // retrieve user params $album_params_model = new photosAlbumParamsModel(); $params = $album_params_model->get($this->album['id']); $params = photosPhoto::escape($params); $this->album += $params; // "childcrumbs" - list of childs (sub-albums). Use in 'plain' template $childcrumbs = $this->album_model->getChildcrumbs($this->album['id'], true); waRequest::setParam('breadcrumbs', $this->album_model->getBreadcrumbs($this->album['id'], true)); waRequest::setParam('nofollow', $this->album['status'] <= 0 ? true : false); waRequest::setParam('disable_sidebar', true); $this->setThemeTemplate('album.html'); $this->view->assign('album', $this->album); $this->view->assign('childcrumbs', $childcrumbs); $this->getResponse()->addJs('js/common.js?v=' . wa()->getVersion(), true); $this->finite(); }
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; }
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() { $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); }
/** * * Get photos albums tree * @param bool $return_html * @param bool $custom_params get with custom params or not * @return string */ public function albums($return_html = true, $custom_params = true) { $album_model = new photosAlbumModel(); $albums = $album_model->getAlbums(true); foreach ($albums as &$a) { $a['name'] = htmlspecialchars($a['name']); } unset($a); if ($custom_params) { $album_params_model = new photosAlbumParamsModel(); $params = $album_params_model->get(array_keys($albums)); foreach ($albums as $a_id => &$a) { foreach (ifset($params[$a_id], array()) as $k => $v) { if (!isset($a[$k])) { $a[$k] = $v; } } } unset($a); } if ($return_html) { $tree = new photosViewTree($albums); return $tree->display('frontend'); } else { foreach ($albums as $album_id => $album) { $albums[$album_id]['url'] = photosFrontendAlbum::getLink($album); if ($album['parent_id'] && isset($albums[$album['parent_id']])) { $albums[$album['parent_id']]['childs'][] =& $albums[$album_id]; } } foreach ($albums as $album_id => $album) { if ($album['parent_id']) { unset($albums[$album_id]); } } return $albums; } }
private function save($data) { if (!$this->id) { $this->log('album_create', 1); $this->id = $this->album_model->add($data); } else { $album = $this->album_model->getById($this->id); if (!$album) { throw new Exception("Album doesn't exist"); } $name = $album['name']; if (empty($data['name'])) { $data['name'] = $name; } if ($album['type'] != photosAlbumModel::TYPE_DYNAMIC && isset($data['conditions'])) { unset($data['conditions']); } if ($data['status'] <= 0) { if (isset($data['url']) && !$data['url']) { unset($data['url']); } } else { if (empty($data['url'])) { $data['url'] = photosPhoto::suggestUrl($data['name']); } } $this->album_model->update($this->id, $data); $album_params = new photosAlbumParamsModel(); $album_params->set($this->id, $data['params']); } $album_rights_model = new photosAlbumRightsModel(); if ($data['status'] <= 0 && $data['group_ids']) { $album_rights_model->setRights($this->id, $data['group_ids']); } else { $album_rights_model->setRights($this->id, 0); } }
/** * @param int $id - ID of the album * @param bool $auto_title */ protected function albumPrepare($id, $auto_title = true) { if (strpos($id, ':') !== false) { list($id, $hash) = explode(':', $id); $this->frontend_rights_user = (int) substr($hash, 16, -16); $hash = substr($hash, 0, 16) . substr($hash, -16); } $album_model = new photosAlbumModel(); $album = $album_model->getById($id); $this->setAlbum($album); // album not found or incorrect hash if (!$album || isset($hash) && $hash !== $album['hash']) { $this->where[] = '0'; return; } $this->frontend_base_url = $album['full_url']; if ($auto_title) { $this->addTitle($album['name']); } $count_model = new photosAlbumCountModel(); $this->update_count = array('model' => $album_model, 'id' => $id, 'count' => (int) $count_model->getCount($id)); if ($album['type']) { $this->setHash('/search/' . $album['conditions']); $this->prepare(false, false); $params_model = new photosAlbumParamsModel(); $params = $params_model->get($album['id']); if (isset($params['order']) && $params['order'] == 'rate') { $this->order_by = 'p.rate DESC, p.id DESC'; } while ($album['parent_id'] && $album['type']) { $album = $album_model->getByid($album['parent_id']); if ($album['type']) { $this->setHash('/search/' . $album['conditions']); $this->prepare(true, false); } else { $this->joins['photos_album_photos'] = array('table' => 'photos_album_photos', 'alias' => 'ap'); $this->where[] = "ap.album_id = " . (int) $album['id']; } } } else { $this->joins['photos_album_photos'] = array('table' => 'photos_album_photos', 'alias' => 'ap'); $this->where[] = "ap.album_id = " . (int) $id; $this->order_by = 'ap.sort ASC'; } }