Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hyperlink parsing under pictures #557

Merged
merged 3 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- PHP 7.1 is now supported - @Progi1984 GH-355
- PhpOffice\PhpPresentation\Style\Color : Define only the transparency - @Progi1984 GH-370
- PowerPoint2007 Reader : Background Color based on SchemeColor - @Progi1984 GH-397
- PowerPoint2007 Reader : Support for hyperlinks under pictures - @ulziibuyan

### Features
- ODPresentation Writer : Support for the position of Legend - @Progi1984 GH-355
Expand Down
12 changes: 8 additions & 4 deletions samples/Sample_Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
function write($phpPresentation, $filename, $writers)
{
$result = '';

// Write documents
foreach ($writers as $writer => $extension) {
$result .= date('H:i:s') . " Write to {$writer} format";
Expand Down Expand Up @@ -177,7 +177,7 @@ function createTemplatedSlide(PhpOffice\PhpPresentation\PhpPresentation $objPHPP
{
// Create slide
$slide = $objPHPPresentation->createSlide();

// Add logo
$shape = $slide->createDrawingShape();
$shape->setName('PHPPresentation logo')
Expand Down Expand Up @@ -301,7 +301,7 @@ protected function displayPhpPresentationInfo(PhpPresentation $oPHPPpt)
$this->append('<dl>');
$this->append('<dt>HashCode</dt><dd>'.$oSlide->getHashCode().'</dd>');
$this->append('<dt>Slide Layout</dt><dd>Layout::'.$this->getConstantName('\PhpOffice\PhpPresentation\Slide\Layout', $oSlide->getSlideLayout()).'</dd>');

$this->append('<dt>Offset X</dt><dd>'.$oSlide->getOffsetX().'</dd>');
$this->append('<dt>Offset Y</dt><dd>'.$oSlide->getOffsetY().'</dd>');
$this->append('<dt>Extent X</dt><dd>'.$oSlide->getExtentX().'</dd>');
Expand Down Expand Up @@ -379,6 +379,10 @@ protected function displayShapeInfo(AbstractShape $oShape)
ob_end_clean();
$this->append('<dt>Mime-Type</dt><dd>'.$oShape->getMimeType().'</dd>');
$this->append('<dt>Image</dt><dd><img src="data:'.$oShape->getMimeType().';base64,'.base64_encode($sShapeImgContents).'"></dd>');
if ($oShape->hasHyperlink()) {
$this->append('<dt>Hyperlink URL</dt><dd>'.$oShape->getHyperlink()->getUrl().'</dd>');
$this->append('<dt>Hyperlink Tooltip</dt><dd>'.$oShape->getHyperlink()->getTooltip().'</dd>');
}
} elseif($oShape instanceof Drawing\AbstractDrawingAdapter) {
$this->append('<dt>Name</dt><dd>'.$oShape->getName().'</dd>');
$this->append('<dt>Description</dt><dd>'.$oShape->getDescription().'</dd>');
Expand Down Expand Up @@ -449,7 +453,7 @@ protected function displayShapeInfo(AbstractShape $oShape)
$this->append('</dl>');
$this->append('</div>');
}

protected function getConstantName($class, $search, $startWith = '') {
$fooClass = new ReflectionClass($class);
$constants = $fooClass->getConstants();
Expand Down
11 changes: 11 additions & 0 deletions src/PhpPresentation/Reader/PowerPoint2007.php
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,17 @@ protected function loadShapeDrawing(XMLReader $document, \DOMElement $node, Abst
if ($oElement instanceof \DOMElement) {
$oShape->setName($oElement->hasAttribute('name') ? $oElement->getAttribute('name') : '');
$oShape->setDescription($oElement->hasAttribute('descr') ? $oElement->getAttribute('descr') : '');

// Hyperlink
$oElementHlinkClick = $document->getElement('a:hlinkClick', $oElement);
if (is_object($oElementHlinkClick)) {
if ($oElementHlinkClick->hasAttribute('tooltip')) {
$oShape->getHyperlink()->setTooltip($oElementHlinkClick->getAttribute('tooltip'));
}
if ($oElementHlinkClick->hasAttribute('r:id') && isset($this->arrayRels[$fileRels][$oElementHlinkClick->getAttribute('r:id')]['Target'])) {
$oShape->getHyperlink()->setUrl($this->arrayRels[$fileRels][$oElementHlinkClick->getAttribute('r:id')]['Target']);
}
}
}

$oElement = $document->getElement('p:blipFill/a:blip', $node);
Expand Down