Completed
Push — develop ( 89b566...088966 )
by Franck
02:27 queued 02:17
created

PowerPoint2007::loadFile()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 32
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 25
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 25
cts 25
cp 1
rs 8.439
c 0
b 0
f 0
cc 5
eloc 21
nc 16
nop 1
crap 5
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 1
        }
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 4
        }
139
140 4
        $docPropsCustom = $this->oZip->getFromName('docProps/custom.xml');
141 4
        if ($docPropsCustom !== false) {
142 1
            $this->loadCustomProperties($docPropsCustom);
143 1
        }
144
145 4
        $pptViewProps = $this->oZip->getFromName('ppt/viewProps.xml');
146 4
        if ($pptViewProps !== false) {
147 4
            $this->loadViewProperties($pptViewProps);
148 4
        }
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 4
        }
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
                        $oLayout->setDocumentLayout($type, false);
177
                    }
178
                }
179 4
            }
180 4
        }
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 4
                '/cp:coreProperties/cp:lastModifiedBy' => 'setLastModifiedBy',
194 4
                '/cp:coreProperties/dc:title' => 'setTitle',
195 4
                '/cp:coreProperties/dc:description' => 'setDescription',
196 4
                '/cp:coreProperties/dc:subject' => 'setSubject',
197 4
                '/cp:coreProperties/cp:keywords' => 'setKeywords',
198 4
                '/cp:coreProperties/cp:category' => 'setCategory',
199 4
                '/cp:coreProperties/dcterms:created' => 'setCreated',
200 4
                '/cp:coreProperties/dcterms:modified' => 'setModified',
201 4
            );
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 4
                    } else {
211 4
                        $oProperties->{$property}($oElement->nodeValue);
212
                    }
213 4
                }
214 4
            }
215 4
        }
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 1
                }
232 1
            }
233 1
        }
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 3
                }
250 3
            }
251 4
        }
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 4
                    }
275 4
                }
276 4
            }
277 4
        }
278 4
    }
279
280
    /**
281
     * Extract all MasterSlides
282
     * @param XMLReader $xmlReader
283
     * @param string $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 4
                }
299 4
            }
300 4
        }
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 4
                }
372 4
            }
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 4
                    }
381 4
                    break;
382
                }
383 4
            }
384 4
        }
385 4
    }
386
387
    /**
388
     * @param string $baseFile
389
     */
390 4
    private function loadMasterSlide($sPart, $baseFile)
391
    {
392 4
        $xmlReader = new XMLReader();
393 4
        if ($xmlReader->getDomFromString($sPart)) {
394
            // Core
395 4
            $oSlideMaster = $this->oPhpPresentation->createMasterSlide();
396 4
            $oSlideMaster->setTextStyles(new TextStyle(false));
397 4
            $oSlideMaster->setRelsIndex('ppt/slideMasters/_rels/' . $baseFile . '.rels');
398
399
            // Background
400 4
            $oElement = $xmlReader->getElement('/p:sldMaster/p:cSld/p:bg');
401 4
            if ($oElement instanceof \DOMElement) {
402 4
                $this->loadSlideBackground($xmlReader, $oElement, $oSlideMaster);
403 4
            }
404
405
            // Shapes
406 4
            $arrayElements = $xmlReader->getElements('/p:sldMaster/p:cSld/p:spTree/*');
407 4
            if ($arrayElements) {
408 4
                $this->loadSlideShapes($oSlideMaster, $arrayElements, $xmlReader);
409 4
            }
410
            // Header & Footer
411
412
            // ColorMapping
413 4
            $colorMap = array();
414 4
            $oElement = $xmlReader->getElement('/p:sldMaster/p:clrMap');
415 4
            if ($oElement->hasAttributes()) {
416 4
                foreach ($oElement->attributes as $attr) {
417 4
                    $colorMap[$attr->nodeName] = $attr->nodeValue;
418 4
                }
419 4
                $oSlideMaster->colorMap->setMapping($colorMap);
420 4
            }
421
422
            // TextStyles
423 4
            $arrayElementTxStyles = $xmlReader->getElements('/p:sldMaster/p:txStyles/*');
424 4
            if ($arrayElementTxStyles) {
425 4
                foreach ($arrayElementTxStyles as $oElementTxStyle) {
426 4
                    $arrayElementsLvl = $xmlReader->getElements('/p:sldMaster/p:txStyles/'.$oElementTxStyle->nodeName.'/*');
427 4
                    foreach ($arrayElementsLvl as $oElementLvl) {
428 4
                        if ($oElementLvl->nodeName == 'a:extLst') {
429 1
                            continue;
430
                        }
431 4
                        $oRTParagraph = new Paragraph();
432
433 4
                        if ($oElementLvl->nodeName == 'a:defPPr') {
434 3
                            $level = 0;
435 3
                        } else {
436 4
                            $level = str_replace('a:lvl', '', $oElementLvl->nodeName);
437 4
                            $level = str_replace('pPr', '', $level);
438
                        }
439
440 4
                        if ($oElementLvl->hasAttribute('algn')) {
441 4
                            $oRTParagraph->getAlignment()->setHorizontal($oElementLvl->getAttribute('algn'));
442 4
                        }
443 4
                        if ($oElementLvl->hasAttribute('marL')) {
444 4
                            $val = $oElementLvl->getAttribute('marL');
445 4
                            $val = CommonDrawing::emuToPixels($val);
446 4
                            $oRTParagraph->getAlignment()->setMarginLeft($val);
447 4
                        }
448 4
                        if ($oElementLvl->hasAttribute('marR')) {
449
                            $val = $oElementLvl->getAttribute('marR');
450
                            $val = CommonDrawing::emuToPixels($val);
451
                            $oRTParagraph->getAlignment()->setMarginRight($val);
452
                        }
453 4
                        if ($oElementLvl->hasAttribute('indent')) {
454 4
                            $val = $oElementLvl->getAttribute('indent');
455 4
                            $val = CommonDrawing::emuToPixels($val);
456 4
                            $oRTParagraph->getAlignment()->setIndent($val);
457 4
                        }
458 4
                        $oElementLvlDefRPR = $xmlReader->getElement('a:defRPr', $oElementLvl);
459 4
                        if ($oElementLvlDefRPR instanceof \DOMElement) {
460 4
                            if ($oElementLvlDefRPR->hasAttribute('sz')) {
461 4
                                $oRTParagraph->getFont()->setSize($oElementLvlDefRPR->getAttribute('sz') / 100);
462 4
                            }
463 4
                            if ($oElementLvlDefRPR->hasAttribute('b') && $oElementLvlDefRPR->getAttribute('b') == 1) {
464 1
                                $oRTParagraph->getFont()->setBold(true);
465 1
                            }
466 4
                            if ($oElementLvlDefRPR->hasAttribute('i') && $oElementLvlDefRPR->getAttribute('i') == 1) {
467
                                $oRTParagraph->getFont()->setItalic(true);
468
                            }
469 4
                        }
470 4
                        $oElementSchemeColor = $xmlReader->getElement('a:defRPr/a:solidFill/a:schemeClr', $oElementLvl);
471 4
                        if ($oElementSchemeColor instanceof \DOMElement) {
472 4
                            if ($oElementSchemeColor->hasAttribute('val')) {
473 4
                                $oSchemeColor = new SchemeColor();
474 4
                                $oSchemeColor->setValue($oElementSchemeColor->getAttribute('val'));
475 4
                                $oRTParagraph->getFont()->setColor($oSchemeColor);
476 4
                            }
477 4
                        }
478
479 4
                        switch ($oElementTxStyle->nodeName) {
480 4
                            case 'p:bodyStyle':
481 4
                                $oSlideMaster->getTextStyles()->setBodyStyleAtLvl($oRTParagraph, $level);
482 4
                                break;
483 4
                            case 'p:otherStyle':
484 4
                                $oSlideMaster->getTextStyles()->setOtherStyleAtLvl($oRTParagraph, $level);
485 4
                                break;
486 4
                            case 'p:titleStyle':
487 4
                                $oSlideMaster->getTextStyles()->setTitleStyleAtLvl($oRTParagraph, $level);
488 4
                                break;
489 4
                        }
490 4
                    }
491 4
                }
492 4
            }
493
494
            // Load the theme
495 4
            foreach ($this->arrayRels[$oSlideMaster->getRelsIndex()] as $arrayRel) {
496 4
                if ($arrayRel['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme') {
497 4
                    $pptTheme = $this->oZip->getFromName('ppt/' . substr($arrayRel['Target'], strrpos($arrayRel['Target'], '../') + 3));
498 4
                    if ($pptTheme !== false) {
499 4
                        $this->loadTheme($pptTheme, $oSlideMaster);
500 4
                    }
501 4
                    break;
502
                }
503 4
            }
504
505
            // Load the Layoutslide
506 4
            foreach ($xmlReader->getElements('/p:sldMaster/p:sldLayoutIdLst/p:sldLayoutId') as $oElement) {
507 4
                $rId = $oElement->getAttribute('r:id');
508
                // Get the path to the masterslide from the array with _rels files
509 4
                $pathLayoutSlide = isset($this->arrayRels[$oSlideMaster->getRelsIndex()][$rId]) ?
510 4
                    $this->arrayRels[$oSlideMaster->getRelsIndex()][$rId]['Target'] : '';
511 4
                if (!empty($pathLayoutSlide)) {
512 4
                    $pptLayoutSlide = $this->oZip->getFromName('ppt/' . substr($pathLayoutSlide, strrpos($pathLayoutSlide, '../') + 3));
513 4
                    if ($pptLayoutSlide !== false) {
514 4
                        $this->loadRels('ppt/slideLayouts/_rels/' . basename($pathLayoutSlide) . '.rels');
515 4
                        $oSlideMaster->addSlideLayout(
516 4
                            $this->loadLayoutSlide($pptLayoutSlide, basename($pathLayoutSlide), $oSlideMaster)
517 4
                        );
518 4
                    }
519 4
                }
520 4
            }
521 4
        }
522 4
    }
523
524
    /**
525
     * @param string $baseFile
526
     */
527 4
    private function loadLayoutSlide($sPart, $baseFile, SlideMaster $oSlideMaster)
528
    {
529 4
        $xmlReader = new XMLReader();
530 4
        if ($xmlReader->getDomFromString($sPart)) {
531
            // Core
532 4
            $oSlideLayout = new SlideLayout($oSlideMaster);
533 4
            $oSlideLayout->setRelsIndex('ppt/slideLayouts/_rels/' . $baseFile . '.rels');
534
535
            // Name
536 4
            $oElement = $xmlReader->getElement('/p:sldLayout/p:cSld');
537 4
            if ($oElement instanceof \DOMElement && $oElement->hasAttribute('name')) {
538 4
                $oSlideLayout->setLayoutName($oElement->getAttribute('name'));
539 4
            }
540
541
            // Background
542 4
            $oElement = $xmlReader->getElement('/p:sldLayout/p:cSld/p:bg');
543 4
            if ($oElement instanceof \DOMElement) {
544 1
                $this->loadSlideBackground($xmlReader, $oElement, $oSlideLayout);
545 1
            }
546
547
            // ColorMapping
548 4
            $oElement = $xmlReader->getElement('/p:sldLayout/p:clrMapOvr/a:overrideClrMapping');
549 4
            if ($oElement instanceof \DOMElement && $oElement->hasAttributes()) {
550 1
                $colorMap = array();
551 1
                foreach ($oElement->attributes as $attr) {
552 1
                    $colorMap[$attr->nodeName] = $attr->nodeValue;
553 1
                }
554 1
                $oSlideLayout->colorMap->setMapping($colorMap);
555 1
            }
556
557
            // Shapes
558 4
            $oElements = $xmlReader->getElements('/p:sldLayout/p:cSld/p:spTree/*');
559 4
            if ($oElements) {
560 4
                $this->loadSlideShapes($oSlideLayout, $oElements, $xmlReader);
561 4
            }
562 4
            $this->arraySlideLayouts[$baseFile] = &$oSlideLayout;
563 4
            return $oSlideLayout;
564
        }
565
        return null;
566
    }
567
568
    /**
569
     * @param string $sPart
570
     * @param SlideMaster $oSlideMaster
571
     */
572 4
    private function loadTheme($sPart, SlideMaster $oSlideMaster)
573
    {
574 4
        $xmlReader = new XMLReader();
575 4
        if ($xmlReader->getDomFromString($sPart)) {
576 4
            $oElements = $xmlReader->getElements('/a:theme/a:themeElements/a:clrScheme/*');
577 4
            if ($oElements) {
578 4
                foreach ($oElements as $oElement) {
579 4
                    $oSchemeColor = new SchemeColor();
580 4
                    $oSchemeColor->setValue(str_replace('a:', '', $oElement->tagName));
581 4
                    $colorElement = $xmlReader->getElement('*', $oElement);
582 4
                    if ($colorElement instanceof \DOMElement) {
583 4
                        if ($colorElement->hasAttribute('lastClr')) {
584 4
                            $oSchemeColor->setRGB($colorElement->getAttribute('lastClr'));
585 4
                        } elseif ($colorElement->hasAttribute('val')) {
586 4
                            $oSchemeColor->setRGB($colorElement->getAttribute('val'));
587 4
                        }
588 4
                    }
589 4
                    $oSlideMaster->addSchemeColor($oSchemeColor);
590 4
                }
591 4
            }
592 4
        }
593 4
    }
594
595
    /**
596
     * @param XMLReader $xmlReader
597
     * @param \DOMElement $oElement
598
     * @param AbstractSlide $oSlide
599
     */
600 4
    private function loadSlideBackground(XMLReader $xmlReader, \DOMElement $oElement, AbstractSlide $oSlide)
601
    {
602
        // Background color
603 4
        $oElementColor = $xmlReader->getElement('p:bgPr/a:solidFill/a:srgbClr', $oElement);
604 4
        if ($oElementColor instanceof \DOMElement) {
605
            // Color
606
            $oColor = new Color();
607
            $oColor->setRGB($oElementColor->hasAttribute('val') ? $oElementColor->getAttribute('val') : null);
608
            // Background
609
            $oBackground = new \PhpOffice\PhpPresentation\Slide\Background\Color();
610
            $oBackground->setColor($oColor);
611
            // Slide Background
612
            $oSlide->setBackground($oBackground);
613
        }
614
615
        // Background scheme color
616 4
        $oElementSchemeColor = $xmlReader->getElement('p:bgRef/a:schemeClr', $oElement);
617 4
        if ($oElementSchemeColor instanceof \DOMElement) {
618
            // Color
619 4
            $oColor = new SchemeColor();
620 4
            $oColor->setValue($oElementSchemeColor->hasAttribute('val') ? $oElementSchemeColor->getAttribute('val') : null);
621
            // Background
622 4
            $oBackground = new \PhpOffice\PhpPresentation\Slide\Background\SchemeColor();
623 4
            $oBackground->setSchemeColor($oColor);
624
            // Slide Background
625 4
            $oSlide->setBackground($oBackground);
626 4
        }
627
628
        // Background image
629 4
        $oElementImage = $xmlReader->getElement('p:bgPr/a:blipFill/a:blip', $oElement);
630 4
        if ($oElementImage instanceof \DOMElement) {
631
            $relImg = $this->arrayRels[$oSlide->getRelsIndex()][$oElementImage->getAttribute('r:embed')];
632
            if (is_array($relImg)) {
633
                // File
634
                $pathImage = 'ppt/slides/' . $relImg['Target'];
635
                $pathImage = explode('/', $pathImage);
636
                foreach ($pathImage as $key => $partPath) {
637
                    if ($partPath == '..') {
638
                        unset($pathImage[$key - 1]);
639
                        unset($pathImage[$key]);
640
                    }
641
                }
642
                $pathImage = implode('/', $pathImage);
643
                $contentImg = $this->oZip->getFromName($pathImage);
644
645
                $tmpBkgImg = tempnam(sys_get_temp_dir(), 'PhpPresentationReaderPpt2007Bkg');
646
                file_put_contents($tmpBkgImg, $contentImg);
647
                // Background
648
                $oBackground = new Image();
649
                $oBackground->setPath($tmpBkgImg);
650
                // Slide Background
651
                $oSlide->setBackground($oBackground);
652
            }
653
        }
654 4
    }
655
656
    /**
657
     *
658
     * @param XMLReader $document
659
     * @param \DOMElement $node
660
     * @param AbstractSlide $oSlide
661
     */
662 3
    protected function loadShapeDrawing(XMLReader $document, \DOMElement $node, AbstractSlide $oSlide)
663
    {
664
        // Core
665 3
        $oShape = new Gd();
666 3
        $oShape->getShadow()->setVisible(false);
667
        // Variables
668 3
        $fileRels = $oSlide->getRelsIndex();
669
670 3
        $oElement = $document->getElement('p:nvPicPr/p:cNvPr', $node);
671 3
        if ($oElement instanceof \DOMElement) {
672 3
            $oShape->setName($oElement->hasAttribute('name') ? $oElement->getAttribute('name') : '');
673 3
            $oShape->setDescription($oElement->hasAttribute('descr') ? $oElement->getAttribute('descr') : '');
674 3
        }
675
676 3
        $oElement = $document->getElement('p:blipFill/a:blip', $node);
677 3
        if ($oElement instanceof \DOMElement) {
678 3
            if ($oElement->hasAttribute('r:embed') && isset($this->arrayRels[$fileRels][$oElement->getAttribute('r:embed')]['Target'])) {
679 3
                $pathImage = 'ppt/slides/' . $this->arrayRels[$fileRels][$oElement->getAttribute('r:embed')]['Target'];
680 3
                $pathImage = explode('/', $pathImage);
681 3
                foreach ($pathImage as $key => $partPath) {
682 3
                    if ($partPath == '..') {
683 3
                        unset($pathImage[$key - 1]);
684 3
                        unset($pathImage[$key]);
685 3
                    }
686 3
                }
687 3
                $pathImage = implode('/', $pathImage);
688 3
                $imageFile = $this->oZip->getFromName($pathImage);
689 3
                if (!empty($imageFile)) {
690 3
                    $oShape->setImageResource(imagecreatefromstring($imageFile));
691 3
                }
692 3
            }
693 3
        }
694
695 3
        $oElement = $document->getElement('p:spPr/a:xfrm', $node);
696 3
        if ($oElement instanceof \DOMElement) {
697 3
            if ($oElement->hasAttribute('rot')) {
698 3
                $oShape->setRotation(CommonDrawing::angleToDegrees($oElement->getAttribute('rot')));
699 3
            }
700 3
        }
701
702 3
        $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node);
703 3
        if ($oElement instanceof \DOMElement) {
704 3
            if ($oElement->hasAttribute('x')) {
705 3
                $oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x')));
706 3
            }
707 3
            if ($oElement->hasAttribute('y')) {
708 3
                $oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y')));
709 3
            }
710 3
        }
711
712 3
        $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node);
713 3
        if ($oElement instanceof \DOMElement) {
714 3
            if ($oElement->hasAttribute('cx')) {
715 3
                $oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx')));
716 3
            }
717 3
            if ($oElement->hasAttribute('cy')) {
718 3
                $oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy')));
719 3
            }
720 3
        }
721
722 3
        $oElement = $document->getElement('p:spPr/a:effectLst', $node);
723 3
        if ($oElement instanceof \DOMElement) {
724 3
            $oShape->getShadow()->setVisible(true);
725
726 3
            $oSubElement = $document->getElement('a:outerShdw', $oElement);
727 3
            if ($oSubElement instanceof \DOMElement) {
728 3
                if ($oSubElement->hasAttribute('blurRad')) {
729 3
                    $oShape->getShadow()->setBlurRadius(CommonDrawing::emuToPixels($oSubElement->getAttribute('blurRad')));
730 3
                }
731 3
                if ($oSubElement->hasAttribute('dist')) {
732 3
                    $oShape->getShadow()->setDistance(CommonDrawing::emuToPixels($oSubElement->getAttribute('dist')));
733 3
                }
734 3
                if ($oSubElement->hasAttribute('dir')) {
735 3
                    $oShape->getShadow()->setDirection(CommonDrawing::angleToDegrees($oSubElement->getAttribute('dir')));
736 3
                }
737 3
                if ($oSubElement->hasAttribute('algn')) {
738 3
                    $oShape->getShadow()->setAlignment($oSubElement->getAttribute('algn'));
739 3
                }
740 3
            }
741
742 3
            $oSubElement = $document->getElement('a:outerShdw/a:srgbClr', $oElement);
743 3
            if ($oSubElement instanceof \DOMElement) {
744 3
                if ($oSubElement->hasAttribute('val')) {
745 3
                    $oColor = new Color();
746 3
                    $oColor->setRGB($oSubElement->getAttribute('val'));
747 3
                    $oShape->getShadow()->setColor($oColor);
748 3
                }
749 3
            }
750
751 3
            $oSubElement = $document->getElement('a:outerShdw/a:srgbClr/a:alpha', $oElement);
752 3
            if ($oSubElement instanceof \DOMElement) {
753 3
                if ($oSubElement->hasAttribute('val')) {
754 3
                    $oShape->getShadow()->setAlpha((int)$oSubElement->getAttribute('val') / 1000);
755 3
                }
756 3
            }
757 3
        }
758
759 3
        $oSlide->addShape($oShape);
760 3
    }
761
762
    /**
763
     * @param XMLReader $document
764
     * @param \DOMElement $node
765
     * @param AbstractSlide $oSlide
766
     * @throws \Exception
767
     */
768 4
    protected function loadShapeRichText(XMLReader $document, \DOMElement $node, AbstractSlide $oSlide)
769
    {
770
        // Core
771 4
        $oShape = $oSlide->createRichTextShape();
772 4
        $oShape->setParagraphs(array());
773
        // Variables
774 4
        $fileRels = $oSlide->getRelsIndex();
775
776 4
        $oElement = $document->getElement('p:spPr/a:xfrm', $node);
777 4
        if ($oElement instanceof \DOMElement && $oElement->hasAttribute('rot')) {
778 4
            $oShape->setRotation(CommonDrawing::angleToDegrees($oElement->getAttribute('rot')));
779 4
        }
780
781 4
        $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node);
782 4
        if ($oElement instanceof \DOMElement) {
783 4
            if ($oElement->hasAttribute('x')) {
784 4
                $oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x')));
785 4
            }
786 4
            if ($oElement->hasAttribute('y')) {
787 4
                $oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y')));
788 4
            }
789 4
        }
790
791 4
        $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node);
792 4
        if ($oElement instanceof \DOMElement) {
793 4
            if ($oElement->hasAttribute('cx')) {
794 4
                $oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx')));
795 4
            }
796 4
            if ($oElement->hasAttribute('cy')) {
797 4
                $oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy')));
798 4
            }
799 4
        }
800
801 4
        $oElement = $document->getElement('p:nvSpPr/p:nvPr/p:ph', $node);
802 4
        if ($oElement instanceof \DOMElement) {
803 4
            if ($oElement->hasAttribute('type')) {
804 4
                $placeholder = new Placeholder($oElement->getAttribute('type'));
805 4
                $oShape->setPlaceHolder($placeholder);
806 4
            }
807 4
        }
808
809 4
        $arrayElements = $document->getElements('p:txBody/a:p', $node);
810 4
        foreach ($arrayElements as $oElement) {
811
            // Core
812 4
            $oParagraph = $oShape->createParagraph();
813 4
            $oParagraph->setRichTextElements(array());
814
815 4
            $oSubElement = $document->getElement('a:pPr', $oElement);
816 4
            if ($oSubElement instanceof \DOMElement) {
817 4
                if ($oSubElement->hasAttribute('algn')) {
818 4
                    $oParagraph->getAlignment()->setHorizontal($oSubElement->getAttribute('algn'));
819 4
                }
820 4
                if ($oSubElement->hasAttribute('fontAlgn')) {
821 3
                    $oParagraph->getAlignment()->setVertical($oSubElement->getAttribute('fontAlgn'));
822 3
                }
823 4
                if ($oSubElement->hasAttribute('marL')) {
824 4
                    $oParagraph->getAlignment()->setMarginLeft(CommonDrawing::emuToPixels($oSubElement->getAttribute('marL')));
825 4
                }
826 4
                if ($oSubElement->hasAttribute('marR')) {
827 3
                    $oParagraph->getAlignment()->setMarginRight(CommonDrawing::emuToPixels($oSubElement->getAttribute('marR')));
828 3
                }
829 4
                if ($oSubElement->hasAttribute('indent')) {
830 3
                    $oParagraph->getAlignment()->setIndent(CommonDrawing::emuToPixels($oSubElement->getAttribute('indent')));
831 3
                }
832 4
                if ($oSubElement->hasAttribute('lvl')) {
833 4
                    $oParagraph->getAlignment()->setLevel($oSubElement->getAttribute('lvl'));
834 4
                }
835
836 4
                $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_NONE);
837
838 4
                $oElementBuFont = $document->getElement('a:buFont', $oSubElement);
839 4
                if ($oElementBuFont instanceof \DOMElement) {
840 3
                    if ($oElementBuFont->hasAttribute('typeface')) {
841 3
                        $oParagraph->getBulletStyle()->setBulletFont($oElementBuFont->getAttribute('typeface'));
842 3
                    }
843 3
                }
844 4
                $oElementBuChar = $document->getElement('a:buChar', $oSubElement);
845 4
                if ($oElementBuChar instanceof \DOMElement) {
846 3
                    $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET);
847 3
                    if ($oElementBuChar->hasAttribute('char')) {
848 3
                        $oParagraph->getBulletStyle()->setBulletChar($oElementBuChar->getAttribute('char'));
849 3
                    }
850 3
                }
851 4
                $oElementBuAutoNum = $document->getElement('a:buAutoNum', $oSubElement);
852 4
                if ($oElementBuAutoNum instanceof \DOMElement) {
853
                    $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_NUMERIC);
854
                    if ($oElementBuAutoNum->hasAttribute('type')) {
855
                        $oParagraph->getBulletStyle()->setBulletNumericStyle($oElementBuAutoNum->getAttribute('type'));
856
                    }
857
                    if ($oElementBuAutoNum->hasAttribute('startAt') && $oElementBuAutoNum->getAttribute('startAt') != 1) {
858
                        $oParagraph->getBulletStyle()->setBulletNumericStartAt($oElementBuAutoNum->getAttribute('startAt'));
859
                    }
860
                }
861 4
                $oElementBuClr = $document->getElement('a:buClr', $oSubElement);
862 4
                if ($oElementBuClr instanceof \DOMElement) {
863
                    $oColor = new Color();
864
                    /**
865
                     * @todo Create protected for reading Color
866
                     */
867
                    $oElementColor = $document->getElement('a:srgbClr', $oElementBuClr);
868
                    if ($oElementColor instanceof \DOMElement) {
869
                        $oColor->setRGB($oElementColor->hasAttribute('val') ? $oElementColor->getAttribute('val') : null);
870
                    }
871
                    $oParagraph->getBulletStyle()->setBulletColor($oColor);
872
                }
873 4
            }
874 4
            $arraySubElements = $document->getElements('(a:r|a:br)', $oElement);
875 4
            foreach ($arraySubElements as $oSubElement) {
876 4
                if ($oSubElement->tagName == 'a:br') {
877 3
                    $oParagraph->createBreak();
878 3
                }
879 4
                if ($oSubElement->tagName == 'a:r') {
880 4
                    $oElementrPr = $document->getElement('a:rPr', $oSubElement);
881 4
                    if (is_object($oElementrPr)) {
882 4
                        $oText = $oParagraph->createTextRun();
883
884 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...
885 3
                            $oText->getFont()->setBold($oElementrPr->getAttribute('b') == 'true' ? true : false);
886 3
                        }
887 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...
888 3
                            $oText->getFont()->setItalic($oElementrPr->getAttribute('i') == 'true' ? true : false);
889 3
                        }
890 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...
891 3
                            $oText->getFont()->setStrikethrough($oElementrPr->getAttribute('strike') == 'noStrike' ? false : true);
892 3
                        }
893 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...
894 3
                            $oText->getFont()->setSize((int)($oElementrPr->getAttribute('sz') / 100));
895 3
                        }
896 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...
897 3
                            $oText->getFont()->setUnderline($oElementrPr->getAttribute('u'));
898 3
                        }
899
                        // Color
900 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...
901 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...
902 3
                            $oColor = new Color();
903 3
                            $oColor->setRGB($oElementSrgbClr->getAttribute('val'));
904 3
                            $oText->getFont()->setColor($oColor);
905 3
                        }
906
                        // Hyperlink
907 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...
908 4
                        if (is_object($oElementHlinkClick)) {
909 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...
910 3
                                $oText->getHyperlink()->setTooltip($oElementHlinkClick->getAttribute('tooltip'));
911 3
                            }
912 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...
913 3
                                $oText->getHyperlink()->setUrl($this->arrayRels[$fileRels][$oElementHlinkClick->getAttribute('r:id')]['Target']);
914 3
                            }
915 3
                        }
916
                        //} else {
917
                        // $oText = $oParagraph->createText();
918
919 4
                        $oSubSubElement = $document->getElement('a:t', $oSubElement);
920 4
                        $oText->setText($oSubSubElement->nodeValue);
921 4
                    }
922 4
                }
923 4
            }
924 4
        }
925
926 4
        if (count($oShape->getParagraphs()) > 0) {
927 4
            $oShape->setActiveParagraph(0);
928 4
        }
929 4
    }
930
931
    /**
932
     *
933
     * @param string $fileRels
934
     * @return string
935
     */
936 4
    protected function loadRels($fileRels)
937
    {
938 4
        $sPart = $this->oZip->getFromName($fileRels);
939 4
        if ($sPart !== false) {
940 4
            $xmlReader = new XMLReader();
941 4
            if ($xmlReader->getDomFromString($sPart)) {
942 4
                foreach ($xmlReader->getElements('*') as $oNode) {
943 4
                    $this->arrayRels[$fileRels][$oNode->getAttribute('Id')] = array(
944 4
                        'Target' => $oNode->getAttribute('Target'),
945 4
                        'Type' => $oNode->getAttribute('Type'),
946
                    );
947 4
                }
948 4
            }
949 4
        }
950 4
    }
951
952
    /**
953
     * @param $oSlide
954
     * @param \DOMNodeList $oElements
955
     * @param XMLReader $xmlReader
956
     * @internal param $baseFile
957
     */
958 4
    private function loadSlideShapes($oSlide, $oElements, $xmlReader)
959
    {
960 4
        foreach ($oElements as $oNode) {
961 4
            switch ($oNode->tagName) {
962 4
                case 'p:pic':
963
                    $this->loadShapeDrawing($xmlReader, $oNode, $oSlide);
964
                    break;
965 4
                case 'p:sp':
966 4
                    $this->loadShapeRichText($xmlReader, $oNode, $oSlide);
967 4
                    break;
968 4
                default:
969
                    //var_export($oNode->tagName);
970 4
            }
971 4
        }
972 4
    }
973
}
974