/**
  * Export HTML content in a ODF document
  * @param string $html
  * @param string $name
  * @param string $format
  *
  * @return bool
  */
 public static function htmlToOdt($html, $name, $format = 'odt')
 {
     $unoconv = api_get_configuration_value('unoconv.binaries');
     if (empty($unoconv)) {
         return false;
     }
     if (!empty($html)) {
         $fs = new Filesystem();
         $paths = ['root_sys' => api_get_path(SYS_PATH), 'path.temp' => api_get_path(SYS_ARCHIVE_PATH)];
         $connector = new Connector();
         $drivers = new DriversContainer();
         $drivers['configuration'] = array('unoconv.binaries' => $unoconv, 'unoconv.timeout' => 60);
         $tempFilesystem = TemporaryFilesystem::create();
         $manager = new Manager($tempFilesystem, $fs);
         $alchemyst = new Alchemyst($drivers, $manager);
         $dataFileSystem = new Data($paths, $fs, $connector, $alchemyst);
         $content = $dataFileSystem->convertRelativeToAbsoluteUrl($html);
         $filePath = $dataFileSystem->putContentInTempFile($content, api_replace_dangerous_char($name), 'html');
         $try = true;
         while ($try) {
             try {
                 $convertedFile = $dataFileSystem->transcode($filePath, $format);
                 $try = false;
                 DocumentManager::file_send_for_download($convertedFile, false, $name . '.' . $format);
             } catch (Exception $e) {
                 // error_log($e->getMessage());
             }
         }
     }
 }
 public function testCreate()
 {
     $this->assertInstanceOf('Neutron\\TemporaryFilesystem\\TemporaryFilesystem', TemporaryFilesystem::create());
 }
 /**
  * {@inheritdoc}
  */
 public function createTemporaryFiles($quantity = 1, $prefix = self::DEFAULT_SCOPE, $suffix = null, $extension = null, $maxTry = 65536)
 {
     $files = $this->tmpFs->createTemporaryFiles($quantity, $prefix, $suffix, $extension, $maxTry);
     $this->add($files, $prefix);
     return $files;
 }
Example #4
0
#!/usr/bin/php
<?php 
$config = ['require_services' => ['sf_filesystem'], 'git_urls' => ['https://github.com/romainneutron/Temporary-Filesystem.git' => 'temporary_fs/'], 'autoload_config' => ['temporary_fs/src/Neutron/TemporaryFilesystem/' => 'Neutron\\TemporaryFilesystem'], 'example' => function () {
    $fs = \Neutron\TemporaryFilesystem\TemporaryFilesystem::create();
    $fs->createTemporaryFile('thumb-', '.dcm', 'jpg');
    var_dump($fs);
}];
if ($return_config) {
    return $config;
}
require_once __DIR__ . '/_yf_autoloader.php';
new yf_autoloader($config);
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testTemporaryFilesInvalidQuantity()
 {
     $this->filesystem->createTemporaryFiles(0);
 }