Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
62 / 62
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
MetaInfManifest
100.00% covered (success)
100.00%
62 / 62
100.00% covered (success)
100.00%
1 / 1
8
100.00% covered (success)
100.00%
1 / 1
 render
100.00% covered (success)
100.00%
62 / 62
100.00% covered (success)
100.00%
1 / 1
8
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 * @see        https://github.com/PHPOffice/PHPPresentation
14 *
15 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16 */
17
18declare(strict_types=1);
19
20namespace PhpOffice\PhpPresentation\Writer\ODPresentation;
21
22use PhpOffice\Common\Adapter\Zip\ZipInterface;
23use PhpOffice\Common\XMLWriter;
24use PhpOffice\PhpPresentation\Shape\Drawing as ShapeDrawing;
25use PhpOffice\PhpPresentation\Slide\Background\Image;
26
27class MetaInfManifest extends AbstractDecoratorWriter
28{
29    public function render(): ZipInterface
30    {
31        // Create XML writer
32        $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
33
34        // XML header
35        $objWriter->startDocument('1.0', 'UTF-8');
36
37        // manifest:manifest
38        $objWriter->startElement('manifest:manifest');
39        $objWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0');
40        $objWriter->writeAttribute('manifest:version', '1.2');
41
42        // manifest:file-entry
43        $objWriter->startElement('manifest:file-entry');
44        $objWriter->writeAttribute('manifest:media-type', 'application/vnd.oasis.opendocument.presentation');
45        $objWriter->writeAttribute('manifest:full-path', '/');
46        $objWriter->writeAttribute('manifest:version', '1.2');
47        $objWriter->endElement();
48        // manifest:file-entry
49        $objWriter->startElement('manifest:file-entry');
50        $objWriter->writeAttribute('manifest:media-type', 'text/xml');
51        $objWriter->writeAttribute('manifest:full-path', 'content.xml');
52        $objWriter->endElement();
53        // manifest:file-entry
54        $objWriter->startElement('manifest:file-entry');
55        $objWriter->writeAttribute('manifest:media-type', 'text/xml');
56        $objWriter->writeAttribute('manifest:full-path', 'meta.xml');
57        $objWriter->endElement();
58        // manifest:file-entry
59        $objWriter->startElement('manifest:file-entry');
60        $objWriter->writeAttribute('manifest:media-type', 'text/xml');
61        $objWriter->writeAttribute('manifest:full-path', 'styles.xml');
62        $objWriter->endElement();
63
64        // Charts
65        foreach ($this->getArrayChart() as $key => $shape) {
66            $objWriter->startElement('manifest:file-entry');
67            $objWriter->writeAttribute('manifest:media-type', 'application/vnd.oasis.opendocument.chart');
68            $objWriter->writeAttribute('manifest:full-path', 'Object ' . $key . '/');
69            $objWriter->endElement();
70            $objWriter->startElement('manifest:file-entry');
71            $objWriter->writeAttribute('manifest:media-type', 'text/xml');
72            $objWriter->writeAttribute('manifest:full-path', 'Object ' . $key . '/content.xml');
73            $objWriter->endElement();
74        }
75
76        $arrMedia = [];
77        for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) {
78            $shape = $this->getDrawingHashTable()->getByIndex($i);
79            if (!($shape instanceof ShapeDrawing\AbstractDrawingAdapter)) {
80                continue;
81            }
82            $arrMedia[] = $shape->getIndexedFilename();
83            $objWriter->startElement('manifest:file-entry');
84            $objWriter->writeAttribute('manifest:media-type', $shape->getMimeType());
85            $objWriter->writeAttribute('manifest:full-path', 'Pictures/' . $shape->getIndexedFilename());
86            $objWriter->endElement();
87        }
88
89        foreach ($this->getPresentation()->getAllSlides() as $numSlide => $oSlide) {
90            $oBkgImage = $oSlide->getBackground();
91            if ($oBkgImage instanceof Image) {
92                $arrayImage = getimagesize($oBkgImage->getPath());
93                $mimeType = image_type_to_mime_type($arrayImage[2]);
94
95                $objWriter->startElement('manifest:file-entry');
96                $objWriter->writeAttribute('manifest:media-type', $mimeType);
97                $objWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $oBkgImage->getIndexedFilename((string) $numSlide)));
98                $objWriter->endElement();
99            }
100        }
101
102        if ($this->getPresentation()->getPresentationProperties()->getThumbnailPath()) {
103            $pathThumbnail = $this->getPresentation()->getPresentationProperties()->getThumbnailPath();
104            // Size : 128x128 pixel
105            // PNG : 8bit, non-interlaced with full alpha transparency
106            $gdImage = imagecreatefromstring(file_get_contents($pathThumbnail));
107            if ($gdImage) {
108                imagedestroy($gdImage);
109                $objWriter->startElement('manifest:file-entry');
110                $objWriter->writeAttribute('manifest:media-type', 'image/png');
111                $objWriter->writeAttribute('manifest:full-path', 'Thumbnails/thumbnail.png');
112                $objWriter->endElement();
113            }
114        }
115
116        $objWriter->endElement();
117
118        $this->getZip()->addFromString('META-INF/manifest.xml', $objWriter->getData());
119
120        return $this->getZip();
121    }
122}