Skip to content

Commit

Permalink
Feedbacks from @Progi1984
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Dec 13, 2023
1 parent 0e5dd85 commit 8b927fb
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 107 deletions.
2 changes: 2 additions & 0 deletions docs/changes/1.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

## Improvements
- Slide : Raised max value for identifier rand call - [@Scheissy](https://github.com/Scheissy) in [#777](https://github.com/PHPOffice/PHPPresentation/pull/777)
- Document Properties : Support for Revision & Status (PowerPoint2007 Reader/Writer) - [@devX2712](https://github.com/devX2712) in [#788](https://github.com/PHPOffice/PHPPresentation/pull/787)
- Presentation Properties : Added support to define content of the thumbnail - [@devX2712](https://github.com/devX2712) in [#788](https://github.com/PHPOffice/PHPPresentation/pull/787)

## Bugfixes

Expand Down
32 changes: 31 additions & 1 deletion docs/usage/presentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ $properties->setCreated(mktime(0, 0, 0, 3, 12, 2014));
$properties->setModified(mktime(0, 0, 0, 3, 14, 2014));
$properties->setSubject('My subject');
$properties->setKeywords('my, key, word');
$properties->setStatus('Work in Progress');
$properties->setRevision('Version 1.2.3');
```

### Custom Properties
Expand Down Expand Up @@ -203,16 +205,44 @@ echo $properties->getSlideshowType();

You can define the thumbnail of the presentation with the method `setThumbnailPath`.


#### From a file
``` php
<?php

use PhpOffice\PhpPresentation\PresentationProperties;

$presentation = new PhpPresentation();

$properties = $presentation->getPresentationProperties();
// Set path of the thumbnail
$properties->setThumbnailPath(__DIR__.'\resources\phppowerpoint_logo.gif');
$properties->setThumbnailPath(
__DIR__.'\resources\phppowerpoint_logo.gif',
PresentationProperties::THUMBNAIL_FILE
);
// Get path of the thumbnail
echo $properties->getThumbnailPath();
// Get content of the thumbnail
echo $properties->getThumbnail();
```

#### From the content of the file
``` php
<?php

use PhpOffice\PhpPresentation\PresentationProperties;

$presentation = new PhpPresentation();

$properties = $presentation->getPresentationProperties();
// Set path of the thumbnail
$properties->setThumbnailPath(
'',
PresentationProperties::THUMBNAIL_DATA,
file_get_contents(__DIR__.'\resources\phppowerpoint_logo.gif')
);
// Get content of the thumbnail
echo $properties->getThumbnail();
```

### Zoom
Expand Down
35 changes: 15 additions & 20 deletions src/PhpPresentation/DocumentProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,18 @@ class DocumentProperties
private $company;

/**
* revision
* Revision.
*
* @var string
*/
private $revision;

/**
* Status.
*
* @var string
*/
private $status;

/**
* Custom Properties.
Expand All @@ -116,14 +123,7 @@ class DocumentProperties
private $customProperties = [];

/**
* status
*
* @var string
*/
private $status;

/**
* Create a new \PhpOffice\PhpPresentation\DocumentProperties
* Create a new \PhpOffice\PhpPresentation\DocumentProperties.
*/
public function __construct()
{
Expand All @@ -139,7 +139,7 @@ public function __construct()
$this->category = '';
$this->company = 'Microsoft Corporation';
$this->revision = '';
$this->status = '';
$this->status = '';
}

/**
Expand Down Expand Up @@ -479,7 +479,7 @@ public function getRevision(): string
}

/**
* Set Revision
* Set Revision.
*/
public function setRevision(string $pValue = ''): self
{
Expand All @@ -489,22 +489,17 @@ public function setRevision(string $pValue = ''): self
}

/**
* Get Status
*
* @return string
* Get Status.
*/
public function getStatus()
public function getStatus(): string
{
return $this->status;
}

/**
* Set Status
*
* @param string $pValue
* @return \PhpOffice\PhpPresentation\DocumentProperties
* Set Status.
*/
public function setStatus($pValue = '')
public function setStatus(string $pValue = ''): self
{
$this->status = $pValue;

Expand Down
45 changes: 23 additions & 22 deletions src/PhpPresentation/PresentationProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class PresentationProperties
public const VIEW_SLIDE_SORTER = 'sldSorterView';
public const VIEW_SLIDE_THUMBNAIL = 'sldThumbnailView';

public const THUMBNAIL_FILE = 'file'; // Thumbnail path is out of PPT
public const THUMBNAIL_ZIP = 'zip'; // Thumbnail path point to an image store into file loaded
public const THUMBNAIL_FILE = 'file';
public const THUMBNAIL_DATA = 'data';

/**
* @var array<int, string>
Expand Down Expand Up @@ -72,17 +72,17 @@ class PresentationProperties
*/
protected $markAsFinal = false;

/*
* @var string Define the thumbnail content (if content into zip file)
/**
* @var string|null Define the thumbnail content (if content into zip file)
*/
protected $thumbnail = null;

/*
* @var string Define the thumbnail place
/**
* @var string|null Define the thumbnail place
*/
protected $thumbnailPath = '';
protected $thumbnailPath = null;

/*
/**
* @var string Define if thumbnail is out of PPT or previouly store into PPT
*/
protected $thumbnailType = self::THUMBNAIL_FILE;
Expand Down Expand Up @@ -130,36 +130,38 @@ public function getThumbnailPath(): ?string
}

/**
* Return the content of thumbnail
*
* @return binary Content of image
* Return the content of thumbnail.
*/
public function getThumbnail()
public function getThumbnail(): ?string
{
// Return content of local file
if ($this->getThumbnailType() == self::THUMBNAIL_FILE) {
if (file_exists($this->getThumbnailPath()))
if ($this->getThumbnailPath()) {
return file_get_contents($this->getThumbnailPath());
}

return null;
}

// Return content of image stored into zip file
if ($this->getThumbnailType() == self::THUMBNAIL_ZIP) {
if ($this->getThumbnailType() == self::THUMBNAIL_DATA) {
return $this->thumbnail;
}
// Return null if no thumbnail

return null;
}

/**
* Define the path for the thumbnail file / preview picture.
*/
public function setThumbnailPath(string $path = '', $type = self::THUMBNAIL_FILE, $content = null)
public function setThumbnailPath(string $path = '', string $type = self::THUMBNAIL_FILE, string $content = null): self
{
if (file_exists($path) && ($type == self::THUMBNAIL_FILE)) {
if (file_exists($path) && $type == self::THUMBNAIL_FILE) {
$this->thumbnailPath = $path;
$this->thumbnailType = $type;
}
if (($path != '') && ($type == self::THUMBNAIL_ZIP)) {
$this->thumbnailPath = $path;
if ($content != '' && $type == self::THUMBNAIL_DATA) {
$this->thumbnailPath = '';
$this->thumbnailType = $type;
$this->thumbnail = $content;
}
Expand All @@ -168,10 +170,9 @@ public function setThumbnailPath(string $path = '', $type = self::THUMBNAIL_FILE
}

/**
* Return the thumbnail type
* @return string
* Return the thumbnail type.
*/
public function getThumbnailType()
public function getThumbnailType(): string
{
return $this->thumbnailType;
}
Expand Down
8 changes: 4 additions & 4 deletions src/PhpPresentation/Reader/PowerPoint2007.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ protected function loadDocumentProperties(string $sPart): void
'/cp:coreProperties/dcterms:modified' => 'setModified',
'/cp:coreProperties/cp:revision' => 'setRevision',
'/cp:coreProperties/cp:contentStatus' => 'setStatus',
);
];
$oProperties = $this->oPhpPresentation->getDocumentProperties();
foreach ($arrayProperties as $path => $property) {
$oElement = $xmlReader->getElement($path);
Expand Down Expand Up @@ -913,15 +913,15 @@ protected function loadEffect(XMLReader $document, \DOMElement $nodeEffect)
$effect = new \PhpOffice\PhpPresentation\Style\Effect($type);
// load blur radius
if ($node->hasAttribute('blurRad')) {
$effect->setBlurRadius(CommonDrawing::emuToPixels($node->getAttribute('blurRad')));
$effect->setBlurRadius(CommonDrawing::emuToPixels((int) $node->getAttribute('blurRad')));
}
// load distance
if ($node->hasAttribute('dist')) {
$effect->setDistance(CommonDrawing::emuToPixels($node->getAttribute('dist')));
$effect->setDistance(CommonDrawing::emuToPixels((int) $node->getAttribute('dist')));
}
// load direction
if ($node->hasAttribute('dir')) {
$effect->setDirection(CommonDrawing::angleToDegrees($node->getAttribute('dir')));
$effect->setDirection((int) CommonDrawing::angleToDegrees((int) $node->getAttribute('dir')));
}
// load alignment
if ($node->hasAttribute('algn')) {
Expand Down
8 changes: 4 additions & 4 deletions src/PhpPresentation/Style/Effect.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ class Effect implements ComparableInterface
/**
* Hash index
*
* @var string
* @var ?int
*/
private string $hashIndex;
private $hashIndex;

/**
* Create a new \PhpOffice\PhpPresentation\Shape\Effect instance
Expand Down Expand Up @@ -276,7 +276,7 @@ public function getAlpha():int
*
* @return string Hash code
*/
public function getHashCode()
public function getHashCode(): string
{
return md5($this->effectType . $this->blurRadius . $this->distance . $this->direction . $this->alignment . $this->color->getHashCode() . $this->alpha . __CLASS__);
}
Expand All @@ -289,7 +289,7 @@ public function getHashCode()
*
* @return string Hash index
*/
public function getHashIndex()
public function getHashIndex(): ?int
{
return $this->hashIndex;
}
Expand Down
11 changes: 5 additions & 6 deletions src/PhpPresentation/Writer/PowerPoint2007/DocPropsCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,17 @@ public function render(): ZipInterface
// cp:keywords
$objWriter->writeElement('cp:keywords', $this->oPresentation->getDocumentProperties()->getKeywords());

// cp:category
$objWriter->writeElement('cp:category', $this->oPresentation->getDocumentProperties()->getCategory());

// cp:revision
$objWriter->writeElement('cp:revision', $this->oPresentation->getDocumentProperties()->getRevision());

// cp:contentStatus
$objWriter->writeElement('cp:contentStatus', $this->oPresentation->getDocumentProperties()->getStatus());

// cp:category
$objWriter->writeElement('cp:category', $this->oPresentation->getDocumentProperties()->getCategory());

if ($this->oPresentation->getPresentationProperties()->isMarkedAsFinal()) {
// cp:contentStatus = Final
$objWriter->writeElement('cp:contentStatus', 'Final');
} else {
$objWriter->writeElement('cp:contentStatus', $this->oPresentation->getDocumentProperties()->getStatus());
}

$objWriter->endElement();
Expand Down
24 changes: 4 additions & 20 deletions src/PhpPresentation/Writer/PowerPoint2007/DocPropsThumbnail.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,15 @@
namespace PhpOffice\PhpPresentation\Writer\PowerPoint2007;

use PhpOffice\Common\Adapter\Zip\ZipInterface;
use PhpOffice\PhpPresentation\PresentationProperties;

class DocPropsThumbnail extends AbstractDecoratorWriter
{
public function render(): ZipInterface
{
$pathThumbnail = $this->getPresentation()->getPresentationProperties()->getThumbnailPath();
$type = $this->getPresentation()->getPresentationProperties()->getThumbnailType();

// From local file
if ($pathThumbnail && $type == \PhpOffice\PhpPresentation\PresentationProperties::THUMBNAIL_FILE) {
$fileThumbnail = file_get_contents($pathThumbnail);
$gdImage = imagecreatefromstring($fileThumbnail);
if ($gdImage) {
ob_start();
imagejpeg($gdImage);
$imageContents = ob_get_contents();
ob_end_clean();
imagedestroy($gdImage);
$this->getZip()->addFromString('docProps/thumbnail.jpeg', $imageContents);
}
}

// From ZIP original file
if ($pathThumbnail && $type == \PhpOffice\PhpPresentation\PresentationProperties::THUMBNAIL_ZIP) {
$gdImage = imagecreatefromstring($this->getPresentation()->getPresentationProperties()->getThumbnail());
$thumnbail = $this->getPresentation()->getPresentationProperties()->getThumbnail();
if ($thumnbail) {
$gdImage = imagecreatefromstring($thumnbail);
if ($gdImage) {
ob_start();
imagejpeg($gdImage);
Expand Down
23 changes: 6 additions & 17 deletions src/PhpPresentation/Writer/PowerPoint2007/Relationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,18 @@ protected function writeRelationships(): string
$this->writeRelationship($objWriter, 4, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties', 'docProps/custom.xml');

$idxRelation = 5;
// Thumbnail
$path = $this->getPresentation()->getPresentationProperties()->getThumbnailPath();
$type = $this->getPresentation()->getPresentationProperties()->getThumbnailType();
// From local file
if ($path && $type == \PhpOffice\PhpPresentation\PresentationProperties::THUMBNAIL_FILE) {
$pathThumbnail = file_get_contents($path);
$gdImage = imagecreatefromstring($pathThumbnail);
if ($gdImage) {
imagedestroy($gdImage);
// Relationship docProps/thumbnail.jpeg
$this->writeRelationship($objWriter, $idxRelation, 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail', 'docProps/thumbnail.jpeg');
}
}
// From ZIP original file
if ($path && $type == \PhpOffice\PhpPresentation\PresentationProperties::THUMBNAIL_ZIP) {
$gdImage = imagecreatefromstring($this->getPresentation()->getPresentationProperties()->getThumbnail());

// Relationship docProps/thumbnail.jpeg
$thumnbail = $this->getPresentation()->getPresentationProperties()->getThumbnail();
if ($thumnbail) {
$gdImage = imagecreatefromstring($thumnbail);
if ($gdImage) {
imagedestroy($gdImage);
// Relationship docProps/thumbnail.jpeg
$this->writeRelationship($objWriter, $idxRelation, 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail', 'docProps/thumbnail.jpeg');
// $idxRelation++;
}
}
// ++$idxRelation

$objWriter->endElement();

Expand Down
Loading

0 comments on commit 8b927fb

Please sign in to comment.