'); define('SCRIPT_FILENAME', basename($_SERVER['SCRIPT_FILENAME'], '.php')); define('IS_INDEX', SCRIPT_FILENAME == 'index'); require_once __DIR__ . '/../src/PhpPresentation/Autoloader.php'; Autoloader::register(); require_once __DIR__ . '/../vendor/autoload.php'; // Set writers $writers = array('PowerPoint2007' => 'pptx', 'ODPresentation' => 'odp'); // Return to the caller script when runs by CLI if (CLI) { return; } // Set titles and names $pageHeading = str_replace('_', ' ', SCRIPT_FILENAME); $pageTitle = IS_INDEX ? 'Welcome to ' : "{$pageHeading} - "; $pageTitle .= 'PHPPresentation'; $pageHeading = IS_INDEX ? '' : "

{$pageHeading}

"; $oShapeDrawing = new Drawing\File(); $oShapeDrawing->setName('PHPPresentation logo') ->setDescription('PHPPresentation logo') ->setPath('./resources/phppowerpoint_logo.gif') ->setHeight(36) ->setOffsetX(10) ->setOffsetY(10); $oShapeDrawing->getShadow()->setVisible(true) ->setDirection(45) ->setDistance(10); $oShapeDrawing->getHyperlink()->setUrl('https://github.com/PHPOffice/PHPPresentation/')->setTooltip('PHPPresentation'); // Create a shape (text) $oShapeRichText = new RichText(); $oShapeRichText->setHeight(300) ->setWidth(600) ->setOffsetX(170) ->setOffsetY(180); $oShapeRichText->getActiveParagraph()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_CENTER ); $textRun = $oShapeRichText->createTextRun('Thank you for using PHPPresentation!'); $textRun->getFont()->setBold(true) ->setSize(60) ->setColor( new Color( 'FFE06B20' ) ); // Populate samples $files = ''; if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if (preg_match('/^Sample_\d+_/', $file)) { $name = str_replace('_', ' ', preg_replace('/(Sample_|\.php)/', '', $file)); $files .= "
  • {$name}
  • "; } } closedir($handle); } /** * Write documents * * @param \PhpOffice\PhpPresentation\PhpPresentation $phpPresentation * @param string $filename * @param array $writers * @return string */ function write($phpPresentation, $filename, $writers) { $result = ''; // Write documents foreach ($writers as $writer => $extension) { $result .= date('H:i:s') . " Write to {$writer} format"; if (!is_null($extension)) { $xmlWriter = IOFactory::createWriter($phpPresentation, $writer); $xmlWriter->save(__DIR__ . "/{$filename}.{$extension}"); rename(__DIR__ . "/{$filename}.{$extension}", __DIR__ . "/results/{$filename}.{$extension}"); } else { $result .= ' ... NOT DONE!'; } $result .= EOL; } $result .= getEndingNotes($writers); return $result; } /** * Get ending notes * * @param array $writers * @return string */ function getEndingNotes($writers) { $result = ''; // Do not show execution time for index if (!IS_INDEX) { $result .= date('H:i:s') . " Done writing file(s)" . EOL; $result .= date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB" . EOL; } // Return if (CLI) { $result .= 'The results are stored in the "results" subdirectory.' . EOL; } else { if (!IS_INDEX) { $types = array_values($writers); $result .= '

     

    '; $result .= '

    Results: '; foreach ($types as $type) { if (!is_null($type)) { $resultFile = 'results/' . SCRIPT_FILENAME . '.' . $type; if (file_exists($resultFile)) { $result .= "{$type} "; } } } $result .= '

    '; } } return $result; } /** * Creates a templated slide * * @param PHPPresentation $objPHPPresentation * @return \PhpOffice\PhpPresentation\Slide */ function createTemplatedSlide(PhpOffice\PhpPresentation\PhpPresentation $objPHPPresentation) { // Create slide $slide = $objPHPPresentation->createSlide(); // Add logo $shape = $slide->createDrawingShape(); $shape->setName('PHPPresentation logo') ->setDescription('PHPPresentation logo') ->setPath('./resources/phppowerpoint_logo.gif') ->setHeight(36) ->setOffsetX(10) ->setOffsetY(10); $shape->getShadow()->setVisible(true) ->setDirection(45) ->setDistance(10); // Return slide return $slide; } class PhpPptTree { protected $oPhpPresentation; protected $htmlOutput; public function __construct(PhpPresentation $oPHPPpt) { $this->oPhpPresentation = $oPHPPpt; } public function display() { $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; } protected function append($sHTML) { $this->htmlOutput .= $sHTML; } protected function displayPhpPresentation(PhpPresentation $oPHPPpt) { $this->append('
  • PhpPresentation'); $this->append(''); $this->append('
  • '); } protected function displayShape(AbstractShape $shape) { if($shape instanceof Drawing\Gd) { $this->append('
  • Shape "Drawing\Gd"
  • '); } elseif($shape instanceof Drawing\File) { $this->append('
  • Shape "Drawing\File"
  • '); } elseif($shape instanceof Drawing\Base64) { $this->append('
  • Shape "Drawing\Base64"
  • '); } elseif($shape instanceof Drawing\Zip) { $this->append('
  • Shape "Drawing\Zip"
  • '); } elseif($shape instanceof RichText) { $this->append('
  • Shape "RichText"
  • '); } else { var_dump($shape); } } protected function displayPhpPresentationInfo(PhpPresentation $oPHPPpt) { $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('
    Slide Layout
    Layout::'.$this->getConstantName('\PhpOffice\PhpPresentation\Slide\Layout', $oSlide->getSlideLayout()).'
    '); $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 Slide\AbstractBackground) { if ($oBkg instanceof Slide\Background\Color) { $this->append('
    Background Color
    #'.$oBkg->getColor()->getRGB().'
    '); } if ($oBkg instanceof Slide\Background\Image) { $sBkgImgContents = file_get_contents($oBkg->getPath()); $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); } } } } protected function displayShapeInfo(AbstractShape $oShape) { $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
    @Todo
    '); $this->append('
    Border
    @Todo
    '); $this->append('
    IsPlaceholder
    ' . ($oShape->isPlaceholder() ? 'true' : 'false') . '
    '); if($oShape instanceof Drawing\Gd) { $this->append('
    Name
    '.$oShape->getName().'
    '); $this->append('
    Description
    '.$oShape->getDescription().'
    '); ob_start(); call_user_func($oShape->getRenderingFunction(), $oShape->getImageResource()); $sShapeImgContents = ob_get_contents(); ob_end_clean(); $this->append('
    Mime-Type
    '.$oShape->getMimeType().'
    '); $this->append('
    Image
    '); } elseif($oShape instanceof Drawing) { $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().'
    '); $this->append('
    Bullet Style
    Bullet::'.$this->getConstantName('\PhpOffice\PhpPresentation\Style\Bullet', $oParagraph->getBulletStyle()->getBulletType()).'
    '); if ($oParagraph->getBulletStyle()->getBulletType() != Bullet::TYPE_NONE) { $this->append('
    Bullet Font
    ' . $oParagraph->getBulletStyle()->getBulletFont() . '
    '); $this->append('
    Bullet Color
    ' . $oParagraph->getBulletStyle()->getBulletColor()->getARGB() . '
    '); } if ($oParagraph->getBulletStyle()->getBulletType() == Bullet::TYPE_BULLET) { $this->append('
    Bullet Char
    '.$oParagraph->getBulletStyle()->getBulletChar().'
    '); } if ($oParagraph->getBulletStyle()->getBulletType() == Bullet::TYPE_NUMERIC) { $this->append('
    Bullet Start At
    '.$oParagraph->getBulletStyle()->getBulletNumericStartAt().'
    '); $this->append('
    Bullet Style
    '.$oParagraph->getBulletStyle()->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) { if ($oRichText->hasHyperlink()) { $this->append('
    Hyperlink URL
    '.$oRichText->getHyperlink()->getUrl().'
    '); $this->append('
    Hyperlink Tooltip
    '.$oRichText->getHyperlink()->getTooltip().'
    '); } } $this->append('
    '); $this->append('
    '); } } $this->append('
    '); } $this->append('
    '); } else { // Add another shape } $this->append('
    '); $this->append('
    '); } protected function getConstantName($class, $search, $startWith = '') { $fooClass = new ReflectionClass($class); $constants = $fooClass->getConstants(); $constName = null; foreach ($constants as $key => $value ) { if ($value == $search) { if (empty($startWith) || (!empty($startWith) && strpos($key, $startWith) === 0)) { $constName = $key; } break; } } return $constName; } } ?> <?php echo $pageTitle; ?>