|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpPresentation\Writer\PowerPoint2007; |
|
4
|
|
|
|
|
5
|
|
|
use PhpOffice\Common\Drawing as CommonDrawing; |
|
6
|
|
|
use PhpOffice\Common\XMLWriter; |
|
7
|
|
|
use PhpOffice\PhpPresentation\Slide; |
|
8
|
|
|
use PhpOffice\PhpPresentation\Slide\SlideLayout; |
|
9
|
|
|
use PhpOffice\PhpPresentation\Style\ColorMap; |
|
10
|
|
|
|
|
11
|
|
|
class PptSlideLayouts extends AbstractSlide |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @return \PhpOffice\Common\Adapter\Zip\ZipInterface |
|
15
|
|
|
*/ |
|
16
|
95 |
|
public function render() |
|
17
|
|
|
{ |
|
18
|
95 |
|
foreach ($this->oPresentation->getAllMasterSlides() as $oSlideMaster) { |
|
19
|
95 |
|
foreach ($oSlideMaster->getAllSlideLayouts() as &$oSlideLayout) { |
|
|
|
|
|
|
20
|
95 |
|
$this->oZip->addFromString('ppt/slideLayouts/_rels/slideLayout' . $oSlideLayout->layoutNr . '.xml.rels', $this->writeSlideLayoutRelationships($oSlideLayout->layoutNr, $oSlideMaster->getRelsIndex())); |
|
21
|
95 |
|
$this->oZip->addFromString('ppt/slideLayouts/slideLayout' . $oSlideLayout->layoutNr . '.xml', $this->writeSlideLayout($oSlideLayout)); |
|
22
|
|
|
} |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/* |
|
26
|
|
|
foreach ($oLayoutPack->getLayoutRelations() as $otherRelation) { |
|
27
|
|
|
if (strpos($otherRelation['target'], 'http://') === 0) { |
|
28
|
|
|
continue; |
|
29
|
|
|
} |
|
30
|
|
|
$this->oZip->addFromString($this->absoluteZipPath('ppt/slideLayouts/' . $otherRelation['target']), $otherRelation['contents']); |
|
31
|
|
|
} |
|
32
|
|
|
*/ |
|
33
|
|
|
|
|
34
|
95 |
|
return $this->oZip; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Write slide layout relationships to XML format |
|
40
|
|
|
* |
|
41
|
|
|
* @param int $slideLayoutIndex |
|
42
|
|
|
* @param int $masterId |
|
43
|
|
|
* @return string XML Output |
|
44
|
|
|
* @throws \Exception |
|
45
|
|
|
*/ |
|
46
|
95 |
|
public function writeSlideLayoutRelationships($slideLayoutIndex, $masterId = 1) |
|
47
|
|
|
{ |
|
48
|
|
|
// Create XML writer |
|
49
|
95 |
|
$objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); |
|
50
|
|
|
|
|
51
|
|
|
// XML header |
|
52
|
95 |
|
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|
53
|
|
|
|
|
54
|
|
|
// Relationships |
|
55
|
95 |
|
$objWriter->startElement('Relationships'); |
|
56
|
95 |
|
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); |
|
57
|
|
|
|
|
58
|
|
|
// Write slideMaster relationship |
|
59
|
95 |
|
$this->writeRelationship($objWriter, 1, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster', '../slideMasters/slideMaster' . $masterId . '.xml'); |
|
60
|
|
|
|
|
61
|
|
|
// Other relationships |
|
62
|
|
|
//@todo |
|
63
|
|
|
$slideLayoutIndex; |
|
64
|
|
|
/* |
|
65
|
|
|
foreach ($oLayoutPack->getLayoutRelations() as $otherRelation) { |
|
66
|
|
|
if ($otherRelation['layoutId'] == $slideLayoutIndex) { |
|
67
|
|
|
$this->writeRelationship($objWriter, $otherRelation['id'], $otherRelation['type'], $otherRelation['target']); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
*/ |
|
71
|
|
|
|
|
72
|
95 |
|
$objWriter->endElement(); |
|
73
|
|
|
|
|
74
|
|
|
// Return |
|
75
|
95 |
|
return $objWriter->getData(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Write slide to XML format |
|
80
|
|
|
* |
|
81
|
|
|
* @param \PhpOffice\PhpPresentation\Slide\SlideLayout $pSlideLayout |
|
82
|
|
|
* @return string XML Output |
|
83
|
|
|
* @throws \Exception |
|
84
|
|
|
*/ |
|
85
|
95 |
|
public function writeSlideLayout(SlideLayout $pSlideLayout) |
|
86
|
|
|
{ |
|
87
|
|
|
// Create XML writer |
|
88
|
95 |
|
$objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); |
|
89
|
|
|
// XML header |
|
90
|
95 |
|
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|
91
|
|
|
// p:sldLayout |
|
92
|
95 |
|
$objWriter->startElement('p:sldLayout'); |
|
93
|
95 |
|
$objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main'); |
|
94
|
95 |
|
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); |
|
95
|
95 |
|
$objWriter->writeAttribute('xmlns:p', 'http://schemas.openxmlformats.org/presentationml/2006/main'); |
|
96
|
95 |
|
$objWriter->writeAttribute('preserve', 1); |
|
97
|
|
|
// p:sldLayout\p:cSld |
|
98
|
95 |
|
$objWriter->startElement('p:cSld'); |
|
99
|
95 |
|
$objWriter->writeAttributeIf($pSlideLayout->getLayoutName() != '', 'name', $pSlideLayout->getLayoutName()); |
|
100
|
|
|
// Background |
|
101
|
95 |
|
$this->writeSlideBackground($pSlideLayout, $objWriter); |
|
102
|
|
|
// p:sldLayout\p:cSld\p:spTree |
|
103
|
95 |
|
$objWriter->startElement('p:spTree'); |
|
104
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr |
|
105
|
95 |
|
$objWriter->startElement('p:nvGrpSpPr'); |
|
106
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr\p:cNvPr |
|
107
|
95 |
|
$objWriter->startElement('p:cNvPr'); |
|
108
|
95 |
|
$objWriter->writeAttribute('id', '1'); |
|
109
|
95 |
|
$objWriter->writeAttribute('name', ''); |
|
110
|
95 |
|
$objWriter->endElement(); |
|
111
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr\p:cNvGrpSpPr |
|
112
|
95 |
|
$objWriter->writeElement('p:cNvGrpSpPr', null); |
|
113
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr\p:nvPr |
|
114
|
95 |
|
$objWriter->writeElement('p:nvPr', null); |
|
115
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr |
|
116
|
95 |
|
$objWriter->endElement(); |
|
117
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:grpSpPr |
|
118
|
95 |
|
$objWriter->startElement('p:grpSpPr'); |
|
119
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm |
|
120
|
95 |
|
$objWriter->startElement('a:xfrm'); |
|
121
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:off |
|
122
|
95 |
|
$objWriter->startElement('a:off'); |
|
123
|
95 |
|
$objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($pSlideLayout->getOffsetX())); |
|
124
|
95 |
|
$objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($pSlideLayout->getOffsetY())); |
|
125
|
95 |
|
$objWriter->endElement(); |
|
126
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:ext |
|
127
|
95 |
|
$objWriter->startElement('a:ext'); |
|
128
|
95 |
|
$objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($pSlideLayout->getExtentX())); |
|
129
|
95 |
|
$objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($pSlideLayout->getExtentY())); |
|
130
|
95 |
|
$objWriter->endElement(); |
|
131
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:chOff |
|
132
|
95 |
|
$objWriter->startElement('a:chOff'); |
|
133
|
95 |
|
$objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($pSlideLayout->getOffsetX())); |
|
134
|
95 |
|
$objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($pSlideLayout->getOffsetY())); |
|
135
|
95 |
|
$objWriter->endElement(); |
|
136
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:chExt |
|
137
|
95 |
|
$objWriter->startElement('a:chExt'); |
|
138
|
95 |
|
$objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($pSlideLayout->getExtentX())); |
|
139
|
95 |
|
$objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($pSlideLayout->getExtentY())); |
|
140
|
95 |
|
$objWriter->endElement(); |
|
141
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\ |
|
142
|
95 |
|
$objWriter->endElement(); |
|
143
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:grpSpPr\ |
|
144
|
95 |
|
$objWriter->endElement(); |
|
145
|
|
|
// Loop shapes |
|
146
|
95 |
|
$this->writeShapeCollection($objWriter, $pSlideLayout->getShapeCollection()); |
|
147
|
|
|
// p:sldLayout\p:cSld\p:spTree\ |
|
148
|
95 |
|
$objWriter->endElement(); |
|
149
|
|
|
// p:sldLayout\p:cSld\ |
|
150
|
95 |
|
$objWriter->endElement(); |
|
151
|
|
|
|
|
152
|
|
|
// p:sldLayout\p:clrMapOvr |
|
153
|
95 |
|
$objWriter->startElement('p:clrMapOvr'); |
|
154
|
95 |
|
$arrayDiff = array_diff_assoc(ColorMap::$mappingDefault, $pSlideLayout->colorMap->getMapping()); |
|
155
|
95 |
|
if (!empty($arrayDiff)) { |
|
156
|
|
|
// p:sldLayout\p:clrMapOvr\a:overrideClrMapping |
|
157
|
|
|
$objWriter->startElement('a:overrideClrMapping'); |
|
158
|
|
|
foreach ($pSlideLayout->colorMap->getMapping() as $n => $v) { |
|
159
|
|
|
$objWriter->writeAttribute($n, $v); |
|
160
|
|
|
} |
|
161
|
|
|
$objWriter->endElement(); |
|
162
|
|
|
} else { |
|
163
|
|
|
// p:sldLayout\p:clrMapOvr\a:masterClrMapping |
|
164
|
95 |
|
$objWriter->writeElement('a:masterClrMapping'); |
|
165
|
|
|
} |
|
166
|
|
|
// p:sldLayout\p:clrMapOvr\ |
|
167
|
95 |
|
$objWriter->endElement(); |
|
168
|
|
|
|
|
169
|
95 |
|
if (!is_null($pSlideLayout->getTransition())) { |
|
170
|
|
|
$this->writeTransition($objWriter, $pSlideLayout->getTransition()); |
|
|
|
|
|
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
// p:sldLayout\ |
|
174
|
95 |
|
$objWriter->endElement(); |
|
175
|
|
|
|
|
176
|
95 |
|
return $objWriter->getData(); |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|
Let?s assume that you have the following
foreachstatement:$itemValueis assigned by reference. This is possible because the expression (in the example$array) can be used as a reference target.However, if we were to replace
$arraywith something different like the result of a function call as inthen assigning by reference is not possible anymore as there is no target that could be modified.
Available Fixes
1. Do not assign by reference
2. Assign to a local variable first
3. Return a reference