42 'CICO' =>
'master/category/icon',
43 'PICO' =>
'master/category/promo_icon',
44 'MICO' =>
'master/manufacturer/icon',
45 'VICO' =>
'master/vendor/icon',
46 'PROMO'=> self::PROMO_PICTURE_DIR,
47 'ICO' =>
'master/product/icon',
48 'TH' =>
'master/product/thumb',
49 'M1' =>
'master/product/1',
50 'M2' =>
'master/product/2',
51 'M3' =>
'master/product/3',
52 'M4' =>
'master/product/4',
53 'M5' =>
'master/product/5',
54 'M6' =>
'master/product/6',
55 'M7' =>
'master/product/7',
56 'M8' =>
'master/product/8',
57 'M9' =>
'master/product/9',
58 'M10' =>
'master/product/10',
59 'M11' =>
'master/product/11',
60 'M12' =>
'master/product/12',
87 'WP' =>
'master/wrapping',
96 protected $_aBadFiles = array(
'php',
'php3',
'php4',
'php5',
'phps',
'php6',
'jsp',
'cgi',
'cmf',
'exe' );
133 if ( $iPicCount =
$myConfig->getConfigParam(
'iPicCount' ) ) {
134 $this->_iMaxPicImgCount = $iPicCount;
159 $this->_iNewFilesCounter = (int) $iNewFilesCounter;
171 if ( isset($sDir) && $sDir !=
"" && substr($sDir, -1) !==
'/' ) {
186 public function copyDir( $sSourceDir, $sTargetDir )
189 $handle = opendir( $sSourceDir );
190 while (
false !== ( $file = readdir( $handle ) ) ) {
191 if ( $file !=
'.' && $file !=
'..' ) {
192 if ( is_dir( $sSourceDir.
'/'.$file ) ) {
195 $sNewSourceDir = $sSourceDir.
'/'.$file;
196 $sNewTargetDir = $sTargetDir.
'/'.$file;
197 if ( strcasecmp( $file,
'CVS' ) && strcasecmp( $file,
'.svn' )) {
198 @mkdir( $sNewTargetDir, 0777 );
199 $this->
copyDir( $sNewSourceDir, $sNewTargetDir );
202 $sSourceFile = $sSourceDir.
'/'.$file;
203 $sTargetFile = $sTargetDir.
'/'.$file;
206 if ( !$oStr->strstr( $sSourceDir,
'dyn_images' ) || $file ==
'nopic.jpg' || $file ==
'nopic_ico.jpg' ) {
207 @copy( $sSourceFile, $sTargetFile );
224 if ( is_dir( $sSourceDir ) ) {
225 if ( $oDir = dir( $sSourceDir ) ) {
227 while (
false !== $sFile = $oDir->read() ) {
228 if ( $sFile ==
'.' || $sFile ==
'..' ) {
232 if ( !$this->
deleteDir( $oDir->path . DIRECTORY_SEPARATOR . $sFile ) ) {
239 return rmdir( $sSourceDir );
241 } elseif ( file_exists( $sSourceDir ) ) {
242 return unlink ( $sSourceDir );
256 $hFile = @fopen( $sPath,
'r' );
258 socket_set_timeout( $hFile, 2 );
259 while ( !feof( $hFile ) ) {
260 $sLine = fgets( $hFile, 4096 );
284 $aFilename = explode(
".", $sValue );
286 $sFileType = trim( $aFilename[count( $aFilename )-1] );
288 if ( isset( $sFileType ) ) {
293 if ( in_array( $sFileType, $this->_aBadFiles ) || ( $blDemo && !in_array( $sFileType, $this->_aAllowedFiles ) ) ) {
298 if ( count( $aFilename ) > 0 ) {
299 unset( $aFilename[count( $aFilename )-1] );
303 if ( isset( $aFilename[0] ) ) {
304 $sFName = $oStr->preg_replace(
'/[^a-zA-Z0-9()_\.-]/',
'', implode(
'.', $aFilename ) );
307 $sValue = $this->
_getUniqueFileName( $sImagePath,
"{$sFName}", $sFileType,
"", $blUnique );
322 $sFolder = array_key_exists( $sType, $this->_aTypeToPath ) ? $this->_aTypeToPath[ $sType ] :
'0';
342 switch ( $sImgConf ) {
343 case 'aDetailImageSizes':
344 $aDetailImageSizes =
$myConfig->getConfigParam( $sImgConf );
345 $sSize =
$myConfig->getConfigParam(
'sDetailImageSize' );
346 if ( isset( $aDetailImageSizes[
'oxpic'.$iImgNum] ) ) {
347 $sSize = $aDetailImageSizes[
'oxpic'.$iImgNum];
351 $sSize =
$myConfig->getConfigParam( $sImgConf );
355 return explode(
'*', $sSize );
371 if ( $sSource === $sTarget ) {
374 $blDone = copy( $sSource, $sTarget );
378 $blDone = @chmod( $sTarget, 0644 );
395 if ( !is_dir( dirname( $sTarget ) ) ) {
396 mkdir(dirname($sTarget), 0744,
true);
398 if ( $sSource === $sTarget ) {
401 $blDone = move_uploaded_file( $sSource, $sTarget );
405 $blDone = @chmod( $sTarget, 0644 );
422 public function processFiles( $oObject = null, $aFiles = array(), $blUseMasterImage =
false, $blUnique =
true )
424 $aFiles = $aFiles ? $aFiles : $_FILES;
425 if ( isset( $aFiles[
'myfile'][
'name'] ) ) {
431 $blDemo = (bool) $oConfig->isDemoShop();
434 $sTmpFolder = $oConfig->getConfigParam(
"sCompileDir" );
436 $iNewFilesCounter = 0;
437 $aSource = $aFiles[
'myfile'][
'tmp_name'];
438 $aError = $aFiles[
'myfile'][
'error'];
439 $sErrorsDescription =
'';
441 $oEx =
oxNew(
"oxExceptionToDisplay" );
443 while ( list( $sKey, $sValue ) = each( $aFiles[
'myfile'][
'name'] ) ) {
445 $sSource = $aSource[$sKey];
446 $iError = $aError[$sKey];
447 $aFiletype = explode(
"@", $sKey );
448 $sKey = $aFiletype[1];
449 $sType = $aFiletype[0];
451 $sValue = strtolower( $sValue );
455 if ( UPLOAD_ERR_OK !== $iError && UPLOAD_ERR_NO_FILE !== $iError ) {
457 $oEx->setMessage( $sErrorsDescription );
462 if ( $sSource && ( $sValue = $this->
_prepareImageName( $sValue, $sType, $blDemo, $sImagePath, $blUnique ) ) ) {
465 $sProcessPath = $sTmpFolder . basename( $sSource );
467 if ( $sProcessPath ) {
469 if ( $blUseMasterImage ) {
471 $blMoved = $this->
_copyFile( $sSource, $sImagePath . $sValue );
473 $blMoved = $this->
_moveImage( $sSource, $sImagePath . $sValue );
480 if ( $oObject && isset( $oObject->$sKey ) ) {
481 $oObject->{$sKey}->setValue( $sValue );
502 function checkFile( $sFile )
506 if ( isset( $aCheckCache[$sFile] ) ) {
507 return $aCheckCache[$sFile];
512 if (is_readable( $sFile)) {
516 $blRet = $this->urlValidate( $sFile );
519 $aCheckCache[$sFile] = $blRet;
532 function urlValidate( $sLink )
534 $aUrlParts = @parse_url( $sLink );
535 $sHost = ( isset( $aUrlParts[
"host"] ) && $aUrlParts[
"host"] ) ? $aUrlParts[
"host"] : null;
539 $sDocumentPath = ( isset( $aUrlParts[
"path"] ) && $aUrlParts[
"path"] ) ? $aUrlParts[
"path"] :
'/';
540 $sDocumentPath .= ( isset( $aUrlParts[
"query"] ) && $aUrlParts[
"query"] ) ?
'?' . $aUrlParts[
"query"] :
'';
542 $sPort = ( isset( $aUrlParts[
"port"] ) && $aUrlParts[
"port"] ) ? $aUrlParts[
"port"] :
'80';
545 if ( ( $oConn = @fsockopen( $sHost, $sPort, $iErrNo, $sErrStr, 30 ) ) ) {
546 fwrite ( $oConn,
"HEAD {$sDocumentPath} HTTP/1.0\r\nHost: {$sHost}\r\n\r\n" );
547 $sResponse = fgets( $oConn, 22 );
550 if ( preg_match(
"/200 OK/", $sResponse ) ) {
569 public function processFile( $sFileName, $sUploadPath )
571 $aFileInfo = $_FILES[$sFileName];
573 $sBasePath = $this->getConfig()->getConfigParam(
'sShopDir');
576 if ( !isset( $aFileInfo[
'name'] ) || !isset( $aFileInfo[
'tmp_name'] ) ) {
577 throw oxNew(
"oxException",
'EXCEPTION_NOFILE' );
581 if ( !
getStr()->preg_match(
'/^[\-_a-z0-9\.]+$/i', $aFileInfo[
'name'] ) ) {
582 throw oxNew(
"oxException",
'EXCEPTION_FILENAMEINVALIDCHARS' );
586 if ( isset( $aFileInfo[
'error'] ) && $aFileInfo[
'error'] ) {
587 throw oxNew(
"oxException",
'EXCEPTION_FILEUPLOADERROR_'.( (
int) $aFileInfo[
'error'] ) );
590 $aPathInfo = pathinfo($aFileInfo[
'name']);
592 $sExt = $aPathInfo[
'extension'];
593 $sFileName = $aPathInfo[
'filename'];
595 $aAllowedUploadTypes = (array) $this->getConfig()->getConfigParam(
'aAllowedUploadTypes' );
596 $aAllowedUploadTypes = array_map(
"strtolower", $aAllowedUploadTypes );
598 if ( !in_array( strtolower( $sExt ), $aAllowedUploadTypes ) ) {
599 throw oxNew(
"oxException",
'EXCEPTION_NOTALLOWEDTYPE' );
602 $sFileName = $this->_getUniqueFileName( $sBasePath . $sUploadPath, $sFileName, $sExt );
604 if ( $this->_moveImage( $aFileInfo[
'tmp_name'], $sBasePath . $sUploadPath .
"/" . $sFileName ) ) {
623 protected function _getUniqueFileName( $sFilePath, $sFileName, $sFileExt, $sSufix =
"", $blUnique =
true )
625 $sFilePath = $this->normalizeDir( $sFilePath );
627 $sTempFileName = $sFileName;
631 while ( $blUnique && file_exists( $sFilePath .
"/" . $sFileName . $sSufix .
"." . $sFileExt ) ) {
635 $sTempFileName = $oStr->preg_replace(
"/\(".$iFileCounter.
"\)/",
"", $sTempFileName );
637 $sFileName = $sTempFileName .
"($iFileCounter)";
640 return $sFileName . $sSufix .
"." . $sFileExt;
651 public function getImageDirByType( $sType, $blGenerated =
false )
653 $sFolder = array_key_exists( $sType, $this->_aTypeToPath ) ? $this->_aTypeToPath[ $sType ] :
'0';
654 $sDir = $this->normalizeDir( $sFolder );
656 if ($blGenerated ===
true) {
657 $sDir = str_replace(
'master/',
'generated/', $sDir);
670 function translateError( $iError )
674 if ( $iError > 0 && $iError < 9 && 5 !== $iError ) {
675 $message =
'EXCEPTION_FILEUPLOADERROR_'.( (int) $iError );