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