Example #1
0
 public function getBinary()
 {
     if (empty(static::$bin)) {
         static::$bin = trim(trim(getenv('PDFINFO_BIN'), '\\/" \'')) ?: 'pdfinfo';
     }
     return static::$bin;
 }
Example #2
0
 /**
  * Sets git executable path
  *
  * @param string $path executable location
  */
 public static function set_bin($path)
 {
     static::$bin = $path;
 }
Example #3
0
 public static function save($param, $dir, $clean = false, $exec = false, $bash = null, $unlink = true, $customName = false)
 {
     $defaultParam = array('id' => null, 'name' => null, 'lang' => null, 'parent' => false);
     // merge param
     $resultMerge = array_merge($defaultParam, $param);
     $selfId = $resultMerge['id'];
     $selfName = $resultMerge['name'];
     $selfLang = $resultMerge['lang'];
     $parent = $resultMerge['parent'];
     $ds = DIRECTORY_SEPARATOR;
     $windows = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
     $bin = static::$bin = sfConfig::get('sf_root_dir') . "{$ds}bin{$ds}";
     // verifica se o arquivo
     if ($selfName && (!preg_match("/\\//i", $selfName) || preg_match("/\\.\\.\\/test/i", $selfName))) {
         $recordDir = static::encontreNoGrupo("{$dir}", "{$selfId}");
         if ($recordDir) {
             if ($clean != false) {
                 GetFile::cleanDir($recordDir, $clean);
             }
         } else {
             $recordDir = static::encontreGrupoDisponivel("{$dir}", "{$selfId}");
             exec("mkdir -p {$recordDir}");
         }
         preg_match("/[0-9a-f]{32}/i", $recordDir, $matches);
         $hash = isset($matches[0]) ? $matches[0] : null;
         // Verifica se existe o hash
         if (!$hash) {
             die('SaveFile error: Missing hash');
         } else {
             $dir = "{$dir}{$ds}{$hash}";
         }
         // move the original file to the record folder
         $uploaded = GetFile::getUploadBasePath() . $selfName;
         $parts = pathinfo($uploaded);
         $newExt = $parts['extension'];
         $partsExt = $parent ? "{$selfLang}.{$parts['extension']}" : "{$parts['extension']}";
         // Final file name
         $newFilename = $exec ? "original.{$partsExt}" : basename($uploaded);
         $newFilename = $customName ? "{$customName}.{$partsExt}" : $newFilename;
         $newLocalFile = "{$recordDir}{$ds}{$newFilename}";
         // move o arquivo para o local
         static::mv("{$uploaded}", $newLocalFile, $windows);
         // Gera outros tamanhos - imagemagick bashscript
         if ($exec) {
             if ($windows) {
                 $dir = str_replace("\\", "/", $dir);
                 $dir = preg_replace("/([a-zA-Z])\\:\\//", "/\$1/", $dir);
                 $cmd = "sh {$bin}{$bash} {$selfId} {$dir}";
             } else {
                 $cmd = "{$bin}{$bash} {$selfId} {$dir}";
             }
             $return_var = 0;
             $cmd = $parent ? "{$cmd} {$selfLang}" : $cmd;
             exec("{$cmd}", $out, $return_var);
             if ($return_var === 0) {
                 $newExt = !empty($out) ? $out[0] : null;
             } else {
                 die("SaveFile error: {$cmd} | exit: {$return_var}");
             }
             // remove o arquivo
             if ($unlink && file_exists($newLocalFile)) {
                 unlink($newLocalFile);
             }
         }
         return array('hash' => $hash, 'id' => $selfId, 'ext' => $newExt);
     }
     return false;
 }