/** * * Get photos albums tree * @return string */ public function albums() { $album_model = new photosAlbumModel(); $albums = $album_model->getAlbums(true); $tree = new photosViewTree($albums); return $tree->display('frontend'); }
public function execute() { $id = waRequest::post('id', null, waRequest::TYPE_INT); $parent_id = waRequest::post('parent_id', null, waRequest::TYPE_INT); $before_id = waRequest::post('before_id', 0, waRequest::TYPE_INT); $album_model = new photosAlbumModel(); $album = $album_model->move($id, $before_id, $parent_id); $this->response['album'] = $album; if ($album['status'] == 1) { $this->response['frontend_link'] = photosFrontendAlbum::getLink($album); } // recalculate // TODO: optimaize $albums = $album_model->getDescendant($album['id']); $albums[] = $album; $counters = array(); foreach ($albums as &$item) { if ($item['type'] == photosAlbumModel::TYPE_DYNAMIC) { $c = new photosCollection('album/' . $item['id']); $counters[$item['id']] = $c->count(); } } unset($item); $this->response['counters'] = $counters; }
public function execute() { $name = $this->get('name', true); $album_model = new photosAlbumModel(); $this->response = $album_model->getByName($name); $this->response['_element'] = 'album'; }
public function execute() { $name = waRequest::post('name', '', waRequest::TYPE_STRING_TRIM); if (in_array($name, $this->availableFields) === false) { throw new waException(_w("Can't update album: unknown field")); } $album_rights_model = new photosAlbumRightsModel(); $id = waRequest::post('id', null, waRequest::TYPE_ARRAY_INT); if (is_array($id)) { $id = current($id); } if ($id) { $album_model = new photosAlbumModel(); $album = $album_model->getById($id); if (!$album) { throw new waException(_w('Unknown album')); } if (!$album_rights_model->checkRights($album, true)) { throw new waException(_w("You don't have sufficient access rights")); } $value = waRequest::post('value', '', waRequest::TYPE_STRING_TRIM); $album_model->updateById($id, array($name => $value)); $album['not_escaped_name'] = $value; $album['name'] = photosPhoto::escape($value); $this->response['album'] = $album; } }
public function execute() { $parent_id = waRequest::get('parent_id'); $depth = waRequest::get('depth', null, 'int'); $album_model = new photosAlbumModel(); $albums = $album_model->getAlbums(); foreach ($albums as $album_id => $album) { if ($album['parent_id'] && isset($albums[$album['parent_id']])) { $albums[$album['parent_id']]['albums'][] =& $albums[$album_id]; } } if (!$parent_id) { foreach ($albums as $album_id => $album) { if ($album['parent_id']) { unset($albums[$album_id]); } } $albums = array_values($albums); } else { $albums = array($albums[$parent_id]); } if ($depth !== null) { $albums = array('albums' => $albums); $this->cutOffSubtree($albums, $depth + 1); $albums = $albums['albums']; } $this->response = $albums; $this->response['_element'] = 'album'; }
public function execute() { $album_model = new photosAlbumModel(); $albums = $album_model->getAlbums(false, photosAlbumModel::TYPE_STATIC, $this->getRights('edit') ? false : true, false); $this->view->assign('albums', $albums); $group_model = new waGroupModel(); $groups = $group_model->getNames(); $this->view->assign('groups', $groups); }
public function execute() { $routes = $this->getRoutes(); $app_id = wa()->getApp(); $album_model = new photosAlbumModel(); $album_photos_model = new photosAlbumPhotosModel(); $page_model = new photosPageModel(); $real_domain = $this->routing->getDomain(null, true, false); foreach ($routes as $route) { $this->routing->setRoute($route); $albums = $album_model->getByField(array('type' => photosAlbumModel::TYPE_STATIC, 'status' => 1), 'id'); $favorites_lastmod_time = null; // albums and photos in albums if ($albums) { $current_album_id = null; $current_album_lastmod_time = null; foreach ((array) $album_photos_model->getPhotos(array_keys($albums)) as $photo) { if ($photo['album_id'] != $current_album_id) { if ($current_album_id) { $this->addUrl(photosFrontendAlbum::getLink($albums[$current_album_id]), $current_album_lastmod_time); } $current_album_id = $photo['album_id']; } $photo_url = photosFrontendPhoto::getLink($photo, $albums[$current_album_id]); $lastmod_time = max($photo['edit_datetime'], $photo['upload_datetime']); $this->addUrl($photo_url, $lastmod_time); $current_album_lastmod_time = max($current_album_lastmod_time, $lastmod_time); if ($photo['rate'] > 0) { $favorites_lastmod_time = max($favorites_lastmod_time, $lastmod_time); } } } // just photos (that aren't inside any album) foreach ((array) $album_photos_model->getPhotos() as $photo) { $photo_url = photosFrontendPhoto::getLink($photo); $lastmod_time = max($photo['edit_datetime'], $photo['upload_datetime']); $this->addUrl($photo_url, $lastmod_time); if ($photo['rate'] > 0) { $favorites_lastmod_time = max($favorites_lastmod_time, $lastmod_time); } } // favorite page $this->addUrl(photosCollection::getFrontendLink('favorites', false), $favorites_lastmod_time ? $favorites_lastmod_time : time()); // pages $main_url = wa()->getRouteUrl($app_id . "/frontend", array(), true, $real_domain); $domain = $this->routing->getDomain(null, true); $sql = "SELECT full_url, url, create_datetime, update_datetime FROM " . $page_model->getTableName() . ' WHERE status = 1 AND domain = s:domain AND route = s:route'; $pages = $page_model->query($sql, array('domain' => $domain, 'route' => $route['url']))->fetchAll(); foreach ($pages as $p) { $this->addUrl($main_url . $p['full_url'], $p['update_datetime'] ? $p['update_datetime'] : $p['create_datetime'], self::CHANGE_MONTHLY, 0.6); } // main page $this->addUrl($main_url, time(), self::CHANGE_DAILY, 1.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; }
public function execute() { $album_id = waRequest::post('album_id', null, waRequest::TYPE_INT); $album_rights_model = new photosAlbumRightsModel(); if (!$album_rights_model->checkRights($album_id, true)) { throw new waException(_w("You don't have sufficient access rights")); } $album_model = new photosAlbumModel(); $album_model->delete($album_id); $this->log('album_delete', 1); }
public function execute() { $id = $this->get('id', true); $album_model = new photosAlbumModel(); $album = $album_model->getById((int) $id); if ($album) { $this->response = $album; } else { throw new waAPIException('invalid_request', 'Album not found', 404); } }
public function execute() { $album_id = waRequest::get('id', null, waRequest::TYPE_INT); if (!$album_id) { throw new waException(_w('Unknown album')); } $album_model = new photosAlbumModel(); $album = $album_model->getById($album_id); $this->view->assign('album', $album); $collection = new photosCollection('/album/' . $album_id); $this->view->assign('photos_count', $collection->count()); }
public function execute() { if ($this->getRights('upload')) { $this->executeAction('upload_dialog', new photosUploadAction()); } $album_model = new photosAlbumModel(); $albums = $album_model->getAlbums(); $top_level_albums_count = 0; foreach ($albums as $a) { if (!$a['parent_id']) { $top_level_albums_count++; } } /** * Extend photo toolbar in photo-page * Add extra item to toolbar * @event backend_photo_toolbar * @return array[string][string]string $return[%plugin_id%]['edit_menu'] Extra item for edit_menu in photo_toolbar * @return array[string][string]string $return[%plugin_id%]['share_menu'] Extra item for edit_menu in photo_toolbar */ $this->view->assign('backend_photo_toolbar', wa()->event('backend_photo_toolbar')); $tree = new photosViewTree($albums); $this->view->assign('albums', $tree->display()); $this->view->assign('albums_count', count($albums)); $this->view->assign('top_level_albums_count', $top_level_albums_count); $this->view->assign('app_albums', self::getAppAlbums()); $collection = new photosCollection(); $collection_rated = new photosCollection('search/rate>0'); $this->view->assign('count', $collection->count()); $this->view->assign('rated_count', $collection_rated->count()); $this->view->assign('last_login_datetime', $this->getConfig()->getLastLoginTime()); /** * Extend sidebar * Add extra item to sidebar * @event backend_sidebar * @return array[string][string]string $return[%plugin_id%]['menu'] Extra item for menu in sidebar * @return array[string][string]string $return[%plugin_id%]['section'] Extra section in sidebar */ $this->view->assign('backend_sidebar', wa()->event('backend_sidebar')); /** * Include plugins js and css * @event backend_assets * @return array[string]string $return[%plugin_id%] Extra head tag content */ $this->view->assign('backend_assets', wa()->event('backend_assets')); $photo_tag_model = new photosTagModel(); $this->view->assign('cloud', $photo_tag_model->getCloud()); $this->view->assign('popular_tags', $photo_tag_model->popularTags()); $this->view->assign('rights', array('upload' => $this->getRights('upload'), 'edit' => $this->getRights('edit'))); $config = $this->getConfig(); $this->view->assign('big_size', $config->getSize('big')); $this->view->assign('sidebar_width', $config->getSidebarWidth()); }
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() { $album_id = waRequest::get('id', null, waRequest::TYPE_INT); $album_model = new photosAlbumModel(); $albums = $album_model->getAlbums(); $album = ifset($albums[$album_id]); if (!$album_id || !$album) { throw new waException(_w('Unknown album')); } $collection = new photosCollection('/album/' . $album_id); $this->view->assign('album', $album); $this->view->assign('photos_count', $collection->count()); $this->view->assign('offspring', $this->getOffspringIds($albums, $album_id)); }
public function execute() { // Load albums $album_model = new photosAlbumModel(); $albums = $album_model->getAlbums(); // We only care about root-level albums foreach ($albums as $aid => $a) { if ($a['parent_id']) { unset($albums[$aid]); continue; } } // Load cover photos $album_model->keyPhotos($albums); $this->view->assign(array('sidebar_width' => wa('photos')->getConfig()->getSidebarWidth(), 'albums' => $albums)); }
public function execute() { $data = waRequest::post(); if (!wa()->getUser()->getRights('photos', 'upload')) { throw new waAPIException('access_denied', 403); } $group_ids = array(0); if (!isset($data['status'])) { $data['status'] = 1; } else { if ($data['status'] == -1) { $group_ids = array(-wa()->getUser()->getId()); } } $data['groups'] = $group_ids; $data['source'] = photosPhotoModel::SOURCE_API; // work with album if (isset($data['album_id'])) { $album_id = $data['album_id']; $album_model = new photosAlbumModel(); $album = $album_model->getById($album_id); if (!$album) { throw new waAPIException('invalid_param', 'Album not found', 404); } $album_rights_model = new photosAlbumRightsModel(); if (!$album_rights_model->checkRights($album_id, true)) { throw new waAPIException('access_denied', 'Not rights to album', 403); } } $file = waRequest::file('file'); if (!$file->uploaded()) { throw new waAPIException('server_error', $file->error, 500); } $id = null; $photo_model = new photosPhotoModel(); try { $id = $photo_model->add($file, $data); } catch (Exception $e) { throw new waAPIException('server_error', $e->getMessage(), 500); } if (!$id) { throw new waAPIException('server_error', 500); } $_GET['id'] = $id; $method = new photosPhotoGetInfoMethod(); $this->response = $method->getResponse(true); }
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); }
public function execute() { if ($id = waRequest::get('id', waRequest::TYPE_INT)) { $photo_model = new photosPhotoModel(); $photo = $photo_model->getById($id); $album_photos_model = new photosAlbumPhotosModel(); $photo_albums = $album_photos_model->getByPhoto($id); } else { $photo = null; $photo_albums = array(); } $this->view->assign('photo_albums', $photo_albums); $album_model = new photosAlbumModel(); $albums = $album_model->getAlbums(false, photosAlbumModel::TYPE_STATIC, $this->getRights('edit') ? false : true, false); $this->view->assign('albums', $albums); $this->view->assign('photo', $photo); }
public function execute() { $routes = $this->getRoutes(); $app_id = wa()->getApp(); $album_model = new photosAlbumModel(); $album_photos_model = new photosAlbumPhotosModel(); foreach ($routes as $route) { $this->routing->setRoute($route); $albums = $album_model->getByField(array('type' => photosAlbumModel::TYPE_STATIC, 'status' => 1), 'id'); $favorites_lastmod_time = null; // albums and photos in albums if ($albums) { $current_album_id = null; $current_album_lastmod_time = null; foreach ((array) $album_photos_model->getPhotos(array_keys($albums)) as $photo) { if ($photo['album_id'] != $current_album_id) { if ($current_album_id) { $this->addUrl(photosFrontendAlbum::getLink($albums[$current_album_id]), $current_album_lastmod_time); } $current_album_id = $photo['album_id']; } $photo_url = photosFrontendPhoto::getLink($photo, $albums[$current_album_id]); $lastmod_time = max($photo['edit_datetime'], $photo['upload_datetime']); $this->addUrl($photo_url, $lastmod_time); $current_album_lastmod_time = max($current_album_lastmod_time, $lastmod_time); if ($photo['rate'] > 0) { $favorites_lastmod_time = max($favorites_lastmod_time, $lastmod_time); } } } // just photos (that aren't inside any album) foreach ((array) $album_photos_model->getPhotos() as $photo) { $photo_url = photosFrontendPhoto::getLink($photo); $lastmod_time = max($photo['edit_datetime'], $photo['upload_datetime']); $this->addUrl($photo_url, $lastmod_time); if ($photo['rate'] > 0) { $favorites_lastmod_time = max($favorites_lastmod_time, $lastmod_time); } } // favorite page $this->addUrl(photosCollection::getFrontendLink('favorites', false), $favorites_lastmod_time); // main page wa()->getRouteUrl($app_id . "/frontend", array(), true); } }
public function execute() { if (!$this->getRights('upload')) { throw new waRightsException(_w("You don't have sufficient access rights")); } $parent_id = waRequest::get('parent_id', 0, waRequest::TYPE_INT); $parent = null; if ($parent_id) { $album_model = new photosAlbumModel(); $parent = $album_model->getById($parent_id); } $this->view->assign('parent', $parent); $groups_model = new waGroupModel(); $this->view->assign('groups', $groups_model->getNames()); $photo_tag_model = new photosTagModel(); $cloud = $photo_tag_model->getCloud('name'); $this->view->assign('cloud', $cloud); }
public function execute() { $id = $this->post('id', true); $album_model = new photosAlbumModel(); $album = $album_model->getById((int) $id); if ($album) { $album_rights_model = new photosAlbumRightsModel(); if (!$album_rights_model->checkRights($id, true)) { throw new waAPIException('access_denied', 403); } if ($album_model->delete($id)) { $this->response = true; } else { throw new waAPIException('server_error', 500); } } else { throw new waAPIException('invalid_request', 'Album not found', 404); } }
public function execute() { $album_id = waRequest::post('album_id', 0, 'int'); $photo_id = waRequest::post('photo_id', 0, 'int'); if (!$album_id || !$photo_id) { throw new waException('Bad parameters', 404); } $album_rights_model = new photosAlbumRightsModel(); if (!$album_rights_model->checkRights($album_id, true)) { throw new waException(_w("You don't have sufficient access rights")); } $photo_model = new photosPhotoModel(); $photo = $photo_model->getById($photo_id); if (!$photo) { $this->errors[] = _w('Photo not found'); return; } $album_model = new photosAlbumModel(); $album_model->updateById($album_id, array('key_photo_id' => $photo_id)); photosPhoto::generateThumbs($photo, array('192x192')); }
private function validate($data) { $album = $this->album_model->getById($this->id); // check url $parent_id = $album['parent_id']; if ($data['url'] != null) { if ($this->album_model->urlExists($data['url'], $this->id, $parent_id)) { $this->errors['url'] = _w('URL is in use'); } } return empty($this->errors); }
/** * * 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; } }
/** * @param array|int $album album or id of album * @param bool $check_edit */ public function checkRights($album, $check_edit = false) { if (!is_array($album)) { $album_model = new photosAlbumModel(); $album = $album_model->getById((int) $album); } if (!$album) { return false; } $album_id = $album['id']; $user = wa()->getUser(); if ($check_edit && $album['contact_id'] != $user->getId() && !$user->getRights('photos', 'edit')) { return false; } if ($user->isAdmin()) { $where = "(group_id >= 0 OR group_id = -" . (int) $user->getId() . ")"; } else { $groups = wa()->getUser()->getGroupIds(); $where = "group_id IN ('" . implode("','", $groups) . "')"; } $sql = "SELECT count(*) FROM " . $this->table . "\n WHERE album_id = " . (int) $album_id . " AND " . $where . "\n LIMIT 1"; return (bool) $this->query($sql)->fetchField(); }
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() { if (!wa()->getUser()->getRights('photos', 'upload')) { throw new waAPIException('access_denied', 403); } $data = waRequest::post(); // check required param name $this->post('name', true); $album_model = new photosAlbumModel(); $group_ids = array(0); if (!isset($data['status'])) { $data['status'] = 1; } else { if ($data['status'] == -1) { $group_ids = array(-wa()->getUser()->getId()); } } if ($data['status'] <= 0) { $data['hash'] = md5(uniqid(time(), true)); } else { $data['url'] = $album_model->suggestUniqueUrl(photosPhoto::suggestUrl($data['name'])); } if (!isset($data['type'])) { $data['type'] == photosAlbumModel::TYPE_STATIC; } $parent_id = waRequest::post('parent_id', 0, 'int'); $parent = $album_model->getById($parent_id); if ($parent_id) { if (!$parent) { throw new waAPIException('invalid_request', 'Parent album not found', 404); } if ($data['type'] == photosAlbumModel::TYPE_STATIC && $parent['type'] == photosAlbumModel::TYPE_DYNAMIC) { throw new waAPIException('invalid_request', 'Inserted album is static but parent album is dynamic', 404); } if ($data['status'] > 0 && $parent['status'] <= 0) { throw new waAPIException('invalid_request', 'Inserted album is public but parent album is private', 404); } } if ($id = $album_model->add($data, $parent_id)) { // return info of the new album $_GET['id'] = $id; if ($parent_id) { $child = $album_model->getFirstChild($parent_id); $album_model->move($id, $child ? $child['id'] : 0, $parent_id); } $album_rights_model = new photosAlbumRightsModel(); $album_rights_model->setRights($id, $group_ids); $method = new photosAlbumGetInfoMethod(); $this->response = $method->getResponse(true); } else { throw new waAPIException('server_error', 500); } }
public function execute() { $id = $this->get('id', true); $album_model = new photosAlbumModel(); $album = $album_model->getById($id); if ($album) { $album_rights_model = new photosAlbumRightsModel(); if (!$album_rights_model->checkRights($id, true)) { throw new waAPIException('access_denied', 403); } $data = waRequest::post(); if (isset($data['parent_id']) && $album['parent_id'] != $data['parent_id']) { if (!$album_model->getById($data['parent_id'])) { throw new waAPIException('invalid_param', 'Parent album not found', 404); } if (!$album_model->move($id, null, $data['parent_id'])) { throw new waAPIException('server_error', 500); } } if (isset($data['type'])) { unset($data['type']); } if ($album_model->update($id, $data)) { // correct rights $album = $album_model->getById($id); $group_ids = array(0); if ($data['status'] == -1) { $group_ids = array(-wa()->getUser()->getId()); } $album_rights_model = new photosAlbumRightsModel(); $album_rights_model->setRights($id, $group_ids); $method = new photosAlbumGetInfoMethod(); $this->response = $method->getResponse(true); } else { throw new waAPIException('server_error', 500); } } else { throw new waAPIException('invalid_param', 'Album not found', 404); } }
private function getBreadcrumbs() { if ($this->album) { $album_model = new photosAlbumModel(); return $album_model->getBreadcrumbs($this->album['id'], true, true); } return array(); }
public function execute() { $this->photo_ids = waRequest::post('photo_id', array(), waRequest::TYPE_ARRAY_INT); $album_id = waRequest::post('album_id', array(), waRequest::TYPE_ARRAY_INT); $copy = waRequest::post('copy', 1, waRequest::TYPE_INT); $this->album_photos_model = new photosAlbumPhotosModel(); $photo_rights_model = new photosPhotoRightsModel(); if (!$copy) { // it means manage with one photo $photo_id = $this->photo_ids[0]; if (!$photo_rights_model->checkRights($photo_id, true)) { throw new waException("You don't have sufficient access rights"); } $early_albums = array_keys($this->album_photos_model->getByField('photo_id', $photo_id, 'album_id')); // TODO: check rights for editing (take into account deleting!) $this->album_photos_model->set($photo_id, $album_id); $this->log('photos_move', 1); $albums = $this->getAlbumsCounters(); $old_albums = array(); foreach ($early_albums as $a_id) { if (!isset($albums[$a_id])) { $collection = new photosCollection('/album/' . $a_id); $album = array('id' => $a_id, 'count' => $collection->count(), 'count_new' => 0); $old_albums[] = $album; } } $this->response['albums'] = array_values($albums); $this->response['old_albums'] = $old_albums; } else { // otherwise copy photos to albums $allowed_photo_id = $photo_rights_model->filterAllowedPhotoIds($this->photo_ids, true); $denied_photo_id = array_values(array_diff($this->photo_ids, $allowed_photo_id)); $album_rights_model = new photosAlbumRightsModel(); $allowed_album_id = $album_rights_model->filterAllowedAlbumIds($album_id, true); $denied_album_id = array_values(array_diff($album_id, $allowed_album_id)); if ($allowed_album_id && $allowed_photo_id) { $this->album_photos_model->add($allowed_photo_id, $allowed_album_id); $this->log('photos_move', 1); } $albums = $this->getAlbumsCounters(); $this->response['albums'] = array_values($albums); if ($denied_photo_id) { $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)", count($denied_photo_id), _w("out of %d selected", "out of %d selected", count($this->photo_ids))) . ', ' . _w("because you don't have sufficient access rights") . '.'; } } // Set cover photos for albums if first photo just been added to it $photo_model = new photosPhotoModel(); $album_model = new photosAlbumModel(); $allowed_photo_id = isset($allowed_photo_id) ? $allowed_photo_id : array($photo_id); $no_cover_album_ids = array(); foreach (ifset($allowed_album_id, $album_id) as $album_id) { if (!empty($albums[$album_id]) && empty($albums[$album_id]['key_photo_id'])) { $no_cover_album_ids[] = $album_id; } } $photos = array(); while ($allowed_photo_id && $no_cover_album_ids) { // Get random photo from added and make sure it exists shuffle($allowed_photo_id); $photo_id = array_pop($allowed_photo_id); if (!empty($photos[$photo_id])) { $photo = $photos[$photo_id]; } else { $photos[$photo_id] = $photo = $photo_model->getById($photo_id); } if (!$photo) { continue; } // Photo exists, so add it back $allowed_photo_id[] = $photo_id; // Set cover for one album $album_id = array_pop($no_cover_album_ids); $album_model->updateById($album_id, array('key_photo_id' => $photo_id)); photosPhoto::generateThumbs($photo, array('192x192')); } }