3 require_once dirname(__FILE__) .
"/../bootstrap.php";
6 if (!function_exists(
"getShopBasePath")) {
12 function getShopBasePath()
14 return realpath(dirname(__FILE__) .
'/..') .
'/';
20 if (!function_exists(
'isAdmin')) {
33 if (!function_exists(
"getConfig")) {
42 include_once getShopBasePath() .
'modules/functions.php';
45 include_once getShopBasePath() .
'core/oxfunctions.php';
53 if (!function_exists(
"getGeneratorInstanceName")) {
59 function getGeneratorInstanceName()
61 return "oxdynimggenerator";
66 if (!function_exists(
"getGdVersion")) {
72 function getGdVersion()
74 static $iVersion = null;
76 if ($iVersion === null) {
78 if (function_exists(
"gd_info")) {
81 if (isset($aInfo[
"GD Version"])) {
82 $iVersion = version_compare(preg_replace(
"/[^0-9\.]/",
"", $aInfo[
"GD Version"]), 1,
'>') ? 2 : 1;
93 if (!function_exists(
"includeImageUtils")) {
97 function includeImageUtils()
99 include_once getShopBasePath() .
"core/utils/oxpicgenerator.php";
158 "sIconsize" =>
'/.*\/generated\/product\/(icon|\d+)\/\d+\_\d+\_\d+$/',
159 "sThumbnailsize" =>
'/.*\/generated\/product\/(thumb|\d+)\/\d+\_\d+\_\d+$/',
160 "sZoomImageSize" =>
'/.*\/generated\/product\/\d+\/\d+\_\d+\_\d+$/',
161 "aDetailImageSizes" =>
'/.*\/generated\/product\/\d+\/\d+\_\d+\_\d+$/',
164 "sManufacturerIconsize" =>
'/.*\/generated\/(manufacturer|vendor)\/icon\/\d+\_\d+\_\d+$/',
167 "sCatThumbnailsize" =>
'/.*\/generated\/category\/thumb\/\d+\_\d+\_\d+$/',
168 "sCatIconsize" =>
'/.*\/generated\/category\/icon\/\d+\_\d+\_\d+$/',
169 "sCatPromotionsize" =>
'/.*\/generated\/category\/promo_icon\/\d+\_\d+\_\d+$/'
179 if (self::$_oInstance === null) {
180 $sInstanceName = getGeneratorInstanceName();
181 self::$_oInstance =
new $sInstanceName();
200 if (defined(
'OXID_PHP_UNIT')) {
201 if (substr($sMethod, 0, 4) ==
"UNIT") {
202 $sMethod = str_replace(
"UNIT",
"_", $sMethod);
204 if (method_exists($this, $sMethod)) {
205 return call_user_func_array(array(& $this, $sMethod), $aArgs);
209 throw new oxSystemComponentException(
"Function '$sMethod' does not exist or is not accessible! (" . get_class($this) .
")" . PHP_EOL);
219 return getConfig()->getConfigParam(
"sShopDir");
229 if ($this->_sImageUri === null) {
231 $this->_sImageUri =
"";
232 $sReqPath =
"out/pictures/generated";
235 $sReqImg = isset($_SERVER[
"REQUEST_URI"]) ? urldecode($_SERVER[
"REQUEST_URI"]) :
"";
236 if (($iPos = strpos($sReqImg, $sReqPath)) !==
false) {
237 $this->_sImageUri = substr($sReqImg, $iPos);
240 $this->_sImageUri = trim($this->_sImageUri,
"/");
266 if ($sUri && ($sPath = dirname(dirname($sUri)))) {
267 $sPath = preg_replace(
"/\/([^\/]*)\/([^\/]*)\/([^\/]*)$/",
"/master/\\2/\\3/", $sPath);
282 $aInfo = explode($this->_sImageInfoSep, basename(dirname($sUri)));
307 return str_replace($this->
_getImageName(),
"nopic.jpg", $sPath);
317 $sType = preg_replace(
"/.*\.(png|jp(e)?g|gif)$/",
"\\1", $this->
_getImageName());
318 $sType = (strcmp($sType,
"jpg") == 0) ?
"jpeg" : $sType;
320 return in_array($sType, $this->_aAllowedImgTypes) ? $sType :
false;
335 return resizePng($sSource, $sTarget, $iWidth, $iHeight, @getimagesize($sSource), getGdVersion(), null);
349 protected function _generateJpg($sSource, $sTarget, $iWidth, $iHeight, $iQuality)
351 return resizeJpeg($sSource, $sTarget, $iWidth, $iHeight, @getimagesize($sSource), getGdVersion(), null, $iQuality);
366 $aImageInfo = @getimagesize($sSource);
368 return resizeGif($sSource, $sTarget, $iWidth, $iHeight, $aImageInfo[0], $aImageInfo[1], getGdVersion());
382 $sDir = dirname(trim($sPath));
385 if (!is_dir($sDir) && ($blValid = $this->
_isValidPath($sDir))) {
402 $oConfig = getConfig();
403 $sPicFolderPath = dirname($oConfig->getMasterPictureDir());
406 if ($sPicFolderPath && is_dir($sPicFolderPath)) {
409 if (strcmp($sPicFolderPath, substr($sDir, 0, strlen($sPicFolderPath))) == 0) {
411 if (!($blDone = file_exists($sDir))) {
415 if (defined(
'OXID_PHP_UNIT')) {
418 $blDone = mkdir($sDir, $iMode,
true) || file_exists($sDir);
438 if ($iWidth && $iHeight && $sQuality) {
440 $oConfig = getConfig();
445 foreach ($this->_aConfParamToPath as $sParamName => $sPathReg) {
446 if (preg_match($sPathReg, $sPath)) {
450 $sNames .= $oDb->quote($sParamName);
452 if ($sParamName ==
"sManufacturerIconsize" || $sParamName ==
"sCatIconsize") {
453 $sNames .=
", " . $oDb->quote(
"sIconsize");
461 $sDecodeField = $oConfig->getDecodeValueQuery();
464 $sQ =
"select oxshopid from oxconfig where oxvarname = 'sDefaultImageQuality' and
465 {$sDecodeField} = " . $oDb->quote($sQuality);
467 $aShopIds = $oDb->getAll($sQ);
472 foreach ($aShopIds as $aShopId) {
480 $sShopIds .= $oDb->quote($aShopId[
"oxshopid"]);
487 $sCheckSize =
"$iWidth*$iHeight";
490 $sQ =
"select oxvartype, {$sDecodeField} as oxvarvalue from oxconfig
491 where oxvarname in ( {$sNames} ) and oxshopid in ( {$sShopIds} ) order by oxshopid";
493 $aValues = $oDb->getAll($sQ);
494 foreach ($aValues as $aValue) {
495 $aConfValues = (array) $oConfig->decodeValue($aValue[
"oxvartype"], $aValue[
"oxvarvalue"]);
496 foreach ($aConfValues as $sValue) {
497 if (strcmp($sCheckSize, $sValue) == 0) {
528 if ($this->
_lock($sImageTarget)) {
532 switch ($sImageType) {
534 $sPath = $this->
_generatePng($sImageSource, $sImageTarget, $iWidth, $iHeight);
537 $sPath = $this->
_generateJpg($sImageSource, $sImageTarget, $iWidth, $iHeight, $iQuality);
540 $sPath = $this->
_generateGif($sImageSource, $sImageTarget, $iWidth, $iHeight);
550 $sPath = file_exists($sImageTarget) ? $sImageTarget :
false;
582 $this->_hLockHandle = @fopen($this->
_getLockName($sSource),
"w");
583 if ($this->_hLockHandle) {
584 if (!($blLocked = flock($this->_hLockHandle, LOCK_EX))) {
594 if ($this->_hLockHandle = @fopen($this->
_getLockName($sSource),
"w")) {
610 if ($this->_hLockHandle) {
611 flock($this->_hLockHandle, LOCK_UN);
612 fclose($this->_hLockHandle);
637 if (file_exists($sMasterImagePath)) {
641 $sMasterImagePath = $this->
_getShopBasePath() . dirname(dirname($sMasterPath)) .
"/nopic.jpg";
649 if (file_exists($sGenImagePath)) {
650 $sImagePath = $sGenImagePath;
651 } elseif (file_exists($sMasterImagePath)) {
653 $sImagePath = $this->
_generateImage($sMasterImagePath, $sGenImagePath);
675 if (defined(
'OXID_PHP_UNIT')) {
694 foreach ($aHeaders as $sHeader) {
706 @readfile($sImgPath);
717 $this->_aHeaders[] = $sHeader;