public function execute() { if (!$this->getUser()->getRights('photos', 'edit')) { throw new waException(_w("Access denied")); } $moderation = waRequest::post('moderation', '', waRequest::TYPE_STRING_TRIM); $id = waRequest::post('id', '', waRequest::TYPE_INT); $photo_model = new photosPhotoModel(); $photo = $photo_model->getById($id); if (!$photo) { $this->errors[] = _wp('Unknown photo'); } if ($moderation == 'approve') { $photo_model->updateById($id, array('moderation' => 1)); $photo_model->updateAccess($id, 1, array(0)); } if ($moderation == 'decline') { $photo_model->updateById($id, array('moderation' => -1)); $photo_model->updateAccess($id, 0, array(0)); } $this->response['photo'] = $photo_model->getById($id); // update for making inline-editable widget $this->response['frontend_link_template'] = photosFrontendPhoto::getLink(array('url' => '%url%')); $this->response['counters'] = array('declined' => $photo_model->countByField('moderation', -1), 'awaiting' => $photo_model->countByField('moderation', 0)); // l18n string $count = (int) waRequest::post('count'); $total_count = (int) waRequest::post('total_count'); $this->response['string'] = array('loaded' => _w('%d photo', '%d photos', $count), 'of' => sprintf(_w('of %d'), $total_count), 'chunk' => $count < $total_count ? _w('%d photo', '%d photos', min($this->getConfig()->getOption('photos_per_page'), $count - $total_count)) : false); }
public function execute() { $photo_id = waRequest::get('photo_id', null, waRequest::TYPE_INT); $size = waRequest::get('size', null, waRequest::TYPE_STRING); $album = null; $photo_model = new photosPhotoModel(); $photo = $photo_model->getById($photo_id); if (!$photo) { throw new waException(_w("Unknown photo")); } $photo['frontend_link'] = photosFrontendPhoto::getLink($photo, $album); $sizes = $this->getConfig()->getSizes(); $contexts = array(); foreach ($sizes as $sz) { $contexts[$sz]['html'] = photosPhoto::getEmbedImgHtml($photo, $sz); $contexts[$sz]['url'] = photosPhoto::getPhotoUrl($photo, $sz, true); } if (!$size || !isset($contexts[$size])) { $size = $sizes[0]; } $domains = photosPhoto::getDomains(null, $photo); if (count($domains) <= 1) { $domains = array(); } $this->view->assign('photo', $photo); $this->view->assign('sizes', $sizes); $this->view->assign('size', $size); $this->view->assign('contexts', $contexts); $this->view->assign('original_domain', wa()->getRootUrl(true)); $this->view->assign('domains', $domains); }
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 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; }
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); } }
protected function workupPhotos(&$photos) { $renderer = new photosPhotoHtmlRenderer($this->getTheme()); $photo_model = new photosPhotoModel(); // parent of current photo (that stacked, i.e. in stack) $parent_id = null; if ($this->photo_url) { $stacked_photo = $photo_model->getByField('url', $this->photo_url); if (!$stacked_photo) { throw new waException(_w('Page not found', 404)); } $parent_id = $photo_model->getStackParentId($stacked_photo); } // During going over all photos we also look if some photo is a parent of current stacked photo foreach ($photos as &$photo) { $photo['stack_nav'] = ''; $stack = (array) $photo_model->getStack($photo['id'], array('tags' => true)); if ($stack) { foreach ($stack as &$item) { $item['thumb_custom'] = array('url' => photosPhoto::getPhotoUrlTemplate($item)); $item['full_url'] = photosFrontendAlbum::getLink($this->album) . $item['url'] . '/'; } unset($item); // iterable photo is parent of current stacked photo - replace if ($parent_id == $photo['id']) { $photo = $stacked_photo; $photo['full_url'] = photosFrontendAlbum::getLink($this->album) . $photo['url'] . '/'; $photo['stack_nav'] = $renderer->getStackNavigationPanel($stack, $photo); } else { $photo['stack_nav'] = $renderer->getStackNavigationPanel($stack, $photo); } } $photo['frontend_link'] = photosFrontendPhoto::getLink($photo, array('full_url' => $this->album_url)); } unset($photo); }
public function execute() { $photo_id = waRequest::post('photo_id', array(), waRequest::TYPE_ARRAY_INT); $status = waRequest::post('status', 0, waRequest::TYPE_INT); $groups = waRequest::post('groups', array(), waRequest::TYPE_ARRAY_INT); if (!$groups) { $status = -1; // only author have access to this photo $groups = array(-$this->getUser()->getId()); } // necessary when manage access rights for one photo. When in one photo extra info is needed in response $is_one_photo = waRequest::post('one_photo', 0, waRequest::TYPE_INT); // necessary only when manage access rights for several photos $prev_allowed_photo_id = waRequest::post('allowed_photo_id', array(), waRequest::TYPE_ARRAY_INT); $prev_denied_photo_id = waRequest::post('denied_photo_id', array(), waRequest::TYPE_ARRAY_INT); $this->photo_model = new photosPhotoModel(); $this->photo_rights_model = new photosPhotoRightsModel(); $allowed_photo_id = $this->photo_rights_model->filterAllowedPhotoIds($photo_id, true); $denied_photo_id = array_diff($photo_id, $allowed_photo_id); $this->photo_model->updateAccess($allowed_photo_id, $status, $groups); // leave only id of parents $denied_parent_id = array(); if ($denied_photo_id) { foreach ($this->photo_model->getByField('id', $denied_photo_id, 'id') as $photo) { $denied_parent_id[] = $photo['parent_id'] > 0 ? $photo['parent_id'] : $photo['id']; } } $denied_photo_id = array_values(array_unique(array_merge($prev_denied_photo_id, $denied_parent_id))); $this->response['denied_photo_id'] = $denied_photo_id; // leave only id of parents $allowed_parent_id = array(); if ($allowed_photo_id) { foreach ($this->photo_model->getByField('id', $allowed_photo_id, 'id') as $photo) { $allowed_parent_id[] = $photo['parent_id'] > 0 ? $photo['parent_id'] : $photo['id']; } } $allowed_photo_id = array_values(array_unique(array_merge($prev_allowed_photo_id, $allowed_parent_id))); $this->response['allowed_photo_id'] = $allowed_photo_id; $all_photos_length = waRequest::post('photos_length', 0, waRequest::TYPE_INT); if (!$all_photos_length) { $all_photos_length = count($photo_id); } $denied_photos_length = count($denied_photo_id); if ($denied_photos_length > 0 && $all_photos_length > 0) { $this->response['alert_msg'] = photosPhoto::sprintf_wplural("The operation was not performed to %d photo (%%s)", "The operation was not performed to %d photos (%%s)", $denied_photos_length, _w("out of %d selected", "out of %d selected", $all_photos_length)) . ', ' . _w("because you don't have sufficient access rights") . '.'; } // if one photo send extra info for update cache and widget if ($is_one_photo && $allowed_photo_id) { $frontend_link_template = photosFrontendPhoto::getLink(array('url' => '%url%')); if (count($photo_id) > 1) { // stack $stack = $this->photo_model->getStack($photo_id[0]); foreach ($stack as &$photo) { $photo = $this->workup($photo); } unset($photo); $this->response['stack'] = array_values($stack); } else { // just photo $photo_id = $photo_id[0]; $photo = $this->photo_model->getById($photo_id); $photo = $this->workup($photo); $this->response['photo'] = $photo; } $this->response['frontend_link_template'] = $frontend_link_template; } }
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; }
/** * Returns photos in this collection. * * @param string|array $fields * @param int $offset * @param int $limit * @param bool $escape * @return array [photo_id][field] = field value in appropriate field format * @throws waException */ public function getPhotos($fields = "*,thumb,tags", $offset = 0, $limit = 50, $escape = true) { $sql = $this->getSQL(); $sql = "SELECT " . ($this->joins ? 'DISTINCT ' : '') . $this->getFields($fields) . " " . $sql; //$sql .= $this->getGroupBy(); $sql .= $this->getOrderBy(); $sql .= " LIMIT " . ($offset ? $offset . ',' : '') . (int) $limit; $data = $this->getModel()->query($sql)->fetchAll('id'); if (!$data) { return array(); } if ($this->post_fields) { $ids = array_keys($data); foreach ($this->post_fields as $table => $fields) { if ($table == '_internal') { foreach ($fields as $i => $f) { if ($f == 'thumb' || substr($f, 0, 6) == 'thumb_') { if ($f == 'thumb') { $size = photosPhoto::getThumbPhotoSize(); } else { $size = substr($f, 6); switch ($size) { case 'crop': $size = photosPhoto::getCropPhotoSize(); break; case 'middle': $size = photosPhoto::getMiddlePhotoSize(); break; case 'big': $size = photosPhoto::getBigPhotoSize(); break; case 'mobile': $size = photosPhoto::getMobilePhotoSize(); break; } } foreach ($data as $id => &$v) { $v[$f] = photosPhoto::getThumbInfo($v, $size); } unset($v); } if ($f == 'frontend_link') { foreach ($data as $id => &$v) { $v['frontend_link'] = photosFrontendPhoto::getLink(array('url' => $this->frontend_base_url ? $this->frontend_base_url . '/' . $v['url'] : $v['url'])); } unset($v); } if ($f == 'edit_rights') { $photo_model_rights = new photosPhotoRightsModel(); $photo_ids = array(); foreach ($data as $id => &$v) { $photo_ids[] = $id; $v['edit_rights'] = false; } unset($v); foreach ($photo_model_rights->filterAllowedPhotoIds($photo_ids, true) as $photo_id) { $data[$photo_id]['edit_rights'] = true; } } } } elseif ($table == 'tags') { $model = $this->getModel('photo_tags'); $tags = $model->getTags($ids); foreach ($data as $id => &$v) { $v['tags'] = isset($tags[$id]) ? $tags[$id] : array(); } unset($v); } } } if ($escape) { self::escapePhotoFields($data); } return $data; }
public function preparePhotosFrontend(&$photos) { foreach ($photos as &$p) { if (!isset($p['frontend_link'])) { $p['frontend_link'] = photosFrontendPhoto::getLink(array('url' => 'myphotos/' . $p['url'])); } } unset($p); }
public function execute() { $id = waRequest::post('id', 0, waRequest::TYPE_INT); $in_stack = waRequest::post('in_stack', 0, waRequest::TYPE_INT); $hash = waRequest::post('hash', null, waRequest::TYPE_STRING_TRIM); $hash = urldecode($hash); // get photo $this->photo_model = new photosPhotoModel(); $this->photo = $this->photo_model->getById($id); if (!$this->photo) { throw new waException(_w("Photo doesn't exists"), 404); } $photo_rights_model = new photosPhotoRightsModel(); if (!$photo_rights_model->checkRights($this->photo)) { throw new waRightsException(_w("You don't have sufficient access rights")); } $this->photo['name_not_escaped'] = $this->photo['name']; $this->photo = photosPhoto::escapeFields($this->photo); $this->photo['upload_datetime_formatted'] = waDateTime::format('humandate', $this->photo['upload_datetime']); $this->photo['upload_timestamp'] = strtotime($this->photo['upload_datetime']); $this->photo['edit_rights'] = $photo_rights_model->checkRights($this->photo, true); $this->photo['private_url'] = photosPhotoModel::getPrivateUrl($this->photo); $this->photo['thumb'] = photosPhoto::getThumbInfo($this->photo, photosPhoto::getThumbPhotoSize()); $this->photo['thumb_big'] = photosPhoto::getThumbInfo($this->photo, photosPhoto::getBigPhotoSize()); $this->photo['thumb_middle'] = photosPhoto::getThumbInfo($this->photo, photosPhoto::getMiddlePhotoSize()); $original_photo_path = photosPhoto::getOriginalPhotoPath($this->photo); if (wa('photos')->getConfig()->getOption('save_original') && file_exists($original_photo_path)) { $this->photo['original_exists'] = true; } else { $this->photo['original_exists'] = false; } $photo_tags_model = new photosPhotoTagsModel(); $tags = $photo_tags_model->getTags($id); $this->photo['tags'] = $tags; $this->response['photo'] = $this->photo; // get stack if it's possible if (!$in_stack && ($stack = $this->photo_model->getStack($id, array('thumb' => true, 'thumb_crop' => true, 'thumb_big' => true, 'thumb_middle' => true)))) { $this->response['stack'] = $stack; } // get albums $album_photos_model = new photosAlbumPhotosModel(); $albums = $album_photos_model->getAlbums($id, array('id', 'name')); $this->response['albums'] = isset($albums[$id]) ? array_values($albums[$id]) : array(); // exif info $exif_model = new photosPhotoExifModel(); $exif = $exif_model->getByPhoto($this->photo['id']); if (isset($exif['DateTimeOriginal'])) { $exif['DateTimeOriginal'] = waDateTime::format('humandatetime', $exif['DateTimeOriginal'], date_default_timezone_get()); } $this->response['exif'] = $exif; // get author $contact = new waContact($this->photo['contact_id']); $this->response['author'] = array('id' => $contact['id'], 'name' => photosPhoto::escape($contact['name']), 'photo_url' => $contact->getPhoto(photosPhoto::AUTHOR_PHOTO_SIZE), 'backend_url' => $this->getConfig()->getBackendUrl(true) . 'contacts/#/contact/' . $contact['id']); // for making inline-editable widget $this->response['frontend_link_template'] = photosFrontendPhoto::getLink(array('url' => '%url%')); $hooks = array(); $parent_id = $this->photo_model->getStackParentId($this->photo); $photo_id = $parent_id ? $parent_id : $id; /** * Extend photo page * Add extra widget(s) * @event backend_photo * @return array[string][string]string $return[%plugin_id%]['bottom'] In bottom, under photo any widget */ $hooks['backend_photo'] = wa()->event('backend_photo', $photo_id); $this->response['hooks'] = $hooks; if ($hash !== null) { $collection = new photosCollection($hash); if (strstr($hash, 'rate>0') !== false) { $collection->orderBy('p.rate DESC, p.id'); } $this->response['photo_stream'] = $this->getPhotoStream($collection); if ($collection->getAlbum()) { $this->response['album'] = $collection->getAlbum(); } } }