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() { $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() { $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() { $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); $this->view->assign('full_base_url', photosFrontendAlbum::getLink()); }
/** * * 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; } }
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 display($view_type = 'backend') { $result = $view_type == 'backend' ? '<li class="dr ' . $this->getClass() . '" rel="' . $this->data['id'] . '"><span class="count">' . (!is_null($this->data['count']) ? $this->data['count'] : '') . '</span>' : '<li>'; if ($this->childs) { $result .= $view_type == 'backend' ? '<i class="icon16 darr overhanging collapse-handler" id="album-' . $this->data['id'] . '-handler"></i>' : ''; } $result .= $view_type == 'backend' ? '<a href="' . $this->getHash() . '"><i class="icon16 ' . $this->getIcon() . '"></i>' . photosPhoto::escape($this->data['name']) . ' ' . $this->getStatusIcon() . ' <strong class="small highlighted count-new">' . (!empty($this->data['count_new']) ? '+' . $this->data['count_new'] : '') . '</strong></a>' : '<a href="' . photosFrontendAlbum::getLink($this->data) . '">' . photosPhoto::escape($this->data['name']) . '</a>'; if ($this->childs) { $result .= $view_type == 'backend' ? '<ul class="menu-v with-icons"><li class="drag-newposition"></li>' : '<ul class="menu-v">'; foreach ($this->childs as $e) { $result .= $e->display($view_type); } $result .= '</ul>'; } $result .= $view_type == 'backend' ? '</li><li class="drag-newposition"></li>' : '</li>'; return $result; }
public function getAlbums($albums) { $html = ''; $i = 0; foreach ($albums as $album) { $html .= ($i++ > 0 ? ', ' : '') . '<a href="' . photosFrontendAlbum::getLink($album) . '">' . photosPhoto::escape($album['name']) . '</a>'; } return $html; }
static function getUrl($post, $type = 'post') { if ($type == 'post' && !empty($post['album_id']) && $post['album_link_type'] == 'photos') { wa('photos'); if (empty($post['album']['full_url'])) { $album_full_url = photosCollection::frontendAlbumHashToUrl('album/' . $post['album_id']); } else { $album_full_url = $post['album']['full_url']; } $url = photosFrontendAlbum::getLink($album_full_url); if (wa()->getEnv() == 'backend') { return array($url); } else { return $url; } } static $blog_urls = array(); $params = array(); $fields = array('blog_url', 'year', 'month', 'day'); foreach ($fields as $field) { if (isset($post[$field])) { $params[$field] = $post[$field]; } } if (isset($post['id']) && $post['id'] && isset($post['url']) && $post['url']) { $params['post_url'] = $post['url']; } elseif ($type != 'timeline') { $params['post_url'] = '%post_url%'; } $blog_id = null; if ($type != 'author') { if (isset($post['datetime']) && $post['datetime'] && ($time = date_parse($post['datetime']))) { $params['post_year'] = sprintf('%04d', $time['year']); $params['post_month'] = sprintf('%02d', $time['month']); $params['post_day'] = sprintf('%02d', $time['day']); } elseif ($type != 'timeline') { $params['post_year'] = '%year%'; $params['post_month'] = '%month%'; $params['post_day'] = '%day%'; } if (!isset($params['blog_url']) && isset($post['blog_id'])) { $blog_id = $post['blog_id']; if (!isset($blog_urls[$blog_id])) { $blog_urls[$blog_id] = false; $blog_model = new blogBlogModel(); if ($blog_data = $blog_model->getById($blog_id)) { if ($blog_data['status'] == blogBlogModel::STATUS_PUBLIC) { if (strlen($blog_data['url'])) { $blog_urls[$blog_id] = $blog_data['url']; } else { $blog_urls[$blog_id] = $blog_id; } } } } $params['blog_url'] = $blog_urls[$blog_id]; } elseif (isset($params['blog_url']) && isset($post['blog_id'])) { $blog_id = $post['blog_id']; } } $route = false; if (!isset($params['blog_url']) || $params['blog_url'] !== false) { switch ($type) { case 'comment': $route = 'blog/frontend/comment'; break; case 'timeline': $route = 'blog/frontend'; break; case 'author': if ($params['contact_id'] = $post['contact_id']) { $route = 'blog/frontend'; } break; case 'post': default: $route = 'blog/frontend/post'; break; } } return $route ? blogHelper::getUrl($blog_id, $route, $params) : array(); }
/** * @param string $hash * @param boolean $check_album * @return string */ public static function getFrontendLink($hash = '', $check_album = true) { if ($check_album) { $url = self::frontendAlbumHashToUrl($hash); if ($url) { $link = photosFrontendAlbum::getLink($url); return $link; } } // another type of collection if (substr($hash, 0, 1) == '#') { $hash = substr($hash, 1); } $hash = trim($hash, '/'); $hash = explode('/', $hash); $params = array(); if (count($hash) >= 2) { $params[$hash[0]] = $hash[1]; } else { if (count($hash) == 1) { $params[$hash[0]] = $hash[0]; } } $link = wa()->getRouteUrl('photos/frontend', $params, true); return $link ? rtrim($link, '/') . '/' : null; }
/** * Get "childcrumbs" (sub-albums) for album (list of childrens) * @param int $id * @param bool $escape * @return array of items array('name' => '..', 'full_url' => '..') */ public function getChildcrumbs($id, $escape = false) { $sql = "SELECT id, full_url, name, note FROM {$this->table} WHERE parent_id = i:id AND status = 1"; $result = $this->query($sql, array('id' => $id)); $childcrumbs = array(); foreach ($result as $album) { $childcrumbs[] = array('id' => $album['id'], 'name' => $escape ? photosPhoto::escape($album['name']) : $album['name'], 'full_url' => photosFrontendAlbum::getLink($album), 'note' => $escape ? photosPhoto::escape($album['note']) : $album['note']); } return $childcrumbs; }
public function childAlbums($parent_album_id = 0) { $album_model = new photosAlbumModel(); $child_albums = $album_model->getChildren($parent_album_id); foreach ($child_albums as $i => &$ca) { if (!$ca['status']) { unset($child_albums[$i]); continue; } $ca['full_url'] = photosFrontendAlbum::getLink($ca); } unset($ca); $album_model->keyPhotos($child_albums); foreach ($child_albums as &$ca) { $ca = photosFrontendAlbum::escapeFields($ca); } unset($ca); return $child_albums; }
public function execute() { $post_id = waRequest::get('id', null, waRequest::TYPE_INT); $blog_model = new blogBlogModel(); $blogs = $blog_model->getAvailable(); if (!$blogs) { $this->setTemplate('BlogNotFound'); return; } $blogs = $blog_model->prepareView($blogs); $post_model = new blogPostModel(); if ($post_id) { // edit post $post = $post_model->getById($post_id); if (!$post) { throw new waException(_w('Post not found'), 404); } //check rights if (blogHelper::checkRights($post['blog_id']) < blogRightConfig::RIGHT_FULL && $post['contact_id'] != $this->getUser()->getId()) { throw new waRightsException(_w('Access denied')); } $post['datetime'] = $post['datetime'] >= 1971 ? $post['datetime'] : ''; $blog_id = $post['blog_id']; $blog = $blogs[$blog_id]; $title = trim(sprintf(_w('Editing post %s'), $post['title'])); } else { // add post $date = waRequest::get('date', ''); $blog = $this->getAllowedBlog($blogs, wa()->getStorage()->read('blog_last_id')); if (!$blog) { throw new waRightsException(_w('Access denied')); } $blog_id = $blog['id']; $post = array('status' => $date ? blogPostModel::STATUS_DEADLINE : blogPostModel::STATUS_DRAFT, 'title' => $this->getRequest()->post('title', '', waRequest::TYPE_STRING_TRIM), 'text' => $this->getRequest()->post('text', '', waRequest::TYPE_STRING_TRIM), 'continued_text' => null, 'categories' => array(), 'contact_id' => wa()->getUser()->getId(), 'blog_id' => $blog_id) + $post_model->getEmptyRow(); $title = _w('Adding new post'); } // Album tree $albums = array(); $photos_frontend_url = null; if (blogPhotosBridge::isAvailable()) { if ($post['album_link_type'] != 'photos') { $post['album_link_type'] = 'blog'; } wa('photos'); $album_model = new photosAlbumModel(); $albums = $album_model->getAlbums(); foreach ($albums as &$a) { if ($a['status'] == 1) { $a['frontend_link'] = photosFrontendAlbum::getLink($a); } else { $a['frontend_link'] = ''; } } unset($a); } // Frontend URLs for this post $album_link_type = $post['album_link_type']; $post['album_link_type'] = 'blog'; $all_links = blogPostModel::getPureUrls($post); $post['album_link_type'] = $album_link_type; $post['other_links'] = $all_links; $post['link'] = array_shift($post['other_links']); $post['remaining_time'] = null; if ($post['status'] == blogPostModel::STATUS_SCHEDULED && $post['datetime']) { $post['remaining_time'] = $this->calculateRemainingTime($post['datetime']); } if ($blog['rights'] >= blogRightConfig::RIGHT_FULL) { $users = blogHelper::getAuthors($post['blog_id']); } else { $user = $this->getUser(); $users = array($user->getId() => $user->getName()); } // preview hash for all type of drafts if ($post['status'] != blogPostModel::STATUS_PUBLISHED) { $options = array('contact_id' => $post['contact_id'], 'blog_id' => $blog_id, 'post_id' => $post['id'], 'user_id' => wa()->getUser()->getId()); $preview_hash = blogPostModel::getPreviewHash($options); $this->view->assign('preview_hash', base64_encode($preview_hash . $options['user_id'])); } $this->view->assign('albums', $albums); $this->view->assign('no_settlements', !wa()->getRouteUrl('blog/')); $this->view->assign('params', $this->getPostParams($post['id'])); $this->view->assign('blog', $blog); $this->view->assign('users', $users); $this->view->assign('blogs', $blogs); $allow_change_blog = 0; foreach ($blogs as $blog_item) { if ($blog_item['rights'] >= blogRightConfig::RIGHT_READ_WRITE) { ++$allow_change_blog; } } $this->view->assign('allow_change_blog', $allow_change_blog); $this->view->assign('post_id', $post_id); $this->view->assign('datetime_timezone', waDateTime::date("T", null, wa()->getUser()->getTimezone())); /** * Backend post edit page * UI hook allow extends post edit page * @event backend_post_edit * @param array[string]mixed $post * @param array[string]int $post['id'] * @param array[string]int $post['blog_id'] * @return array[string][string]string $return[%plugin_id%]['sidebar'] Plugin sidebar html output * @return array[string][string]string $return[%plugin_id%]['toolbar'] Plugin toolbar html output * @return array[string][string]string $return[%plugin_id%]['editor_tab'] Plugin editor tab html output */ $this->view->assign('backend_post_edit', wa()->event('backend_post_edit', $post, array('sidebar', 'toolbar', 'editor_tab'))); $app_settings = new waAppSettingsModel(); $show_comments = $app_settings->get($this->getApp(), 'show_comments', true); $this->view->assign('show_comments', $show_comments); $this->view->assign('post', $post); /** * @deprecated * For backward compatibility reason */ $this->view->assign('cron_schedule_time', waSystem::getSetting('cron_schedule', 0, 'blog')); $this->view->assign('last_schedule_cron_time', waSystem::getSetting('last_schedule_cron_time', 0, 'blog')); $this->view->assign('cron_command', 'php ' . wa()->getConfig()->getRootPath() . '/cli.php blog schedule'); $this->setLayout(new blogDefaultLayout()); $this->getResponse()->setTitle($title); }
/** * Get breadcrumbs for album (list of parents) * @param int $id * @param boolean $escape * @param boolean $use_itself * @return array of items array('name' => '..', 'full_url' => '..') */ public function getBreadcrumbs($album_id, $escape = false, $use_itself = false) { $breadcrumbs = array(); while ($album_id) { $sql = "SELECT id, full_url, parent_id, name, status FROM {$this->table} WHERE id = i:id AND status = 1"; $album = $this->query($sql, array('id' => $album_id))->fetch(); if ($album) { $url = photosFrontendAlbum::getLink($album); $breadcrumbs[] = array('album_id' => $album['id'], 'name' => $escape ? photosPhoto::escape($album['name']) : $album['name'], 'full_url' => $url, 'url' => $url, 'status' => $album['status']); $album_id = $album['parent_id']; } else { $album_id = null; } } $breadcrumbs = array_reverse($breadcrumbs); if (!$use_itself) { array_pop($breadcrumbs); } return $breadcrumbs; }