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() { $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); } }
/** * Translate frontend album url to hash looks like 'album/<album_id>[:<hash>]'. * Take into account private hash * * @param string $album_url full url or string looks like album:<hash> * @param array &$album If $album_url is path to real album than album will be retrieved to this parameter * @return string $hash Hash of collection */ public static function frontendAlbumUrlToHash($album_url, &$album = null) { $hash = ''; if ($album_url) { $album_model = new photosAlbumModel(); if (wa()->getEnv() == 'frontend') { $album = $album_model->getByField(array('full_url' => $album_url, 'status' => 1)); } else { $album = $album_model->getByField('full_url', $full_url); } if (!$album) { $parts = explode(':', $album_url); if (count($parts) == 2 && $parts[0] == 'album') { $full_private_hash = $parts[1]; $private_hash = substr_replace($full_private_hash, '', 16, -16); $album = $album_model->getByField('hash', $private_hash); } } if ($album) { // album collection $album_id = $album['id']; $hash = 'album/' . $album_id . (isset($full_private_hash) ? ':' . $full_private_hash : ''); } else { // other kind of collection $hash = $album_url; } } return $hash; }