Example #1
0
 function parse_ini_string($ini, $process_sections = false, $scanner_mode = INI_SCANNER_NORMAL)
 {
     $path = @tmp_file('parse_ini_string');
     if (empty($path)) {
         throw new Exception("Failed to create temporary file");
     }
     if (!@file_put_contents($path, $ini)) {
         throw new Exception("Failed to write ini string to temporary file");
     }
     $data = parse_ini_file($path, $process_sections, $scanner_mode);
     @unlink($path);
     return $data;
 }
Example #2
0
 /**
  * Mixes the input files
  * and adjusts the duration of mix files (by repeating or cutting)
  * until they have the duration of the first file.
  *
  * @param array  $inputFiles Input files
  * @param string $outputFile The output file
  * @return string|boolean    resulted file path or false if the mix failed
  */
 public function mix(array $inputFiles, $outputFile)
 {
     // the input files have to be repeated while the first one is played
     // we have to see for how many times each should be repeated
     $firstInputFile = array_shift($inputFiles);
     // we need the duration of first input file
     $inputFileDuration = $this->_decoder->_decodeFormat($firstInputFile)->getDuration();
     // add first input file unaltered
     $preparedInputFiles = array($firstInputFile);
     foreach ($inputFiles as $file) {
         // for each input file
         // we have to build a temporary mix file having the same duration as the source
         // we will join the mixFile with itself until the length of this temporary
         // file becomess greater than the source duration
         // then we will cut the temporary file for exactly matching with the source duration
         $fileDuration = $this->_decoder->_decodeFormat($file)->getDuration();
         // find out how many times the mix file should be repeated to cover the source length
         $repetitionsNumber = ceil($inputFileDuration / $fileDuration);
         $repeatedFile = $file;
         $repeatedFileCreated = false;
         if ($repetitionsNumber > 1) {
             $repeatedFile = tmp_file();
             $repeatedFileCreated = true;
             // concatenate the mixFile to the tempMixFile as many times as needed
             $joinFiles = array();
             for ($i = 1; $i < $repetitionsNumber; $i++) {
                 $joinFiles[] = $file;
             }
             $this->_joiner->join($joinFiles, $repeatedFile);
         }
         $adjustedFile = tmp_file();
         // cut the repeatedFile to the same length as the inputFile
         $format = new Streamwide_Media_Format();
         $format->setDuration($inputFileDuration);
         $this->_converter->convert($tempFile, $adjustedFile, $format);
         // add the prepared file
         $preparedInputFiles[] = $adjustedFile;
         // cleanup
         if ($repeatedFileCreated) {
             unlink($repeatedFile);
         }
     }
     // finally make the mix
     $this->_mixer->mix($preparedInputFiles, $outputFile);
     // check if the outputFile was created
     if (!file_exists($outputFile)) {
         return false;
     }
     return $outputFile;
 }