Skip to content

Commit

Permalink
More modular gallery class, also allows to retrieve the list of image…
Browse files Browse the repository at this point in the history
…s (#3173)
  • Loading branch information
aschempp committed May 10, 2012
1 parent ef50bbe commit 5cbf269
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 50 deletions.
1 change: 1 addition & 0 deletions system/modules/isotope/CHANGELOG.md
Expand Up @@ -15,6 +15,7 @@ Version 1.4.beta1 (2012-??-??)
### Improved
- Checkout steps are now a numbered list (#3040)
- Product list can be sorted by dateAdded, this allows to list the newest products
- More modular gallery class, also allows to retrieve the list of images (#3173)


Version 1.3.1 stable (2012-04-30)
Expand Down
126 changes: 76 additions & 50 deletions system/modules/isotope/IsotopeGallery.php
Expand Up @@ -94,66 +94,31 @@ public function __set($strKey, $varValue)
$this->arrFiles = array();
$varValue = deserialize($varValue);

if (is_array($varValue) && count($varValue))
if (is_array($varValue) && !empty($varValue))
{
foreach ($varValue as $k => $file)
foreach ($varValue as $file)
{
$strFile = 'isotope/' . strtolower(substr($file['src'], 0, 1)) . '/' . $file['src'];

if (is_file(TL_ROOT . '/' . $strFile))
{
$objFile = new File($strFile);

if ($objFile->isGdImage)
{
foreach ((array) $this->Isotope->Config->imageSizes as $size)
{
$strImage = $this->getImage($strFile, $size['width'], $size['height'], $size['mode']);

if ($size['watermark'] != '')
{
$strImage = IsotopeFrontend::watermarkImage($strImage, $size['watermark'], $size['position']);
}

$arrSize = @getimagesize(TL_ROOT . '/' . $strImage);

if (is_array($arrSize) && strlen($arrSize[3]))
{
$file[$size['name'] . '_size'] = $arrSize[3];
}

$file['alt'] = specialchars($file['alt']);
$file['desc'] = specialchars($file['desc']);

$file[$size['name']] = $strImage;
}

$this->arrFiles[] = $file;
}
}
$this->addImage($file);
}
}

// No image available, add default image
if (!count($this->arrFiles) && is_file(TL_ROOT . '/' . $this->Isotope->Config->missing_image_placeholder))
// No image available, add placeholder from store configuration
if (empty($this->arrFiles))
{
foreach ((array) $this->Isotope->Config->imageSizes as $size)
$strPlaceholder = $this->Isotope->Config->missing_image_placeholder;

if ($strPlaceholder != '' && is_file(TL_ROOT . '/' . $strPlaceholder))
{
$strImage = $this->getImage($this->Isotope->Config->missing_image_placeholder, $size['width'], $size['height'], $size['mode']);
$arrSize = @getimagesize(TL_ROOT . '/' . $strImage);

if (is_array($arrSize) && strlen($arrSize[3]))
{
$file[$size['name'] . '_size'] = $arrSize[3];
}

$file[$size['name']] = $strImage;
$this->addImage(array('src'=>$this->Isotope->Config->missing_image_placeholder), false);
}

$this->arrFiles[] = $file;
}
break;

case 'main_image':
$file = is_array($varValue) ? $varValue : array('src'=>$file);
return $this->addImage($file, true, true);
break;

default:
$this->arrData[$strKey] = $varValue;
break;
Expand All @@ -174,6 +139,10 @@ public function __get($strKey)
return reset($this->arrFiles);
break;

case 'images':
return $this->arrFiles;
break;

default:
return $this->arrData[$strKey];
}
Expand All @@ -196,7 +165,7 @@ public function size()
*/
public function hasImages()
{
return ($this->size()) ? true : false;
return !empty($this->arrFiles);
}


Expand Down Expand Up @@ -317,5 +286,62 @@ protected function generateAttribute($strId, $strBuffer, $strClass='')
{
return '<div class="iso_attribute' . ($strClass != '' ? ' '.strtolower($strClass) : '') .'" id="' . $strId . '">' . $strBuffer . '</div>';
}


/**
* Add an image to the gallery
* @param array
* @param bool
* @param bool
* @return bool
*/
private function addImage(array $file, $blnWatermark=true, $blnMain=false)
{
$strFile = 'isotope/' . strtolower(substr($file['src'], 0, 1)) . '/' . $file['src'];

if (is_file(TL_ROOT . '/' . $strFile))
{
$objFile = new File($strFile);

if ($objFile->isGdImage)
{
foreach ((array) $this->Isotope->Config->imageSizes as $size)
{
$strImage = $this->getImage($strFile, $size['width'], $size['height'], $size['mode']);

if ($size['watermark'] != '' && $blnWatermark)
{
$strImage = IsotopeFrontend::watermarkImage($strImage, $size['watermark'], $size['position']);
}

$arrSize = @getimagesize(TL_ROOT . '/' . $strImage);

if (is_array($arrSize) && strlen($arrSize[3]))
{
$file[$size['name'] . '_size'] = $arrSize[3];
}

$file['alt'] = specialchars($file['alt']);
$file['desc'] = specialchars($file['desc']);

$file[$size['name']] = $strImage;
}

// Main image is first in the array
if ($blnMain)
{
array_unshift($this->arrFiles, $file);
}
else
{
$this->arrFiles[] = $file;
}

return true;
}
}

return false;
}
}

0 comments on commit 5cbf269

Please sign in to comment.