2012-05-06 23:25:37 +02:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-05-05 13:06:53 +04:00
|
|
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
|
|
|
|
* word processing documents.
|
|
|
|
|
*
|
|
|
|
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
|
|
|
|
* General Public License version 3 as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please read the LICENSE
|
|
|
|
|
* file that was distributed with this source code. For the full list of
|
|
|
|
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
2012-05-06 23:25:37 +02:00
|
|
|
*
|
2014-03-27 23:55:06 +07:00
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
2014-05-05 12:38:31 +04:00
|
|
|
* @copyright 2010-2014 PHPWord contributors
|
2014-05-04 21:03:28 +04:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
2012-05-06 23:25:37 +02:00
|
|
|
*/
|
|
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
namespace PhpOffice\PhpWord\Writer;
|
|
|
|
|
|
2014-04-18 23:12:51 +07:00
|
|
|
use PhpOffice\PhpWord\Media;
|
2014-03-22 10:06:08 +04:00
|
|
|
use PhpOffice\PhpWord\PhpWord;
|
|
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* ODText writer
|
2014-04-17 16:19:23 +07:00
|
|
|
*
|
|
|
|
|
* @since 0.7.0
|
2014-03-24 00:26:10 +07:00
|
|
|
*/
|
2014-04-08 00:23:49 +07:00
|
|
|
class ODText extends AbstractWriter implements WriterInterface
|
2012-05-06 23:25:37 +02:00
|
|
|
{
|
2013-12-11 14:45:44 -05:00
|
|
|
/**
|
2014-03-24 00:26:10 +07:00
|
|
|
* Create new ODText writer
|
2014-04-03 11:34:06 +07:00
|
|
|
*
|
2014-04-16 17:22:30 +04:00
|
|
|
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
2014-03-22 10:06:08 +04:00
|
|
|
public function __construct(PhpWord $phpWord = null)
|
2013-12-11 14:45:44 -05:00
|
|
|
{
|
2014-03-22 10:06:08 +04:00
|
|
|
// Assign PhpWord
|
|
|
|
|
$this->setPhpWord($phpWord);
|
2013-12-11 14:45:44 -05:00
|
|
|
|
2014-04-30 08:54:38 +07:00
|
|
|
// Create parts
|
2014-05-06 08:50:55 +07:00
|
|
|
$this->parts = array(
|
|
|
|
|
'Mimetype' => 'mimetype',
|
|
|
|
|
'Content' => 'content.xml',
|
|
|
|
|
'Meta' => 'meta.xml',
|
|
|
|
|
'Styles' => 'styles.xml',
|
|
|
|
|
'Manifest' => 'META-INF/manifest.xml',
|
|
|
|
|
);
|
|
|
|
|
foreach (array_keys($this->parts) as $partName) {
|
2014-05-07 09:47:02 +07:00
|
|
|
$partClass = get_class($this) . '\\Part\\' . $partName;
|
2014-04-30 08:54:38 +07:00
|
|
|
if (class_exists($partClass)) {
|
2014-05-18 11:13:38 +07:00
|
|
|
/** @var $partObject \PhpOffice\PhpWord\Writer\ODText\Part\AbstractPart Type hint */
|
2014-04-30 08:54:38 +07:00
|
|
|
$partObject = new $partClass();
|
|
|
|
|
$partObject->setParentWriter($this);
|
2014-05-06 08:50:55 +07:00
|
|
|
$this->writerParts[strtolower($partName)] = $partObject;
|
2014-04-30 08:54:38 +07:00
|
|
|
}
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
2014-04-18 23:12:51 +07:00
|
|
|
|
|
|
|
|
// Set package paths
|
|
|
|
|
$this->mediaPaths = array('image' => 'Pictures/');
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-22 10:06:08 +04:00
|
|
|
* Save PhpWord to file
|
2013-12-11 14:45:44 -05:00
|
|
|
*
|
2014-04-08 03:03:14 +07:00
|
|
|
* @param string $filename
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
2014-04-08 03:03:14 +07:00
|
|
|
public function save($filename = null)
|
2013-12-11 14:45:44 -05:00
|
|
|
{
|
2014-05-07 09:47:02 +07:00
|
|
|
$filename = $this->getTempFile($filename);
|
2014-05-17 11:14:52 +07:00
|
|
|
$zip = $this->getZipArchive($filename);
|
2014-04-18 23:12:51 +07:00
|
|
|
|
2014-05-07 09:47:02 +07:00
|
|
|
// Add section media files
|
|
|
|
|
$sectionMedia = Media::getElements('section');
|
|
|
|
|
if (!empty($sectionMedia)) {
|
2014-05-17 11:14:52 +07:00
|
|
|
$this->addFilesToPackage($zip, $sectionMedia);
|
2014-05-07 09:47:02 +07:00
|
|
|
}
|
2013-12-11 14:45:44 -05:00
|
|
|
|
2014-05-07 09:47:02 +07:00
|
|
|
// Write parts
|
|
|
|
|
foreach ($this->parts as $partName => $fileName) {
|
|
|
|
|
if ($fileName != '') {
|
2014-05-17 11:14:52 +07:00
|
|
|
$zip->addFromString($fileName, $this->getWriterPart($partName)->write());
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
2014-05-07 09:47:02 +07:00
|
|
|
}
|
2013-12-11 14:45:44 -05:00
|
|
|
|
2014-05-17 11:14:52 +07:00
|
|
|
// Close zip archive and cleanup temp file
|
|
|
|
|
$zip->close();
|
2014-05-07 09:47:02 +07:00
|
|
|
$this->cleanupTempFile();
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
2014-03-11 19:26:56 +07:00
|
|
|
}
|