summaryrefslogtreecommitdiff
path: root/modules/gallery
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery')
-rw-r--r--modules/gallery/controllers/albums.php21
-rw-r--r--modules/gallery/controllers/movies.php25
-rw-r--r--modules/gallery/controllers/photos.php25
-rw-r--r--modules/gallery/helpers/item.php18
-rw-r--r--modules/gallery/libraries/Theme_View.php19
5 files changed, 58 insertions, 50 deletions
diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php
index 1c48c734..8aa3bb35 100644
--- a/modules/gallery/controllers/albums.php
+++ b/modules/gallery/controllers/albums.php
@@ -72,10 +72,29 @@ class Albums_Controller extends Items_Controller {
"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");
+ }
+
+ static function get_display_context($item) {
+ $where = array(array("type", "!=", "album"));
+ $position = item::get_position($item, $where);
+ if ($position > 1) {
+ list ($previous_item, $ignore, $next_item) =
+ $item->parent()->viewable()->children(3, $position - 2, $where);
+ } else {
+ $previous_item = null;
+ list ($next_item) = $item->parent()->viewable()->children(1, $position, $where);
+ }
+
+ return array("position" => $position,
+ "previous_item" => $previous_item,
+ "next_item" => $next_item,
+ "sibling_count" => $item->parent()->viewable()->children_count($where),
+ "parents" => $item->parents()->as_array(),
+ "breadcrumbs" => Breadcrumb::array_from_item_parents($item));
}
public function create($parent_id) {
diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php
index 0f12c3fb..76263dc0 100644
--- a/modules/gallery/controllers/movies.php
+++ b/modules/gallery/controllers/movies.php
@@ -27,28 +27,11 @@ class Movies_Controller extends Items_Controller {
access::required("view", $movie);
- $where = array(array("type", "!=", "album"));
- $position = item::get_position($movie, $where);
- if ($position > 1) {
- list ($previous_item, $ignore, $next_item) =
- $movie->parent()->viewable()->children(3, $position - 2, $where);
- } else {
- $previous_item = null;
- list ($next_item) = $movie->parent()->viewable()->children(1, $position, $where);
- }
-
$template = new Theme_View("page.html", "item", "movie");
- $template->set_global(
- array("item" => $movie,
- "children" => array(),
- "children_count" => 0,
- "parents" => $movie->parents()->as_array(),
- "breadcrumbs" => Breadcrumb::array_from_item_parents($movie),
- "next_item" => $next_item,
- "previous_item" => $previous_item,
- "sibling_count" => $movie->parent()->viewable()->children_count($where),
- "position" => $position));
-
+ $template->set_global(array("item" => $movie,
+ "children" => array(),
+ "children_count" => 0));
+ $template->set_global(item::get_display_context($movie));
$template->content = new View("movie.html");
$movie->increment_view_count();
diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php
index af8aed16..7e78b205 100644
--- a/modules/gallery/controllers/photos.php
+++ b/modules/gallery/controllers/photos.php
@@ -27,28 +27,11 @@ class Photos_Controller extends Items_Controller {
access::required("view", $photo);
- $where = array(array("type", "!=", "album"));
- $position = item::get_position($photo, $where);
- if ($position > 1) {
- list ($previous_item, $ignore, $next_item) =
- $photo->parent()->viewable()->children(3, $position - 2, $where);
- } else {
- $previous_item = null;
- list ($next_item) = $photo->parent()->viewable()->children(1, $position, $where);
- }
-
$template = new Theme_View("page.html", "item", "photo");
- $template->set_global(
- array("item" => $photo,
- "children" => array(),
- "children_count" => 0,
- "parents" => $photo->parents()->as_array(),
- "breadcrumbs" => Breadcrumb::array_from_item_parents($photo),
- "next_item" => $next_item,
- "previous_item" => $previous_item,
- "sibling_count" => $photo->parent()->viewable()->children_count($where),
- "position" => $position));
-
+ $template->set_global(array("item" => $photo,
+ "children" => array(),
+ "children_count" => 0));
+ $template->set_global(item::get_display_context($photo));
$template->content = new View("photo.html");
$photo->increment_view_count();
diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php
index 7e779544..0bb45e49 100644
--- a/modules/gallery/helpers/item.php
+++ b/modules/gallery/helpers/item.php
@@ -402,4 +402,22 @@ class item_Core {
return $position;
}
+
+ /**
+ * Set the display context callback for any future item renders.
+ */
+ static function set_display_context_callback() {
+ $args = func_get_args();
+ Cache::instance()->set("display_context_" . $sid = Session::instance()->id(), $args);
+ }
+
+ /**
+ * Call the display context callback for the given item
+ */
+ static function get_display_context($item) {
+ $args = Cache::instance()->get("display_context_" . $sid = Session::instance()->id());
+ $callback = $args[0];
+ $args[0] = $item;
+ return call_user_func_array($callback, $args);
+ }
} \ No newline at end of file
diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php
index d6834464..389eace6 100644
--- a/modules/gallery/libraries/Theme_View.php
+++ b/modules/gallery/libraries/Theme_View.php
@@ -43,9 +43,6 @@ class Theme_View_Core extends Gallery_View {
"page_type" => $page_type,
"page_subtype" => $page_subtype,
"page_title" => null));
- if ($page_type == "collection") {
- $this->set_global("thumb_proportion", $this->thumb_proportion());
- }
if (module::get_var("gallery", "maintenance_mode", 0)) {
if (identity::active_user()->admin) {
@@ -57,12 +54,20 @@ class Theme_View_Core extends Gallery_View {
/**
* Proportion of the current thumb_size's to default
+ * @param object Item_Model (optional) check the proportions for this item
* @return int
*/
- public function thumb_proportion() {
- // @TODO change the 200 to a theme supplied value when and if we come up with an
- // API to allow the theme to set defaults.
- return module::get_var("gallery", "thumb_size", 200) / 200;
+ public function thumb_proportion($item=null) {
+ // By default we have a globally fixed thumbnail size In core code, we just return a fixed
+ // proportion based on the global thumbnail size, but since modules can override that, we
+ // return the actual proportions when we have them.
+ if ($item && $item->has_thumb()) {
+ return max($item->thumb_width, $item->thumb_height) / 200;
+ } else {
+ // @TODO change the 200 to a theme supplied value when and if we come up with an
+ // API to allow the theme to set defaults.
+ return module::get_var("gallery", "thumb_size", 200) / 200;
+ }
}
public function item() {