From ec3c62b0518b1f472e28dddf49fe563875c34ddb Mon Sep 17 00:00:00 2001 From: Roman Syroeshko Date: Sat, 4 Jun 2016 20:06:37 +0400 Subject: [PATCH] #483. Output escaping for OOXML. --- README.md | 28 ++---- docs/general.rst | 50 +++++----- phpword.ini.dist | 11 ++- samples/Sample_01_SimpleText.php | 83 ++++++++-------- samples/Sample_02_TabStops.php | 25 +++-- samples/Sample_03_Sections.php | 18 ++-- samples/Sample_04_Textrun.php | 52 +++++----- samples/Sample_05_Multicolumn.php | 10 +- samples/Sample_06_Footnote.php | 54 +++++------ samples/Sample_07_TemplateCloneRow.php | 72 +++++++------- samples/Sample_08_ParagraphPagination.php | 64 +++++-------- samples/Sample_09_Tables.php | 74 ++++++++------- samples/Sample_10_EastAsianFontStyle.php | 2 +- samples/Sample_12_HeaderFooter.php | 20 ++-- samples/Sample_13_Images.php | 16 ++-- samples/Sample_14_ListItem.php | 94 ++++++++++--------- samples/Sample_15_Link.php | 14 +-- samples/Sample_16_Object.php | 2 +- samples/Sample_17_TitleTOC.php | 57 ++++++----- samples/Sample_18_Watermark.php | 3 +- samples/Sample_19_TextBreak.php | 38 ++++---- samples/Sample_20_BGColor.php | 11 +-- samples/Sample_21_TableRowRules.php | 30 ++---- samples/Sample_22_CheckBox.php | 10 +- samples/Sample_25_TextBox.php | 21 +++-- samples/Sample_27_Field.php | 12 +-- samples/Sample_29_Line.php | 10 +- samples/Sample_31_Shape.php | 18 ++-- samples/Sample_32_Chart.php | 7 +- samples/Sample_33_FormField.php | 11 ++- samples/Sample_34_SDT.php | 7 +- samples/Sample_35_InternalLink.php | 8 +- samples/Sample_36_RTL.php | 6 +- samples/Sample_Header.php | 3 + src/PhpWord/Escaper/AbstractEscaper.php | 46 +++++++++ src/PhpWord/Escaper/EscaperInterface.php | 4 +- src/PhpWord/Escaper/RegExp.php | 24 +---- src/PhpWord/Escaper/Xml.php | 32 +++++++ src/PhpWord/Settings.php | 33 +++++++ src/PhpWord/TemplateProcessor.php | 12 ++- .../Writer/Word2007/Element/CheckBox.php | 9 +- src/PhpWord/Writer/Word2007/Element/Field.php | 4 +- .../Writer/Word2007/Element/FormField.php | 9 +- src/PhpWord/Writer/Word2007/Element/Link.php | 7 +- .../Writer/Word2007/Element/PreserveText.php | 13 ++- src/PhpWord/Writer/Word2007/Element/SDT.php | 4 +- src/PhpWord/Writer/Word2007/Element/TOC.php | 15 ++- src/PhpWord/Writer/Word2007/Element/Text.php | 7 +- src/PhpWord/Writer/Word2007/Element/Title.php | 11 ++- src/PhpWord/Writer/Word2007/Part/Chart.php | 12 ++- .../Writer/Word2007/Part/DocPropsCore.php | 4 +- .../Writer/Word2007/Part/DocPropsCustom.php | 4 +- .../Writer/Word2007/Part/Footnotes.php | 2 +- tests/PhpWord/Element/CellTest.php | 30 +++--- tests/PhpWord/Element/CheckBoxTest.php | 12 +-- tests/PhpWord/Element/FooterTest.php | 16 ++-- tests/PhpWord/Element/FootnoteTest.php | 2 +- tests/PhpWord/Element/HeaderTest.php | 18 ++-- tests/PhpWord/Element/LinkTest.php | 4 +- tests/PhpWord/Element/ListItemRunTest.php | 12 +-- tests/PhpWord/Element/ListItemTest.php | 11 +-- tests/PhpWord/Element/PreserveTextTest.php | 10 +- tests/PhpWord/Element/SectionTest.php | 12 +-- tests/PhpWord/Element/TOCTest.php | 2 +- tests/PhpWord/Element/TextRunTest.php | 12 +-- tests/PhpWord/Element/TextTest.php | 10 +- tests/PhpWord/Element/TitleTest.php | 6 +- tests/PhpWord/SettingsTest.php | 13 +-- tests/PhpWord/Style/FontTest.php | 6 +- tests/PhpWord/Style/ParagraphTest.php | 2 +- tests/PhpWord/TemplateProcessorTest.php | 12 +-- tests/PhpWord/Writer/PDF/DomPDFTest.php | 2 +- tests/PhpWord/Writer/PDF/MPDFTest.php | 2 +- tests/PhpWord/Writer/PDF/TCPDFTest.php | 2 +- tests/PhpWord/Writer/Word2007/ElementTest.php | 4 +- .../Writer/Word2007/Part/DocumentTest.php | 64 ++++++------- .../Writer/Word2007/Part/FooterTest.php | 6 +- .../Writer/Word2007/Part/FootnotesTest.php | 6 +- .../Writer/Word2007/Part/HeaderTest.php | 6 +- .../Writer/Word2007/Style/FontTest.php | 2 +- tests/PhpWord/Writer/Word2007Test.php | 10 +- 81 files changed, 790 insertions(+), 697 deletions(-) create mode 100644 src/PhpWord/Escaper/AbstractEscaper.php create mode 100644 src/PhpWord/Escaper/Xml.php diff --git a/README.md b/README.md index b3bfa53a45..d18561d7e6 100644 --- a/README.md +++ b/README.md @@ -93,11 +93,9 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); // Adding Text element to the Section having font styled by default... $section->addText( - htmlspecialchars( - '"Learn from yesterday, live for today, hope for tomorrow. ' - . 'The important thing is not to stop questioning." ' - . '(Albert Einstein)' - ) + '"Learn from yesterday, live for today, hope for tomorrow. ' + . 'The important thing is not to stop questioning." ' + . '(Albert Einstein)' ); /* @@ -109,11 +107,9 @@ $section->addText( // Adding Text element with font customized inline... $section->addText( - htmlspecialchars( - '"Great achievement is usually born of great sacrifice, ' - . 'and is never the result of selfishness." ' - . '(Napoleon Hill)' - ), + '"Great achievement is usually born of great sacrifice, ' + . 'and is never the result of selfishness." ' + . '(Napoleon Hill)', array('name' => 'Tahoma', 'size' => 10) ); @@ -124,11 +120,9 @@ $phpWord->addFontStyle( array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true) ); $section->addText( - htmlspecialchars( - '"The greatest accomplishment is not in never falling, ' - . 'but in rising again after you fall." ' - . '(Vince Lombardi)' - ), + '"The greatest accomplishment is not in never falling, ' + . 'but in rising again after you fall." ' + . '(Vince Lombardi)', $fontStyleName ); @@ -137,9 +131,7 @@ $fontStyle = new \PhpOffice\PhpWord\Style\Font(); $fontStyle->setBold(true); $fontStyle->setName('Tahoma'); $fontStyle->setSize(13); -$myTextElement = $section->addText( - htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)') -); +$myTextElement = $section->addText('"Believe you can and you\'re halfway there." (Theodor Roosevelt)'); $myTextElement->setFontStyle($fontStyle); // Saving the document as OOXML file... diff --git a/docs/general.rst b/docs/general.rst index 13bb1a7b69..27d0448abd 100644 --- a/docs/general.rst +++ b/docs/general.rst @@ -24,13 +24,9 @@ folder `__. $section = $phpWord->addSection(); // Adding Text element to the Section having font styled by default... $section->addText( - htmlspecialchars( - '"Learn from yesterday, live for today, hope for tomorrow. ' - . 'The important thing is not to stop questioning." ' - . '(Albert Einstein)', - ENT_COMPAT, - 'UTF-8' - ) + '"Learn from yesterday, live for today, hope for tomorrow. ' + . 'The important thing is not to stop questioning." ' + . '(Albert Einstein)' ); /* @@ -42,13 +38,9 @@ folder `__. // Adding Text element with font customized inline... $section->addText( - htmlspecialchars( - '"Great achievement is usually born of great sacrifice, ' - . 'and is never the result of selfishness." ' - . '(Napoleon Hill)', - ENT_COMPAT, - 'UTF-8' - ), + '"Great achievement is usually born of great sacrifice, ' + . 'and is never the result of selfishness." ' + . '(Napoleon Hill)', array('name' => 'Tahoma', 'size' => 10) ); @@ -59,13 +51,9 @@ folder `__. array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true) ); $section->addText( - htmlspecialchars( - '"The greatest accomplishment is not in never falling, ' - . 'but in rising again after you fall." ' - . '(Vince Lombardi)', - ENT_COMPAT, - 'UTF-8' - ), + '"The greatest accomplishment is not in never falling, ' + . 'but in rising again after you fall." ' + . '(Vince Lombardi)', $fontStyleName ); @@ -74,9 +62,7 @@ folder `__. $fontStyle->setBold(true); $fontStyle->setName('Tahoma'); $fontStyle->setSize(13); - $myTextElement = $section->addText( - htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)', ENT_COMPAT, 'UTF-8') - ); + $myTextElement = $section->addText('"Believe you can and you\'re halfway there." (Theodor Roosevelt)'); $myTextElement->setFontStyle($fontStyle); // Saving the document as OOXML file... @@ -130,8 +116,22 @@ included with PHPWord. \PhpOffice\PhpWord\Settings::setZipClass(\PhpOffice\PhpWord\Settings::PCLZIP); +Output escaping +~~~~~~~~~~~~~~~ + +Writing documents of some formats, especially XML-based, requires correct output escaping. +Without it your document may become broken when you put special characters like ampersand, quotes, and others in it. + +Escaping can be performed in two ways: outside of the library by a software developer and inside of the library by built-in mechanism. +By default, the built-in mechanism is disabled for backward compatibility with versions prior to v0.13.0. +To turn it on set ``outputEscapingEnabled`` option to ``true`` in your PHPWord configuration file or use the following instruction at runtime: + +.. code-block:: php + + \PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true); + Default font ------------- +~~~~~~~~~~~~ By default, every text appears in Arial 10 point. You can alter the default font by using the following two functions: diff --git a/phpword.ini.dist b/phpword.ini.dist index f8eafb6a78..0f4cc358df 100644 --- a/phpword.ini.dist +++ b/phpword.ini.dist @@ -3,11 +3,12 @@ [General] -compatibility = true -zipClass = ZipArchive -pdfRendererName = DomPDF -pdfRendererPath = -; tempDir = "C:\PhpWordTemp" +compatibility = true +zipClass = ZipArchive +pdfRendererName = DomPDF +pdfRendererPath = +; tempDir = "C:\PhpWordTemp" +outputEscapingEnabled = false [Font] diff --git a/samples/Sample_01_SimpleText.php b/samples/Sample_01_SimpleText.php index d8d5915ab5..1e51b2c072 100644 --- a/samples/Sample_01_SimpleText.php +++ b/samples/Sample_01_SimpleText.php @@ -4,24 +4,29 @@ // New Word Document echo date('H:i:s') , ' Create new PhpWord object' , EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); -$phpWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true)); -$phpWord->addParagraphStyle('pStyle', array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER, 'spaceAfter' => 100)); + +$fontStyleName = 'rStyle'; +$phpWord->addFontStyle($fontStyleName, array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true)); + +$paragraphStyleName = 'pStyle'; +$phpWord->addParagraphStyle($paragraphStyleName, array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER, 'spaceAfter' => 100)); + $phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240)); // New portrait section $section = $phpWord->addSection(); // Simple text -$section->addTitle(htmlspecialchars('Welcome to PhpWord', ENT_COMPAT, 'UTF-8'), 1); -$section->addText(htmlspecialchars('Hello World!', ENT_COMPAT, 'UTF-8')); +$section->addTitle('Welcome to PhpWord', 1); +$section->addText('Hello World!'); // Two text break $section->addTextBreak(2); -// Defined style -$section->addText(htmlspecialchars('I am styled by a font style definition.', ENT_COMPAT, 'UTF-8'), 'rStyle'); -$section->addText(htmlspecialchars('I am styled by a paragraph style definition.', ENT_COMPAT, 'UTF-8'), null, 'pStyle'); -$section->addText(htmlspecialchars('I am styled by both font and paragraph style.', ENT_COMPAT, 'UTF-8'), 'rStyle', 'pStyle'); +// Define styles +$section->addText('I am styled by a font style definition.', $fontStyleName); +$section->addText('I am styled by a paragraph style definition.', null, $paragraphStyleName); +$section->addText('I am styled by both font and paragraph style.', $fontStyleName, $paragraphStyleName); $section->addTextBreak(); @@ -30,39 +35,39 @@ $fontStyle['size'] = 20; $textrun = $section->addTextRun(); -$textrun->addText(htmlspecialchars('I am inline styled ', ENT_COMPAT, 'UTF-8'), $fontStyle); -$textrun->addText(htmlspecialchars('with ', ENT_COMPAT, 'UTF-8')); -$textrun->addText(htmlspecialchars('color', ENT_COMPAT, 'UTF-8'), array('color' => '996699')); -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); -$textrun->addText(htmlspecialchars('bold', ENT_COMPAT, 'UTF-8'), array('bold' => true)); -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); -$textrun->addText(htmlspecialchars('italic', ENT_COMPAT, 'UTF-8'), array('italic' => true)); -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); -$textrun->addText(htmlspecialchars('underline', ENT_COMPAT, 'UTF-8'), array('underline' => 'dash')); -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); -$textrun->addText(htmlspecialchars('strikethrough', ENT_COMPAT, 'UTF-8'), array('strikethrough' => true)); -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); -$textrun->addText(htmlspecialchars('doubleStrikethrough', ENT_COMPAT, 'UTF-8'), array('doubleStrikethrough' => true)); -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); -$textrun->addText(htmlspecialchars('superScript', ENT_COMPAT, 'UTF-8'), array('superScript' => true)); -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); -$textrun->addText(htmlspecialchars('subScript', ENT_COMPAT, 'UTF-8'), array('subScript' => true)); -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); -$textrun->addText(htmlspecialchars('smallCaps', ENT_COMPAT, 'UTF-8'), array('smallCaps' => true)); -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); -$textrun->addText(htmlspecialchars('allCaps', ENT_COMPAT, 'UTF-8'), array('allCaps' => true)); -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); -$textrun->addText(htmlspecialchars('fgColor', ENT_COMPAT, 'UTF-8'), array('fgColor' => 'yellow')); -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); -$textrun->addText(htmlspecialchars('scale', ENT_COMPAT, 'UTF-8'), array('scale' => 200)); -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); -$textrun->addText(htmlspecialchars('spacing', ENT_COMPAT, 'UTF-8'), array('spacing' => 120)); -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); -$textrun->addText(htmlspecialchars('kerning', ENT_COMPAT, 'UTF-8'), array('kerning' => 10)); -$textrun->addText(htmlspecialchars('. ', ENT_COMPAT, 'UTF-8')); +$textrun->addText('I am inline styled ', $fontStyle); +$textrun->addText('with '); +$textrun->addText('color', array('color' => '996699')); +$textrun->addText(', '); +$textrun->addText('bold', array('bold' => true)); +$textrun->addText(', '); +$textrun->addText('italic', array('italic' => true)); +$textrun->addText(', '); +$textrun->addText('underline', array('underline' => 'dash')); +$textrun->addText(', '); +$textrun->addText('strikethrough', array('strikethrough' => true)); +$textrun->addText(', '); +$textrun->addText('doubleStrikethrough', array('doubleStrikethrough' => true)); +$textrun->addText(', '); +$textrun->addText('superScript', array('superScript' => true)); +$textrun->addText(', '); +$textrun->addText('subScript', array('subScript' => true)); +$textrun->addText(', '); +$textrun->addText('smallCaps', array('smallCaps' => true)); +$textrun->addText(', '); +$textrun->addText('allCaps', array('allCaps' => true)); +$textrun->addText(', '); +$textrun->addText('fgColor', array('fgColor' => 'yellow')); +$textrun->addText(', '); +$textrun->addText('scale', array('scale' => 200)); +$textrun->addText(', '); +$textrun->addText('spacing', array('spacing' => 120)); +$textrun->addText(', '); +$textrun->addText('kerning', array('kerning' => 10)); +$textrun->addText('. '); // Link -$section->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8')); +$section->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); $section->addTextBreak(); // Image diff --git a/samples/Sample_02_TabStops.php b/samples/Sample_02_TabStops.php index 618454b299..1702198751 100644 --- a/samples/Sample_02_TabStops.php +++ b/samples/Sample_02_TabStops.php @@ -5,9 +5,10 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); -// Ads styles +// Define styles +$multipleTabsStyleName = 'multipleTab'; $phpWord->addParagraphStyle( - 'multipleTab', + $multipleTabsStyleName, array( 'tabs' => array( new \PhpOffice\PhpWord\Style\Tab('left', 1550), @@ -16,22 +17,20 @@ ) ) ); -$phpWord->addParagraphStyle( - 'rightTab', - array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('right', 9090))) -); -$phpWord->addParagraphStyle( - 'centerTab', - array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('center', 4680))) -); + +$rightTabStyleName = 'rightTab'; +$phpWord->addParagraphStyle($rightTabStyleName, array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('right', 9090)))); + +$leftTabStyleName = 'centerTab'; +$phpWord->addParagraphStyle($leftTabStyleName, array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('center', 4680)))); // New portrait section $section = $phpWord->addSection(); // Add listitem elements -$section->addText(htmlspecialchars("Multiple Tabs:\tOne\tTwo\tThree", ENT_COMPAT, 'UTF-8'), null, 'multipleTab'); -$section->addText(htmlspecialchars("Left Aligned\tRight Aligned", ENT_COMPAT, 'UTF-8'), null, 'rightTab'); -$section->addText(htmlspecialchars("\tCenter Aligned", ENT_COMPAT, 'UTF-8'), null, 'centerTab'); +$section->addText("Multiple Tabs:\tOne\tTwo\tThree", null, $multipleTabsStyleName); +$section->addText("Left Aligned\tRight Aligned", null, $rightTabStyleName); +$section->addText("\tCenter Aligned", null, $leftTabStyleName); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_03_Sections.php b/samples/Sample_03_Sections.php index 3a7ea19ec6..a7b5b13d6d 100644 --- a/samples/Sample_03_Sections.php +++ b/samples/Sample_03_Sections.php @@ -7,17 +7,11 @@ // New portrait section $section = $phpWord->addSection(array('borderColor' => '00FF00', 'borderSize' => 12)); -$section->addText(htmlspecialchars('I am placed on a default section.', ENT_COMPAT, 'UTF-8')); +$section->addText('I am placed on a default section.'); // New landscape section $section = $phpWord->addSection(array('orientation' => 'landscape')); -$section->addText( - htmlspecialchars( - 'I am placed on a landscape section. Every page starting from this section will be landscape style.', - ENT_COMPAT, - 'UTF-8' - ) -); +$section->addText('I am placed on a landscape section. Every page starting from this section will be landscape style.'); $section->addPageBreak(); $section->addPageBreak(); @@ -25,7 +19,7 @@ $section = $phpWord->addSection( array('paperSize' => 'Folio', 'marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600) ); -$section->addText(htmlspecialchars('This section uses other margins with folio papersize.', ENT_COMPAT, 'UTF-8')); +$section->addText('This section uses other margins with folio papersize.'); // New portrait section with Header & Footer $section = $phpWord->addSection( @@ -38,9 +32,9 @@ 'footerHeight' => 50, ) ); -$section->addText(htmlspecialchars('This section and we play with header/footer height.', ENT_COMPAT, 'UTF-8')); -$section->addHeader()->addText(htmlspecialchars('Header', ENT_COMPAT, 'UTF-8')); -$section->addFooter()->addText(htmlspecialchars('Footer', ENT_COMPAT, 'UTF-8')); +$section->addText('This section and we play with header/footer height.'); +$section->addHeader()->addText('Header'); +$section->addFooter()->addText('Footer'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_04_Textrun.php b/samples/Sample_04_Textrun.php index 9590f6df37..48978dd36b 100644 --- a/samples/Sample_04_Textrun.php +++ b/samples/Sample_04_Textrun.php @@ -5,39 +5,39 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); -// Ads styles -$phpWord->addParagraphStyle('pStyle', array('spacing' => 100)); -$phpWord->addFontStyle('BoldText', array('bold' => true)); -$phpWord->addFontStyle('ColoredText', array('color' => 'FF8080', 'bgColor' => 'FFFFCC')); -$phpWord->addLinkStyle( - 'NLink', - array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE) -); +// Define styles +$paragraphStyleName = 'pStyle'; +$phpWord->addParagraphStyle($paragraphStyleName, array('spacing' => 100)); + +$boldFontStyleName = 'BoldText'; +$phpWord->addFontStyle($boldFontStyleName, array('bold' => true)); + +$coloredFontStyleName = 'ColoredText'; +$phpWord->addFontStyle($coloredFontStyleName, array('color' => 'FF8080', 'bgColor' => 'FFFFCC')); + +$linkFontStyleName = 'NLink'; +$phpWord->addLinkStyle($linkFontStyleName, array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)); // New portrait section $section = $phpWord->addSection(); // Add text run -$textrun = $section->addTextRun('pStyle'); - -$textrun->addText(htmlspecialchars('Each textrun can contain native text, link elements or an image.', ENT_COMPAT, 'UTF-8')); -$textrun->addText(htmlspecialchars(' No break is placed after adding an element.', ENT_COMPAT, 'UTF-8'), 'BoldText'); -$textrun->addText(htmlspecialchars(' Both ', ENT_COMPAT, 'UTF-8')); -$textrun->addText(htmlspecialchars('superscript', ENT_COMPAT, 'UTF-8'), array('superScript' => true)); -$textrun->addText(htmlspecialchars(' and ', ENT_COMPAT, 'UTF-8')); -$textrun->addText(htmlspecialchars('subscript', ENT_COMPAT, 'UTF-8'), array('subScript' => true)); -$textrun->addText(htmlspecialchars(' are also available.', ENT_COMPAT, 'UTF-8')); -$textrun->addText( - htmlspecialchars(' All elements are placed inside a paragraph with the optionally given p-Style.', ENT_COMPAT, 'UTF-8'), - 'ColoredText' -); -$textrun->addText(htmlspecialchars(' Sample Link: ', ENT_COMPAT, 'UTF-8')); -$textrun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), 'NLink'); -$textrun->addText(htmlspecialchars(' Sample Image: ', ENT_COMPAT, 'UTF-8')); +$textrun = $section->addTextRun($paragraphStyleName); +$textrun->addText('Each textrun can contain native text, link elements or an image.'); +$textrun->addText(' No break is placed after adding an element.', $boldFontStyleName); +$textrun->addText(' Both '); +$textrun->addText('superscript', array('superScript' => true)); +$textrun->addText(' and '); +$textrun->addText('subscript', array('subScript' => true)); +$textrun->addText(' are also available.'); +$textrun->addText(' All elements are placed inside a paragraph with the optionally given paragraph style.', $coloredFontStyleName); +$textrun->addText(' Sample Link: '); +$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub', $linkFontStyleName); +$textrun->addText(' Sample Image: '); $textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18)); -$textrun->addText(htmlspecialchars(' Sample Object: ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(' Sample Object: '); $textrun->addObject('resources/_sheet.xls'); -$textrun->addText(htmlspecialchars(' Here is some more text. ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(' Here is some more text. '); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_05_Multicolumn.php b/samples/Sample_05_Multicolumn.php index 5c0367294c..f7cefa58d3 100644 --- a/samples/Sample_05_Multicolumn.php +++ b/samples/Sample_05_Multicolumn.php @@ -11,7 +11,7 @@ // Normal $section = $phpWord->addSection(); -$section->addText(htmlspecialchars("Normal paragraph. {$filler}", ENT_COMPAT, 'UTF-8')); +$section->addText("Normal paragraph. {$filler}"); // Two columns $section = $phpWord->addSection( @@ -21,11 +21,11 @@ 'breakType' => 'continuous', ) ); -$section->addText(htmlspecialchars("Two columns, one inch (1440 twips) spacing. {$filler}", ENT_COMPAT, 'UTF-8')); +$section->addText("Two columns, one inch (1440 twips) spacing. {$filler}"); // Normal $section = $phpWord->addSection(array('breakType' => 'continuous')); -$section->addText(htmlspecialchars("Normal paragraph again. {$filler}", ENT_COMPAT, 'UTF-8')); +$section->addText("Normal paragraph again. {$filler}"); // Three columns $section = $phpWord->addSection( @@ -35,11 +35,11 @@ 'breakType' => 'continuous', ) ); -$section->addText(htmlspecialchars("Three columns, half inch (720 twips) spacing. {$filler}", ENT_COMPAT, 'UTF-8')); +$section->addText("Three columns, half inch (720 twips) spacing. {$filler}"); // Normal $section = $phpWord->addSection(array('breakType' => 'continuous')); -$section->addText(htmlspecialchars('Normal paragraph again.', ENT_COMPAT, 'UTF-8')); +$section->addText("Normal paragraph again. {$filler}"); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_06_Footnote.php b/samples/Sample_06_Footnote.php index 71c1ff1de9..30afcf815b 100644 --- a/samples/Sample_06_Footnote.php +++ b/samples/Sample_06_Footnote.php @@ -6,46 +6,46 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord(); \PhpOffice\PhpWord\Settings::setCompatibility(false); +// Define styles +$paragraphStyleName = 'pStyle'; +$phpWord->addParagraphStyle($paragraphStyleName, array('spacing' => 100)); + +$boldFontStyleName = 'BoldText'; +$phpWord->addFontStyle($boldFontStyleName, array('bold' => true)); + +$coloredFontStyleName = 'ColoredText'; +$phpWord->addFontStyle($coloredFontStyleName, array('color' => 'FF8080', 'bgColor' => 'FFFFCC')); + +$linkFontStyleName = 'NLink'; +$phpWord->addLinkStyle($linkFontStyleName, array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)); + // New portrait section $section = $phpWord->addSection(); -// Add style definitions -$phpWord->addParagraphStyle('pStyle', array('spacing' => 100)); -$phpWord->addFontStyle('BoldText', array('bold' => true)); -$phpWord->addFontStyle('ColoredText', array('color' => 'FF8080')); -$phpWord->addLinkStyle( - 'NLink', - array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE) -); - // Add text elements -$textrun = $section->addTextRun('pStyle'); -$textrun->addText(htmlspecialchars('This is some lead text in a paragraph with a following footnote. ', ENT_COMPAT, 'UTF-8'), 'pStyle'); +$textrun = $section->addTextRun($paragraphStyleName); +$textrun->addText('This is some lead text in a paragraph with a following footnote. ', $paragraphStyleName); $footnote = $textrun->addFootnote(); -$footnote->addText(htmlspecialchars('Just like a textrun, a footnote can contain native texts. ', ENT_COMPAT, 'UTF-8')); -$footnote->addText(htmlspecialchars('No break is placed after adding an element. ', ENT_COMPAT, 'UTF-8'), 'BoldText'); -$footnote->addText(htmlspecialchars('All elements are placed inside a paragraph. ', ENT_COMPAT, 'UTF-8'), 'ColoredText'); +$footnote->addText('Just like a textrun, a footnote can contain native texts. '); +$footnote->addText('No break is placed after adding an element. ', $boldFontStyleName); +$footnote->addText('All elements are placed inside a paragraph. ', $coloredFontStyleName); $footnote->addTextBreak(); -$footnote->addText(htmlspecialchars('But you can insert a manual text break like above, ', ENT_COMPAT, 'UTF-8')); -$footnote->addText(htmlspecialchars('links like ', ENT_COMPAT, 'UTF-8')); -$footnote->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), 'NLink'); -$footnote->addText(htmlspecialchars(', image like ', ENT_COMPAT, 'UTF-8')); +$footnote->addText('But you can insert a manual text break like above, '); +$footnote->addText('links like '); +$footnote->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub', $linkFontStyleName); +$footnote->addText(', image like '); $footnote->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18)); -$footnote->addText(htmlspecialchars(', or object like ', ENT_COMPAT, 'UTF-8')); +$footnote->addText(', or object like '); $footnote->addObject('resources/_sheet.xls'); -$footnote->addText(htmlspecialchars('But you can only put footnote in section, not in header or footer.', ENT_COMPAT, 'UTF-8')); +$footnote->addText('But you can only put footnote in section, not in header or footer.'); $section->addText( - htmlspecialchars( - 'You can also create the footnote directly from the section making it wrap in a paragraph ' - . 'like the footnote below this paragraph. But is is best used from within a textrun.', - ENT_COMPAT, - 'UTF-8' - ) + 'You can also create the footnote directly from the section making it wrap in a paragraph ' + . 'like the footnote below this paragraph. But is is best used from within a textrun.' ); $footnote = $section->addFootnote(); -$footnote->addText(htmlspecialchars('The reference for this is wrapped in its own line', ENT_COMPAT, 'UTF-8')); +$footnote->addText('The reference for this is wrapped in its own line'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_07_TemplateCloneRow.php b/samples/Sample_07_TemplateCloneRow.php index c227a67488..22a68537c6 100644 --- a/samples/Sample_07_TemplateCloneRow.php +++ b/samples/Sample_07_TemplateCloneRow.php @@ -6,52 +6,52 @@ $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/Sample_07_TemplateCloneRow.docx'); // Variables on different parts of document -$templateProcessor->setValue('weekday', htmlspecialchars(date('l'), ENT_COMPAT, 'UTF-8')); // On section/content -$templateProcessor->setValue('time', htmlspecialchars(date('H:i'), ENT_COMPAT, 'UTF-8')); // On footer -$templateProcessor->setValue('serverName', htmlspecialchars(realpath(__DIR__), ENT_COMPAT, 'UTF-8')); // On header +$templateProcessor->setValue('weekday', date('l')); // On section/content +$templateProcessor->setValue('time', date('H:i')); // On footer +$templateProcessor->setValue('serverName', realpath(__DIR__)); // On header // Simple table $templateProcessor->cloneRow('rowValue', 10); -$templateProcessor->setValue('rowValue#1', htmlspecialchars('Sun', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('rowValue#2', htmlspecialchars('Mercury', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('rowValue#3', htmlspecialchars('Venus', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('rowValue#4', htmlspecialchars('Earth', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('rowValue#5', htmlspecialchars('Mars', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('rowValue#6', htmlspecialchars('Jupiter', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('rowValue#7', htmlspecialchars('Saturn', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('rowValue#8', htmlspecialchars('Uranus', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('rowValue#9', htmlspecialchars('Neptun', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('rowValue#10', htmlspecialchars('Pluto', ENT_COMPAT, 'UTF-8')); - -$templateProcessor->setValue('rowNumber#1', htmlspecialchars('1', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('rowNumber#2', htmlspecialchars('2', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('rowNumber#3', htmlspecialchars('3', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('rowNumber#4', htmlspecialchars('4', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('rowNumber#5', htmlspecialchars('5', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('rowNumber#6', htmlspecialchars('6', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('rowNumber#7', htmlspecialchars('7', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('rowNumber#8', htmlspecialchars('8', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('rowNumber#9', htmlspecialchars('9', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('rowNumber#10', htmlspecialchars('10', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('rowValue#1', 'Sun'); +$templateProcessor->setValue('rowValue#2', 'Mercury'); +$templateProcessor->setValue('rowValue#3', 'Venus'); +$templateProcessor->setValue('rowValue#4', 'Earth'); +$templateProcessor->setValue('rowValue#5', 'Mars'); +$templateProcessor->setValue('rowValue#6', 'Jupiter'); +$templateProcessor->setValue('rowValue#7', 'Saturn'); +$templateProcessor->setValue('rowValue#8', 'Uranus'); +$templateProcessor->setValue('rowValue#9', 'Neptun'); +$templateProcessor->setValue('rowValue#10', 'Pluto'); + +$templateProcessor->setValue('rowNumber#1', '1'); +$templateProcessor->setValue('rowNumber#2', '2'); +$templateProcessor->setValue('rowNumber#3', '3'); +$templateProcessor->setValue('rowNumber#4', '4'); +$templateProcessor->setValue('rowNumber#5', '5'); +$templateProcessor->setValue('rowNumber#6', '6'); +$templateProcessor->setValue('rowNumber#7', '7'); +$templateProcessor->setValue('rowNumber#8', '8'); +$templateProcessor->setValue('rowNumber#9', '9'); +$templateProcessor->setValue('rowNumber#10', '10'); // Table with a spanned cell $templateProcessor->cloneRow('userId', 3); -$templateProcessor->setValue('userId#1', htmlspecialchars('1', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('userFirstName#1', htmlspecialchars('James', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('userName#1', htmlspecialchars('Taylor', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('userPhone#1', htmlspecialchars('+1 428 889 773', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('userId#1', '1'); +$templateProcessor->setValue('userFirstName#1', 'James'); +$templateProcessor->setValue('userName#1', 'Taylor'); +$templateProcessor->setValue('userPhone#1', '+1 428 889 773'); -$templateProcessor->setValue('userId#2', htmlspecialchars('2', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('userFirstName#2', htmlspecialchars('Robert', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('userName#2', htmlspecialchars('Bell', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('userPhone#2', htmlspecialchars('+1 428 889 774', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('userId#2', '2'); +$templateProcessor->setValue('userFirstName#2', 'Robert'); +$templateProcessor->setValue('userName#2', 'Bell'); +$templateProcessor->setValue('userPhone#2', '+1 428 889 774'); -$templateProcessor->setValue('userId#3', htmlspecialchars('3', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('userFirstName#3', htmlspecialchars('Michael', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('userName#3', htmlspecialchars('Ray', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('userPhone#3', htmlspecialchars('+1 428 889 775', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('userId#3', '3'); +$templateProcessor->setValue('userFirstName#3', 'Michael'); +$templateProcessor->setValue('userName#3', 'Ray'); +$templateProcessor->setValue('userPhone#3', '+1 428 889 775'); echo date('H:i:s'), ' Saving the result document...', EOL; $templateProcessor->saveAs('results/Sample_07_TemplateCloneRow.docx'); diff --git a/samples/Sample_08_ParagraphPagination.php b/samples/Sample_08_ParagraphPagination.php index 1a802f32df..f91b1c56b4 100644 --- a/samples/Sample_08_ParagraphPagination.php +++ b/samples/Sample_08_ParagraphPagination.php @@ -12,72 +12,52 @@ ) ); -// Sample +// New section $section = $phpWord->addSection(); $section->addText( - htmlspecialchars( - 'Below are the samples on how to control your paragraph ' - . 'pagination. See "Line and Page Break" tab on paragraph properties ' - . 'window to see the attribute set by these controls.', - ENT_COMPAT, - 'UTF-8' - ), + 'Below are the samples on how to control your paragraph ' + . 'pagination. See "Line and Page Break" tab on paragraph properties ' + . 'window to see the attribute set by these controls.', array('bold' => true), array('space' => array('before' => 360, 'after' => 480)) ); $section->addText( - htmlspecialchars( - 'Paragraph with widowControl = false (default: true). ' - . 'A "widow" is the last line of a paragraph printed by itself at the top ' - . 'of a page. An "orphan" is the first line of a paragraph printed by ' - . 'itself at the bottom of a page. Set this option to "false" if you want ' - . 'to disable this automatic control.', - ENT_COMPAT, - 'UTF-8' - ), + 'Paragraph with widowControl = false (default: true). ' + . 'A "widow" is the last line of a paragraph printed by itself at the top ' + . 'of a page. An "orphan" is the first line of a paragraph printed by ' + . 'itself at the bottom of a page. Set this option to "false" if you want ' + . 'to disable this automatic control.', null, array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120)) ); $section->addText( - htmlspecialchars( - 'Paragraph with keepNext = true (default: false). ' - . '"Keep with next" is used to prevent Word from inserting automatic page ' - . 'breaks between paragraphs. Set this option to "true" if you do not want ' - . 'your paragraph to be separated with the next paragraph.', - ENT_COMPAT, - 'UTF-8' - ), + 'Paragraph with keepNext = true (default: false). ' + . '"Keep with next" is used to prevent Word from inserting automatic page ' + . 'breaks between paragraphs. Set this option to "true" if you do not want ' + . 'your paragraph to be separated with the next paragraph.', null, array('keepNext' => true, 'indentation' => array('firstLine' => 240)) ); $section->addText( - htmlspecialchars( - 'Paragraph with keepLines = true (default: false). ' - . '"Keep lines together" will prevent Word from inserting an automatic page ' - . 'break within a paragraph. Set this option to "true" if you do not want ' - . 'all lines of your paragraph to be in the same page.', - ENT_COMPAT, - 'UTF-8' - ), + 'Paragraph with keepLines = true (default: false). ' + . '"Keep lines together" will prevent Word from inserting an automatic page ' + . 'break within a paragraph. Set this option to "true" if you do not want ' + . 'all lines of your paragraph to be in the same page.', null, array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240)) ); -$section->addText(htmlspecialchars('Keep scrolling. More below.', ENT_COMPAT, 'UTF-8')); +$section->addText('Keep scrolling. More below.'); $section->addText( - htmlspecialchars( - 'Paragraph with pageBreakBefore = true (default: false). ' - . 'Different with all other control above, "page break before" separates ' - . 'your paragraph into the next page. This option is most useful for ' - . 'heading styles.', - ENT_COMPAT, - 'UTF-8' - ), + 'Paragraph with pageBreakBefore = true (default: false). ' + . 'Different with all other control above, "page break before" separates ' + . 'your paragraph into the next page. This option is most useful for ' + . 'heading styles.', null, array('pageBreakBefore' => true) ); diff --git a/samples/Sample_09_Tables.php b/samples/Sample_09_Tables.php index d2e903be5a..53d32e0888 100644 --- a/samples/Sample_09_Tables.php +++ b/samples/Sample_09_Tables.php @@ -11,42 +11,43 @@ $rows = 10; $cols = 5; -$section->addText(htmlspecialchars('Basic table', ENT_COMPAT, 'UTF-8'), $header); +$section->addText('Basic table', $header); $table = $section->addTable(); for ($r = 1; $r <= 8; $r++) { $table->addRow(); for ($c = 1; $c <= 5; $c++) { - $table->addCell(1750)->addText(htmlspecialchars("Row {$r}, Cell {$c}", ENT_COMPAT, 'UTF-8')); + $table->addCell(1750)->addText("Row {$r}, Cell {$c}"); } } // 2. Advanced table $section->addTextBreak(1); -$section->addText(htmlspecialchars('Fancy table', ENT_COMPAT, 'UTF-8'), $header); - -$styleTable = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER); -$styleFirstRow = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF'); -$styleCell = array('valign' => 'center'); -$styleCellBTLR = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR); -$fontStyle = array('bold' => true); -$phpWord->addTableStyle('Fancy Table', $styleTable, $styleFirstRow); -$table = $section->addTable('Fancy Table'); +$section->addText('Fancy table', $header); + +$fancyTableStyleName = 'Fancy Table'; +$fancyTableStyle = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER); +$fancyTableFirstRowStyle = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF'); +$fancyTableCellStyle = array('valign' => 'center'); +$fancyTableCellBtlrStyle = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR); +$fancyTableFontStyle = array('bold' => true); +$phpWord->addTableStyle($fancyTableStyleName, $fancyTableStyle, $fancyTableFirstRowStyle); +$table = $section->addTable($fancyTableStyleName); $table->addRow(900); -$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 1', ENT_COMPAT, 'UTF-8'), $fontStyle); -$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 2', ENT_COMPAT, 'UTF-8'), $fontStyle); -$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 3', ENT_COMPAT, 'UTF-8'), $fontStyle); -$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 4', ENT_COMPAT, 'UTF-8'), $fontStyle); -$table->addCell(500, $styleCellBTLR)->addText(htmlspecialchars('Row 5', ENT_COMPAT, 'UTF-8'), $fontStyle); +$table->addCell(2000, $fancyTableCellStyle)->addText('Row 1', $fancyTableFontStyle); +$table->addCell(2000, $fancyTableCellStyle)->addText('Row 2', $fancyTableFontStyle); +$table->addCell(2000, $fancyTableCellStyle)->addText('Row 3', $fancyTableFontStyle); +$table->addCell(2000, $fancyTableCellStyle)->addText('Row 4', $fancyTableFontStyle); +$table->addCell(500, $fancyTableCellBtlrStyle)->addText('Row 5', $fancyTableFontStyle); for ($i = 1; $i <= 8; $i++) { $table->addRow(); - $table->addCell(2000)->addText(htmlspecialchars("Cell {$i}", ENT_COMPAT, 'UTF-8')); - $table->addCell(2000)->addText(htmlspecialchars("Cell {$i}", ENT_COMPAT, 'UTF-8')); - $table->addCell(2000)->addText(htmlspecialchars("Cell {$i}", ENT_COMPAT, 'UTF-8')); - $table->addCell(2000)->addText(htmlspecialchars("Cell {$i}", ENT_COMPAT, 'UTF-8')); + $table->addCell(2000)->addText("Cell {$i}"); + $table->addCell(2000)->addText("Cell {$i}"); + $table->addCell(2000)->addText("Cell {$i}"); + $table->addCell(2000)->addText("Cell {$i}"); $text = (0== $i % 2) ? 'X' : ''; - $table->addCell(500)->addText(htmlspecialchars($text, ENT_COMPAT, 'UTF-8')); + $table->addCell(500)->addText($text); } /** @@ -59,36 +60,37 @@ */ $section->addPageBreak(); -$section->addText(htmlspecialchars('Table with colspan and rowspan', ENT_COMPAT, 'UTF-8'), $header); +$section->addText('Table with colspan and rowspan', $header); -$styleTable = array('borderSize' => 6, 'borderColor' => '999999'); +$fancyTableStyle = array('borderSize' => 6, 'borderColor' => '999999'); $cellRowSpan = array('vMerge' => 'restart', 'valign' => 'center', 'bgColor' => 'FFFF00'); $cellRowContinue = array('vMerge' => 'continue'); $cellColSpan = array('gridSpan' => 2, 'valign' => 'center'); $cellHCentered = array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER); $cellVCentered = array('valign' => 'center'); -$phpWord->addTableStyle('Colspan Rowspan', $styleTable); -$table = $section->addTable('Colspan Rowspan'); +$spanTableStyleName = 'Colspan Rowspan'; +$phpWord->addTableStyle($spanTableStyleName, $fancyTableStyle); +$table = $section->addTable($spanTableStyleName); $table->addRow(); $cell1 = $table->addCell(2000, $cellRowSpan); $textrun1 = $cell1->addTextRun($cellHCentered); -$textrun1->addText(htmlspecialchars('A', ENT_COMPAT, 'UTF-8')); -$textrun1->addFootnote()->addText(htmlspecialchars('Row span', ENT_COMPAT, 'UTF-8')); +$textrun1->addText('A'); +$textrun1->addFootnote()->addText('Row span'); $cell2 = $table->addCell(4000, $cellColSpan); $textrun2 = $cell2->addTextRun($cellHCentered); -$textrun2->addText(htmlspecialchars('B', ENT_COMPAT, 'UTF-8')); -$textrun2->addFootnote()->addText(htmlspecialchars('Colspan span', ENT_COMPAT, 'UTF-8')); +$textrun2->addText('B'); +$textrun2->addFootnote()->addText('Column span'); -$table->addCell(2000, $cellRowSpan)->addText(htmlspecialchars('E', ENT_COMPAT, 'UTF-8'), null, $cellHCentered); +$table->addCell(2000, $cellRowSpan)->addText('E', null, $cellHCentered); $table->addRow(); $table->addCell(null, $cellRowContinue); -$table->addCell(2000, $cellVCentered)->addText(htmlspecialchars('C', ENT_COMPAT, 'UTF-8'), null, $cellHCentered); -$table->addCell(2000, $cellVCentered)->addText(htmlspecialchars('D', ENT_COMPAT, 'UTF-8'), null, $cellHCentered); +$table->addCell(2000, $cellVCentered)->addText('C', null, $cellHCentered); +$table->addCell(2000, $cellVCentered)->addText('D', null, $cellHCentered); $table->addCell(null, $cellRowContinue); /** @@ -103,7 +105,7 @@ * @see https://github.com/PHPOffice/PHPWord/issues/806 */ $section->addPageBreak(); -$section->addText(htmlspecialchars('Table with colspan and rowspan', ENT_COMPAT, 'UTF-8'), $header); +$section->addText('Table with colspan and rowspan', $header); $styleTable = ['borderSize' => 6, 'borderColor' => '999999']; $phpWord->addTableStyle('Colspan Rowspan', $styleTable); @@ -128,13 +130,13 @@ // 5. Nested table $section->addTextBreak(2); -$section->addText(htmlspecialchars('Nested table in a centered and 50% width table.', ENT_COMPAT, 'UTF-8'), $header); +$section->addText('Nested table in a centered and 50% width table.', $header); $table = $section->addTable(array('width' => 50 * 50, 'unit' => 'pct', 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER)); $cell = $table->addRow()->addCell(); -$cell->addText(htmlspecialchars('This cell contains nested table.', ENT_COMPAT, 'UTF-8')); +$cell->addText('This cell contains nested table.'); $innerCell = $cell->addTable(array('alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER))->addRow()->addCell(); -$innerCell->addText(htmlspecialchars('Inside nested table', ENT_COMPAT, 'UTF-8')); +$innerCell->addText('Inside nested table'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_10_EastAsianFontStyle.php b/samples/Sample_10_EastAsianFontStyle.php index e4cda63695..2541af86dc 100644 --- a/samples/Sample_10_EastAsianFontStyle.php +++ b/samples/Sample_10_EastAsianFontStyle.php @@ -7,7 +7,7 @@ $section = $phpWord->addSection(); $header = array('size' => 16, 'bold' => true); //1.Use EastAisa FontStyle -$section->addText(htmlspecialchars('中文楷体样式测试', ENT_COMPAT, 'UTF-8'), array('name' => '楷体', 'size' => 16, 'color' => '1B2232')); +$section->addText('中文楷体样式测试', array('name' => '楷体', 'size' => 16, 'color' => '1B2232')); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_12_HeaderFooter.php b/samples/Sample_12_HeaderFooter.php index 4ea3e2872c..b99d81f8dd 100644 --- a/samples/Sample_12_HeaderFooter.php +++ b/samples/Sample_12_HeaderFooter.php @@ -15,47 +15,47 @@ $table->addRow(); $cell = $table->addCell(4500); $textrun = $cell->addTextRun(); -$textrun->addText(htmlspecialchars('This is the header with ', ENT_COMPAT, 'UTF-8')); -$textrun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8')); +$textrun->addText('This is the header with '); +$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); $table->addCell(4500)->addImage('resources/PhpWord.png', array('width' => 80, 'height' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END)); // Add header for all other pages $subsequent = $section->addHeader(); -$subsequent->addText(htmlspecialchars('Subsequent pages in Section 1 will Have this!', ENT_COMPAT, 'UTF-8')); +$subsequent->addText('Subsequent pages in Section 1 will Have this!'); $subsequent->addImage('resources/_mars.jpg', array('width' => 80, 'height' => 80)); // Add footer $footer = $section->addFooter(); -$footer->addPreserveText(htmlspecialchars('Page {PAGE} of {NUMPAGES}.', ENT_COMPAT, 'UTF-8'), null, array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER)); -$footer->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8')); +$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', null, array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER)); +$footer->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); // Write some text $section->addTextBreak(); -$section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8')); +$section->addText('Some text...'); // Create a second page $section->addPageBreak(); // Write some text $section->addTextBreak(); -$section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8')); +$section->addText('Some text...'); // Create a third page $section->addPageBreak(); // Write some text $section->addTextBreak(); -$section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8')); +$section->addText('Some text...'); // New portrait section $section2 = $phpWord->addSection(); $sec2Header = $section2->addHeader(); -$sec2Header->addText(htmlspecialchars('All pages in Section 2 will Have this!', ENT_COMPAT, 'UTF-8')); +$sec2Header->addText('All pages in Section 2 will Have this!'); // Write some text $section2->addTextBreak(); -$section2->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8')); +$section2->addText('Some text...'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_13_Images.php b/samples/Sample_13_Images.php index 0088acbd92..a3c2af23a9 100644 --- a/samples/Sample_13_Images.php +++ b/samples/Sample_13_Images.php @@ -7,17 +7,17 @@ // Begin code $section = $phpWord->addSection(); -$section->addText(htmlspecialchars('Local image without any styles:', ENT_COMPAT, 'UTF-8')); +$section->addText('Local image without any styles:'); $section->addImage('resources/_mars.jpg'); $section->addTextBreak(2); -$section->addText(htmlspecialchars('Local image with styles:', ENT_COMPAT, 'UTF-8')); +$section->addText('Local image with styles:'); $section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER)); $section->addTextBreak(2); // Remote image $source = 'http://php.net/images/logos/php-med-trans-light.gif'; -$section->addText(htmlspecialchars("Remote image from: {$source}", ENT_COMPAT, 'UTF-8')); +$section->addText("Remote image from: {$source}"); $section->addImage($source); //Wrapping style @@ -25,7 +25,7 @@ $wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight'); foreach ($wrappingStyles as $wrappingStyle) { $section->addTextBreak(5); - $section->addText(htmlspecialchars("Wrapping style {$wrappingStyle}", ENT_COMPAT, 'UTF-8')); + $section->addText("Wrapping style {$wrappingStyle}"); $section->addImage( 'resources/_earth.jpg', array( @@ -37,12 +37,12 @@ 'wrappingStyle' => $wrappingStyle, ) ); - $section->addText(htmlspecialchars($text, ENT_COMPAT, 'UTF-8')); + $section->addText($text); } //Absolute positioning $section->addTextBreak(3); -$section->addText(htmlspecialchars('Absolute positioning: see top right corner of page', ENT_COMPAT, 'UTF-8')); +$section->addText('Absolute positioning: see top right corner of page'); $section->addImage( 'resources/_mars.jpg', array( @@ -59,8 +59,8 @@ //Relative positioning $section->addTextBreak(3); -$section->addText(htmlspecialchars('Relative positioning: Horizontal position center relative to column,', ENT_COMPAT, 'UTF-8')); -$section->addText(htmlspecialchars('Vertical position top relative to line', ENT_COMPAT, 'UTF-8')); +$section->addText('Relative positioning: Horizontal position center relative to column,'); +$section->addText('Vertical position top relative to line'); $section->addImage( 'resources/_mars.jpg', array( diff --git a/samples/Sample_14_ListItem.php b/samples/Sample_14_ListItem.php index df5ffee3fd..689ac3d3eb 100644 --- a/samples/Sample_14_ListItem.php +++ b/samples/Sample_14_ListItem.php @@ -5,15 +5,16 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); -// Begin code -$section = $phpWord->addSection(); +// Define styles +$fontStyleName = 'myOwnStyle'; +$phpWord->addFontStyle($fontStyleName, array('color' => 'FF0000')); -// Style definition +$paragraphStyleName = 'P-Style'; +$phpWord->addParagraphStyle($paragraphStyleName, array('spaceAfter' => 95)); -$phpWord->addFontStyle('myOwnStyle', array('color' => 'FF0000')); -$phpWord->addParagraphStyle('P-Style', array('spaceAfter' => 95)); +$multilevelNumberingStyleName = 'multilevel'; $phpWord->addNumberingStyle( - 'multilevel', + $multilevelNumberingStyleName, array( 'type' => 'multilevel', 'levels' => array( @@ -22,56 +23,59 @@ ), ) ); -$predefinedMultilevel = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER_NESTED); -// Lists +$predefinedMultilevelStyle = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER_NESTED); + +// New section +$section = $phpWord->addSection(); -$section->addText(htmlspecialchars('Multilevel list.', ENT_COMPAT, 'UTF-8')); -$section->addListItem(htmlspecialchars('List Item I', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel'); -$section->addListItem(htmlspecialchars('List Item I.a', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel'); -$section->addListItem(htmlspecialchars('List Item I.b', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel'); -$section->addListItem(htmlspecialchars('List Item II', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel'); -$section->addListItem(htmlspecialchars('List Item II.a', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel'); -$section->addListItem(htmlspecialchars('List Item III', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel'); +// Lists +$section->addText('Multilevel list.'); +$section->addListItem('List Item I', 0, null, $multilevelNumberingStyleName); +$section->addListItem('List Item I.a', 1, null, $multilevelNumberingStyleName); +$section->addListItem('List Item I.b', 1, null, $multilevelNumberingStyleName); +$section->addListItem('List Item II', 0, null, $multilevelNumberingStyleName); +$section->addListItem('List Item II.a', 1, null, $multilevelNumberingStyleName); +$section->addListItem('List Item III', 0, null, $multilevelNumberingStyleName); $section->addTextBreak(2); -$section->addText(htmlspecialchars('Basic simple bulleted list.', ENT_COMPAT, 'UTF-8')); -$section->addListItem(htmlspecialchars('List Item 1', ENT_COMPAT, 'UTF-8')); -$section->addListItem(htmlspecialchars('List Item 2', ENT_COMPAT, 'UTF-8')); -$section->addListItem(htmlspecialchars('List Item 3', ENT_COMPAT, 'UTF-8')); +$section->addText('Basic simple bulleted list.'); +$section->addListItem('List Item 1'); +$section->addListItem('List Item 2'); +$section->addListItem('List Item 3'); $section->addTextBreak(2); -$section->addText(htmlspecialchars('Continue from multilevel list above.', ENT_COMPAT, 'UTF-8')); -$section->addListItem(htmlspecialchars('List Item IV', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel'); -$section->addListItem(htmlspecialchars('List Item IV.a', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel'); +$section->addText('Continue from multilevel list above.'); +$section->addListItem('List Item IV', 0, null, $multilevelNumberingStyleName); +$section->addListItem('List Item IV.a', 1, null, $multilevelNumberingStyleName); $section->addTextBreak(2); -$section->addText(htmlspecialchars('Multilevel predefined list.', ENT_COMPAT, 'UTF-8')); -$section->addListItem(htmlspecialchars('List Item 1', ENT_COMPAT, 'UTF-8'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); -$section->addListItem(htmlspecialchars('List Item 2', ENT_COMPAT, 'UTF-8'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); -$section->addListItem(htmlspecialchars('List Item 3', ENT_COMPAT, 'UTF-8'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); -$section->addListItem(htmlspecialchars('List Item 4', ENT_COMPAT, 'UTF-8'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); -$section->addListItem(htmlspecialchars('List Item 5', ENT_COMPAT, 'UTF-8'), 2, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); -$section->addListItem(htmlspecialchars('List Item 6', ENT_COMPAT, 'UTF-8'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); -$section->addListItem(htmlspecialchars('List Item 7', ENT_COMPAT, 'UTF-8'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); +$section->addText('Multilevel predefined list.'); +$section->addListItem('List Item 1', 0, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName); +$section->addListItem('List Item 2', 0, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName); +$section->addListItem('List Item 3', 1, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName); +$section->addListItem('List Item 4', 1, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName); +$section->addListItem('List Item 5', 2, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName); +$section->addListItem('List Item 6', 1, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName); +$section->addListItem('List Item 7', 0, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName); $section->addTextBreak(2); -$section->addText(htmlspecialchars('List with inline formatting.', ENT_COMPAT, 'UTF-8')); +$section->addText('List with inline formatting.'); $listItemRun = $section->addListItemRun(); -$listItemRun->addText(htmlspecialchars('List item 1', ENT_COMPAT, 'UTF-8')); -$listItemRun->addText(htmlspecialchars(' in bold', ENT_COMPAT, 'UTF-8'), array('bold' => true)); +$listItemRun->addText('List item 1'); +$listItemRun->addText(' in bold', array('bold' => true)); $listItemRun = $section->addListItemRun(); -$listItemRun->addText(htmlspecialchars('List item 2', ENT_COMPAT, 'UTF-8')); -$listItemRun->addText(htmlspecialchars(' in italic', ENT_COMPAT, 'UTF-8'), array('italic' => true)); +$listItemRun->addText('List item 2'); +$listItemRun->addText(' in italic', array('italic' => true)); $listItemRun = $section->addListItemRun(); -$listItemRun->addText(htmlspecialchars('List item 3', ENT_COMPAT, 'UTF-8')); -$listItemRun->addText(htmlspecialchars(' underlined', ENT_COMPAT, 'UTF-8'), array('underline' => 'dash')); +$listItemRun->addText('List item 3'); +$listItemRun->addText(' underlined', array('underline' => 'dash')); $section->addTextBreak(2); // Numbered heading - +$headingNumberingStyleName = 'headingNumbering'; $phpWord->addNumberingStyle( - 'headingNumbering', + $headingNumberingStyleName, array('type' => 'multilevel', 'levels' => array( array('pStyle' => 'Heading1', 'format' => 'decimal', 'text' => '%1'), @@ -80,13 +84,13 @@ ), ) ); -$phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => 'headingNumbering', 'numLevel' => 0)); -$phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => 'headingNumbering', 'numLevel' => 1)); -$phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => 'headingNumbering', 'numLevel' => 2)); +$phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => $headingNumberingStyleName, 'numLevel' => 0)); +$phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => $headingNumberingStyleName, 'numLevel' => 1)); +$phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => $headingNumberingStyleName, 'numLevel' => 2)); -$section->addTitle(htmlspecialchars('Heading 1', ENT_COMPAT, 'UTF-8'), 1); -$section->addTitle(htmlspecialchars('Heading 2', ENT_COMPAT, 'UTF-8'), 2); -$section->addTitle(htmlspecialchars('Heading 3', ENT_COMPAT, 'UTF-8'), 3); +$section->addTitle('Heading 1', 1); +$section->addTitle('Heading 2', 2); +$section->addTitle('Heading 3', 3); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_15_Link.php b/samples/Sample_15_Link.php index b55db21cae..86c7973bc1 100644 --- a/samples/Sample_15_Link.php +++ b/samples/Sample_15_Link.php @@ -5,20 +5,22 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); -// Begin code +// Define styles +$linkFontStyleName = 'myOwnLinStyle'; +$phpWord->addLinkStyle($linkFontStyleName, array('bold' => true, 'color' => '808000')); + +// New section $section = $phpWord->addSection(); // Add hyperlink elements $section->addLink( 'https://github.com/PHPOffice/PHPWord', - htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), + 'PHPWord on GitHub', array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE) ); $section->addTextBreak(2); - -$phpWord->addLinkStyle('myOwnLinkStyle', array('bold' => true, 'color' => '808000')); -$section->addLink('http://www.bing.com', null, 'myOwnLinkStyle'); -$section->addLink('http://www.yahoo.com', null, 'myOwnLinkStyle'); +$section->addLink('http://www.bing.com', null, $linkFontStyleName); +$section->addLink('http://www.yahoo.com', null, $linkFontStyleName); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_16_Object.php b/samples/Sample_16_Object.php index 950f7743df..8b05b9e8ac 100644 --- a/samples/Sample_16_Object.php +++ b/samples/Sample_16_Object.php @@ -7,7 +7,7 @@ // Begin code $section = $phpWord->addSection(); -$section->addText(htmlspecialchars('You can open this OLE object by double clicking on the icon:', ENT_COMPAT, 'UTF-8')); +$section->addText('You can open this OLE object by double clicking on the icon:'); $section->addTextBreak(2); $section->addObject('resources/_sheet.xls'); diff --git a/samples/Sample_17_TitleTOC.php b/samples/Sample_17_TitleTOC.php index 6fcf671500..306595eb39 100644 --- a/samples/Sample_17_TitleTOC.php +++ b/samples/Sample_17_TitleTOC.php @@ -5,66 +5,63 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); -// Begin code +// New section $section = $phpWord->addSection(); -// Define the TOC font style -$fontStyle = array('spaceAfter' => 60, 'size' => 12); -$fontStyle2 = array('size' => 10); - -// Add title styles +// Define styles +$fontStyle12 = array('spaceAfter' => 60, 'size' => 12); +$fontStyle10 = array('size' => 10); $phpWord->addTitleStyle(1, array('size' => 20, 'color' => '333333', 'bold' => true)); $phpWord->addTitleStyle(2, array('size' => 16, 'color' => '666666')); $phpWord->addTitleStyle(3, array('size' => 14, 'italic' => true)); $phpWord->addTitleStyle(4, array('size' => 12)); // Add text elements -$section->addText(htmlspecialchars('Table of contents 1', ENT_COMPAT, 'UTF-8')); +$section->addText('Table of contents 1'); $section->addTextBreak(2); // Add TOC #1 -$toc = $section->addTOC($fontStyle); +$toc = $section->addTOC($fontStyle12); $section->addTextBreak(2); // Filler -$section->addText(htmlspecialchars('Text between TOC', ENT_COMPAT, 'UTF-8')); +$section->addText('Text between TOC'); $section->addTextBreak(2); // Add TOC #1 -$section->addText(htmlspecialchars('Table of contents 2', ENT_COMPAT, 'UTF-8')); +$section->addText('Table of contents 2'); $section->addTextBreak(2); -$toc2 = $section->addTOC($fontStyle2); +$toc2 = $section->addTOC($fontStyle10); $toc2->setMinDepth(2); $toc2->setMaxDepth(3); - // Add Titles $section->addPageBreak(); -$section->addTitle(htmlspecialchars('Foo & Bar', ENT_COMPAT, 'UTF-8'), 1); -$section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8')); +$section->addTitle('Foo n Bar', 1); +$section->addText('Some text...'); $section->addTextBreak(2); -$section->addTitle(htmlspecialchars('I am a Subtitle of Title 1', ENT_COMPAT, 'UTF-8'), 2); +$section->addTitle('I am a Subtitle of Title 1', 2); $section->addTextBreak(2); -$section->addText(htmlspecialchars('Some more text...', ENT_COMPAT, 'UTF-8')); +$section->addText('Some more text...'); $section->addTextBreak(2); -$section->addTitle(htmlspecialchars('Another Title (Title 2)', ENT_COMPAT, 'UTF-8'), 1); -$section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8')); +$section->addTitle('Another Title (Title 2)', 1); +$section->addText('Some text...'); $section->addPageBreak(); -$section->addTitle(htmlspecialchars('I am Title 3', ENT_COMPAT, 'UTF-8'), 1); -$section->addText(htmlspecialchars('And more text...', ENT_COMPAT, 'UTF-8')); +$section->addTitle('I am Title 3', 1); +$section->addText('And more text...'); $section->addTextBreak(2); -$section->addTitle(htmlspecialchars('I am a Subtitle of Title 3', ENT_COMPAT, 'UTF-8'), 2); -$section->addText(htmlspecialchars('Again and again, more text...', ENT_COMPAT, 'UTF-8')); -$section->addTitle(htmlspecialchars('Subtitle 3.1.1', ENT_COMPAT, 'UTF-8'), 3); -$section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8')); -$section->addTitle(htmlspecialchars('Subtitle 3.1.1.1', ENT_COMPAT, 'UTF-8'), 4); -$section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8')); -$section->addTitle(htmlspecialchars('Subtitle 3.1.1.2', ENT_COMPAT, 'UTF-8'), 4); -$section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8')); -$section->addTitle(htmlspecialchars('Subtitle 3.1.2', ENT_COMPAT, 'UTF-8'), 3); -$section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8')); +$section->addTitle('I am a Subtitle of Title 3', 2); +$section->addText('Again and again, more text...'); +$section->addTitle('Subtitle 3.1.1', 3); +$section->addText('Text'); +$section->addTitle('Subtitle 3.1.1.1', 4); +$section->addText('Text'); +$section->addTitle('Subtitle 3.1.1.2', 4); +$section->addText('Text'); +$section->addTitle('Subtitle 3.1.2', 3); +$section->addText('Text'); echo date('H:i:s'), ' Note: Please refresh TOC manually.', EOL; diff --git a/samples/Sample_18_Watermark.php b/samples/Sample_18_Watermark.php index 5a26fd0465..dbab2b7f26 100644 --- a/samples/Sample_18_Watermark.php +++ b/samples/Sample_18_Watermark.php @@ -6,11 +6,10 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord(); // Begin code - $section = $phpWord->addSection(); $header = $section->addHeader(); $header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55)); -$section->addText(htmlspecialchars('The header reference to the current section includes a watermark image.', ENT_COMPAT, 'UTF-8')); +$section->addText('The header reference to the current section includes a watermark image.'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_19_TextBreak.php b/samples/Sample_19_TextBreak.php index b0405b6c72..17e2b1cbd7 100644 --- a/samples/Sample_19_TextBreak.php +++ b/samples/Sample_19_TextBreak.php @@ -5,25 +5,31 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); -// Begin code -$fontStyle = array('size' => 24); -$paragraphStyle = array('spacing' => 240, 'size' => 24); -$phpWord->addFontStyle('fontStyle', array('size' => 9)); -$phpWord->addParagraphStyle('paragraphStyle', array('spacing' => 480)); -$fontStyle = array('size' => 24); +// Define styles +$fontStyle24 = array('size' => 24); +$paragraphStyle24 = array('spacing' => 240, 'size' => 24); + +$fontStyleName = 'fontStyle'; +$phpWord->addFontStyle($fontStyleName, array('size' => 9)); + +$paragraphStyleName = 'paragraphStyle'; +$phpWord->addParagraphStyle($paragraphStyleName, array('spacing' => 480)); + +// New section $section = $phpWord->addSection(); -$section->addText(htmlspecialchars('Text break with no style:', ENT_COMPAT, 'UTF-8')); + +$section->addText('Text break with no style:'); $section->addTextBreak(); -$section->addText(htmlspecialchars('Text break with defined font style:', ENT_COMPAT, 'UTF-8')); -$section->addTextBreak(1, 'fontStyle'); -$section->addText(htmlspecialchars('Text break with defined paragraph style:', ENT_COMPAT, 'UTF-8')); -$section->addTextBreak(1, null, 'paragraphStyle'); -$section->addText(htmlspecialchars('Text break with inline font style:', ENT_COMPAT, 'UTF-8')); -$section->addTextBreak(1, $fontStyle); -$section->addText(htmlspecialchars('Text break with inline paragraph style:', ENT_COMPAT, 'UTF-8')); -$section->addTextBreak(1, null, $paragraphStyle); -$section->addText(htmlspecialchars('Done.', ENT_COMPAT, 'UTF-8')); +$section->addText('Text break with defined font style:'); +$section->addTextBreak(1, $fontStyleName); +$section->addText('Text break with defined paragraph style:'); +$section->addTextBreak(1, null, $paragraphStyleName); +$section->addText('Text break with inline font style:'); +$section->addTextBreak(1, $fontStyle24); +$section->addText('Text break with inline paragraph style:'); +$section->addTextBreak(1, null, $paragraphStyle24); +$section->addText('Done.'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_20_BGColor.php b/samples/Sample_20_BGColor.php index 143189ad86..628ae8902e 100644 --- a/samples/Sample_20_BGColor.php +++ b/samples/Sample_20_BGColor.php @@ -4,17 +4,16 @@ // New Word document echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); + +// New section $section = $phpWord->addSection(); $section->addText( - htmlspecialchars('This is some text highlighted using fgColor (limited to 15 colors) ', ENT_COMPAT, 'UTF-8'), + 'This is some text highlighted using fgColor (limited to 15 colors)', array('fgColor' => \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW) ); -$section->addText( - htmlspecialchars('This one uses bgColor and is using hex value (0xfbbb10)', ENT_COMPAT, 'UTF-8'), - array('bgColor' => 'fbbb10') -); -$section->addText(htmlspecialchars('Compatible with font colors', ENT_COMPAT, 'UTF-8'), array('color' => '0000ff', 'bgColor' => 'fbbb10')); +$section->addText('This one uses bgColor and is using hex value (0xfbbb10)', array('bgColor' => 'fbbb10')); +$section->addText('Compatible with font colors', array('color' => '0000ff', 'bgColor' => 'fbbb10')); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_21_TableRowRules.php b/samples/Sample_21_TableRowRules.php index a1414dc14c..ca33de3bcd 100644 --- a/samples/Sample_21_TableRowRules.php +++ b/samples/Sample_21_TableRowRules.php @@ -4,19 +4,15 @@ // New Word document echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); + +// New section $section = $phpWord->addSection(); -$section->addText(htmlspecialchars('By default, when you insert an image, it adds a textbreak after its content.', ENT_COMPAT, 'UTF-8')); +$section->addText('By default, when you insert an image, it adds a textbreak after its content.'); +$section->addText('If we want a simple border around an image, we wrap the image inside a table->row->cell'); $section->addText( - htmlspecialchars('If we want a simple border around an image, we wrap the image inside a table->row->cell', ENT_COMPAT, 'UTF-8') -); -$section->addText( - htmlspecialchars( - 'On the image with the red border, even if we set the row height to the height of the image, ' - . 'the textbreak is still there:', - ENT_COMPAT, - 'UTF-8' - ) + 'On the image with the red border, even if we set the row height to the height of the image, ' + . 'the textbreak is still there:' ); $table1 = $section->addTable(array('cellMargin' => 0, 'cellMarginRight' => 0, 'cellMarginBottom' => 0, 'cellMarginLeft' => 0)); @@ -25,13 +21,7 @@ $cell1->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER)); $section->addTextBreak(); -$section->addText( - htmlspecialchars( - "But if we set the rowStyle 'exactHeight' to true, the real row height is used, removing the textbreak:", - ENT_COMPAT, - 'UTF-8' - ) -); +$section->addText("But if we set the rowStyle 'exactHeight' to true, the real row height is used, removing the textbreak:"); $table2 = $section->addTable( array( @@ -46,10 +36,8 @@ $cell2->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER)); $section->addTextBreak(); -$section->addText( - htmlspecialchars('In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips.', ENT_COMPAT, 'UTF-8') -); -$section->addText(htmlspecialchars('So: $' . "table2->addRow(3750, array('exactHeight'=>true));", ENT_COMPAT, 'UTF-8')); +$section->addText('In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips.'); +$section->addText('So: $' . "table2->addRow(3750, array('exactHeight'=>true));"); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_22_CheckBox.php b/samples/Sample_22_CheckBox.php index 9c8c05a71a..5a2ac3e2cc 100644 --- a/samples/Sample_22_CheckBox.php +++ b/samples/Sample_22_CheckBox.php @@ -5,14 +5,16 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); +// New section $section = $phpWord->addSection(); -$section->addText(htmlspecialchars('Check box in section', ENT_COMPAT, 'UTF-8')); -$section->addCheckBox('chkBox1', htmlspecialchars('Checkbox 1', ENT_COMPAT, 'UTF-8')); -$section->addText(htmlspecialchars('Check box in table cell', ENT_COMPAT, 'UTF-8')); + +$section->addText('Check box in section'); +$section->addCheckBox('chkBox1', 'Checkbox 1'); +$section->addText('Check box in table cell'); $table = $section->addTable(); $table->addRow(); $cell = $table->addCell(); -$cell->addCheckBox('chkBox2', htmlspecialchars('Checkbox 2', ENT_COMPAT, 'UTF-8')); +$cell->addCheckBox('chkBox2', 'Checkbox 2'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_25_TextBox.php b/samples/Sample_25_TextBox.php index 36bd171840..7655e25f9d 100644 --- a/samples/Sample_25_TextBox.php +++ b/samples/Sample_25_TextBox.php @@ -5,6 +5,7 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); +// New section $section = $phpWord->addSection(); // In section @@ -17,28 +18,28 @@ 'borderColor' => '#FF0000', ) ); -$textbox->addText(htmlspecialchars('Text box content in section.', ENT_COMPAT, 'UTF-8')); -$textbox->addText(htmlspecialchars('Another line.', ENT_COMPAT, 'UTF-8')); +$textbox->addText('Text box content in section.'); +$textbox->addText('Another line.'); $cell = $textbox->addTable()->addRow()->addCell(); -$cell->addText(htmlspecialchars('Table inside textbox', ENT_COMPAT, 'UTF-8')); +$cell->addText('Table inside textbox'); // Inside table $section->addTextBreak(2); $cell = $section->addTable()->addRow()->addCell(300); $textbox = $cell->addTextBox(array('borderSize' => 1, 'borderColor' => '#0000FF', 'innerMargin' => 100)); -$textbox->addText(htmlspecialchars('Textbox inside table', ENT_COMPAT, 'UTF-8')); +$textbox->addText('Textbox inside table'); // Inside header with textrun $header = $section->addHeader(); $textbox = $header->addTextBox(array('width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00')); $textrun = $textbox->addTextRun(); -$textrun->addText(htmlspecialchars('TextBox in header. TextBox can contain a TextRun ', ENT_COMPAT, 'UTF-8')); -$textrun->addText(htmlspecialchars('with bold text', ENT_COMPAT, 'UTF-8'), array('bold' => true)); -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); -$textrun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8')); -$textrun->addText(htmlspecialchars(', and image ', ENT_COMPAT, 'UTF-8')); +$textrun->addText('TextBox in header. TextBox can contain a TextRun '); +$textrun->addText('with bold text', array('bold' => true)); +$textrun->addText(', '); +$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); +$textrun->addText(', and image '); $textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18)); -$textrun->addText(htmlspecialchars('.', ENT_COMPAT, 'UTF-8')); +$textrun->addText('.'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_27_Field.php b/samples/Sample_27_Field.php index 479342e3dd..5774789561 100644 --- a/samples/Sample_27_Field.php +++ b/samples/Sample_27_Field.php @@ -5,24 +5,24 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); -// Begin code +// New section $section = $phpWord->addSection(); // Add Field elements // See Element/Field.php for all options -$section->addText(htmlspecialchars('Date field:', ENT_COMPAT, 'UTF-8')); +$section->addText('Date field:'); $section->addField('DATE', array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat')); -$section->addText(htmlspecialchars('Page field:', ENT_COMPAT, 'UTF-8')); +$section->addText('Page field:'); $section->addField('PAGE', array('format' => 'ArabicDash')); -$section->addText(htmlspecialchars('Number of pages field:', ENT_COMPAT, 'UTF-8')); +$section->addText('Number of pages field:'); $section->addField('NUMPAGES', array('format' => 'Arabic', 'numformat' => '0,00'), array('PreserveFormat')); $textrun = $section->addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER)); -$textrun->addText(htmlspecialchars('This is the date of lunar calendar ', ENT_COMPAT, 'UTF-8')); +$textrun->addText('This is the date of lunar calendar '); $textrun->addField('DATE', array('dateformat' => 'd-M-yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar')); -$textrun->addText(htmlspecialchars(' written in a textrun.', ENT_COMPAT, 'UTF-8')); +$textrun->addText(' written in a textrun.'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_29_Line.php b/samples/Sample_29_Line.php index 5b288803a4..030308eef1 100644 --- a/samples/Sample_29_Line.php +++ b/samples/Sample_29_Line.php @@ -5,12 +5,12 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); -// Begin code +// New section $section = $phpWord->addSection(); // Add Line elements // See Element/Line.php for all options -$section->addText(htmlspecialchars('Horizontal Line (Inline style):', ENT_COMPAT, 'UTF-8')); +$section->addText('Horizontal Line (Inline style):'); $section->addLine( array( 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4), @@ -18,7 +18,7 @@ 'positioning' => 'absolute', ) ); -$section->addText(htmlspecialchars('Vertical Line (Inline style):', ENT_COMPAT, 'UTF-8')); +$section->addText('Vertical Line (Inline style):'); $section->addLine( array( 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0), @@ -29,7 +29,7 @@ // Two text break $section->addTextBreak(1); -$section->addText(htmlspecialchars('Positioned Line (red):', ENT_COMPAT, 'UTF-8')); +$section->addText('Positioned Line (red):'); $section->addLine( array( 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4), @@ -44,7 +44,7 @@ ) ); -$section->addText(htmlspecialchars('Horizontal Formatted Line', ENT_COMPAT, 'UTF-8')); +$section->addText('Horizontal Formatted Line'); $section->addLine( array( 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15), diff --git a/samples/Sample_31_Shape.php b/samples/Sample_31_Shape.php index d8c4e4f208..33628fcea4 100644 --- a/samples/Sample_31_Shape.php +++ b/samples/Sample_31_Shape.php @@ -3,14 +3,16 @@ // New Word document echo date('H:i:s'), ' Create new PhpWord object', EOL; - $phpWord = new \PhpOffice\PhpWord\PhpWord(); -$phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true)); +// New section $section = $phpWord->addSection(); +// Define styles +$phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true)); + // Arc -$section->addTitle(htmlspecialchars('Arc', ENT_COMPAT, 'UTF-8'), 1); +$section->addTitle('Arc', 1); $section->addShape( 'arc', array( @@ -21,7 +23,7 @@ ); // Curve -$section->addTitle(htmlspecialchars('Curve', ENT_COMPAT, 'UTF-8'), 1); +$section->addTitle('Curve', 1); $section->addShape( 'curve', array( @@ -38,7 +40,7 @@ ); // Line -$section->addTitle(htmlspecialchars('Line', ENT_COMPAT, 'UTF-8'), 1); +$section->addTitle('Line', 1); $section->addShape( 'line', array( @@ -54,7 +56,7 @@ ); // Polyline -$section->addTitle(htmlspecialchars('Polyline', ENT_COMPAT, 'UTF-8'), 1); +$section->addTitle('Polyline', 1); $section->addShape( 'polyline', array( @@ -64,7 +66,7 @@ ); // Rectangle -$section->addTitle(htmlspecialchars('Rectangle', ENT_COMPAT, 'UTF-8'), 1); +$section->addTitle('Rectangle', 1); $section->addShape( 'rect', array( @@ -77,7 +79,7 @@ ); // Oval -$section->addTitle(htmlspecialchars('Oval', ENT_COMPAT, 'UTF-8'), 1); +$section->addTitle('Oval', 1); $section->addShape( 'oval', array( diff --git a/samples/Sample_32_Chart.php b/samples/Sample_32_Chart.php index bc18392ef9..2c6458ca4a 100644 --- a/samples/Sample_32_Chart.php +++ b/samples/Sample_32_Chart.php @@ -5,14 +5,15 @@ // New Word document echo date('H:i:s'), ' Create new PhpWord object', EOL; - $phpWord = new \PhpOffice\PhpWord\PhpWord(); + +// Define styles $phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true), array('keepNext' => true, 'spaceBefore' => 240)); $phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true), array('keepNext' => true, 'spaceBefore' => 240)); // 2D charts $section = $phpWord->addSection(); -$section->addTitle(htmlspecialchars('2D charts', ENT_COMPAT, 'UTF-8'), 1); +$section->addTitle('2D charts', 1); $section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous')); $chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar'); @@ -38,7 +39,7 @@ // 3D charts $section = $phpWord->addSection(array('breakType' => 'continuous')); -$section->addTitle(htmlspecialchars('3D charts', ENT_COMPAT, 'UTF-8'), 1); +$section->addTitle('3D charts', 1); $section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous')); $chartTypes = array('pie', 'bar', 'column', 'line', 'area'); diff --git a/samples/Sample_33_FormField.php b/samples/Sample_33_FormField.php index df7fcb7ae9..a855d42a02 100644 --- a/samples/Sample_33_FormField.php +++ b/samples/Sample_33_FormField.php @@ -6,18 +6,19 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord->getProtection()->setEditing('forms'); +// New section $section = $phpWord->addSection(); $textrun = $section->addTextRun(); -$textrun->addText(htmlspecialchars('Form fields can be added in a text run and can be in form of textinput ', ENT_COMPAT, 'UTF-8')); +$textrun->addText('Form fields can be added in a text run and can be in form of textinput '); $textrun->addFormField('textinput')->setName('MyTextBox'); -$textrun->addText(htmlspecialchars(', checkbox ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(', checkbox '); $textrun->addFormField('checkbox')->setDefault(true); -$textrun->addText(htmlspecialchars(', or dropdown ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(', or dropdown '); $textrun->addFormField('dropdown')->setEntries(array('Choice 1', 'Choice 2', 'Choice 3')); -$textrun->addText(htmlspecialchars('. You have to set document protection to "forms" to enable dropdown.', ENT_COMPAT, 'UTF-8')); +$textrun->addText('. You have to set document protection to "forms" to enable dropdown.'); -$section->addText(htmlspecialchars('They can also be added as a stand alone paragraph.', ENT_COMPAT, 'UTF-8')); +$section->addText('They can also be added as a stand alone paragraph.'); $section->addFormField('textinput')->setValue('Your name'); // Save file diff --git a/samples/Sample_34_SDT.php b/samples/Sample_34_SDT.php index 3f2cdcc154..a50422796e 100644 --- a/samples/Sample_34_SDT.php +++ b/samples/Sample_34_SDT.php @@ -5,18 +5,19 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); +// New section $section = $phpWord->addSection(); $textrun = $section->addTextRun(); -$textrun->addText(htmlspecialchars('Combobox: ', ENT_COMPAT, 'UTF-8')); +$textrun->addText('Combobox: '); $textrun->addSDT('comboBox')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2')); $textrun = $section->addTextRun(); -$textrun->addText(htmlspecialchars('Date: ', ENT_COMPAT, 'UTF-8')); +$textrun->addText('Date: '); $textrun->addSDT('date'); $textrun = $section->addTextRun(); -$textrun->addText(htmlspecialchars('Drop down list: ', ENT_COMPAT, 'UTF-8')); +$textrun->addText('Drop down list: '); $textrun->addSDT('dropDownList')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2')); // Save file diff --git a/samples/Sample_35_InternalLink.php b/samples/Sample_35_InternalLink.php index 90bae238ef..5ab7d9b4d9 100644 --- a/samples/Sample_35_InternalLink.php +++ b/samples/Sample_35_InternalLink.php @@ -6,13 +6,13 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); -$section->addTitle(htmlspecialchars('This is page 1', ENT_COMPAT, 'UTF-8'), 1); +$section->addTitle('This is page 1', 1); $linkIsInternal = true; -$section->addLink('MyBookmark', htmlspecialchars('Take me to page 3', ENT_COMPAT, 'UTF-8'), null, null, $linkIsInternal); +$section->addLink('MyBookmark', 'Take me to page 3', null, null, $linkIsInternal); $section->addPageBreak(); -$section->addTitle(htmlspecialchars('This is page 2', ENT_COMPAT, 'UTF-8'), 1); +$section->addTitle('This is page 2', 1); $section->addPageBreak(); -$section->addTitle(htmlspecialchars('This is page 3', ENT_COMPAT, 'UTF-8'), 1); +$section->addTitle('This is page 3', 1); $section->addBookmark('MyBookmark'); // Save file diff --git a/samples/Sample_36_RTL.php b/samples/Sample_36_RTL.php index 3121e4d06b..615557d78e 100644 --- a/samples/Sample_36_RTL.php +++ b/samples/Sample_36_RTL.php @@ -5,12 +5,14 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); +// New section $section = $phpWord->addSection(); + $textrun = $section->addTextRun(); -$textrun->addText(htmlspecialchars('This is a Left to Right paragraph.', ENT_COMPAT, 'UTF-8')); +$textrun->addText('This is a Left to Right paragraph.'); $textrun = $section->addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END)); -$textrun->addText(htmlspecialchars('سلام این یک پاراگراف راست به چپ است', ENT_COMPAT, 'UTF-8'), array('rtl' => true)); +$textrun->addText('سلام این یک پاراگراف راست به چپ است', array('rtl' => true)); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_Header.php b/samples/Sample_Header.php index 80af0f888d..90bdf4fa11 100644 --- a/samples/Sample_Header.php +++ b/samples/Sample_Header.php @@ -20,6 +20,9 @@ $writers['PDF'] = null; } +// Turn output escaping on +Settings::setOutputEscapingEnabled(true); + // Return to the caller script when runs by CLI if (CLI) { return; diff --git a/src/PhpWord/Escaper/AbstractEscaper.php b/src/PhpWord/Escaper/AbstractEscaper.php new file mode 100644 index 0000000000..7055da3182 --- /dev/null +++ b/src/PhpWord/Escaper/AbstractEscaper.php @@ -0,0 +1,46 @@ +escapeSingleValue($item); + } + } else { + $subject = $this->escapeSingleValue($subject); + } + + return $subject; + } +} diff --git a/src/PhpWord/Escaper/EscaperInterface.php b/src/PhpWord/Escaper/EscaperInterface.php index 2d86050066..39ddf9b424 100644 --- a/src/PhpWord/Escaper/EscaperInterface.php +++ b/src/PhpWord/Escaper/EscaperInterface.php @@ -19,6 +19,8 @@ /** * @since 0.13.0 + * + * @codeCoverageIgnore */ interface EscaperInterface { @@ -27,5 +29,5 @@ interface EscaperInterface * * @return mixed */ - public static function escape($subject); + public function escape($subject); } diff --git a/src/PhpWord/Escaper/RegExp.php b/src/PhpWord/Escaper/RegExp.php index 5f6d129867..30d799d96a 100644 --- a/src/PhpWord/Escaper/RegExp.php +++ b/src/PhpWord/Escaper/RegExp.php @@ -19,31 +19,15 @@ /** * @since 0.13.0 + * + * @codeCoverageIgnore */ -class RegExp implements EscaperInterface +class RegExp extends AbstractEscaper { const REG_EXP_DELIMITER = '/'; - /** - * @param string $subject - * - * @return string - */ - protected static function escapeSingleItem($subject) + protected function escapeSingleValue($subject) { return self::REG_EXP_DELIMITER . preg_quote($subject, self::REG_EXP_DELIMITER) . self::REG_EXP_DELIMITER . 'u'; } - - public static function escape($subject) - { - if (is_array($subject)) { - foreach ($subject as &$item) { - $item = self::escapeSingleItem($item); - } - } else { - $subject = self::escapeSingleItem($subject); - } - - return $subject; - } } diff --git a/src/PhpWord/Escaper/Xml.php b/src/PhpWord/Escaper/Xml.php new file mode 100644 index 0000000000..6cbdceca1f --- /dev/null +++ b/src/PhpWord/Escaper/Xml.php @@ -0,0 +1,32 @@ +escape($replace); + } + $this->tempDocumentHeaders = $this->setValueForPart($search, $replace, $this->tempDocumentHeaders, $limit); $this->tempDocumentMainPart = $this->setValueForPart($search, $replace, $this->tempDocumentMainPart, $limit); $this->tempDocumentFooters = $this->setValueForPart($search, $replace, $this->tempDocumentFooters, $limit); @@ -442,7 +451,8 @@ protected function setValueForPart($search, $replace, $documentPartXML, $limit) if (self::MAXIMUM_REPLACEMENTS_DEFAULT === $limit) { return str_replace($search, $replace, $documentPartXML); } else { - return preg_replace(RegExp::escape($search), $replace, $documentPartXML, $limit); + $regExpEscaper = new RegExp(); + return preg_replace($regExpEscaper->escape($search), $replace, $documentPartXML, $limit); } } diff --git a/src/PhpWord/Writer/Word2007/Element/CheckBox.php b/src/PhpWord/Writer/Word2007/Element/CheckBox.php index 247c7feb7d..5d2e7302b9 100644 --- a/src/PhpWord/Writer/Word2007/Element/CheckBox.php +++ b/src/PhpWord/Writer/Word2007/Element/CheckBox.php @@ -16,6 +16,7 @@ */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; +use PhpOffice\PhpWord\Settings; /** * CheckBox element writer @@ -63,7 +64,7 @@ public function write() $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:instrText'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw(' FORMCHECKBOX '); + $xmlWriter->text(' FORMCHECKBOX '); $xmlWriter->endElement();// w:instrText $xmlWriter->endElement(); // w:r $xmlWriter->startElement('w:r'); @@ -83,7 +84,11 @@ public function write() $xmlWriter->startElement('w:t'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw($this->getText($element->getText())); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->text($this->getText($element->getText())); + } else { + $xmlWriter->writeRaw($this->getText($element->getText())); + } $xmlWriter->endElement(); // w:t $xmlWriter->endElement(); // w:r diff --git a/src/PhpWord/Writer/Word2007/Element/Field.php b/src/PhpWord/Writer/Word2007/Element/Field.php index 19239287c5..5dadfadfed 100644 --- a/src/PhpWord/Writer/Word2007/Element/Field.php +++ b/src/PhpWord/Writer/Word2007/Element/Field.php @@ -79,9 +79,7 @@ public function write() $xmlWriter->endElement(); // w:noProof $xmlWriter->endElement(); // w:rPr - $xmlWriter->startElement('w:t'); - $xmlWriter->writeRaw('1'); - $xmlWriter->endElement(); // w:t + $xmlWriter->writeElement('w:t', '1'); $xmlWriter->endElement(); // w:r $xmlWriter->endElement(); // w:fldSimple diff --git a/src/PhpWord/Writer/Word2007/Element/FormField.php b/src/PhpWord/Writer/Word2007/Element/FormField.php index 669b8183a9..9b22e60741 100644 --- a/src/PhpWord/Writer/Word2007/Element/FormField.php +++ b/src/PhpWord/Writer/Word2007/Element/FormField.php @@ -19,6 +19,7 @@ use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Element\FormField as FormFieldElement; +use PhpOffice\PhpWord\Settings; /** * FormField element writer @@ -78,7 +79,7 @@ public function write() $this->writeFontStyle(); $xmlWriter->startElement('w:instrText'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw("{$instruction}"); + $xmlWriter->text("{$instruction}"); $xmlWriter->endElement();// w:instrText $xmlWriter->endElement(); // w:r @@ -91,7 +92,11 @@ public function write() $this->writeFontStyle(); $xmlWriter->startElement('w:t'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw($value); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->text($value); + } else { + $xmlWriter->writeRaw($value); + } $xmlWriter->endElement(); // w:t $xmlWriter->endElement(); // w:r diff --git a/src/PhpWord/Writer/Word2007/Element/Link.php b/src/PhpWord/Writer/Word2007/Element/Link.php index 3b90db5ccc..b504a94b25 100644 --- a/src/PhpWord/Writer/Word2007/Element/Link.php +++ b/src/PhpWord/Writer/Word2007/Element/Link.php @@ -16,6 +16,7 @@ */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; +use PhpOffice\PhpWord\Settings; /** * Link element writer @@ -54,7 +55,11 @@ public function write() $xmlWriter->startElement('w:t'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw($element->getText()); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->text($element->getText()); + } else { + $xmlWriter->writeRaw($element->getText()); + } $xmlWriter->endElement(); // w:t $xmlWriter->endElement(); // w:r $xmlWriter->endElement(); // w:hyperlink diff --git a/src/PhpWord/Writer/Word2007/Element/PreserveText.php b/src/PhpWord/Writer/Word2007/Element/PreserveText.php index 4856edc7b1..5c1c493b12 100644 --- a/src/PhpWord/Writer/Word2007/Element/PreserveText.php +++ b/src/PhpWord/Writer/Word2007/Element/PreserveText.php @@ -16,6 +16,7 @@ */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; +use PhpOffice\PhpWord\Settings; /** * PreserveText element writer @@ -60,7 +61,11 @@ public function write() $xmlWriter->startElement('w:instrText'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw($text); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->text($text); + } else { + $xmlWriter->writeRaw($text); + } $xmlWriter->endElement(); $xmlWriter->endElement(); @@ -82,7 +87,11 @@ public function write() $xmlWriter->startElement('w:t'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw($this->getText($text)); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->text($this->getText($text)); + } else { + $xmlWriter->writeRaw($this->getText($text)); + } $xmlWriter->endElement(); $xmlWriter->endElement(); } diff --git a/src/PhpWord/Writer/Word2007/Element/SDT.php b/src/PhpWord/Writer/Word2007/Element/SDT.php index 2d639242a3..706eefdebb 100644 --- a/src/PhpWord/Writer/Word2007/Element/SDT.php +++ b/src/PhpWord/Writer/Word2007/Element/SDT.php @@ -58,9 +58,7 @@ public function write() // Content $xmlWriter->startElement('w:sdtContent'); $xmlWriter->startElement('w:r'); - $xmlWriter->startElement('w:t'); - $xmlWriter->writeRaw('Pick value'); - $xmlWriter->endElement(); // w:t + $xmlWriter->writeElement('w:t', 'Pick value'); $xmlWriter->endElement(); // w:r $xmlWriter->endElement(); // w:sdtContent diff --git a/src/PhpWord/Writer/Word2007/Element/TOC.php b/src/PhpWord/Writer/Word2007/Element/TOC.php index fcc90886df..cf839127b0 100644 --- a/src/PhpWord/Writer/Word2007/Element/TOC.php +++ b/src/PhpWord/Writer/Word2007/Element/TOC.php @@ -19,6 +19,7 @@ use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Element\TOC as TOCElement; +use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter; @@ -99,9 +100,13 @@ private function writeTitle(XMLWriter $xmlWriter, TOCElement $element, $title, $ $styleWriter = new FontStyleWriter($xmlWriter, $fontStyle); $styleWriter->write(); } - $xmlWriter->startElement('w:t'); - $xmlWriter->writeRaw($title->getText()); - $xmlWriter->endElement(); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->writeElement('w:t', $title->getText()); + } else { + $xmlWriter->startElement('w:t'); + $xmlWriter->writeRaw($title->getText()); + $xmlWriter->endElement(); + } $xmlWriter->endElement(); // w:r $xmlWriter->startElement('w:r'); @@ -117,7 +122,7 @@ private function writeTitle(XMLWriter $xmlWriter, TOCElement $element, $title, $ $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:instrText'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw("PAGEREF _Toc{$rId} \h"); + $xmlWriter->text("PAGEREF _Toc{$rId} \h"); $xmlWriter->endElement(); $xmlWriter->endElement(); @@ -200,7 +205,7 @@ private function writeFieldMark(XMLWriter $xmlWriter, TOCElement $element) $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:instrText'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw("TOC \o {$minDepth}-{$maxDepth} \h \z \u"); + $xmlWriter->text("TOC \o {$minDepth}-{$maxDepth} \h \z \u"); $xmlWriter->endElement(); $xmlWriter->endElement(); diff --git a/src/PhpWord/Writer/Word2007/Element/Text.php b/src/PhpWord/Writer/Word2007/Element/Text.php index 3c628cd275..97fd17754c 100644 --- a/src/PhpWord/Writer/Word2007/Element/Text.php +++ b/src/PhpWord/Writer/Word2007/Element/Text.php @@ -16,6 +16,7 @@ */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; +use PhpOffice\PhpWord\Settings; /** * Text element writer @@ -45,7 +46,11 @@ public function write() $xmlWriter->startElement('w:t'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw($this->getText($element->getText())); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->text($this->getText($element->getText())); + } else { + $xmlWriter->writeRaw($this->getText($element->getText())); + } $xmlWriter->endElement(); $xmlWriter->endElement(); // w:r diff --git a/src/PhpWord/Writer/Word2007/Element/Title.php b/src/PhpWord/Writer/Word2007/Element/Title.php index f5ece9c776..3865f59aa9 100644 --- a/src/PhpWord/Writer/Word2007/Element/Title.php +++ b/src/PhpWord/Writer/Word2007/Element/Title.php @@ -16,6 +16,7 @@ */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; +use PhpOffice\PhpWord\Settings; /** * TextRun element writer @@ -60,9 +61,13 @@ public function write() // Actual text $xmlWriter->startElement('w:r'); - $xmlWriter->startElement('w:t'); - $xmlWriter->writeRaw($this->getText($element->getText())); - $xmlWriter->endElement(); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->writeElement('w:t', $this->getText($element->getText())); + } else { + $xmlWriter->startElement('w:t'); + $xmlWriter->writeRaw($this->getText($element->getText())); + $xmlWriter->endElement(); + } $xmlWriter->endElement(); // Bookmark end diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 78f2ca24e3..f7d1c2ce14 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -241,11 +241,13 @@ private function writeSeriesItem(XMLWriter $xmlWriter, $type, $values) foreach ($values as $value) { $xmlWriter->startElement('c:pt'); $xmlWriter->writeAttribute('idx', $index); - - $xmlWriter->startElement('c:v'); - $xmlWriter->writeRaw($value); - $xmlWriter->endElement(); // c:v - + if (\PhpOffice\PhpWord\Settings::isOutputEscapingEnabled()) { + $xmlWriter->writeElement('c:v', $value); + } else { + $xmlWriter->startElement('c:v'); + $xmlWriter->writeRaw($value); + $xmlWriter->endElement(); + } $xmlWriter->endElement(); // c:pt $index++; } diff --git a/src/PhpWord/Writer/Word2007/Part/DocPropsCore.php b/src/PhpWord/Writer/Word2007/Part/DocPropsCore.php index f866803497..96faae2e39 100644 --- a/src/PhpWord/Writer/Word2007/Part/DocPropsCore.php +++ b/src/PhpWord/Writer/Word2007/Part/DocPropsCore.php @@ -54,13 +54,13 @@ public function write() // dcterms:created $xmlWriter->startElement('dcterms:created'); $xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF'); - $xmlWriter->writeRaw(date($this->dateFormat, $phpWord->getDocInfo()->getCreated())); + $xmlWriter->text(date($this->dateFormat, $phpWord->getDocInfo()->getCreated())); $xmlWriter->endElement(); // dcterms:modified $xmlWriter->startElement('dcterms:modified'); $xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF'); - $xmlWriter->writeRaw(date($this->dateFormat, $phpWord->getDocInfo()->getModified())); + $xmlWriter->text(date($this->dateFormat, $phpWord->getDocInfo()->getModified())); $xmlWriter->endElement(); $xmlWriter->endElement(); // cp:coreProperties diff --git a/src/PhpWord/Writer/Word2007/Part/DocPropsCustom.php b/src/PhpWord/Writer/Word2007/Part/DocPropsCustom.php index c4510e199a..6c404ce930 100644 --- a/src/PhpWord/Writer/Word2007/Part/DocPropsCustom.php +++ b/src/PhpWord/Writer/Word2007/Part/DocPropsCustom.php @@ -60,9 +60,7 @@ public function write() $xmlWriter->writeElement('vt:bool', ($propertyValue) ? 'true' : 'false'); break; case 'd': - $xmlWriter->startElement('vt:filetime'); - $xmlWriter->writeRaw(date($this->dateFormat, $propertyValue)); - $xmlWriter->endElement(); + $xmlWriter->writeElement('vt:filetime', date($this->dateFormat, $propertyValue)); break; default: $xmlWriter->writeElement('vt:lpwstr', $propertyValue); diff --git a/src/PhpWord/Writer/Word2007/Part/Footnotes.php b/src/PhpWord/Writer/Word2007/Part/Footnotes.php index e0faf6ac81..0de413002b 100644 --- a/src/PhpWord/Writer/Word2007/Part/Footnotes.php +++ b/src/PhpWord/Writer/Word2007/Part/Footnotes.php @@ -164,7 +164,7 @@ protected function writeNote(XMLWriter $xmlWriter, $element) $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:t'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw(' '); + $xmlWriter->text(' '); $xmlWriter->endElement(); // w:t $xmlWriter->endElement(); // w:r diff --git a/tests/PhpWord/Element/CellTest.php b/tests/PhpWord/Element/CellTest.php index 4beee149a2..4c122f9e94 100644 --- a/tests/PhpWord/Element/CellTest.php +++ b/tests/PhpWord/Element/CellTest.php @@ -52,7 +52,7 @@ public function testConstructWithStyleArray() public function testAddText() { $oCell = new Cell(); - $element = $oCell->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); + $element = $oCell->addText('text'); $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); @@ -64,11 +64,11 @@ public function testAddText() public function testAddTextNotUTF8() { $oCell = new Cell(); - $element = $oCell->addText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); + $element = $oCell->addText(utf8_decode('ééé')); $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); - $this->assertEquals(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'), $element->getText()); + $this->assertEquals('ééé', $element->getText()); } /** @@ -77,7 +77,7 @@ public function testAddTextNotUTF8() public function testAddLink() { $oCell = new Cell(); - $element = $oCell->addLink(utf8_decode('ééé'), utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); + $element = $oCell->addLink(utf8_decode('ééé'), utf8_decode('ééé')); $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element); @@ -100,11 +100,11 @@ public function testAddTextBreak() public function testAddListItem() { $oCell = new Cell(); - $element = $oCell->addListItem(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); + $element = $oCell->addListItem('text'); $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItem', $element); - $this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $element->getTextObject()->getText()); + $this->assertEquals('text', $element->getTextObject()->getText()); } /** @@ -113,11 +113,11 @@ public function testAddListItem() public function testAddListItemNotUTF8() { $oCell = new Cell(); - $element = $oCell->addListItem(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); + $element = $oCell->addListItem(utf8_decode('ééé')); $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItem', $element); - $this->assertEquals(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'), $element->getTextObject()->getText()); + $this->assertEquals('ééé', $element->getTextObject()->getText()); } /** @@ -165,9 +165,7 @@ public function testAddImageFooter() public function testAddImageSectionByUrl() { $oCell = new Cell(); - $element = $oCell->addImage( - 'http://php.net/images/logos/php-med-trans-light.gif' - ); + $element = $oCell->addImage('http://php.net/images/logos/php-med-trans-light.gif'); $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element); @@ -205,7 +203,7 @@ public function testAddPreserveText() { $oCell = new Cell(); $oCell->setDocPart('Header', 1); - $element = $oCell->addPreserveText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); + $element = $oCell->addPreserveText('text'); $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); @@ -218,11 +216,11 @@ public function testAddPreserveTextNotUTF8() { $oCell = new Cell(); $oCell->setDocPart('Header', 1); - $element = $oCell->addPreserveText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); + $element = $oCell->addPreserveText(utf8_decode('ééé')); $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); - $this->assertEquals(array(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')), $element->getText()); + $this->assertEquals(array('ééé'), $element->getText()); } /** @@ -234,7 +232,7 @@ public function testAddPreserveTextException() { $oCell = new Cell(); $oCell->setDocPart('Section', 1); - $oCell->addPreserveText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); + $oCell->addPreserveText('text'); } /** @@ -255,7 +253,7 @@ public function testCreateTextRun() public function testAddCheckBox() { $oCell = new Cell(); - $element = $oCell->addCheckBox(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')), utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); + $element = $oCell->addCheckBox(utf8_decode('ééé'), utf8_decode('ééé')); $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\CheckBox', $element); diff --git a/tests/PhpWord/Element/CheckBoxTest.php b/tests/PhpWord/Element/CheckBoxTest.php index ef84e469f0..fd0969020f 100644 --- a/tests/PhpWord/Element/CheckBoxTest.php +++ b/tests/PhpWord/Element/CheckBoxTest.php @@ -45,10 +45,10 @@ public function testConstruct() */ public function testCheckBox() { - $oCheckBox = new CheckBox(htmlspecialchars('chkBox', ENT_COMPAT, 'UTF-8'), htmlspecialchars('CheckBox', ENT_COMPAT, 'UTF-8')); + $oCheckBox = new CheckBox('chkBox', 'CheckBox'); - $this->assertEquals(htmlspecialchars('chkBox', ENT_COMPAT, 'UTF-8'), $oCheckBox->getName()); - $this->assertEquals(htmlspecialchars('CheckBox', ENT_COMPAT, 'UTF-8'), $oCheckBox->getText()); + $this->assertEquals('chkBox', $oCheckBox->getName()); + $this->assertEquals('CheckBox', $oCheckBox->getText()); } /** @@ -56,7 +56,7 @@ public function testCheckBox() */ public function testFont() { - $oCheckBox = new CheckBox(htmlspecialchars('chkBox', ENT_COMPAT, 'UTF-8'), htmlspecialchars('CheckBox', ENT_COMPAT, 'UTF-8'), 'fontStyle'); + $oCheckBox = new CheckBox('chkBox', 'CheckBox', 'fontStyle'); $this->assertEquals('fontStyle', $oCheckBox->getFontStyle()); $oCheckBox->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16)); @@ -69,7 +69,7 @@ public function testFont() public function testFontObject() { $font = new Font(); - $oCheckBox = new CheckBox(htmlspecialchars('chkBox', ENT_COMPAT, 'UTF-8'), htmlspecialchars('CheckBox', ENT_COMPAT, 'UTF-8'), $font); + $oCheckBox = new CheckBox('chkBox', 'CheckBox', $font); $this->assertEquals($font, $oCheckBox->getFontStyle()); } @@ -78,7 +78,7 @@ public function testFontObject() */ public function testParagraph() { - $oCheckBox = new CheckBox(htmlspecialchars('chkBox', ENT_COMPAT, 'UTF-8'), htmlspecialchars('CheckBox', ENT_COMPAT, 'UTF-8'), 'fontStyle', 'paragraphStyle'); + $oCheckBox = new CheckBox('chkBox', 'CheckBox', 'fontStyle', 'paragraphStyle'); $this->assertEquals('paragraphStyle', $oCheckBox->getParagraphStyle()); $oCheckBox->setParagraphStyle(array('alignment' => Jc::CENTER, 'spaceAfter' => 100)); diff --git a/tests/PhpWord/Element/FooterTest.php b/tests/PhpWord/Element/FooterTest.php index ccaec3f284..c6d10469db 100644 --- a/tests/PhpWord/Element/FooterTest.php +++ b/tests/PhpWord/Element/FooterTest.php @@ -42,7 +42,7 @@ public function testConstruct() public function testAddText() { $oFooter = new Footer(1); - $element = $oFooter->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); + $element = $oFooter->addText('text'); $this->assertCount(1, $oFooter->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); @@ -54,11 +54,11 @@ public function testAddText() public function testAddTextNotUTF8() { $oFooter = new Footer(1); - $element = $oFooter->addText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); + $element = $oFooter->addText(utf8_decode('ééé')); $this->assertCount(1, $oFooter->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); - $this->assertEquals(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'), $element->getText()); + $this->assertEquals('ééé', $element->getText()); } /** @@ -116,9 +116,7 @@ public function testAddImage() public function testAddImageByUrl() { $oFooter = new Footer(1); - $element = $oFooter->addImage( - 'http://php.net/images/logos/php-med-trans-light.gif' - ); + $element = $oFooter->addImage('http://php.net/images/logos/php-med-trans-light.gif'); $this->assertCount(1, $oFooter->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element); @@ -130,7 +128,7 @@ public function testAddImageByUrl() public function testAddPreserveText() { $oFooter = new Footer(1); - $element = $oFooter->addPreserveText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); + $element = $oFooter->addPreserveText('text'); $this->assertCount(1, $oFooter->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); @@ -142,11 +140,11 @@ public function testAddPreserveText() public function testAddPreserveTextNotUTF8() { $oFooter = new Footer(1); - $element = $oFooter->addPreserveText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); + $element = $oFooter->addPreserveText(utf8_decode('ééé')); $this->assertCount(1, $oFooter->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); - $this->assertEquals(array(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')), $element->getText()); + $this->assertEquals(array('ééé'), $element->getText()); } /** diff --git a/tests/PhpWord/Element/FootnoteTest.php b/tests/PhpWord/Element/FootnoteTest.php index c95b2624f6..17625c80be 100644 --- a/tests/PhpWord/Element/FootnoteTest.php +++ b/tests/PhpWord/Element/FootnoteTest.php @@ -65,7 +65,7 @@ public function testConstructArray() public function testAddText() { $oFootnote = new Footnote(); - $element = $oFootnote->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); + $element = $oFootnote->addText('text'); $this->assertCount(1, $oFootnote->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); diff --git a/tests/PhpWord/Element/HeaderTest.php b/tests/PhpWord/Element/HeaderTest.php index b9c1de25e6..4de82556d3 100644 --- a/tests/PhpWord/Element/HeaderTest.php +++ b/tests/PhpWord/Element/HeaderTest.php @@ -43,11 +43,11 @@ public function testConstructDefault() public function testAddText() { $oHeader = new Header(1); - $element = $oHeader->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); + $element = $oHeader->addText('text'); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertCount(1, $oHeader->getElements()); - $this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $element->getText()); + $this->assertEquals('text', $element->getText()); } /** @@ -56,11 +56,11 @@ public function testAddText() public function testAddTextNotUTF8() { $oHeader = new Header(1); - $element = $oHeader->addText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); + $element = $oHeader->addText(utf8_decode('ééé')); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertCount(1, $oHeader->getElements()); - $this->assertEquals(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'), $element->getText()); + $this->assertEquals('ééé', $element->getText()); } /** @@ -125,9 +125,7 @@ public function testAddImage() public function testAddImageByUrl() { $oHeader = new Header(1); - $element = $oHeader->addImage( - 'http://php.net/images/logos/php-med-trans-light.gif' - ); + $element = $oHeader->addImage('http://php.net/images/logos/php-med-trans-light.gif'); $this->assertCount(1, $oHeader->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element); @@ -139,7 +137,7 @@ public function testAddImageByUrl() public function testAddPreserveText() { $oHeader = new Header(1); - $element = $oHeader->addPreserveText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); + $element = $oHeader->addPreserveText('text'); $this->assertCount(1, $oHeader->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); @@ -151,11 +149,11 @@ public function testAddPreserveText() public function testAddPreserveTextNotUTF8() { $oHeader = new Header(1); - $element = $oHeader->addPreserveText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); + $element = $oHeader->addPreserveText(utf8_decode('ééé')); $this->assertCount(1, $oHeader->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); - $this->assertEquals(array(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')), $element->getText()); + $this->assertEquals(array('ééé'), $element->getText()); } /** diff --git a/tests/PhpWord/Element/LinkTest.php b/tests/PhpWord/Element/LinkTest.php index e67028b4d2..7f9c0178a9 100644 --- a/tests/PhpWord/Element/LinkTest.php +++ b/tests/PhpWord/Element/LinkTest.php @@ -48,14 +48,14 @@ public function testConstructWithParamsArray() { $oLink = new Link( 'https://github.com/PHPOffice/PHPWord', - htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), + 'PHPWord on GitHub', array('color' => '0000FF', 'underline' => Font::UNDERLINE_SINGLE), array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600) ); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $oLink); $this->assertEquals('https://github.com/PHPOffice/PHPWord', $oLink->getSource()); - $this->assertEquals(htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), $oLink->getText()); + $this->assertEquals('PHPWord on GitHub', $oLink->getText()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oLink->getFontStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oLink->getParagraphStyle()); } diff --git a/tests/PhpWord/Element/ListItemRunTest.php b/tests/PhpWord/Element/ListItemRunTest.php index ccec75fa9a..84f3ec890b 100644 --- a/tests/PhpWord/Element/ListItemRunTest.php +++ b/tests/PhpWord/Element/ListItemRunTest.php @@ -99,11 +99,11 @@ public function testDepth() public function testAddText() { $oListItemRun = new ListItemRun(); - $element = $oListItemRun->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); + $element = $oListItemRun->addText('text'); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertCount(1, $oListItemRun->getElements()); - $this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $element->getText()); + $this->assertEquals('text', $element->getText()); } /** @@ -112,11 +112,11 @@ public function testAddText() public function testAddTextNotUTF8() { $oListItemRun = new ListItemRun(); - $element = $oListItemRun->addText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); + $element = $oListItemRun->addText(utf8_decode('ééé')); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertCount(1, $oListItemRun->getElements()); - $this->assertEquals(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'), $element->getText()); + $this->assertEquals('ééé', $element->getText()); } /** @@ -138,12 +138,12 @@ public function testAddLink() public function testAddLinkWithName() { $oListItemRun = new ListItemRun(); - $element = $oListItemRun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8')); + $element = $oListItemRun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element); $this->assertCount(1, $oListItemRun->getElements()); $this->assertEquals('https://github.com/PHPOffice/PHPWord', $element->getSource()); - $this->assertEquals(htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), $element->getText()); + $this->assertEquals('PHPWord on GitHub', $element->getText()); } /** diff --git a/tests/PhpWord/Element/ListItemTest.php b/tests/PhpWord/Element/ListItemTest.php index 3a1a557625..4f055620f3 100644 --- a/tests/PhpWord/Element/ListItemTest.php +++ b/tests/PhpWord/Element/ListItemTest.php @@ -30,7 +30,7 @@ class ListItemTest extends \PHPUnit_Framework_TestCase */ public function testText() { - $oListItem = new ListItem(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); + $oListItem = new ListItem('text'); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $oListItem->getTextObject()); } @@ -40,12 +40,7 @@ public function testText() */ public function testStyle() { - $oListItem = new ListItem( - htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), - 1, - null, - array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER) - ); + $oListItem = new ListItem('text', 1, null, array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER)); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\ListItem', $oListItem->getStyle()); $this->assertEquals(\PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER, $oListItem->getStyle()->getListType()); @@ -57,7 +52,7 @@ public function testStyle() public function testDepth() { $iVal = rand(1, 1000); - $oListItem = new ListItem(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $iVal); + $oListItem = new ListItem('text', $iVal); $this->assertEquals($iVal, $oListItem->getDepth()); } diff --git a/tests/PhpWord/Element/PreserveTextTest.php b/tests/PhpWord/Element/PreserveTextTest.php index 06a919c112..71299264f3 100644 --- a/tests/PhpWord/Element/PreserveTextTest.php +++ b/tests/PhpWord/Element/PreserveTextTest.php @@ -44,8 +44,8 @@ public function testConstruct() */ public function testConstructWithString() { - $oPreserveText = new PreserveText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), 'styleFont', 'styleParagraph'); - $this->assertEquals(array(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')), $oPreserveText->getText()); + $oPreserveText = new PreserveText('text', 'styleFont', 'styleParagraph'); + $this->assertEquals(array('text'), $oPreserveText->getText()); $this->assertEquals('styleFont', $oPreserveText->getFontStyle()); $this->assertEquals('styleParagraph', $oPreserveText->getParagraphStyle()); } @@ -55,11 +55,7 @@ public function testConstructWithString() */ public function testConstructWithArray() { - $oPreserveText = new PreserveText( - htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), - array('size' => 16, 'color' => '1B2232'), - array('alignment' => Jc::CENTER) - ); + $oPreserveText = new PreserveText('text', array('size' => 16, 'color' => '1B2232'), array('alignment' => Jc::CENTER)); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oPreserveText->getFontStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oPreserveText->getParagraphStyle()); } diff --git a/tests/PhpWord/Element/SectionTest.php b/tests/PhpWord/Element/SectionTest.php index b09c0b78ee..9cfba74b2c 100644 --- a/tests/PhpWord/Element/SectionTest.php +++ b/tests/PhpWord/Element/SectionTest.php @@ -48,18 +48,18 @@ public function testAddElements() $section = new Section(0); $section->setPhpWord(new PhpWord()); - $section->addText(utf8_decode(htmlspecialchars('ä', ENT_COMPAT, 'UTF-8'))); - $section->addLink(utf8_decode('http://äää.com'), utf8_decode(htmlspecialchars('ä', ENT_COMPAT, 'UTF-8'))); + $section->addText(utf8_decode('ä')); + $section->addLink(utf8_decode('http://äää.com'), utf8_decode('ä')); $section->addTextBreak(); $section->addPageBreak(); $section->addTable(); - $section->addListItem(utf8_decode(htmlspecialchars('ä', ENT_COMPAT, 'UTF-8'))); + $section->addListItem(utf8_decode('ä')); $section->addObject($objectSource); $section->addImage($imageSource); - $section->addTitle(utf8_decode(htmlspecialchars('ä', ENT_COMPAT, 'UTF-8')), 1); + $section->addTitle(utf8_decode('ä'), 1); $section->addTextRun(); $section->addFootnote(); - $section->addCheckBox(utf8_decode(htmlspecialchars('chkä', ENT_COMPAT, 'UTF-8')), utf8_decode(htmlspecialchars('Contentä', ENT_COMPAT, 'UTF-8'))); + $section->addCheckBox(utf8_decode('chkä'), utf8_decode('Contentä')); $section->addTOC(); $elementCollection = $section->getElements(); @@ -106,7 +106,7 @@ public function testAddTitleWithStyle() Style::addTitleStyle(1, array('size' => 14)); $section = new Section(0); $section->setPhpWord(new PhpWord()); - $section->addTitle(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), 1); + $section->addTitle('Test', 1); $elementCollection = $section->getElements(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Title', $elementCollection[0]); diff --git a/tests/PhpWord/Element/TOCTest.php b/tests/PhpWord/Element/TOCTest.php index b96fb9cb5b..6cb8524232 100644 --- a/tests/PhpWord/Element/TOCTest.php +++ b/tests/PhpWord/Element/TOCTest.php @@ -84,7 +84,7 @@ public function testSetGetMinMaxDepth() $phpWord = new PhpWord(); foreach ($titles as $text => $depth) { - $phpWord->addTitle(new Title(htmlspecialchars($text, ENT_COMPAT, 'UTF-8'), $depth)); + $phpWord->addTitle(new Title($text, $depth)); } $toc = new TOC(); $toc->setPhpWord($phpWord); diff --git a/tests/PhpWord/Element/TextRunTest.php b/tests/PhpWord/Element/TextRunTest.php index bdfa4bf53c..e47d42af64 100644 --- a/tests/PhpWord/Element/TextRunTest.php +++ b/tests/PhpWord/Element/TextRunTest.php @@ -68,11 +68,11 @@ public function testConstructArray() public function testAddText() { $oTextRun = new TextRun(); - $element = $oTextRun->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); + $element = $oTextRun->addText('text'); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertCount(1, $oTextRun->getElements()); - $this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $element->getText()); + $this->assertEquals('text', $element->getText()); } /** @@ -81,11 +81,11 @@ public function testAddText() public function testAddTextNotUTF8() { $oTextRun = new TextRun(); - $element = $oTextRun->addText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); + $element = $oTextRun->addText(utf8_decode('ééé')); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertCount(1, $oTextRun->getElements()); - $this->assertEquals(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'), $element->getText()); + $this->assertEquals('ééé', $element->getText()); } /** @@ -107,12 +107,12 @@ public function testAddLink() public function testAddLinkWithName() { $oTextRun = new TextRun(); - $element = $oTextRun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8')); + $element = $oTextRun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element); $this->assertCount(1, $oTextRun->getElements()); $this->assertEquals('https://github.com/PHPOffice/PHPWord', $element->getSource()); - $this->assertEquals(htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), $element->getText()); + $this->assertEquals('PHPWord on GitHub', $element->getText()); } /** diff --git a/tests/PhpWord/Element/TextTest.php b/tests/PhpWord/Element/TextTest.php index 1659e5dbf0..f5e3cc8192 100644 --- a/tests/PhpWord/Element/TextTest.php +++ b/tests/PhpWord/Element/TextTest.php @@ -45,9 +45,9 @@ public function testConstruct() */ public function testText() { - $oText = new Text(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); + $oText = new Text('text'); - $this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $oText->getText()); + $this->assertEquals('text', $oText->getText()); } /** @@ -55,7 +55,7 @@ public function testText() */ public function testFont() { - $oText = new Text(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), 'fontStyle'); + $oText = new Text('text', 'fontStyle'); $this->assertEquals('fontStyle', $oText->getFontStyle()); $oText->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16)); @@ -68,7 +68,7 @@ public function testFont() public function testFontObject() { $font = new Font(); - $oText = new Text(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $font); + $oText = new Text('text', $font); $this->assertEquals($font, $oText->getFontStyle()); } @@ -77,7 +77,7 @@ public function testFontObject() */ public function testParagraph() { - $oText = new Text(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), 'fontStyle', 'paragraphStyle'); + $oText = new Text('text', 'fontStyle', 'paragraphStyle'); $this->assertEquals('paragraphStyle', $oText->getParagraphStyle()); $oText->setParagraphStyle(array('alignment' => Jc::CENTER, 'spaceAfter' => 100)); diff --git a/tests/PhpWord/Element/TitleTest.php b/tests/PhpWord/Element/TitleTest.php index 687a32f645..3b6f190f21 100644 --- a/tests/PhpWord/Element/TitleTest.php +++ b/tests/PhpWord/Element/TitleTest.php @@ -30,10 +30,10 @@ class TitleTest extends \PHPUnit_Framework_TestCase */ public function testConstruct() { - $oTitle = new Title(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); + $oTitle = new Title('text'); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Title', $oTitle); - $this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $oTitle->getText()); + $this->assertEquals('text', $oTitle->getText()); } /** @@ -41,7 +41,7 @@ public function testConstruct() */ public function testStyleNull() { - $oTitle = new Title(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); + $oTitle = new Title('text'); $this->assertNull($oTitle->getStyle()); } diff --git a/tests/PhpWord/SettingsTest.php b/tests/PhpWord/SettingsTest.php index f5bdb1d9dd..483535b9ae 100644 --- a/tests/PhpWord/SettingsTest.php +++ b/tests/PhpWord/SettingsTest.php @@ -120,12 +120,13 @@ public function testSetGetDefaultFontSize() public function testLoadConfig() { $expected = array( - 'compatibility' => true, - 'zipClass' => 'ZipArchive', - 'pdfRendererName' => 'DomPDF', - 'pdfRendererPath' => '', - 'defaultFontName' => 'Arial', - 'defaultFontSize' => 10, + 'compatibility' => true, + 'zipClass' => 'ZipArchive', + 'pdfRendererName' => 'DomPDF', + 'pdfRendererPath' => '', + 'defaultFontName' => 'Arial', + 'defaultFontSize' => 10, + 'outputEscapingEnabled' => false, ); // Test default value diff --git a/tests/PhpWord/Style/FontTest.php b/tests/PhpWord/Style/FontTest.php index 8c3ed4f752..1108bd3a50 100644 --- a/tests/PhpWord/Style/FontTest.php +++ b/tests/PhpWord/Style/FontTest.php @@ -41,9 +41,9 @@ public function tearDown() */ public function testInitiation() { - $object = new Font(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), array('alignment' => Jc::BOTH)); + $object = new Font('text', array('alignment' => Jc::BOTH)); - $this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $object->getStyleType()); + $this->assertEquals('text', $object->getStyleType()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $object->getParagraphStyle()); $this->assertTrue(is_array($object->getStyleValues())); } @@ -129,7 +129,7 @@ public function testLineHeight() $section = $phpWord->addSection(); // Test style array - $text = $section->addText(htmlspecialchars('This is a test', ENT_COMPAT, 'UTF-8'), array('line-height' => 2.0)); + $text = $section->addText('This is a test', array('line-height' => 2.0)); $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing'); diff --git a/tests/PhpWord/Style/ParagraphTest.php b/tests/PhpWord/Style/ParagraphTest.php index 56180c076b..b8c387a792 100644 --- a/tests/PhpWord/Style/ParagraphTest.php +++ b/tests/PhpWord/Style/ParagraphTest.php @@ -124,7 +124,7 @@ public function testLineHeight() $section = $phpWord->addSection(); // Test style array - $text = $section->addText(htmlspecialchars('This is a test', ENT_COMPAT, 'UTF-8'), array(), array('line-height' => 2.0)); + $text = $section->addText('This is a test', array(), array('line-height' => 2.0)); $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing'); diff --git a/tests/PhpWord/TemplateProcessorTest.php b/tests/PhpWord/TemplateProcessorTest.php index 82c1b75472..c5a4b1a32f 100644 --- a/tests/PhpWord/TemplateProcessorTest.php +++ b/tests/PhpWord/TemplateProcessorTest.php @@ -116,7 +116,7 @@ final public function testXslStyleSheetCanNotBeAppliedOnFailureOfSettingParamete * We have to use error control below, because \XSLTProcessor::setParameter omits warning on failure. * This warning fails the test. */ - @$templateProcessor->applyXslStyleSheet($xslDOMDocument, array(1 => htmlspecialchars('somevalue', ENT_COMPAT, 'UTF-8'))); + @$templateProcessor->applyXslStyleSheet($xslDOMDocument, array(1 => 'somevalue')); } /** @@ -157,9 +157,9 @@ public function testCloneRow() ); $docName = 'clone-test-result.docx'; - $templateProcessor->setValue('tableHeader', utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); + $templateProcessor->setValue('tableHeader', utf8_decode('ééé')); $templateProcessor->cloneRow('userId', 1); - $templateProcessor->setValue('userId#1', htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); + $templateProcessor->setValue('userId#1', 'Test'); $templateProcessor->saveAs($docName); $docFound = file_exists($docName); unlink($docName); @@ -178,11 +178,7 @@ public function testMacrosCanBeReplacedInHeaderAndFooter() $this->assertEquals(array('documentContent', 'headerValue', 'footerValue'), $templateProcessor->getVariables()); $macroNames = array('headerValue', 'documentContent', 'footerValue'); - $macroValues = array( - htmlspecialchars('Header Value', ENT_COMPAT, 'UTF-8'), - htmlspecialchars('Document text.', ENT_COMPAT, 'UTF-8'), - htmlspecialchars('Footer Value', ENT_COMPAT, 'UTF-8') - ); + $macroValues = array('Header Value', 'Document text.', 'Footer Value'); $templateProcessor->setValue($macroNames, $macroValues); $docName = 'header-footer-test-result.docx'; diff --git a/tests/PhpWord/Writer/PDF/DomPDFTest.php b/tests/PhpWord/Writer/PDF/DomPDFTest.php index 5ba36c0279..7484125674 100644 --- a/tests/PhpWord/Writer/PDF/DomPDFTest.php +++ b/tests/PhpWord/Writer/PDF/DomPDFTest.php @@ -37,7 +37,7 @@ public function testConstruct() $phpWord = new PhpWord(); $section = $phpWord->addSection(); - $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8')); + $section->addText('Test 1'); $rendererName = Settings::PDF_RENDERER_DOMPDF; $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf'); diff --git a/tests/PhpWord/Writer/PDF/MPDFTest.php b/tests/PhpWord/Writer/PDF/MPDFTest.php index 3be94f0c4c..5d5e8bf623 100644 --- a/tests/PhpWord/Writer/PDF/MPDFTest.php +++ b/tests/PhpWord/Writer/PDF/MPDFTest.php @@ -36,7 +36,7 @@ public function testConstruct() $phpWord = new PhpWord(); $section = $phpWord->addSection(); - $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8')); + $section->addText('Test 1'); $rendererName = Settings::PDF_RENDERER_MPDF; $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/mpdf/mpdf'); diff --git a/tests/PhpWord/Writer/PDF/TCPDFTest.php b/tests/PhpWord/Writer/PDF/TCPDFTest.php index 3f2bf766e6..62c55fb64d 100644 --- a/tests/PhpWord/Writer/PDF/TCPDFTest.php +++ b/tests/PhpWord/Writer/PDF/TCPDFTest.php @@ -36,7 +36,7 @@ public function testConstruct() $phpWord = new PhpWord(); $section = $phpWord->addSection(); - $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8')); + $section->addText('Test 1'); $rendererName = Settings::PDF_RENDERER_TCPDF; $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/tecnickcom/tcpdf'); diff --git a/tests/PhpWord/Writer/Word2007/ElementTest.php b/tests/PhpWord/Writer/Word2007/ElementTest.php index 789d00f2f5..8e73ccdfd1 100644 --- a/tests/PhpWord/Writer/Word2007/ElementTest.php +++ b/tests/PhpWord/Writer/Word2007/ElementTest.php @@ -202,9 +202,7 @@ public function testFormFieldElements() $section->addFormField('textinput')->setName('MyTextBox'); $section->addFormField('checkbox')->setDefault(true)->setValue('Your name'); - $section->addFormField('dropdown')->setEntries( - array(htmlspecialchars('Choice 1', ENT_COMPAT, 'UTF-8'), htmlspecialchars('Choice 2', ENT_COMPAT, 'UTF-8'), htmlspecialchars('Choice 3', ENT_COMPAT, 'UTF-8')) - ); + $section->addFormField('dropdown')->setEntries(array('Choice 1', 'Choice 2', 'Choice 3')); $doc = TestHelperDOCX::getDocument($phpWord); diff --git a/tests/PhpWord/Writer/Word2007/Part/DocumentTest.php b/tests/PhpWord/Writer/Word2007/Part/DocumentTest.php index bf2a7aef3c..bf5e7edb19 100644 --- a/tests/PhpWord/Writer/Word2007/Part/DocumentTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/DocumentTest.php @@ -70,14 +70,14 @@ public function testElements() $section = $phpWord->addSection(); $section->addTOC(); $section->addPageBreak(); - $section->addText(htmlspecialchars('After page break.', ENT_COMPAT, 'UTF-8')); - $section->addTitle(htmlspecialchars('Title 1', ENT_COMPAT, 'UTF-8'), 1); - $section->addListItem(htmlspecialchars('List Item 1', ENT_COMPAT, 'UTF-8'), 0); - $section->addListItem(htmlspecialchars('List Item 2', ENT_COMPAT, 'UTF-8'), 0); - $section->addListItem(htmlspecialchars('List Item 3', ENT_COMPAT, 'UTF-8'), 0); + $section->addText('After page break.'); + $section->addTitle('Title 1', 1); + $section->addListItem('List Item 1', 0); + $section->addListItem('List Item 2', 0); + $section->addListItem('List Item 3', 0); $section = $phpWord->addSection(); - $section->addTitle(htmlspecialchars('Title 2', ENT_COMPAT, 'UTF-8'), 2); + $section->addTitle('Title 2', 2); $section->addObject($objectSrc); $section->addTextBox(array()); $section->addTextBox( @@ -92,7 +92,7 @@ public function testElements() ) ); $section->addTextBox(array('wrappingStyle' => 'tight', 'positioning' => 'absolute', 'alignment' => Jc::CENTER)); - $section->addListItemRun()->addText(htmlspecialchars('List item run 1', ENT_COMPAT, 'UTF-8')); + $section->addListItemRun()->addText('List item run 1'); $section->addField( 'DATE', array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), @@ -180,10 +180,10 @@ public function testElementStyles() $fontStyle = new Font('text', array('alignment' => Jc::CENTER)); $section = $phpWord->addSection(); - $section->addListItem(htmlspecialchars('List Item', ENT_COMPAT, 'UTF-8'), 0, null, null, 'pStyle'); // Style #5 + $section->addListItem('List Item', 0, null, null, 'pStyle'); // Style #5 $section->addObject($objectSrc, array('alignment' => Jc::CENTER)); $section->addTOC($fontStyle); - $section->addTitle(htmlspecialchars('Title 1', ENT_COMPAT, 'UTF-8'), 1); + $section->addTitle('Title 1', 1); $section->addTOC('fStyle'); $table = $section->addTable('tStyle'); $table->setWidth(100); @@ -216,7 +216,7 @@ public function testWriteText() $phpWord->addFontStyle($rStyle, array('bold' => true)); $phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120)); $section = $phpWord->addSection(); - $section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), $rStyle, $pStyle); + $section->addText('Test', $rStyle, $pStyle); $doc = TestHelperDOCX::getDocument($phpWord); $element = '/w:document/w:body/w:p/w:r/w:rPr/w:rStyle'; @@ -236,9 +236,9 @@ public function testWriteTextRun() $phpWord = new PhpWord(); $phpWord->addParagraphStyle($pStyle, $aStyle); - $section = $phpWord->addSection(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); + $section = $phpWord->addSection('Test'); $textrun = $section->addTextRun($pStyle); - $textrun->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); + $textrun->addText('Test'); $textrun->addTextBreak(); $textrun = $section->addTextRun($aStyle); $textrun->addLink('https://github.com/PHPOffice/PHPWord'); @@ -263,24 +263,14 @@ public function testWriteLink() $paragraphStyleName = 'Paragraph Style'; $expected = 'PHPWord on GitHub'; - $section->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars($expected, ENT_COMPAT, 'UTF-8')); - $section->addLink( - 'https://github.com/PHPOffice/PHPWord', - htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), - $fontStyleArray, - $paragraphStyleArray - ); - $section->addLink( - 'https://github.com/PHPOffice/PHPWord', - htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), - $fontStyleName, - $paragraphStyleName - ); + $section->addLink('https://github.com/PHPOffice/PHPWord', $expected); + $section->addLink('https://github.com/PHPOffice/PHPWord', 'Test', $fontStyleArray, $paragraphStyleArray); + $section->addLink('https://github.com/PHPOffice/PHPWord', 'Test', $fontStyleName, $paragraphStyleName); $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t'); - $this->assertEquals(htmlspecialchars($expected, ENT_COMPAT, 'UTF-8'), $element->nodeValue); + $this->assertEquals($expected, $element->nodeValue); } /** @@ -296,9 +286,9 @@ public function testWritePreserveText() $paragraphStyleArray = array('alignment' => Jc::END); $paragraphStyleName = 'Paragraph'; - $footer->addPreserveText(htmlspecialchars('Page {PAGE}', ENT_COMPAT, 'UTF-8')); - $footer->addPreserveText(htmlspecialchars('{PAGE}', ENT_COMPAT, 'UTF-8'), $fontStyleArray, $paragraphStyleArray); - $footer->addPreserveText(htmlspecialchars('{PAGE}', ENT_COMPAT, 'UTF-8'), $fontStyleName, $paragraphStyleName); + $footer->addPreserveText('Page {PAGE}'); + $footer->addPreserveText('{PAGE}', $fontStyleArray, $paragraphStyleArray); + $footer->addPreserveText('{PAGE}', $fontStyleName, $paragraphStyleName); $doc = TestHelperDOCX::getDocument($phpWord); $preserve = $doc->getElement('w:p/w:r[2]/w:instrText', 'word/footer1.xml'); @@ -387,7 +377,7 @@ public function testWriteTitle() { $phpWord = new PhpWord(); $phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240)); - $phpWord->addSection()->addTitle(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), 1); + $phpWord->addSection()->addTitle('Test', 1); $doc = TestHelperDOCX::getDocument($phpWord); $element = '/w:document/w:body/w:p/w:pPr/w:pStyle'; @@ -406,11 +396,11 @@ public function testWriteCheckbox() // $phpWord->addFontStyle($rStyle, array('bold' => true)); // $phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120)); $section = $phpWord->addSection(); - $section->addCheckBox(htmlspecialchars('Check1', ENT_COMPAT, 'UTF-8'), htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), $rStyle, $pStyle); + $section->addCheckBox('Check1', 'Test', $rStyle, $pStyle); $doc = TestHelperDOCX::getDocument($phpWord); $element = '/w:document/w:body/w:p/w:r/w:fldChar/w:ffData/w:name'; - $this->assertEquals(htmlspecialchars('Check1', ENT_COMPAT, 'UTF-8'), $doc->getElementAttribute($element, 'w:val')); + $this->assertEquals('Check1', $doc->getElementAttribute($element, 'w:val')); } /** @@ -429,7 +419,7 @@ public function testWriteParagraphStyle() 'pageBreakBefore' => true, ); foreach ($attributes as $attribute => $value) { - $section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), null, array($attribute => $value)); + $section->addText('Test', null, array($attribute => $value)); } $doc = TestHelperDOCX::getDocument($phpWord); @@ -467,7 +457,7 @@ public function testWriteFontStyle() $styles['smallCaps'] = true; $section = $phpWord->addSection(); - $section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), $styles); + $section->addText('Test', $styles); $doc = TestHelperDOCX::getDocument($phpWord); $parent = '/w:document/w:body/w:p/w:r/w:rPr'; @@ -519,14 +509,14 @@ public function testWriteTableStyle() $table->setWidth = 100; $table->addRow($rHeight, $rStyles); $cell = $table->addCell($cWidth, $cStyles); - $cell->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); + $cell->addText('Test'); $cell->addTextBreak(); $cell->addLink('https://github.com/PHPOffice/PHPWord'); - $cell->addListItem(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); + $cell->addListItem('Test'); $cell->addImage($imageSrc); $cell->addObject($objectSrc); $textrun = $cell->addTextRun(); - $textrun->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); + $textrun->addText('Test'); $doc = TestHelperDOCX::getDocument($phpWord); diff --git a/tests/PhpWord/Writer/Word2007/Part/FooterTest.php b/tests/PhpWord/Writer/Word2007/Part/FooterTest.php index 82ec12dc85..dc32ebc929 100644 --- a/tests/PhpWord/Writer/Word2007/Part/FooterTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/FooterTest.php @@ -33,11 +33,11 @@ public function testWriteFooter() { $imageSrc = __DIR__ . '/../../../_files/images/PhpWord.png'; $container = new \PhpOffice\PhpWord\Element\Footer(1); - $container->addText(htmlspecialchars('', ENT_COMPAT, 'UTF-8')); - $container->addPreserveText(htmlspecialchars('', ENT_COMPAT, 'UTF-8')); + $container->addText(''); + $container->addPreserveText(''); $container->addTextBreak(); $container->addTextRun(); - $container->addTable()->addRow()->addCell()->addText(htmlspecialchars('', ENT_COMPAT, 'UTF-8')); + $container->addTable()->addRow()->addCell()->addText(''); $container->addImage($imageSrc); $writer = new Word2007(); diff --git a/tests/PhpWord/Writer/Word2007/Part/FootnotesTest.php b/tests/PhpWord/Writer/Word2007/Part/FootnotesTest.php index c89311cfb0..9f4f8f9fbe 100644 --- a/tests/PhpWord/Writer/Word2007/Part/FootnotesTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/FootnotesTest.php @@ -36,13 +36,13 @@ public function testWriteFootnotes() $phpWord = new PhpWord(); $phpWord->addParagraphStyle('pStyle', array('alignment' => Jc::START)); $section = $phpWord->addSection(); - $section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8')); + $section->addText('Text'); $footnote1 = $section->addFootnote('pStyle'); - $footnote1->addText(htmlspecialchars('Footnote', ENT_COMPAT, 'UTF-8')); + $footnote1->addText('Footnote'); $footnote1->addTextBreak(); $footnote1->addLink('https://github.com/PHPOffice/PHPWord'); $footnote2 = $section->addEndnote(array('alignment' => Jc::START)); - $footnote2->addText(htmlspecialchars('Endnote', ENT_COMPAT, 'UTF-8')); + $footnote2->addText('Endnote'); $doc = TestHelperDOCX::getDocument($phpWord); $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:footnoteReference')); diff --git a/tests/PhpWord/Writer/Word2007/Part/HeaderTest.php b/tests/PhpWord/Writer/Word2007/Part/HeaderTest.php index 0f2a4de46b..4db0de7bcd 100644 --- a/tests/PhpWord/Writer/Word2007/Part/HeaderTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/HeaderTest.php @@ -33,11 +33,11 @@ public function testWriteHeader() $imageSrc = __DIR__ . '/../../../_files/images/PhpWord.png'; $container = new \PhpOffice\PhpWord\Element\Header(1); - $container->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); - $container->addPreserveText(htmlspecialchars('', ENT_COMPAT, 'UTF-8')); + $container->addText('Test'); + $container->addPreserveText(''); $container->addTextBreak(); $container->addTextRun(); - $container->addTable()->addRow()->addCell()->addText(htmlspecialchars('', ENT_COMPAT, 'UTF-8')); + $container->addTable()->addRow()->addCell()->addText(''); $container->addImage($imageSrc); $container->addWatermark($imageSrc); diff --git a/tests/PhpWord/Writer/Word2007/Style/FontTest.php b/tests/PhpWord/Writer/Word2007/Style/FontTest.php index 1731f90d52..5a482cbe01 100644 --- a/tests/PhpWord/Writer/Word2007/Style/FontTest.php +++ b/tests/PhpWord/Writer/Word2007/Style/FontTest.php @@ -42,7 +42,7 @@ public function testFontRTL() $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); $textrun = $section->addTextRun(); - $textrun->addText(htmlspecialchars('سلام این یک پاراگراف راست به چپ است', ENT_COMPAT, 'UTF-8'), array('rtl' => true)); + $textrun->addText('سلام این یک پاراگراف راست به چپ است', array('rtl' => true)); $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); $file = 'word/document.xml'; diff --git a/tests/PhpWord/Writer/Word2007Test.php b/tests/PhpWord/Writer/Word2007Test.php index c87ef356ce..00072181b0 100644 --- a/tests/PhpWord/Writer/Word2007Test.php +++ b/tests/PhpWord/Writer/Word2007Test.php @@ -79,12 +79,12 @@ public function testSave() $phpWord->addFontStyle('Font', array('size' => 11)); $phpWord->addParagraphStyle('Paragraph', array('alignment' => Jc::CENTER)); $section = $phpWord->addSection(); - $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'), 'Font', 'Paragraph'); + $section->addText('Test 1', 'Font', 'Paragraph'); $section->addTextBreak(); - $section->addText(htmlspecialchars('Test 2', ENT_COMPAT, 'UTF-8')); + $section->addText('Test 2'); $section = $phpWord->addSection(); $textrun = $section->addTextRun(); - $textrun->addText(htmlspecialchars('Test 3', ENT_COMPAT, 'UTF-8')); + $textrun->addText('Test 3'); $footnote = $textrun->addFootnote(); $footnote->addLink('https://github.com/PHPOffice/PHPWord'); $header = $section->addHeader(); @@ -108,9 +108,9 @@ public function testSaveUseDiskCaching() { $phpWord = new PhpWord(); $section = $phpWord->addSection(); - $section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); + $section->addText('Test'); $footnote = $section->addFootnote(); - $footnote->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); + $footnote->addText('Test'); $writer = new Word2007($phpWord); $writer->setUseDiskCaching(true);