diff --git a/Classes/PHPWord/Media.php b/Classes/PHPWord/Media.php index 28d3d033..82294132 100755 --- a/Classes/PHPWord/Media.php +++ b/Classes/PHPWord/Media.php @@ -86,11 +86,14 @@ class PHPWord_Media $file = null; if ($type === 'image') { $cImg++; + //Detect if it's a memory image first by php ext and second by regex $isMemImage = false; if (stripos(strrev($src), strrev('.php')) === 0) { $isMemImage = true; } - + if (!$isMemImage) { + $isMemImage = (filter_var($src, FILTER_VALIDATE_URL) !== false); + } $extension = ''; if ($isMemImage) { $extension = $memoryImage->getImageExtension(); diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index f1324253..0168a649 100755 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -751,9 +751,9 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart /** * @param \PHPWord_Shared_XMLWriter $objWriter - * @param \PHPWord_Section_Image $image + * @param \PHPWord_Section_Image|\PHPWord_Section_MemoryImage $image */ - protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Image $image, $withoutP = false) + protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, $image, $withoutP = false) { $rId = $image->getRelationId(); diff --git a/Tests/PHPWord/SettingsTest.php b/Tests/PHPWord/SettingsTest.php new file mode 100644 index 00000000..e61a2129 --- /dev/null +++ b/Tests/PHPWord/SettingsTest.php @@ -0,0 +1,26 @@ +assertTrue(PHPWord_Settings::getCompatibility()); + $this->assertTrue(PHPWord_Settings::setCompatibility(false)); + $this->assertFalse(PHPWord_Settings::getCompatibility()); + $this->assertFalse(PHPWord_Settings::setCompatibility('Non boolean')); + } +} diff --git a/changelog.txt b/changelog.txt index a76efb00..a75fa93c 100755 --- a/changelog.txt +++ b/changelog.txt @@ -51,6 +51,7 @@ Changes in branch for release 0.7.1 : - Feature: (ivanlanin) - Paragraph: setTabs() function - Feature: (ivanlanin) GH-99 - General: Basic support for TextRun on ODT and RTF - Feature: (ivanlanin) - Reader: Initial effort for Word2007 +- Feature: (ivanlanin) - MemoryImage: Allow remote image when allow_url_open = on - QA: (Progi1984) - UnitTests Changes in branch for release 0.7.0 : diff --git a/samples/Sample_00.php b/samples/Sample_00.php new file mode 100644 index 00000000..db490cbd --- /dev/null +++ b/samples/Sample_00.php @@ -0,0 +1,33 @@ +'); +require_once '../Classes/PHPWord.php'; + +// New Word document +echo date('H:i:s'), " Create new PHPWord object", EOL; +$PHPWord = new PHPWord(); + +// Begin code + + + +// End code + +// Save file +$name = basename(__FILE__, '.php'); +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} + +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; diff --git a/samples/Sample_12_HeaderFooter.php b/samples/Sample_12_HeaderFooter.php new file mode 100644 index 00000000..b0d0e137 --- /dev/null +++ b/samples/Sample_12_HeaderFooter.php @@ -0,0 +1,74 @@ +'); +require_once '../Classes/PHPWord.php'; + +// New Word document +echo date('H:i:s') , " Create new PHPWord object" , EOL; +$PHPWord = new PHPWord(); + +// New portrait section +$section = $PHPWord->createSection(); + +// Add first page header +$header = $section->createHeader(); +$header->firstPage(); +$table = $header->addTable(); +$table->addRow(); +$table->addCell(4500)->addText('This is the header.'); +$table->addCell(4500)->addImage( + 'resources/PHPWord.png', + array('width' => 80, 'height' => 80, 'align' => 'right') +); + +// Add header for all other pages +$subsequent = $section->createHeader(); +$subsequent->addText("Subsequent pages in Section 1 will Have this!"); + +// Add footer +$footer = $section->createFooter(); +$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', array('align' => 'center')); + +// Write some text +$section->addTextBreak(); +$section->addText('Some text...'); + +// Create a second page +$section->addPageBreak(); + +// Write some text +$section->addTextBreak(); +$section->addText('Some text...'); + +// Create a third page +$section->addPageBreak(); + +// Write some text +$section->addTextBreak(); +$section->addText('Some text...'); + +// New portrait section +$section2 = $PHPWord->createSection(); + +$sec2Header = $section2->createHeader(); +$sec2Header->addText("All pages in Section 2 will Have this!"); + +// Write some text +$section2->addTextBreak(); +$section2->addText('Some text...'); + + +// Save file +$name = basename(__FILE__, '.php'); +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} + +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; diff --git a/samples/Sample_13_Images.php b/samples/Sample_13_Images.php new file mode 100644 index 00000000..0f64cb7b --- /dev/null +++ b/samples/Sample_13_Images.php @@ -0,0 +1,42 @@ +'); +require_once '../Classes/PHPWord.php'; + +// New Word document +echo date('H:i:s'), " Create new PHPWord object", EOL; +$PHPWord = new PHPWord(); + +// Begin code +$section = $PHPWord->createSection(); +$section->addText('Local image without any styles:'); +$section->addImage('resources/_mars.jpg'); +$section->addTextBreak(2); +// +$section->addText('Local image with styles:'); +$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'align' => 'center')); +$section->addTextBreak(2); + +$source = 'http://php.net/images/logos/php-med-trans-light.gif'; +$section->addText("Remote image from: {$source}"); +$section->addMemoryImage($source); +// End code + +// Save file +$name = basename(__FILE__, '.php'); +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} + +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; diff --git a/samples/resources/PHPWord.png b/samples/resources/PHPWord.png new file mode 100644 index 00000000..9b7f4930 Binary files /dev/null and b/samples/resources/PHPWord.png differ diff --git a/samples/resources/_earth.jpg b/samples/resources/_earth.jpg new file mode 100644 index 00000000..28537b06 Binary files /dev/null and b/samples/resources/_earth.jpg differ diff --git a/samples/resources/_mars.jpg b/samples/resources/_mars.jpg new file mode 100644 index 00000000..584d3171 Binary files /dev/null and b/samples/resources/_mars.jpg differ