36                                     'CICO'  => 
'master/category/icon',
 
   37                                     'PICO'  => 
'master/category/promo_icon',
 
   38                                     'MICO'  => 
'master/manufacturer/icon',
 
   39                                     'VICO'  => 
'master/vendor/icon',
 
   40                                     'PROMO' => self::PROMO_PICTURE_DIR,
 
   41                                     'ICO'   => 
'master/product/icon',
 
   42                                     'TH'    => 
'master/product/thumb',
 
   43                                     'M1'    => 
'master/product/1',
 
   44                                     'M2'    => 
'master/product/2',
 
   45                                     'M3'    => 
'master/product/3',
 
   46                                     'M4'    => 
'master/product/4',
 
   47                                     'M5'    => 
'master/product/5',
 
   48                                     'M6'    => 
'master/product/6',
 
   49                                     'M7'    => 
'master/product/7',
 
   50                                     'M8'    => 
'master/product/8',
 
   51                                     'M9'    => 
'master/product/9',
 
   52                                     'M10'   => 
'master/product/10',
 
   53                                     'M11'   => 
'master/product/11',
 
   54                                     'M12'   => 
'master/product/12',
 
   81                                     'WP'    => 
'master/wrapping',
 
   90     protected $_aBadFiles = array(
'php', 
'php3', 
'php4', 
'php5', 
'phps', 
'php6', 
'jsp', 
'cgi', 
'cmf', 
'exe');
 
  115         if ($iPicCount = 
$myConfig->getConfigParam(
'iPicCount')) {
 
  116             $this->_iMaxPicImgCount = $iPicCount;
 
  139         $this->_iNewFilesCounter = (int) $iNewFilesCounter;
 
  151         if (isset($sDir) && $sDir != 
"" && substr($sDir, -1) !== 
'/') {
 
  164     public function copyDir($sSourceDir, $sTargetDir)
 
  167         $handle = opendir($sSourceDir);
 
  168         while (
false !== ($file = readdir($handle))) {
 
  169             if ($file != 
'.' && $file != 
'..') {
 
  170                 if (is_dir($sSourceDir . 
'/' . $file)) {
 
  173                     $sNewSourceDir = $sSourceDir . 
'/' . $file;
 
  174                     $sNewTargetDir = $sTargetDir . 
'/' . $file;
 
  175                     if (strcasecmp($file, 
'CVS') && strcasecmp($file, 
'.svn')) {
 
  176                         @mkdir($sNewTargetDir, 0777);
 
  177                         $this->
copyDir($sNewSourceDir, $sNewTargetDir);
 
  180                     $sSourceFile = $sSourceDir . 
'/' . $file;
 
  181                     $sTargetFile = $sTargetDir . 
'/' . $file;
 
  184                     if (!$oStr->strstr($sSourceDir, 
'dyn_images') || $file == 
'nopic.jpg' || $file == 
'nopic_ico.jpg') {
 
  185                         @copy($sSourceFile, $sTargetFile);
 
  202         if (is_dir($sSourceDir)) {
 
  203             if ($oDir = dir($sSourceDir)) {
 
  205                 while (
false !== $sFile = $oDir->read()) {
 
  206                     if ($sFile == 
'.' || $sFile == 
'..') {
 
  210                     if (!$this->
deleteDir($oDir->path . DIRECTORY_SEPARATOR . $sFile)) {
 
  219                 return rmdir($sSourceDir);
 
  221         } elseif (file_exists($sSourceDir)) {
 
  222             return unlink($sSourceDir);
 
  236         $hFile = @fopen($sPath, 
'r');
 
  238             socket_set_timeout($hFile, 2);
 
  239             while (!feof($hFile)) {
 
  240                 $sLine = fgets($hFile, 4096);
 
  264             $aFilename = explode(
".", $sValue);
 
  266             $sFileType = trim($aFilename[count($aFilename) - 1]);
 
  268             if (isset($sFileType)) {
 
  273                 if (in_array($sFileType, $this->_aBadFiles) || ($blDemo && !in_array($sFileType, $this->_aAllowedFiles))) {
 
  278                 if (count($aFilename) > 0) {
 
  279                     unset($aFilename[count($aFilename) - 1]);
 
  283                 if (isset($aFilename[0])) {
 
  284                     $sFName = $oStr->preg_replace(
'/[^a-zA-Z0-9()_\.-]/', 
'', implode(
'.', $aFilename));
 
  287                 $sValue = $this->
_getUniqueFileName($sImagePath, 
"{$sFName}", $sFileType, 
"", $blUnique);
 
  303         $sFolder = array_key_exists($sType, $this->_aTypeToPath) ? $this->_aTypeToPath[$sType] : 
'0';
 
  325             case 'aDetailImageSizes':
 
  326                 $aDetailImageSizes = 
$myConfig->getConfigParam($sImgConf);
 
  327                 $sSize = 
$myConfig->getConfigParam(
'sDetailImageSize');
 
  328                 if (isset($aDetailImageSizes[
'oxpic' . $iImgNum])) {
 
  329                     $sSize = $aDetailImageSizes[
'oxpic' . $iImgNum];
 
  333                 $sSize = 
$myConfig->getConfigParam($sImgConf);
 
  337             return explode(
'*', $sSize);
 
  353         if ($sSource === $sTarget) {
 
  356             $blDone = copy($sSource, $sTarget);
 
  360             $blDone = @chmod($sTarget, 0644);
 
  377         if (!is_dir(dirname($sTarget))) {
 
  378             mkdir(dirname($sTarget), 0744, 
true);
 
  380         if ($sSource === $sTarget) {
 
  383             $blDone = move_uploaded_file($sSource, $sTarget);
 
  387             $blDone = @chmod($sTarget, 0644);
 
  404     public function processFiles($oObject = null, $aFiles = array(), $blUseMasterImage = 
false, $blUnique = 
true)
 
  406         $aFiles = $aFiles ? $aFiles : $_FILES;
 
  407         if (isset($aFiles[
'myfile'][
'name'])) {
 
  413             $blDemo = (bool) $oConfig->isDemoShop();
 
  416             $sTmpFolder = $oConfig->getConfigParam(
"sCompileDir");
 
  418             $iNewFilesCounter = 0;
 
  419             $aSource = $aFiles[
'myfile'][
'tmp_name'];
 
  420             $aError = $aFiles[
'myfile'][
'error'];
 
  421             $sErrorsDescription = 
'';
 
  423             $oEx = 
oxNew(
"oxExceptionToDisplay");
 
  425             while (list($sKey, $sValue) = each($aFiles[
'myfile'][
'name'])) {
 
  427                 $sSource = $aSource[$sKey];
 
  428                 $iError = $aError[$sKey];
 
  429                 $aFiletype = explode(
"@", $sKey);
 
  430                 $sKey = $aFiletype[1];
 
  431                 $sType = $aFiletype[0];
 
  433                 $sValue = strtolower($sValue);
 
  437                 if (UPLOAD_ERR_OK !== $iError && UPLOAD_ERR_NO_FILE !== $iError) {
 
  439                     $oEx->setMessage($sErrorsDescription);
 
  444                 if ($sSource && ($sValue = $this->
_prepareImageName($sValue, $sType, $blDemo, $sImagePath, $blUnique))) {
 
  447                     $sProcessPath = $sTmpFolder . basename($sSource);
 
  451                         if ($blUseMasterImage) {
 
  453                             $blMoved = $this->
_copyFile($sSource, $sImagePath . $sValue);
 
  455                             $blMoved = $this->
_moveImage($sSource, $sImagePath . $sValue);
 
  462                             if ($oObject && isset($oObject->$sKey)) {
 
  463                                 $oObject->{$sKey}->setValue($sValue);
 
  484     public function checkFile($sFile)
 
  488         if (isset($aCheckCache[$sFile])) {
 
  489             return $aCheckCache[$sFile];
 
  494         if (is_readable($sFile)) {
 
  498             $blRet = $this->urlValidate($sFile);
 
  501         $aCheckCache[$sFile] = $blRet;
 
  514     public function urlValidate($sLink)
 
  516         $aUrlParts = @parse_url($sLink);
 
  517         $sHost = (isset($aUrlParts[
"host"]) && $aUrlParts[
"host"]) ? $aUrlParts[
"host"] : null;
 
  521             $sDocumentPath = (isset($aUrlParts[
"path"]) && $aUrlParts[
"path"]) ? $aUrlParts[
"path"] : 
'/';
 
  522             $sDocumentPath .= (isset($aUrlParts[
"query"]) && $aUrlParts[
"query"]) ? 
'?' . $aUrlParts[
"query"] : 
'';
 
  524             $sPort = (isset($aUrlParts[
"port"]) && $aUrlParts[
"port"]) ? $aUrlParts[
"port"] : 
'80';
 
  527             if (($oConn = @fsockopen($sHost, $sPort, $iErrNo, $sErrStr, 30))) {
 
  528                 fwrite($oConn, 
"HEAD {$sDocumentPath} HTTP/1.0\r\nHost: {$sHost}\r\n\r\n");
 
  529                 $sResponse = fgets($oConn, 22);
 
  532                 if (preg_match(
"/200 OK/", $sResponse)) {
 
  551     public function processFile($sFileName, $sUploadPath)
 
  553         $aFileInfo = $_FILES[$sFileName];
 
  555         $sBasePath = $this->getConfig()->getConfigParam(
'sShopDir');
 
  558         if (!isset($aFileInfo[
'name']) || !isset($aFileInfo[
'tmp_name'])) {
 
  559             throw oxNew(
"oxException", 
'EXCEPTION_NOFILE');
 
  563         if (!
getStr()->preg_match(
'/^[\-_a-z0-9\.]+$/i', $aFileInfo[
'name'])) {
 
  564             throw oxNew(
"oxException", 
'EXCEPTION_FILENAMEINVALIDCHARS');
 
  568         if (isset($aFileInfo[
'error']) && $aFileInfo[
'error']) {
 
  569             throw oxNew(
"oxException", 
'EXCEPTION_FILEUPLOADERROR_' . ((
int) $aFileInfo[
'error']));
 
  572         $aPathInfo = pathinfo($aFileInfo[
'name']);
 
  574         $sExt = $aPathInfo[
'extension'];
 
  575         $sFileName = $aPathInfo[
'filename'];
 
  577         $aAllowedUploadTypes = (array) $this->getConfig()->getConfigParam(
'aAllowedUploadTypes');
 
  578         $aAllowedUploadTypes = array_map(
"strtolower", $aAllowedUploadTypes);
 
  580         if (!in_array(strtolower($sExt), $aAllowedUploadTypes)) {
 
  581             throw oxNew(
"oxException", 
'EXCEPTION_NOTALLOWEDTYPE');
 
  584         $sFileName = $this->_getUniqueFileName($sBasePath . $sUploadPath, $sFileName, $sExt);
 
  586         if ($this->_moveImage($aFileInfo[
'tmp_name'], $sBasePath . $sUploadPath . 
"/" . $sFileName)) {
 
  605     protected function _getUniqueFileName($sFilePath, $sFileName, $sFileExt, $sSufix = 
"", $blUnique = 
true)
 
  607         $sFilePath = $this->normalizeDir($sFilePath);
 
  609         $sTempFileName = $sFileName;
 
  613         while ($blUnique && file_exists($sFilePath . 
"/" . $sFileName . $sSufix . 
"." . $sFileExt)) {
 
  617             $sTempFileName = $oStr->preg_replace(
"/\(" . $iFileCounter . 
"\)/", 
"", $sTempFileName);
 
  619             $sFileName = $sTempFileName . 
"($iFileCounter)";
 
  622         return $sFileName . $sSufix . 
"." . $sFileExt;
 
  633     public function getImageDirByType($sType, $blGenerated = 
false)
 
  635         $sFolder = array_key_exists($sType, $this->_aTypeToPath) ? $this->_aTypeToPath[$sType] : 
'0';
 
  636         $sDir = $this->normalizeDir($sFolder);
 
  638         if ($blGenerated === 
true) {
 
  639             $sDir = str_replace(
'master/', 
'generated/', $sDir);
 
  652     public function translateError($iError)
 
  656         if ($iError > 0 && $iError < 9 && 5 !== $iError) {
 
  657             $message = 
'EXCEPTION_FILEUPLOADERROR_' . ((int) $iError);