Exemplo n.º 1
0
 /**
  * Validate input and set value
  */
 public function validate()
 {
     $this->varValue = $this->getPost($this->strName);
     if (!is_array($this->varValue)) {
         $this->varValue = array();
     }
     // Fetch fallback language record
     $arrFallback = $this->getFallbackData();
     if (is_array($arrFallback)) {
         foreach ($arrFallback as $k => $arrImage) {
             if ($arrImage['translate'] == 'all') {
                 unset($arrFallback[$k]);
             }
         }
     }
     // Check that image is not assigned in fallback language
     foreach ($this->varValue as $k => $v) {
         if (is_array($arrFallback) && in_array($v, $arrFallback)) {
             $this->addError($GLOBALS['TL_LANG']['ERR']['imageInFallback']);
         } elseif ($arrFallback !== false) {
             $this->varValue[$k]['translate'] = 'all';
         }
     }
     // Move all temporary files
     foreach ($this->varValue as $k => $v) {
         if (stripos($v['src'], $this->strTempFolder) !== false) {
             $strFile = $this->getFilePath(basename($v['src']));
             \Haste\Haste::mkdirr(dirname($strFile));
             if (\Files::getInstance()->rename($v['src'], $strFile)) {
                 $this->varValue[$k]['src'] = basename($strFile);
             } else {
                 unset($this->varValue[$k]);
             }
         }
     }
     // Check if there are values
     if ($this->mandatory) {
         foreach ($this->varValue as $file) {
             if (is_file(TL_ROOT . '/' . $this->getFilePath($file['src']))) {
                 return;
             }
         }
         if (!is_array($arrFallback) || empty($arrFallback)) {
             $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['mandatory'], $this->strLabel));
         }
     }
     if (empty($this->varValue)) {
         $this->varValue = null;
     }
 }