Completed
Pull Request — develop (#304)
by Franck
08:39
created

PowerPoint2007::loadTheme()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 16
cts 16
cp 1
rs 6.9811
c 0
b 0
f 0
cc 7
eloc 15
nc 7
nop 2
crap 7
1
<?php
2
/**
3
 * This file is part of PHPPresentation - A pure PHP library for reading and writing
4
 * presentations documents.
5
 *
6
 * PHPPresentation is free software distributed under the terms of the GNU Lesser
7
 * General Public License version 3 as published by the Free Software Foundation.
8
 *
9
 * For the full copyright and license information, please read the LICENSE
10
 * file that was distributed with this source code. For the full list of
11
 * contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12
 *
13
 * @link        https://github.com/PHPOffice/PHPPresentation
14
 * @copyright   2009-2015 PHPPresentation contributors
15
 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16
 */
17
18
namespace PhpOffice\PhpPresentation\Reader;
19
20
use PhpOffice\PhpPresentation\DocumentLayout;
21
use PhpOffice\PhpPresentation\Shape\RichText\Paragraph;
22
use PhpOffice\PhpPresentation\Slide\AbstractSlide;
23
use PhpOffice\PhpPresentation\Shape\Placeholder;
24
use PhpOffice\PhpPresentation\Slide\Background\Image;
25
use PhpOffice\PhpPresentation\Slide\SlideLayout;
26
use PhpOffice\PhpPresentation\Slide\SlideMaster;
27
use PhpOffice\PhpPresentation\Shape\Drawing\Gd;
28
use PhpOffice\PhpPresentation\Style\SchemeColor;
29
use PhpOffice\PhpPresentation\Style\TextStyle;
30
use ZipArchive;
31
use PhpOffice\Common\XMLReader;
32
use PhpOffice\Common\Drawing as CommonDrawing;
33
use PhpOffice\PhpPresentation\PhpPresentation;
34
use PhpOffice\PhpPresentation\Style\Bullet;
35
use PhpOffice\PhpPresentation\Style\Color;
36
37
/**
38
 * Serialized format reader
39
 */
40
class PowerPoint2007 implements ReaderInterface
41
{
42
    /**
43
     * Output Object
44
     * @var PhpPresentation
45
     */
46
    protected $oPhpPresentation;
47
    /**
48
     * Output Object
49
     * @var \ZipArchive
50
     */
51
    protected $oZip;
52
    /**
53
     * @var array[]
54
     */
55
    protected $arrayRels = array();
56
    /**
57
     * @var SlideLayout[]
58
     */
59
    protected $arraySlideLayouts = array();
60
    /*
61
     * @var string
62
     */
63
    protected $filename;
64
65
    /**
66
     * Can the current \PhpOffice\PhpPresentation\Reader\ReaderInterface read the file?
67
     *
68
     * @param  string $pFilename
69
     * @throws \Exception
70
     * @return boolean
71
     */
72 2
    public function canRead($pFilename)
73
    {
74 2
        return $this->fileSupportsUnserializePhpPresentation($pFilename);
75
    }
76
77
    /**
78
     * Does a file support UnserializePhpPresentation ?
79
     *
80
     * @param  string $pFilename
81
     * @throws \Exception
82
     * @return boolean
83
     */
84 9
    public function fileSupportsUnserializePhpPresentation($pFilename = '')
85
    {
86
        // Check if file exists
87 9
        if (!file_exists($pFilename)) {
88 2
            throw new \Exception("Could not open " . $pFilename . " for reading! File does not exist.");
89
        }
90
91 7
        $oZip = new ZipArchive();
92
        // Is it a zip ?
93 7
        if ($oZip->open($pFilename) === true) {
94
            // Is it an OpenXML Document ?
95
            // Is it a Presentation ?
96 5
            if (is_array($oZip->statName('[Content_Types].xml')) && is_array($oZip->statName('ppt/presentation.xml'))) {
97 5
                return true;
98
            }
99
        }
100 3
        return false;
101
    }
102
103
    /**
104
     * Loads PhpPresentation Serialized file
105
     *
106
     * @param  string $pFilename
107
     * @return \PhpOffice\PhpPresentation\PhpPresentation
108
     * @throws \Exception
109
     */
110 6
    public function load($pFilename)
111
    {
112
        // Unserialize... First make sure the file supports it!
113 6
        if (!$this->fileSupportsUnserializePhpPresentation($pFilename)) {
114 1
            throw new \Exception("Invalid file format for PhpOffice\PhpPresentation\Reader\PowerPoint2007: " . $pFilename . ".");
115
        }
116
117 4
        return $this->loadFile($pFilename);
118
    }
119
120
    /**
121
     * Load PhpPresentation Serialized file
122
     *
123
     * @param  string $pFilename
124
     * @return \PhpOffice\PhpPresentation\PhpPresentation
125
     */
126 4
    protected function loadFile($pFilename)
127
    {
128 4
        $this->oPhpPresentation = new PhpPresentation();
129 4
        $this->oPhpPresentation->removeSlideByIndex();
130 4
        $this->oPhpPresentation->setAllMasterSlides(array());
131 4
        $this->filename = $pFilename;
132
133 4
        $this->oZip = new ZipArchive();
134 4
        $this->oZip->open($this->filename);
135 4
        $docPropsCore = $this->oZip->getFromName('docProps/core.xml');
136 4
        if ($docPropsCore !== false) {
137 4
            $this->loadDocumentProperties($docPropsCore);
138
        }
139
140 4
        $docPropsCustom = $this->oZip->getFromName('docProps/custom.xml');
141 4
        if ($docPropsCustom !== false) {
142 1
            $this->loadCustomProperties($docPropsCustom);
143
        }
144
145 4
        $pptViewProps = $this->oZip->getFromName('ppt/viewProps.xml');
146 4
        if ($pptViewProps !== false) {
147 4
            $this->loadViewProperties($pptViewProps);
148
        }
149
150 4
        $pptPresentation = $this->oZip->getFromName('ppt/presentation.xml');
151 4
        if ($pptPresentation !== false) {
152 4
            $this->loadDocumentLayout($pptPresentation);
153 4
            $this->loadSlides($pptPresentation);
154
        }
155
156 4
        return $this->oPhpPresentation;
157
    }
158
159
    /**
160
     * Read Document Layout
161
     * @param $sPart
162
     */
163 4
    protected function loadDocumentLayout($sPart)
164
    {
165 4
        $xmlReader = new XMLReader();
166 4
        if ($xmlReader->getDomFromString($sPart)) {
167 4
            foreach ($xmlReader->getElements('/p:presentation/p:sldSz') as $oElement) {
168 4
                $type = $oElement->getAttribute('type');
169 4
                $oLayout = $this->oPhpPresentation->getLayout();
170 4
                if ($type == DocumentLayout::LAYOUT_CUSTOM) {
171
                    $oLayout->setCX($oElement->getAttribute('cx'));
172
                    $oLayout->setCY($oElement->getAttribute('cy'));
173
                } else {
174 4
                    $oLayout->setDocumentLayout($type, true);
175 4
                    if ($oElement->getAttribute('cx') < $oElement->getAttribute('cy')) {
176 4
                        $oLayout->setDocumentLayout($type, false);
177
                    }
178
                }
179
            }
180
        }
181 4
    }
182
183
    /**
184
     * Read Document Properties
185
     * @param string $sPart
186
     */
187 4
    protected function loadDocumentProperties($sPart)
188
    {
189 4
        $xmlReader = new XMLReader();
190 4
        if ($xmlReader->getDomFromString($sPart)) {
191
            $arrayProperties = array(
192 4
                '/cp:coreProperties/dc:creator' => 'setCreator',
193
                '/cp:coreProperties/cp:lastModifiedBy' => 'setLastModifiedBy',
194
                '/cp:coreProperties/dc:title' => 'setTitle',
195
                '/cp:coreProperties/dc:description' => 'setDescription',
196
                '/cp:coreProperties/dc:subject' => 'setSubject',
197
                '/cp:coreProperties/cp:keywords' => 'setKeywords',
198
                '/cp:coreProperties/cp:category' => 'setCategory',
199
                '/cp:coreProperties/dcterms:created' => 'setCreated',
200
                '/cp:coreProperties/dcterms:modified' => 'setModified',
201
            );
202 4
            $oProperties = $this->oPhpPresentation->getDocumentProperties();
203 4
            foreach ($arrayProperties as $path => $property) {
204 4
                $oElement = $xmlReader->getElement($path);
205 4
                if ($oElement instanceof \DOMElement) {
206 4
                    if ($oElement->hasAttribute('xsi:type') && $oElement->getAttribute('xsi:type') == 'dcterms:W3CDTF') {
207 4
                        $oDateTime = new \DateTime();
208 4
                        $oDateTime->createFromFormat(\DateTime::W3C, $oElement->nodeValue);
209 4
                        $oProperties->{$property}($oDateTime->getTimestamp());
210
                    } else {
211 4
                        $oProperties->{$property}($oElement->nodeValue);
212
                    }
213
                }
214
            }
215
        }
216 4
    }
217
218
    /**
219
     * Read Custom Properties
220
     * @param string $sPart
221
     */
222 1
    protected function loadCustomProperties($sPart)
223
    {
224 1
        $xmlReader = new XMLReader();
225 1
        $sPart = str_replace(' xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"', '', $sPart);
226 1
        if ($xmlReader->getDomFromString($sPart)) {
227 1
            $pathMarkAsFinal = '/Properties/property[@pid="2"][@fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"][@name="_MarkAsFinal"]/vt:bool';
228 1
            if (is_object($oElement = $xmlReader->getElement($pathMarkAsFinal))) {
229 1
                if ($oElement->nodeValue == 'true') {
230 1
                    $this->oPhpPresentation->getPresentationProperties()->markAsFinal(true);
231
                }
232
            }
233
        }
234 1
    }
235
236
    /**
237
     * Read View Properties
238
     * @param string $sPart
239
     */
240 4
    protected function loadViewProperties($sPart)
241
    {
242 4
        $xmlReader = new XMLReader();
243 4
        if ($xmlReader->getDomFromString($sPart)) {
244 4
            $pathZoom = '/p:viewPr/p:slideViewPr/p:cSldViewPr/p:cViewPr/p:scale/a:sx';
245 4
            $oElement = $xmlReader->getElement($pathZoom);
246 4
            if ($oElement instanceof \DOMElement) {
247 3
                if ($oElement->hasAttribute('d') && $oElement->hasAttribute('n')) {
248 3
                    $this->oPhpPresentation->getPresentationProperties()->setZoom($oElement->getAttribute('n') / $oElement->getAttribute('d'));
249
                }
250
            }
251
        }
252 4
    }
253
254
    /**
255
     * Extract all slides
256
     */
257 4
    protected function loadSlides($sPart)
258
    {
259 4
        $xmlReader = new XMLReader();
260 4
        if ($xmlReader->getDomFromString($sPart)) {
261 4
            $fileRels = 'ppt/_rels/presentation.xml.rels';
262 4
            $this->loadRels($fileRels);
263
            // Load the Masterslides
264 4
            $this->loadMasterSlides($xmlReader, $fileRels);
265
            // Continue with loading the slides
266 4
            foreach ($xmlReader->getElements('/p:presentation/p:sldIdLst/p:sldId') as $oElement) {
267 4
                $rId = $oElement->getAttribute('r:id');
268 4
                $pathSlide = isset($this->arrayRels[$fileRels][$rId]) ? $this->arrayRels[$fileRels][$rId]['Target'] : '';
269 4
                if (!empty($pathSlide)) {
270 4
                    $pptSlide = $this->oZip->getFromName('ppt/' . $pathSlide);
271 4
                    if ($pptSlide !== false) {
272 4
                        $this->loadRels('ppt/slides/_rels/' . basename($pathSlide) . '.rels');
273 4
                        $this->loadSlide($pptSlide, basename($pathSlide));
274
                    }
275
                }
276
            }
277
        }
278 4
    }
279
280
    /**
281
     * Extract all MasterSlides
282
     * @param XMLReader $xmlReader
283
     * @param $fileRels
284
     */
285 4
    protected function loadMasterSlides(XMLReader $xmlReader, $fileRels)
286
    {
287
        // Get all the MasterSlide Id's from the presentation.xml file
288 4
        foreach ($xmlReader->getElements('/p:presentation/p:sldMasterIdLst/p:sldMasterId') as $oElement) {
289 4
            $rId = $oElement->getAttribute('r:id');
290
            // Get the path to the masterslide from the array with _rels files
291 4
            $pathMasterSlide = isset($this->arrayRels[$fileRels][$rId]) ?
292 4
                $this->arrayRels[$fileRels][$rId]['Target'] : '';
293 4
            if (!empty($pathMasterSlide)) {
294 4
                $pptMasterSlide = $this->oZip->getFromName('ppt/' . $pathMasterSlide);
295 4
                if ($pptMasterSlide !== false) {
296 4
                    $this->loadRels('ppt/slideMasters/_rels/' . basename($pathMasterSlide) . '.rels');
297 4
                    $this->loadMasterSlide($pptMasterSlide, basename($pathMasterSlide));
298
                }
299
            }
300
        }
301 4
    }
302
303
    /**
304
     * Extract data from slide
305
     * @param string $sPart
306
     * @param string $baseFile
307
     */
308 4
    protected function loadSlide($sPart, $baseFile)
309
    {
310 4
        $xmlReader = new XMLReader();
311 4
        if ($xmlReader->getDomFromString($sPart)) {
312
            // Core
313 4
            $oSlide = $this->oPhpPresentation->createSlide();
314 4
            $this->oPhpPresentation->setActiveSlideIndex($this->oPhpPresentation->getSlideCount() - 1);
315 4
            $oSlide->setRelsIndex('ppt/slides/_rels/' . $baseFile . '.rels');
316
317
            // Background
318 4
            $oElement = $xmlReader->getElement('/p:sld/p:cSld/p:bg/p:bgPr');
319 4
            if ($oElement instanceof \DOMElement) {
320
                $oElementColor = $xmlReader->getElement('a:solidFill/a:srgbClr', $oElement);
321
                if ($oElementColor instanceof \DOMElement) {
322
                    // Color
323
                    $oColor = new Color();
324
                    $oColor->setRGB($oElementColor->hasAttribute('val') ? $oElementColor->getAttribute('val') : null);
325
                    // Background
326
                    $oBackground = new \PhpOffice\PhpPresentation\Slide\Background\Color();
327
                    $oBackground->setColor($oColor);
328
                    // Slide Background
329
                    $oSlide = $this->oPhpPresentation->getActiveSlide();
330
                    $oSlide->setBackground($oBackground);
331
                }
332
                $oElementImage = $xmlReader->getElement('a:blipFill/a:blip', $oElement);
333
                if ($oElementImage instanceof \DOMElement) {
334
                    $relImg = $this->arrayRels['ppt/slides/_rels/' . $baseFile . '.rels'][$oElementImage->getAttribute('r:embed')];
335
                    if (is_array($relImg)) {
336
                        // File
337
                        $pathImage = 'ppt/slides/' . $relImg['Target'];
338
                        $pathImage = explode('/', $pathImage);
339
                        foreach ($pathImage as $key => $partPath) {
340
                            if ($partPath == '..') {
341
                                unset($pathImage[$key - 1]);
342
                                unset($pathImage[$key]);
343
                            }
344
                        }
345
                        $pathImage = implode('/', $pathImage);
346
                        $contentImg = $this->oZip->getFromName($pathImage);
347
348
                        $tmpBkgImg = tempnam(sys_get_temp_dir(), 'PhpPresentationReaderPpt2007Bkg');
349
                        file_put_contents($tmpBkgImg, $contentImg);
350
                        // Background
351
                        $oBackground = new Image();
352
                        $oBackground->setPath($tmpBkgImg);
353
                        // Slide Background
354
                        $oSlide = $this->oPhpPresentation->getActiveSlide();
355
                        $oSlide->setBackground($oBackground);
356
                    }
357
                }
358
            }
359
360
            // Shapes
361 4
            foreach ($xmlReader->getElements('/p:sld/p:cSld/p:spTree/*') as $oNode) {
362 4
                switch ($oNode->tagName) {
363 4
                    case 'p:pic':
364 3
                        $this->loadShapeDrawing($xmlReader, $oNode, $oSlide);
365 3
                        break;
366 4
                    case 'p:sp':
367 4
                        $this->loadShapeRichText($xmlReader, $oNode, $oSlide);
368 4
                        break;
369 4
                    default:
370
                        //var_export($oNode->tagName);
371
                }
372
            }
373
            // Layout
374 4
            $oSlide = $this->oPhpPresentation->getActiveSlide();
375 4
            foreach ($this->arrayRels['ppt/slides/_rels/' . $baseFile . '.rels'] as $valueRel) {
376 4
                if ($valueRel['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout') {
377 4
                    $layoutBasename = basename($valueRel['Target']);
378 4
                    if (array_key_exists($layoutBasename, $this->arraySlideLayouts)) {
379 4
                        $oSlide->setSlideLayout($this->arraySlideLayouts[$layoutBasename]);
380
                    }
381 4
                    break;
382
                }
383
            }
384
        }
385 4
    }
386
387 4
    private function loadMasterSlide($sPart, $baseFile)
388
    {
389 4
        $xmlReader = new XMLReader();
390 4
        if ($xmlReader->getDomFromString($sPart)) {
391
            // Core
392 4
            $oSlideMaster = $this->oPhpPresentation->createMasterSlide();
393 4
            $oSlideMaster->setTextStyles(new TextStyle(false));
394 4
            $oSlideMaster->setRelsIndex('ppt/slideMasters/_rels/' . $baseFile . '.rels');
395
396
            // Background
397 4
            $oElement = $xmlReader->getElement('/p:sldMaster/p:cSld/p:bg');
398 4
            if ($oElement instanceof \DOMElement) {
399 4
                $this->loadSlideBackground($xmlReader, $oElement, $oSlideMaster);
400
            }
401
402
            // Shapes
403 4
            $arrayElements = $xmlReader->getElements('/p:sldMaster/p:cSld/p:spTree/*');
404 4
            if ($arrayElements) {
405 4
                $this->loadSlideShapes($oSlideMaster, $arrayElements, $xmlReader);
406
            }
407
            // Header & Footer
408
409
            // ColorMapping
410 4
            $colorMap = array();
411 4
            $oElement = $xmlReader->getElement('/p:sldMaster/p:clrMap');
412 4
            if ($oElement->hasAttributes()) {
413 4
                foreach ($oElement->attributes as $attr) {
414 4
                    $colorMap[$attr->nodeName] = $attr->nodeValue;
415
                }
416 4
                $oSlideMaster->colorMap->setMapping($colorMap);
417
            }
418
419
            // TextStyles
420 4
            $arrayElementTxStyles = $xmlReader->getElements('/p:sldMaster/p:txStyles/*');
421 4
            if ($arrayElementTxStyles) {
422 4
                foreach ($arrayElementTxStyles as $oElementTxStyle) {
423 4
                    $arrayElementsLvl = $xmlReader->getElements('/p:sldMaster/p:txStyles/'.$oElementTxStyle->nodeName.'/*');
424 4
                    foreach ($arrayElementsLvl as $oElementLvl) {
425 4
                        if ($oElementLvl->nodeName == 'a:extLst') {
426 1
                            continue;
427
                        }
428 4
                        $oRTParagraph = new Paragraph();
429
430 4
                        if ($oElementLvl->nodeName == 'a:defPPr') {
431 3
                            $level = 0;
432
                        } else {
433 4
                            $level = str_replace('a:lvl', '', $oElementLvl->nodeName);
434 4
                            $level = str_replace('pPr', '', $level);
435
                        }
436
437 4
                        if ($oElementLvl->hasAttribute('algn')) {
438 4
                            $oRTParagraph->getAlignment()->setHorizontal($oElementLvl->getAttribute('algn'));
439
                        }
440 4
                        if ($oElementLvl->hasAttribute('marL')) {
441 4
                            $val = $oElementLvl->getAttribute('marL');
442 4
                            $val = CommonDrawing::emuToPixels($val);
443 4
                            $oRTParagraph->getAlignment()->setMarginLeft($val);
444
                        }
445 4
                        if ($oElementLvl->hasAttribute('marR')) {
446
                            $val = $oElementLvl->getAttribute('marR');
447
                            $val = CommonDrawing::emuToPixels($val);
448
                            $oRTParagraph->getAlignment()->setMarginRight($val);
449
                        }
450 4
                        if ($oElementLvl->hasAttribute('indent')) {
451 4
                            $val = $oElementLvl->getAttribute('indent');
452 4
                            $val = CommonDrawing::emuToPixels($val);
453 4
                            $oRTParagraph->getAlignment()->setIndent($val);
454
                        }
455 4
                        $oElementLvlDefRPR = $xmlReader->getElement('a:defRPr', $oElementLvl);
456 4
                        if ($oElementLvlDefRPR instanceof \DOMElement) {
457 4
                            if ($oElementLvlDefRPR->hasAttribute('sz')) {
458 4
                                $oRTParagraph->getFont()->setSize($oElementLvlDefRPR->getAttribute('sz') / 100);
459
                            }
460 4
                            if ($oElementLvlDefRPR->hasAttribute('b') && $oElementLvlDefRPR->getAttribute('b') == 1) {
461 1
                                $oRTParagraph->getFont()->setBold(true);
462
                            }
463 4
                            if ($oElementLvlDefRPR->hasAttribute('i') && $oElementLvlDefRPR->getAttribute('i') == 1) {
464
                                $oRTParagraph->getFont()->setItalic(true);
465
                            }
466
                        }
467 4
                        $oElementSchemeColor = $xmlReader->getElement('a:defRPr/a:solidFill/a:schemeClr', $oElementLvl);
468 4
                        if ($oElementSchemeColor instanceof \DOMElement) {
469 4
                            if ($oElementSchemeColor->hasAttribute('val')) {
470 4
                                $oSchemeColor = new SchemeColor();
471 4
                                $oSchemeColor->setValue($oElementSchemeColor->getAttribute('val'));
472 4
                                $oRTParagraph->getFont()->setColor($oSchemeColor);
473
                            }
474
                        }
475
476 4
                        switch ($oElementTxStyle->nodeName) {
477 4
                            case 'p:bodyStyle':
478 4
                                $oSlideMaster->getTextStyles()->setBodyStyleAtLvl($oRTParagraph, $level);
479 4
                                break;
480 4
                            case 'p:otherStyle':
481 4
                                $oSlideMaster->getTextStyles()->setOtherStyleAtLvl($oRTParagraph, $level);
482 4
                                break;
483 4
                            case 'p:titleStyle':
484 4
                                $oSlideMaster->getTextStyles()->setTitleStyleAtLvl($oRTParagraph, $level);
485 4
                                break;
486
                        }
487
                    }
488
                }
489
            }
490
491
            // Load the theme
492 4
            foreach ($this->arrayRels[$oSlideMaster->getRelsIndex()] as $arrayRel) {
493 4
                if ($arrayRel['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme') {
494 4
                    $pptTheme = $this->oZip->getFromName('ppt/' . substr($arrayRel['Target'], strrpos($arrayRel['Target'], '../') + 3));
495 4
                    if ($pptTheme !== false) {
496 4
                        $this->loadTheme($pptTheme, $oSlideMaster);
497
                    }
498 4
                    break;
499
                }
500
            }
501
502
            // Load the Layoutslide
503 4
            foreach ($xmlReader->getElements('/p:sldMaster/p:sldLayoutIdLst/p:sldLayoutId') as $oElement) {
504 4
                $rId = $oElement->getAttribute('r:id');
505
                // Get the path to the masterslide from the array with _rels files
506 4
                $pathLayoutSlide = isset($this->arrayRels[$oSlideMaster->getRelsIndex()][$rId]) ?
507 4
                    $this->arrayRels[$oSlideMaster->getRelsIndex()][$rId]['Target'] : '';
508 4
                if (!empty($pathLayoutSlide)) {
509 4
                    $pptLayoutSlide = $this->oZip->getFromName('ppt/' . substr($pathLayoutSlide, strrpos($pathLayoutSlide, '../') + 3));
510 4
                    if ($pptLayoutSlide !== false) {
511 4
                        $this->loadRels('ppt/slideLayouts/_rels/' . basename($pathLayoutSlide) . '.rels');
512 4
                        $oSlideMaster->addSlideLayout(
513 4
                            $this->loadLayoutSlide($pptLayoutSlide, basename($pathLayoutSlide), $oSlideMaster)
514
                        );
515
                    }
516
                }
517
            }
518
        }
519 4
    }
520
521 4
    private function loadLayoutSlide($sPart, $baseFile, SlideMaster $oSlideMaster)
522
    {
523 4
        $xmlReader = new XMLReader();
524 4
        if ($xmlReader->getDomFromString($sPart)) {
525
            // Core
526 4
            $oSlideLayout = new SlideLayout($oSlideMaster);
527 4
            $oSlideLayout->setRelsIndex('ppt/slideLayouts/_rels/' . $baseFile . '.rels');
528
529
            // Name
530 4
            $oElement = $xmlReader->getElement('/p:sldLayout/p:cSld');
531 4
            if ($oElement instanceof \DOMElement && $oElement->hasAttribute('name')) {
532 4
                $oSlideLayout->setLayoutName($oElement->getAttribute('name'));
533
            }
534
535
            // Background
536 4
            $oElement = $xmlReader->getElement('/p:sldLayout/p:cSld/p:bg');
537 4
            if ($oElement instanceof \DOMElement) {
538 1
                $this->loadSlideBackground($xmlReader, $oElement, $oSlideLayout);
539
            }
540
541
            // ColorMapping
542 4
            $oElement = $xmlReader->getElement('/p:sldLayout/p:clrMapOvr/a:overrideClrMapping');
543 4
            if ($oElement instanceof \DOMElement && $oElement->hasAttributes()) {
544 1
                $colorMap = array();
545 1
                foreach ($oElement->attributes as $attr) {
546 1
                    $colorMap[$attr->nodeName] = $attr->nodeValue;
547
                }
548 1
                $oSlideLayout->colorMap->setMapping($colorMap);
549
            }
550
551
            // Shapes
552 4
            $oElements = $xmlReader->getElements('/p:sldLayout/p:cSld/p:spTree/*');
553 4
            if ($oElements) {
554 4
                $this->loadSlideShapes($oSlideLayout, $oElements, $xmlReader);
555
            }
556 4
            $this->arraySlideLayouts[$baseFile] = &$oSlideLayout;
557 4
            return $oSlideLayout;
558
        }
559
        return null;
560
    }
561
562
    /**
563
     * @param string $sPart
564
     * @param SlideMaster $oSlideMaster
565
     */
566 4
    private function loadTheme($sPart, SlideMaster $oSlideMaster)
567
    {
568 4
        $xmlReader = new XMLReader();
569 4
        if ($xmlReader->getDomFromString($sPart)) {
570 4
            $oElements = $xmlReader->getElements('/a:theme/a:themeElements/a:clrScheme/*');
571 4
            if ($oElements) {
572 4
                foreach ($oElements as $oElement) {
573 4
                    $oSchemeColor = new SchemeColor();
574 4
                    $oSchemeColor->setValue(str_replace('a:', '', $oElement->tagName));
575 4
                    $colorElement = $xmlReader->getElement('*', $oElement);
576 4
                    if ($colorElement instanceof \DOMElement) {
577 4
                        if ($colorElement->hasAttribute('lastClr')) {
578 4
                            $oSchemeColor->setRGB($colorElement->getAttribute('lastClr'));
579 4
                        } elseif ($colorElement->hasAttribute('val')) {
580 4
                            $oSchemeColor->setRGB($colorElement->getAttribute('val'));
581
                        }
582
                    }
583 4
                    $oSlideMaster->addSchemeColor($oSchemeColor);
584
                }
585
            }
586
        }
587 4
    }
588
589
    /**
590
     * @param XMLReader $xmlReader
591
     * @param \DOMElement $oElement
592
     * @param AbstractSlide $oSlide
593
     */
594 4
    private function loadSlideBackground(XMLReader $xmlReader, \DOMElement $oElement, AbstractSlide $oSlide)
595
    {
596
        // Background color
597 4
        $oElementColor = $xmlReader->getElement('p:bgPr/a:solidFill/a:srgbClr', $oElement);
598 4
        if ($oElementColor instanceof \DOMElement) {
599
            // Color
600
            $oColor = new Color();
601
            $oColor->setRGB($oElementColor->hasAttribute('val') ? $oElementColor->getAttribute('val') : null);
602
            // Background
603
            $oBackground = new \PhpOffice\PhpPresentation\Slide\Background\Color();
604
            $oBackground->setColor($oColor);
605
            // Slide Background
606
            $oSlide->setBackground($oBackground);
607
        }
608
609
        // Background scheme color
610 4
        $oElementSchemeColor = $xmlReader->getElement('p:bgRef/a:schemeClr', $oElement);
611 4
        if ($oElementSchemeColor instanceof \DOMElement) {
612
            // Color
613 4
            $oColor = new SchemeColor();
614 4
            $oColor->setValue($oElementSchemeColor->hasAttribute('val') ? $oElementSchemeColor->getAttribute('val') : null);
615
            // Background
616 4
            $oBackground = new \PhpOffice\PhpPresentation\Slide\Background\SchemeColor();
617 4
            $oBackground->setSchemeColor($oColor);
618
            // Slide Background
619 4
            $oSlide->setBackground($oBackground);
620
        }
621
622
        // Background image
623 4
        $oElementImage = $xmlReader->getElement('p:bgPr/a:blipFill/a:blip', $oElement);
624 4
        if ($oElementImage instanceof \DOMElement) {
625
            $relImg = $this->arrayRels[$oSlide->getRelsIndex()][$oElementImage->getAttribute('r:embed')];
626
            if (is_array($relImg)) {
627
                // File
628
                $pathImage = 'ppt/slides/' . $relImg['Target'];
629
                $pathImage = explode('/', $pathImage);
630
                foreach ($pathImage as $key => $partPath) {
631
                    if ($partPath == '..') {
632
                        unset($pathImage[$key - 1]);
633
                        unset($pathImage[$key]);
634
                    }
635
                }
636
                $pathImage = implode('/', $pathImage);
637
                $contentImg = $this->oZip->getFromName($pathImage);
638
639
                $tmpBkgImg = tempnam(sys_get_temp_dir(), 'PhpPresentationReaderPpt2007Bkg');
640
                file_put_contents($tmpBkgImg, $contentImg);
641
                // Background
642
                $oBackground = new Image();
643
                $oBackground->setPath($tmpBkgImg);
644
                // Slide Background
645
                $oSlide->setBackground($oBackground);
646
            }
647
        }
648 4
    }
649
650
    /**
651
     *
652
     * @param XMLReader $document
653
     * @param \DOMElement $node
654
     * @param AbstractSlide $oSlide
655
     */
656 3
    protected function loadShapeDrawing(XMLReader $document, \DOMElement $node, AbstractSlide $oSlide)
657
    {
658
        // Core
659 3
        $oShape = new Gd();
660 3
        $oShape->getShadow()->setVisible(false);
661
        // Variables
662 3
        $fileRels = $oSlide->getRelsIndex();
663
664 3
        $oElement = $document->getElement('p:nvPicPr/p:cNvPr', $node);
665 3
        if ($oElement instanceof \DOMElement) {
666 3
            $oShape->setName($oElement->hasAttribute('name') ? $oElement->getAttribute('name') : '');
667 3
            $oShape->setDescription($oElement->hasAttribute('descr') ? $oElement->getAttribute('descr') : '');
668
        }
669
670 3
        $oElement = $document->getElement('p:blipFill/a:blip', $node);
671 3
        if ($oElement instanceof \DOMElement) {
672 3
            if ($oElement->hasAttribute('r:embed') && isset($this->arrayRels[$fileRels][$oElement->getAttribute('r:embed')]['Target'])) {
673 3
                $pathImage = 'ppt/slides/' . $this->arrayRels[$fileRels][$oElement->getAttribute('r:embed')]['Target'];
674 3
                $pathImage = explode('/', $pathImage);
675 3
                foreach ($pathImage as $key => $partPath) {
676 3
                    if ($partPath == '..') {
677 3
                        unset($pathImage[$key - 1]);
678 3
                        unset($pathImage[$key]);
679
                    }
680
                }
681 3
                $pathImage = implode('/', $pathImage);
682 3
                $imageFile = $this->oZip->getFromName($pathImage);
683 3
                if (!empty($imageFile)) {
684 3
                    $oShape->setImageResource(imagecreatefromstring($imageFile));
685
                }
686
            }
687
        }
688
689 3
        $oElement = $document->getElement('p:spPr/a:xfrm', $node);
690 3
        if ($oElement instanceof \DOMElement) {
691 3
            if ($oElement->hasAttribute('rot')) {
692 3
                $oShape->setRotation(CommonDrawing::angleToDegrees($oElement->getAttribute('rot')));
693
            }
694
        }
695
696 3
        $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node);
697 3
        if ($oElement instanceof \DOMElement) {
698 3
            if ($oElement->hasAttribute('x')) {
699 3
                $oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x')));
700
            }
701 3
            if ($oElement->hasAttribute('y')) {
702 3
                $oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y')));
703
            }
704
        }
705
706 3
        $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node);
707 3
        if ($oElement instanceof \DOMElement) {
708 3
            if ($oElement->hasAttribute('cx')) {
709 3
                $oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx')));
710
            }
711 3
            if ($oElement->hasAttribute('cy')) {
712 3
                $oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy')));
713
            }
714
        }
715
716 3
        $oElement = $document->getElement('p:spPr/a:effectLst', $node);
717 3
        if ($oElement instanceof \DOMElement) {
718 3
            $oShape->getShadow()->setVisible(true);
719
720 3
            $oSubElement = $document->getElement('a:outerShdw', $oElement);
721 3
            if ($oSubElement instanceof \DOMElement) {
722 3
                if ($oSubElement->hasAttribute('blurRad')) {
723 3
                    $oShape->getShadow()->setBlurRadius(CommonDrawing::emuToPixels($oSubElement->getAttribute('blurRad')));
724
                }
725 3
                if ($oSubElement->hasAttribute('dist')) {
726 3
                    $oShape->getShadow()->setDistance(CommonDrawing::emuToPixels($oSubElement->getAttribute('dist')));
727
                }
728 3
                if ($oSubElement->hasAttribute('dir')) {
729 3
                    $oShape->getShadow()->setDirection(CommonDrawing::angleToDegrees($oSubElement->getAttribute('dir')));
730
                }
731 3
                if ($oSubElement->hasAttribute('algn')) {
732 3
                    $oShape->getShadow()->setAlignment($oSubElement->getAttribute('algn'));
733
                }
734
            }
735
736 3
            $oSubElement = $document->getElement('a:outerShdw/a:srgbClr', $oElement);
737 3
            if ($oSubElement instanceof \DOMElement) {
738 3
                if ($oSubElement->hasAttribute('val')) {
739 3
                    $oColor = new Color();
740 3
                    $oColor->setRGB($oSubElement->getAttribute('val'));
741 3
                    $oShape->getShadow()->setColor($oColor);
742
                }
743
            }
744
745 3
            $oSubElement = $document->getElement('a:outerShdw/a:srgbClr/a:alpha', $oElement);
746 3
            if ($oSubElement instanceof \DOMElement) {
747 3
                if ($oSubElement->hasAttribute('val')) {
748 3
                    $oShape->getShadow()->setAlpha((int)$oSubElement->getAttribute('val') / 1000);
749
                }
750
            }
751
        }
752
753 3
        $oSlide->addShape($oShape);
754 3
    }
755
756
    /**
757
     * @param XMLReader $document
758
     * @param \DOMElement $node
759
     * @param AbstractSlide $oSlide
760
     * @throws \Exception
761
     */
762 4
    protected function loadShapeRichText(XMLReader $document, \DOMElement $node, AbstractSlide $oSlide)
763
    {
764
        // Core
765 4
        $oShape = $oSlide->createRichTextShape();
766 4
        $oShape->setParagraphs(array());
767
        // Variables
768 4
        $fileRels = $oSlide->getRelsIndex();
769
770 4
        $oElement = $document->getElement('p:spPr/a:xfrm', $node);
771 4
        if ($oElement instanceof \DOMElement && $oElement->hasAttribute('rot')) {
772 4
            $oShape->setRotation(CommonDrawing::angleToDegrees($oElement->getAttribute('rot')));
773
        }
774
775 4
        $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node);
776 4
        if ($oElement instanceof \DOMElement) {
777 4
            if ($oElement->hasAttribute('x')) {
778 4
                $oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x')));
779
            }
780 4
            if ($oElement->hasAttribute('y')) {
781 4
                $oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y')));
782
            }
783
        }
784
785 4
        $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node);
786 4
        if ($oElement instanceof \DOMElement) {
787 4
            if ($oElement->hasAttribute('cx')) {
788 4
                $oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx')));
789
            }
790 4
            if ($oElement->hasAttribute('cy')) {
791 4
                $oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy')));
792
            }
793
        }
794
795 4
        $oElement = $document->getElement('p:nvSpPr/p:nvPr/p:ph', $node);
796 4
        if ($oElement instanceof \DOMElement) {
797 4
            if ($oElement->hasAttribute('type')) {
798 4
                $placeholder = new Placeholder($oElement->getAttribute('type'));
799 4
                $oShape->setPlaceHolder($placeholder);
800
            }
801
        }
802
803 4
        $arrayElements = $document->getElements('p:txBody/a:p', $node);
804 4
        foreach ($arrayElements as $oElement) {
805
            // Core
806 4
            $oParagraph = $oShape->createParagraph();
807 4
            $oParagraph->setRichTextElements(array());
808
809 4
            $oSubElement = $document->getElement('a:pPr', $oElement);
810 4
            if ($oSubElement instanceof \DOMElement) {
811 4
                if ($oSubElement->hasAttribute('algn')) {
812 4
                    $oParagraph->getAlignment()->setHorizontal($oSubElement->getAttribute('algn'));
813
                }
814 4
                if ($oSubElement->hasAttribute('fontAlgn')) {
815 3
                    $oParagraph->getAlignment()->setVertical($oSubElement->getAttribute('fontAlgn'));
816
                }
817 4
                if ($oSubElement->hasAttribute('marL')) {
818 4
                    $oParagraph->getAlignment()->setMarginLeft(CommonDrawing::emuToPixels($oSubElement->getAttribute('marL')));
819
                }
820 4
                if ($oSubElement->hasAttribute('marR')) {
821 3
                    $oParagraph->getAlignment()->setMarginRight(CommonDrawing::emuToPixels($oSubElement->getAttribute('marR')));
822
                }
823 4
                if ($oSubElement->hasAttribute('indent')) {
824 3
                    $oParagraph->getAlignment()->setIndent(CommonDrawing::emuToPixels($oSubElement->getAttribute('indent')));
825
                }
826 4
                if ($oSubElement->hasAttribute('lvl')) {
827 4
                    $oParagraph->getAlignment()->setLevel($oSubElement->getAttribute('lvl'));
828
                }
829
830 4
                $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_NONE);
831
832 4
                $oElementBuFont = $document->getElement('a:buFont', $oSubElement);
833 4
                if ($oElementBuFont instanceof \DOMElement) {
834 3
                    if ($oElementBuFont->hasAttribute('typeface')) {
835 3
                        $oParagraph->getBulletStyle()->setBulletFont($oElementBuFont->getAttribute('typeface'));
836
                    }
837
                }
838 4
                $oElementBuChar = $document->getElement('a:buChar', $oSubElement);
839 4
                if ($oElementBuChar instanceof \DOMElement) {
840 3
                    $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET);
841 3
                    if ($oElementBuChar->hasAttribute('char')) {
842 3
                        $oParagraph->getBulletStyle()->setBulletChar($oElementBuChar->getAttribute('char'));
843
                    }
844
                }
845 4
                $oElementBuAutoNum = $document->getElement('a:buAutoNum', $oSubElement);
846 4
                if ($oElementBuAutoNum instanceof \DOMElement) {
847
                    $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_NUMERIC);
848
                    if ($oElementBuAutoNum->hasAttribute('type')) {
849
                        $oParagraph->getBulletStyle()->setBulletNumericStyle($oElementBuAutoNum->getAttribute('type'));
850
                    }
851
                    if ($oElementBuAutoNum->hasAttribute('startAt') && $oElementBuAutoNum->getAttribute('startAt') != 1) {
852
                        $oParagraph->getBulletStyle()->setBulletNumericStartAt($oElementBuAutoNum->getAttribute('startAt'));
853
                    }
854
                }
855 4
                $oElementBuClr = $document->getElement('a:buClr', $oSubElement);
856 4
                if ($oElementBuClr instanceof \DOMElement) {
857
                    $oColor = new Color();
858
                    /**
859
                     * @todo Create protected for reading Color
860
                     */
861
                    $oElementColor = $document->getElement('a:srgbClr', $oElementBuClr);
862
                    if ($oElementColor instanceof \DOMElement) {
863
                        $oColor->setRGB($oElementColor->hasAttribute('val') ? $oElementColor->getAttribute('val') : null);
864
                    }
865
                    $oParagraph->getBulletStyle()->setBulletColor($oColor);
866
                }
867
            }
868 4
            $arraySubElements = $document->getElements('(a:r|a:br)', $oElement);
869 4
            foreach ($arraySubElements as $oSubElement) {
870 4
                if ($oSubElement->tagName == 'a:br') {
871 3
                    $oParagraph->createBreak();
872
                }
873 4
                if ($oSubElement->tagName == 'a:r') {
874 4
                    $oElementrPr = $document->getElement('a:rPr', $oSubElement);
875 4
                    if (is_object($oElementrPr)) {
876 4
                        $oText = $oParagraph->createTextRun();
877
878 4
                        if ($oElementrPr->hasAttribute('b')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
879 3
                            $oText->getFont()->setBold($oElementrPr->getAttribute('b') == 'true' ? true : false);
880
                        }
881 4
                        if ($oElementrPr->hasAttribute('i')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
882 3
                            $oText->getFont()->setItalic($oElementrPr->getAttribute('i') == 'true' ? true : false);
883
                        }
884 4
                        if ($oElementrPr->hasAttribute('strike')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
885 3
                            $oText->getFont()->setStrikethrough($oElementrPr->getAttribute('strike') == 'noStrike' ? false : true);
886
                        }
887 4
                        if ($oElementrPr->hasAttribute('sz')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
888 3
                            $oText->getFont()->setSize((int)($oElementrPr->getAttribute('sz') / 100));
889
                        }
890 4
                        if ($oElementrPr->hasAttribute('u')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
891 3
                            $oText->getFont()->setUnderline($oElementrPr->getAttribute('u'));
892
                        }
893
                        // Color
894 4
                        $oElementSrgbClr = $document->getElement('a:solidFill/a:srgbClr', $oElementrPr);
0 ignored issues
show
Documentation introduced by
$oElementrPr is of type object<DOMNode>, but the function expects a null|object<DOMElement>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
895 4
                        if (is_object($oElementSrgbClr) && $oElementSrgbClr->hasAttribute('val')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
896 3
                            $oColor = new Color();
897 3
                            $oColor->setRGB($oElementSrgbClr->getAttribute('val'));
898 3
                            $oText->getFont()->setColor($oColor);
899
                        }
900
                        // Hyperlink
901 4
                        $oElementHlinkClick = $document->getElement('a:hlinkClick', $oElementrPr);
0 ignored issues
show
Documentation introduced by
$oElementrPr is of type object<DOMNode>, but the function expects a null|object<DOMElement>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
902 4
                        if (is_object($oElementHlinkClick)) {
903 3
                            if ($oElementHlinkClick->hasAttribute('tooltip')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
904 3
                                $oText->getHyperlink()->setTooltip($oElementHlinkClick->getAttribute('tooltip'));
905
                            }
906 3
                            if ($oElementHlinkClick->hasAttribute('r:id') && isset($this->arrayRels[$fileRels][$oElementHlinkClick->getAttribute('r:id')]['Target'])) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
907 3
                                $oText->getHyperlink()->setUrl($this->arrayRels[$fileRels][$oElementHlinkClick->getAttribute('r:id')]['Target']);
908
                            }
909
                        }
910
                        //} else {
911
                        // $oText = $oParagraph->createText();
912
913 4
                        $oSubSubElement = $document->getElement('a:t', $oSubElement);
914 4
                        $oText->setText($oSubSubElement->nodeValue);
915
                    }
916
                }
917
            }
918
        }
919
920 4
        if (count($oShape->getParagraphs()) > 0) {
921 4
            $oShape->setActiveParagraph(0);
922
        }
923 4
    }
924
925
    /**
926
     *
927
     * @param string $fileRels
928
     * @return string
929
     */
930 4
    protected function loadRels($fileRels)
931
    {
932 4
        $sPart = $this->oZip->getFromName($fileRels);
933 4
        if ($sPart !== false) {
934 4
            $xmlReader = new XMLReader();
935 4
            if ($xmlReader->getDomFromString($sPart)) {
936 4
                foreach ($xmlReader->getElements('*') as $oNode) {
937 4
                    $this->arrayRels[$fileRels][$oNode->getAttribute('Id')] = array(
938 4
                        'Target' => $oNode->getAttribute('Target'),
939 4
                        'Type' => $oNode->getAttribute('Type'),
940
                    );
941
                }
942
            }
943
        }
944 4
    }
945
946
    /**
947
     * @param $oSlide
948
     * @param $oElements
949
     * @param $xmlReader
950
     * @internal param $baseFile
951
     */
952 4
    private function loadSlideShapes($oSlide, $oElements, $xmlReader)
953
    {
954 4
        foreach ($oElements as $oNode) {
955 4
            switch ($oNode->tagName) {
956 4
                case 'p:pic':
957
                    $this->loadShapeDrawing($xmlReader, $oNode, $oSlide);
958
                    break;
959 4
                case 'p:sp':
960 4
                    $this->loadShapeRichText($xmlReader, $oNode, $oSlide);
961 4
                    break;
962 4
                default:
963
                    //var_export($oNode->tagName);
964
            }
965
        }
966 4
    }
967
}
968