|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpPresentation\Writer\PowerPoint2007; |
|
4
|
|
|
|
|
5
|
|
|
use PhpOffice\PhpPresentation\Writer\PowerPoint2007\LayoutPack\PackDefault; |
|
6
|
|
|
use PhpOffice\Common\XMLWriter; |
|
7
|
|
|
|
|
8
|
|
|
class PptTheme extends AbstractDecoratorWriter |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @return \PhpOffice\Common\Adapter\Zip\ZipInterface |
|
12
|
|
|
* @throws \Exception |
|
13
|
|
|
*/ |
|
14
|
97 |
|
public function render() |
|
15
|
|
|
{ |
|
16
|
97 |
|
$oLayoutPack = new PackDefault(); |
|
17
|
|
|
|
|
18
|
97 |
|
$masterSlides = $oLayoutPack->getMasterSlides(); |
|
19
|
97 |
|
foreach ($masterSlides as $masterSlide) { |
|
20
|
|
|
// Add themes to ZIP file |
|
21
|
97 |
|
$this->getZip()->addFromString('ppt/theme/_rels/theme' . $masterSlide['masterid'] . '.xml.rels', $this->writeThemeRelationships($masterSlide['masterid'])); |
|
22
|
97 |
|
$this->getZip()->addFromString('ppt/theme/theme' . $masterSlide['masterid'] . '.xml', $this->writeTheme($masterSlide['masterid'])); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
97 |
|
$otherRelations = $oLayoutPack->getThemeRelations(); |
|
26
|
97 |
|
foreach ($otherRelations as $otherRelation) { |
|
27
|
|
|
if (strpos($otherRelation['target'], 'http://') !== 0) { |
|
28
|
|
|
$this->getZip()->addFromString($this->absoluteZipPath('ppt/theme/' . $otherRelation['target']), $otherRelation['contents']); |
|
29
|
|
|
} |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
97 |
|
return $this->getZip(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Write theme to XML format |
|
38
|
|
|
* |
|
39
|
|
|
* @param int $masterId |
|
40
|
|
|
* @throws \Exception |
|
41
|
|
|
* @return string XML Output |
|
42
|
|
|
*/ |
|
43
|
97 |
|
public function writeTheme($masterId = 1) |
|
44
|
|
|
{ |
|
45
|
97 |
|
$oLayoutPack = new PackDefault(); |
|
46
|
97 |
|
foreach ($oLayoutPack->getThemes() as $theme) { |
|
47
|
97 |
|
if ($theme['masterid'] == $masterId) { |
|
48
|
97 |
|
return $theme['body']; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
throw new \Exception('No theme has been found!'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Write theme relationships to XML format |
|
57
|
|
|
* |
|
58
|
|
|
* @param int $masterId Master slide id |
|
59
|
|
|
* @return string XML Output |
|
60
|
|
|
* @throws \Exception |
|
61
|
|
|
*/ |
|
62
|
97 |
|
public function writeThemeRelationships($masterId = 1) |
|
63
|
|
|
{ |
|
64
|
|
|
// Create XML writer |
|
65
|
97 |
|
$objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); |
|
66
|
|
|
|
|
67
|
|
|
// Layout pack |
|
68
|
97 |
|
$oLayoutPack = new PackDefault(); |
|
69
|
|
|
|
|
70
|
|
|
// XML header |
|
71
|
97 |
|
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|
72
|
|
|
|
|
73
|
|
|
// Relationships |
|
74
|
97 |
|
$objWriter->startElement('Relationships'); |
|
75
|
97 |
|
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); |
|
76
|
|
|
|
|
77
|
|
|
// Other relationships |
|
78
|
97 |
|
$otherRelations = $oLayoutPack->getThemeRelations(); |
|
79
|
97 |
|
foreach ($otherRelations as $otherRelation) { |
|
80
|
|
|
if ($otherRelation['masterid'] == $masterId) { |
|
81
|
|
|
$this->writeRelationship($objWriter, $otherRelation['id'], $otherRelation['type'], $otherRelation['target']); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
97 |
|
$objWriter->endElement(); |
|
86
|
|
|
|
|
87
|
|
|
// Return |
|
88
|
97 |
|
return $objWriter->getData(); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|