public function random($item_id) { $item = ORM::factory("item", $item_id); access::required("view", $item); item::set_display_context_callback("Albums_Controller::get_display_context"); url::redirect($item->abs_url()); }
public function index() { $page_size = module::get_var("gallery", "page_size", 9); $q = Input::instance()->get("q"); $q_with_more_terms = search::add_query_terms($q); $show = Input::instance()->get("show"); if ($show) { $child = ORM::factory("item", $show); $index = search::get_position($child, $q_with_more_terms); if ($index) { $page = ceil($index / $page_size); url::redirect(url::abs_site("search?q=" . urlencode($q) . ($page == 1 ? "" : "&page={$page}"))); } } $page = Input::instance()->get("page", 1); // Make sure that the page references a valid offset if ($page < 1) { $page = 1; } $offset = ($page - 1) * $page_size; list($count, $result) = search::search($q_with_more_terms, $page_size, $offset); $title = t("Search: %q", array("q" => $q_with_more_terms)); $max_pages = max(ceil($count / $page_size), 1); $template = new Theme_View("page.html", "collection", "search"); $root = item::root(); $template->set_global(array("page" => $page, "max_pages" => $max_pages, "page_size" => $page_size, "breadcrumbs" => array(Breadcrumb::instance($root->title, $root->url())->set_first(), Breadcrumb::instance($q, url::abs_site("search?q=" . urlencode($q)))->set_last()), "children_count" => $count)); $template->content = new View("search.html"); $template->content->items = $result; $template->content->q = $q; print $template; item::set_display_context_callback("Search_Controller::get_display_context", $title, $q_with_more_terms, $q); }
private function _show($album) { $page_size = module::get_var("gallery", "page_size", 9); $album_defn = unserialize(module::get_var("dynamic", $album)); $input = Input::instance(); $show = $input->get("show"); if ($show) { $child = ORM::factory("item", $show); $index = dynamic::get_position($album_defn, $child); if ($index) { $page = ceil($index / $page_size); url::redirect("dynamic/{$album}" . ($page == 1 ? "" : "?page={$page}")); } } else { $page = (int) $input->get("page", "1"); } $children_count = dynamic::get_display_count($album_defn); $offset = ($page - 1) * $page_size; $max_pages = max(ceil($children_count / $page_size), 1); // Make sure that the page references a valid offset if ($page < 1) { url::redirect(url::merge(array("page" => 1))); } else { if ($page > $max_pages) { url::redirect(url::merge(array("page" => $max_pages))); } } $root = item::root(); $template = new Theme_View("page.html", "collection", "dynamic"); $template->set_global(array("page" => $page, "max_pages" => $max_pages, "page_size" => $page_size, "children" => dynamic::items($album_defn->key_field, $page_size, $offset), "breadcrumbs" => array(Breadcrumb::instance($root->title, $root->url())->set_first(), Breadcrumb::instance($album_defn->title, url::site("dynamic/{$album}"))->set_last()), "children_count" => $children_count)); $template->content = new View("dynamic.html"); $template->content->title = t($album_defn->title); print $template; item::set_display_context_callback("Dynamic_Controller::get_display_context", $album_defn, $album); }
public function item($item_id) { // Make sure the context callback is set to album when linking to photos from map pages. $item = ORM::factory("item", $item_id); access::required("view", $item); item::set_display_context_callback("Albums_Controller::get_display_context"); url::redirect($item->abs_url()); }
public function show($album) { if (!is_object($album)) { // show() must be public because we route to it in url::parse_url(), so make // sure that we're actually receiving an object throw new Kohana_404_Exception(); } access::required("view", $album); $page_size = module::get_var("gallery", "page_size", 9); $input = Input::instance(); $show = $input->get("show"); if ($show) { $child = ORM::factory("item", $show); $index = item::get_position($child); if ($index) { $page = ceil($index / $page_size); if ($page == 1) { url::redirect($album->abs_url()); } else { url::redirect($album->abs_url("page={$page}")); } } } $page = $input->get("page", "1"); $children_count = $album->viewable()->children_count(); $offset = ($page - 1) * $page_size; $max_pages = max(ceil($children_count / $page_size), 1); // Make sure that the page references a valid offset if ($page < 1) { url::redirect($album->abs_url()); } else { if ($page > $max_pages) { url::redirect($album->abs_url("page={$max_pages}")); } } $five_items = $album->viewable()->children(5, 0); $template = new Theme_View("page.html", "collection", "album"); $template->set_global(array("page" => $page, "page_title" => null, "max_pages" => $max_pages, "page_size" => $page_size, "item" => $album, "fiveitems" => $five_items, "children" => $album->viewable()->children($page_size, $offset), "parents" => $album->parents()->as_array(), "breadcrumbs" => Breadcrumb::array_from_item_parents($album), "children_count" => $children_count)); $template->content = new View("album.html"); $album->increment_view_count(); print $template; item::set_display_context_callback("Albums_Controller::get_display_context"); }
public function __call($function, $args) { $tag_id = $function; $tag = ORM::factory("tag")->where("id", "=", $tag_id)->find(); $page_size = module::get_var("gallery", "page_size", 9); $input = Input::instance(); $show = $input->get("show"); if ($show) { $child = ORM::factory("item", $show); $index = tag::get_position($tag, $child); if ($index) { $page = ceil($index / $page_size); $uri = "tag/{$tag_id}/" . urlencode($tag->name); url::redirect($uri . ($page == 1 ? "" : "?page={$page}")); } } else { $page = (int) $input->get("page", "1"); } $children_count = $tag->items_count(); $offset = ($page - 1) * $page_size; $max_pages = max(ceil($children_count / $page_size), 1); // Make sure that the page references a valid offset if ($page < 1) { url::redirect(url::merge(array("page" => 1))); } else { if ($page > $max_pages) { url::redirect(url::merge(array("page" => $max_pages))); } } $root = item::root(); $template = new Theme_View("page.html", "collection", "tag"); $template->set_global(array("page" => $page, "max_pages" => $max_pages, "page_size" => $page_size, "tag" => $tag, "children" => $tag->items($page_size, $offset), "breadcrumbs" => array(Breadcrumb::instance($root->title, $root->url())->set_first(), Breadcrumb::instance(t("Tag: %tag_name", array("tag_name" => $tag->name)), $tag->url())->set_last()), "children_count" => $children_count)); $template->content = new View("dynamic.html"); $template->content->title = t("Tag: %tag_name", array("tag_name" => $tag->name)); print $template; item::set_display_context_callback("Tag_Controller::get_display_context", $tag->id); }
public function show($item_id, $tag_id, $album_id) { // This function used to be responsible for displaying photos. // As of Gallery 3.0.3, it is no longer needed, now it just // redirects to the photo's primary URL to avoid breaking older links. item::set_display_context_callback("tag_albums_Controller::get_display_context", $tag_id, $album_id); $item = ORM::factory("item", $item_id); url::redirect(url::abs_site("{$item->type}s/{$item->id}")); }
public function month($display_year, $display_user, $display_month) { // Display all images for the specified month. // Set up default search conditions for retrieving all photos from the specified month. $where = array(array("type", "!=", "album")); if ($display_user != "-1") { $where[] = array("owner_id", "=", $display_user); } $where[] = array("captured", ">=", mktime(0, 0, 0, $display_month, 1, $display_year)); $where[] = array("captured", "<", mktime(0, 0, 0, $display_month + 1, 1, $display_year)); // Figure out the total number of photos to display. $day_count = calendarview::get_items_count($where); // Figure out paging stuff. $page_size = module::get_var("gallery", "page_size", 9); $page = (int) Input::instance()->get("page", "1"); $offset = ($page - 1) * $page_size; $max_pages = max(ceil($day_count / $page_size), 1); // Make sure that the page references a valid offset if ($page < 1 || $page > $max_pages) { throw new Kohana_404_Exception(); } // Figure out which photos go on this page. $children = calendarview::get_items($page_size, $offset, $where); // Create and display the page. $root = item::root(); $template = new Theme_View("page.html", "collection", "CalendarMonthView"); $template->set_global(array("page" => $page, "max_pages" => $max_pages, "page_size" => $page_size, "breadcrumbs" => array(Breadcrumb::instance($root->title, $root->url())->set_first(), Breadcrumb::instance($display_year, url::site("calendarview/calendar/" . $display_year . "/" . $display_user)), Breadcrumb::instance(t(date("F", mktime(0, 0, 0, $display_month, 1, $display_year))), url::site("calendarview/month/" . $display_year . "/" . $display_user . "/" . $display_month))->set_last()), "children" => $children, "children_count" => $day_count)); $template->page_title = t("Gallery :: Calendar"); $template->content = new View("dynamic.html"); $template->content->title = t("Photos From ") . t(date("F", mktime(0, 0, 0, $display_month, 1, $display_year))) . " " . date("Y", mktime(0, 0, 0, $display_month, 1, $display_year)); print $template; // Set up breadcrumbs for the photo pages to point back to the calendar month view. item::set_display_context_callback("CalendarView_Controller::get_display_month_context", $display_user, $display_year, $display_month); }
public function updates() { // Figure out how many items to display on each page. $page_size = module::get_var("gallery", "page_size", 9); // Figure out which page # the visitor is on and // don't allow the visitor to go below page 1. $page = Input::instance()->get("page", 1); if ($page < 1) { url::redirect("latestupdates/updates"); } // If this page was reached from a breadcrumb, figure out what page to load from the show id. $show = Input::instance()->get("show"); if ($show) { $child = ORM::factory("item", $show); $index = latestupdates_Controller::_get_position($child, "recent", 0); if ($index) { $page = ceil($index / $page_size); if ($page == 1) { url::redirect("latestupdates/updates"); } else { url::redirect("latestupdates/updates?page={$page}"); } } } // First item to display. $offset = ($page - 1) * $page_size; // Determine the total number of items, // for page numbering purposes. $count = latestupdates_Controller::items_count("recent", 0); // Figure out what the highest page number is. $max_pages = ceil($count / $page_size); // Don't let the visitor go past the last page. if ($max_pages && $page > $max_pages) { url::redirect("latestupdates/updates?page={$max_pages}"); } // Figure out which items to display on this page. $items = latestupdates_Controller::items("recent", 0, $page_size, $offset); // Set up the previous and next page buttons. if ($page > 1) { $previous_page = $page - 1; $view->previous_page_link = url::site("latestupdates/updates?page={$previous_page}"); } if ($page < $max_pages) { $next_page = $page + 1; $view->next_page_link = url::site("latestupdates/updates?page={$next_page}"); } // Set up and display the actual page. $root = item::root(); $template = new Theme_View("page.html", "collection", "LatestUpdates"); $template->page_title = t("Gallery :: Latest Updates"); $template->set_global(array("page" => $page, "max_pages" => $max_pages, "page_size" => $page_size, "children" => $items, "breadcrumbs" => array(Breadcrumb::instance($root->title, $root->url())->set_first(), Breadcrumb::instance(t("Recent Uploads"), url::site("latestupdates/updates"))->set_last()), "children_count" => $count)); $template->content = new View("dynamic.html"); $template->content->title = t("Recent Uploads"); // Display the page. print $template; // Set up the callback so links within the photo page will lead to photos within the virtual album // instead of the actual album. item::set_display_context_callback("latestupdates_Controller::get_display_context", "recent", 0); }
/** * Redirect Gallery 2 urls to their appropriate matching Gallery 3 url. * * We use mod_rewrite to create this path, so Gallery2 urls like this: * /gallery2/v/Family/Wedding.jpg.html * /gallery2/main.php?g2_view=core.ShowItem&g2_itemId=1234 * * Show up here like this: * /g2/map?path=v/Family/Wedding.jpg.html * /g2/map?g2_view=core.ShowItem&g2_itemId=1931 */ public function map() { $input = Input::instance(); $path = $input->get("path"); $id = $input->get("g2_itemId"); $view = $input->get("g2_view"); // Tags did not have mappings created, so we need to catch them first. However, if a g2_itemId was // passed, we'll want to show lookup the mapping anyway if ($path && 0 === strpos($path, "tag/") || $view == "tags.VirtualAlbum") { if (0 === strpos($path, "tag/")) { $tag_name = substr($path, 4); } if ($view == "tags.VirtualAlbum") { $tag_name = $input->get("g2_tagName"); } if (!$id) { url::redirect("tag_name/{$tag_name}", 301); } $tag = ORM::factory("tag")->where("name", "=", $tag_name)->find(); if ($tag->loaded()) { item::set_display_context_callback("Tag_Controller::get_display_context", $tag->id); // We want to show the item as part of the tag virtual album. Most of this code is below; we'll // change $path and $view to let it fall through $view = ""; $path = ""; } } if ($path && $path != 'index.php' && $path != 'main.php' || $id) { if ($id) { // Requests by id are either core.DownloadItem or core.ShowItem requests. Later versions of // Gallery 2 don't specify g2_view if it's the default (core.ShowItem). And in some cases // (bbcode, embedding) people are using the id style URLs although URL rewriting is enabled. $where = array(array("g2_id", "=", $id)); if ($view == "core.DownloadItem") { $where[] = array("resource_type", "IN", array("file", "resize", "thumbnail", "full")); } else { if ($view) { $where[] = array("g2_url", "LIKE", "%" . Database::escape_for_like("g2_view={$view}") . "%"); } } // else: Assuming that the first search hit is sufficiently good. } else { if ($path) { $where = array(array("g2_url", "IN", array($path, str_replace(" ", "+", $path)))); } else { throw new Kohana_404_Exception(); } } $g2_map = ORM::factory("g2_map")->merge_where($where)->find(); if (!$g2_map->loaded()) { throw new Kohana_404_Exception(); } $item = ORM::factory("item", $g2_map->g3_id); if (!$item->loaded()) { throw new Kohana_404_Exception(); } $resource_type = $g2_map->resource_type; } else { $item = item::root(); $resource_type = "album"; } access::required("view", $item); // Redirect the user to the new url switch ($resource_type) { case "thumbnail": url::redirect($item->thumb_url(true), 301); case "resize": url::redirect($item->resize_url(true), 301); case "file": case "full": url::redirect($item->file_url(true), 301); case "item": case "album": url::redirect($item->abs_url(), 301); case "group": case "user": default: throw new Kohana_404_Exception(); } }