| Current Path : /home/j/u/v/juvelize/martine/modules/mod_magiczoomplus/ |
| Current File : /home/j/u/v/juvelize/martine/modules/mod_magiczoomplus/mod_magiczoomplus.php |
<?php
/*------------------------------------------------------------------------
# mod_magiczoomplus - Magic Zoom Plus for Joomla
# ------------------------------------------------------------------------
# Magic Toolbox
# Copyright 2011 MagicToolbox.com. All Rights Reserved.
# @license - http://www.opensource.org/licenses/artistic-license-2.0 Artistic License 2.0 (GPL compatible)
# Website: http://www.magictoolbox.com/magiczoomplus/modules/joomla/
# Technical Support: http://www.magictoolbox.com/contact/
/*-------------------------------------------------------------------------*/
// no direct access
defined('_JEXEC') or die('Restricted access.');
//NOTE: this file is included in JModuleHelper::renderModule function
ini_set('display_errors', true );
error_reporting(E_ALL & ~E_NOTICE);
global $magiczoomplusProfiles;
global $displayMagicZoomPlusForJoomlaHeaders;
if(!defined('MAGICZOOMPLUS_FOR_JOOMLA_INIT')) {
define('MAGICZOOMPLUS_FOR_JOOMLA_INIT', true);
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
defined('JVERSION_16') or define('JVERSION_16', version_compare(JVERSION, '1.6.0','>=') ? true : false);
defined('JVERSION_30') or define('JVERSION_30', version_compare(JVERSION, '3.0.0','>=') ? true : false);
$magiczoomplusProfiles = array('default' => false);
$displayMagicZoomPlusForJoomlaHeaders = false;
}
if(!defined('MAGICTOOLBOX_JURI_BASE')) {
$url = JURI::base(true);
//NOTE: JURI::base() return URI according to $live_site variable in configuration
// this leads to problem with wrong protocol prefix (http/https)
// so this is a fix
if(empty($_SERVER['HTTPS']) || (strtolower($_SERVER['HTTPS']) == 'off')) {
$url = preg_replace('/^https:/i', 'http:', $url);
} else {
$url = preg_replace('/^http:/i', 'https:', $url);
}
define('MAGICTOOLBOX_JURI_BASE', $url);
}
$magiczoomplusScope = $params->get('scope', '__default__');
if(!isset($magiczoomplusProfiles[$magiczoomplusScope]) || $magiczoomplusProfiles[$magiczoomplusScope]) return;
//NOTE: not to run twice
$magiczoomplusProfiles[$magiczoomplusScope] = true;
if(!defined('MAGICZOOMPLUS_FOR_JOOMLA_FUNCTIONS_DEFINED')) {
define('MAGICZOOMPLUS_FOR_JOOMLA_FUNCTIONS_DEFINED', true);
function onAfterRenderMagicZoomPlusForJoomlaHandler() {
global $displayMagicZoomPlusForJoomlaHeaders;
$tool = getToolMagicZoomPlusForJoomla();
$contents = JResponse::getBody();//JResponse::toString();
if(!$tool->params->checkValue('enable-effect', 'No', 'default')) {
$tool->params->setProfile('default');
//NOTE: old pattern
//'<a\b([^>]*?\bclass=["\'][^"\']*?\bMagicZoomPlus\b[^"\']*+["\'][^>]*+)>(.*?)</a>'
$pattern = '(?:<p[^>]*+>[^<]*+)?<a\b([^>]*?\bclass=["\'][^"\']*?\bMagicZoomPlus\b[^"\']*+["\'][^>]*+)>'.
'('.
'(?:'.
'[^<]++'.
'|'.
'<(?!/?a\b|!--)'.
'|'.
'<!--.*?-->'.
'|'.
'<a\b[^>]*+>'.
'(?2)'.
'</a\s*+>'.
')*+'.
')'.
'</a\s*+>(?:[^<]*+</p\s*+>)?';
$contents = preg_replace_callback("#{$pattern}#is", 'callbackMagicZoomPlusForJoomla', $contents);
//preg_match_all('%'.$pattern.'%is', $contents, $__matches, PREG_SET_ORDER);
}
else return true;
if(!$displayMagicZoomPlusForJoomlaHeaders || defined('MagicZoomPlus_HEADERS_LOADED')) return true;
define('MagicZoomPlus_HEADERS_LOADED', true);
$tool->params->resetProfile();
$url = MAGICTOOLBOX_JURI_BASE.'/media/mod_magiczoomplus';
$headers = array();
$headers[] = "\n".$tool->getHeadersTemplate($url);
$headers[] = "\n<link type=\"text/css\" href=\"{$url}/module.css\" rel=\"stylesheet\" media=\"screen\" />\n";
$contents = preg_replace('#(<!-- Magic Slideshow Joomla module|</head>)#is', implode($headers).'$1', $contents, 1);
JResponse::setBody($contents);
return true;
}
function getToolMagicZoomPlusForJoomla() {
static $mainCoreClass = null;
if($mainCoreClass === null) {
require_once(dirname(__FILE__).DS.'classes'.DS.'magiczoomplus.module.core.class.php');
$mainCoreClass = new MagicZoomPlusModuleCoreClass();
$database = JFactory::getDBO();
$database->setQuery("SELECT `profile`, `name`, `value` FROM `#__magiczoomplus_config` WHERE `disabled`='0'");
$results = $database->loadAssocList();
if(!empty($results)) {
foreach($results as $row) {
$mainCoreClass->params->setValue($row['name'], $row['value'], $row['profile']);
}
foreach($mainCoreClass->params->getProfiles() as $profile) {
if($mainCoreClass->params->checkValue('enable-effect', 'Zoom', $profile)) {
$mainCoreClass->params->setValue('disable-expand', 'Yes', $profile);
$mainCoreClass->params->setValue('disable-zoom', 'No', $profile);
} else if($mainCoreClass->params->checkValue('enable-effect', 'Expand', $profile)) {
$mainCoreClass->params->setValue('disable-expand', 'No', $profile);
$mainCoreClass->params->setValue('disable-zoom', 'Yes', $profile);
} else if($mainCoreClass->params->checkValue('enable-effect', 'Swap images only', $profile)) {
$mainCoreClass->params->setValue('disable-expand', 'Yes', $profile);
$mainCoreClass->params->setValue('disable-zoom', 'Yes', $profile);
}
}
// for MT module
//$this->conf->set('caption-source', 'Title');
// for MM and MMP modules (centered thumbnails)
//$this->conf->set('containerDisplay', 'inline-block');
}
}
return $mainCoreClass;
}
function callbackMagicZoomPlusForJoomla($_matches) {
$original = &$_matches[0];
$attributes = &$_matches[1];
$innerHTML = &$_matches[2];
$matches = array();
$id = '';
if(preg_match('#\bid\s*+=\s*+["\']([^"\']*+)["\']#is', $attributes, $matches)) {
$id = $matches[1];
}
if(preg_match('/MagicZoomPlusImage/is', $id)) return $original;
$img = '';
if(preg_match('#\bhref\s*+=\s*+["\']([^"\']*+)["\']#is', $attributes, $matches)) {
$img = $matches[1];
}
$link = '';
if(preg_match('#\btarget\s*+=\s*+["\']([^"\']*+)["\']#is', $attributes, $matches)) {
$link = $matches[1];
}
$thumb = '';
if(preg_match('#\bsrc\s*+=\s*+["\']([^"\']*+)["\']#is', $innerHTML, $matches)) {
$thumb = $matches[1];
}
$alt = '';
if(preg_match('#\balt\s*+=\s*+["\']([^"\']*+)["\']#is', $innerHTML, $matches)) {
$alt = $matches[1];
}
$title = '';
if(preg_match('#\btitle\s*+=\s*+["\']([^"\']*+)["\']#is', $innerHTML, $matches)) {
$title = $matches[1];
}
$aTitle = '';
if(preg_match('#\btitle\s*+=\s*+["\']([^"\']*+)["\']#is', $attributes, $matches)) {
$aTitle = $matches[1];
}
$spanTitle = '';
//"#<span>(.*)</span>(?!.*?</span>.*?)#is"
if(preg_match( '#<span\b[^>]*+>'.
'('.
'(?:'.
'[^<]++'.
'|'.
'<(?!/?span\b|!--)'.
'|'.
'<!--.*?-->'.
'|'.
'<span\b[^>]*+>'.
'(?1)'.
'</span\s*+>'.
')*+'.
')'.
'</span\s*+>#is', $innerHTML, $matches)) {
$spanTitle = $matches[1];
}
$caption = '';
$mosimage = false;
if($alt == $title && $alt == 'Image') {
$mosimage = true;
$alt = $title = '';
}
if(preg_match('#mosimage#is', $innerHTML)) {
$mosimage = true;
if(preg_match( '#<div\b[^>]*?\bclass\s*+=\s*+["\'][^"\']*?\bmosimage_caption\b[^"\']*+["\'][^>]*+>'.
'('.
'(?:'.
'[^<]++'.
'|'.
'<(?!/?div\b|!--)'.
'|'.
'<!--.*?-->'.
'|'.
'<div\b[^>]*+>'.
'(?1)'.
'</div\s*+>'.
')*+'.
')'.
'</div\s*+>#is', $innerHTML, $matches)) {
$caption = $matches[1];
}
}
$title = empty($caption) ? (empty($spanTitle) ? (empty($alt) ? (empty($title) ? $aTitle : $title) : $alt) : $spanTitle) : $caption;
if(!empty($title)) {
$title = html_entity_decode($title);
$title = str_replace('mce_thref', 'href', $title);
}
$width = '';
if(preg_match('#\bwidth\s*+=\s*+["\']([^"\']*+)["\']#is', $innerHTML, $matches)) {
$width = $matches[1];
}
$height = '';
if(preg_match('#\bheight\s*+=\s*+["\']([^"\']*+)["\']#is', $innerHTML, $matches)) {
$height = $matches[1];
}
$align = '';
if(preg_match('#\balign\s*+=\s*+["\']([^"\']*+)["\']#is', $innerHTML, $matches)) {
$align = $matches[1];
}
if(empty($align)) {
if(preg_match('#float\s*+:\s*+(left|right)\s*+[;"\']#is', $innerHTML, $matches)) {
$align = $matches[1];
}
}
$tool = getToolMagicZoomPlusForJoomla();
$html = $tool->getMainTemplate(compact('img', 'thumb', 'id', 'title', 'width', 'height', 'link'));
if(!empty($id)) $html = preg_replace('#(<a\b[^>]*?id\s*+=\s*+["\'])MagicZoomPlusImage#s', '$1', $html);
$rel = '';
if(preg_match('#\brel\s*+=\s*+["\']([^"\']*+)["\']#is', $attributes, $matches)) {
$rel = $matches[1];
if(preg_match('#\brel\s*+=\s*+["\']([^"\']*+)["\']#is', $html, $matches)) {
$magictoolboxRel = explode(';', $matches[1]);
$magictoolboxRelLength = count($magictoolboxRel);
for($i = 0; $i < $magictoolboxRelLength; $i++) {
$optionLine = trim($magictoolboxRel[$i]);
unset($magictoolboxRel[$i]);
if(empty($optionLine)) continue;
list($key, $value) = explode(':', $optionLine);
if(!empty($value)) $magictoolboxRel[trim($key)] = $value;
}
$rel = explode(';', $rel);
foreach($rel as $optionLine) {
$optionLine = trim($optionLine);
if(empty($optionLine)) continue;
list($key, $value) = explode(':', $optionLine);
if(!empty($value)) $magictoolboxRel[trim($key)] = $value;
}
$rel = array();
foreach($magictoolboxRel as $key => $value) {
$rel[] = "{$key}:{$value}";
}
$rel = implode(';', $rel).';';
$html = preg_replace('#^(.*?\brel\s*+=\s*+["\'])[^"\']*+(["\'].*+)$#is', "$1{$rel}$2", $html);
} else {
$html = preg_replace('#<a\b[^>]*?class=["\'][^"\']*?\bMagicZoomPlus\b[^"\']*+["\'][^>]*+#is', "$0 {$rel} ", $html);
}
}
/*
$html = preg_replace("/^(<a.*?<\/a>).*$/iUs", "$1", $html);
$message = trim($tool->params->getValue('message'));
if(!empty($message) && $tool->params->checkValue('show-message', 'Yes')) {
$html = $html.'<br />'.$message;
}
*/
$float = empty($align) ? '' : "float: {$align};";
//$html = "<b style=\"display: block; font-weight: normal; {$float}; margin: 0 3px 0 0; text-align: center;\">{$html}</b>";
$html = '<div class="MagicToolboxContainer" style="'.$float.'">'.$html.'</div>';
global $displayMagicZoomPlusForJoomlaHeaders;
$displayMagicZoomPlusForJoomlaHeaders = true;
return $html;
}
}
$magiczoomplus = getToolMagicZoomPlusForJoomla();
if($magiczoomplusScope == 'default') {
//NOTE: can't use $mainframe->registerEvent function when System.Cache plugin activated
JDispatcher::getInstance()->register('onAfterRender', 'onAfterRenderMagicZoomPlusForJoomlaHandler');
}