コード例 #1
0
ファイル: sqlite.php プロジェクト: mdb-webdev/livehelperchat
 /**
  * Constructs a handler object from the parameters $dbParams.
  *
  * Supported database parameters are:
  * - dbname|database: Database name
  * - port:            If "memory" is used then the driver will use an
  *                    in-memory database, and the database name is ignored.
  *
  * @throws ezcDbMissingParameterException if the database name was not specified.
  * @param array $dbParams Database connection parameters (key=>value pairs).
  */
 public function __construct($dbParams)
 {
     $database = false;
     foreach ($dbParams as $key => $val) {
         switch ($key) {
             case 'database':
             case 'dbname':
                 $database = $val;
                 if (!empty($database) && $database[0] != '/' && ezcBaseFeatures::os() != 'Windows') {
                     $database = '/' . $database;
                 }
                 break;
         }
     }
     // If the "port" is set then we use "sqlite::memory:" as DSN, otherwise we fallback
     // to the database name.
     if (!empty($dbParams['port']) && $dbParams['port'] == 'memory') {
         $dsn = "sqlite::memory:";
     } else {
         if ($database === false) {
             throw new ezcDbMissingParameterException('database', 'dbParams');
         }
         $dsn = "sqlite:{$database}";
     }
     parent::__construct($dbParams, $dsn);
     /* Register PHP implementations of missing functions in SQLite */
     $this->sqliteCreateFunction('md5', array('ezcQuerySqliteFunctions', 'md5Impl'), 1);
     $this->sqliteCreateFunction('mod', array('ezcQuerySqliteFunctions', 'modImpl'), 2);
     $this->sqliteCreateFunction('locate', array('ezcQuerySqliteFunctions', 'positionImpl'), 2);
     $this->sqliteCreateFunction('floor', array('ezcQuerySqliteFunctions', 'floorImpl'), 1);
     $this->sqliteCreateFunction('ceil', array('ezcQuerySqliteFunctions', 'ceilImpl'), 1);
     $this->sqliteCreateFunction('concat', array('ezcQuerySqliteFunctions', 'concatImpl'));
     $this->sqliteCreateFunction('toUnixTimestamp', array('ezcQuerySqliteFunctions', 'toUnixTimestampImpl'), 1);
     $this->sqliteCreateFunction('now', 'time', 0);
 }
コード例 #2
0
ファイル: dialog_test.php プロジェクト: jacomyma/GEXF-Atlas
 protected function setUp()
 {
     $this->dataDir = dirname(__FILE__) . "/data/" . (ezcBaseFeatures::os() === "windows" ? "windows" : "posix");
     $this->phpPath = isset($_SERVER["_"]) ? $_SERVER["_"] : "/bin/env php";
     $this->output = new ezcConsoleOutput();
     $this->output->formats->test->color = "blue";
 }
コード例 #3
0
ファイル: dialog_test.php プロジェクト: naderman/pflow
 protected function determinePhpPath()
 {
     if (isset($_SERVER["_"])) {
         $this->phpPath = $_SERVER["_"];
     } else {
         if (ezcBaseFeatures::os() === 'Windows') {
             $this->phpPath = 'php.exe';
         } else {
             $this->phpPath = '/bin/env php';
         }
     }
 }
コード例 #4
0
ファイル: converter_test.php プロジェクト: bmdevel/ezc
 public function testConstructFailureInvalidSettings()
 {
     $conversionsIn = array("image/gif" => "image/png", "image/xpm" => "image/jpeg", "image/wbmp" => "image/jpeg");
     if (ezcBaseFeatures::os() === 'Windows') {
         unset($conversionsIn["image/xpm"]);
     }
     try {
         $settings = new ezcImageConverterSettings(array(new stdClass()), $conversionsIn);
         $converter = new ezcImageConverter($settings);
         $this->fail('Exception not thrown on invalid handler settings.');
     } catch (ezcImageHandlerSettingsInvalidException $e) {
     }
 }
コード例 #5
0
 public function testStatusbar2()
 {
     $out = new ezcConsoleOutput();
     $out->options->useFormats = false;
     $status = new ezcConsoleStatusbar($out);
     ob_start();
     foreach ($this->stati as $statusVal) {
         $status->add($statusVal);
     }
     $res = ob_get_contents();
     ob_end_clean();
     $this->assertEquals(file_get_contents(dirname(__FILE__) . '/data/' . (ezcBaseFeatures::os() === "Windows" ? "windows/" : "posix/") . 'testStatusbar2.dat'), $res, "Unformated statusbar not generated correctly.");
     // To prepare test files use this:
     // file_put_contents( dirname( __FILE__ ) . '/data/' . ( ezcBaseFeatures::os() === "Windows" ? "windows/" : "posix/" ) . 'testStatusbar2.dat', $res );
 }
コード例 #6
0
 protected function setUp()
 {
     try {
         $this->testFiltersSuccess = array(0 => array(0 => new ezcImageFilter("scaleExact", array("width" => 50, "height" => 50, "direction" => ezcImageGeometryFilters::SCALE_BOTH)), 1 => new ezcImageFilter("crop", array("x" => 10, "width" => 30, "y" => 10, "height" => 30)), 2 => new ezcImageFilter("colorspace", array("space" => ezcImageColorspaceFilters::COLORSPACE_GREY))), 1 => array(0 => new ezcImageFilter("scale", array("width" => 50, "height" => 1000, "direction" => ezcImageGeometryFilters::SCALE_DOWN)), 2 => new ezcImageFilter("colorspace", array("space" => ezcImageColorspaceFilters::COLORSPACE_MONOCHROME))), 2 => array(0 => new ezcImageFilter("scaleHeight", array("height" => 70, "direction" => ezcImageGeometryFilters::SCALE_BOTH)), 2 => new ezcImageFilter("colorspace", array("space" => ezcImageColorspaceFilters::COLORSPACE_SEPIA))), 3 => array(0 => new ezcImageFilter("scale", array("width" => 50, "height" => 50))));
         $this->testFiltersFailure = array(0 => array(0 => new ezcImageFilter("toby", array("width" => 50, "height" => 50, "direction" => ezcImageGeometryFilters::SCALE_BOTH)), 1 => new ezcImageFilter("crop", array("x" => 10, "width" => 30, "y" => 10, "height" => 30)), 2 => new ezcImageFilter("colorspace", array("space" => ezcImageColorspaceFilters::COLORSPACE_GREY))), 1 => array(0 => new ezcImageFilter("scale", array()), 2 => new ezcImageFilter("colorspace", array("space" => ezcImageColorspaceFilters::COLORSPACE_MONOCHROME))));
         $conversionsIn = array("image/gif" => "image/png", "image/xpm" => "image/jpeg", "image/wbmp" => "image/jpeg");
         if (ezcBaseFeatures::os() === 'Windows') {
             unset($conversionsIn["image/xpm"]);
         }
         $settings = new ezcImageConverterSettings(array(new ezcImageHandlerSettings("GD", "ezcImageGdHandler")), $conversionsIn);
         $this->converter = new ezcImageConverter($settings);
     } catch (Exception $e) {
         $this->markTestSkipped($e->getMessage());
     }
 }
コード例 #7
0
 public function testProgressMonitor4()
 {
     $out = new ezcConsoleOutput();
     $out->formats->tag->color = 'red';
     $out->formats->percent->color = 'blue';
     $out->formats->percent->style = array('bold');
     $out->formats->data->color = 'green';
     $status = new ezcConsoleProgressMonitor($out, 7, array('formatString' => $out->formatText('%2$10s', 'tag') . ' ' . $out->formatText('%1$6.2f%%', 'percent') . ' ' . $out->formatText('%3$s', 'data')));
     ob_start();
     for ($i = 0; $i < 7; $i++) {
         $status->addEntry($this->stati[$i][0], $this->stati[$i][1]);
     }
     $res = ob_get_contents();
     ob_end_clean();
     // To prepare test files use this:
     // file_put_contents( dirname( __FILE__ ) . '/data/' . ( ezcBaseFeatures::os() === "Windows" ? "windows/" : "posix/" ) . 'testProgressMonitor4.dat', $res );
     $this->assertEquals(file_get_contents(dirname(__FILE__) . '/data/' . (ezcBaseFeatures::os() === "Windows" ? "windows/" : "posix/") . 'testProgressMonitor4.dat'), $res, "Formated statusbar not generated correctly.");
 }
コード例 #8
0
ファイル: mssql.php プロジェクト: fobiaweb/ezc-database
 /**
  * Constructs a handler object from the parameters $dbParams.
  *
  * Supported database parameters are:
  * - dbname|database: Database name
  * - host|hostspec:   Name of the host database is running on
  * - port:            TCP port
  * - user|username:   Database user name
  * - pass|password:   Database user password
  *
  * @param mixed $dbParams Database connection parameters (key=>value pairs).
  * @throws ezcDbMissingParameterException if the database name was not specified.
  */
 public function __construct($dbParams)
 {
     if ($dbParams instanceof PDO) {
         parent::__construct($dbParams);
         return;
     }
     $database = null;
     $host = null;
     $port = null;
     foreach ($dbParams as $key => $val) {
         switch ($key) {
             case 'database':
             case 'dbname':
                 $database = $val;
                 break;
             case 'host':
             case 'hostspec':
                 $host = $val;
                 break;
             case 'port':
                 $port = $val;
                 break;
         }
     }
     if (!isset($database)) {
         throw new ezcDbMissingParameterException('database', 'dbParams');
     }
     if (ezcBaseFeatures::os() === 'Windows') {
         $dsn = "mssql:dbname={$database}";
     } else {
         // uses FreeTDS
         $dsn = "dblib:dbname={$database}";
     }
     if (isset($host) && $host) {
         $dsn .= ";host={$host}";
         if (isset($port) && $port) {
             $dsn .= ":{$port}";
         }
     }
     $db = parent::createPDO($dbParams, $dsn);
     parent::__construct($db);
     // setup options
     $this->setOptions(new ezcDbMssqlOptions());
 }
コード例 #9
0
ファイル: parser_test.php プロジェクト: bmdevel/ezc
 /**
  * Test for bug #12844.
  */
 public function testTempDirNonWindows()
 {
     if (ezcBaseFeatures::os() === 'Windows') {
         self::markTestSkipped('Test is for non-Windows only');
     }
     ezcMailParser::setTmpDir(null);
     $this->assertEquals('/tmp/', ezcMailParser::getTmpDir());
 }
コード例 #10
0
ファイル: output_test.php プロジェクト: jacomyma/GEXF-Atlas
    /**
     * testOutputTextAutobreak
     * 
     * @access public
     */
    public function testOutputTextAutobreak()
    {
        $this->consoleOutput->options->autobreak = 20;
        $testText = 'Some text which is obviously longer than 20 characters and should be broken.';
        $testResText = <<<EOT
Some text which is
obviously longer
than 20 characters
and should be
broken.
EOT;
        foreach ($this->testFormats as $name => $inout) {
            ob_start();
            $this->consoleOutput->outputText($testText, $name);
            $realRes = ob_get_contents();
            ob_end_clean();
            $fakeRes = ezcBaseFeatures::os() !== "Windows" ? sprintf($inout['out'], $testResText) : $testResText;
            $this->assertEquals($fakeRes, $realRes, 'Test "' . $name . ' failed. String <' . $realRes . '> (real) is not equal to <' . $fakeRes . '> (fake).');
        }
    }
コード例 #11
0
ファイル: table_test.php プロジェクト: bmdevel/ezc
 protected function assertTableOutputEquals($expectedRef, $actualContent)
 {
     $refFile = dirname(__FILE__) . '/data/' . (ezcBaseFeatures::os() === "Windows" ? "windows/" : "posix/") . $expectedRef . '.dat';
     // To prepare test files, uncomment this block
     // file_put_contents( $refFile, $actualContent );
     if (!file_exists($refFile)) {
         // Default assert for new files.
         $this->assertEquals('', $actualContent, "Asserted against empty string, since reference file '{$refFile}' does not exist.");
     } else {
         $this->assertEquals(file_get_contents($refFile), $actualContent, 'Table not correctly generated for ' . $expectedRef . '.');
     }
 }
コード例 #12
0
ファイル: features.php プロジェクト: jordanmanning/ezpublish
 /**
  * Reset the cached information. 
  * 
  * @return void
  * @access private
  * @ignore
  */
 public static function reset()
 {
     self::$imageIdentify = null;
     self::$imageConvert = null;
     self::$os = null;
 }
コード例 #13
0
 public function testCannotReadCompiled()
 {
     if (ezcBaseFeatures::os() === 'Windows') {
         self::markTestSkipped('Test is for non-Windows only - permission system is not the same on Windows.');
     }
     $temp = $this->createTempDir("ezcTemplate");
     file_put_contents($temp . "/myFile", "bla");
     chmod($temp . "/myFile", 0200);
     // Write only for the owner of the file.
     $conf = new ezcTemplateCompiledCode('8efb', $temp . "/myFile");
     $conf->template = new ezcTemplate();
     $conf->context = new ezcTemplateXhtmlContext();
     try {
         $conf->execute();
         self::fail("No exception thrown");
     } catch (ezcTemplateInvalidCompiledFileException $e) {
     }
     $this->removeTempDir();
 }
コード例 #14
0
 public function testSqliteDSN4()
 {
     if (!ezcBaseFeatures::hasExtensionSupport('pdo_sqlite') || ezcBaseFeatures::os() !== 'Windows') {
         $this->markTestSkipped('Windows only test');
         return;
     }
     $db = ezcDbFactory::create('sqlite:///c:\\tmp\\foo.sqlite');
     $this->assertEquals(true, file_exists('c:\\tmp\\foo.sqlite'));
     unlink('c:\\tmp\\foo.sqlite');
 }
コード例 #15
0
 /**
  * Returns the operating system on which PHP is running.
  *
  * This method returns a sanitized form of the OS name, example
  * return values are "Windows", "Mac", "Linux" and "FreeBSD". In
  * all other cases it returns the value of the internal PHP constant
  * PHP_OS.
  *
  * @return string
  */
 public static function os()
 {
     if (is_null(self::$os)) {
         $uname = php_uname('s');
         if (substr($uname, 0, 7) == 'Windows') {
             self::$os = 'Windows';
         } elseif (substr($uname, 0, 3) == 'Mac') {
             self::$os = 'Mac';
         } elseif (strtolower($uname) == 'linux') {
             self::$os = 'Linux';
         } elseif (strtolower(substr($uname, 0, 7)) == 'freebsd') {
             self::$os = 'FreeBSD';
         } else {
             self::$os = PHP_OS;
         }
     }
     return self::$os;
 }
コード例 #16
0
ファイル: progressbar_test.php プロジェクト: bmdevel/ezc
 private function commonProgressbarTest($refFile, $max, $step, $options)
 {
     $out = new ezcConsoleOutput();
     $bar = new ezcConsoleProgressbar($out, $max, $options);
     if ($step != 1) {
         $bar->options->step = $step;
     }
     $res = array();
     for ($i = 0; $i < $max; $i += $step) {
         ob_start();
         $bar->advance();
         //            sleep( 1 );
         $resTmp = ob_get_clean();
         if (trim($resTmp) !== '') {
             $res[] = $resTmp;
         }
     }
     $refFile = dirname(__FILE__) . '/data/' . (ezcBaseFeatures::os() === "Windows" ? "windows/" : "posix/") . $refFile . '.dat';
     // Use the following line to regenerate test reference files
     // file_put_contents( $refFile, implode( PHP_EOL, $res ) );
     $expected = file_exists($refFile) ? file_get_contents($refFile) : '';
     $this->assertEquals($expected, implode(PHP_EOL, $res), 'Progressbar not correctly generated for ' . $refFile . '.');
 }
コード例 #17
0
ファイル: output.php プロジェクト: sakshika/ATM
 /**
  * Move the cursor to a specific column of the current line.
  *
  * Moves the cursor to a specific column index of the current line (default
  * is 1).
  * 
  * @param int $column Column to jump to.
  * @return void
  */
 public function toPos($column = 1)
 {
     if (ezcBaseFeatures::os() !== "Windows") {
         echo "[{$column}G";
     }
 }
コード例 #18
0
 public function testRestorePosFailure()
 {
     if (ezcBaseFeatures::os() === 'Windows') {
         $this->markTestSkipped("Does not work on Windows");
     }
     $output = new ezcConsoleOutput();
     try {
         $output->restorePos();
     } catch (ezcConsoleNoPositionStoredException $e) {
         return;
     }
     $this->fail("Exception not thrown on restore position without stored position.");
 }
コード例 #19
0
ファイル: file.php プロジェクト: Adeelgill/livehelperchat
 /**
  * Store data to the cache storage.
  * This method stores the given cache data into the cache, assigning the
  * ID given to it.
  *
  * The type of cache data which is expected by a ezcCacheStorage depends on
  * its implementation. In most cases strings and arrays will be accepted,
  * in some rare cases only strings might be accepted.
  *
  * Using attributes you can describe your cache data further. This allows
  * you to deal with multiple cache data at once later. Some ezcCacheStorage
  * implementations also use the attributes for storage purposes. Attributes
  * form some kind of "extended ID".
  *
  * @param string $id                        Unique identifier for the data.
  * @param mixed $data                       The data to store.
  * @param array(string=>string) $attributes Attributes describing the
  *                                          cached data.
  *
  * @return string The ID string of the newly cached data.
  *
  * @throws ezcBaseFilePermissionException
  *         If an already existsing cache file could not be unlinked to
  *         store the new data (may occur, when a cache item's TTL
  *         has expired and the file should be stored with more actual
  *         data). This exception means most likely that your cache directory
  *         has been corrupted by external influences (file permission
  *         change).
  * @throws ezcBaseFilePermissionException
  *         If the directory to store the cache file could not be created.
  *         This exception means most likely that your cache directory
  *         has been corrupted by external influences (file permission
  *         change).
  * @throws ezcBaseFileIoException
  *         If an error occured while writing the data to the cache. If this
  *         exception occurs, a serious error occured and your storage might
  *         be corruped (e.g. broken network connection, file system broken,
  *         ...).
  * @throws ezcCacheInvalidDataException
  *         If the data submitted can not be handled by the implementation
  *         of {@link ezcCacheStorageFile}. Most implementations can not
  *         handle objects and resources.
  */
 public function store($id, $data, $attributes = array())
 {
     $filename = $this->properties['location'] . $this->generateIdentifier($id, $attributes);
     if (file_exists($filename)) {
         if (unlink($filename) === false) {
             throw new ezcBaseFilePermissionException($filename, ezcBaseFileException::WRITE, 'Could not delete existsing cache file.');
         }
     }
     $dataStr = $this->prepareData($data);
     $dirname = dirname($filename);
     if (!is_dir($dirname) && !mkdir($dirname, 0777, true)) {
         throw new ezcBaseFilePermissionException($dirname, ezcBaseFileException::WRITE, 'Could not create directory to stor cache file.');
     }
     $this->storeRawData($filename, $dataStr);
     if (ezcBaseFeatures::os() !== "Windows") {
         chmod($filename, $this->options->permissions);
     }
     return $id;
 }
コード例 #20
0
ファイル: progressbar.php プロジェクト: sakshika/ATM
 /**
  * Draw the progress bar.
  * Prints the progress-bar to the screen. If start() has not been called 
  * yet, the current line is used for {@link ezcConsolProgressbar::start()}.
  *
  * @return void
  */
 public function output()
 {
     if ($this->options->minVerbosity > $this->output->options->verbosityLevel || $this->options->maxVerbosity !== false && $this->options->maxVerbosity < $this->output->options->verbosityLevel) {
         // Do not print progress bar if verbosity level is lower than it's
         // output objects value.
         return;
     }
     if ($this->started === false) {
         $this->start();
     }
     $this->output->restorePos();
     if (ezcBaseFeatures::os() === "Windows") {
         echo str_repeat("", $this->options->width);
     }
     $this->generateValues();
     echo $this->insertValues();
 }
コード例 #21
0
ファイル: apc_array.php プロジェクト: jordanmanning/ezpublish
 /**
  * Stores data to the cache storage.
  *
  * @throws ezcBaseFilePermissionException
  *         If the directory to store the cache file could not be created.
  *         This exception means most likely that your cache directory
  *         has been corrupted by external influences (file permission
  *         change).
  * @throws ezcBaseFileIoException
  *         If an error occured while writing the data to the cache. If this
  *         exception occurs, a serious error occured and your storage might
  *         be corruped (e.g. broken network connection, file system broken,
  *         ...).
  * @throws ezcCacheInvalidDataException
  *         If the data submitted can not be handled by the implementation
  *         of {@link ezcCacheStorageFile}. Most implementations can not
  *         handle objects and resources.
  * @throws ezcCacheApcException
  *         If the data could not be stored in APC.
  *
  * @param string $id Unique identifier
  * @param mixed $data The data to store
  * @param array(string=>string) $attributes Attributes describing the cached data
  * @return string The ID string of the newly cached data
  */
 public function store($id, $data, $attributes = array())
 {
     // Generates the identifier
     $filename = $this->properties['location'] . $this->generateIdentifier($id, $attributes);
     // Purges the Registry Cache
     if (isset($this->registry[$filename])) {
         unset($this->registry[$filename]);
     }
     // Deletes the files if it already exists on the filesystem
     if (file_exists($filename)) {
         if (unlink($filename) === false) {
             throw new ezcBaseFilePermissionException($filename, ezcBaseFileException::WRITE, 'Could not delete existing cache file.');
         }
     }
     // Deletes the data from APC if it already exists
     $this->backend->delete($filename);
     // Prepares the data for filesystem storage
     $dataStr = $this->prepareData($data);
     // Tries to create the directory on the filesystem
     $dirname = dirname($filename);
     if (!is_dir($dirname) && !mkdir($dirname, 0777, true)) {
         throw new ezcBaseFilePermissionException($dirname, ezcBaseFileException::WRITE, 'Could not create directory to store cache file.');
     }
     // Tries to write the file the filesystem
     if (@file_put_contents($filename, $dataStr) !== strlen($dataStr)) {
         throw new ezcBaseFileIoException($filename, ezcBaseFileException::WRITE, 'Could not write data to cache file.');
     }
     // Tries to set the file permissions
     if (ezcBaseFeatures::os() !== "Windows") {
         chmod($filename, $this->options->permissions);
     }
     // Prepares the data for APC storage
     $dataObj = $this->prepareData($data, true);
     $dataObj->mtime = @filemtime($filename);
     $dataObj->atime = time();
     // Stores it in APC
     $this->registerIdentifier($id, $attributes, $filename);
     if (!$this->backend->store($filename, $dataObj, $this->properties['options']['ttl'])) {
         throw new ezcCacheApcException("APC store failed.");
     }
     // Returns the ID for no good reason
     return $id;
 }
コード例 #22
0
 /**
  * Apply the given filters for the transformation.
  * Applies the conversion as defined to the given file and saves it as 
  * defined.
  *
  * @param string $fileIn  The file to transform.
  * @param string $fileOut The file to save the transformed image to.
  * @return void
  *
  * @throws ezcImageTransformationException If an error occurs during the 
  *         transformation. The returned exception contains the exception
  *         the problem resulted from in it's public $parent attribute.
  * @throws ezcBaseFileNotFoundException If the file you are trying to 
  *         transform does not exists.
  * @throws ezcBaseFilePermissionException If the file you are trying to 
  *         transform is not readable.
  */
 public function transform($fileIn, $fileOut)
 {
     // Sanity checks
     if (!is_file($fileIn)) {
         throw new ezcBaseFileNotFoundException($fileIn);
     }
     if (!is_readable($fileIn)) {
         throw new ezcBaseFilePermissionException($fileIn, ezcBaseFileException::READ);
     }
     // Start atomic file operation
     $fileTmp = tempnam(dirname($fileOut) . DIRECTORY_SEPARATOR, '.' . basename($fileOut));
     copy($fileIn, $fileTmp);
     try {
         // MIME types
         $analyzer = new ezcImageAnalyzer($fileTmp);
         // Do not process animated GIFs
         if ($analyzer->data->isAnimated) {
             copy($fileTmp, $fileOut);
             unlink($fileTmp);
             return;
         }
         $mimeIn = $analyzer->mime;
     } catch (ezcImageAnalyzerException $e) {
         // Clean up
         unlink($fileTmp);
         // Rethrow
         throw new ezcImageTransformationException($e);
     }
     $outMime = $this->getOutMime($fileTmp, $mimeIn);
     $ref = '';
     // Catch exceptions for cleanup
     try {
         // Apply the filters
         foreach ($this->filters as $filter) {
             // Avoid reopening in same handler
             if (isset($this->lastHandler)) {
                 if ($this->lastHandler->hasFilter($filter->name)) {
                     $this->lastHandler->applyFilter($ref, $filter);
                     continue;
                 } else {
                     // Handler does not support filter, save file
                     $this->lastHandler->save($ref);
                     $this->lastHandler->close($ref);
                 }
             }
             // Get handler to perform filter correctly
             $this->lastHandler = $this->converter->getHandler($filter->name, $mimeIn);
             $ref = $this->lastHandler->load($fileTmp, $mimeIn);
             $this->lastHandler->applyFilter($ref, $filter);
         }
         // When no filters are performed by a transformation, we might have no last handler here
         if (!isset($this->lastHandler)) {
             $this->lastHandler = $this->converter->getHandler(null, $mimeIn, $outMime);
             $ref = $this->lastHandler->load($fileTmp, $mimeIn);
         }
         // Perform conversion
         if ($this->lastHandler->allowsOutput($outMime)) {
             $this->lastHandler->convert($ref, $outMime);
         } else {
             // Close in last handler
             $this->lastHandler->save($ref);
             $this->lastHandler->close($ref);
             // Destroy invalid reference (has been closed)
             $ref = null;
             // Retreive correct handler
             $this->lastHandler = $this->converter->getHandler(null, $mimeIn, $outMime);
             // Load in new handler
             $ref = $this->lastHandler->load($fileTmp);
             // Perform conversion
             $this->lastHandler->convert($ref, $outMime);
         }
         // Everything done, save and close
         $this->lastHandler->save($ref, null, null, $this->saveOptions);
         $this->lastHandler->close($ref);
     } catch (ezcImageException $e) {
         // Cleanup
         if ($ref !== null) {
             $this->lastHandler->close($ref);
         }
         if (file_exists($fileTmp)) {
             unlink($fileTmp);
         }
         $this->lastHandler = null;
         // Rethrow
         throw new ezcImageTransformationException($e);
     }
     // Cleanup
     $this->lastHandler = null;
     // Finalize atomic file operation
     if (ezcBaseFeatures::os() === 'Windows' && file_exists($fileOut)) {
         // Windows does not allows overwriting files using rename,
         // therefore the file is unlinked here first.
         if (unlink($fileOut) === false) {
             // Cleanup
             unlink($fileTmp);
             throw new ezcImageFileNotProcessableException($fileOut, 'The file exists and could not be unlinked.');
         }
     }
     if (@rename($fileTmp, $fileOut) === false) {
         unlink($fileTmp);
         throw new ezcImageFileNotProcessableException($fileOut, "The temporary file {$fileTmp} could not be renamed to {$fileOut}.");
     }
 }
コード例 #23
0
ファイル: file.php プロジェクト: corcre/elabftw
 /**
  * Returns whether the passed $path is an absolute path, giving the current $os.
  *
  * With the $os parameter you can tell this function to use the semantics
  * for a different operating system to determine whether a path is
  * absolute. The $os argument defaults to the OS that the script is running
  * on.
  *
  * @param string $path
  * @param string $os
  * @return bool
  */
 public static function isAbsolutePath($path, $os = null)
 {
     if ($os === null) {
         $os = ezcBaseFeatures::os();
     }
     // Stream wrapper like phar can also be considered absolute paths
     if (preg_match('(^[a-z]{3,}://)S', $path)) {
         return true;
     }
     switch ($os) {
         case 'Windows':
             // Sanitize the paths to use the correct directory separator for the platform
             $path = strtr($path, '\\/', '\\\\');
             // Absolute paths with drive letter: X:\
             if (preg_match('@^[A-Z]:\\\\@i', $path)) {
                 return true;
             }
             // Absolute paths with network paths: \\server\share\
             if (preg_match('@^\\\\\\\\[A-Z]+\\\\[^\\\\]@i', $path)) {
                 return true;
             }
             break;
         case 'Mac':
         case 'Linux':
         case 'FreeBSD':
         default:
             // Sanitize the paths to use the correct directory separator for the platform
             $path = strtr($path, '\\/', '//');
             if ($path[0] == '/') {
                 return true;
             }
     }
     return false;
 }
コード例 #24
0
 public static function testAbsoluteLinux3()
 {
     if (ezcBaseFeatures::os() === 'Windows') {
         self::markTestSkipped('Test is for unix-like systems only');
     }
     self::assertEquals(false, ezcBaseFile::isAbsolutePath('c://winnt//winnt.sys'));
     self::assertEquals(false, ezcBaseFile::isAbsolutePath('c:/winnt/winnt.sys'));
     self::assertEquals(false, ezcBaseFile::isAbsolutePath('c://winnt'));
     self::assertEquals(false, ezcBaseFile::isAbsolutePath('c://winnt.sys'));
     self::assertEquals(false, ezcBaseFile::isAbsolutePath('c:/winnt.sys'));
     self::assertEquals(false, ezcBaseFile::isAbsolutePath('c://winnt.sys'));
     self::assertEquals(false, ezcBaseFile::isAbsolutePath('c:/table.sys'));
     self::assertEquals(false, ezcBaseFile::isAbsolutePath('c:winnt'));
     self::assertEquals(false, ezcBaseFile::isAbsolutePath('c//winnt.sys'));
     self::assertEquals(true, ezcBaseFile::isAbsolutePath('//winnt.sys'));
     self::assertEquals(true, ezcBaseFile::isAbsolutePath('/winnt.sys'));
     self::assertEquals(false, ezcBaseFile::isAbsolutePath('winnt.sys'));
     self::assertEquals(true, ezcBaseFile::isAbsolutePath('//server/share/foo.sys'));
     self::assertEquals(true, ezcBaseFile::isAbsolutePath('////server/share/foo.sys'));
     self::assertEquals(true, ezcBaseFile::isAbsolutePath('//tequila/share/foo.sys'));
     self::assertEquals(true, ezcBaseFile::isAbsolutePath('////tequila/share/foo.sys'));
     self::assertEquals(true, ezcBaseFile::isAbsolutePath('//tequila/thare/foo.sys'));
     self::assertEquals(true, ezcBaseFile::isAbsolutePath('////tequila/thare/foo.sys'));
     self::assertEquals(true, ezcBaseFile::isAbsolutePath('//server//share/foo.sys'));
     self::assertEquals(true, ezcBaseFile::isAbsolutePath('////server//share/foo.sys'));
     self::assertEquals(true, ezcBaseFile::isAbsolutePath('//tequila//share/foo.sys'));
     self::assertEquals(true, ezcBaseFile::isAbsolutePath('////tequila//share/foo.sys'));
     self::assertEquals(true, ezcBaseFile::isAbsolutePath('/etc/init.d/apache'));
     self::assertEquals(true, ezcBaseFile::isAbsolutePath('//etc//init.d//apache'));
     self::assertEquals(false, ezcBaseFile::isAbsolutePath('etc/init.d/apache'));
     self::assertEquals(false, ezcBaseFile::isAbsolutePath('etc//init.d//apache'));
 }
コード例 #25
0
 /**
  * Run the binary registered in ezcImageAnalyzerImagemagickHandler::$binary.
  *
  * This method executes the ImageMagick binary using the applied parameter
  * string. It returns the return value of the command. The output printed
  * to STDOUT and ERROUT is available through the $stdOut and $errOut
  * parameters.
  *
  * @param string $parameters    The parameters for the binary to execute.
  * @param string $stdOut        The standard output.
  * @param string $errOut        The error output.
  * @param bool   $stripNewlines Wether to strip the newlines from STDOUT.
  * @return int The return value of the command (0 on success).
  */
 protected function runCommand($parameters, &$stdOut, &$errOut, $stripNewlines = true)
 {
     $command = (ezcBaseFeatures::os() === 'Windows' ? $this->binary : escapeshellcmd($this->binary)) . ($parameters !== '' ? ' ' . $parameters : '');
     // Prepare to run ImageMagick command
     $descriptors = array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w'));
     // Open ImageMagick process
     $process = proc_open($command, $descriptors, $pipes);
     // Close STDIN pipe
     fclose($pipes[0]);
     // Read STDOUT
     $stdOut = '';
     do {
         $stdOut .= $stripNewlines === true ? rtrim(fgets($pipes[1], 1024), "\n") : fgets($pipes[1], 1024);
     } while (!feof($pipes[1]));
     // Read STDERR
     $errOut = '';
     do {
         $errOut .= rtrim(fgets($pipes[2], 1024), "\n");
     } while (!feof($pipes[2]));
     // Wait for process to terminate and store return value
     return proc_close($process);
 }