Completed
Pull Request — develop (#230)
by Franck
09:07
created

PowerPoint2007::loadRels()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

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