Completed
Pull Request — develop (#306)
by
unknown
07:24
created

PowerPoint2007::loadSlide()   D

Complexity

Conditions 9
Paths 33

Size

Total Lines 41
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 9.0051

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 41
ccs 24
cts 25
cp 0.96
rs 4.909
cc 9
eloc 24
nc 33
nop 2
crap 9.0051
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
                if (is_object($oElement = $xmlReader->getElement($path))) {
205 4
                    if ($oElement->hasAttribute('xsi:type') && $oElement->getAttribute('xsi:type') == 'dcterms:W3CDTF') {
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...
206 4
                        $oDateTime = new \DateTime();
207 4
                        $oDateTime->createFromFormat(\DateTime::W3C, $oElement->nodeValue);
208 4
                        $oProperties->{$property}($oDateTime->getTimestamp());
209
                    } else {
210 4
                        $oProperties->{$property}($oElement->nodeValue);
211
                    }
212
                }
213
            }
214
        }
215 4
    }
216
217
    /**
218
     * Read Custom Properties
219
     * @param string $sPart
220
     */
221 1
    protected function loadCustomProperties($sPart)
222
    {
223 1
        $xmlReader = new XMLReader();
224 1
        $sPart = str_replace(' xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"', '', $sPart);
225 1
        if ($xmlReader->getDomFromString($sPart)) {
226 1
            $pathMarkAsFinal = '/Properties/property[@pid="2"][@fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"][@name="_MarkAsFinal"]/vt:bool';
227 1
            if (is_object($oElement = $xmlReader->getElement($pathMarkAsFinal))) {
228 1
                if ($oElement->nodeValue == 'true') {
229 1
                    $this->oPhpPresentation->getPresentationProperties()->markAsFinal(true);
230
                }
231
            }
232
        }
233 1
    }
234
235
    /**
236
     * Read View Properties
237
     * @param string $sPart
238
     */
239 4
    protected function loadViewProperties($sPart)
240
    {
241 4
        $xmlReader = new XMLReader();
242 4
        if ($xmlReader->getDomFromString($sPart)) {
243 4
            $pathZoom = '/p:viewPr/p:slideViewPr/p:cSldViewPr/p:cViewPr/p:scale/a:sx';
244 4
            if (is_object($oElement = $xmlReader->getElement($pathZoom))) {
245 3
                if ($oElement->hasAttribute('d') && $oElement->hasAttribute('n')) {
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...
246 3
                    $this->oPhpPresentation->getPresentationProperties()->setZoom($oElement->getAttribute('n') / $oElement->getAttribute('d'));
247
                }
248
            }
249
        }
250 4
    }
251
252
    /**
253
     * Extract all slides
254
     */
255 4
    protected function loadSlides($sPart)
256
    {
257 4
        $xmlReader = new XMLReader();
258 4
        if ($xmlReader->getDomFromString($sPart)) {
259 4
            $fileRels = 'ppt/_rels/presentation.xml.rels';
260 4
            $this->loadRels($fileRels);
261
            // Load the Masterslides
262 4
            $this->loadMasterSlides($xmlReader, $fileRels);
263
            // Continue with loading the slides
264 4
            foreach ($xmlReader->getElements('/p:presentation/p:sldIdLst/p:sldId') as $oElement) {
265 4
                $rId = $oElement->getAttribute('r:id');
266 4
                $pathSlide = isset($this->arrayRels[$fileRels][$rId]) ? $this->arrayRels[$fileRels][$rId]['Target'] : '';
267 4
                if (!empty($pathSlide)) {
268 4
                    $pptSlide = $this->oZip->getFromName('ppt/' . $pathSlide);
269 4
                    if ($pptSlide !== false) {
270 4
                        $this->loadRels('ppt/slides/_rels/' . basename($pathSlide) . '.rels');
271 4
                        $this->loadSlide($pptSlide, basename($pathSlide));
272
                    }
273
                }
274
            }
275
        }
276 4
    }
277
278
    /**
279
     * Extract all MasterSlides
280
     * @param XMLReader $xmlReader
281
     * @param $fileRels
282
     */
283 4
    protected function loadMasterSlides(XMLReader $xmlReader, $fileRels)
284
    {
285
        // Get all the MasterSlide Id's from the presentation.xml file
286 4
        foreach ($xmlReader->getElements('/p:presentation/p:sldMasterIdLst/p:sldMasterId') as $oElement) {
287 4
            $rId = $oElement->getAttribute('r:id');
288
            // Get the path to the masterslide from the array with _rels files
289 4
            $pathMasterSlide = isset($this->arrayRels[$fileRels][$rId]) ?
290 4
                $this->arrayRels[$fileRels][$rId]['Target'] : '';
291 4
            if (!empty($pathMasterSlide)) {
292 4
                $pptMasterSlide = $this->oZip->getFromName('ppt/' . $pathMasterSlide);
293 4
                if ($pptMasterSlide !== false) {
294 4
                    $this->loadRels('ppt/slideMasters/_rels/' . basename($pathMasterSlide) . '.rels');
295 4
                    $this->loadMasterSlide($pptMasterSlide, basename($pathMasterSlide));
296
                }
297
            }
298
        }
299 4
    }
300
301
    /**
302
     * Extract data from slide
303
     * @param string $sPart
304
     * @param string $baseFile
305
     */
306 4
    protected function loadSlide($sPart, $baseFile)
307
    {
308 4
        $xmlReader = new XMLReader();
309 4
        if ($xmlReader->getDomFromString($sPart)) {
310
            // Core
311 4
            $oSlide = $this->oPhpPresentation->createSlide();
312 4
            $this->oPhpPresentation->setActiveSlideIndex($this->oPhpPresentation->getSlideCount() - 1);
313 4
            $oSlide->setRelsIndex('ppt/slides/_rels/' . $baseFile . '.rels');
314
315
            // Background
316 4
            $oElement = $xmlReader->getElement('/p:sld/p:cSld/p:bg');
317 4
            if ($oElement) {
318
                $this->loadSlideBackground($xmlReader, $oElement, $oSlide);
0 ignored issues
show
Compatibility introduced by
$oElement of type object<DOMNode> is not a sub-type of object<DOMElement>. It seems like you assume a child class of the class DOMNode to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
319
            }
320
321
            // Shapes
322 4
            foreach ($xmlReader->getElements('/p:sld/p:cSld/p:spTree/*') as $oNode) {
323 4
                switch ($oNode->tagName) {
324 4
                    case 'p:pic':
325 3
                        $this->loadShapeDrawing($xmlReader, $oNode, $oSlide);
326 3
                        break;
327 4
                    case 'p:sp':
328 4
                        $this->loadShapeRichText($xmlReader, $oNode, $oSlide);
329 4
                        break;
330 4
                    default:
331
                        //var_export($oNode->tagName);
332
                }
333
            }
334
335
            // Layout
336 4
            foreach ($this->arrayRels[$oSlide->getRelsIndex()] as $valueRel) {
337 4
                if ($valueRel['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout') {
338 4
                    $layoutBasename = basename($valueRel['Target']);
339 4
                    if (array_key_exists($layoutBasename, $this->arraySlideLayouts)) {
340 4
                        $oSlide->setSlideLayout($this->arraySlideLayouts[$layoutBasename]);
341
                    }
342 4
                    break;
343
                }
344
            }
345
        }
346 4
    }
347
348 4
    private function loadMasterSlide($sPart, $baseFile)
349
    {
350 4
        $xmlReader = new XMLReader();
351 4
        if ($xmlReader->getDomFromString($sPart)) {
352
            // Core
353 4
            $oSlideMaster = $this->oPhpPresentation->createMasterSlide();
354 4
            $oSlideMaster->setTextStyles(new TextStyle(false));
355 4
            $oSlideMaster->setRelsIndex('ppt/slideMasters/_rels/' . $baseFile . '.rels');
356
357
            // Background
358 4
            $oElement = $xmlReader->getElement('/p:sldMaster/p:cSld/p:bg');
359 4
            if ($oElement) {
360 4
                $this->loadSlideBackground($xmlReader, $oElement, $oSlideMaster);
0 ignored issues
show
Compatibility introduced by
$oElement of type object<DOMNode> is not a sub-type of object<DOMElement>. It seems like you assume a child class of the class DOMNode to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
361
            }
362
363
            // Shapes
364 4
            $arrayElements = $xmlReader->getElements('/p:sldMaster/p:cSld/p:spTree/*');
365 4
            if ($arrayElements) {
366 4
                $this->loadSlideShapes($oSlideMaster, $arrayElements, $xmlReader);
367
            }
368
            // Header & Footer
369
370
            // ColorMapping
371 4
            $colorMap = array();
372 4
            $oElement = $xmlReader->getElement('/p:sldMaster/p:clrMap');
373 4
            if ($oElement->hasAttributes()) {
374 4
                foreach ($oElement->attributes as $attr) {
375 4
                    $colorMap[$attr->nodeName] = $attr->nodeValue;
376
                }
377 4
                $oSlideMaster->colorMap->setMapping($colorMap);
378
            }
379
380
            // TextStyles
381 4
            $arrayElementTxStyles = $xmlReader->getElements('/p:sldMaster/p:txStyles/*');
382 4
            if ($arrayElementTxStyles) {
383 4
                foreach ($arrayElementTxStyles as $oElementTxStyle) {
384 4
                    $arrayElementsLvl = $xmlReader->getElements('/p:sldMaster/p:txStyles/'.$oElementTxStyle->nodeName.'/*');
385 4
                    foreach ($arrayElementsLvl as $oElementLvl) {
386 4
                        if ($oElementLvl->nodeName == 'a:extLst') {
387 1
                            continue;
388
                        }
389 4
                        $oRTParagraph = new Paragraph();
390
391 4
                        if ($oElementLvl->nodeName == 'a:defPPr') {
392 3
                            $level = 0;
393
                        } else {
394 4
                            $level = str_replace('a:lvl', '', $oElementLvl->nodeName);
395 4
                            $level = str_replace('pPr', '', $level);
396
                        }
397
398 4
                        if ($oElementLvl->hasAttribute('algn')) {
399 4
                            $oRTParagraph->getAlignment()->setHorizontal($oElementLvl->getAttribute('algn'));
400
                        }
401 4
                        if ($oElementLvl->hasAttribute('marL')) {
402 4
                            $val = $oElementLvl->getAttribute('marL');
403 4
                            $val = CommonDrawing::emuToPixels($val);
404 4
                            $oRTParagraph->getAlignment()->setMarginLeft($val);
405
                        }
406 4
                        if ($oElementLvl->hasAttribute('marR')) {
407
                            $val = $oElementLvl->getAttribute('marR');
408
                            $val = CommonDrawing::emuToPixels($val);
409
                            $oRTParagraph->getAlignment()->setMarginRight($val);
410
                        }
411 4
                        if ($oElementLvl->hasAttribute('indent')) {
412 4
                            $val = $oElementLvl->getAttribute('indent');
413 4
                            $val = CommonDrawing::emuToPixels($val);
414 4
                            $oRTParagraph->getAlignment()->setIndent($val);
415
                        }
416 4
                        $oElementLvlDefRPR = $xmlReader->getElement('a:defRPr', $oElementLvl);
417 4
                        if ($oElementLvlDefRPR) {
418 4
                            if ($oElementLvlDefRPR->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...
419 4
                                $oRTParagraph->getFont()->setSize($oElementLvlDefRPR->getAttribute('sz') / 100);
420
                            }
421 4
                            if ($oElementLvlDefRPR->hasAttribute('b') && $oElementLvlDefRPR->getAttribute('b') == 1) {
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...
422 1
                                $oRTParagraph->getFont()->setBold(true);
423
                            }
424 4
                            if ($oElementLvlDefRPR->hasAttribute('i') && $oElementLvlDefRPR->getAttribute('i') == 1) {
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...
425
                                $oRTParagraph->getFont()->setItalic(true);
426
                            }
427
                        }
428 4
                        $oElementSchemeColor = $xmlReader->getElement('a:defRPr/a:solidFill/a:schemeClr', $oElementLvl);
429 4
                        if ($oElementSchemeColor) {
430 4
                            if ($oElementSchemeColor->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...
431 4
                                $oRTParagraph->getFont()->setColor(new SchemeColor())->getColor()->setValue($oElementSchemeColor->getAttribute('val'));
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class PhpOffice\PhpPresentation\Style\Color as the method setValue() does only exist in the following sub-classes of PhpOffice\PhpPresentation\Style\Color: PhpOffice\PhpPresentation\Style\SchemeColor. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
432
                            }
433
                        }
434
435 4
                        switch ($oElementTxStyle->nodeName) {
436 4
                            case 'p:bodyStyle':
437 4
                                $oSlideMaster->getTextStyles()->setBodyStyleAtLvl($oRTParagraph, $level);
438 4
                                break;
439 4
                            case 'p:otherStyle':
440 4
                                $oSlideMaster->getTextStyles()->setOtherStyleAtLvl($oRTParagraph, $level);
441 4
                                break;
442 4
                            case 'p:titleStyle':
443 4
                                $oSlideMaster->getTextStyles()->setTitleStyleAtLvl($oRTParagraph, $level);
444 4
                                break;
445
                        }
446
                    }
447
                }
448
            }
449
450
            // Load the theme
451 4
            foreach ($this->arrayRels[$oSlideMaster->getRelsIndex()] as $arrayRel) {
452 4
                if ($arrayRel['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme') {
453 4
                    $pptTheme = $this->oZip->getFromName('ppt/' . substr($arrayRel['Target'], strrpos($arrayRel['Target'], '../') + 3));
454 4
                    if ($pptTheme !== false) {
455 4
                        $this->loadTheme($pptTheme, $oSlideMaster);
456
                    }
457 4
                    break;
458
                }
459
            }
460
461
            // Load the Layoutslide
462 4
            foreach ($xmlReader->getElements('/p:sldMaster/p:sldLayoutIdLst/p:sldLayoutId') as $oElement) {
463 4
                $rId = $oElement->getAttribute('r:id');
464
                // Get the path to the masterslide from the array with _rels files
465 4
                $pathLayoutSlide = isset($this->arrayRels[$oSlideMaster->getRelsIndex()][$rId]) ?
466 4
                    $this->arrayRels[$oSlideMaster->getRelsIndex()][$rId]['Target'] : '';
467 4
                if (!empty($pathLayoutSlide)) {
468 4
                    $pptLayoutSlide = $this->oZip->getFromName('ppt/' . substr($pathLayoutSlide, strrpos($pathLayoutSlide, '../') + 3));
469 4
                    if ($pptLayoutSlide !== false) {
470 4
                        $this->loadRels('ppt/slideLayouts/_rels/' . basename($pathLayoutSlide) . '.rels');
471 4
                        $oSlideMaster->addSlideLayout(
472 4
                            $this->loadLayoutSlide($pptLayoutSlide, basename($pathLayoutSlide), $oSlideMaster)
473
                        );
474
                    }
475
                }
476
            }
477
        }
478 4
    }
479
480 4
    private function loadLayoutSlide($sPart, $baseFile, SlideMaster $oSlideMaster)
481
    {
482 4
        $xmlReader = new XMLReader();
483 4
        if ($xmlReader->getDomFromString($sPart)) {
484
            // Core
485 4
            $oSlideLayout = new SlideLayout($oSlideMaster);
486 4
            $oSlideLayout->setRelsIndex('ppt/slideLayouts/_rels/' . $baseFile . '.rels');
487
488
            // Name
489 4
            $oElement = $xmlReader->getElement('/p:sldLayout/p:cSld');
490 4
            if ($oElement && $oElement->hasAttribute('name')) {
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...
491 4
                $oSlideLayout->setLayoutName($oElement->getAttribute('name'));
492
            }
493
494
            // Background
495 4
            $oElement = $xmlReader->getElement('/p:sldLayout/p:cSld/p:bg');
496 4
            if ($oElement) {
497 1
                $this->loadSlideBackground($xmlReader, $oElement, $oSlideLayout);
0 ignored issues
show
Compatibility introduced by
$oElement of type object<DOMNode> is not a sub-type of object<DOMElement>. It seems like you assume a child class of the class DOMNode to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
498
            }
499
500
            // ColorMapping
501 4
            $oElement = $xmlReader->getElement('/p:sldLayout/p:clrMapOvr/a:overrideClrMapping');
502 4
            if ($oElement && $oElement->hasAttributes()) {
503 1
                $colorMap = array();
504 1
                foreach ($oElement->attributes as $attr) {
505 1
                    $colorMap[$attr->nodeName] = $attr->nodeValue;
506
                }
507 1
                $oSlideLayout->colorMap->setMapping($colorMap);
508
            }
509
510
            // Shapes
511 4
            $oElements = $xmlReader->getElements('/p:sldLayout/p:cSld/p:spTree/*');
512 4
            if ($oElements) {
513 4
                $this->loadSlideShapes($oSlideLayout, $oElements, $xmlReader);
514
            }
515 4
            $this->arraySlideLayouts[$baseFile] = &$oSlideLayout;
516 4
            return $oSlideLayout;
517
        }
518
        return null;
519
    }
520
521
    /**
522
     * @param string $sPart
523
     * @param SlideMaster $oSlideMaster
524
     */
525 4
    private function loadTheme($sPart, SlideMaster $oSlideMaster)
526
    {
527 4
        $xmlReader = new XMLReader();
528 4
        if ($xmlReader->getDomFromString($sPart)) {
529 4
            $oElements = $xmlReader->getElements('/a:theme/a:themeElements/a:clrScheme/*');
530 4
            if ($oElements) {
531 4
                foreach ($oElements as $oElement) {
532 4
                    $oSchemeColor = new SchemeColor();
533 4
                    $oSchemeColor->setValue(str_replace('a:', '', $oElement->tagName));
534 4
                    $colorElement = $xmlReader->getElement('*', $oElement);
535 4
                    if ($colorElement) {
536 4
                        if ($colorElement->hasAttribute('lastClr')) {
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...
537 4
                            $oSchemeColor->setRGB($colorElement->getAttribute('lastClr'));
538 4
                        } elseif ($colorElement->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...
539 4
                            $oSchemeColor->setRGB($colorElement->getAttribute('val'));
540
                        }
541
                    }
542 4
                    $oSlideMaster->addSchemeColor($oSchemeColor);
543
                }
544
            }
545
        }
546 4
    }
547
548
    /**
549
     * @param XMLReader $xmlReader
550
     * @param \DOMElement $oElement
551
     * @param AbstractSlide $oSlide
552
     */
553 4
    private function loadSlideBackground(XMLReader $xmlReader, \DOMElement $oElement, AbstractSlide $oSlide)
554
    {
555
        // Background color
556 4
        $oElementColor = $xmlReader->getElement('p:bgPr/a:solidFill/a:srgbClr', $oElement);
557 4
        if ($oElementColor) {
558
            // Color
559
            $oColor = new Color();
560
            $oColor->setRGB($oElementColor->hasAttribute('val') ? $oElementColor->getAttribute('val') : null);
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...
561
            // Background
562
            $oBackground = new \PhpOffice\PhpPresentation\Slide\Background\Color();
563
            $oBackground->setColor($oColor);
564
            // Slide Background
565
            $oSlide->setBackground($oBackground);
566
        }
567
568
        // Background scheme color
569 4
        $oElementSchemeColor = $xmlReader->getElement('p:bgRef/a:schemeClr', $oElement);
570 4
        if ($oElementSchemeColor) {
571
            // Color
572 4
            $oColor = new SchemeColor();
573 4
            $oColor->setValue($oElementSchemeColor->hasAttribute('val') ? $oElementSchemeColor->getAttribute('val') : null);
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...
574
            // Background
575 4
            $oBackground = new \PhpOffice\PhpPresentation\Slide\Background\SchemeColor();
576 4
            $oBackground->setSchemeColor($oColor);
577
            // Slide Background
578 4
            $oSlide->setBackground($oBackground);
579
        }
580
581
        // Background image
582 4
        $oElementImage = $xmlReader->getElement('p:bgPr/a:blipFill/a:blip', $oElement);
583 4
        if ($oElementImage) {
584
            $relImg = $this->arrayRels[$oSlide->getRelsIndex()][$oElementImage->getAttribute('r:embed')];
585
            if (is_array($relImg)) {
586
                // File
587
                $pathImage = 'ppt/slides/' . $relImg['Target'];
588
                $pathImage = explode('/', $pathImage);
589
                foreach ($pathImage as $key => $partPath) {
590
                    if ($partPath == '..') {
591
                        unset($pathImage[$key - 1]);
592
                        unset($pathImage[$key]);
593
                    }
594
                }
595
                $pathImage = implode('/', $pathImage);
596
                $contentImg = $this->oZip->getFromName($pathImage);
597
598
                $tmpBkgImg = tempnam(sys_get_temp_dir(), 'PhpPresentationReaderPpt2007Bkg');
599
                file_put_contents($tmpBkgImg, $contentImg);
600
                // Background
601
                $oBackground = new Image();
602
                $oBackground->setPath($tmpBkgImg);
603
                // Slide Background
604
                $oSlide->setBackground($oBackground);
605
            }
606
        }
607 4
    }
608
609
    /**
610
     *
611
     * @param XMLReader $document
612
     * @param \DOMElement $node
613
     * @param AbstractSlide $oSlide
614
     */
615 3
    protected function loadShapeDrawing(XMLReader $document, \DOMElement $node, AbstractSlide $oSlide)
616
    {
617
        // Core
618 3
        $oShape = new Gd();
619 3
        $oShape->getShadow()->setVisible(false);
620
        // Variables
621 3
        $fileRels = $oSlide->getRelsIndex();
622
623 3
        $oElement = $document->getElement('p:nvPicPr/p:cNvPr', $node);
624 3
        if ($oElement) {
625 3
            $oShape->setName($oElement->hasAttribute('name') ? $oElement->getAttribute('name') : '');
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...
626 3
            $oShape->setDescription($oElement->hasAttribute('descr') ? $oElement->getAttribute('descr') : '');
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...
627
        }
628
629 3
        $oElement = $document->getElement('p:blipFill/a:blip', $node);
630 3
        if ($oElement) {
631 3
            if ($oElement->hasAttribute('r:embed') && isset($this->arrayRels[$fileRels][$oElement->getAttribute('r:embed')]['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...
632 3
                $pathImage = 'ppt/slides/' . $this->arrayRels[$fileRels][$oElement->getAttribute('r:embed')]['Target'];
633 3
                $pathImage = explode('/', $pathImage);
634 3
                foreach ($pathImage as $key => $partPath) {
635 3
                    if ($partPath == '..') {
636 3
                        unset($pathImage[$key - 1]);
637 3
                        unset($pathImage[$key]);
638
                    }
639
                }
640 3
                $pathImage = implode('/', $pathImage);
641 3
                $imageFile = $this->oZip->getFromName($pathImage);
642 3
                if (!empty($imageFile)) {
643 3
                    $oShape->setImageResource(imagecreatefromstring($imageFile));
644
                }
645
            }
646
        }
647
648 3
        $oElement = $document->getElement('p:spPr/a:xfrm', $node);
649 3
        if ($oElement) {
650 3
            if ($oElement->hasAttribute('rot')) {
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...
651 3
                $oShape->setRotation(CommonDrawing::angleToDegrees($oElement->getAttribute('rot')));
652
            }
653
        }
654
655 3
        $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node);
656 3
        if ($oElement) {
657 3
            if ($oElement->hasAttribute('x')) {
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...
658 3
                $oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x')));
659
            }
660 3
            if ($oElement->hasAttribute('y')) {
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...
661 3
                $oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y')));
662
            }
663
        }
664
665 3
        $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node);
666 3
        if ($oElement) {
667 3
            if ($oElement->hasAttribute('cx')) {
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...
668 3
                $oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx')));
669
            }
670 3
            if ($oElement->hasAttribute('cy')) {
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...
671 3
                $oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy')));
672
            }
673
        }
674
675 3
        $oElement = $document->getElement('p:spPr/a:effectLst', $node);
676 3
        if ($oElement) {
677 3
            $oShape->getShadow()->setVisible(true);
678
679 3
            $oSubElement = $document->getElement('a:outerShdw', $oElement);
0 ignored issues
show
Documentation introduced by
$oElement 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...
680 3
            if ($oSubElement) {
681 3
                if ($oSubElement->hasAttribute('blurRad')) {
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...
682 3
                    $oShape->getShadow()->setBlurRadius(CommonDrawing::emuToPixels($oSubElement->getAttribute('blurRad')));
683
                }
684 3
                if ($oSubElement->hasAttribute('dist')) {
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...
685 3
                    $oShape->getShadow()->setDistance(CommonDrawing::emuToPixels($oSubElement->getAttribute('dist')));
686
                }
687 3
                if ($oSubElement->hasAttribute('dir')) {
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...
688 3
                    $oShape->getShadow()->setDirection(CommonDrawing::angleToDegrees($oSubElement->getAttribute('dir')));
689
                }
690 3
                if ($oSubElement->hasAttribute('algn')) {
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...
691 3
                    $oShape->getShadow()->setAlignment($oSubElement->getAttribute('algn'));
692
                }
693
            }
694
695 3
            $oSubElement = $document->getElement('a:outerShdw/a:srgbClr', $oElement);
0 ignored issues
show
Documentation introduced by
$oElement 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...
696 3
            if ($oSubElement) {
697 3
                if ($oSubElement->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...
698 3
                    $oColor = new Color();
699 3
                    $oColor->setRGB($oSubElement->getAttribute('val'));
700 3
                    $oShape->getShadow()->setColor($oColor);
701
                }
702
            }
703
704 3
            $oSubElement = $document->getElement('a:outerShdw/a:srgbClr/a:alpha', $oElement);
0 ignored issues
show
Documentation introduced by
$oElement 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...
705 3
            if ($oSubElement) {
706 3
                if ($oSubElement->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...
707 3
                    $oShape->getShadow()->setAlpha((int)$oSubElement->getAttribute('val') / 1000);
708
                }
709
            }
710
        }
711
712 3
        $oSlide->addShape($oShape);
713 3
    }
714
715
    /**
716
     * @param XMLReader $document
717
     * @param \DOMElement $node
718
     * @param AbstractSlide $oSlide
719
     * @throws \Exception
720
     */
721 4
    protected function loadShapeRichText(XMLReader $document, \DOMElement $node, AbstractSlide $oSlide)
722
    {
723
        // Core
724 4
        $oShape = $oSlide->createRichTextShape();
725 4
        $oShape->setParagraphs(array());
726
        // Variables
727 4
        $fileRels = $oSlide->getRelsIndex();
728
729 4
        $oElement = $document->getElement('p:spPr/a:xfrm', $node);
730 4
        if ($oElement && $oElement->hasAttribute('rot')) {
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...
731 4
            $oShape->setRotation(CommonDrawing::angleToDegrees($oElement->getAttribute('rot')));
732
        }
733
734 4
        $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node);
735 4
        if ($oElement) {
736 4
            if ($oElement->hasAttribute('x')) {
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...
737 4
                $oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x')));
738
            }
739 4
            if ($oElement->hasAttribute('y')) {
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...
740 4
                $oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y')));
741
            }
742
        }
743
744 4
        $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node);
745 4
        if ($oElement) {
746 4
            if ($oElement->hasAttribute('cx')) {
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...
747 4
                $oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx')));
748
            }
749 4
            if ($oElement->hasAttribute('cy')) {
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...
750 4
                $oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy')));
751
            }
752
        }
753
754 4
        $oElement = $document->getElement('p:nvSpPr/p:nvPr/p:ph', $node);
755 4
        if ($oElement) {
756 4
            if ($oElement->hasAttribute('type')) {
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...
757 4
                $placeholder = new Placeholder($oElement->getAttribute('type'));
758 4
                $oShape->setPlaceHolder($placeholder);
759
            }
760
        }
761
762 4
        $arrayElements = $document->getElements('p:txBody/a:p', $node);
763 4
        foreach ($arrayElements as $oElement) {
764
            // Core
765 4
            $oParagraph = $oShape->createParagraph();
766 4
            $oParagraph->setRichTextElements(array());
767
768 4
            $oSubElement = $document->getElement('a:pPr', $oElement);
769 4
            if ($oSubElement) {
770 4
                if ($oSubElement->hasAttribute('algn')) {
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...
771 4
                    $oParagraph->getAlignment()->setHorizontal($oSubElement->getAttribute('algn'));
772
                }
773 4
                if ($oSubElement->hasAttribute('fontAlgn')) {
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...
774 3
                    $oParagraph->getAlignment()->setVertical($oSubElement->getAttribute('fontAlgn'));
775
                }
776 4
                if ($oSubElement->hasAttribute('marL')) {
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...
777 4
                    $oParagraph->getAlignment()->setMarginLeft(CommonDrawing::emuToPixels($oSubElement->getAttribute('marL')));
778
                }
779 4
                if ($oSubElement->hasAttribute('marR')) {
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...
780 3
                    $oParagraph->getAlignment()->setMarginRight(CommonDrawing::emuToPixels($oSubElement->getAttribute('marR')));
781
                }
782 4
                if ($oSubElement->hasAttribute('indent')) {
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...
783 3
                    $oParagraph->getAlignment()->setIndent(CommonDrawing::emuToPixels($oSubElement->getAttribute('indent')));
784
                }
785 4
                if ($oSubElement->hasAttribute('lvl')) {
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...
786 4
                    $oParagraph->getAlignment()->setLevel($oSubElement->getAttribute('lvl'));
787
                }
788
789 4
                $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_NONE);
790
791 4
                $oElementBuFont = $document->getElement('a:buFont', $oSubElement);
0 ignored issues
show
Documentation introduced by
$oSubElement 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...
792 4
                if ($oElementBuFont) {
793 3
                    if ($oElementBuFont->hasAttribute('typeface')) {
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...
794 3
                        $oParagraph->getBulletStyle()->setBulletFont($oElementBuFont->getAttribute('typeface'));
795
                    }
796
                }
797 4
                $oElementBuChar = $document->getElement('a:buChar', $oSubElement);
0 ignored issues
show
Documentation introduced by
$oSubElement 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...
798 4
                if ($oElementBuChar) {
799 3
                    $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET);
800 3
                    if ($oElementBuChar->hasAttribute('char')) {
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...
801 3
                        $oParagraph->getBulletStyle()->setBulletChar($oElementBuChar->getAttribute('char'));
802
                    }
803
                }
804 4
                $oElementBuAutoNum = $document->getElement('a:buAutoNum', $oSubElement);
0 ignored issues
show
Documentation introduced by
$oSubElement 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...
805 4
                if ($oElementBuAutoNum) {
806
                    $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_NUMERIC);
807
                    if ($oElementBuAutoNum->hasAttribute('type')) {
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...
808
                        $oParagraph->getBulletStyle()->setBulletNumericStyle($oElementBuAutoNum->getAttribute('type'));
809
                    }
810
                    if ($oElementBuAutoNum->hasAttribute('startAt') && $oElementBuAutoNum->getAttribute('startAt') != 1) {
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...
811
                        $oParagraph->getBulletStyle()->setBulletNumericStartAt($oElementBuAutoNum->getAttribute('startAt'));
812
                    }
813
                }
814 4
                $oElementBuClr = $document->getElement('a:buClr', $oSubElement);
0 ignored issues
show
Documentation introduced by
$oSubElement 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...
815 4
                if ($oElementBuClr) {
816
                    $oColor = new Color();
817
                    /**
818
                     * @todo Create protected for reading Color
819
                     */
820
                    $oElementColor = $document->getElement('a:srgbClr', $oElementBuClr);
0 ignored issues
show
Documentation introduced by
$oElementBuClr 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...
821
                    if ($oElementColor) {
822
                        $oColor->setRGB($oElementColor->hasAttribute('val') ? $oElementColor->getAttribute('val') : null);
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...
823
                    }
824
                    $oParagraph->getBulletStyle()->setBulletColor($oColor);
825
                }
826
            }
827 4
            $arraySubElements = $document->getElements('(a:r|a:br)', $oElement);
828 4
            foreach ($arraySubElements as $oSubElement) {
829 4
                if ($oSubElement->tagName == 'a:br') {
830 3
                    $oParagraph->createBreak();
831
                }
832 4
                if ($oSubElement->tagName == 'a:r') {
833 4
                    $oElementrPr = $document->getElement('a:rPr', $oSubElement);
834 4
                    if (is_object($oElementrPr)) {
835 4
                        $oText = $oParagraph->createTextRun();
836
837 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...
838 3
                            $oText->getFont()->setBold($oElementrPr->getAttribute('b') == 'true' ? true : false);
839
                        }
840 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...
841 3
                            $oText->getFont()->setItalic($oElementrPr->getAttribute('i') == 'true' ? true : false);
842
                        }
843 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...
844 3
                            $oText->getFont()->setStrikethrough($oElementrPr->getAttribute('strike') == 'noStrike' ? false : true);
845
                        }
846 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...
847 3
                            $oText->getFont()->setSize((int)($oElementrPr->getAttribute('sz') / 100));
848
                        }
849 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...
850 3
                            $oText->getFont()->setUnderline($oElementrPr->getAttribute('u'));
851
                        }
852
                        // Color
853 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...
854 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...
855 3
                            $oColor = new Color();
856 3
                            $oColor->setRGB($oElementSrgbClr->getAttribute('val'));
857 3
                            $oText->getFont()->setColor($oColor);
858
                        }
859
                        // Hyperlink
860 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...
861 4
                        if (is_object($oElementHlinkClick)) {
862 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...
863 3
                                $oText->getHyperlink()->setTooltip($oElementHlinkClick->getAttribute('tooltip'));
864
                            }
865 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...
866 3
                                $oText->getHyperlink()->setUrl($this->arrayRels[$fileRels][$oElementHlinkClick->getAttribute('r:id')]['Target']);
867
                            }
868
                        }
869
                        //} else {
870
                        // $oText = $oParagraph->createText();
871
872 4
                        $oSubSubElement = $document->getElement('a:t', $oSubElement);
873 4
                        $oText->setText($oSubSubElement->nodeValue);
874
                    }
875
                }
876
            }
877
        }
878
879 4
        if (count($oShape->getParagraphs()) > 0) {
880 4
            $oShape->setActiveParagraph(0);
881
        }
882 4
    }
883
884
    /**
885
     *
886
     * @param string $fileRels
887
     * @return string
888
     */
889 4
    protected function loadRels($fileRels)
890
    {
891 4
        $sPart = $this->oZip->getFromName($fileRels);
892 4
        if ($sPart !== false) {
893 4
            $xmlReader = new XMLReader();
894 4
            if ($xmlReader->getDomFromString($sPart)) {
895 4
                foreach ($xmlReader->getElements('*') as $oNode) {
896 4
                    $this->arrayRels[$fileRels][$oNode->getAttribute('Id')] = array(
897 4
                        'Target' => $oNode->getAttribute('Target'),
898 4
                        'Type' => $oNode->getAttribute('Type'),
899
                    );
900
                }
901
            }
902
        }
903 4
    }
904
905
    /**
906
     * @param $oSlide
907
     * @param $oElements
908
     * @param $xmlReader
909
     * @internal param $baseFile
910
     */
911 4
    private function loadSlideShapes($oSlide, $oElements, $xmlReader)
912
    {
913 4
        foreach ($oElements as $oNode) {
914 4
            switch ($oNode->tagName) {
915 4
                case 'p:pic':
916
                    $this->loadShapeDrawing($xmlReader, $oNode, $oSlide);
917
                    break;
918 4
                case 'p:sp':
919 4
                    $this->loadShapeRichText($xmlReader, $oNode, $oSlide);
920 4
                    break;
921 4
                default:
922
                    //var_export($oNode->tagName);
923
            }
924
        }
925 4
    }
926
}
927