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() { $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 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 = $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); } }
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); }
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() { $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() { 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); } }
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() { 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); } }
/** * @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 static function frontendAlbumHashToUrl($hash) { if (strstr($hash, 'album') !== false) { if (substr($hash, 0, 1) == '#') { $hash = substr($hash, 1); } $hash = trim($hash, '/'); $hash = explode('/', $hash); if (count($hash) == 2) { $album_id = $hash[1]; if (strpos($album_id, ':') !== false) { list($album_id, $private_hash) = explode(':', $album_id); return 'album:' . $private_hash; } $album_model = new photosAlbumModel(); $album = $album_model->getById($album_id); if ($album['hash'] && $album['status'] <= 0) { return 'album:' . substr($album['hash'], 0, 16) . wa()->getUser()->getId() . substr($album['hash'], 16); } else { return $album['full_url']; } } } return null; }
/** * Prepare for saving posted post and return it * * @return array prepared post * */ private function getPreparedPost() { $post = array('id' => waRequest::post('post_id', null, waRequest::TYPE_INT), 'title' => substr(waRequest::post('title', '', waRequest::TYPE_STRING_TRIM), 0, 255), 'text' => waRequest::post('text'), 'blog_id' => waRequest::post('blog_id'), 'contact_id' => waRequest::post('contact_id'), 'datetime' => waRequest::post('datetime'), 'url' => waRequest::post('url', '', waRequest::TYPE_STRING_TRIM), 'draft' => waRequest::post('draft'), 'comments_allowed' => max(0, min(1, waRequest::post('comments_allowed', 0, waRequest::TYPE_INT))), 'public' => waRequest::post('public'), 'schedule_datetime' => waRequest::post('schedule_datetime'), 'meta_title' => waRequest::post('meta_title', null, waRequest::TYPE_STRING_TRIM), 'meta_keywords' => waRequest::post('meta_keywords', null, waRequest::TYPE_STRING_TRIM), 'meta_description' => waRequest::post('meta_description', null, waRequest::TYPE_STRING_TRIM), 'album_id' => waRequest::post('album_id', null, waRequest::TYPE_INT), 'album_link_type' => waRequest::post('album_link_type', null, waRequest::TYPE_STRING_TRIM)); if ($post['album_id'] && blogPhotosBridge::isAvailable()) { wa('photos'); $album_model = new photosAlbumModel(); $album = $album_model->getById($post['album_id']); if (!$album) { $album = $post['album_id'] = null; } else { if ($album['status'] <= 0) { $post['album_link_type'] = null; } } } else { $post['album_id'] = null; } if (!$post['album_id']) { $post['album_id'] = $post['album_link_type'] = null; } else { if ($post['album_link_type'] != 'photos') { $post['album_link_type'] = 'blog'; } } $this->inline = waRequest::post('inline', false); if (waRequest::post('scheduled') && !empty($post['schedule_datetime'])) { $post['datetime'] = $post['schedule_datetime']; } if (!is_null($post['datetime'])) { $post['datetime'] = (array) $post['datetime']; if (count($post['datetime']) == 3) { $post['datetime'][1] = (int) $post['datetime'][1]; $post['datetime'][2] = (int) $post['datetime'][2]; $date_time = $post['datetime'][0] . ' ' . $post['datetime'][1] . ':' . $post['datetime'][2]; } else { $date_time = implode(' ', $post['datetime']); } $post['datetime'] = $date_time; } if (waRequest::post('draft')) { $post['status'] = blogPostModel::STATUS_DRAFT; $this->operation = self::OPERATION_SAVE_DRAFT; } else { if (waRequest::post('deadline')) { if ($post['datetime']) { $post['status'] = blogPostModel::STATUS_DEADLINE; $this->operation = self::OPERATION_SET_DEADLINE; } else { $post['status'] = blogPostModel::STATUS_DRAFT; $this->operation = self::OPERATION_SAVE_DRAFT; } } else { if (waRequest::post('scheduled')) { $post['status'] = blogPostModel::STATUS_SCHEDULED; } else { if (waRequest::post('published')) { $post['status'] = blogPostModel::STATUS_PUBLISHED; $this->operation = self::OPERATION_PUBLISH; } else { if (waRequest::post('unpublish')) { $post['status'] = blogPostModel::STATUS_DRAFT; $this->operation = self::OPERATION_UNPUBLISH; } else { if ($post['id'] && waRequest::issetPost('delete')) { $this->operation = self::OPERATION_DELETE; } else { if (waRequest::issetPost("schedule_cancel")) { $this->operation = self::OPERATION_CANCEL_SCHEDULE; } } } } } } } if (!isset($post['status'])) { if ($post['id']) { $post['status'] = $this->post_model->select('status')->where('id = i:id', array('id' => $post['id']))->fetchField('status'); } else { $post['status'] = blogPostModel::STATUS_DRAFT; } } $blog_model = new blogBlogModel(); $blog = $blog_model->getById($post['blog_id']); $post['blog_status'] = $blog['status']; $post['plugin'] = (array) waRequest::post('plugin', null); foreach ($post['plugin'] as $k => &$plugin_data) { if (!is_array($plugin_data)) { $plugin_data = trim($plugin_data); } } return $post; }