private function insertMediaGalleries($text, Ess_M2ePro_Model_Magento_Product $magentoProduct) { preg_match_all("/#media_gallery\\[(.*?)\\]#/", $text, $matches); if (!count($matches[0])) { return $text; } $blockObj = Mage::getSingleton('core/layout')->createBlock('M2ePro/adminhtml_renderer_description_gallery'); $search = array(); $replace = array(); $attributeCounter = 0; foreach ($matches[0] as $key => $match) { $tempMediaGalleryAttributes = explode(',', $matches[1][$key]); $realMediaGalleryAttributes = array(); for ($i = 0; $i < 8; $i++) { if (!isset($tempMediaGalleryAttributes[$i])) { $realMediaGalleryAttributes[$i] = ''; } else { $realMediaGalleryAttributes[$i] = $tempMediaGalleryAttributes[$i]; } } $imagesQty = (int) $realMediaGalleryAttributes[5]; if ($imagesQty == self::IMAGES_QTY_ALL) { $imagesQty = $realMediaGalleryAttributes[3] == self::IMAGES_MODE_GALLERY ? 100 : 25; } $galleryImagesLinks = $magentoProduct->getGalleryImagesLinks($imagesQty); if (!count($galleryImagesLinks)) { $search = $matches[0]; $replace = ''; break; } if (!in_array($realMediaGalleryAttributes[4], array(self::LAYOUT_MODE_ROW, self::LAYOUT_MODE_COLUMN))) { $realMediaGalleryAttributes[4] = self::LAYOUT_MODE_ROW; } $data = array('width' => (int) $realMediaGalleryAttributes[0], 'height' => (int) $realMediaGalleryAttributes[1], 'margin' => (int) $realMediaGalleryAttributes[2], 'linked_mode' => (int) $realMediaGalleryAttributes[3], 'layout' => $realMediaGalleryAttributes[4], 'gallery_hint' => trim($realMediaGalleryAttributes[6], '"'), 'watermark' => (int) $realMediaGalleryAttributes[7], 'images_count' => count($galleryImagesLinks), 'image_counter' => 0); $tempHtml = ''; $attributeCounter++; foreach ($galleryImagesLinks as $imageLink) { $data['image_counter']++; $data['attribute_counter'] = $attributeCounter; $data['src'] = $imageLink; $tempHtml .= $blockObj->addData($data)->toHtml(); } $search[] = $match; $replace[] = preg_replace('/\\s{2,}/', '', $tempHtml); } $text = str_replace($search, $replace, $text); return $text; }
public function getGalleryImagesLinks($limitImages = 0) { $cacheKey = array(__METHOD__, func_get_args()); if ($this->isCacheEnabled && !is_null($cacheResult = $this->getCache()->getData($cacheKey))) { return $cacheResult; } return $this->getCache()->setData($cacheKey, parent::getGalleryImagesLinks($limitImages)); }