oPhpPresentation = $oPHPPpt;
}
/**
* Render presentation
*
* @return string
*
* @since 1.0.0
*/
public function renderHtml() : string
{
$this->append('
');
$this->append('
');
$this->append('
');
$this->append('
');
$this->append('
');
$this->displayPhpPresentation($this->oPhpPresentation);
$this->append('
');
$this->append('
');
$this->append('
');
$this->append('
');
$this->displayPhpPresentationInfo($this->oPhpPresentation);
$this->append('
');
$this->append('
');
$this->append('
');
return $this->htmlOutput;
}
/**
* Add html to output
*
* @param string $sHTML Html
*
* @return void
*
* @since 1.0.0
*/
protected function append(string $sHTML) : void
{
$this->htmlOutput .= $sHTML;
}
/**
* Constructor
*
* @param PhpPresentation $oPHPPpt Presentation object
*
* @return void
*
* @since 1.0.0
*/
protected function displayPhpPresentation(PhpPresentation $oPHPPpt) : void
{
$this->append('folder_open PhpPresentation');
$this->append('');
$this->append('- info Info "PhpPresentation"
');
foreach ($oPHPPpt->getAllSlides() as $oSlide) {
$this->append('- indeterminate_check_box Slide');
$this->append('
');
$this->append('- info Info "Slide"
');
foreach ($oSlide->getShapeCollection() as $oShape) {
if ($oShape instanceof Group) {
$this->append('- indeterminate_check_box Shape "Group"');
$this->append('
');
// $this->append('- info Info "Group"
');
foreach ($oShape->getShapeCollection() as $oShapeChild) {
$this->displayShape($oShapeChild);
}
$this->append('
');
$this->append(' ');
} else {
$this->displayShape($oShape);
}
}
$this->append('
');
$this->append(' ');
}
$this->append('
');
$this->append('');
}
/**
* Render a shape
*
* @param AbstractShape $shape Shape to render
*
* @return void
*
* @since 1.0.0
*/
protected function displayShape(AbstractShape $shape) : void
{
if ($shape instanceof Gd) {
$this->append('Shape "Drawing\Gd"');
} elseif ($shape instanceof File) {
$this->append('Shape "Drawing\File"');
} elseif ($shape instanceof Base64) {
$this->append('Shape "Drawing\Base64"');
} elseif ($shape instanceof ZipFile) {
$this->append('Shape "Drawing\Zip"');
} elseif ($shape instanceof RichText) {
$this->append('Shape "RichText"');
} else {
\var_dump($shape);
}
}
/**
* Render a shape
*
* @param PhpPresentation $oPHPPpt Presentation object
*
* @return void
*
* @since 1.0.0
*/
protected function displayPhpPresentationInfo(PhpPresentation $oPHPPpt) : void
{
$this->append('');
$this->append('
');
$this->append('- Number of slides
- ' . $oPHPPpt->getSlideCount() . '
');
$this->append('- Document Layout Name
- ' . (empty($oPHPPpt->getLayout()->getDocumentLayout()) ? 'Custom' : $oPHPPpt->getLayout()->getDocumentLayout()) . '
');
$this->append('- Document Layout Height
- ' . $oPHPPpt->getLayout()->getCY(DocumentLayout::UNIT_MILLIMETER) . ' mm
');
$this->append('- Document Layout Width
- ' . $oPHPPpt->getLayout()->getCX(DocumentLayout::UNIT_MILLIMETER) . ' mm
');
$this->append('- Properties : Category
- ' . $oPHPPpt->getDocumentProperties()->getCategory() . '
');
$this->append('- Properties : Company
- ' . $oPHPPpt->getDocumentProperties()->getCompany() . '
');
$this->append('- Properties : Created
- ' . $oPHPPpt->getDocumentProperties()->getCreated() . '
');
$this->append('- Properties : Creator
- ' . $oPHPPpt->getDocumentProperties()->getCreator() . '
');
$this->append('- Properties : Description
- ' . $oPHPPpt->getDocumentProperties()->getDescription() . '
');
$this->append('- Properties : Keywords
- ' . $oPHPPpt->getDocumentProperties()->getKeywords() . '
');
$this->append('- Properties : Last Modified By
- ' . $oPHPPpt->getDocumentProperties()->getLastModifiedBy() . '
');
$this->append('- Properties : Modified
- ' . $oPHPPpt->getDocumentProperties()->getModified() . '
');
$this->append('- Properties : Subject
- ' . $oPHPPpt->getDocumentProperties()->getSubject() . '
');
$this->append('- Properties : Title
- ' . $oPHPPpt->getDocumentProperties()->getTitle() . '
');
$this->append('
');
$this->append('
');
foreach ($oPHPPpt->getAllSlides() as $oSlide) {
$this->append('');
$this->append('
');
$this->append('- HashCode
- ' . $oSlide->getHashCode() . '
');
$this->append('- Offset X
- ' . $oSlide->getOffsetX() . '
');
$this->append('- Offset Y
- ' . $oSlide->getOffsetY() . '
');
$this->append('- Extent X
- ' . $oSlide->getExtentX() . '
');
$this->append('- Extent Y
- ' . $oSlide->getExtentY() . '
');
$oBkg = $oSlide->getBackground();
if ($oBkg instanceof AbstractBackground) {
if ($oBkg instanceof BackgroundColor) {
$this->append('- Background Color
- #' . $oBkg->getColor()->getRGB() . '
');
}
if ($oBkg instanceof Image) {
$sBkgImgContents = \file_get_contents($oBkg->getPath());
if ($sBkgImgContents !== false) {
$this->append('- Background Image
 . ')
');
}
}
}
$oNote = $oSlide->getNote();
if ($oNote->getShapeCollection()->count() > 0) {
$this->append('- Notes
');
foreach ($oNote->getShapeCollection() as $oShape) {
if ($oShape instanceof RichText) {
$this->append('- ' . $oShape->getPlainText() . '
');
}
}
}
$this->append('
');
$this->append('
');
foreach ($oSlide->getShapeCollection() as $oShape) {
if ($oShape instanceof Group) {
foreach ($oShape->getShapeCollection() as $oShapeChild) {
$this->displayShapeInfo($oShapeChild);
}
} else {
$this->displayShapeInfo($oShape);
}
}
}
}
/**
* Render a shape info
*
* @param AbstractShape $oShape Shape to render
*
* @return void
*
* @since 1.0.0
*/
protected function displayShapeInfo(AbstractShape $oShape) : void
{
$this->append('');
$this->append('
');
$this->append('- HashCode
- ' . $oShape->getHashCode() . '
');
$this->append('- Offset X
- ' . $oShape->getOffsetX() . '
');
$this->append('- Offset Y
- ' . $oShape->getOffsetY() . '
');
$this->append('- Height
- ' . $oShape->getHeight() . '
');
$this->append('- Width
- ' . $oShape->getWidth() . '
');
$this->append('- Rotation
- ' . $oShape->getRotation() . '°
');
$this->append('- Hyperlink
- ' . \ucfirst(\var_export($oShape->hasHyperlink(), true)) . '
');
$this->append('- Fill
');
if ($oShape->getFill() === null) {
$this->append('- None
');
} else {
switch ($oShape->getFill()->getFillType()) {
case \PhpOffice\PhpPresentation\Style\Fill::FILL_NONE:
$this->append('- None
');
break;
case \PhpOffice\PhpPresentation\Style\Fill::FILL_SOLID:
$this->append('- Solid (');
$this->append('Color : #' . $oShape->getFill()->getStartColor()->getRGB());
$this->append(' - Alpha : ' . $oShape->getFill()->getStartColor()->getAlpha() . '%');
$this->append(')
');
break;
}
}
$this->append('- Border
- @Todo
');
$this->append('- IsPlaceholder
- ' . ($oShape->isPlaceholder() ? 'true' : 'false') . '
');
if ($oShape instanceof Gd) {
$this->append('- Name
- ' . $oShape->getName() . '
');
$this->append('- Description
- ' . $oShape->getDescription() . '
');
\ob_start();
$oShape->getRenderingFunction()($oShape->getImageResource());
$sShapeImgContents = \ob_get_contents();
\ob_end_clean();
$this->append('- Mime-Type
- ' . $oShape->getMimeType() . '
');
$this->append('- Image
 . ';base64,' . \base64_encode($sShapeImgContents) . ')
');
if ($oShape->hasHyperlink()) {
$this->append('- Hyperlink URL
- ' . $oShape->getHyperlink()->getUrl() . '
');
$this->append('- Hyperlink Tooltip
- ' . $oShape->getHyperlink()->getTooltip() . '
');
}
} elseif ($oShape instanceof AbstractDrawingAdapter) {
$this->append('- Name
- ' . $oShape->getName() . '
');
$this->append('- Description
- ' . $oShape->getDescription() . '
');
} elseif ($oShape instanceof RichText) {
$this->append('- # of paragraphs
- ' . \count($oShape->getParagraphs()) . '
');
$this->append('- Inset (T / R / B / L)
- ' . $oShape->getInsetTop() . 'px / ' . $oShape->getInsetRight() . 'px / ' . $oShape->getInsetBottom() . 'px / ' . $oShape->getInsetLeft() . 'px
');
$this->append('- Text
');
$this->append('- ');
foreach ($oShape->getParagraphs() as $oParagraph) {
$this->append('Paragraph
');
$this->append('- Alignment Horizontal
- Alignment::' . $this->getConstantName('\PhpOffice\PhpPresentation\Style\Alignment', $oParagraph->getAlignment()->getHorizontal()) . '
');
$this->append('- Alignment Vertical
- Alignment::' . $this->getConstantName('\PhpOffice\PhpPresentation\Style\Alignment', $oParagraph->getAlignment()->getVertical()) . '
');
$this->append('- Alignment Margin (L / R)
- ' . $oParagraph->getAlignment()->getMarginLeft() . ' px / ' . $oParagraph->getAlignment()->getMarginRight() . 'px
');
$this->append('- Alignment Indent
- ' . $oParagraph->getAlignment()->getIndent() . ' px
');
$this->append('- Alignment Level
- ' . $oParagraph->getAlignment()->getLevel() . '
');
$bulletStyle = $oParagraph->getBulletStyle();
if ($bulletStyle !== null) {
$this->append('- Bullet Style
- Bullet::' . $this->getConstantName('\PhpOffice\PhpPresentation\Style\Bullet', $bulletStyle->getBulletType()) . '
');
if ($bulletStyle->getBulletType() != Bullet::TYPE_NONE) {
$this->append('- Bullet Font
- ' . $bulletStyle->getBulletFont() . '
');
$this->append('- Bullet Color
- ' . $bulletStyle->getBulletColor()->getARGB() . '
');
}
if ($bulletStyle->getBulletType() == Bullet::TYPE_BULLET) {
$this->append('- Bullet Char
- ' . $bulletStyle->getBulletChar() . '
');
}
if ($bulletStyle->getBulletType() == Bullet::TYPE_NUMERIC) {
$this->append('- Bullet Start At
- ' . $bulletStyle->getBulletNumericStartAt() . '
');
$this->append('- Bullet Style
- ' . $bulletStyle->getBulletNumericStyle() . '
');
}
}
$this->append('- Line Spacing
- ' . $oParagraph->getLineSpacing() . '
');
$this->append('- RichText
');
foreach ($oParagraph->getRichTextElements() as $oRichText) {
if ($oRichText instanceof BreakElement) {
$this->append('- Break
');
} else {
if ($oRichText instanceof TextElement) {
$this->append('- TextElement
');
} else {
$this->append('- Run
');
}
$this->append('- ' . $oRichText->getText());
$this->append('
');
$this->append('- Font Name
- ' . $oRichText->getFont()->getName() . '
');
$this->append('- Font Size
- ' . $oRichText->getFont()->getSize() . '
');
$this->append('- Font Color
- #' . $oRichText->getFont()->getColor()->getARGB() . '
');
$this->append('- Font Transform
- ');
$this->append('Bold : ' . ($oRichText->getFont()->isBold() ? 'Y' : 'N') . ' - ');
$this->append('Italic : ' . ($oRichText->getFont()->isItalic() ? 'Y' : 'N') . ' - ');
$this->append('Underline : Underline::' . $this->getConstantName('\PhpOffice\PhpPresentation\Style\Font', $oRichText->getFont()->getUnderline()) . ' - ');
$this->append('Strikethrough : ' . ($oRichText->getFont()->isStrikethrough() ? 'Y' : 'N') . ' - ');
$this->append('SubScript : ' . ($oRichText->getFont()->isSubScript() ? 'Y' : 'N') . ' - ');
$this->append('SuperScript : ' . ($oRichText->getFont()->isSuperScript() ? 'Y' : 'N'));
$this->append('
');
if ($oRichText instanceof TextElement && $oRichText->hasHyperlink()) {
$this->append('- Hyperlink URL
- ' . $oRichText->getHyperlink()->getUrl() . '
');
$this->append('- Hyperlink Tooltip
- ' . $oRichText->getHyperlink()->getTooltip() . '
');
}
$this->append('
');
$this->append(' ');
}
}
$this->append('
');
}
$this->append(' ');
}
$this->append('
');
$this->append('
');
}
/**
* Find constant
*
* @param string $class Class to search in
* @param string $search Value to search for
* @param string $startWith Constant name it starts with
*
* @return string
*
* @since 1.0.0
*/
protected function getConstantName(string $class, string $search, string $startWith = '') : string
{
$fooClass = new \ReflectionClass($class);
$constants = $fooClass->getConstants();
$constName = '';
foreach ($constants as $key => $value) {
if ($value === $search) {
if ($startWith === '' || \str_starts_with($key, $startWith)) {
$constName = $key;
}
break;
}
}
return $constName;
}
}