Complex classes like PowerPoint2007 often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PowerPoint2007, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 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 | protected $arraySlideLayouts = array(); |
||
| 61 | /* |
||
| 62 | * @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 | */ |
||
| 73 | 2 | public function canRead($pFilename) |
|
| 77 | |||
| 78 | /** |
||
| 79 | * Does a file support UnserializePhpPresentation ? |
||
| 80 | * |
||
| 81 | * @param string $pFilename |
||
| 82 | * @throws \Exception |
||
| 83 | * @return boolean |
||
| 84 | */ |
||
| 85 | 8 | public function fileSupportsUnserializePhpPresentation($pFilename = '') |
|
| 86 | { |
||
| 87 | // Check if file exists |
||
| 88 | 8 | if (!file_exists($pFilename)) { |
|
| 89 | 2 | throw new \Exception("Could not open " . $pFilename . " for reading! File does not exist."); |
|
| 90 | } |
||
| 91 | |||
| 92 | 6 | $oZip = new ZipArchive(); |
|
| 93 | // Is it a zip ? |
||
| 94 | 6 | if ($oZip->open($pFilename) === true) { |
|
| 95 | // Is it an OpenXML Document ? |
||
| 96 | // Is it a Presentation ? |
||
| 97 | 4 | if (is_array($oZip->statName('[Content_Types].xml')) && is_array($oZip->statName('ppt/presentation.xml'))) { |
|
| 98 | 4 | return true; |
|
| 99 | } |
||
| 100 | } |
||
| 101 | 3 | return false; |
|
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Loads PhpPresentation Serialized file |
||
| 106 | * |
||
| 107 | * @param string $pFilename |
||
| 108 | * @return \PhpOffice\PhpPresentation\PhpPresentation |
||
| 109 | * @throws \Exception |
||
| 110 | */ |
||
| 111 | 5 | public function load($pFilename) |
|
| 120 | |||
| 121 | /** |
||
| 122 | * Load PhpPresentation Serialized file |
||
| 123 | * |
||
| 124 | * @param string $pFilename |
||
| 125 | * @return \PhpOffice\PhpPresentation\PhpPresentation |
||
| 126 | */ |
||
| 127 | 3 | protected function loadFile($pFilename) |
|
| 128 | { |
||
| 129 | 3 | $this->oPhpPresentation = new PhpPresentation(); |
|
| 130 | 3 | $this->oPhpPresentation->removeSlideByIndex(); |
|
| 131 | 3 | $this->oPhpPresentation->setAllMasterSlides(array()); |
|
| 132 | 3 | $this->filename = $pFilename; |
|
| 133 | |||
| 134 | 3 | $this->oZip = new ZipArchive(); |
|
| 135 | 3 | $this->oZip->open($this->filename); |
|
| 136 | 3 | $docPropsCore = $this->oZip->getFromName('docProps/core.xml'); |
|
| 137 | 3 | if ($docPropsCore !== false) { |
|
| 138 | 3 | $this->loadDocumentProperties($docPropsCore); |
|
| 139 | } |
||
| 140 | |||
| 141 | 3 | $docPropsCustom = $this->oZip->getFromName('docProps/custom.xml'); |
|
| 142 | 3 | if ($docPropsCustom !== false) { |
|
| 143 | 1 | $this->loadCustomProperties($docPropsCustom); |
|
| 144 | } |
||
| 145 | |||
| 146 | 3 | $pptViewProps = $this->oZip->getFromName('ppt/viewProps.xml'); |
|
| 147 | 3 | if ($pptViewProps !== false) { |
|
| 148 | 3 | $this->loadViewProperties($pptViewProps); |
|
| 149 | } |
||
| 150 | |||
| 151 | 3 | $pptPresentation = $this->oZip->getFromName('ppt/presentation.xml'); |
|
| 152 | 3 | if ($pptPresentation !== false) { |
|
| 153 | 3 | $this->loadSlides($pptPresentation); |
|
| 154 | } |
||
| 155 | |||
| 156 | 3 | return $this->oPhpPresentation; |
|
| 157 | } |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Read Document Properties |
||
| 161 | * @param string $sPart |
||
| 162 | */ |
||
| 163 | 3 | protected function loadDocumentProperties($sPart) |
|
| 164 | { |
||
| 165 | 3 | $xmlReader = new XMLReader(); |
|
| 166 | 3 | if ($xmlReader->getDomFromString($sPart)) { |
|
| 167 | $arrayProperties = array( |
||
| 168 | 3 | '/cp:coreProperties/dc:creator' => 'setCreator', |
|
| 169 | '/cp:coreProperties/cp:lastModifiedBy' => 'setLastModifiedBy', |
||
| 170 | '/cp:coreProperties/dc:title' => 'setTitle', |
||
| 171 | '/cp:coreProperties/dc:description' => 'setDescription', |
||
| 172 | '/cp:coreProperties/dc:subject' => 'setSubject', |
||
| 173 | '/cp:coreProperties/cp:keywords' => 'setKeywords', |
||
| 174 | '/cp:coreProperties/cp:category' => 'setCategory', |
||
| 175 | '/cp:coreProperties/dcterms:created' => 'setCreated', |
||
| 176 | '/cp:coreProperties/dcterms:modified' => 'setModified', |
||
| 177 | ); |
||
| 178 | 3 | $oProperties = $this->oPhpPresentation->getDocumentProperties(); |
|
| 179 | 3 | foreach ($arrayProperties as $path => $property) { |
|
| 180 | 3 | if (is_object($oElement = $xmlReader->getElement($path))) { |
|
| 181 | 3 | if ($oElement->hasAttribute('xsi:type') && $oElement->getAttribute('xsi:type') == 'dcterms:W3CDTF') { |
|
|
|
|||
| 182 | 3 | $oDateTime = new \DateTime(); |
|
| 183 | 3 | $oDateTime->createFromFormat(\DateTime::W3C, $oElement->nodeValue); |
|
| 184 | 3 | $oProperties->{$property}($oDateTime->getTimestamp()); |
|
| 185 | } else { |
||
| 186 | 3 | $oProperties->{$property}($oElement->nodeValue); |
|
| 187 | } |
||
| 188 | } |
||
| 189 | } |
||
| 190 | } |
||
| 191 | 3 | } |
|
| 192 | |||
| 193 | /** |
||
| 194 | * Read Custom Properties |
||
| 195 | * @param string $sPart |
||
| 196 | */ |
||
| 197 | 1 | protected function loadCustomProperties($sPart) |
|
| 198 | { |
||
| 199 | 1 | $xmlReader = new XMLReader(); |
|
| 200 | 1 | $sPart = str_replace(' xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"', '', $sPart); |
|
| 201 | 1 | if ($xmlReader->getDomFromString($sPart)) { |
|
| 202 | 1 | $pathMarkAsFinal = '/Properties/property[@pid="2"][@fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"][@name="_MarkAsFinal"]/vt:bool'; |
|
| 203 | 1 | if (is_object($oElement = $xmlReader->getElement($pathMarkAsFinal))) { |
|
| 204 | 1 | if ($oElement->nodeValue == 'true') { |
|
| 205 | 1 | $this->oPhpPresentation->getPresentationProperties()->markAsFinal(true); |
|
| 206 | } |
||
| 207 | } |
||
| 208 | } |
||
| 209 | 1 | } |
|
| 210 | |||
| 211 | /** |
||
| 212 | * Read View Properties |
||
| 213 | * @param string $sPart |
||
| 214 | */ |
||
| 215 | 3 | protected function loadViewProperties($sPart) |
|
| 216 | { |
||
| 217 | 3 | $xmlReader = new XMLReader(); |
|
| 218 | 3 | 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 | 2 | if ($oElement->hasAttribute('d') && $oElement->hasAttribute('n')) { |
|
| 222 | 2 | $this->oPhpPresentation->getPresentationProperties()->setZoom($oElement->getAttribute('n') / $oElement->getAttribute('d')); |
|
| 223 | } |
||
| 224 | } |
||
| 225 | } |
||
| 226 | 3 | } |
|
| 227 | |||
| 228 | /** |
||
| 229 | * Extract all slides |
||
| 230 | */ |
||
| 231 | 3 | protected function loadSlides($sPart) |
|
| 253 | |||
| 254 | /** |
||
| 255 | * Extract all MasterSlides |
||
| 256 | * @param XMLReader $xmlReader |
||
| 257 | * @param $fileRels |
||
| 258 | */ |
||
| 259 | 3 | protected function loadMasterSlides(XMLReader $xmlReader, $fileRels) |
|
| 276 | |||
| 277 | /** |
||
| 278 | * Extract data from slide |
||
| 279 | * @param string $sPart |
||
| 280 | * @param string $baseFile |
||
| 281 | */ |
||
| 282 | 3 | protected function loadSlide($sPart, $baseFile) |
|
| 283 | { |
||
| 284 | 3 | $xmlReader = new XMLReader(); |
|
| 285 | 3 | if ($xmlReader->getDomFromString($sPart)) { |
|
| 286 | // Core |
||
| 287 | 3 | $oSlide = $this->oPhpPresentation->createSlide(); |
|
| 288 | 3 | $this->oPhpPresentation->setActiveSlideIndex($this->oPhpPresentation->getSlideCount() - 1); |
|
| 289 | 3 | $oSlide->setRelsIndex('ppt/slides/_rels/' . $baseFile . '.rels'); |
|
| 290 | |||
| 291 | // Background |
||
| 292 | 3 | $oElement = $xmlReader->getElement('/p:sld/p:cSld/p:bg/p:bgPr'); |
|
| 293 | 3 | if ($oElement) { |
|
| 294 | $oElementColor = $xmlReader->getElement('a:solidFill/a:srgbClr', $oElement); |
||
| 295 | if ($oElementColor) { |
||
| 296 | // Color |
||
| 297 | $oColor = new Color(); |
||
| 298 | $oColor->setRGB($oElementColor->hasAttribute('val') ? $oElementColor->getAttribute('val') : null); |
||
| 299 | // Background |
||
| 300 | $oBackground = new \PhpOffice\PhpPresentation\Slide\Background\Color(); |
||
| 301 | $oBackground->setColor($oColor); |
||
| 302 | // Slide Background |
||
| 303 | $oSlide = $this->oPhpPresentation->getActiveSlide(); |
||
| 304 | $oSlide->setBackground($oBackground); |
||
| 305 | } |
||
| 306 | $oElementImage = $xmlReader->getElement('a:blipFill/a:blip', $oElement); |
||
| 307 | if ($oElementImage) { |
||
| 308 | $relImg = $this->arrayRels['ppt/slides/_rels/' . $baseFile . '.rels'][$oElementImage->getAttribute('r:embed')]; |
||
| 309 | if (is_array($relImg)) { |
||
| 310 | // File |
||
| 311 | $pathImage = 'ppt/slides/' . $relImg['Target']; |
||
| 312 | $pathImage = explode('/', $pathImage); |
||
| 313 | foreach ($pathImage as $key => $partPath) { |
||
| 314 | if ($partPath == '..') { |
||
| 315 | unset($pathImage[$key - 1]); |
||
| 316 | unset($pathImage[$key]); |
||
| 317 | } |
||
| 318 | } |
||
| 319 | $pathImage = implode('/', $pathImage); |
||
| 320 | $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 | $oSlide = $this->oPhpPresentation->getActiveSlide(); |
||
| 329 | $oSlide->setBackground($oBackground); |
||
| 330 | } |
||
| 331 | } |
||
| 332 | } |
||
| 333 | |||
| 334 | // Shapes |
||
| 335 | 3 | 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 | 3 | $this->loadShapeRichText($xmlReader, $oNode, $oSlide); |
|
| 342 | 3 | break; |
|
| 343 | 3 | default: |
|
| 344 | //var_export($oNode->tagName); |
||
| 345 | } |
||
| 346 | } |
||
| 347 | // 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 | } |
||
| 355 | 3 | break; |
|
| 356 | } |
||
| 357 | } |
||
| 358 | } |
||
| 359 | 3 | } |
|
| 360 | |||
| 361 | 3 | private function loadMasterSlide($sPart, $baseFile) |
|
| 492 | |||
| 493 | 3 | private function loadLayoutSlide($sPart, $baseFile, SlideMaster $oSlideMaster) |
|
| 533 | |||
| 534 | /** |
||
| 535 | * @param string $sPart |
||
| 536 | * @param SlideMaster $oSlideMaster |
||
| 537 | */ |
||
| 538 | 3 | private function loadTheme($sPart, SlideMaster $oSlideMaster) |
|
| 560 | |||
| 561 | /** |
||
| 562 | * @param XMLReader $xmlReader |
||
| 563 | * @param \DOMElement $oElement |
||
| 564 | * @param AbstractSlide $oSlide |
||
| 565 | */ |
||
| 566 | 3 | private function loadSlideBackground(XMLReader $xmlReader, \DOMElement $oElement, AbstractSlide $oSlide) |
|
| 621 | |||
| 622 | /** |
||
| 623 | * |
||
| 624 | * @param XMLReader $document |
||
| 625 | * @param \DOMElement $node |
||
| 626 | * @param AbstractSlide $oSlide |
||
| 627 | */ |
||
| 628 | 3 | protected function loadShapeDrawing(XMLReader $document, \DOMElement $node, AbstractSlide $oSlide) |
|
| 629 | { |
||
| 630 | // Core |
||
| 631 | 3 | $oShape = new Gd(); |
|
| 632 | 3 | $oShape->getShadow()->setVisible(false); |
|
| 633 | // Variables |
||
| 634 | 3 | $fileRels = $oSlide->getRelsIndex(); |
|
| 635 | |||
| 636 | 3 | $oElement = $document->getElement('p:nvPicPr/p:cNvPr', $node); |
|
| 637 | 3 | if ($oElement) { |
|
| 638 | 3 | $oShape->setName($oElement->hasAttribute('name') ? $oElement->getAttribute('name') : ''); |
|
| 639 | 3 | $oShape->setDescription($oElement->hasAttribute('descr') ? $oElement->getAttribute('descr') : ''); |
|
| 640 | } |
||
| 641 | |||
| 642 | 3 | $oElement = $document->getElement('p:blipFill/a:blip', $node); |
|
| 643 | 3 | if ($oElement) { |
|
| 644 | 3 | if ($oElement->hasAttribute('r:embed') && isset($this->arrayRels[$fileRels][$oElement->getAttribute('r:embed')]['Target'])) { |
|
| 645 | 3 | $pathImage = 'ppt/slides/' . $this->arrayRels[$fileRels][$oElement->getAttribute('r:embed')]['Target']; |
|
| 646 | 3 | $pathImage = explode('/', $pathImage); |
|
| 647 | 3 | foreach ($pathImage as $key => $partPath) { |
|
| 648 | 3 | if ($partPath == '..') { |
|
| 649 | 3 | unset($pathImage[$key - 1]); |
|
| 650 | 3 | unset($pathImage[$key]); |
|
| 651 | } |
||
| 652 | } |
||
| 653 | 3 | $pathImage = implode('/', $pathImage); |
|
| 654 | 3 | $imageFile = $this->oZip->getFromName($pathImage); |
|
| 655 | 3 | if (!empty($imageFile)) { |
|
| 656 | 3 | $oShape->setImageResource(imagecreatefromstring($imageFile)); |
|
| 657 | } |
||
| 658 | } |
||
| 659 | } |
||
| 660 | |||
| 661 | 3 | $oElement = $document->getElement('p:spPr/a:xfrm', $node); |
|
| 662 | 3 | if ($oElement) { |
|
| 663 | 3 | if ($oElement->hasAttribute('rot')) { |
|
| 664 | 3 | $oShape->setRotation(CommonDrawing::angleToDegrees($oElement->getAttribute('rot'))); |
|
| 665 | } |
||
| 666 | } |
||
| 667 | |||
| 668 | 3 | $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node); |
|
| 669 | 3 | if ($oElement) { |
|
| 670 | 3 | if ($oElement->hasAttribute('x')) { |
|
| 671 | 3 | $oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x'))); |
|
| 672 | } |
||
| 673 | 3 | if ($oElement->hasAttribute('y')) { |
|
| 674 | 3 | $oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y'))); |
|
| 675 | } |
||
| 676 | } |
||
| 677 | |||
| 678 | 3 | $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node); |
|
| 679 | 3 | if ($oElement) { |
|
| 680 | 3 | if ($oElement->hasAttribute('cx')) { |
|
| 681 | 3 | $oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx'))); |
|
| 682 | } |
||
| 683 | 3 | if ($oElement->hasAttribute('cy')) { |
|
| 684 | 3 | $oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy'))); |
|
| 685 | } |
||
| 686 | } |
||
| 687 | |||
| 688 | 3 | $oElement = $document->getElement('p:spPr/a:effectLst', $node); |
|
| 689 | 3 | if ($oElement) { |
|
| 690 | 3 | $oShape->getShadow()->setVisible(true); |
|
| 691 | |||
| 692 | 3 | $oSubElement = $document->getElement('a:outerShdw', $oElement); |
|
| 693 | 3 | if ($oSubElement) { |
|
| 694 | 3 | if ($oSubElement->hasAttribute('blurRad')) { |
|
| 695 | 3 | $oShape->getShadow()->setBlurRadius(CommonDrawing::emuToPixels($oSubElement->getAttribute('blurRad'))); |
|
| 696 | } |
||
| 697 | 3 | if ($oSubElement->hasAttribute('dist')) { |
|
| 698 | 3 | $oShape->getShadow()->setDistance(CommonDrawing::emuToPixels($oSubElement->getAttribute('dist'))); |
|
| 699 | } |
||
| 700 | 3 | if ($oSubElement->hasAttribute('dir')) { |
|
| 701 | 3 | $oShape->getShadow()->setDirection(CommonDrawing::angleToDegrees($oSubElement->getAttribute('dir'))); |
|
| 702 | } |
||
| 703 | 3 | if ($oSubElement->hasAttribute('algn')) { |
|
| 704 | 3 | $oShape->getShadow()->setAlignment($oSubElement->getAttribute('algn')); |
|
| 705 | } |
||
| 706 | } |
||
| 707 | |||
| 708 | 3 | $oSubElement = $document->getElement('a:outerShdw/a:srgbClr', $oElement); |
|
| 709 | 3 | if ($oSubElement) { |
|
| 710 | 3 | if ($oSubElement->hasAttribute('val')) { |
|
| 711 | 3 | $oColor = new Color(); |
|
| 712 | 3 | $oColor->setRGB($oSubElement->getAttribute('val')); |
|
| 713 | 3 | $oShape->getShadow()->setColor($oColor); |
|
| 714 | } |
||
| 715 | } |
||
| 716 | |||
| 717 | 3 | $oSubElement = $document->getElement('a:outerShdw/a:srgbClr/a:alpha', $oElement); |
|
| 718 | 3 | if ($oSubElement) { |
|
| 719 | 3 | if ($oSubElement->hasAttribute('val')) { |
|
| 720 | 3 | $oShape->getShadow()->setAlpha((int)$oSubElement->getAttribute('val') / 1000); |
|
| 721 | } |
||
| 722 | } |
||
| 723 | } |
||
| 724 | |||
| 725 | 3 | $oSlide->addShape($oShape); |
|
| 726 | 3 | } |
|
| 727 | |||
| 728 | /** |
||
| 729 | * @param XMLReader $document |
||
| 730 | * @param \DOMElement $node |
||
| 731 | * @param AbstractSlide $oSlide |
||
| 732 | * @throws \Exception |
||
| 733 | */ |
||
| 734 | 3 | protected function loadShapeRichText(XMLReader $document, \DOMElement $node, AbstractSlide $oSlide) |
|
| 735 | { |
||
| 736 | // Core |
||
| 737 | 3 | $oShape = $oSlide->createRichTextShape(); |
|
| 738 | 3 | $oShape->setParagraphs(array()); |
|
| 739 | // Variables |
||
| 740 | 3 | $fileRels = $oSlide->getRelsIndex(); |
|
| 741 | |||
| 742 | 3 | $oElement = $document->getElement('p:spPr/a:xfrm', $node); |
|
| 743 | 3 | if ($oElement && $oElement->hasAttribute('rot')) { |
|
| 744 | 3 | $oShape->setRotation(CommonDrawing::angleToDegrees($oElement->getAttribute('rot'))); |
|
| 745 | } |
||
| 746 | |||
| 747 | 3 | $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node); |
|
| 748 | 3 | if ($oElement) { |
|
| 749 | 3 | if ($oElement->hasAttribute('x')) { |
|
| 750 | 3 | $oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x'))); |
|
| 751 | } |
||
| 752 | 3 | if ($oElement->hasAttribute('y')) { |
|
| 753 | 3 | $oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y'))); |
|
| 754 | } |
||
| 755 | } |
||
| 756 | |||
| 757 | 3 | $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node); |
|
| 758 | 3 | if ($oElement) { |
|
| 759 | 3 | if ($oElement->hasAttribute('cx')) { |
|
| 760 | 3 | $oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx'))); |
|
| 761 | } |
||
| 762 | 3 | if ($oElement->hasAttribute('cy')) { |
|
| 763 | 3 | $oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy'))); |
|
| 764 | } |
||
| 765 | } |
||
| 766 | |||
| 767 | 3 | $oElement = $document->getElement('p:nvSpPr/p:nvPr/p:ph', $node); |
|
| 768 | 3 | if ($oElement) { |
|
| 769 | 3 | if ($oElement->hasAttribute('type')) { |
|
| 770 | 3 | $placeholder = new Placeholder($oElement->getAttribute('type')); |
|
| 771 | 3 | $oShape->setPlaceHolder($placeholder); |
|
| 772 | } |
||
| 773 | } |
||
| 774 | |||
| 775 | 3 | $arrayElements = $document->getElements('p:txBody/a:p', $node); |
|
| 776 | 3 | foreach ($arrayElements as $oElement) { |
|
| 777 | // Core |
||
| 778 | 3 | $oParagraph = $oShape->createParagraph(); |
|
| 779 | 3 | $oParagraph->setRichTextElements(array()); |
|
| 780 | |||
| 781 | 3 | $oSubElement = $document->getElement('a:pPr', $oElement); |
|
| 782 | 3 | if ($oSubElement) { |
|
| 783 | 3 | if ($oSubElement->hasAttribute('algn')) { |
|
| 784 | 3 | $oParagraph->getAlignment()->setHorizontal($oSubElement->getAttribute('algn')); |
|
| 785 | } |
||
| 786 | 3 | if ($oSubElement->hasAttribute('fontAlgn')) { |
|
| 787 | 3 | $oParagraph->getAlignment()->setVertical($oSubElement->getAttribute('fontAlgn')); |
|
| 788 | } |
||
| 789 | 3 | if ($oSubElement->hasAttribute('marL')) { |
|
| 790 | 3 | $oParagraph->getAlignment()->setMarginLeft(CommonDrawing::emuToPixels($oSubElement->getAttribute('marL'))); |
|
| 791 | } |
||
| 792 | 3 | if ($oSubElement->hasAttribute('marR')) { |
|
| 793 | 3 | $oParagraph->getAlignment()->setMarginRight(CommonDrawing::emuToPixels($oSubElement->getAttribute('marR'))); |
|
| 794 | } |
||
| 795 | 3 | if ($oSubElement->hasAttribute('indent')) { |
|
| 796 | 3 | $oParagraph->getAlignment()->setIndent(CommonDrawing::emuToPixels($oSubElement->getAttribute('indent'))); |
|
| 797 | } |
||
| 798 | 3 | if ($oSubElement->hasAttribute('lvl')) { |
|
| 799 | 3 | $oParagraph->getAlignment()->setLevel($oSubElement->getAttribute('lvl')); |
|
| 800 | } |
||
| 801 | |||
| 802 | 3 | $oElementBuFont = $document->getElement('a:buFont', $oSubElement); |
|
| 803 | 3 | $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_NONE); |
|
| 804 | 3 | if ($oElementBuFont) { |
|
| 805 | 3 | if ($oElementBuFont->hasAttribute('typeface')) { |
|
| 806 | 3 | $oParagraph->getBulletStyle()->setBulletFont($oElementBuFont->getAttribute('typeface')); |
|
| 807 | } |
||
| 808 | } |
||
| 809 | 3 | $oElementBuChar = $document->getElement('a:buChar', $oSubElement); |
|
| 810 | 3 | if ($oElementBuChar) { |
|
| 811 | 3 | $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET); |
|
| 812 | 3 | if ($oElementBuChar->hasAttribute('char')) { |
|
| 813 | 3 | $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 | 3 | $arraySubElements = $document->getElements('(a:r|a:br)', $oElement); |
|
| 828 | 3 | foreach ($arraySubElements as $oSubElement) { |
|
| 829 | 3 | if ($oSubElement->tagName == 'a:br') { |
|
| 830 | 3 | $oParagraph->createBreak(); |
|
| 831 | } |
||
| 832 | 3 | if ($oSubElement->tagName == 'a:r') { |
|
| 833 | 3 | $oElementrPr = $document->getElement('a:rPr', $oSubElement); |
|
| 834 | 3 | if (is_object($oElementrPr)) { |
|
| 835 | 3 | $oText = $oParagraph->createTextRun(); |
|
| 836 | |||
| 837 | 3 | if ($oElementrPr->hasAttribute('b')) { |
|
| 838 | 3 | $oText->getFont()->setBold($oElementrPr->getAttribute('b') == 'true' ? true : false); |
|
| 839 | } |
||
| 840 | 3 | if ($oElementrPr->hasAttribute('i')) { |
|
| 841 | 3 | $oText->getFont()->setItalic($oElementrPr->getAttribute('i') == 'true' ? true : false); |
|
| 842 | } |
||
| 843 | 3 | if ($oElementrPr->hasAttribute('strike')) { |
|
| 844 | 3 | $oText->getFont()->setStrikethrough($oElementrPr->getAttribute('strike') == 'noStrike' ? false : true); |
|
| 845 | } |
||
| 846 | 3 | if ($oElementrPr->hasAttribute('sz')) { |
|
| 847 | 3 | $oText->getFont()->setSize((int)($oElementrPr->getAttribute('sz') / 100)); |
|
| 848 | } |
||
| 849 | 3 | if ($oElementrPr->hasAttribute('u')) { |
|
| 850 | 3 | $oText->getFont()->setUnderline($oElementrPr->getAttribute('u')); |
|
| 851 | } |
||
| 852 | // Color |
||
| 853 | 3 | $oElementSrgbClr = $document->getElement('a:solidFill/a:srgbClr', $oElementrPr); |
|
| 854 | 3 | if (is_object($oElementSrgbClr) && $oElementSrgbClr->hasAttribute('val')) { |
|
| 855 | 3 | $oColor = new Color(); |
|
| 856 | 3 | $oColor->setRGB($oElementSrgbClr->getAttribute('val')); |
|
| 857 | 3 | $oText->getFont()->setColor($oColor); |
|
| 858 | } |
||
| 859 | // Hyperlink |
||
| 860 | 3 | $oElementHlinkClick = $document->getElement('a:hlinkClick', $oElementrPr); |
|
| 861 | 3 | if (is_object($oElementHlinkClick)) { |
|
| 862 | 3 | if ($oElementHlinkClick->hasAttribute('tooltip')) { |
|
| 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'])) { |
|
| 866 | 3 | $oText->getHyperlink()->setUrl($this->arrayRels[$fileRels][$oElementHlinkClick->getAttribute('r:id')]['Target']); |
|
| 867 | } |
||
| 868 | } |
||
| 869 | //} else { |
||
| 870 | // $oText = $oParagraph->createText(); |
||
| 871 | |||
| 872 | 3 | $oSubSubElement = $document->getElement('a:t', $oSubElement); |
|
| 873 | 3 | $oText->setText($oSubSubElement->nodeValue); |
|
| 874 | } |
||
| 875 | } |
||
| 876 | } |
||
| 877 | } |
||
| 878 | |||
| 879 | 3 | if (count($oShape->getParagraphs()) > 0) { |
|
| 880 | 3 | $oShape->setActiveParagraph(0); |
|
| 881 | } |
||
| 882 | 3 | } |
|
| 883 | |||
| 884 | /** |
||
| 885 | * |
||
| 886 | * @param string $fileRels |
||
| 887 | * @return string |
||
| 888 | */ |
||
| 889 | 3 | protected function loadRels($fileRels) |
|
| 890 | { |
||
| 891 | 3 | $sPart = $this->oZip->getFromName($fileRels); |
|
| 892 | 3 | if ($sPart !== false) { |
|
| 893 | 3 | $xmlReader = new XMLReader(); |
|
| 894 | 3 | if ($xmlReader->getDomFromString($sPart)) { |
|
| 895 | 3 | foreach ($xmlReader->getElements('*') as $oNode) { |
|
| 896 | 3 | $this->arrayRels[$fileRels][$oNode->getAttribute('Id')] = array( |
|
| 897 | 3 | 'Target' => $oNode->getAttribute('Target'), |
|
| 898 | 3 | 'Type' => $oNode->getAttribute('Type'), |
|
| 899 | ); |
||
| 900 | } |
||
| 901 | } |
||
| 902 | } |
||
| 903 | 3 | } |
|
| 904 | |||
| 905 | /** |
||
| 906 | * @param $oSlide |
||
| 907 | * @param $oElements |
||
| 908 | * @param $xmlReader |
||
| 909 | * @internal param $baseFile |
||
| 910 | */ |
||
| 911 | 3 | private function loadSlideShapes($oSlide, $oElements, $xmlReader) |
|
| 926 | } |
||
| 927 |
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.