function getUniqueOverrideParameters($srcParams, $overrideParams, $caseInsensitive = false)
	{
		$uniqueParams = array();
		
		foreach ($srcParams as $srcKey => $srcValue)
		{
			if (is_array($srcValue))
			{
				if (isset($overrideParams[$srcKey]) || ($caseInsensitive && isset($overrideParams[strtolower($srcKey)])))
				{
					$subParams = AriParametersHelper::getUniqueOverrideParameters(
						$srcValue, 
						isset($overrideParams[$srcKey]) ? $overrideParams[$srcKey] : $overrideParams[strtolower($srcKey)],
						$caseInsensitive);
					if (count($subParams) > 0)
						$uniqueParams[$srcKey] = $subParams;
				}
			}
			else if (array_key_exists($srcKey, $overrideParams) || ($caseInsensitive && array_key_exists(strtolower($srcKey), $overrideParams)))
			{
				$overrideValue = AriUtils2::parseValueBySample(
					isset($overrideParams[$srcKey]) ? $overrideParams[$srcKey] : $overrideParams[strtolower($srcKey)], 
					$srcValue);
				if ($overrideValue != $srcValue)
					$uniqueParams[$srcKey] = $overrideValue; 
			}
		}
		
		return $uniqueParams;
	}
	function modifyData(&$data, $params, $modelParams)
	{
		$rootUri = JURI::root(true) . '/';
		$keepSize = AriUtils2::getParam($modelParams, 'keepSize', false);
		$target = AriUtils2::getParam($modelParams, 'target');
		if ($target == '_self')
			$target = null;
		
		$group = $params['_default']['groupName'];
		if (empty($group)) $group = uniqid('asexy_');
		$modal = AriUtils2::parseValueBySample($params['_default']['modal'], false);
		
		$captionTemplate = AriUtils2::getParam($modelParams, 'caption', '{$Title}');
		$needParseTemplate = strpos($captionTemplate, '{$') !== false;
		
		foreach ($data as $key => $value)
		{
			$dataItem =& $data[$key];
			
			$img = $dataItem['image'];
			$title = $needParseTemplate
				? AriSimpleTemplate::parse($captionTemplate, $dataItem, true)
				: $captionTemplate;
			$aAttrs = array('href' => $rootUri . $img . ($modal ? '?modal=1' : ''), 'rel' => 'sexylightbox[' . $group . ']', 'title' => $title);
			if ($target)
				$aAttrs['target'] = $target;
			if ($keepSize)
			{
				$size = @getimagesize(JPATH_ROOT . DS . $img);
				if (!empty($size) &&  count($size) > 1)
				{
					 $aAttrs['href'] .= $modal ? '&' : '?';
					 $aAttrs['href'] .= 'width=' . $size[0] . '&height=' . $size[1];
				}
			}
			
			$imgAttrs = array('src' => $rootUri . $dataItem['thumb'], 'border' => '0', 'alt' => str_replace('"', '&qout;', AriUtils2::getParam($dataItem, 'Title', '')));
			if ($dataItem['w']) $imgAttrs['width'] = $dataItem['w'];
			if ($dataItem['h']) $imgAttrs['height'] = $dataItem['h'];
			if (!empty($dataItem['Link'])) $imgAttrs['longdesc'] = $dataItem['Link'];
			$dataItem['sexyimage'] = sprintf('<a%1$s><img%2$s/></a>',
				AriHtmlHelper::getAttrStr($aAttrs),
				AriHtmlHelper::getAttrStr($imgAttrs));
		}
	}	
	function inlineGalleryUpdateCallback($content, $images, $params)
	{
		$thumbCount = $params['thumbCount'];
		$single = $params['single'];
		$groupName = !$single ? AriUtils2::getParam($this->_params['_default'], 'groupName') : null;
		$modal = AriUtils2::parseValueBySample($this->_params['_default']['modal'], false);
		for ($i = 0; $i < count($images); $i++)
		{
			$relAttr = 'sexylightbox' . ($groupName ? '[' . $groupName . ']' : '');
			$image =& $images[$i];
			$image['image']['attributes']['rel'] = $relAttr;
			$image['image']['attributes']['src'] = $image['image']['src'] . ($modal ? '?modal=1' : '');
			if ($thumbCount > 0 && $i >= $thumbCount)
				$image['image']['attributes']['style'] = 'display: none;';
		}

		return AriInlineThumbnailProvider::updateCallback($content, $images, $params);
	}	
	function getData($picasaData, $modelParams, $params)
	{
		$data = array();
		if (empty($picasaData))
			return $data;
		
		$group = $params['_default']['groupName'];
		if (empty($group)) $group = uniqid('asexy_');
		$modal = AriUtils2::parseValueBySample($params['_default']['modal'], false);
		$keepSize = AriUtils2::getParam($modelParams, 'keepSize', false);
		
		$captionTemplate = AriUtils2::getParam($modelParams, 'caption', '{$Title}');
		$needParseTemplate = strpos($captionTemplate, '{$') !== false;
		
		foreach ($picasaData as $key => $value)
		{
			$dataItem = $value;

			$dataItem['Title'] = AriUtils2::getParam($dataItem, 'summary', '');
			$title = $needParseTemplate
				? AriSimpleTemplate::parse($captionTemplate, $dataItem, true)
				: $captionTemplate;
			$img = $dataItem['image'];
			$thumb = $dataItem['thumb'];
			$aAttrs = array('href' => $img['url'] . ($modal ? '?modal=1' : ''), 'rel' => 'sexylightbox[' . $group . ']', 'title' => $title);
			$imgAttrs = array('src' => $thumb['url'], 'border' => '0', 'alt' => $dataItem['Title'], 'width' => $thumb['w'], 'height' => $thumb['h']);
			
			if ($keepSize)
			{
				$aAttrs['href'] .= $modal ? '&' : '?';
				$aAttrs['href'] .= 'width=' . $img['w'] . '&height=' . $img['h'];
			}

			$dataItem['sexyimage'] = sprintf('<a%1$s><img%2$s/></a>',
					AriHtmlHelper::getAttrStr($aAttrs),
					AriHtmlHelper::getAttrStr($imgAttrs));
					
			$data[$key] = $dataItem;
		}

		return $data;
	}
	function getCorrectedParameters($params)
	{
		$clearParams = array(
			'thumbWidth' => 150,
			'thumbHeight' => 0,
			'generateThumbs' => true,
			'thumbCount' => 0,
			'single' => false,
			'class' => '',
			'groupName' => uniqid('app_', false),
			'ignoreEmptyDim' => false,
			'ignoreRemote' => false
		);
		
		$correctedParams = array();
		foreach ($clearParams as $key => $value)
		{
			$correctedParams[$key] = AriUtils2::parseValueBySample(
				AriUtils2::getParam($params, $key, $value),
				$value);			
		}
		
		$correctedParams = array_merge($correctedParams, array_diff($params, $correctedParams));
		unset($correctedParams['content']);
		
		$thumbType = strtolower(AriUtils2::getParam($params, 'thumbType', 'resize'));
		if (!in_array($thumbType, array('resize', 'crop', 'cropresize')))
			$thumbType = 'resize';
			
		$thumbTypeParamKey = 'thumbType' . ucfirst($thumbType);
		$correctedParams['thumbTypeParams'] = AriUtils2::getParam($params, $thumbTypeParamKey, array());
		$correctedParams['thumbType'] = $thumbType;
		if (!isset($correctedParams['thumbFilters']))
			$correctedParams['thumbFilters'] = array();
		
		return $correctedParams;
	}
	function getData($flickrData, $modelParams, $params)
	{
		$data = array('photos' => array(), 'photosets' => array());
		if (empty($flickrData))
			return $data;
		
		$group = $params['_default']['groupName'];
		if (empty($group)) $group = uniqid('asexy_');
		$modal = AriUtils2::parseValueBySample($params['_default']['modal'], false);
		
		$captionTemplate = AriUtils2::getParam($modelParams, 'caption', '{$Title}');
		$needParseTemplate = strpos($captionTemplate, '{$') !== false;

		$photos = AriUtils2::getParam($flickrData, 'photos', $flickrData);
		foreach ($photos as $key => $value)
		{
			$dataItem = $value;

			$title = $needParseTemplate
				? AriSimpleTemplate::parse($captionTemplate, $dataItem, true)
				: $captionTemplate;
			$aAttrs = array('href' => $dataItem['imgUrl'] . ($modal ? '?modal=1' : ''), 'rel' => 'sexylightbox[' . $group . ']', 'title' => $title);
			$imgAttrs = array('src' => $dataItem['thumbUrl'], 'border' => '0', 'alt' => $dataItem['Title']);

			$dataItem['thumb'] = $dataItem['thumbUrl'];
			$dataItem['sexyimage'] = sprintf('<a%1$s><img%2$s/></a>',
					AriHtmlHelper::getAttrStr($aAttrs),
					AriHtmlHelper::getAttrStr($imgAttrs));
					
			$data['photos'][$key] = $dataItem;
		}
		
		$data['photosets'] = AriUtils2::getParam($flickrData, 'photosets', array());

		return $data;
	}
	function getCorrectedParameters($params)
	{
		$thumbWidth = intval(AriUtils2::getParam($params, 'thumbWidth', 0), 10);
		if ($thumbWidth < 0) $thumbWidth = 0;

		$thumbHeight = intval(AriUtils2::getParam($params, 'thumbHeight', 0), 10);
		if ($thumbHeight < 0) $thumbHeight = 0;
		
		$cachePeriod = intval(AriUtils2::getParam($params, 'cachePeriod', 0), 10);
		if ($cachePeriod < 0) $cachePeriod = 0;
		
		$generateThumbs = (($thumbWidth || $thumbHeight) && AriAsidoHelper::isExtensionLoaded())
			? AriUtils2::parseValueBySample(AriUtils2::getParam($params, 'generateThumbs'), false)
			: false;

		$scanSubFolders = AriUtils2::parseValueBySample(AriUtils2::getParam($params, 'subdir'), false);
		$folders = $this->getFolders(trim(AriUtils2::getParam($params, 'dir', '')), $scanSubFolders);
		
		$thumbPath = trim(AriUtils2::getParam($params, 'thumbPath', ''));
		if ($thumbPath)
			$thumbPath = preg_replace('#^[/\\\\]+|[/\\\\]+$#', '', JPath::clean($thumbPath));
			
		$sortDir = strtolower(AriUtils2::getParam($params, 'sortDir', 'asc'));
		if (!in_array($sortDir, array('asc', 'desc')))
			$sortDir = 'asc';

		$thumbType = strtolower(AriUtils2::getParam($params, 'thumbType', 'resize'));
		if (!in_array($thumbType, array('resize', 'crop', 'cropresize')))
			$thumbType = 'resize';
			
		$thumbTypeParamKey = 'thumbType' . ucfirst($thumbType);
		$thumbTypeParams = AriUtils2::getParam($params, $thumbTypeParamKey, array());

		return array(
			'key' => $params['key'],
			'checkSum' => $params['checkSum'],
			'descrFile' => trim(AriUtils2::getParam($params, 'descrFile', '')),
			'fileFilter' => $params['fileFilter'],
			'thumbWidth' => $thumbWidth,
			'thumbHeight' => $thumbHeight,
			'generateThumbs' => $generateThumbs,
			'thumbType' => $thumbType,
			'thumbTypeParams' => $thumbTypeParams,
			'thumbFilters' => AriUtils2::getParam($params, 'thumbFilters', array()),
			'folders' => $folders,
			'cachePeriod' => $cachePeriod,
			'thumbPath' => $thumbPath,
			'sortDir' => $sortDir,
			'sortBy' => strtolower(AriUtils2::getParam($params, 'sortBy', '')),
			'emptyTitle' => AriUtils2::getParam($params['simplegallery'], 'emptyTitle', '')
		);
	}
$params->set('key', 'arisexybox_mod_' . $module->id);
$params->set('checkSum', md5($module->params));
$groupName = $params->get('groupName');
$thumbQuality = intval($params->get('thumbQuality', 80), 10);
if (!defined('ASIDO_GD_JPEG_QUALITY'))
	define('ASIDO_GD_JPEG_QUALITY', $thumbQuality);

if (empty($groupName)) $params->set('groupName', uniqid('asexy_'));
$autoShow = $params->get('autoShow');
$showOnClose = $params->get('showOnClose');
$mParams = AriParametersHelper::flatParametersToArray($params);
AriSexyLightboxHelper::includeAssets(
	AriUtils2::parseValueBySample($params->get('includeJQuery'), true),
	AriUtils2::parseValueBySample($params->get('noConflict'), true),
	AriUtils2::parseValueBySample($params->get('jQueryVer', '1.4.4'), '1.4.4'),
	AriUtils2::getParam($mParams, 'opt', array()));

AriSexyLightboxHelper::activateAutoShow(
	trim($params->get('groupName', '')), 
	$autoShow, 
	$params->get('unique', 'aslmod_' . $module->id),
	AriUtils2::getParam($mParams, 'cookie'));
	
AriSexyLightboxHelper::activateAutoShowOnClose(
	trim($params->get('groupName', '')),
	$params->get('onCloseMessage'), 
	$showOnClose, 
	$params->get('unique', 'aslmod_' . $module->id),
	AriUtils2::getParam($mParams, 'cookie'));
Esempio n. 9
0
	function activateAutoShowOnClose($group = '', $message = '', $autoShow = true, $uniqueKey = false, $cookie = null)
	{
		if ($autoShow != 'first')
			$autoShow = AriUtils2::parseValueBySample($autoShow, false);
		
		if (!$autoShow)
			return ;
			
		static $loaded;
		
		if ($loaded)
			return ;

		if ('first' === $autoShow && !empty($uniqueKey))
		{
			$cookieKey = 'asl_' . $uniqueKey;
			$cookieDuration = intval(AriUtils2::getParam($cookie, 'duration', 365), 10) * 24 * 60 * 60;

			if ($cookieDuration == 0)
			{
			 	if (!empty($_SESSION[$cookieKey]))
					return ;
					
				$_SESSION[$cookieKey] = true;
			}	
			else
			{
				if (!empty($_COOKIE[$cookieKey]))
					return ;

				setcookie($cookieKey, '1', time() + $cookieDuration);
			}
		}
		
		AriSexyLightboxHelper::includeTools();
		$document =& JFactory::getDocument();
		$document->addScriptDeclaration(sprintf('ARISexyLightboxTools.initBeforeUnload("a[rel^=\'%1$s\']:eq(0)", "%2$s");',
			$group 
				? 'sexylightbox[' . $group . ']'
				: 'sexylightbox',
			addcslashes($message, '"')));
		
		$loaded = true;
	}