Example #1
0
function fn_magiczoom_parse(&$contents, &$products, $block)
{
    $tool = fn_magiczoom_load();
    $tool->params->setProfile($block);
    //NOTE: Non-ASCII filenames are chunked if no locale is provided
    //$oldLocale = setlocale(LC_ALL, NULL);
    //setlocale(LC_ALL, 'en_US.UTF8');
    switch ($block) {
        case 'product':
            $productThumbImageType = $tool->params->getValue('quick-view') ? 'quick-view-thumb' : 'thumb';
            $isMainPairExists = true;
            if (isset($products[0]['main_pair']['detailed']['image_path'])) {
                $imagePath = $products[0]['main_pair']['detailed']['image_path'];
                $imageAlt = $products[0]['main_pair']['detailed']['alt'];
            } else {
                if (isset($products[0]['main_pair']['icon']['image_path'])) {
                    $imagePath = $products[0]['main_pair']['icon']['image_path'];
                    $imageAlt = $products[0]['main_pair']['icon']['alt'];
                } else {
                    if (!empty($products[0]['image_pairs'])) {
                        $isMainPairExists = false;
                        $mainImagePair = reset($products[0]['image_pairs']);
                        if (isset($mainImagePair['detailed']['image_path'])) {
                            $imagePath = $mainImagePair['detailed']['image_path'];
                            $imageAlt = $mainImagePair['detailed']['alt'];
                        } else {
                            $imagePath = $mainImagePair['icon']['image_path'];
                            $imageAlt = $mainImagePair['icon']['alt'];
                        }
                    } else {
                        break;
                    }
                }
            }
            $img = fn_magiczoom_create_thumb($imagePath, 'original', $products[0]['product_id']);
            if (!$img) {
                break;
            }
            //NOTE: possibly image does not exists
            $useMagic360 = false;
            if (function_exists('fn_magic360_load') && Registry::ifGet('addons.magic360.status', 'D') == 'A') {
                $magic360tool = fn_magic360_load();
                if ($magic360tool->params->checkValue('enable-effect', 'Yes', 'product')) {
                    $rezult = db_get_row('SELECT gallery FROM ?:addon_magic360_images WHERE id = ?i', $products[0]['product_id']);
                    if (isset($rezult['gallery']) && !empty($rezult['gallery'])) {
                        $magic360Images = explode(';', $rezult['gallery']);
                        if (count($magic360Images)) {
                            $useMagic360 = true;
                            //NOTE: disable transition effect to prevent the disappearance of the image when it is toggled
                            $tool->params->setValue('transitionEffect', 'No', 'product');
                        }
                    }
                }
            }
            $thumb = fn_magiczoom_create_thumb($imagePath, $productThumbImageType, $products[0]['product_id']);
            $title = !empty($imageAlt) ? $imageAlt : $products[0]['product'];
            $mainImageHTML = $tool->getMainTemplate(array('id' => $block . $products[0]['product_id'], 'group' => $block . $tool->params->getValue('block-id'), 'img' => $img, 'thumb' => $thumb, 'title' => $title)) . "<style type=\"text/css\">.MagicZoom { max-width: " . $tool->params->getValue('thumb-max-width') . "px; }</style>";
            $jcarousel = Registry::get('settings.Appearance.thumbnails_gallery') == 'Y';
            //NOTE: this important for JCarousel
            if ($jcarousel && $tool->params->checkValue('template', 'original')) {
                $width = $tool->params->checkValue('selector-max-width', array('0', '')) ? 'auto' : $tool->params->getValue('selector-max-width');
                $height = $tool->params->checkValue('selector-max-height', array('0', '')) ? 'auto' : $tool->params->getValue('selector-max-height');
            } else {
                $width = '';
                $height = '';
            }
            $mainImageSelectorHTML = $tool->getSelectorTemplate(array('id' => $block . $products[0]['product_id'], 'group' => $block . $tool->params->getValue('block-id'), 'img' => $img, 'medium' => $thumb, 'thumb' => fn_magiczoom_create_thumb($imagePath, 'selector', $products[0]['product_id']), 'title' => $title, 'width' => $width, 'height' => $height));
            $additionalImages = array();
            if (!empty($products[0]['image_pairs'])) {
                if ($isMainPairExists) {
                    $additionalImages[] = str_replace('<a ', '<a class="cm-gallery-item cm-thumbnails-mini thumbnails-item" ', $mainImageSelectorHTML);
                }
                foreach ($products[0]['image_pairs'] as $imagePair) {
                    if (isset($imagePair['detailed']['image_path'])) {
                        $imagePairPath = $imagePair['detailed']['image_path'];
                        $imageAlt = $imagePair['detailed']['alt'];
                        //if(!file_exists($imagePair['detailed']['absolute_path'])) {
                        //NOTICE: there is no guarantee that this picture exists
                        //NOTICE: there is no guarantee that this is a picture of this product (it may be a different picture, if the name is the same)
                        //$imageData = fn_image_to_display($imagePair, Registry::get('settings.Thumbnails.product_details_thumbnail_width'), Registry::get('settings.Thumbnails.product_details_thumbnail_height'));
                        //$imagePairPath = $imageData['image_path'];
                        //}
                    } else {
                        $imagePairPath = $imagePair['icon']['image_path'];
                        $imageAlt = $imagePair['icon']['alt'];
                    }
                    $img = fn_magiczoom_create_thumb($imagePairPath, 'original', $products[0]['product_id']);
                    if (!$img) {
                        continue;
                    }
                    //NOTE: possibly image does not exists
                    $a = $tool->getSelectorTemplate(array('id' => $block . $products[0]['product_id'], 'group' => $block . $tool->params->getValue('block-id'), 'img' => $img, 'medium' => fn_magiczoom_create_thumb($imagePairPath, $productThumbImageType, $products[0]['product_id']), 'thumb' => fn_magiczoom_create_thumb($imagePairPath, 'selector', $products[0]['product_id']), 'title' => !empty($imageAlt) ? $imageAlt : $products[0]['product'], 'width' => $width, 'height' => $height));
                    $additionalImages[] = str_replace('<a ', '<a class="cm-gallery-item cm-thumbnails-mini thumbnails-item" ', $a);
                }
            }
            if ($useMagic360) {
                $GLOBALS['magictoolbox']['cooperative_mode'] = 'magiczoom';
                $magic360tool->params->setValue('selector-max-width', $tool->params->getValue('selector-max-width'));
                $magic360tool->params->setValue('selector-max-height', $tool->params->getValue('selector-max-height'));
                $mainImageHTML = '<div style="position: relative;">' . '<div id="mainImageContainer' . $products[0]['product_id'] . '" style="position: absolute; left: -10000px;">' . '<div>' . $mainImageHTML . '</div>' . '</div>' . '<div id="magic360Container' . $products[0]['product_id'] . '"><!-- MAGIC360 --></div>' . '</div>';
                if (empty($additionalImages)) {
                    $additionalImages[] = str_replace('<a ', '<a class="cm-gallery-item cm-thumbnails-mini thumbnails-item" ', $mainImageSelectorHTML);
                }
                array_unshift($additionalImages, '<!-- MAGIC360SELECTOR -->');
            }
            require_once dirname(__FILE__) . MT_DS . 'classes' . MT_DS . 'magictoolbox.templatehelper.class.php';
            MagicToolboxTemplateHelperClass::setPath(dirname(__FILE__) . MT_DS . 'templates');
            MagicToolboxTemplateHelperClass::setOptions($tool->params);
            $html = MagicToolboxTemplateHelperClass::render(array('main' => $mainImageHTML, 'thumbs' => $additionalImages, 'pid' => $products[0]['product_id'], 'jcarousel' => $jcarousel, 'ul' => version_compare(PRODUCT_VERSION, '4.1', '<')));
            //NOTE: set width for a large number of selectors
            if ($tool->params->checkValue('magicscroll', 'No') && $tool->params->checkValue('template', array('top', 'bottom', 'original'))) {
                $html = preg_replace('#(<div\\b[^>]*?\\bclass="[^"]*?MagicToolboxContainer[^"]*+)("[^>]*+>)#i', '$1 maxWidth$2', $html);
            }
            $html .= '
<script type="text/javascript">
    magicToolboxProductId = ' . $products[0]['product_id'] . ';
</script>';
            $additionalThumbnailsPattern = '(<div\\b[^>]*?\\bclass="[^"]*?\\bcm-image-gallery-wrapper\\b[^"]*+"[^>]*+>[^<]*+)?' . '<(div|ul)\\b[^>]*?\\bclass="[^"]*?\\bproduct-thumbnails\\b[^"]*+"[^>]*+>' . '(' . '(?:' . '[^<]++' . '|' . '<(?!/?\\2\\b|!--)' . '|' . '<!--.*?-->' . '|' . '<\\2\\b[^>]*+>' . '(?3)' . '</\\2\\s*+>' . ')*+' . ')' . '</\\2\\s*+>' . '(?(1)[^<]*+</div\\s*+>)';
            $matches = array();
            preg_match('#' . $additionalThumbnailsPattern . '#is', $contents, $matches);
            /*
            $imagePattern =
                '<a [^>]*?id="det_img_link_[^"]*"[^>]*>[^<]*'.//class=cm-image-previewer, det_img_link_{$preview_id}_
                '(?:<img [^>]*?id="det_img_(?!variant_image)[^"]*"[^>]*>[^<]*'.//class=pict, det_img_{$preview_id}_
                '(?:<span [^>]*?class="view-larger-image"[^>]*>[^<]*</span>[^<]*)?'.
                '|<div [^>]*?class="no-image"[^>]*>.*?</div>[^<]*)'.
                '</a>[^<]*';
            */
            $imagePattern = '(?:' . '<img [^>]*?id="det_img_' . $products[0]['product_id'] . '[0-9][^"]*+"[^>]*+>' . '|' . '<div [^>]*?class="no-image"[^>]*+>.*?</div>' . '|' . '<span [^>]*?class="ty-no-image"[^>]*+>.*?</span>' . ')';
            $imagePattern = '(?:<a [^>]*?id="det_img_link_[^"]*+"[^>]*+>[^<]*+' . $imagePattern . '[^<]*+' . '(?:<span\\b[^>]*+>[^<]*+</span>[^<]*+)?' . '</a>|' . $imagePattern . ')[^<]*+';
            $replaced = 0;
            $contents = preg_replace('#(?:' . $imagePattern . ')+#is', str_replace('$', '\\$', $html), $contents, 1, $replaced);
            //NOTE: $limit = 1 to prevent the replacement of product in product tabs(product id == block id)
            if ($replaced && !empty($matches)) {
                //NOTE: cut selectors
                $contents = str_replace($matches[0], '', $contents);
            }
            break;
        case 'category':
        case 'search':
        case 'newest':
        case 'recent_products':
        case 'most_popular':
        case 'bestsellers':
        case 'rating':
        case 'on_sale':
        case 'manually':
            $useLink = $tool->params->checkValue('link-to-product-page', 'Yes');
            $showGallery = $tool->params->getValue('show-gallery');
            foreach ($products as $product) {
                $imagePairs = $product['image_pairs'];
                if (isset($product['main_pair']['detailed']['image_path'])) {
                    $imagePath = $product['main_pair']['detailed']['image_path'];
                    $imageAlt = $product['main_pair']['detailed']['alt'];
                    if (isset($product['main_pair']['icon']['image_path'])) {
                        $srcPattern = $product['main_pair']['icon']['image_path'];
                    } else {
                        $srcPattern = $imagePath;
                    }
                } else {
                    if (isset($product['main_pair']['icon']['image_path'])) {
                        $imagePath = $product['main_pair']['icon']['image_path'];
                        $imageAlt = $product['main_pair']['icon']['alt'];
                        $srcPattern = $imagePath;
                    } else {
                        if ($showGallery && !empty($imagePairs)) {
                            $imagePair = array_shift($imagePairs);
                            if (isset($imagePair['detailed']['image_path'])) {
                                $imagePath = $imagePair['detailed']['image_path'];
                                $imageAlt = $imagePair['detailed']['alt'];
                                if (isset($imagePair['icon']['image_path'])) {
                                    $srcPattern = $imagePair['icon']['image_path'];
                                } else {
                                    $srcPattern = $imagePath;
                                }
                            } else {
                                $imagePath = $imagePair['icon']['image_path'];
                                $imageAlt = $imagePair['icon']['alt'];
                                $srcPattern = $imagePath;
                            }
                        } else {
                            continue;
                        }
                    }
                }
                //NOTE: cut off timestamp from URL
                $srcPattern = preg_replace('#\\?t=\\d+$#i', '', $srcPattern);
                //NOTE: prepare regexp
                $srcPattern = '[^"]*?/' . preg_quote(basename($srcPattern)) . '(?:\\?t=\\d++)?';
                $img = fn_magiczoom_create_thumb($imagePath, 'original', $product['product_id']);
                if (!$img) {
                    continue;
                }
                //NOTE: possibly image does not exists
                if ($showGallery && !empty($product['image_pairs'])) {
                    //product_icon.tpl (with gallery)
                    /*
                    $galleryPattern =
                        '<div [^>]*?id="icons_[^"]*?'.$product['product_id'].'"[^>]*+>[^<]*+'.//cm-image-gallery `$block.block_id`000`$product.product_id`
                        '(?:'.
                        //new 4.1.x pattern
                        '(?:<div [^>]*?class="[^"]*?cm-gallery-item[^"]*+"[^>]*+>[^<]*+'.
                        '<a [^>]*+>[^<]*+'.
                        '<img [^>]*?id="det_img_[^"]*?'.$product['product_id'].'(?:_[^"]*+)?"[^>]*+>[^<]*+'.
                        '</a>[^<]*+'.
                        '</div>[^<]*+)+'.
                        '|'.
                        //old 4.0.x pattern
                        '<ul[^>]*+>[^<]*+'.
                        '(?:<li [^>]*?class="[^"]*?cm-gallery-item[^"]*+"[^>]*+>[^<]*+'.
                        '<a [^>]*+>[^<]*+'.
                        '<img [^>]*?id="det_img_[^"]*?'.$product['product_id'].'(?:_[^"]*+)?"[^>]*+>[^<]*+'.
                        '</a>[^<]*+'.
                        '</li>[^<]*+)+'.
                        '</ul>[^<]*+'.
                        '(?:<i [^>]*+></i>[^<]*+){2}?'.
                        ')'.
                        '</div>';
                    */
                    $galleryPattern = '<div\\b[^>]*?\\bid\\s*+=\\s*+"icons_[^"]*?' . $product['product_id'] . '"[^>]*+>' . '(' . '(?:' . '[^<]++' . '|' . '<(?!/?div\\b|!--)' . '|' . '<!--.*?-->' . '|' . '<div\\b[^>]*+>' . '(?1)' . '</div\\s*+>' . ')*+' . ')' . '</div\\s*+>';
                    $matches = array();
                    if (preg_match('#' . $galleryPattern . '#is', $contents, $matches)) {
                        $galleryHTML = $matches[0];
                        //product_icon.tpl
                        $galleryItemPattern = '<a\\b[^>]*+>[^<]*+' . '<img\\b[^>]*+>[^<]*+' . '</a>';
                        $index = 0;
                        $html = $tool->getMainTemplate(array('id' => $block . $product['product_id'] . "_{$index}", 'group' => $block . $tool->params->getValue('block-id') . "_{$product['product_id']}", 'img' => $img, 'thumb' => fn_magiczoom_create_thumb($imagePath, 'thumb', $product['product_id']), 'title' => $product['product'], 'link' => $useLink ? fn_url("products.view?product_id={$product['product_id']}") : ''));
                        $galleryHTML = preg_replace('#' . $galleryItemPattern . '#is', str_replace('$', '\\$', $html), $galleryHTML, 1);
                        foreach ($imagePairs as $imagePair) {
                            $index++;
                            if (isset($imagePair['detailed']['image_path'])) {
                                $imagePath = $imagePair['detailed']['image_path'];
                                $imageAlt = $imagePair['detailed']['alt'];
                            } else {
                                $imagePath = $imagePair['icon']['image_path'];
                                $imageAlt = $imagePair['icon']['alt'];
                            }
                            $img = fn_magiczoom_create_thumb($imagePath, 'original', $product['product_id']);
                            if (!$img) {
                                continue;
                            }
                            //NOTE: possibly image does not exists
                            $html = $tool->getMainTemplate(array('id' => $block . $product['product_id'] . "_{$index}", 'group' => $block . $tool->params->getValue('block-id') . "_{$product['product_id']}", 'img' => $img, 'thumb' => fn_magiczoom_create_thumb($imagePath, 'thumb', $product['product_id']), 'title' => $product['product'], 'link' => $useLink ? fn_url("products.view?product_id={$product['product_id']}") : ''));
                            $galleryHTML = preg_replace('#' . $galleryItemPattern . '#is', str_replace('$', '\\$', $html), $galleryHTML, 1);
                        }
                        $contents = str_replace($matches[0], $galleryHTML, $contents);
                    }
                } else {
                    $html = $tool->getMainTemplate(array('id' => $block . $product['product_id'], 'group' => $block . $tool->params->getValue('block-id'), 'img' => $img, 'thumb' => fn_magiczoom_create_thumb($imagePath, 'thumb', $product['product_id']), 'title' => $product['product'], 'link' => $useLink ? fn_url("products.view?product_id={$product['product_id']}") : ''));
                    //products_list.tpl
                    $productListPattern = '(?P<discount><span [^>]*?class="[^"]*?thumb-discount-label[^"]*+"[^>]*+>.*?</span>[^<]*+)?' . '(?P<input1><input [^>]*+>[^<]*+)' . '<img [^>]*?id="det_img_[^"]*?' . $product['product_id'] . '"[^>]*+>';
                    $productListPattern = '(<a [^>]*+>[^<]*+(?P<input2><input [^>]*+>)[^<]*+)?' . $productListPattern . '(?(1)[^<]*+</a>)';
                    //product_icon.tpl (without gallery)
                    $productIconPattern = '<a [^>]*+>[^<]*+' . '(?:<img [^>]*?id="det_img_[^"]*?' . $product['product_id'] . '"[^>]*+>|' . '<img [^>]*?src="' . $srcPattern . '"[^>]*+>)' . '[^<]*+</a>';
                    /*
                    //product_icon.tpl (with gallery)
                    $productIconPattern =
                        '<div [^>]*?id="icons_'.$product['product_id'].'"[^>]*>[^<]*'.//cm-image-gallery
                        '<ul>[^<]*'.
                        '(?:<li [^>]*?class="[^"]*?cm-gallery-item[^"]*"[^>]*>[^<]*'.
                        '<a [^>]*>[^<]*'.
                        '<img [^>]*?id="det_img_[^"]*?'.$product['product_id'].'(?:_[^"]*)?"[^>]*>[^<]*'.
                        '</a>[^<]*'.
                        '</li>[^<]*)+'.
                        '</ul>[^<]*'.
                        '(?:<i [^>]*></i>[^<]*){2}?'.
                        '</div>|'.$productIconPattern;
                    */
                    $matches = array();
                    $matchedData = '';
                    //inputs, span
                    if (preg_match('#' . $productListPattern . '|' . $productIconPattern . '#is', $contents, $matches)) {
                        $matchedData = (empty($matches['discount']) ? '' : $matches['discount']) . (empty($matches['input1']) ? '' : $matches['input1']) . (empty($matches['input2']) ? '' : $matches['input2']);
                        $contents = str_replace($matches[0], $matchedData . $html, $contents);
                    }
                }
            }
            if ($tool->params->getValue('products-scroller')) {
                $contents = str_replace('wrap: \'circular\'', 'wrap: \'both\'', $contents);
            }
            break;
    }
    //setlocale(LC_ALL, $oldLocale);
    $tool->params->resetProfile();
    return $contents;
}
Example #2
0
function magictoolbox_WordPress_MagicZoom_create($content)
{
    $plugin = $GLOBALS['magictoolbox']['WordPressMagicZoom'];
    /*$pattern = "<img([^>]*)(?:>)(?:[^<]*<\/img>)?";
      $pattern = "(?:<a([^>]*)>.*?){$pattern}(.*?)(?:<\/a>)";*/
    $pattern = "(?:<a([^>]*)>)[^<]*<img([^>]*)(?:>)(?:[^<]*<\\/img>)?(.*?)[^<]*?<\\/a>";
    $oldContent = $content;
    $content = preg_replace_callback("/{$pattern}/is", "magictoolbox_WordPress_MagicZoom_callback", $content);
    if ($content == $oldContent) {
        return $content;
    }
    /*$content = str_replace('{MAGICTOOLBOX_'.strtoupper('magiczoom').'_MAIN_IMAGE_SELECTOR}',$GLOBALS['MAGICTOOLBOX_'.strtoupper('magiczoom').'_MAIN_IMAGE_SELECTOR'],$content);  //add main image selector to other
      $content = str_replace('{MAGICTOOLBOX_'.strtoupper('magiczoom').'_SELECTORS}','',$content); //if no selectors - remove constant
       onlyForModend  */
    if (!$plugin->params->checkValue('template', 'original') && $plugin->type == 'standard' && isset($GLOBALS['magictoolbox']['MagicZoom']['main'])) {
        // template helper class
        require_once dirname(__FILE__) . '/core/magictoolbox.templatehelper.class.php';
        MagicToolboxTemplateHelperClass::setPath(dirname(__FILE__) . '/core/templates');
        MagicToolboxTemplateHelperClass::setOptions($plugin->params);
        if (!WordPress_MagicZoom_page_check('WordPress')) {
            //do not render thumbs on category pages
            $thumbs = WordPress_MagicZoom_get_prepared_selectors();
        } else {
            $thumbs = array();
        }
        if (is_array($GLOBALS['MAGICTOOLBOX_' . strtoupper('MagicZoom') . '_SELECTORS'])) {
            $thumbs = array_merge($thumbs, $GLOBALS['MAGICTOOLBOX_' . strtoupper('MagicZoom') . '_SELECTORS']);
        }
        $html = MagicToolboxTemplateHelperClass::render(array('main' => $GLOBALS['magictoolbox']['MagicZoom']['main'], 'thumbs' => count($thumbs) >= 1 ? $thumbs : array(), 'pid' => $GLOBALS['magictoolbox']['prods_info']['product_id']));
        $content = str_replace('MAGICTOOLBOX_PLACEHOLDER', $html, $content);
    } else {
        if ($plugin->params->checkValue('template', 'original') || $plugin->type != 'standard') {
            $html = $GLOBALS['magictoolbox']['MagicZoom']['main'];
            $content = str_replace('MAGICTOOLBOX_PLACEHOLDER', $html, $content);
        }
    }
    return $content;
}
Example #3
0
 public function loadTool($profile = '')
 {
     if (null === self::$_toolCoreClass) {
         $helper = Mage::helper('magiczoomplus/params');
         require_once BP . str_replace('/', DS, '/app/code/local/MagicToolbox/MagicZoomPlus/core/magiczoomplus.module.core.class.php');
         self::$_toolCoreClass = new MagicZoomPlusModuleCoreClass();
         /*
         foreach($helper->getDefaultValues() as $block => $params) {
             foreach($params as $id => $value) {
                 self::$_toolCoreClass->params->setValue($id, $value, $block);
             }
         }
         */
         $store = Mage::app()->getStore();
         $website_id = $store->getWebsiteId();
         $group_id = $store->getGroupId();
         $store_id = $store->getId();
         $designPackage = Mage::getSingleton('core/design_package');
         $interface = $designPackage->getPackageName();
         $theme = $designPackage->getTheme('template');
         $model = Mage::getModel('magiczoomplus/settings');
         $collection = $model->getCollection();
         $zendDbSelect = $collection->getSelect();
         $zendDbSelect->where('(website_id = ?) OR (website_id IS NULL)', $website_id);
         $zendDbSelect->where('(group_id = ?) OR (group_id IS NULL)', $group_id);
         $zendDbSelect->where('(store_id = ?) OR (store_id IS NULL)', $store_id);
         $zendDbSelect->where('(package = ?) OR (package = \'\')', $interface);
         $zendDbSelect->where('(theme = ?) OR (theme = \'\')', $theme);
         $zendDbSelect->order(array('theme DESC', 'package DESC', 'store_id DESC', 'group_id DESC', 'website_id DESC'));
         $_params = $collection->getFirstItem()->getValue();
         if (!empty($_params)) {
             $_params = unserialize($_params);
             foreach ($_params as $block => $params) {
                 if (is_array($params)) {
                     foreach ($params as $id => $value) {
                         self::$_toolCoreClass->params->setValue($id, $value, $block);
                     }
                 }
             }
         }
         foreach ($helper->getBlocks() as $id => $label) {
             switch (self::$_toolCoreClass->params->getValue('enable-effect', $id)) {
                 case 'Zoom':
                     self::$_toolCoreClass->params->setValue('disable-expand', 'Yes', $id);
                     break;
                 case 'Expand':
                     self::$_toolCoreClass->params->setValue('disable-zoom', 'Yes', $id);
                     break;
                 case 'Swap images only':
                     self::$_toolCoreClass->params->setValue('disable-expand', 'Yes', $id);
                     self::$_toolCoreClass->params->setValue('disable-zoom', 'Yes', $id);
                     break;
             }
             /* load locale */
             $locale = $this->__('MagicZoomPlus_LoadingMessage');
             if (strpos($locale, 'MagicZoomPlus_LoadingMessage') === false) {
                 //if($locale != 'MagicZoomPlus_LoadingMessage') {
                 self::$_toolCoreClass->params->setValue('loading-msg', $locale, $id);
             }
             $locale = $this->__('MagicZoomPlus_Message');
             if (strpos($locale, 'MagicZoomPlus_Message') === false) {
                 //if($locale != 'MagicZoomPlus_Message') {
                 self::$_toolCoreClass->params->setValue('message', $locale, $id);
             }
         }
         if (self::$_toolCoreClass->params->checkValue('magicscroll', 'yes', 'product')) {
             require_once BP . str_replace('/', DS, '/app/code/local/MagicToolbox/MagicZoomPlus/core/magicscroll.module.core.class.php');
             self::$_scrollCoreClass = new MagicScrollModuleCoreClass();
             self::$_scrollCoreClass->params->setScope('MagicScroll');
             self::$_scrollCoreClass->params->appendParams(self::$_toolCoreClass->params->getParams('product'));
             self::$_scrollCoreClass->params->setValue('direction', self::$_scrollCoreClass->params->checkValue('template', array('left', 'right')) ? 'bottom' : 'right');
         }
         require_once BP . str_replace('/', DS, '/app/code/local/MagicToolbox/MagicZoomPlus/core/magictoolbox.templatehelper.class.php');
         //MagicToolboxTemplateHelperClass::setPath(dirname(Mage::getSingleton('core/design_package')->getTemplateFilename('magiczoomplus'.DS.'media.phtml')) . DS . 'templates');
         MagicToolboxTemplateHelperClass::setPath(dirname(Mage::getSingleton('core/design_package')->getTemplateFilename('magiczoomplus' . DS . 'templates' . DS . preg_replace('/[^a-zA-Z0-9_]/is', '-', self::$_toolCoreClass->params->getValue('template', 'product')) . '.tpl.php')));
         MagicToolboxTemplateHelperClass::setOptions(self::$_toolCoreClass->params);
     }
     if ($profile) {
         self::$_toolCoreClass->params->setProfile($profile);
     }
     return self::$_toolCoreClass;
 }
 static function setOptions($options)
 {
     self::$options = $options;
 }
Example #5
0
function magiczoomplus($content, $currentController = false, $type = false, $info = false)
{
    if (VERSION < 2) {
        $magiczoomplus_status = $currentController->config->get('magiczoomplus_status');
    } else {
        $settings = $currentController->config->get('magiczoomplus_settings');
        $magiczoomplus_status = $settings['magiczoomplus_status'];
    }
    if ($magiczoomplus_status != 0) {
        $tool =& magiczoomplus_load_core_class($currentController);
        //set_params_from_config($currentController->config);
        $enabled_on_this_page = false;
        unset($GLOBALS['magictoolbox']['items']);
        $tool->params->set('disable-expand', 'No');
        $tool->params->set('disable-zoom', 'No');
        if ($tool->type == 'standard') {
            //do not apply MSS-like modules to category & product pages
            if ($type && $type == 'category' && !$tool->params->checkValue('use-effect-on-category-page', 'No')) {
                $enabled_on_this_page = true;
                if ($tool->params->checkValue('use-effect-on-category-page', 'Zoom')) {
                    $tool->params->set('disable-expand', 'Yes');
                    $tool->params->set('disable-zoom', 'No');
                } else {
                    if ($tool->params->checkValue('use-effect-on-category-page', 'Expand')) {
                        $tool->params->set('disable-expand', 'No');
                        $tool->params->set('disable-zoom', 'Yes');
                    }
                }
            }
            if ($type && $type == 'manufacturers' && !$tool->params->checkValue('use-effect-on-manufacturers-page', 'No')) {
                $enabled_on_this_page = true;
                if ($tool->params->checkValue('use-effect-on-manufacturers-page', 'Zoom')) {
                    $tool->params->set('disable-expand', 'Yes');
                    $tool->params->set('disable-zoom', 'No');
                } else {
                    if ($tool->params->checkValue('use-effect-on-manufacturers-page', 'Expand')) {
                        $tool->params->set('disable-expand', 'No');
                        $tool->params->set('disable-zoom', 'Yes');
                    }
                }
            }
            if ($type && $type == 'search' && !$tool->params->checkValue('use-effect-on-search-page', 'No')) {
                $enabled_on_this_page = true;
                if ($tool->params->checkValue('use-effect-on-search-page', 'Zoom')) {
                    $tool->params->set('disable-expand', 'Yes');
                    $tool->params->set('disable-zoom', 'No');
                } else {
                    if ($tool->params->checkValue('use-effect-on-search-page', 'Expand')) {
                        $tool->params->set('disable-expand', 'No');
                        $tool->params->set('disable-zoom', 'Yes');
                    }
                }
            }
            if ($type && $type == 'product' && !$tool->params->checkValue('use-effect-on-product-page', 'No')) {
                $enabled_on_this_page = true;
                if ($tool->params->checkValue('use-effect-on-product-page', 'Zoom')) {
                    $tool->params->set('disable-expand', 'Yes');
                    $tool->params->set('disable-zoom', 'No');
                } else {
                    if ($tool->params->checkValue('use-effect-on-product-page', 'Expand')) {
                        $tool->params->set('disable-expand', 'No');
                        $tool->params->set('disable-zoom', 'Yes');
                    } else {
                        if ($tool->params->checkValue('use-effect-on-product-page', 'Swap images only')) {
                            $tool->params->set('disable-expand', 'Yes');
                            $tool->params->set('disable-zoom', 'Yes');
                        }
                    }
                }
            }
        }
        if ($tool->type == 'circle') {
            //Apply 360 only to Products Page
            if ($type && $type == 'product') {
                $enabled_on_this_page = true;
            }
        } else {
            if ($type && ($type == 'latest_home_category' || $type == 'latest_home' || $type == 'latest_right' || $type == 'latest_left' || $type == 'latest_content_top' || $type == 'latest_content_bottom' || $type == 'latest_column_left' || $type == 'latest_column_right') && !$tool->params->checkValue('use-effect-on-latest-box', 'No')) {
                $enabled_on_this_page = true;
                if ($tool->params->checkValue('use-effect-on-latest-box', 'Zoom')) {
                    $tool->params->set('disable-expand', 'Yes');
                    $tool->params->set('disable-zoom', 'No');
                } else {
                    if ($tool->params->checkValue('use-effect-on-latest-box', 'Expand')) {
                        $tool->params->set('disable-expand', 'No');
                        $tool->params->set('disable-zoom', 'Yes');
                    }
                }
            }
            if ($type && ($type == 'featured_home' || $type == 'featured_right' || $type == 'featured_left' || $type == 'featured_left' || $type == 'featured_content_top' || $type == 'featured_content_bottom' || $type == 'featured_column_left' || $type == 'featured_column_right') && !$tool->params->checkValue('use-effect-on-featured-box', 'No')) {
                $enabled_on_this_page = true;
                if ($tool->params->checkValue('use-effect-on-featured-box', 'Zoom')) {
                    $tool->params->set('disable-expand', 'Yes');
                    $tool->params->set('disable-zoom', 'No');
                } else {
                    if ($tool->params->checkValue('use-effect-on-featured-box', 'Expand')) {
                        $tool->params->set('disable-expand', 'No');
                        $tool->params->set('disable-zoom', 'Yes');
                    }
                }
            }
            if ($type && ($type == 'special_home' || $type == 'special_right' || $type == 'special_left' || $type == 'special_content_top' || $type == 'special_content_bottom' || $type == 'special_column_left' || $type == 'special_column_right') && !$tool->params->checkValue('use-effect-on-special-box', 'No')) {
                $enabled_on_this_page = true;
                if ($tool->params->checkValue('use-effect-on-special-box', 'Zoom')) {
                    $tool->params->set('disable-expand', 'Yes');
                    $tool->params->set('disable-zoom', 'No');
                } else {
                    if ($tool->params->checkValue('use-effect-on-special-box', 'Expand')) {
                        $tool->params->set('disable-expand', 'No');
                        $tool->params->set('disable-zoom', 'Yes');
                    }
                }
            }
            if ($type && ($type == 'bestseller_home' || $type == 'bestseller_right' || $type == 'bestseller_left' || $type == 'bestseller_content_top' || $type == 'bestseller_content_bottom' || $type == 'bestseller_column_left' || $type == 'bestseller_column_right') && !$tool->params->checkValue('use-effect-on-bestsellers-box', 'No')) {
                $enabled_on_this_page = true;
                if ($tool->params->checkValue('use-effect-on-bestsellers-box', 'Zoom')) {
                    $tool->params->set('disable-expand', 'Yes');
                    $tool->params->set('disable-zoom', 'No');
                } else {
                    if ($tool->params->checkValue('use-effect-on-bestsellers-box', 'Expand')) {
                        $tool->params->set('disable-expand', 'No');
                        $tool->params->set('disable-zoom', 'Yes');
                    }
                }
            }
        }
        if ($enabled_on_this_page) {
            if ($type && $info) {
                $GLOBALS['magictoolbox']['page_type'] = $type;
                $GLOBALS['magictoolbox']['prods_info'] = $info;
            } else {
                return $content;
            }
            $oldContent = $content;
            $content = magiczoomplus_parse_contents($content, $currentController);
            if ($oldContent != $content) {
                $content = magiczoomplus_set_headers($content);
            }
            if ($type == 'product' && $tool->type == 'standard' && isset($GLOBALS['magictoolbox']['MagicZoomPlus']['main'])) {
                // template helper class
                require_once MTOOLBOX_ADMIN_FOLDER_magiczoomplus . 'magictoolbox.templatehelper.class.php';
                MagicToolboxTemplateHelperClass::setPath(MTOOLBOX_ADMIN_FOLDER_magiczoomplus . 'templates');
                MagicToolboxTemplateHelperClass::setOptions($tool->params);
                $html = MagicToolboxTemplateHelperClass::render(array('main' => $GLOBALS['magictoolbox']['MagicZoomPlus']['main'], 'thumbs' => count($GLOBALS['magictoolbox']['MagicZoomPlus']['selectors']) > 1 ? $GLOBALS['magictoolbox']['MagicZoomPlus']['selectors'] : array(), 'pid' => $GLOBALS['magictoolbox']['prods_info']['product_id']));
                $content = str_replace('MAGICTOOLBOX_PLACEHOLDER', $html, $content);
            }
        }
    }
    return $content;
}
Example #6
0
function magiczoom($content, $currentController = false, $type = false, $info = false)
{
    if ($currentController->config->get('magiczoom_status') != 0) {
        $tool =& magiczoom_load_core_class($currentController);
        //set_params_from_config($currentController->config);
        $enabled_on_this_page = false;
        unset($GLOBALS['magictoolbox']['items']);
        $tool->params->set('disable-zoom', 'No');
        if ($tool->type == 'standard') {
            //do not apply MSS-like modules to category & product pages
            if ($type && $type == 'category' && !$tool->params->checkValue('use-effect-on-category-page', 'No')) {
                $enabled_on_this_page = true;
            }
            if ($type && $type == 'manufacturers' && !$tool->params->checkValue('use-effect-on-manufacturers-page', 'No')) {
                $enabled_on_this_page = true;
            }
            if ($type && $type == 'product' && !$tool->params->checkValue('use-effect-on-product-page', 'No')) {
                $enabled_on_this_page = true;
                $tool->params->set('disable-zoom', $GLOBALS['magictoolbox']['product-disable-zoom']);
            }
        }
        if ($tool->type == 'circle') {
            //Apply 360 only to Products Page
            if ($type && $type == 'product') {
                $enabled_on_this_page = true;
            }
        } else {
            if ($type && ($type == 'latest_home_category' || $type == 'latest_home' || $type == 'latest_right' || $type == 'latest_left' || $type == 'latest_content_top' || $type == 'latest_content_bottom' || $type == 'latest_column_left' || $type == 'latest_column_right') && !$tool->params->checkValue('use-effect-on-latest-box', 'No')) {
                $enabled_on_this_page = true;
            }
            if ($type && ($type == 'featured_home' || $type == 'featured_right' || $type == 'featured_left' || $type == 'featured_left' || $type == 'featured_content_top' || $type == 'featured_content_bottom' || $type == 'featured_column_left' || $type == 'featured_column_right') && !$tool->params->checkValue('use-effect-on-featured-box', 'No')) {
                $enabled_on_this_page = true;
            }
            if ($type && ($type == 'special_home' || $type == 'special_right' || $type == 'special_left' || $type == 'special_content_top' || $type == 'special_content_bottom' || $type == 'special_column_left' || $type == 'special_column_right') && !$tool->params->checkValue('use-effect-on-special-box', 'No')) {
                $enabled_on_this_page = true;
            }
            if ($type && ($type == 'bestseller_home' || $type == 'bestseller_right' || $type == 'bestseller_left' || $type == 'bestseller_content_top' || $type == 'bestseller_content_bottom' || $type == 'bestseller_column_left' || $type == 'bestseller_column_right') && !$tool->params->checkValue('use-effect-on-bestsellers-box', 'No')) {
                $enabled_on_this_page = true;
            }
        }
        //if ($type == 'product' || $type == 'category')  { //hack! TODO: load headers only if we need them
        //    $content = set_headers($content);
        //}
        if ($enabled_on_this_page) {
            if ($type) {
                $GLOBALS['magictoolbox']['page_type'] = $type;
            }
            if ($info) {
                $GLOBALS['magictoolbox']['prods_info'] = $info;
            }
            $content = set_headers($content);
            $content = parse_contents($content, $currentController);
            if ($type == 'product' && $tool->type == 'standard' && isset($GLOBALS['magictoolbox']['MagicZoom']['main'])) {
                // template helper class
                require_once dirname(__FILE__) . '/magictoolbox.templatehelper.class.php';
                MagicToolboxTemplateHelperClass::setPath(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'templates');
                MagicToolboxTemplateHelperClass::setOptions($tool->params);
                $html = MagicToolboxTemplateHelperClass::render(array('main' => $GLOBALS['magictoolbox']['MagicZoom']['main'], 'thumbs' => count($GLOBALS['magictoolbox']['MagicZoom']['selectors']) > 1 ? $GLOBALS['magictoolbox']['MagicZoom']['selectors'] : array(), 'pid' => $GLOBALS['magictoolbox']['prods_info']['product_id']));
                $content = str_replace('MAGICTOOLBOX_PLACEHOLDER', $html, $content);
            }
        }
    }
    return $content;
}
 public function parseTemplateStandard($output, $smarty)
 {
     $output = self::prepareOutput($output);
     if (Configuration::get('PS_FORCE_SMARTY_2') === "0") {
         //Smarty v3 template engine
         //$currentTemplate = substr(basename($smarty->_current_file), 0, -4);
         $currentTemplate = substr(basename($smarty->template_resource), 0, -4);
         if ($currentTemplate == 'breadcrumb') {
             $currentTemplate = 'product';
         } elseif ($currentTemplate == 'pagination') {
             $currentTemplate = 'category';
         }
         $getTemplateVars = 'getTemplateVars';
     } else {
         //Smarty v2 template engine
         $currentTemplate = $smarty->currentTemplate;
         $getTemplateVars = 'get_template_vars';
     }
     switch ($currentTemplate) {
         case 'manufacturer':
             $currentTemplate = 'manufacturer';
             break;
         case 'best-sales':
             $currentTemplate = 'bestsellerspage';
             break;
         case 'new-products':
             $currentTemplate = 'newproductpage';
             break;
         case 'prices-drop':
             $currentTemplate = 'specialspage';
             break;
     }
     $tool = $this->loadTool();
     if (!$tool->params->profileExists($currentTemplate) || $tool->params->checkValue('enable-effect', 'No', $currentTemplate)) {
         return self::prepareOutput($output);
     }
     $tool->params->setProfile($currentTemplate);
     global $link;
     $cookie =& $GLOBALS['magictoolbox']['magiczoomplus']['cookie'];
     if (method_exists($link, 'getImageLink')) {
         $_link =& $link;
     } else {
         //for Prestashop ver 1.1
         $_link =& $this;
     }
     switch ($currentTemplate) {
         case 'homefeatured':
             $GLOBALS['magictoolbox']['magiczoomplus']['headers'] = true;
             $category = new Category(1);
             $nb = intval(Configuration::get('HOME_FEATURED_NBR'));
             //Number of product displayed
             $products = $category->getProducts(intval($cookie->id_lang), 1, $nb ? $nb : 10);
             foreach ($products as $product) {
                 $lrw = $product['link_rewrite'];
                 if (!$tool->params->checkValue('link-to-product-page', 'No')) {
                     $lnk = $link->getProductLink($product['id_product'], $lrw);
                 } else {
                     $lnk = false;
                 }
                 $thumb = $_link->getImageLink($lrw, $product['id_image'], $tool->params->getValue('thumb-image'));
                 $image = $tool->getMainTemplate(array('id' => 'homefeatured' . $product['id_image'], 'group' => 'homefeatured', 'link' => $lnk, 'img' => $_link->getImageLink($lrw, $product['id_image'], $tool->params->getValue('large-image')), 'thumb' => $thumb, 'title' => $product['name'], 'shortDescription' => $product['description_short'], 'description' => $product['description']));
                 //need a.product_image > img for blockcart module
                 $image = '<div class="MagicToolboxContainer"><div style="width:0px;height:1px;overflow:hidden;visibility:hidden;"><a class="product_image" href="#"><img src="' . $thumb . '" /></a></div>' . $image . '</div>';
                 //$image = '<div class="MagicToolboxContainer">' . $image . '</div>';
                 $pattern = '<img src="[^"]*?' . preg_quote($_link->getImageLink($lrw, $product['id_image'], 'home'), '/') . '"[^>]*?>';
                 $pattern = '(?:<a[^>]*?href="[^"]*?"[^>]*>\\s*)?' . $pattern . '(?:\\s*<\\/a>)?';
                 $output = preg_replace('/' . $pattern . '/is', $image, $output);
             }
             break;
         case 'category':
         case 'manufacturer':
         case 'newproductpage':
         case 'bestsellerspage':
         case 'specialspage':
             //global $p, $n, $orderBy, $orderWay;
             //$category = new Category(intval(Tools::getValue('id_category')), intval($cookie->id_lang));
             //$products = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay);
             $GLOBALS['magictoolbox']['magiczoomplus']['headers'] = true;
             $products = $smarty->{$getTemplateVars}('products');
             foreach ($products as $product) {
                 $lrw = $product['link_rewrite'];
                 if (!$tool->params->checkValue('link-to-product-page', 'No')) {
                     $lnk = $link->getProductLink($product['id_product'], $lrw);
                 } else {
                     $lnk = false;
                 }
                 $thumb = $_link->getImageLink($lrw, $product['id_image'], $tool->params->getValue('thumb-image'));
                 $image = $tool->getMainTemplate(array('id' => 'category' . $product['id_image'], 'group' => 'category', 'link' => $lnk, 'img' => $_link->getImageLink($lrw, $product['id_image'], $tool->params->getValue('large-image')), 'thumb' => $thumb, 'title' => $product['name'], 'shortDescription' => $product['description_short'], 'description' => $product['description']));
                 //$image = preg_replace('/<a class="MagicZoomPlus"/is', '<a class="MagicZoomPlus product_img_link"', $image);
                 $image_suffix = $tool->params->getValue('thumb-image') ? '-' . $tool->params->getValue('thumb-image') : '';
                 $file_path = _PS_PROD_IMG_DIR_ . $product['id_image'] . $image_suffix . '.jpg';
                 if (!file_exists($file_path)) {
                     $split_ids = explode('-', $product['id_image']);
                     $id_image = isset($split_ids[1]) ? $split_ids[1] : $split_ids[0];
                     $folders = implode('/', str_split((string) $id_image)) . '/';
                     $file_path = _PS_PROD_IMG_DIR_ . $folders . $id_image . $image_suffix . '.jpg';
                 }
                 $size = getimagesize($file_path);
                 //need a.product_img_link > img for blockcart module
                 $image = '<div class="MagicToolboxContainer" style="float: left; width: ' . $size[0] . 'px; margin-right: 0.6em;" ><div style="width:0px;height:1px;overflow:hidden;visibility:hidden;"><a class="product_img_link" href="#"><img src="' . $thumb . '" /></a></div>' . $image . '</div>';
                 //$image = '<div class="MagicToolboxContainer" style="float: left; width: '.$size[0].'px; margin-right: 0.6em;" >'.$image.'</div>';
                 $pattern = '<img src="[^"]*?' . preg_quote($_link->getImageLink($lrw, $product['id_image'], 'home'), '/') . '"[^>]*?>';
                 $pattern = '(<a[^>]*?href="[^"]*?"[^>]*>\\s*)?' . $pattern . '(\\s*<\\/a>)?';
                 $output = preg_replace('/' . $pattern . '/is', $image, $output);
             }
             break;
         case 'product':
             if (!isset($GLOBALS['magictoolbox']['magiczoomplus']['product'])) {
                 //for skip loyalty module product.tpl
                 return self::prepareOutput($output);
             }
             //$product = new Product(intval($smarty->$tpl_vars['product']->id), true, intval($cookie->id_lang));
             //get some data from $GLOBALS for compatible with Prestashop modules which reset the $product smarty variable
             $product = new Product(intval($GLOBALS['magictoolbox']['magiczoomplus']['product']['id']), true, intval($cookie->id_lang));
             $lrw = $product->link_rewrite;
             $pid = $product->id;
             $images = $product->getImages(intval($cookie->id_lang));
             $productImages = array();
             foreach ($images as $image) {
                 if ($image['cover']) {
                     $cover = $image;
                     $cover['id_image'] = intval($product->id) . '-' . $cover['id_image'];
                 }
                 $productImages[intval($image['id_image'])] = $image;
             }
             if (!isset($cover)) {
                 // ensure that we have the image
                 return self::prepareOutput($output);
             }
             $GLOBALS['magictoolbox']['magiczoomplus']['headers'] = true;
             $thumb = $_link->getImageLink($lrw, $cover['id_image'], $tool->params->getValue('thumb-image'));
             $image = $tool->getMainTemplate(array('id' => 'MainImage', 'img' => $_link->getImageLink($lrw, $cover['id_image'], $tool->params->getValue('large-image')), 'thumb' => $thumb, 'title' => $product->name, 'shortDescription' => $product->description_short, 'description' => $product->description));
             $iTypes = $this->getImagesTypes();
             $selectors = array();
             if (count($productImages) > 0) {
                 $pattern = '<img[^>]*?src="[^"]*?{medium}"[^>]*>';
                 //$pattern = '(<a[^>]*?href="[^"]*?{thickbox}"[^>]*>\s*)?' . $pattern . '(\s*<\/a>)?';
                 $pattern = '(<a[^>]*?href="[^"]*"[^>]*>\\s*)?' . $pattern . '(\\s*<\\/a>)?';
                 foreach ($productImages as $i) {
                     $s = $tool->getSelectorTemplate(array('id' => 'MainImage', 'img' => $_link->getImageLink($lrw, $pid . '-' . $i['id_image'], $tool->params->getValue('large-image')), 'medium' => $_link->getImageLink($lrw, $pid . '-' . $i['id_image'], $tool->params->getValue('thumb-image')), 'thumb' => $_link->getImageLink($lrw, $pid . '-' . $i['id_image'], $tool->params->getValue('selector-image')), 'title' => $i['legend']));
                     $s = str_replace('<img ', '<img id="thumb_' . $i['id_image'] . '" ', $s);
                     $s = str_replace('<a ', '<a class="magicthickbox" ', $s);
                     //$p = str_replace('{thickbox}', preg_quote($_link->getImageLink($lrw, $pid . '-' . $i['id_image'], 'thickbox'), '/'), $pattern);
                     //$p = str_replace('{medium}', preg_quote($_link->getImageLink($lrw, $pid . '-' . $i['id_image'], 'medium'), '/'), $p);
                     $p = str_replace('{medium}', preg_quote($_link->getImageLink($lrw, $pid . '-' . $i['id_image'], 'medium'), '/'), $pattern);
                     $replaced = 0;
                     if ($tool->params->checkValue('template', 'original')) {
                         // append selector in their preserved place
                         $output = preg_replace('/' . $p . '/is', $s, $output, -1, $replaced);
                         if (!$replaced) {
                             $p = '(<a[^>]*?href="[^"]*"[^>]*>\\s*)?<img[^>]*?id="thumb_' . $i['id_image'] . '"[^>]*>(\\s*<\\/a>)?';
                             $output = preg_replace('/' . $p . '/is', $s, $output, -1, $replaced);
                         }
                     } else {
                         // remove selector from contents
                         $output = preg_replace('/' . $p . '/is', '', $output, -1, $replaced);
                         if (!$replaced) {
                             $p = '(<a[^>]*?href="[^"]*"[^>]*>\\s*)?<img[^>]*?id="thumb_' . $i['id_image'] . '"[^>]*>(\\s*<\\/a>)?';
                             $output = preg_replace('/' . $p . '/is', $s, $output, -1, $replaced);
                         }
                         $selectors[] = $s;
                     }
                 }
             }
             // append selectors
             if (!$tool->params->checkValue('template', 'original')) {
                 //remove selectors from contents
                 $pattern = '<div id="thumbs_list">.*?<\\/div>';
                 $output = preg_replace('/<div id="thumbs_list">.*?<\\/div>/is', '', $output);
                 $output = preg_replace('/<\\!-- thumbnails -->\\s*<div id="views_block"\\s*>.*?<\\/div>/is', '<!-- thumbnails -->', $output);
                 $output = preg_replace('/<\\!-- thumbnails -->\\s*<p[^>]*><a[^>]+reset[^>]+>.*?<\\/a><\\/p>/is', '<!-- thumbnails -->', $output);
                 //remove "View full size" link
                 $output = preg_replace('/<li>[^<]*?<span[^>]*?id="view_full_size"[^>]*?>[^<]*?<\\/span>[^<]*?<\\/li>/is', '', $output);
             } else {
                 $tool->params->setValue('template', 'bottom');
             }
             // we need this sizes for template renderer
             $sql = 'SELECT name,width,height FROM `' . _DB_PREFIX_ . 'image_type` WHERE name in (\'' . $tool->params->getValue('thumb-image') . '\',\'' . $tool->params->getValue('selector-image') . '\')';
             $result = Db::getInstance()->ExecuteS($sql);
             $result[$result[0]['name']] = $result[0];
             $result[$result[1]['name']] = $result[1];
             $tool->params->setValue('thumb-max-width', $result[$tool->params->getValue('thumb-image')]['width']);
             $tool->params->setValue('thumb-max-height', $result[$tool->params->getValue('thumb-image')]['height']);
             $tool->params->setValue('selector-max-width', $result[$tool->params->getValue('selector-image')]['width']);
             $tool->params->setValue('selector-max-height', $result[$tool->params->getValue('selector-image')]['height']);
             require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magictoolbox.templatehelper.class.php';
             MagicToolboxTemplateHelperClass::setPath(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'templates');
             MagicToolboxTemplateHelperClass::setOptions($tool->params);
             $html = MagicToolboxTemplateHelperClass::render(array('main' => $image, 'thumbs' => $selectors, 'pid' => $pid));
             //need img#bigpic for blockcart module
             $html = preg_replace('/(<div class="MagicToolboxContainer"[^>]*>)/is', '$1<div style="width:0px;height:1px;overflow:hidden;visibility:hidden;"><img id="bigpic" src="' . $thumb . '" /></div>', $html);
             // append main image
             $replaced = 0;
             $pattern = '<img src="[^"]*?' . preg_quote($_link->getImageLink($lrw, $cover['id_image'], 'large'), '/') . '".*?>';
             $output = preg_replace('/' . $pattern . '/is', $html, $output, -1, $replaced);
             if (!$replaced) {
                 $iTypes = $this->getImagesTypes();
                 foreach ($iTypes as $iType) {
                     if ($iType != 'large') {
                         $pattern = '<img src="[^"]*?' . preg_quote($_link->getImageLink($lrw, $cover['id_image'], $iType), '/') . '".*?>';
                         $output = preg_replace('/' . $pattern . '/is', $html, $output, -1, $replaced);
                         if ($replaced) {
                             break;
                         }
                     }
                 }
             }
             break;
         case 'blockspecials':
             $GLOBALS['magictoolbox']['magiczoomplus']['headers'] = true;
             //$product = $smarty->get_template_vars('special');
             $product = $smarty->{$getTemplateVars}('special');
             $lrw = $product['link_rewrite'];
             if (!$tool->params->checkValue('link-to-product-page', 'No') && (!isset($_GET['id_product']) || $_GET['id_product'] != $product['id_product'])) {
                 $lnk = $link->getProductLink($product['id_product'], $lrw);
             } else {
                 $lnk = false;
             }
             $image = $tool->getMainTemplate(array('id' => 'blockspecials' . $product['id_image'], 'group' => 'blockspecials', 'link' => $lnk, 'img' => $_link->getImageLink($lrw, $product['id_image'], $tool->params->getValue('large-image')), 'thumb' => $_link->getImageLink($lrw, $product['id_image'], $tool->params->getValue('thumb-image')), 'title' => $product['name'], 'shortDescription' => $product['description_short'], 'description' => $product['description']));
             $image = '<div class="MagicToolboxContainer">' . $image . '</div>';
             $pattern = '<img src="[^"]*?' . preg_quote($_link->getImageLink($lrw, $product['id_image'], 'medium'), '/') . '"[^>]*?>';
             $pattern = '(<a[^>]*?href="[^"]*?"[^>]*>\\s*)?' . $pattern . '(\\s*<\\/a>)?';
             $output = preg_replace('/' . $pattern . '/is', $image, $output);
             break;
         case 'blockviewed':
             $productsViewed = array_slice($GLOBALS['magictoolbox']['magiczoomplus']['productsViewed'], 0, Configuration::get('PRODUCTS_VIEWED_NBR'));
             if (sizeof($productsViewed)) {
                 foreach ($productsViewed as $id_product) {
                     $productViewedObj = new Product(intval($id_product), false, intval($cookie->id_lang));
                     if (!Validate::isLoadedObject($productViewedObj) or !$productViewedObj->active) {
                         continue;
                     } else {
                         $GLOBALS['magictoolbox']['magiczoomplus']['headers'] = true;
                         $images = $productViewedObj->getImages(intval($cookie->id_lang));
                         foreach ($images as $image) {
                             if ($image['cover']) {
                                 $productViewedObj->cover = $productViewedObj->id . '-' . $image['id_image'];
                                 $productViewedObj->legend = $image['legend'];
                                 break;
                             }
                         }
                         if (!isset($productViewedObj->cover)) {
                             $productViewedObj->cover = Language::getIsoById($cookie->id_lang) . '-default';
                             $productViewedObj->legend = '';
                         }
                         $lrw = $productViewedObj->link_rewrite;
                         if (!$tool->params->checkValue('link-to-product-page', 'No') && (!isset($_GET['id_product']) || $_GET['id_product'] != $id_product)) {
                             $lnk = $link->getProductLink($id_product, $lrw);
                         } else {
                             $lnk = false;
                         }
                         $image = $tool->getMainTemplate(array('id' => 'blockviewed' . $id_product, 'group' => 'blockviewed', 'link' => $lnk, 'img' => $_link->getImageLink($lrw, $productViewedObj->cover, $tool->params->getValue('large-image')), 'thumb' => $_link->getImageLink($lrw, $productViewedObj->cover, $tool->params->getValue('thumb-image')), 'title' => $productViewedObj->name, 'shortDescription' => $productViewedObj->description_short, 'description' => $productViewedObj->description));
                         $image_suffix = $tool->params->getValue('thumb-image') ? '-' . $tool->params->getValue('thumb-image') : '';
                         $file_path = _PS_PROD_IMG_DIR_ . $productViewedObj->cover . $image_suffix . '.jpg';
                         if (!file_exists($file_path)) {
                             $split_ids = explode('-', $productViewedObj->cover);
                             $id_image = isset($split_ids[1]) ? $split_ids[1] : $split_ids[0];
                             $folders = implode('/', str_split((string) $id_image)) . '/';
                             $file_path = _PS_PROD_IMG_DIR_ . $folders . $id_image . $image_suffix . '.jpg';
                         }
                         $size = getimagesize($file_path);
                         $image = '<div class="MagicToolboxContainer" style="float: left; width: ' . $size[0] . 'px;">' . $image . '</div>';
                         $pattern = '<img src="[^"]*?' . preg_quote($_link->getImageLink($lrw, $productViewedObj->cover, 'medium'), '/') . '"[^>]*?>';
                         $pattern = '(<a[^>]*?href="[^"]*?"[^>]*>\\s*)?' . $pattern . '(\\s*<\\/a>)?';
                         $output = preg_replace('/' . $pattern . '/is', $image, $output);
                     }
                 }
             }
             break;
         case 'blockbestsellers':
             $blockbestsellers = true;
         case 'blocknewproducts':
             if (isset($blockbestsellers)) {
                 //$products = $smarty->$getTemplateVars('best_sellers');
                 //to get with description etc.
                 $products = ProductSale::getBestSales(intval($cookie->id_lang), 0, 4);
             } else {
                 $products = $smarty->{$getTemplateVars}('new_products');
             }
             $pCount = count($products);
             if ($pCount) {
                 $GLOBALS['magictoolbox']['magiczoomplus']['headers'] = true;
                 for ($i = 0; $i < 2 && $i < $pCount; $i++) {
                     $lrw = $products[$i]['link_rewrite'];
                     if (!$tool->params->checkValue('link-to-product-page', 'No') && (!isset($_GET['id_product']) || $_GET['id_product'] != $products[$i]['id_product'])) {
                         $lnk = $link->getProductLink($products[$i]['id_product'], $lrw);
                     } else {
                         $lnk = false;
                     }
                     $image = $tool->getMainTemplate(array('id' => $currentTemplate . $products[$i]['id_image'], 'group' => $currentTemplate, 'link' => $lnk, 'img' => $_link->getImageLink($lrw, $products[$i]['id_image'], $tool->params->getValue('large-image')), 'thumb' => $_link->getImageLink($lrw, $products[$i]['id_image'], $tool->params->getValue('thumb-image')), 'title' => $products[$i]['name'], 'shortDescription' => $products[$i]['description_short'], 'description' => $products[$i]['description']));
                     $image = '<div class="MagicToolboxContainer">' . $image . '</div>';
                     $pattern = '<img src="[^"]*?' . preg_quote($_link->getImageLink($lrw, $products[$i]['id_image'], 'medium'), '/') . '"[^>]*?>';
                     $pattern = '(<a[^>]*?href="[^"]*?"[^>]*>\\s*)?' . $pattern . '(\\s*<\\/a>)?';
                     $output = preg_replace('/' . $pattern . '/is', $image, $output);
                 }
             }
             break;
     }
     return self::prepareOutput($output);
 }