Expand virtual album code to cover the rest of Latest Updates.
This commit is contained in:
parent
e1ef476c48
commit
26cd108cb7
@ -140,7 +140,7 @@ class latestupdates_Controller extends Controller {
|
|||||||
url::site("latestupdates/users/{$str_display_type}/{$user_id}"))->set_last()),
|
url::site("latestupdates/users/{$str_display_type}/{$user_id}"))->set_last()),
|
||||||
"children_count" => $count));
|
"children_count" => $count));
|
||||||
$template->content = new View("dynamic.html");
|
$template->content = new View("dynamic.html");
|
||||||
$template->content->title = t($str_page_title);
|
$template->content->title = $str_page_title;
|
||||||
|
|
||||||
// Display the page.
|
// Display the page.
|
||||||
print $template;
|
print $template;
|
||||||
@ -151,9 +151,183 @@ class latestupdates_Controller extends Controller {
|
|||||||
$str_display_type, $user_id);
|
$str_display_type, $user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function albums($id) {
|
||||||
|
// Figure out how many items to display on each page.
|
||||||
|
$page_size = module::get_var("gallery", "page_size", 9);
|
||||||
|
|
||||||
|
// Load the parent album.
|
||||||
|
$item = ORM::factory("item", $id);
|
||||||
|
|
||||||
|
// 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/albums/{$item->id}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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, "descendants", $item->id);
|
||||||
|
if ($index) {
|
||||||
|
$page = ceil($index / $page_size);
|
||||||
|
if ($page == 1) {
|
||||||
|
url::redirect("latestupdates/albums/{$item->id}");
|
||||||
|
} else {
|
||||||
|
url::redirect("latestupdates/albums/{$item->id}?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("descendants", $item->id);
|
||||||
|
|
||||||
|
// 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/albums/{$item->id}?page=$max_pages");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Figure out which items to display on this page.
|
||||||
|
$children = latestupdates_Controller::items("descendants", $item->id, $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/albums/{$item->id}?page={$previous_page}");
|
||||||
|
}
|
||||||
|
if ($page < $max_pages) {
|
||||||
|
$next_page = $page + 1;
|
||||||
|
$view->next_page_link = url::site("latestupdates/albums/{$item->id}?page={$next_page}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up breadcrumbs.
|
||||||
|
$breadcrumbs = array();
|
||||||
|
$counter = 0;
|
||||||
|
$breadcrumbs[] = Breadcrumb::instance(t("Recent Uploads"), url::site("latestupdates/albums/{$item->id}"))->set_last();
|
||||||
|
$parent_item = $item;
|
||||||
|
while ($parent_item->id != 1) {
|
||||||
|
$breadcrumbs[] = Breadcrumb::instance($parent_item->title, $parent_item->url());
|
||||||
|
$parent_item = ORM::factory("item", $parent_item->parent_id);
|
||||||
|
}
|
||||||
|
$breadcrumbs[] = Breadcrumb::instance($parent_item->title, $parent_item->url())->set_first();
|
||||||
|
$breadcrumbs = array_reverse($breadcrumbs, true);
|
||||||
|
|
||||||
|
// 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" => $children,
|
||||||
|
"breadcrumbs" => $breadcrumbs,
|
||||||
|
"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",
|
||||||
|
"descendants", $item->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
static function get_display_context($item, $str_display_type, $user_id) {
|
static function get_display_context($item, $str_display_type, $user_id) {
|
||||||
// Set up display elements on the photo page to link to the virtual album.
|
// Set up display elements on the photo page to link to the virtual album.
|
||||||
$current_user = ORM::factory("user", $user_id);
|
// Valid $str_display_type values are popular, recent, albums and descendants.
|
||||||
|
// $user_id can be set to "0" to search site wide.
|
||||||
|
// For "descendants", $user_id should be the album id #.
|
||||||
|
|
||||||
// Figure out page title.
|
// Figure out page title.
|
||||||
$str_page_title = "";
|
$str_page_title = "";
|
||||||
@ -161,6 +335,8 @@ class latestupdates_Controller extends Controller {
|
|||||||
$str_page_title = t("Recent Uploads");
|
$str_page_title = t("Recent Uploads");
|
||||||
} elseif ($str_display_type == "albums") {
|
} elseif ($str_display_type == "albums") {
|
||||||
$str_page_title = t("Recent Albums");
|
$str_page_title = t("Recent Albums");
|
||||||
|
} elseif ($str_display_type == "descendants") {
|
||||||
|
$str_page_title = t("Recent Uploads");
|
||||||
} else {
|
} else {
|
||||||
$str_page_title = t("Most Viewed");
|
$str_page_title = t("Most Viewed");
|
||||||
}
|
}
|
||||||
@ -180,43 +356,101 @@ class latestupdates_Controller extends Controller {
|
|||||||
// Figure out total number of items (excluding albums).
|
// Figure out total number of items (excluding albums).
|
||||||
$count = latestupdates_Controller::items_count($str_display_type, $user_id);
|
$count = latestupdates_Controller::items_count($str_display_type, $user_id);
|
||||||
|
|
||||||
// Return the display elements.
|
// Set up breadcrumbs.
|
||||||
$root = item::root();
|
$root = item::root();
|
||||||
|
$breadcrumbs = array();
|
||||||
|
if ($user_id == 0) {
|
||||||
|
$breadcrumbs[0] = Breadcrumb::instance($root->title, $root->url())->set_first();
|
||||||
|
$breadcrumbs[1] = Breadcrumb::instance($str_page_title,
|
||||||
|
url::site("latestupdates/updates?show={$item->id}"));
|
||||||
|
$breadcrumbs[2] = Breadcrumb::instance($item->title, $item->url())->set_last();
|
||||||
|
} else {
|
||||||
|
if ($str_display_type == "descendants") {
|
||||||
|
$counter = 0;
|
||||||
|
$breadcrumbs[] = Breadcrumb::instance($item->title, $item->url())->set_last();
|
||||||
|
$breadcrumbs[] = Breadcrumb::instance(t("Recent Uploads"), url::site("latestupdates/albums/{$user_id}?show={$item->id}"));
|
||||||
|
$parent_item = ORM::factory("item", $user_id);
|
||||||
|
while ($parent_item->id != 1) {
|
||||||
|
$breadcrumbs[] = Breadcrumb::instance($parent_item->title, $parent_item->url());
|
||||||
|
$parent_item = ORM::factory("item", $parent_item->parent_id);
|
||||||
|
}
|
||||||
|
$breadcrumbs[] = Breadcrumb::instance($parent_item->title, $parent_item->url())->set_first();
|
||||||
|
$breadcrumbs = array_reverse($breadcrumbs, true);
|
||||||
|
} else {
|
||||||
|
$current_user = ORM::factory("user", $user_id);
|
||||||
|
$breadcrumbs[0] = Breadcrumb::instance($root->title, $root->url())->set_first();
|
||||||
|
$breadcrumbs[1] = Breadcrumb::instance(t("User profile: %name", array("name" => $current_user->display_name())),
|
||||||
|
url::site("user_profile/show/{$user_id}"));
|
||||||
|
$breadcrumbs[2] = Breadcrumb::instance($str_page_title,
|
||||||
|
url::site("latestupdates/users/{$str_display_type}/{$user_id}?show={$item->id}"));
|
||||||
|
$breadcrumbs[3] = Breadcrumb::instance($item->title, $item->url())->set_last();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the display elements.
|
||||||
return array("position" => $position,
|
return array("position" => $position,
|
||||||
"previous_item" => $previous_item,
|
"previous_item" => $previous_item,
|
||||||
"next_item" => $next_item,
|
"next_item" => $next_item,
|
||||||
"sibling_count" => $count,
|
"sibling_count" => $count,
|
||||||
"breadcrumbs" => array(
|
"breadcrumbs" => $breadcrumbs
|
||||||
Breadcrumb::instance($root->title, $root->url())->set_first(),
|
|
||||||
Breadcrumb::instance(t("User profile: %name", array("name" => $current_user->display_name())),
|
|
||||||
url::site("user_profile/show/{$user_id}")),
|
|
||||||
Breadcrumb::instance($str_page_title,
|
|
||||||
url::site("latestupdates/users/{$str_display_type}/{$user_id}?show={$item->id}")),
|
|
||||||
Breadcrumb::instance($item->title, $item->url())->set_last())
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function items_count($str_display_type, $user_id) {
|
static function items_count($str_display_type, $user_id) {
|
||||||
// Figure out the total number of items.
|
// Figure out the total number of items.
|
||||||
|
// Valid $str_display_type values are popular, recent, albums and descendants.
|
||||||
|
// $user_id can be set to "0" to search site wide.
|
||||||
|
// For "descendants", $user_id should be the album id #.
|
||||||
|
|
||||||
|
// If $str_display_type is albums, then we only want albums.
|
||||||
|
// If it's not, then we want everything except albums.
|
||||||
if ($str_display_type == "albums") {
|
if ($str_display_type == "albums") {
|
||||||
|
// This is only used for user profiles, so we always want
|
||||||
|
// results from a specific user.
|
||||||
$count = ORM::factory("item")
|
$count = ORM::factory("item")
|
||||||
->viewable()
|
->viewable()
|
||||||
->where("type", "=", "album")
|
->where("type", "=", "album")
|
||||||
->where("owner_id", "=", $user_id)
|
->where("owner_id", "=", $user_id)
|
||||||
->count_all();
|
->count_all();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
// If $user_id is not 0 we only want results from a specific user,
|
||||||
|
// Or else we want results from any user.
|
||||||
|
if ($user_id == 0) {
|
||||||
|
$count = ORM::factory("item")
|
||||||
|
->viewable()
|
||||||
|
->where("type", "!=", "album")
|
||||||
|
->count_all();
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// If type is descendants, then user_id is actually an item id#.
|
||||||
|
if ($str_display_type == "descendants") {
|
||||||
|
$item = ORM::factory("item", $user_id);
|
||||||
|
$count = $item
|
||||||
|
->viewable()
|
||||||
|
->where("type", "!=", "album")
|
||||||
|
->order_by("created", "DESC")
|
||||||
|
->descendants_count();
|
||||||
|
} else {
|
||||||
$count = ORM::factory("item")
|
$count = ORM::factory("item")
|
||||||
->viewable()
|
->viewable()
|
||||||
->where("type", "!=", "album")
|
->where("type", "!=", "album")
|
||||||
->where("owner_id", "=", $user_id)
|
->where("owner_id", "=", $user_id)
|
||||||
->count_all();
|
->count_all();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $count;
|
return $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function items($str_display_type, $user_id, $limit=null, $offset=null) {
|
static function items($str_display_type, $user_id, $limit=null, $offset=null) {
|
||||||
// Query the database for a list of items to display in the virtual album.
|
// Query the database for a list of items to display in the virtual album.
|
||||||
|
// Valid $str_display_type values are popular, recent, albums and descendants.
|
||||||
|
// $user_id can be set to "0" to search site wide.
|
||||||
|
// For "descendants", $user_id should be the album id #.
|
||||||
|
|
||||||
|
// Figure out search parameters based on $str_display_type.
|
||||||
$str_where = array();
|
$str_where = array();
|
||||||
$str_orderby_field = "";
|
$str_orderby_field = "";
|
||||||
if ($str_display_type == "recent") {
|
if ($str_display_type == "recent") {
|
||||||
@ -230,6 +464,29 @@ class latestupdates_Controller extends Controller {
|
|||||||
$str_orderby_field = "view_count";
|
$str_orderby_field = "view_count";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Search the database for matching items.
|
||||||
|
|
||||||
|
// Searching for descendants of a parent album is significantly
|
||||||
|
// different from the other query types, so we're doing this one
|
||||||
|
// seperately.
|
||||||
|
if ($str_display_type == "descendants") {
|
||||||
|
$item = ORM::factory("item", $user_id);
|
||||||
|
return $item
|
||||||
|
->viewable()
|
||||||
|
->where("type", "!=", "album")
|
||||||
|
->order_by("created", "DESC")
|
||||||
|
->descendants($limit, $offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If $user_id is greater then 0, limit results
|
||||||
|
// to a specific user.
|
||||||
|
if ($user_id == 0) {
|
||||||
|
return ORM::factory("item")
|
||||||
|
->viewable()
|
||||||
|
->merge_where($str_where)
|
||||||
|
->order_by($str_orderby_field, "DESC")
|
||||||
|
->find_all($limit, $offset);
|
||||||
|
} else {
|
||||||
return ORM::factory("item")
|
return ORM::factory("item")
|
||||||
->viewable()
|
->viewable()
|
||||||
->merge_where($str_where)
|
->merge_where($str_where)
|
||||||
@ -237,9 +494,15 @@ class latestupdates_Controller extends Controller {
|
|||||||
->order_by($str_orderby_field, "DESC")
|
->order_by($str_orderby_field, "DESC")
|
||||||
->find_all($limit, $offset);
|
->find_all($limit, $offset);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function _get_position($item, $str_display_type, $user_id) {
|
private function _get_position($item, $str_display_type, $user_id) {
|
||||||
// Figure out the item's position within the virtual album.
|
// Figure out the item's position within the virtual album.
|
||||||
|
// Valid $str_display_type values are popular, recent, albums and descendants.
|
||||||
|
// $user_id can be set to "0" to search site wide.
|
||||||
|
// For "descendants", $user_id should be the album id #.
|
||||||
|
|
||||||
|
// Figure out search conditions.
|
||||||
$str_where = array();
|
$str_where = array();
|
||||||
$str_orderby_field = "";
|
$str_orderby_field = "";
|
||||||
if ($str_display_type == "recent") {
|
if ($str_display_type == "recent") {
|
||||||
@ -253,6 +516,26 @@ class latestupdates_Controller extends Controller {
|
|||||||
$str_orderby_field = "view_count";
|
$str_orderby_field = "view_count";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Count the number of records that have a higher orderby_field value then
|
||||||
|
// the item we're looking for.
|
||||||
|
$position = 0;
|
||||||
|
if ($user_id == 0) {
|
||||||
|
$position = ORM::factory("item")
|
||||||
|
->viewable()
|
||||||
|
->merge_where($str_where)
|
||||||
|
->where($str_orderby_field, ">", $item->$str_orderby_field)
|
||||||
|
->order_by($str_orderby_field, "DESC")
|
||||||
|
->count_all();
|
||||||
|
} else {
|
||||||
|
if ($str_display_type == "descendants") {
|
||||||
|
$album_item = ORM::factory("item", $user_id);
|
||||||
|
$position = $album_item
|
||||||
|
->viewable()
|
||||||
|
->where("type", "!=", "album")
|
||||||
|
->where("created", ">", $item->created)
|
||||||
|
->order_by("created", "DESC")
|
||||||
|
->descendants_count();
|
||||||
|
} else {
|
||||||
$position = ORM::factory("item")
|
$position = ORM::factory("item")
|
||||||
->viewable()
|
->viewable()
|
||||||
->where("owner_id", "=", $user_id)
|
->where("owner_id", "=", $user_id)
|
||||||
@ -260,142 +543,53 @@ class latestupdates_Controller extends Controller {
|
|||||||
->where($str_orderby_field, ">", $item->$str_orderby_field)
|
->where($str_orderby_field, ">", $item->$str_orderby_field)
|
||||||
->order_by($str_orderby_field, "DESC")
|
->order_by($str_orderby_field, "DESC")
|
||||||
->count_all();
|
->count_all();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach (ORM::factory("item")
|
// Set up a db query for all records with the same orderby field value
|
||||||
|
// as the item we're looking for.
|
||||||
|
$items = ORM::factory("item");
|
||||||
|
if ($user_id == 0) {
|
||||||
|
$items->viewable()
|
||||||
|
->merge_where($str_where)
|
||||||
|
->where($str_orderby_field, "=", $item->$str_orderby_field)
|
||||||
|
->order_by($str_orderby_field, "DESC");
|
||||||
|
} else {
|
||||||
|
if ($str_display_type == "descendants") {
|
||||||
|
$item_album = ORM::factory("item", $user_id);
|
||||||
|
$items = $item_album
|
||||||
->viewable()
|
->viewable()
|
||||||
|
->where("type", "!=", "album")
|
||||||
|
->where("created", "=", $item->created)
|
||||||
|
->order_by("created", "DESC");
|
||||||
|
} else {
|
||||||
|
$items->viewable()
|
||||||
->where("owner_id", "=", $user_id)
|
->where("owner_id", "=", $user_id)
|
||||||
->merge_where($str_where)
|
->merge_where($str_where)
|
||||||
->where($str_orderby_field, "=", $item->$str_orderby_field)
|
->where($str_orderby_field, "=", $item->$str_orderby_field)
|
||||||
->order_by($str_orderby_field, "DESC")
|
->order_by($str_orderby_field, "DESC");
|
||||||
->find_all() as $row) {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through each remaining match, increasing position by 1 each time
|
||||||
|
// until we find a match.
|
||||||
|
if ($str_display_type == "descendants") {
|
||||||
|
foreach ($items->descendants() as $row) {
|
||||||
$position++;
|
$position++;
|
||||||
if ($row->id == $item->id) {
|
if ($row->id == $item->id) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
foreach ($items->find_all() as $row) {
|
||||||
|
$position++;
|
||||||
|
if ($row->id == $item->id) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the result.
|
||||||
return $position;
|
return $position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function albums($id) {
|
|
||||||
// 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/albums/{$item->id}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// First item to display.
|
|
||||||
$offset = ($page - 1) * $page_size;
|
|
||||||
|
|
||||||
$item = ORM::factory("item", $id);
|
|
||||||
|
|
||||||
// Determine the total number of items,
|
|
||||||
// for page numbering purposes.
|
|
||||||
$count = $item
|
|
||||||
->viewable()
|
|
||||||
->where("type", "!=", "album")
|
|
||||||
->order_by("created", "DESC")
|
|
||||||
->descendants_count();
|
|
||||||
|
|
||||||
// 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/albums/{$item->id}?page=$max_pages");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Figure out which items to display on this page.
|
|
||||||
$children = $item
|
|
||||||
->viewable()
|
|
||||||
->where("type", "!=", "album")
|
|
||||||
->order_by("created", "DESC")
|
|
||||||
->descendants($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/albums/{$item->id}?page={$previous_page}");
|
|
||||||
}
|
|
||||||
if ($page < $max_pages) {
|
|
||||||
$next_page = $page + 1;
|
|
||||||
$view->next_page_link = url::site("latestupdates/albums/{$item->id}?page={$next_page}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up and display the actual page.
|
|
||||||
$template = new Theme_View("page.html", "collection", "LatestUpdates");
|
|
||||||
$template->page_title = t("Gallery :: Latest Updates");
|
|
||||||
$template->set_global("page", $page);
|
|
||||||
$template->set_global("page_size", $page_size);
|
|
||||||
$template->set_global("max_pages", $max_pages);
|
|
||||||
$template->set_global("children", $children);
|
|
||||||
$template->set_global("children_count", $count);
|
|
||||||
$template->content = new View("dynamic.html");
|
|
||||||
$template->content->title = t("Latest Updates");
|
|
||||||
print $template;
|
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
// First item to display.
|
|
||||||
$offset = ($page - 1) * $page_size;
|
|
||||||
|
|
||||||
// Determine the total number of items,
|
|
||||||
// for page numbering purposes.
|
|
||||||
$count = ORM::factory("item")
|
|
||||||
->viewable()
|
|
||||||
->where("type", "!=", "album")
|
|
||||||
->find_all()
|
|
||||||
->count();
|
|
||||||
|
|
||||||
// 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 = ORM::factory("item")
|
|
||||||
->viewable()
|
|
||||||
->where("type", "!=", "album")
|
|
||||||
->order_by("created", "DESC")
|
|
||||||
->find_all($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.
|
|
||||||
$template = new Theme_View("page.html", "collection", "LatestUpdates");
|
|
||||||
$template->page_title = t("Gallery :: Latest Updates");
|
|
||||||
$template->set_global("page", $page);
|
|
||||||
$template->set_global("page_size", $page_size);
|
|
||||||
$template->set_global("max_pages", $max_pages);
|
|
||||||
$template->set_global("children", $items);
|
|
||||||
$template->set_global("children_count", $count);
|
|
||||||
$template->content = new View ("dynamic.html");
|
|
||||||
$template->content->title = t("Latest Updates");
|
|
||||||
print $template;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ class latestupdates_block_Core {
|
|||||||
static function get($block_id, $theme) {
|
static function get($block_id, $theme) {
|
||||||
$block = "";
|
$block = "";
|
||||||
|
|
||||||
|
|
||||||
switch ($block_id) {
|
switch ($block_id) {
|
||||||
case "latestupdates":
|
case "latestupdates":
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user