From 5e90c066e88de63d944bddddfc72511100a22d62 Mon Sep 17 00:00:00 2001 From: Roman Syroeshko Date: Fri, 8 Nov 2013 04:40:18 -0800 Subject: [PATCH 01/12] https://github.com/PHPOffice/PHPWord/issues/34 PHPWord_Shared_String.IsUTF8 returns FALSE for Cyrillic UTF-8 input --- src/PHPWord/Shared/String.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PHPWord/Shared/String.php b/src/PHPWord/Shared/String.php index 64309229..3dcdc80e 100644 --- a/src/PHPWord/Shared/String.php +++ b/src/PHPWord/Shared/String.php @@ -141,13 +141,13 @@ class PHPWord_Shared_String } /** - * Check if a string contains UTF8 data + * Check if a string contains UTF-8 data * * @param string $value * @return boolean */ public static function IsUTF8($value = '') { - return utf8_encode(utf8_decode($value)) === $value; + return $value === '' || preg_match('/^./su', $value) === 1; } /** From 3c78edd9f48550c4779854187145b535a1051d3c Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Sun, 15 Dec 2013 12:56:40 +0100 Subject: [PATCH 02/12] IMPROVED : Test if text is UTF-8 before converting --- src/PHPWord/Section.php | 22 ++++++++++++++++------ src/PHPWord/Section/Footer.php | 10 +++++++--- src/PHPWord/Section/Header.php | 10 +++++++--- src/PHPWord/Section/Table/Cell.php | 20 +++++++++++++++----- src/PHPWord/Section/TextRun.php | 6 ++++-- src/PHPWord/Template.php | 4 +++- 6 files changed, 52 insertions(+), 20 deletions(-) diff --git a/src/PHPWord/Section.php b/src/PHPWord/Section.php index 10d1ce6d..d1106d8a 100644 --- a/src/PHPWord/Section.php +++ b/src/PHPWord/Section.php @@ -109,8 +109,10 @@ class PHPWord_Section { * @return PHPWord_Section_Text */ public function addText($text, $styleFont = null, $styleParagraph = null) { - $givenText = utf8_encode($text); - $text = new PHPWord_Section_Text($givenText, $styleFont, $styleParagraph); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } + $text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $text; return $text; } @@ -125,9 +127,13 @@ class PHPWord_Section { * @return PHPWord_Section_Link */ public function addLink($linkSrc, $linkName = null, $styleFont = null, $styleParagraph = null) { - $linkSrc = utf8_encode($linkSrc); + if(!PHPWord_Shared_String::IsUTF8($linkSrc)){ + $linkSrc = utf8_encode($linkSrc); + } if(!is_null($linkName)) { - $linkName = utf8_encode($linkName); + if(!PHPWord_Shared_String::IsUTF8($linkName)){ + $linkName = utf8_encode($linkName); + } } $link = new PHPWord_Section_Link($linkSrc, $linkName, $styleFont, $styleParagraph); @@ -179,7 +185,9 @@ class PHPWord_Section { * @return PHPWord_Section_ListItem */ public function addListItem($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null) { - $text = utf8_encode($text); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } $listItem = new PHPWord_Section_ListItem($text, $depth, $styleFont, $styleList, $styleParagraph); $this->_elementCollection[] = $listItem; return $listItem; @@ -287,7 +295,9 @@ class PHPWord_Section { * @return PHPWord_Section_Title */ public function addTitle($text, $depth = 1) { - $text = utf8_encode($text); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } $styles = PHPWord_Style::getStyles(); if(array_key_exists('Heading_'.$depth, $styles)) { $style = 'Heading'.$depth; diff --git a/src/PHPWord/Section/Footer.php b/src/PHPWord/Section/Footer.php index 90cc9a48..39115097 100644 --- a/src/PHPWord/Section/Footer.php +++ b/src/PHPWord/Section/Footer.php @@ -72,8 +72,10 @@ class PHPWord_Section_Footer { * @return PHPWord_Section_Text */ public function addText($text, $styleFont = null, $styleParagraph = null) { - $givenText = utf8_encode($text); - $text = new PHPWord_Section_Text($givenText, $styleFont, $styleParagraph); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } + $text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $text; return $text; } @@ -162,7 +164,9 @@ class PHPWord_Section_Footer { * @return PHPWord_Section_Footer_PreserveText */ public function addPreserveText($text, $styleFont = null, $styleParagraph = null) { - $text = utf8_encode($text); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } $ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $ptext; return $ptext; diff --git a/src/PHPWord/Section/Header.php b/src/PHPWord/Section/Header.php index 5ea9919a..6734047e 100644 --- a/src/PHPWord/Section/Header.php +++ b/src/PHPWord/Section/Header.php @@ -72,8 +72,10 @@ class PHPWord_Section_Header { * @return PHPWord_Section_Text */ public function addText($text, $styleFont = null, $styleParagraph = null) { - $givenText = utf8_encode($text); - $text = new PHPWord_Section_Text($givenText, $styleFont, $styleParagraph); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } + $text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $text; return $text; } @@ -162,7 +164,9 @@ class PHPWord_Section_Header { * @return PHPWord_Section_Footer_PreserveText */ public function addPreserveText($text, $styleFont = null, $styleParagraph = null) { - $text = utf8_encode($text); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } $ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $ptext; return $ptext; diff --git a/src/PHPWord/Section/Table/Cell.php b/src/PHPWord/Section/Table/Cell.php index 2cf03a62..989042fe 100644 --- a/src/PHPWord/Section/Table/Cell.php +++ b/src/PHPWord/Section/Table/Cell.php @@ -108,7 +108,9 @@ class PHPWord_Section_Table_Cell { * @return PHPWord_Section_Text */ public function addText($text, $styleFont = null, $styleParagraph = null) { - $text = utf8_encode($text); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } $text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $text; return $text; @@ -124,9 +126,13 @@ class PHPWord_Section_Table_Cell { */ public function addLink($linkSrc, $linkName = null, $style = null) { if($this->_insideOf == 'section') { - $linkSrc = utf8_encode($linkSrc); + if(!PHPWord_Shared_String::IsUTF8($linkSrc)){ + $linkSrc = utf8_encode($linkSrc); + } if(!is_null($linkName)) { - $linkName = utf8_encode($linkName); + if(!PHPWord_Shared_String::IsUTF8($linkName)){ + $linkName = utf8_encode($linkName); + } } $link = new PHPWord_Section_Link($linkSrc, $linkName, $style); @@ -160,7 +166,9 @@ class PHPWord_Section_Table_Cell { * @return PHPWord_Section_ListItem */ public function addListItem($text, $depth = 0, $styleText = null, $styleList = null) { - $text = utf8_encode($text); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } $listItem = new PHPWord_Section_ListItem($text, $depth, $styleText, $styleList); $this->_elementCollection[] = $listItem; return $listItem; @@ -269,7 +277,9 @@ class PHPWord_Section_Table_Cell { */ public function addPreserveText($text, $styleFont = null, $styleParagraph = null) { if($this->_insideOf == 'footer' || $this->_insideOf == 'header') { - $text = utf8_encode($text); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } $ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $ptext; return $ptext; diff --git a/src/PHPWord/Section/TextRun.php b/src/PHPWord/Section/TextRun.php index 4f5eece9..6a9bfaca 100644 --- a/src/PHPWord/Section/TextRun.php +++ b/src/PHPWord/Section/TextRun.php @@ -80,8 +80,10 @@ class PHPWord_Section_TextRun { * @return PHPWord_Section_Text */ public function addText($text = null, $styleFont = null) { - $givenText = utf8_encode($text); - $text = new PHPWord_Section_Text($givenText, $styleFont); + if(!PHPWord_Shared_String::IsUTF8($text)){ + $text = utf8_encode($text); + } + $text = new PHPWord_Section_Text($text, $styleFont); $this->_elementCollection[] = $text; return $text; } diff --git a/src/PHPWord/Template.php b/src/PHPWord/Template.php index 832776c3..72004253 100644 --- a/src/PHPWord/Template.php +++ b/src/PHPWord/Template.php @@ -86,7 +86,9 @@ class PHPWord_Template { } if(!is_array($replace)) { - $replace = utf8_encode($replace); + if(!PHPWord_Shared_String::IsUTF8($replace)){ + $replace = utf8_encode($replace); + } } $this->_documentXML = str_replace($search, $replace, $this->_documentXML); From 5d6bb158259971de14975fbcc665403706d4eb57 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Sun, 15 Dec 2013 13:11:28 +0100 Subject: [PATCH 03/12] ADDED : Changelog --- changelog.txt | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 changelog.txt diff --git a/changelog.txt b/changelog.txt new file mode 100644 index 00000000..7ce6daa9 --- /dev/null +++ b/changelog.txt @@ -0,0 +1,32 @@ +************************************************************************************** +* PHPWord +* +* Copyright (c) 2011 - 2013 PHPWord +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* +* @copyright Copyright (c) 2011 - 2013 PHPWord (https://github.com/PHPOffice/PHPWord/) +* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL +* @version ##VERSION##, ##DATE## +************************************************************************************** + +Fixed in branch for release 0.7 : +- Bugfix: (RomanSyroeshko) GH-34 - PHPWord_Shared_String.IsUTF8 returns FALSE for Cyrillic UTF-8 input +- Feature: (Progi1984) GH-1 - Implement RTF Writer +- Feature: (Progi1984) GH-2 - Implement ODT Writer +- General: (MarkBaker) - Add superscript/subscript styling in Excel2007 Writer +- General: (deds) - add indentation support to paragraphs +- General: (Progi1984) GH-27 - Support for Composer +- General: (Progi1984) - Basic CI with Travis \ No newline at end of file From 1b849ec1bb7d01ef1f1babc27fa380fa1b8fc637 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Sun, 15 Dec 2013 13:18:07 +0100 Subject: [PATCH 04/12] Added PHPWord_Exception and exception when could not copy the template --- changelog.txt | 3 ++- src/PHPWord/Exception.php | 52 +++++++++++++++++++++++++++++++++++++++ src/PHPWord/Template.php | 7 ++++-- 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 src/PHPWord/Exception.php diff --git a/changelog.txt b/changelog.txt index 7ce6daa9..72b9644c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -29,4 +29,5 @@ Fixed in branch for release 0.7 : - General: (MarkBaker) - Add superscript/subscript styling in Excel2007 Writer - General: (deds) - add indentation support to paragraphs - General: (Progi1984) GH-27 - Support for Composer -- General: (Progi1984) - Basic CI with Travis \ No newline at end of file +- General: (Progi1984) - Basic CI with Travis +- General: (Progi1984) - Added PHPWord_Exception and exception when could not copy the template \ No newline at end of file diff --git a/src/PHPWord/Exception.php b/src/PHPWord/Exception.php new file mode 100644 index 00000000..1cf4f050 --- /dev/null +++ b/src/PHPWord/Exception.php @@ -0,0 +1,52 @@ +line = $line; + $e->file = $file; + throw $e; + } +} \ No newline at end of file diff --git a/src/PHPWord/Template.php b/src/PHPWord/Template.php index 72004253..bbc3197f 100644 --- a/src/PHPWord/Template.php +++ b/src/PHPWord/Template.php @@ -65,8 +65,11 @@ class PHPWord_Template { public function __construct($strFilename) { $path = dirname($strFilename); $this->_tempFileName = $path.DIRECTORY_SEPARATOR.time().'.docx'; - - copy($strFilename, $this->_tempFileName); // Copy the source File to the temp File + + // Copy the source File to the temp File + if(!copy($strFilename, $this->_tempFileName)){ + throw new PHPWord_Exception('Could not copy the template from '.$strFilename.' to '.$this->_tempFileName.'.'); + } $this->_objZip = new ZipArchive(); $this->_objZip->open($this->_tempFileName); From 0d19d57cba119ca28a230c294b8f8745966bad3f Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Sun, 15 Dec 2013 13:35:17 +0100 Subject: [PATCH 05/12] IMPROVED : Moved examples out of Classes directory --- .gitignore | 7 ++++++- .travis.yml | 10 +++++----- {src => Classes}/PHPWord.php | 0 {src => Classes}/PHPWord/Autoloader.php | 0 {src => Classes}/PHPWord/DocumentProperties.php | 0 {src => Classes}/PHPWord/Exception.php | 0 {src => Classes}/PHPWord/HashTable.php | 0 {src => Classes}/PHPWord/IOFactory.php | 0 {src => Classes}/PHPWord/Media.php | 0 {src => Classes}/PHPWord/Section.php | 0 {src => Classes}/PHPWord/Section/Footer.php | 0 .../PHPWord/Section/Footer/PreserveText.php | 0 {src => Classes}/PHPWord/Section/Header.php | 0 {src => Classes}/PHPWord/Section/Image.php | 0 {src => Classes}/PHPWord/Section/Link.php | 0 {src => Classes}/PHPWord/Section/ListItem.php | 0 {src => Classes}/PHPWord/Section/MemoryImage.php | 0 {src => Classes}/PHPWord/Section/Object.php | 0 {src => Classes}/PHPWord/Section/PageBreak.php | 0 {src => Classes}/PHPWord/Section/Settings.php | 0 {src => Classes}/PHPWord/Section/Table.php | 0 {src => Classes}/PHPWord/Section/Table/Cell.php | 0 {src => Classes}/PHPWord/Section/Text.php | 0 {src => Classes}/PHPWord/Section/TextBreak.php | 0 {src => Classes}/PHPWord/Section/TextRun.php | 0 {src => Classes}/PHPWord/Section/Title.php | 0 {src => Classes}/PHPWord/Shared/Drawing.php | 0 {src => Classes}/PHPWord/Shared/File.php | 0 {src => Classes}/PHPWord/Shared/Font.php | 0 {src => Classes}/PHPWord/Shared/String.php | 0 {src => Classes}/PHPWord/Shared/XMLWriter.php | 0 .../PHPWord/Shared/ZipStreamWrapper.php | 0 {src => Classes}/PHPWord/Style.php | 0 {src => Classes}/PHPWord/Style/Cell.php | 0 {src => Classes}/PHPWord/Style/Font.php | 0 {src => Classes}/PHPWord/Style/Image.php | 0 {src => Classes}/PHPWord/Style/ListItem.php | 0 {src => Classes}/PHPWord/Style/Paragraph.php | 0 {src => Classes}/PHPWord/Style/TOC.php | 0 {src => Classes}/PHPWord/Style/Table.php | 0 {src => Classes}/PHPWord/Style/TableFull.php | 0 {src => Classes}/PHPWord/TOC.php | 0 {src => Classes}/PHPWord/Template.php | 0 {src => Classes}/PHPWord/Writer/IWriter.php | 0 {src => Classes}/PHPWord/Writer/ODText.php | 0 {src => Classes}/PHPWord/Writer/ODText/Content.php | 0 {src => Classes}/PHPWord/Writer/ODText/Manifest.php | 0 {src => Classes}/PHPWord/Writer/ODText/Meta.php | 0 {src => Classes}/PHPWord/Writer/ODText/Mimetype.php | 0 {src => Classes}/PHPWord/Writer/ODText/Styles.php | 0 .../PHPWord/Writer/ODText/WriterPart.php | 0 {src => Classes}/PHPWord/Writer/RTF.php | 0 {src => Classes}/PHPWord/Writer/Word2007.php | 0 {src => Classes}/PHPWord/Writer/Word2007/Base.php | 0 .../PHPWord/Writer/Word2007/ContentTypes.php | 0 .../PHPWord/Writer/Word2007/DocProps.php | 0 .../PHPWord/Writer/Word2007/Document.php | 0 .../PHPWord/Writer/Word2007/DocumentRels.php | 0 {src => Classes}/PHPWord/Writer/Word2007/Footer.php | 0 {src => Classes}/PHPWord/Writer/Word2007/Header.php | 0 {src => Classes}/PHPWord/Writer/Word2007/Rels.php | 0 {src => Classes}/PHPWord/Writer/Word2007/Styles.php | 0 .../PHPWord/Writer/Word2007/WriterPart.php | 0 {src => Classes}/PHPWord/_staticDocParts/_doc.png | Bin {src => Classes}/PHPWord/_staticDocParts/_ppt.png | Bin {src => Classes}/PHPWord/_staticDocParts/_xls.png | Bin .../PHPWord/_staticDocParts/fontTable.xml | 0 .../PHPWord/_staticDocParts/numbering.xml | 0 .../PHPWord/_staticDocParts/settings.xml | 0 {src => Classes}/PHPWord/_staticDocParts/theme1.xml | 0 .../PHPWord/_staticDocParts/webSettings.xml | 0 changelog.txt | 3 ++- composer.json | 2 +- samples/.gitignore | 5 ----- samples/Sample_01_SimpleText.php | 2 +- {src/Examples => samples/old}/AdvancedTable.php | 2 +- {src/Examples => samples/old}/BasicTable.php | 2 +- {src/Examples => samples/old}/HeaderFooter.php | 2 +- {src/Examples => samples/old}/Image.php | 2 +- {src/Examples => samples/old}/Link.php | 2 +- {src/Examples => samples/old}/ListItem.php | 2 +- {src/Examples => samples/old}/Object.php | 2 +- {src/Examples => samples/old}/Section.php | 2 +- {src/Examples => samples/old}/Template.php | 2 +- {src/Examples => samples/old}/Textrun.php | 2 +- {src/Examples => samples/old}/TitleTOC.php | 2 +- {src/Examples => samples/old}/Watermark.php | 2 +- {src/Examples => samples/old}/_earth.JPG | Bin {src/Examples => samples/old}/_mars.jpg | Bin {src/Examples => samples/old}/_sheet.xls | Bin 90 files changed, 27 insertions(+), 26 deletions(-) rename {src => Classes}/PHPWord.php (100%) rename {src => Classes}/PHPWord/Autoloader.php (100%) rename {src => Classes}/PHPWord/DocumentProperties.php (100%) rename {src => Classes}/PHPWord/Exception.php (100%) rename {src => Classes}/PHPWord/HashTable.php (100%) rename {src => Classes}/PHPWord/IOFactory.php (100%) rename {src => Classes}/PHPWord/Media.php (100%) rename {src => Classes}/PHPWord/Section.php (100%) rename {src => Classes}/PHPWord/Section/Footer.php (100%) rename {src => Classes}/PHPWord/Section/Footer/PreserveText.php (100%) rename {src => Classes}/PHPWord/Section/Header.php (100%) rename {src => Classes}/PHPWord/Section/Image.php (100%) rename {src => Classes}/PHPWord/Section/Link.php (100%) rename {src => Classes}/PHPWord/Section/ListItem.php (100%) rename {src => Classes}/PHPWord/Section/MemoryImage.php (100%) rename {src => Classes}/PHPWord/Section/Object.php (100%) rename {src => Classes}/PHPWord/Section/PageBreak.php (100%) rename {src => Classes}/PHPWord/Section/Settings.php (100%) rename {src => Classes}/PHPWord/Section/Table.php (100%) rename {src => Classes}/PHPWord/Section/Table/Cell.php (100%) rename {src => Classes}/PHPWord/Section/Text.php (100%) rename {src => Classes}/PHPWord/Section/TextBreak.php (100%) rename {src => Classes}/PHPWord/Section/TextRun.php (100%) rename {src => Classes}/PHPWord/Section/Title.php (100%) rename {src => Classes}/PHPWord/Shared/Drawing.php (100%) rename {src => Classes}/PHPWord/Shared/File.php (100%) rename {src => Classes}/PHPWord/Shared/Font.php (100%) rename {src => Classes}/PHPWord/Shared/String.php (100%) rename {src => Classes}/PHPWord/Shared/XMLWriter.php (100%) rename {src => Classes}/PHPWord/Shared/ZipStreamWrapper.php (100%) rename {src => Classes}/PHPWord/Style.php (100%) rename {src => Classes}/PHPWord/Style/Cell.php (100%) rename {src => Classes}/PHPWord/Style/Font.php (100%) rename {src => Classes}/PHPWord/Style/Image.php (100%) rename {src => Classes}/PHPWord/Style/ListItem.php (100%) rename {src => Classes}/PHPWord/Style/Paragraph.php (100%) rename {src => Classes}/PHPWord/Style/TOC.php (100%) rename {src => Classes}/PHPWord/Style/Table.php (100%) rename {src => Classes}/PHPWord/Style/TableFull.php (100%) rename {src => Classes}/PHPWord/TOC.php (100%) rename {src => Classes}/PHPWord/Template.php (100%) rename {src => Classes}/PHPWord/Writer/IWriter.php (100%) rename {src => Classes}/PHPWord/Writer/ODText.php (100%) rename {src => Classes}/PHPWord/Writer/ODText/Content.php (100%) rename {src => Classes}/PHPWord/Writer/ODText/Manifest.php (100%) rename {src => Classes}/PHPWord/Writer/ODText/Meta.php (100%) rename {src => Classes}/PHPWord/Writer/ODText/Mimetype.php (100%) rename {src => Classes}/PHPWord/Writer/ODText/Styles.php (100%) rename {src => Classes}/PHPWord/Writer/ODText/WriterPart.php (100%) rename {src => Classes}/PHPWord/Writer/RTF.php (100%) rename {src => Classes}/PHPWord/Writer/Word2007.php (100%) rename {src => Classes}/PHPWord/Writer/Word2007/Base.php (100%) rename {src => Classes}/PHPWord/Writer/Word2007/ContentTypes.php (100%) rename {src => Classes}/PHPWord/Writer/Word2007/DocProps.php (100%) rename {src => Classes}/PHPWord/Writer/Word2007/Document.php (100%) rename {src => Classes}/PHPWord/Writer/Word2007/DocumentRels.php (100%) rename {src => Classes}/PHPWord/Writer/Word2007/Footer.php (100%) rename {src => Classes}/PHPWord/Writer/Word2007/Header.php (100%) rename {src => Classes}/PHPWord/Writer/Word2007/Rels.php (100%) rename {src => Classes}/PHPWord/Writer/Word2007/Styles.php (100%) rename {src => Classes}/PHPWord/Writer/Word2007/WriterPart.php (100%) rename {src => Classes}/PHPWord/_staticDocParts/_doc.png (100%) rename {src => Classes}/PHPWord/_staticDocParts/_ppt.png (100%) rename {src => Classes}/PHPWord/_staticDocParts/_xls.png (100%) rename {src => Classes}/PHPWord/_staticDocParts/fontTable.xml (100%) rename {src => Classes}/PHPWord/_staticDocParts/numbering.xml (100%) rename {src => Classes}/PHPWord/_staticDocParts/settings.xml (100%) rename {src => Classes}/PHPWord/_staticDocParts/theme1.xml (100%) rename {src => Classes}/PHPWord/_staticDocParts/webSettings.xml (100%) delete mode 100644 samples/.gitignore rename {src/Examples => samples/old}/AdvancedTable.php (97%) rename {src/Examples => samples/old}/BasicTable.php (91%) rename {src/Examples => samples/old}/HeaderFooter.php (94%) rename {src/Examples => samples/old}/Image.php (92%) rename {src/Examples => samples/old}/Link.php (93%) rename {src/Examples => samples/old}/ListItem.php (97%) rename {src/Examples => samples/old}/Object.php (90%) rename {src/Examples => samples/old}/Section.php (94%) rename {src/Examples => samples/old}/Template.php (93%) rename {src/Examples => samples/old}/Textrun.php (96%) rename {src/Examples => samples/old}/TitleTOC.php (96%) rename {src/Examples => samples/old}/Watermark.php (91%) rename {src/Examples => samples/old}/_earth.JPG (100%) rename {src/Examples => samples/old}/_mars.jpg (100%) rename {src/Examples => samples/old}/_sheet.xls (100%) diff --git a/.gitignore b/.gitignore index 29a804cb..4abb8c94 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,9 @@ /.settings /.buildpath /.project -/docs \ No newline at end of file +/docs + +*.odt +*.docx +*.rtf +*.txt \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 2cca49ae..5796deca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,14 +26,14 @@ before_script: script: ## PHP_CodeSniffer - - phpcs --standard=PSR1 src/ - - phpcs --standard=PSR2 src/ + - phpcs --standard=PSR1 Classes/ + - phpcs --standard=PSR2 Classes/ ## PHP Copy/Paste Detector - - php phpcpd.phar --verbose src/ + - php phpcpd.phar --verbose Classes/ ## PHP Mess Detector - - phpmd src/ text codesize,unusedcode,naming,design + - phpmd Classes/ text codesize,unusedcode,naming,design ## PHPLOC - - php phploc.phar src/ + - php phploc.phar Classes/ notifications: email: diff --git a/src/PHPWord.php b/Classes/PHPWord.php similarity index 100% rename from src/PHPWord.php rename to Classes/PHPWord.php diff --git a/src/PHPWord/Autoloader.php b/Classes/PHPWord/Autoloader.php similarity index 100% rename from src/PHPWord/Autoloader.php rename to Classes/PHPWord/Autoloader.php diff --git a/src/PHPWord/DocumentProperties.php b/Classes/PHPWord/DocumentProperties.php similarity index 100% rename from src/PHPWord/DocumentProperties.php rename to Classes/PHPWord/DocumentProperties.php diff --git a/src/PHPWord/Exception.php b/Classes/PHPWord/Exception.php similarity index 100% rename from src/PHPWord/Exception.php rename to Classes/PHPWord/Exception.php diff --git a/src/PHPWord/HashTable.php b/Classes/PHPWord/HashTable.php similarity index 100% rename from src/PHPWord/HashTable.php rename to Classes/PHPWord/HashTable.php diff --git a/src/PHPWord/IOFactory.php b/Classes/PHPWord/IOFactory.php similarity index 100% rename from src/PHPWord/IOFactory.php rename to Classes/PHPWord/IOFactory.php diff --git a/src/PHPWord/Media.php b/Classes/PHPWord/Media.php similarity index 100% rename from src/PHPWord/Media.php rename to Classes/PHPWord/Media.php diff --git a/src/PHPWord/Section.php b/Classes/PHPWord/Section.php similarity index 100% rename from src/PHPWord/Section.php rename to Classes/PHPWord/Section.php diff --git a/src/PHPWord/Section/Footer.php b/Classes/PHPWord/Section/Footer.php similarity index 100% rename from src/PHPWord/Section/Footer.php rename to Classes/PHPWord/Section/Footer.php diff --git a/src/PHPWord/Section/Footer/PreserveText.php b/Classes/PHPWord/Section/Footer/PreserveText.php similarity index 100% rename from src/PHPWord/Section/Footer/PreserveText.php rename to Classes/PHPWord/Section/Footer/PreserveText.php diff --git a/src/PHPWord/Section/Header.php b/Classes/PHPWord/Section/Header.php similarity index 100% rename from src/PHPWord/Section/Header.php rename to Classes/PHPWord/Section/Header.php diff --git a/src/PHPWord/Section/Image.php b/Classes/PHPWord/Section/Image.php similarity index 100% rename from src/PHPWord/Section/Image.php rename to Classes/PHPWord/Section/Image.php diff --git a/src/PHPWord/Section/Link.php b/Classes/PHPWord/Section/Link.php similarity index 100% rename from src/PHPWord/Section/Link.php rename to Classes/PHPWord/Section/Link.php diff --git a/src/PHPWord/Section/ListItem.php b/Classes/PHPWord/Section/ListItem.php similarity index 100% rename from src/PHPWord/Section/ListItem.php rename to Classes/PHPWord/Section/ListItem.php diff --git a/src/PHPWord/Section/MemoryImage.php b/Classes/PHPWord/Section/MemoryImage.php similarity index 100% rename from src/PHPWord/Section/MemoryImage.php rename to Classes/PHPWord/Section/MemoryImage.php diff --git a/src/PHPWord/Section/Object.php b/Classes/PHPWord/Section/Object.php similarity index 100% rename from src/PHPWord/Section/Object.php rename to Classes/PHPWord/Section/Object.php diff --git a/src/PHPWord/Section/PageBreak.php b/Classes/PHPWord/Section/PageBreak.php similarity index 100% rename from src/PHPWord/Section/PageBreak.php rename to Classes/PHPWord/Section/PageBreak.php diff --git a/src/PHPWord/Section/Settings.php b/Classes/PHPWord/Section/Settings.php similarity index 100% rename from src/PHPWord/Section/Settings.php rename to Classes/PHPWord/Section/Settings.php diff --git a/src/PHPWord/Section/Table.php b/Classes/PHPWord/Section/Table.php similarity index 100% rename from src/PHPWord/Section/Table.php rename to Classes/PHPWord/Section/Table.php diff --git a/src/PHPWord/Section/Table/Cell.php b/Classes/PHPWord/Section/Table/Cell.php similarity index 100% rename from src/PHPWord/Section/Table/Cell.php rename to Classes/PHPWord/Section/Table/Cell.php diff --git a/src/PHPWord/Section/Text.php b/Classes/PHPWord/Section/Text.php similarity index 100% rename from src/PHPWord/Section/Text.php rename to Classes/PHPWord/Section/Text.php diff --git a/src/PHPWord/Section/TextBreak.php b/Classes/PHPWord/Section/TextBreak.php similarity index 100% rename from src/PHPWord/Section/TextBreak.php rename to Classes/PHPWord/Section/TextBreak.php diff --git a/src/PHPWord/Section/TextRun.php b/Classes/PHPWord/Section/TextRun.php similarity index 100% rename from src/PHPWord/Section/TextRun.php rename to Classes/PHPWord/Section/TextRun.php diff --git a/src/PHPWord/Section/Title.php b/Classes/PHPWord/Section/Title.php similarity index 100% rename from src/PHPWord/Section/Title.php rename to Classes/PHPWord/Section/Title.php diff --git a/src/PHPWord/Shared/Drawing.php b/Classes/PHPWord/Shared/Drawing.php similarity index 100% rename from src/PHPWord/Shared/Drawing.php rename to Classes/PHPWord/Shared/Drawing.php diff --git a/src/PHPWord/Shared/File.php b/Classes/PHPWord/Shared/File.php similarity index 100% rename from src/PHPWord/Shared/File.php rename to Classes/PHPWord/Shared/File.php diff --git a/src/PHPWord/Shared/Font.php b/Classes/PHPWord/Shared/Font.php similarity index 100% rename from src/PHPWord/Shared/Font.php rename to Classes/PHPWord/Shared/Font.php diff --git a/src/PHPWord/Shared/String.php b/Classes/PHPWord/Shared/String.php similarity index 100% rename from src/PHPWord/Shared/String.php rename to Classes/PHPWord/Shared/String.php diff --git a/src/PHPWord/Shared/XMLWriter.php b/Classes/PHPWord/Shared/XMLWriter.php similarity index 100% rename from src/PHPWord/Shared/XMLWriter.php rename to Classes/PHPWord/Shared/XMLWriter.php diff --git a/src/PHPWord/Shared/ZipStreamWrapper.php b/Classes/PHPWord/Shared/ZipStreamWrapper.php similarity index 100% rename from src/PHPWord/Shared/ZipStreamWrapper.php rename to Classes/PHPWord/Shared/ZipStreamWrapper.php diff --git a/src/PHPWord/Style.php b/Classes/PHPWord/Style.php similarity index 100% rename from src/PHPWord/Style.php rename to Classes/PHPWord/Style.php diff --git a/src/PHPWord/Style/Cell.php b/Classes/PHPWord/Style/Cell.php similarity index 100% rename from src/PHPWord/Style/Cell.php rename to Classes/PHPWord/Style/Cell.php diff --git a/src/PHPWord/Style/Font.php b/Classes/PHPWord/Style/Font.php similarity index 100% rename from src/PHPWord/Style/Font.php rename to Classes/PHPWord/Style/Font.php diff --git a/src/PHPWord/Style/Image.php b/Classes/PHPWord/Style/Image.php similarity index 100% rename from src/PHPWord/Style/Image.php rename to Classes/PHPWord/Style/Image.php diff --git a/src/PHPWord/Style/ListItem.php b/Classes/PHPWord/Style/ListItem.php similarity index 100% rename from src/PHPWord/Style/ListItem.php rename to Classes/PHPWord/Style/ListItem.php diff --git a/src/PHPWord/Style/Paragraph.php b/Classes/PHPWord/Style/Paragraph.php similarity index 100% rename from src/PHPWord/Style/Paragraph.php rename to Classes/PHPWord/Style/Paragraph.php diff --git a/src/PHPWord/Style/TOC.php b/Classes/PHPWord/Style/TOC.php similarity index 100% rename from src/PHPWord/Style/TOC.php rename to Classes/PHPWord/Style/TOC.php diff --git a/src/PHPWord/Style/Table.php b/Classes/PHPWord/Style/Table.php similarity index 100% rename from src/PHPWord/Style/Table.php rename to Classes/PHPWord/Style/Table.php diff --git a/src/PHPWord/Style/TableFull.php b/Classes/PHPWord/Style/TableFull.php similarity index 100% rename from src/PHPWord/Style/TableFull.php rename to Classes/PHPWord/Style/TableFull.php diff --git a/src/PHPWord/TOC.php b/Classes/PHPWord/TOC.php similarity index 100% rename from src/PHPWord/TOC.php rename to Classes/PHPWord/TOC.php diff --git a/src/PHPWord/Template.php b/Classes/PHPWord/Template.php similarity index 100% rename from src/PHPWord/Template.php rename to Classes/PHPWord/Template.php diff --git a/src/PHPWord/Writer/IWriter.php b/Classes/PHPWord/Writer/IWriter.php similarity index 100% rename from src/PHPWord/Writer/IWriter.php rename to Classes/PHPWord/Writer/IWriter.php diff --git a/src/PHPWord/Writer/ODText.php b/Classes/PHPWord/Writer/ODText.php similarity index 100% rename from src/PHPWord/Writer/ODText.php rename to Classes/PHPWord/Writer/ODText.php diff --git a/src/PHPWord/Writer/ODText/Content.php b/Classes/PHPWord/Writer/ODText/Content.php similarity index 100% rename from src/PHPWord/Writer/ODText/Content.php rename to Classes/PHPWord/Writer/ODText/Content.php diff --git a/src/PHPWord/Writer/ODText/Manifest.php b/Classes/PHPWord/Writer/ODText/Manifest.php similarity index 100% rename from src/PHPWord/Writer/ODText/Manifest.php rename to Classes/PHPWord/Writer/ODText/Manifest.php diff --git a/src/PHPWord/Writer/ODText/Meta.php b/Classes/PHPWord/Writer/ODText/Meta.php similarity index 100% rename from src/PHPWord/Writer/ODText/Meta.php rename to Classes/PHPWord/Writer/ODText/Meta.php diff --git a/src/PHPWord/Writer/ODText/Mimetype.php b/Classes/PHPWord/Writer/ODText/Mimetype.php similarity index 100% rename from src/PHPWord/Writer/ODText/Mimetype.php rename to Classes/PHPWord/Writer/ODText/Mimetype.php diff --git a/src/PHPWord/Writer/ODText/Styles.php b/Classes/PHPWord/Writer/ODText/Styles.php similarity index 100% rename from src/PHPWord/Writer/ODText/Styles.php rename to Classes/PHPWord/Writer/ODText/Styles.php diff --git a/src/PHPWord/Writer/ODText/WriterPart.php b/Classes/PHPWord/Writer/ODText/WriterPart.php similarity index 100% rename from src/PHPWord/Writer/ODText/WriterPart.php rename to Classes/PHPWord/Writer/ODText/WriterPart.php diff --git a/src/PHPWord/Writer/RTF.php b/Classes/PHPWord/Writer/RTF.php similarity index 100% rename from src/PHPWord/Writer/RTF.php rename to Classes/PHPWord/Writer/RTF.php diff --git a/src/PHPWord/Writer/Word2007.php b/Classes/PHPWord/Writer/Word2007.php similarity index 100% rename from src/PHPWord/Writer/Word2007.php rename to Classes/PHPWord/Writer/Word2007.php diff --git a/src/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php similarity index 100% rename from src/PHPWord/Writer/Word2007/Base.php rename to Classes/PHPWord/Writer/Word2007/Base.php diff --git a/src/PHPWord/Writer/Word2007/ContentTypes.php b/Classes/PHPWord/Writer/Word2007/ContentTypes.php similarity index 100% rename from src/PHPWord/Writer/Word2007/ContentTypes.php rename to Classes/PHPWord/Writer/Word2007/ContentTypes.php diff --git a/src/PHPWord/Writer/Word2007/DocProps.php b/Classes/PHPWord/Writer/Word2007/DocProps.php similarity index 100% rename from src/PHPWord/Writer/Word2007/DocProps.php rename to Classes/PHPWord/Writer/Word2007/DocProps.php diff --git a/src/PHPWord/Writer/Word2007/Document.php b/Classes/PHPWord/Writer/Word2007/Document.php similarity index 100% rename from src/PHPWord/Writer/Word2007/Document.php rename to Classes/PHPWord/Writer/Word2007/Document.php diff --git a/src/PHPWord/Writer/Word2007/DocumentRels.php b/Classes/PHPWord/Writer/Word2007/DocumentRels.php similarity index 100% rename from src/PHPWord/Writer/Word2007/DocumentRels.php rename to Classes/PHPWord/Writer/Word2007/DocumentRels.php diff --git a/src/PHPWord/Writer/Word2007/Footer.php b/Classes/PHPWord/Writer/Word2007/Footer.php similarity index 100% rename from src/PHPWord/Writer/Word2007/Footer.php rename to Classes/PHPWord/Writer/Word2007/Footer.php diff --git a/src/PHPWord/Writer/Word2007/Header.php b/Classes/PHPWord/Writer/Word2007/Header.php similarity index 100% rename from src/PHPWord/Writer/Word2007/Header.php rename to Classes/PHPWord/Writer/Word2007/Header.php diff --git a/src/PHPWord/Writer/Word2007/Rels.php b/Classes/PHPWord/Writer/Word2007/Rels.php similarity index 100% rename from src/PHPWord/Writer/Word2007/Rels.php rename to Classes/PHPWord/Writer/Word2007/Rels.php diff --git a/src/PHPWord/Writer/Word2007/Styles.php b/Classes/PHPWord/Writer/Word2007/Styles.php similarity index 100% rename from src/PHPWord/Writer/Word2007/Styles.php rename to Classes/PHPWord/Writer/Word2007/Styles.php diff --git a/src/PHPWord/Writer/Word2007/WriterPart.php b/Classes/PHPWord/Writer/Word2007/WriterPart.php similarity index 100% rename from src/PHPWord/Writer/Word2007/WriterPart.php rename to Classes/PHPWord/Writer/Word2007/WriterPart.php diff --git a/src/PHPWord/_staticDocParts/_doc.png b/Classes/PHPWord/_staticDocParts/_doc.png similarity index 100% rename from src/PHPWord/_staticDocParts/_doc.png rename to Classes/PHPWord/_staticDocParts/_doc.png diff --git a/src/PHPWord/_staticDocParts/_ppt.png b/Classes/PHPWord/_staticDocParts/_ppt.png similarity index 100% rename from src/PHPWord/_staticDocParts/_ppt.png rename to Classes/PHPWord/_staticDocParts/_ppt.png diff --git a/src/PHPWord/_staticDocParts/_xls.png b/Classes/PHPWord/_staticDocParts/_xls.png similarity index 100% rename from src/PHPWord/_staticDocParts/_xls.png rename to Classes/PHPWord/_staticDocParts/_xls.png diff --git a/src/PHPWord/_staticDocParts/fontTable.xml b/Classes/PHPWord/_staticDocParts/fontTable.xml similarity index 100% rename from src/PHPWord/_staticDocParts/fontTable.xml rename to Classes/PHPWord/_staticDocParts/fontTable.xml diff --git a/src/PHPWord/_staticDocParts/numbering.xml b/Classes/PHPWord/_staticDocParts/numbering.xml similarity index 100% rename from src/PHPWord/_staticDocParts/numbering.xml rename to Classes/PHPWord/_staticDocParts/numbering.xml diff --git a/src/PHPWord/_staticDocParts/settings.xml b/Classes/PHPWord/_staticDocParts/settings.xml similarity index 100% rename from src/PHPWord/_staticDocParts/settings.xml rename to Classes/PHPWord/_staticDocParts/settings.xml diff --git a/src/PHPWord/_staticDocParts/theme1.xml b/Classes/PHPWord/_staticDocParts/theme1.xml similarity index 100% rename from src/PHPWord/_staticDocParts/theme1.xml rename to Classes/PHPWord/_staticDocParts/theme1.xml diff --git a/src/PHPWord/_staticDocParts/webSettings.xml b/Classes/PHPWord/_staticDocParts/webSettings.xml similarity index 100% rename from src/PHPWord/_staticDocParts/webSettings.xml rename to Classes/PHPWord/_staticDocParts/webSettings.xml diff --git a/changelog.txt b/changelog.txt index 72b9644c..028aea1c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -30,4 +30,5 @@ Fixed in branch for release 0.7 : - General: (deds) - add indentation support to paragraphs - General: (Progi1984) GH-27 - Support for Composer - General: (Progi1984) - Basic CI with Travis -- General: (Progi1984) - Added PHPWord_Exception and exception when could not copy the template \ No newline at end of file +- General: (Progi1984) - Added PHPWord_Exception and exception when could not copy the template +- General: (Progi1984) - IMPROVED : Moved examples out of Classes directory \ No newline at end of file diff --git a/composer.json b/composer.json index 75678888..28060794 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ }, "autoload": { "psr-0": { - "PHPWord": "src/" + "PHPWord": "Classes/" } } } diff --git a/samples/.gitignore b/samples/.gitignore deleted file mode 100644 index f3b243cb..00000000 --- a/samples/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ - -*.odt -*.docx -*.rtf -*.txt \ No newline at end of file diff --git a/samples/Sample_01_SimpleText.php b/samples/Sample_01_SimpleText.php index 4bf9d343..d421c37d 100644 --- a/samples/Sample_01_SimpleText.php +++ b/samples/Sample_01_SimpleText.php @@ -9,7 +9,7 @@ else { define('EOL', '
'); } -require_once '../src/PHPWord.php'; +require_once '../Classes/PHPWord.php'; // New Word Document echo date('H:i:s') , " Create new PHPWord object" , EOL; diff --git a/src/Examples/AdvancedTable.php b/samples/old/AdvancedTable.php similarity index 97% rename from src/Examples/AdvancedTable.php rename to samples/old/AdvancedTable.php index 5a2088ff..e83c4e98 100644 --- a/src/Examples/AdvancedTable.php +++ b/samples/old/AdvancedTable.php @@ -1,5 +1,5 @@ Date: Sun, 15 Dec 2013 13:42:36 +0100 Subject: [PATCH 06/12] Word2007 : Add rowspan and colspan to cells --- Classes/PHPWord/Style/Cell.php | 35 +++++++++++++++++++++--- Classes/PHPWord/Writer/Word2007/Base.php | 13 +++++++++ changelog.txt | 1 + 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/Classes/PHPWord/Style/Cell.php b/Classes/PHPWord/Style/Cell.php index a09b3067..090ff7b4 100644 --- a/Classes/PHPWord/Style/Cell.php +++ b/Classes/PHPWord/Style/Cell.php @@ -121,7 +121,20 @@ class PHPWord_Style_Cell { * @var string */ private $_defaultBorderColor; - + + /** + * colspan + * + * @var integer + */ + private $_gridSpan = NULL; + + /** + * rowspan + * + * @var integer + */ + private $_vMerge = NULL; /** * Create a new Cell Style @@ -233,7 +246,6 @@ class PHPWord_Style_Cell { return $this->_borderTopColor; } - public function setBorderLeftSize($pValue = null) { $this->_borderLeftSize = $pValue; } @@ -249,8 +261,7 @@ class PHPWord_Style_Cell { public function getBorderLeftColor() { return $this->_borderLeftColor; } - - + public function setBorderRightSize($pValue = null) { $this->_borderRightSize = $pValue; } @@ -287,5 +298,21 @@ class PHPWord_Style_Cell { public function getDefaultBorderColor() { return $this->_defaultBorderColor; } + + public function setGridSpan($pValue = null) { + $this->_gridSpan = $pValue; + } + + public function getGridSpan() { + return $this->_gridSpan; + } + + public function setVMerge($pValue = null) { + $this->_vMerge = $pValue; + } + + public function getVMerge() { + return $this->_vMerge; + } } ?> \ No newline at end of file diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index c03342ea..3800148e 100644 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -586,6 +586,19 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart { $objWriter->endElement(); } } + $gridSpan = $style->getGridSpan(); + if(!is_null($gridSpan)) { + $objWriter->startElement('w:gridSpan'); + $objWriter->writeAttribute('w:val', $gridSpan); + $objWriter->endElement(); + } + + $vMerge = $style->getVMerge(); + if(!is_null($vMerge)) { + $objWriter->startElement('w:vMerge'); + $objWriter->writeAttribute('w:val', $vMerge); + $objWriter->endElement(); + } } protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, $image) { diff --git a/changelog.txt b/changelog.txt index 028aea1c..fa976217 100644 --- a/changelog.txt +++ b/changelog.txt @@ -26,6 +26,7 @@ Fixed in branch for release 0.7 : - Bugfix: (RomanSyroeshko) GH-34 - PHPWord_Shared_String.IsUTF8 returns FALSE for Cyrillic UTF-8 input - Feature: (Progi1984) GH-1 - Implement RTF Writer - Feature: (Progi1984) GH-2 - Implement ODT Writer +- Feature: (kaystrobach) - Word2007 : Add rowspan and colspan to cells - General: (MarkBaker) - Add superscript/subscript styling in Excel2007 Writer - General: (deds) - add indentation support to paragraphs - General: (Progi1984) GH-27 - Support for Composer From 38a15e5da5865d52f807d4f3dab0e6ebccb60725 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Sun, 15 Dec 2013 14:35:18 +0100 Subject: [PATCH 07/12] Word2007 : Support for tab stops --- .gitignore | 3 +- Classes/PHPWord/Style/Paragraph.php | 33 +++-- Classes/PHPWord/Style/Tab.php | 147 +++++++++++++++++++++++ Classes/PHPWord/Style/Tabs.php | 67 +++++++++++ Classes/PHPWord/Writer/Word2007/Base.php | 46 +++---- changelog.txt | 1 + composer.json | 2 +- samples/Sample_02_TabStops.php | 64 ++++++++++ samples/old/Image.php | 2 +- samples/old/{_earth.JPG => _earth.jpg} | Bin 10 files changed, 332 insertions(+), 33 deletions(-) create mode 100644 Classes/PHPWord/Style/Tab.php create mode 100644 Classes/PHPWord/Style/Tabs.php create mode 100644 samples/Sample_02_TabStops.php rename samples/old/{_earth.JPG => _earth.jpg} (100%) diff --git a/.gitignore b/.gitignore index 4abb8c94..edbe05c7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ *.odt *.docx *.rtf -*.txt \ No newline at end of file +*.txt +*.xml diff --git a/Classes/PHPWord/Style/Paragraph.php b/Classes/PHPWord/Style/Paragraph.php index 9c841c7c..937d8650 100644 --- a/Classes/PHPWord/Style/Paragraph.php +++ b/Classes/PHPWord/Style/Paragraph.php @@ -62,8 +62,14 @@ class PHPWord_Style_Paragraph { * @var int */ private $_spacing; - - + + /** + * Set of Custom Tab Stops + * + * @var array + */ + private $_tabs; + /** * Indent by how much * @@ -80,6 +86,7 @@ class PHPWord_Style_Paragraph { $this->_spaceBefore = null; $this->_spaceAfter = null; $this->_spacing = null; + $this->_tabs = null; $this->_indent = null; } @@ -90,13 +97,16 @@ class PHPWord_Style_Paragraph { * @param mixed $value */ public function setStyleValue($key, $value) { - if($key == '_spacing') { - $value += 240; // because line height of 1 matches 240 twips - } if($key == '_indent') { - $value = (int)$value * 720; // 720 twips per indent + $value = (int)$value * 720; // 720 twips per indent } - $this->$key = $value; + if($key == '_spacing') { + $value += 240; // because line height of 1 matches 240 twips + } + if($key === '_tabs') { + $value = new PHPWord_Style_Tabs($value); + } + $this->$key = $value; } /** @@ -202,5 +212,14 @@ class PHPWord_Style_Paragraph { $this->_indent = $pValue; return $this; } + + /** + * Get tabs + * + * @return PHPWord_Style_Tabs + */ + public function getTabs() { + return $this->_tabs; + } } ?> \ No newline at end of file diff --git a/Classes/PHPWord/Style/Tab.php b/Classes/PHPWord/Style/Tab.php new file mode 100644 index 00000000..cd0882c1 --- /dev/null +++ b/Classes/PHPWord/Style/Tab.php @@ -0,0 +1,147 @@ +_val = (self::isStopType($val)) ? $val : 'clear'; + + // Default to 0 if the position is non-numeric + $this->_position = (is_numeric($position)) ? intval($position) : 0; + + // Default to NULL if no tab leader + $this->_leader = (self::isLeaderType($leader)) ? $leader : NULL; + } + + /** + * Creates the XML DOM for the instance of PHPWord_Style_Tab. + * + * @param PHPWord_Shared_XMLWriter $objWriter + */ + public function toXml(PHPWord_Shared_XMLWriter &$objWriter = NULL) { + if(isset($objWriter)) { + $objWriter->startElement("w:tab"); + $objWriter->writeAttribute("w:val", $this->_val); + if(!is_null($this->_leader)) { + $objWriter->writeAttribute("w:leader", $this->_leader); + } + $objWriter->writeAttribute("w:pos", $this->_position); + $objWriter->endElement(); + } + } + + /** + * Test if attribute is a valid stop type. + * + * @param string $attribute + * @return bool True if it is; false otherwise. + */ + private static function isStopType($attribute) { + return in_array($attribute, self::$_possibleStopTypes); + } + + /** + * Test if attribute is a valid leader type. + * + * @param string $attribute + * @return bool True if it is; false otherwise. + */ + private static function isLeaderType($attribute) { + return in_array($attribute, self::$_possibleLeaders); + } +} +?> \ No newline at end of file diff --git a/Classes/PHPWord/Style/Tabs.php b/Classes/PHPWord/Style/Tabs.php new file mode 100644 index 00000000..096c0b6f --- /dev/null +++ b/Classes/PHPWord/Style/Tabs.php @@ -0,0 +1,67 @@ +_tabs = $tabs; + } + + /** + * + * @param PHPWord_Shared_XMLWriter $objWriter + */ + public function toXml(PHPWord_Shared_XMLWriter &$objWriter = NULL) { + if(isset($objWriter)) { + $objWriter->startElement("w:tabs"); + foreach ($this->_tabs as &$tab) { + $tab->toXml($objWriter); + } + $objWriter->endElement(); + } + } +} +?> \ No newline at end of file diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index 3800148e..549f1253 100644 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -114,13 +114,12 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart { $spaceAfter = $style->getSpaceAfter(); $spacing = $style->getSpacing(); $indent = $style->getIndent(); - + $tabs = $style->getTabs(); - if(!is_null($align) || !is_null($spacing) || !is_null($spaceBefore) || !is_null($spaceAfter) || !is_null($indent)) { - - if(!$withoutPPR) { - $objWriter->startElement('w:pPr'); - } + if(!is_null($align) || !is_null($spacing) || !is_null($spaceBefore) || !is_null($spaceAfter) || !is_null($indent) || !is_null($tabs)) { + if(!$withoutPPR) { + $objWriter->startElement('w:pPr'); + } if(!is_null($align)) { $objWriter->startElement('w:jc'); @@ -136,26 +135,27 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart { } if(!is_null($spaceBefore) || !is_null($spaceAfter) || !is_null($spacing)) { - $objWriter->startElement('w:spacing'); - - if(!is_null($spaceBefore)) { - $objWriter->writeAttribute('w:before', $spaceBefore); - } - if(!is_null($spaceAfter)) { - $objWriter->writeAttribute('w:after', $spaceAfter); - } - if(!is_null($spacing)) { - $objWriter->writeAttribute('w:line', $spacing); - $objWriter->writeAttribute('w:lineRule', 'auto'); - } - + if(!is_null($spaceBefore)) { + $objWriter->writeAttribute('w:before', $spaceBefore); + } + if(!is_null($spaceAfter)) { + $objWriter->writeAttribute('w:after', $spaceAfter); + } + if(!is_null($spacing)) { + $objWriter->writeAttribute('w:line', $spacing); + $objWriter->writeAttribute('w:lineRule', 'auto'); + } $objWriter->endElement(); } - - if(!$withoutPPR) { - $objWriter->endElement(); // w:pPr - } + + if(!is_null($tabs)) { + $tabs->toXml($objWriter); + } + + if(!$withoutPPR) { + $objWriter->endElement(); // w:pPr + } } } diff --git a/changelog.txt b/changelog.txt index fa976217..d614ffaf 100644 --- a/changelog.txt +++ b/changelog.txt @@ -27,6 +27,7 @@ Fixed in branch for release 0.7 : - Feature: (Progi1984) GH-1 - Implement RTF Writer - Feature: (Progi1984) GH-2 - Implement ODT Writer - Feature: (kaystrobach) - Word2007 : Add rowspan and colspan to cells +- Feature: (RLovelett) - Word2007 : Support for tab stops - General: (MarkBaker) - Add superscript/subscript styling in Excel2007 Writer - General: (deds) - add indentation support to paragraphs - General: (Progi1984) GH-27 - Support for Composer diff --git a/composer.json b/composer.json index 28060794..0d714310 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ ], "require": { - "php": ">=5.2.0", + "php": ">=5.3.0", "ext-xml": "*" }, "recommend": { diff --git a/samples/Sample_02_TabStops.php b/samples/Sample_02_TabStops.php new file mode 100644 index 00000000..3c4d3841 --- /dev/null +++ b/samples/Sample_02_TabStops.php @@ -0,0 +1,64 @@ +'); +} + +require_once '../Classes/PHPWord.php'; + +// New Word Document +echo date('H:i:s') , ' Create new PHPWord object' , EOL; +$PHPWord = new PHPWord(); + +// Ads styles +$PHPWord->addParagraphStyle('multipleTab', array( + 'tabs' => array( + new PHPWord_Style_Tab('left', 1550), + new PHPWord_Style_Tab('center', 3200), + new PHPWord_Style_Tab('right', 5300) + ) +)); +$PHPWord->addParagraphStyle('rightTab', array( + 'tabs' => array( + new PHPWord_Style_Tab('right', 9090) + ) +)); +$PHPWord->addParagraphStyle('centerTab', array( + 'tabs' => array( + new PHPWord_Style_Tab('center', 4680) + ) +)); + +// New portrait section +$section = $PHPWord->createSection(); + +// Add listitem elements +$section->addText("Multiple Tabs:\tOne\tTwo\tThree", NULL, 'multipleTab'); +$section->addText("Left Aligned\tRight Aligned", NULL, 'rightTab'); +$section->addText("\tCenter Aligned", NULL, 'centerTab'); + +// Save File +echo date('H:i:s') , ' Write to Word2007 format' , EOL; +$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save(str_replace('.php', '.docx', __FILE__)); + +echo date('H:i:s') , ' Write to OpenDocumentText format' , EOL; +$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText'); +$objWriter->save(str_replace('.php', '.odt', __FILE__)); + +echo date('H:i:s') , ' Write to RTF format' , EOL; +$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF'); +$objWriter->save(str_replace('.php', '.rtf', __FILE__)); + + +// Echo memory peak usage +echo date('H:i:s') , ' Peak memory usage: ' , (memory_get_peak_usage(true) / 1024 / 1024) , ' MB' , EOL; + +// Echo done +echo date('H:i:s') , ' Done writing file' , EOL; +?> \ No newline at end of file diff --git a/samples/old/Image.php b/samples/old/Image.php index 71d0a7f2..6316783f 100644 --- a/samples/old/Image.php +++ b/samples/old/Image.php @@ -11,7 +11,7 @@ $section = $PHPWord->createSection(); $section->addImage('_mars.jpg'); $section->addTextBreak(2); -$section->addImage('_earth.JPG', array('width'=>210, 'height'=>210, 'align'=>'center')); +$section->addImage('_earth.jpg', array('width'=>210, 'height'=>210, 'align'=>'center')); $section->addTextBreak(2); $section->addImage('_mars.jpg', array('width'=>100, 'height'=>100, 'align'=>'right')); diff --git a/samples/old/_earth.JPG b/samples/old/_earth.jpg similarity index 100% rename from samples/old/_earth.JPG rename to samples/old/_earth.jpg From 049c89d0790e14186877997c4aaaee1e9cab8633 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Sun, 15 Dec 2013 14:46:05 +0100 Subject: [PATCH 08/12] IMPROVED : Advanced string replace in setValue for Template --- Classes/PHPWord/Template.php | 10 ++++++++++ changelog.txt | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Classes/PHPWord/Template.php b/Classes/PHPWord/Template.php index bbc3197f..dedc8f9c 100644 --- a/Classes/PHPWord/Template.php +++ b/Classes/PHPWord/Template.php @@ -84,6 +84,14 @@ class PHPWord_Template { * @param mixed $replace */ public function setValue($search, $replace) { + $pattern = '|\$\{([^\}]+)\}|U'; + preg_match_all($pattern, $this->_documentXML, $matches); + foreach ($matches[0] as $value) { + $valueCleaned = preg_replace('/<[^>]+>/', '', $value); + $valueCleaned = preg_replace('/<\/[^>]+>/', '', $valueCleaned); + $this->_documentXML = str_replace($value, $valueCleaned, $this->_documentXML); + } + if(substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') { $search = '${'.$search.'}'; } @@ -96,6 +104,7 @@ class PHPWord_Template { $this->_documentXML = str_replace($search, $replace, $this->_documentXML); } + /** * Returns array of all variables in template */ @@ -104,6 +113,7 @@ class PHPWord_Template { preg_match_all('/\$\{(.*?)}/i', $this->_documentXML, $matches); return $matches[1]; } + /** * Save Template * diff --git a/changelog.txt b/changelog.txt index d614ffaf..4b0e6edc 100644 --- a/changelog.txt +++ b/changelog.txt @@ -33,4 +33,5 @@ Fixed in branch for release 0.7 : - General: (Progi1984) GH-27 - Support for Composer - General: (Progi1984) - Basic CI with Travis - General: (Progi1984) - Added PHPWord_Exception and exception when could not copy the template -- General: (Progi1984) - IMPROVED : Moved examples out of Classes directory \ No newline at end of file +- General: (Progi1984) - IMPROVED : Moved examples out of Classes directory +- General: (Esmeraldo) CP-49 - IMPROVED : Advanced string replace in setValue for Template \ No newline at end of file From 9557dd9da8681379ba960c4ebc9fdf20621de482 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Sun, 15 Dec 2013 14:50:08 +0100 Subject: [PATCH 09/12] FIXED : "Warning: Invalid error type specified in ...\PHPWord.php on line 226" is thrown when the specified template file is not found GH-32 --- Classes/PHPWord.php | 2 +- Classes/PHPWord/Section/Footer.php | 2 +- Classes/PHPWord/Section/Header.php | 4 ++-- changelog.txt | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Classes/PHPWord.php b/Classes/PHPWord.php index cf160233..d17a2f6c 100644 --- a/Classes/PHPWord.php +++ b/Classes/PHPWord.php @@ -223,7 +223,7 @@ class PHPWord { $template = new PHPWord_Template($strFilename); return $template; } else { - trigger_error('Template file '.$strFilename.' not found.', E_ERROR); + trigger_error('Template file '.$strFilename.' not found.', E_USER_ERROR); } } } diff --git a/Classes/PHPWord/Section/Footer.php b/Classes/PHPWord/Section/Footer.php index 39115097..e54d1ea5 100644 --- a/Classes/PHPWord/Section/Footer.php +++ b/Classes/PHPWord/Section/Footer.php @@ -131,7 +131,7 @@ class PHPWord_Section_Footer { $this->_elementCollection[] = $image; return $image; } else { - trigger_error('Src does not exist or invalid image type.', E_ERROR); + trigger_error('Src does not exist or invalid image type.', E_USER_ERROR); } } diff --git a/Classes/PHPWord/Section/Header.php b/Classes/PHPWord/Section/Header.php index 6734047e..2d7af5c1 100644 --- a/Classes/PHPWord/Section/Header.php +++ b/Classes/PHPWord/Section/Header.php @@ -131,7 +131,7 @@ class PHPWord_Section_Header { $this->_elementCollection[] = $image; return $image; } else { - trigger_error('Src does not exist or invalid image type.', E_ERROR); + trigger_error('Src does not exist or invalid image type.', E_USER_ERROR); } } @@ -189,7 +189,7 @@ class PHPWord_Section_Header { $this->_elementCollection[] = $image; return $image; } else { - trigger_error('Src does not exist or invalid image type.', E_ERROR); + trigger_error('Src does not exist or invalid image type.', E_USER_ERROR); } } diff --git a/changelog.txt b/changelog.txt index 4b0e6edc..3f6f9444 100644 --- a/changelog.txt +++ b/changelog.txt @@ -24,6 +24,7 @@ Fixed in branch for release 0.7 : - Bugfix: (RomanSyroeshko) GH-34 - PHPWord_Shared_String.IsUTF8 returns FALSE for Cyrillic UTF-8 input +- Bugfix: (RomanSyroeshko) GH-32 - "Warning: Invalid error type specified in ...\PHPWord.php on line 226" is thrown when the specified template file is not found - Feature: (Progi1984) GH-1 - Implement RTF Writer - Feature: (Progi1984) GH-2 - Implement ODT Writer - Feature: (kaystrobach) - Word2007 : Add rowspan and colspan to cells From 95f16cc3a5ab2a8a8247cff47848f7110952d715 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Sun, 15 Dec 2013 14:58:44 +0100 Subject: [PATCH 10/12] Temporary files naming logic in PHPWord_Template can lead to a collision (GH-38) --- Classes/PHPWord/Template.php | 22 ++++++++++++---------- changelog.txt | 3 ++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Classes/PHPWord/Template.php b/Classes/PHPWord/Template.php index dedc8f9c..1d2765d0 100644 --- a/Classes/PHPWord/Template.php +++ b/Classes/PHPWord/Template.php @@ -63,18 +63,20 @@ class PHPWord_Template { * @param string $strFilename */ public function __construct($strFilename) { - $path = dirname($strFilename); - $this->_tempFileName = $path.DIRECTORY_SEPARATOR.time().'.docx'; + $this->_tempFileName = tempnam(sys_get_temp_dir(), ''); + if ($this->_tempFileName !== false) { + // Copy the source File to the temp File + if(!copy($strFilename, $this->_tempFileName)){ + throw new PHPWord_Exception('Could not copy the template from '.$strFilename.' to '.$this->_tempFileName.'.'); + } - // Copy the source File to the temp File - if(!copy($strFilename, $this->_tempFileName)){ - throw new PHPWord_Exception('Could not copy the template from '.$strFilename.' to '.$this->_tempFileName.'.'); + $this->_objZip = new ZipArchive(); + $this->_objZip->open($this->_tempFileName); + + $this->_documentXML = $this->_objZip->getFromName('word/document.xml'); + } else { + throw new PHPWord_Exception('Could not create temporary file with unique name in the default temporary directory.'); } - - $this->_objZip = new ZipArchive(); - $this->_objZip->open($this->_tempFileName); - - $this->_documentXML = $this->_objZip->getFromName('word/document.xml'); } /** diff --git a/changelog.txt b/changelog.txt index 3f6f9444..c09bd6d0 100644 --- a/changelog.txt +++ b/changelog.txt @@ -23,8 +23,9 @@ ************************************************************************************** Fixed in branch for release 0.7 : -- Bugfix: (RomanSyroeshko) GH-34 - PHPWord_Shared_String.IsUTF8 returns FALSE for Cyrillic UTF-8 input - Bugfix: (RomanSyroeshko) GH-32 - "Warning: Invalid error type specified in ...\PHPWord.php on line 226" is thrown when the specified template file is not found +- Bugfix: (RomanSyroeshko) GH-34 - PHPWord_Shared_String.IsUTF8 returns FALSE for Cyrillic UTF-8 input +- Bugfix: (RomanSyroeshko) GH-38 - Temporary files naming logic in PHPWord_Template can lead to a collision - Feature: (Progi1984) GH-1 - Implement RTF Writer - Feature: (Progi1984) GH-2 - Implement ODT Writer - Feature: (kaystrobach) - Word2007 : Add rowspan and colspan to cells From 4fb18005ceaa4a11e524a6d34c3c4df6df039c09 Mon Sep 17 00:00:00 2001 From: Ryan Lovelett Date: Thu, 8 Nov 2012 17:14:15 -0600 Subject: [PATCH 11/12] Sections can support multiple headers Each section can now have a single header (previous behavior). It can now also support multiple headers. The spec defines three types of headers: default, first, and even. These code changes provide support for all three. The HeaderFooter.php example has also been updated to illustrate how to use the new multiple headers for a section. Used these pages as spec reference: http://www.schemacentral.com/sc/ooxml/e-w_headerReference-1.html http://www.schemacentral.com/sc/ooxml/a-w_type-4.html --- Classes/PHPWord/Section.php | 32 ++++++++--- Classes/PHPWord/Section/Header.php | 58 ++++++++++++++++++++ Classes/PHPWord/Writer/Word2007.php | 7 +-- Classes/PHPWord/Writer/Word2007/Document.php | 11 +++- samples/old/HeaderFooter.php | 31 ++++++++++- 5 files changed, 123 insertions(+), 16 deletions(-) diff --git a/Classes/PHPWord/Section.php b/Classes/PHPWord/Section.php index d1106d8a..d5f5618d 100644 --- a/Classes/PHPWord/Section.php +++ b/Classes/PHPWord/Section.php @@ -57,11 +57,11 @@ class PHPWord_Section { private $_elementCollection = array(); /** - * Section Header + * Section Headers * - * @var PHPWord_Section_Header + * @var array */ - private $_header = null; + private $_headers = array(); /** * Section Footer @@ -345,17 +345,33 @@ class PHPWord_Section { */ public function createHeader() { $header = new PHPWord_Section_Header($this->_sectionCount); - $this->_header = $header; + $this->_headers[] = $header; return $header; } /** - * Get Header + * Get Headers * - * @return PHPWord_Section_Header + * @return array */ - public function getHeader() { - return $this->_header; + public function getHeaders() { + return $this->_headers; + } + + /** + * Is there a header for this section that is for the first page only? + * + * If any of the PHPWord_Section_Header instances have a type of + * PHPWord_Section_Header::FIRST then this method returns true. False + * otherwise. + * + * @return Boolean + */ + public function hasDifferentFirstPage() { + $value = array_filter($this->_headers, function(PHPWord_Section_Header &$header) { + return $header->getType() == PHPWord_Section_Header::FIRST; + }); + return count($value) > 0; } /** diff --git a/Classes/PHPWord/Section/Header.php b/Classes/PHPWord/Section/Header.php index 2d7af5c1..65ad3971 100644 --- a/Classes/PHPWord/Section/Header.php +++ b/Classes/PHPWord/Section/Header.php @@ -48,6 +48,35 @@ class PHPWord_Section_Header { * @var int */ private $_rId; + + /** + * Header type + * + * @var string + * @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type + */ + private $_type = PHPWord_Section_Header::AUTO; + + /** + * Even Numbered Pages Only + * @var string + * @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type + */ + const EVEN = 'even'; + + /** + * Default Header or Footer + * @var string + * @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type + */ + const AUTO = 'default'; // Did not use DEFAULT because it is a PHP keyword + + /** + * First Page Only + * @var string + * @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type + */ + const FIRST = 'first'; /** * Header Element Collection @@ -222,5 +251,34 @@ class PHPWord_Section_Header { public function getHeaderCount() { return $this->_headerCount; } + + /** + * Get Header Type + */ + public function getType() { + return $this->_type; + } + + /** + * Reset back to default + */ + public function resetType() { + return $this->_type = PHPWord_Section_Header::AUTO; + } + + /** + * First page only header + */ + public function firstPage() { + return $this->_type = PHPWord_Section_Header::FIRST; + } + + /** + * Even numbered Pages only + */ + public function evenPage() { + return $this->_type = PHPWord_Section_Header::EVEN; + } + } ?> diff --git a/Classes/PHPWord/Writer/Word2007.php b/Classes/PHPWord/Writer/Word2007.php index 0ad491dd..c9bf9870 100644 --- a/Classes/PHPWord/Writer/Word2007.php +++ b/Classes/PHPWord/Writer/Word2007.php @@ -114,12 +114,11 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter { $_sections = $this->_document->getSections(); foreach($_sections as $section) { - $_header = $section->getHeader(); - if(!is_null($_header)) { + $_headers = $section->getHeaders(); + foreach ($_headers as $index => &$_header) { $_cHdrs++; $_header->setRelationId(++$rID); - $_headerCount = $_header->getHeaderCount(); - $_headerFile = 'header'.$_headerCount.'.xml'; + $_headerFile = 'header'.$_cHdrs.'.xml'; $sectionElements[] = array('target'=>$_headerFile, 'type'=>'header', 'rID'=>$rID); $objZip->addFromString('word/'.$_headerFile, $this->getWriterPart('header')->writeHeader($_header)); } diff --git a/Classes/PHPWord/Writer/Word2007/Document.php b/Classes/PHPWord/Writer/Word2007/Document.php index b07e2698..4543aeae 100644 --- a/Classes/PHPWord/Writer/Word2007/Document.php +++ b/Classes/PHPWord/Writer/Word2007/Document.php @@ -117,7 +117,7 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base { private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section) { $_settings = $section->getSettings(); - $_header = $section->getHeader(); + $_headers = $section->getHeaders(); $_footer = $section->getFooter(); $pgSzW = $_settings->getPageSizeW(); $pgSzH = $_settings->getPageSizeH(); @@ -132,14 +132,19 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base { $objWriter->startElement('w:sectPr'); - if(!is_null($_header)) { + foreach ($_headers as &$_header) { $rId = $_header->getRelationId(); $objWriter->startElement('w:headerReference'); - $objWriter->writeAttribute('w:type', 'default'); + $objWriter->writeAttribute('w:type', $_header->getType()); $objWriter->writeAttribute('r:id', 'rId'.$rId); $objWriter->endElement(); } + if($section->hasDifferentFirstPage()) { + $objWriter->startElement('w:titlePg'); + $objWriter->endElement(); + } + if(!is_null($_footer)) { $rId = $_footer->getRelationId(); $objWriter->startElement('w:footerReference'); diff --git a/samples/old/HeaderFooter.php b/samples/old/HeaderFooter.php index 63298a05..addb3d8d 100644 --- a/samples/old/HeaderFooter.php +++ b/samples/old/HeaderFooter.php @@ -7,13 +7,18 @@ $PHPWord = new PHPWord(); // New portrait section $section = $PHPWord->createSection(); -// Add header +// Add first page header $header = $section->createHeader(); +$header->firstPage(); $table = $header->addTable(); $table->addRow(); $table->addCell(4500)->addText('This is the header.'); $table->addCell(4500)->addImage('_earth.jpg', array('width'=>50, 'height'=>50, 'align'=>'right')); +// Add header for all other pages +$subsequent = $section->createHeader(); +$subsequent->addText("Subsequent pages in Section 1 will Have this!"); + // Add footer $footer = $section->createFooter(); $footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', array('align'=>'center')); @@ -22,6 +27,30 @@ $footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', array('align'=>'center')) $section->addTextBreak(); $section->addText('Some text...'); +// Create a second page +$section->addPageBreak(); + +// Write some text +$section->addTextBreak(); +$section->addText('Some text...'); + +// Create a third page +$section->addPageBreak(); + +// Write some text +$section->addTextBreak(); +$section->addText('Some text...'); + +// New portrait section +$section2 = $PHPWord->createSection(); + +$sec2Header = $section2->createHeader(); +$sec2Header->addText("All pages in Section 2 will Have this!"); + +// Write some text +$section2->addTextBreak(); +$section2->addText('Some text...'); + // Save File $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter->save('HeaderFooter.docx'); From fa7de9c977a495718cdc7c5387f388a6d4e18519 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Sun, 15 Dec 2013 15:54:09 +0100 Subject: [PATCH 12/12] Word2007 : Support Multiple headers --- changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.txt b/changelog.txt index c09bd6d0..9a8170d0 100644 --- a/changelog.txt +++ b/changelog.txt @@ -30,6 +30,7 @@ Fixed in branch for release 0.7 : - Feature: (Progi1984) GH-2 - Implement ODT Writer - Feature: (kaystrobach) - Word2007 : Add rowspan and colspan to cells - Feature: (RLovelett) - Word2007 : Support for tab stops +- Feature: (RLovelett) - Word2007 : Support Multiple headers - General: (MarkBaker) - Add superscript/subscript styling in Excel2007 Writer - General: (deds) - add indentation support to paragraphs - General: (Progi1984) GH-27 - Support for Composer