Skip to content

Commit b419d64

Browse files
committed
Change Application DocProps to "PHPWord"
1 parent 52b3506 commit b419d64

File tree

2 files changed

+15
-98
lines changed

2 files changed

+15
-98
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ This release marked heavy refactorings on internal code structure with the creat
3434
- Image: Keep image aspect ratio if only 1 dimension styled - @japonicus GH-194
3535
- HTML Writer: Basic HTML writer: text, textrun, link, title, textbreak, table, image (as Base64), footnote, endnote - @ivanlanin GH-203 GH-67 GH-147
3636
- PDF Writer: Basic PDF writer using DomPDF: All HTML element except image - @ivanlanin GH-68
37+
- DOCX Writer: Change `docProps/app.xml` `Application` to `PHPWord` - @ivanlanin
3738

3839
### Bugfixes
3940

4041
- Footnote: Footnote content doesn't show footnote reference number - @ivanlanin GH-170
41-
- Documentation : Error in a fonction - @theBeerNut GH-195
42+
- Documentation: Error in a function - @theBeerNut GH-195
4243

4344
### Deprecated
4445

src/PhpWord/Writer/Word2007/DocProps.php

Lines changed: 13 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use PhpOffice\PhpWord\PhpWord;
1313

1414
/**
15-
* Word2007 contenttypes part writer
15+
* Word2007 document properties part writer
1616
*/
1717
class DocProps extends AbstractWriterPart
1818
{
@@ -24,88 +24,19 @@ public function writeDocPropsApp(PhpWord $phpWord = null)
2424
if (is_null($phpWord)) {
2525
throw new Exception("No PhpWord assigned.");
2626
}
27-
28-
// Create XML writer
2927
$xmlWriter = $this->getXmlWriter();
3028

31-
// XML header
3229
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
33-
34-
// Properties
3530
$xmlWriter->startElement('Properties');
3631
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties');
3732
$xmlWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
3833

39-
// Application
40-
$xmlWriter->writeElement('Application', 'Microsoft Office Word');
41-
42-
// ScaleCrop
43-
$xmlWriter->writeElement('ScaleCrop', 'false');
44-
45-
// HeadingPairs
46-
$xmlWriter->startElement('HeadingPairs');
47-
48-
// Vector
49-
$xmlWriter->startElement('vt:vector');
50-
$xmlWriter->writeAttribute('size', '4');
51-
$xmlWriter->writeAttribute('baseType', 'variant');
52-
53-
// Variant
54-
$xmlWriter->startElement('vt:variant');
55-
$xmlWriter->writeElement('vt:lpstr', 'Theme');
56-
$xmlWriter->endElement();
57-
58-
// Variant
59-
$xmlWriter->startElement('vt:variant');
60-
$xmlWriter->writeElement('vt:i4', '1');
61-
$xmlWriter->endElement();
62-
63-
// Variant
64-
$xmlWriter->startElement('vt:variant');
65-
$xmlWriter->writeElement('vt:lpstr', 'Slide Titles');
66-
$xmlWriter->endElement();
67-
68-
// Variant
69-
$xmlWriter->startElement('vt:variant');
70-
$xmlWriter->writeElement('vt:i4', '1');
71-
$xmlWriter->endElement();
72-
73-
$xmlWriter->endElement();
74-
75-
$xmlWriter->endElement();
76-
77-
// TitlesOfParts
78-
$xmlWriter->startElement('TitlesOfParts');
79-
80-
// Vector
81-
$xmlWriter->startElement('vt:vector');
82-
$xmlWriter->writeAttribute('size', '1');
83-
$xmlWriter->writeAttribute('baseType', 'lpstr');
84-
85-
$xmlWriter->writeElement('vt:lpstr', 'Office Theme');
86-
87-
$xmlWriter->endElement();
88-
89-
$xmlWriter->endElement();
90-
91-
// Company
34+
$xmlWriter->writeElement('Application', 'PHPWord');
9235
$xmlWriter->writeElement('Company', $phpWord->getDocumentProperties()->getCompany());
36+
$xmlWriter->writeElement('Manager', $phpWord->getDocumentProperties()->getManager());
9337

94-
// LinksUpToDate
95-
$xmlWriter->writeElement('LinksUpToDate', 'false');
96-
97-
// SharedDoc
98-
$xmlWriter->writeElement('SharedDoc', 'false');
38+
$xmlWriter->endElement(); // Properties
9939

100-
// HyperlinksChanged
101-
$xmlWriter->writeElement('HyperlinksChanged', 'false');
102-
103-
// AppVersion
104-
$xmlWriter->writeElement('AppVersion', '12.0000');
105-
106-
$xmlWriter->endElement();
107-
108-
// Return
10940
return $xmlWriter->getData();
11041
}
11142

@@ -117,24 +48,25 @@ public function writeDocPropsApp(PhpWord $phpWord = null)
11748
*/
11849
public function writeDocPropsCore(PhpWord $phpWord)
11950
{
120-
// Create XML writer
51+
if (is_null($phpWord)) {
52+
throw new Exception("No PhpWord assigned.");
53+
}
12154
$xmlWriter = $this->getXmlWriter();
12255

123-
// XML header
12456
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
125-
126-
// cp:coreProperties
12757
$xmlWriter->startElement('cp:coreProperties');
12858
$xmlWriter->writeAttribute('xmlns:cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties');
12959
$xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
13060
$xmlWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/');
13161
$xmlWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/');
13262
$xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
13363

134-
// dc:creator
13564
$xmlWriter->writeElement('dc:creator', $phpWord->getDocumentProperties()->getCreator());
136-
137-
// cp:lastModifiedBy
65+
$xmlWriter->writeElement('dc:title', $phpWord->getDocumentProperties()->getTitle());
66+
$xmlWriter->writeElement('dc:description', $phpWord->getDocumentProperties()->getDescription());
67+
$xmlWriter->writeElement('dc:subject', $phpWord->getDocumentProperties()->getSubject());
68+
$xmlWriter->writeElement('cp:keywords', $phpWord->getDocumentProperties()->getKeywords());
69+
$xmlWriter->writeElement('cp:category', $phpWord->getDocumentProperties()->getCategory());
13870
$xmlWriter->writeElement('cp:lastModifiedBy', $phpWord->getDocumentProperties()->getLastModifiedBy());
13971

14072
// dcterms:created
@@ -149,24 +81,8 @@ public function writeDocPropsCore(PhpWord $phpWord)
14981
$xmlWriter->writeRaw(date(DATE_W3C, $phpWord->getDocumentProperties()->getModified()));
15082
$xmlWriter->endElement();
15183

152-
// dc:title
153-
$xmlWriter->writeElement('dc:title', $phpWord->getDocumentProperties()->getTitle());
154-
155-
// dc:description
156-
$xmlWriter->writeElement('dc:description', $phpWord->getDocumentProperties()->getDescription());
157-
158-
// dc:subject
159-
$xmlWriter->writeElement('dc:subject', $phpWord->getDocumentProperties()->getSubject());
160-
161-
// cp:keywords
162-
$xmlWriter->writeElement('cp:keywords', $phpWord->getDocumentProperties()->getKeywords());
163-
164-
// cp:category
165-
$xmlWriter->writeElement('cp:category', $phpWord->getDocumentProperties()->getCategory());
166-
167-
$xmlWriter->endElement();
84+
$xmlWriter->endElement(); // cp:coreProperties
16885

169-
// Return
17086
return $xmlWriter->getData();
17187
}
17288
}

0 commit comments

Comments
 (0)