Beispiel #1
0
 function makeImageBGImage(&$edit, &$dataArr, $dataFile, $fieldID, $desc, $isBG = false, $count = null, $repeatFieldID = null)
 {
     if (isset($edit->autocms)) {
         $desc = $edit->autocms;
     }
     $tag = null;
     $source = null;
     if ($isBG) {
         $source = $edit->style;
         preg_match('~\\bbackground(-image)?\\s*:(.*?)\\(\\s*(\'|")?(?<image>.*?)\\3?\\s*\\)~i', $source, $matches);
         $source = $matches[4];
         $tag = $matches[0];
     } else {
         $source = $edit->src;
     }
     if ($source[0] != '/') {
         $source = '/' . $source;
     }
     if ($source[0] == '/') {
         $source = $_SERVER['DOCUMENT_ROOT'] . $source;
     }
     $fileExt = pathinfo(parse_url($edit->src, PHP_URL_PATH), PATHINFO_EXTENSION);
     $fileExt = MediaData::getImageType($fileExt, $source);
     if ($fileExt != 'error') {
         $media = new MediaData();
         if (!$media->checkMediaLibrary('images', $source)) {
             $imgFileName = $media->makeDateFolders() . uniqid() . '.' . $fileExt;
             if (file_exists($source)) {
                 copy($source, $_SERVER['DOCUMENT_ROOT'] . $imgFileName);
             }
             $media->addToMediaLibrary('images', $imgFileName, $source);
         } else {
             $imgFileName = $media->getFromMediaLibrary('images', $source);
         }
         if (!is_null($repeatFieldID)) {
             $dataArr[$fieldID]['repeat'][$count][$repeatFieldID] = array('image' => $imgFileName, 'description' => $desc, 'type' => 'image');
         } else {
             $dataArr[$fieldID] = array('image' => $imgFileName, 'description' => $desc, 'type' => 'image');
         }
         if ($isBG) {
             if (!is_null($repeatFieldID)) {
                 $edit->style = str_replace($tag, '', $edit->style) . "background-image: url('<?=get('{$dataFile}', '{$fieldID}', " . '$x' . ", '{$repeatFieldID}')?>');";
             } else {
                 $edit->style = str_replace($tag, '', $edit->style) . "background-image: url('<?=get('{$dataFile}', '{$fieldID}')?>');";
             }
             $edit->class = str_replace('auto-edit-bg-img', '', $edit->class);
         } else {
             $altText = $edit->alt;
             if ($altText === false) {
                 $altText = '';
             }
             $altFieldID = uniqid();
             if (!is_null($repeatFieldID)) {
                 $edit->src = "<?=get('{$dataFile}', '{$fieldID}', " . '$x' . ", '{$repeatFieldID}')?>";
                 $dataArr[$fieldID]['repeat'][$count][$altFieldID] = array('text' => $altText, 'description' => 'image alt text', 'type' => 'text', 'parent' => $fieldID);
             } else {
                 $edit->src = "<?=get('{$dataFile}', '{$fieldID}')?>";
                 $dataArr[$altFieldID] = array('text' => $altText, 'description' => 'image alt text', 'type' => 'text', 'parent' => $fieldID);
             }
             if (!is_null($repeatFieldID)) {
                 $edit->alt = "<?=get('{$dataFile}', '{$fieldID}', " . '$x' . ", '{$altFieldID}')?>";
             } else {
                 $edit->alt = "<?=get('{$dataFile}', '{$altFieldID}')?>";
             }
             $edit->class = str_replace('auto-edit-img', '', $edit->class);
         }
         if (trim($edit->class) === '') {
             $edit->class = null;
         }
         $edit->autocms = null;
     }
 }