From bae14a76e52524e2157948bf30cfe3340d1e9a94 Mon Sep 17 00:00:00 2001 From: Jozef Selesi Date: Mon, 11 Mar 2013 14:42:43 +0100 Subject: Themes can set minimum thumbnail size when calculating proportions. This prevents broken item rendering when thumbnails are smaller than the theme design allows. Trac-Ticket: #1838 --- modules/gallery/libraries/Theme_View.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'modules/gallery/libraries/Theme_View.php') diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index 0a4c96e1..16c57794 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -60,9 +60,10 @@ 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 + * @param int (optional) minimum thumbnail width * @return int */ - public function thumb_proportion($item=null) { + public function thumb_proportion($item=null, $minimum_size=0) { // If the item is an album with children, grab the first item in that album instead. We're // interested in the size of the thumbnails in this album, not the thumbnail of the // album itself. @@ -74,7 +75,7 @@ class Theme_View_Core extends Gallery_View { // 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; + return max($item->thumb_width, $item->thumb_height, $minimum_size) / 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. -- cgit v1.2.3 From 3c47deb9ef3fd35b1602c822af2b752c6733bed3 Mon Sep 17 00:00:00 2001 From: Jozef Selesi Date: Mon, 11 Mar 2013 15:59:00 +0100 Subject: Themes can choose child thumbnail when asking for proportion. This helps themes better calculate an item's container size, for cases when the first item significantly differs in size from the rest. Trac-Ticket: #1838 --- modules/gallery/libraries/Theme_View.php | 21 +++++++++++++++++---- themes/wind/views/page.html.php | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'modules/gallery/libraries/Theme_View.php') diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index 16c57794..da1e8ce8 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -58,17 +58,30 @@ class Theme_View_Core extends Gallery_View { } /** - * Proportion of the current thumb_size's to default + * Proportion of the current thumb_size's to default. + * + * Themes can optionally use the $dimension parameter to choose which of the album's + * children will be used to determine the proportion. If set, the proportion will be + * calculated based on the child item with the largest width or height. + * * @param object Item_Model (optional) check the proportions for this item * @param int (optional) minimum thumbnail width + * @param string (optional) "width" or "height" * @return int */ - public function thumb_proportion($item=null, $minimum_size=0) { - // If the item is an album with children, grab the first item in that album instead. We're + public function thumb_proportion($item=null, $minimum_size=0, $dimension=null) { + if (!in_array($dimension, array("height", "width"))) { + $dimension = null; + } + + // If the item is an album with children, grab an item from that album instead. We're // interested in the size of the thumbnails in this album, not the thumbnail of the // album itself. if ($item && $item->is_album() && $item->children_count()) { - $item = $item->children(1)->current(); + $orderBy = (is_null($dimension)) ? array() + : array("thumb_".$dimension => "desc"); + + $item = $item->children(1, null, array(), $orderBy)->current(); } // By default we have a globally fixed thumbnail size In core code, we just return a fixed diff --git a/themes/wind/views/page.html.php b/themes/wind/views/page.html.php index 1dbb31c0..0ae41ea7 100644 --- a/themes/wind/views/page.html.php +++ b/themes/wind/views/page.html.php @@ -24,7 +24,7 @@ " /> page_type == "collection"): ?> - thumb_proportion($theme->item(), 100)) != 1): ?> + thumb_proportion($theme->item(), 100, "width")) != 1): ?>