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

Modified for adding compatible objects #511

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Modified for adding compatible objects
  • Loading branch information
adiabvs committed Mar 25, 2015
commit 3c99b351459df55abcbaeeb2675a20273ee8d8cf
2 changes: 1 addition & 1 deletion src/PhpWord/Element/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Object extends AbstractElement
*/
public function __construct($source, $style = null)
{
$supportedTypes = array('xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx');
$supportedTypes = array('xlsx', 'docx', 'pptx');
$pathInfo = pathinfo($source);

if (file_exists($source) && in_array($pathInfo['extension'], $supportedTypes)) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static function addElement($container, $mediaType, $source, Image $image

// Objects
case 'object':
$target = "{$container}_oleObject{$mediaTypeCount}.bin";
$target = "{$container}_oleObject{$mediaTypeCount}.".pathinfo($source)['extension']."";
break;

// Links
Expand Down
23 changes: 20 additions & 3 deletions src/PhpWord/Writer/Word2007.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,26 @@ private function registerContentTypes($media)
$this->contentTypes['default'][$extension] = $medium['imageType'];
}
} elseif ($mediumType == 'object') {
if (!isset($this->contentTypes['default']['bin'])) {
$this->contentTypes['default']['bin'] = 'application/vnd.openxmlformats-officedocument.oleObject';
}
switch($mediumExtension)
{
case "docx":
if (!isset($this->contentTypes['default']['docx'])) {
$this->contentTypes['default']['docx'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
}
break;

case "pptx":
if (!isset($this->contentTypes['default']['pptx'])) {
$this->contentTypes['default']['pptx'] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
}
break;

case "xlsx":
if (!isset($this->contentTypes['default']['xlsx'])) {
$this->contentTypes['default']['xlsx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
}
break;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Writer/Word2007/Part/Rels.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected function writeRels(XMLWriter $xmlWriter, $xmlRels = array(), $mediaRel
private function writeMediaRel(XMLWriter $xmlWriter, $relId, $mediaRel)
{
$typePrefix = 'officeDocument/2006/relationships/';
$typeMapping = array('image' => 'image', 'object' => 'oleObject', 'link' => 'hyperlink');
$typeMapping = array('image' => 'image', 'object' => 'package', 'link' => 'hyperlink');
$targetMapping = array('image' => 'media/', 'object' => 'embeddings/');

$mediaType = $mediaRel['type'];
Expand Down