Merge branch 'refs/heads/master' into develop
Conflicts: changelog.txt
This commit is contained in:
commit
12a79779bf
|
|
@ -94,25 +94,13 @@ class PHPWord_Media
|
||||||
if (!$isMemImage) {
|
if (!$isMemImage) {
|
||||||
$isMemImage = (filter_var($src, FILTER_VALIDATE_URL) !== false);
|
$isMemImage = (filter_var($src, FILTER_VALIDATE_URL) !== false);
|
||||||
}
|
}
|
||||||
$extension = '';
|
|
||||||
if ($isMemImage) {
|
if ($isMemImage) {
|
||||||
$extension = $memoryImage->getImageExtension();
|
$extension = $memoryImage->getImageExtension();
|
||||||
$media['isMemImage'] = true;
|
$media['isMemImage'] = true;
|
||||||
$media['createfunction'] = $memoryImage->getImageCreateFunction();
|
$media['createfunction'] = $memoryImage->getImageCreateFunction();
|
||||||
$media['imagefunction'] = $memoryImage->getImageFunction();
|
$media['imagefunction'] = $memoryImage->getImageFunction();
|
||||||
} else {
|
} else {
|
||||||
$imageType = exif_imagetype($src);
|
$extension = PHPWord_Shared_File::imagetype($src);
|
||||||
if ($imageType === IMAGETYPE_JPEG) {
|
|
||||||
$extension = 'jpg';
|
|
||||||
} elseif ($imageType === IMAGETYPE_GIF) {
|
|
||||||
$extension = 'gif';
|
|
||||||
} elseif ($imageType === IMAGETYPE_PNG) {
|
|
||||||
$extension = 'png';
|
|
||||||
} elseif ($imageType === IMAGETYPE_BMP) {
|
|
||||||
$extension = 'bmp';
|
|
||||||
} elseif ($imageType === IMAGETYPE_TIFF_II || $imageType === IMAGETYPE_TIFF_MM) {
|
|
||||||
$extension = 'tif';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$folder = 'media';
|
$folder = 'media';
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,6 @@ class PHPWord_Section_Image
|
||||||
*/
|
*/
|
||||||
private $_isWatermark;
|
private $_isWatermark;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Image
|
* Create a new Image
|
||||||
*
|
*
|
||||||
|
|
@ -72,13 +71,11 @@ class PHPWord_Section_Image
|
||||||
*/
|
*/
|
||||||
public function __construct($src, $style = null, $isWatermark = false)
|
public function __construct($src, $style = null, $isWatermark = false)
|
||||||
{
|
{
|
||||||
$supportedImageTypes = array(IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM);
|
|
||||||
|
|
||||||
if (!file_exists($src)) {
|
if (!file_exists($src)) {
|
||||||
throw new InvalidImageException;
|
throw new InvalidImageException;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!in_array(exif_imagetype($src), $supportedImageTypes)) {
|
if (!PHPWord_Shared_File::imagetype($src)) {
|
||||||
throw new UnsupportedImageTypeException;
|
throw new UnsupportedImageTypeException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,15 +30,20 @@
|
||||||
*/
|
*/
|
||||||
class PHPWord_Shared_File
|
class PHPWord_Shared_File
|
||||||
{
|
{
|
||||||
|
const IMAGETYPE_JPEG = 'jpg';
|
||||||
|
const IMAGETYPE_GIF = 'gif';
|
||||||
|
const IMAGETYPE_PNG = 'png';
|
||||||
|
const IMAGETYPE_BMP = 'bmp';
|
||||||
|
const IMAGETYPE_TIFF = 'tif';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify if a file exists
|
* Verify if a file exists
|
||||||
*
|
*
|
||||||
* @param string $pFilename Filename
|
* @param string $pFilename Filename
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function file_exists($pFilename)
|
public static function file_exists($pFilename)
|
||||||
{
|
{
|
||||||
// Regular file_exists
|
|
||||||
return file_exists($pFilename);
|
return file_exists($pFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,18 +55,13 @@ class PHPWord_Shared_File
|
||||||
*/
|
*/
|
||||||
public static function realpath($pFilename)
|
public static function realpath($pFilename)
|
||||||
{
|
{
|
||||||
// Returnvalue
|
|
||||||
$returnValue = '';
|
|
||||||
|
|
||||||
// Try using realpath()
|
|
||||||
$returnValue = realpath($pFilename);
|
$returnValue = realpath($pFilename);
|
||||||
|
|
||||||
// Found something?
|
if (!$returnValue) {
|
||||||
if ($returnValue == '' || is_null($returnValue)) {
|
|
||||||
$pathArray = explode('/', $pFilename);
|
$pathArray = explode('/', $pFilename);
|
||||||
while (in_array('..', $pathArray) && $pathArray[0] != '..') {
|
while (in_array('..', $pathArray) && $pathArray[0] !== '..') {
|
||||||
for ($i = 0; $i < count($pathArray); ++$i) {
|
for ($i = 0; $i < count($pathArray); ++$i) {
|
||||||
if ($pathArray[$i] == '..' && $i > 0) {
|
if ($pathArray[$i] === '..' && $i > 0) {
|
||||||
unset($pathArray[$i]);
|
unset($pathArray[$i]);
|
||||||
unset($pathArray[$i - 1]);
|
unset($pathArray[$i - 1]);
|
||||||
break;
|
break;
|
||||||
|
|
@ -71,7 +71,58 @@ class PHPWord_Shared_File
|
||||||
$returnValue = implode('/', $pathArray);
|
$returnValue = implode('/', $pathArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return
|
|
||||||
return $returnValue;
|
return $returnValue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* PHP Words version of exif_imagetype to return the Image Type from a file
|
||||||
|
*
|
||||||
|
* @param string $filename
|
||||||
|
* @return int|bool
|
||||||
|
*/
|
||||||
|
private static function fallbackImagetype($filename)
|
||||||
|
{
|
||||||
|
if ((list($width, $height, $type, $attr) = getimagesize($filename)) !== false) {
|
||||||
|
if ($type === 2) {
|
||||||
|
return self::IMAGETYPE_JPEG;
|
||||||
|
} elseif ($type === 1) {
|
||||||
|
return self::IMAGETYPE_GIF;
|
||||||
|
} elseif ($type === 3) {
|
||||||
|
return self::IMAGETYPE_PNG;
|
||||||
|
} elseif ($type === 6) {
|
||||||
|
return self::IMAGETYPE_BMP;
|
||||||
|
} elseif ($type === 7 || $type === 8) {
|
||||||
|
return self::IMAGETYPE_TIFF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the Image Type from a file
|
||||||
|
*
|
||||||
|
* @param string $filename
|
||||||
|
* @param bool $userFallbackFunction
|
||||||
|
* @return int|bool
|
||||||
|
*/
|
||||||
|
public static function imagetype($filename, $userFallbackFunction = false)
|
||||||
|
{
|
||||||
|
if ($userFallbackFunction || !function_exists('exif_imagetype')) {
|
||||||
|
return self::fallbackImagetype($filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
$imagetype = exif_imagetype($filename);
|
||||||
|
if ($imagetype === IMAGETYPE_JPEG) {
|
||||||
|
return self::IMAGETYPE_JPEG;
|
||||||
|
} elseif ($imagetype === IMAGETYPE_GIF) {
|
||||||
|
return self::IMAGETYPE_GIF;
|
||||||
|
} elseif ($imagetype === IMAGETYPE_PNG) {
|
||||||
|
return self::IMAGETYPE_PNG;
|
||||||
|
} elseif ($imagetype === IMAGETYPE_BMP) {
|
||||||
|
return self::IMAGETYPE_BMP;
|
||||||
|
} elseif ($imagetype === IMAGETYPE_TIFF_II || $imagetype === IMAGETYPE_TIFF_MM) {
|
||||||
|
return self::IMAGETYPE_TIFF;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -212,21 +212,10 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
|
||||||
if (stripos(strrev($src), strrev('.php')) === 0) {
|
if (stripos(strrev($src), strrev('.php')) === 0) {
|
||||||
$extension = 'php';
|
$extension = 'php';
|
||||||
} else {
|
} else {
|
||||||
$imageType = exif_imagetype($src);
|
$extension = PHPWord_Shared_File::imagetype($src);
|
||||||
if ($imageType === IMAGETYPE_JPEG) {
|
|
||||||
$extension = 'jpg';
|
|
||||||
} elseif ($imageType === IMAGETYPE_GIF) {
|
|
||||||
$extension = 'gif';
|
|
||||||
} elseif ($imageType === IMAGETYPE_PNG) {
|
|
||||||
$extension = 'png';
|
|
||||||
} elseif ($imageType === IMAGETYPE_BMP) {
|
|
||||||
$extension = 'bmp';
|
|
||||||
} elseif ($imageType === IMAGETYPE_TIFF_II || $imageType === IMAGETYPE_TIFF_MM) {
|
|
||||||
$extension = 'tif';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($extension)) {
|
if (isset($extension) && $extension) {
|
||||||
$imageData = getimagesize($src);
|
$imageData = getimagesize($src);
|
||||||
$imageType = image_type_to_mime_type($imageData[2]);
|
$imageType = image_type_to_mime_type($imageData[2]);
|
||||||
$imageExtension = str_replace('.', '', image_type_to_extension($imageData[2]));
|
$imageExtension = str_replace('.', '', image_type_to_extension($imageData[2]));
|
||||||
|
|
@ -236,10 +225,8 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
|
||||||
if (!in_array($imageType, $this->_imageTypes)) {
|
if (!in_array($imageType, $this->_imageTypes)) {
|
||||||
$this->_imageTypes[$imageExtension] = $imageType;
|
$this->_imageTypes[$imageExtension] = $imageType;
|
||||||
}
|
}
|
||||||
} else {
|
} elseif (!in_array($extension, $this->_objectTypes)) {
|
||||||
if (!in_array($extension, $this->_objectTypes)) {
|
$this->_objectTypes[] = $extension;
|
||||||
$this->_objectTypes[] = $extension;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,4 +54,39 @@ class FileTest extends \PHPUnit_Framework_TestCase
|
||||||
$expected = $dir . DIRECTORY_SEPARATOR . $file;
|
$expected = $dir . DIRECTORY_SEPARATOR . $file;
|
||||||
$this->assertEquals($expected, PHPWord_Shared_File::realpath($file));
|
$this->assertEquals($expected, PHPWord_Shared_File::realpath($file));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* @covers PHPWord_Shared_File::imagetype
|
||||||
|
* @covers PHPWord_Shared_File::fallbackImagetype
|
||||||
|
*/
|
||||||
|
public function testImagetype()
|
||||||
|
{
|
||||||
|
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg";
|
||||||
|
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_JPEG, PHPWord_Shared_File::imagetype($filename, true));
|
||||||
|
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_JPEG, PHPWord_Shared_File::imagetype($filename));
|
||||||
|
|
||||||
|
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg";
|
||||||
|
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_JPEG, PHPWord_Shared_File::imagetype($filename, true));
|
||||||
|
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_JPEG, PHPWord_Shared_File::imagetype($filename));
|
||||||
|
|
||||||
|
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif";
|
||||||
|
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_GIF, PHPWord_Shared_File::imagetype($filename, true));
|
||||||
|
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_GIF, PHPWord_Shared_File::imagetype($filename));
|
||||||
|
|
||||||
|
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png";
|
||||||
|
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_PNG, PHPWord_Shared_File::imagetype($filename, true));
|
||||||
|
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_PNG, PHPWord_Shared_File::imagetype($filename));
|
||||||
|
|
||||||
|
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp";
|
||||||
|
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_BMP, PHPWord_Shared_File::imagetype($filename, true));
|
||||||
|
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_BMP, PHPWord_Shared_File::imagetype($filename));
|
||||||
|
|
||||||
|
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif";
|
||||||
|
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_TIFF, PHPWord_Shared_File::imagetype($filename, true));
|
||||||
|
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_TIFF, PHPWord_Shared_File::imagetype($filename));
|
||||||
|
|
||||||
|
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/alexz-johnson.pcx";
|
||||||
|
$this->assertFalse(PHPWord_Shared_File::imagetype($filename, true));
|
||||||
|
$this->assertFalse(PHPWord_Shared_File::imagetype($filename));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -84,4 +84,4 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
||||||
$element = $doc->getElement('/w:document/w:body/w:p[11]/w:r/w:object/o:OLEObject');
|
$element = $doc->getElement('/w:document/w:body/w:p[11]/w:r/w:object/o:OLEObject');
|
||||||
$this->assertEquals('Embed', $element->getAttribute('Type'));
|
$this->assertEquals('Embed', $element->getAttribute('Type'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -5,11 +5,14 @@ use PHPWord;
|
||||||
|
|
||||||
class TestHelperDOCX
|
class TestHelperDOCX
|
||||||
{
|
{
|
||||||
/** @var string $file */
|
/**
|
||||||
static protected $file;
|
* @var string
|
||||||
|
*/
|
||||||
|
protected static $file;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \PHPWord $PHPWord
|
* @param \PHPWord $PHPWord
|
||||||
|
* @param string $writer
|
||||||
* @return \PHPWord\Tests\XmlDocument
|
* @return \PHPWord\Tests\XmlDocument
|
||||||
*/
|
*/
|
||||||
public static function getDocument(PHPWord $PHPWord, $writer = 'Word2007')
|
public static function getDocument(PHPWord $PHPWord, $writer = 'Word2007')
|
||||||
|
|
@ -67,4 +70,4 @@ class TestHelperDOCX
|
||||||
{
|
{
|
||||||
return self::$file;
|
return self::$file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -22,8 +22,8 @@
|
||||||
* @version ##VERSION##, ##DATE##
|
* @version ##VERSION##, ##DATE##
|
||||||
**************************************************************************************
|
**************************************************************************************
|
||||||
|
|
||||||
Changes in branch for release 0.9.0 :
|
Changes in branch for release 0.8.1 :
|
||||||
- QA: (Progi1984) - Documentation
|
- Feature: (bskrtich, gabrielbull) - Added fallback for computers that do not have exif_imagetype
|
||||||
|
|
||||||
Changes in branch for release 0.8.0 :
|
Changes in branch for release 0.8.0 :
|
||||||
- Bugfix: (gabrielbull) - Fixed bug with cell styling
|
- Bugfix: (gabrielbull) - Fixed bug with cell styling
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue