Code formatting for PSR1 & PSR2 - Part 1

This commit is contained in:
Ivan Lanin 2014-03-11 19:26:56 +07:00
parent ec514f310f
commit 4e3450e39f
44 changed files with 518 additions and 456 deletions

View File

@ -33,7 +33,8 @@
* @package PHPWord * @package PHPWord
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Footnote { class PHPWord_Footnote
{
/** /**
* Footnote Elements * Footnote Elements
@ -57,7 +58,8 @@ class PHPWord_Footnote {
* *
* @return mixed * @return mixed
*/ */
public static function addFootnoteElement(PHPWord_Section_Footnote $footnote) { public static function addFootnoteElement(PHPWord_Section_Footnote $footnote)
{
$refID = self::countFootnoteElements() + 2; $refID = self::countFootnoteElements() + 2;
self::$_footnoteCollection[] = $footnote; self::$_footnoteCollection[] = $footnote;
@ -70,7 +72,8 @@ class PHPWord_Footnote {
* *
* @return array * @return array
*/ */
public static function getFootnoteElements() { public static function getFootnoteElements()
{
return self::$_footnoteCollection; return self::$_footnoteCollection;
} }
@ -79,7 +82,8 @@ class PHPWord_Footnote {
* *
* @return int * @return int
*/ */
public static function countFootnoteElements() { public static function countFootnoteElements()
{
return count(self::$_footnoteCollection); return count(self::$_footnoteCollection);
} }
@ -91,7 +95,8 @@ class PHPWord_Footnote {
* *
* @return mixed * @return mixed
*/ */
public static function addFootnoteLinkElement($linkSrc) { public static function addFootnoteLinkElement($linkSrc)
{
$rID = self::countFootnoteLinkElements() + 1; $rID = self::countFootnoteLinkElements() + 1;
$link = array(); $link = array();
@ -109,7 +114,8 @@ class PHPWord_Footnote {
* *
* @return array * @return array
*/ */
public static function getFootnoteLinkElements() { public static function getFootnoteLinkElements()
{
return self::$_footnoteLink; return self::$_footnoteLink;
} }
@ -118,8 +124,8 @@ class PHPWord_Footnote {
* *
* @return int * @return int
*/ */
public static function countFootnoteLinkElements() { public static function countFootnoteLinkElements()
{
return count(self::$_footnoteLink); return count(self::$_footnoteLink);
} }
} }

View File

@ -126,7 +126,8 @@ class PHPWord_IOFactory
* @param string $readerType Example: Word2007 * @param string $readerType Example: Word2007
* @return PHPWord_Reader_IReader * @return PHPWord_Reader_IReader
*/ */
public static function createReader($readerType = '') { public static function createReader($readerType = '')
{
$searchType = 'IReader'; $searchType = 'IReader';
foreach (self::$_searchLocations as $searchLocation) { foreach (self::$_searchLocations as $searchLocation) {
@ -134,7 +135,7 @@ class PHPWord_IOFactory
$className = str_replace('{0}', $readerType, $searchLocation['class']); $className = str_replace('{0}', $readerType, $searchLocation['class']);
$instance = new $className(); $instance = new $className();
if ($instance !== NULL) { if ($instance !== null) {
return $instance; return $instance;
} }
} }
@ -149,9 +150,9 @@ class PHPWord_IOFactory
* @param string $pFilename The name of the file * @param string $pFilename The name of the file
* @return PHPWord * @return PHPWord
*/ */
public static function load($pFilename, $readerType = 'Word2007') { public static function load($pFilename, $readerType = 'Word2007')
{
$reader = self::createReader($readerType); $reader = self::createReader($readerType);
return $reader->load($pFilename); return $reader->load($pFilename);
} }
} }

View File

@ -330,4 +330,3 @@ class PHPWord_Media
return self::$_footerMedia; return self::$_footerMedia;
} }
} }

View File

@ -36,9 +36,9 @@ abstract class PHPWord_Reader_Abstract implements PHPWord_Reader_IReader
* *
* @var boolean * @var boolean
*/ */
protected $readDataOnly = TRUE; protected $readDataOnly = true;
protected $fileHandle = NULL; protected $fileHandle = true;
/** /**
@ -46,9 +46,10 @@ abstract class PHPWord_Reader_Abstract implements PHPWord_Reader_IReader
* *
* @return boolean * @return boolean
*/ */
public function getReadDataOnly() { public function getReadDataOnly()
{
// return $this->readDataOnly; // return $this->readDataOnly;
return TRUE; return true;
} }
/** /**
@ -57,7 +58,8 @@ abstract class PHPWord_Reader_Abstract implements PHPWord_Reader_IReader
* @param boolean $pValue * @param boolean $pValue
* @return PHPWord_Reader_IReader * @return PHPWord_Reader_IReader
*/ */
public function setReadDataOnly($pValue = TRUE) { public function setReadDataOnly($pValue = true)
{
$this->readDataOnly = $pValue; $this->readDataOnly = $pValue;
return $this; return $this;
} }
@ -78,7 +80,7 @@ abstract class PHPWord_Reader_Abstract implements PHPWord_Reader_IReader
// Open file // Open file
$this->fileHandle = fopen($pFilename, 'r'); $this->fileHandle = fopen($pFilename, 'r');
if ($this->fileHandle === FALSE) { if ($this->fileHandle === false) {
throw new PHPWord_Exception("Could not open file " . $pFilename . " for reading."); throw new PHPWord_Exception("Could not open file " . $pFilename . " for reading.");
} }
} }
@ -96,10 +98,9 @@ abstract class PHPWord_Reader_Abstract implements PHPWord_Reader_IReader
try { try {
$this->openFile($pFilename); $this->openFile($pFilename);
} catch (Exception $e) { } catch (Exception $e) {
return FALSE; return false;
} }
fclose ($this->fileHandle); fclose($this->fileHandle);
return $readable; return $readable;
} }
} }

View File

@ -42,7 +42,8 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements
/** /**
* Create a new PHPWord_Reader_Word2007 instance * Create a new PHPWord_Reader_Word2007 instance
*/ */
public function __construct() { public function __construct()
{
} }
/** /**
@ -55,8 +56,10 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements
{ {
// Check if file exists // Check if file exists
if (!file_exists($pFilename)) { if (!file_exists($pFilename)) {
throw new PHPWord_Exception("Could not open " . $pFilename . throw new PHPWord_Exception(
" for reading! File does not exist."); "Could not open " . $pFilename .
" for reading! File does not exist."
);
} }
$return = false; $return = false;
@ -96,16 +99,14 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements
$removeNamespace = false $removeNamespace = false
) { ) {
// Root-relative paths // Root-relative paths
if (strpos($fileName, '//') !== false) if (strpos($fileName, '//') !== false) {
{
$fileName = substr($fileName, strpos($fileName, '//') + 1); $fileName = substr($fileName, strpos($fileName, '//') + 1);
} }
$fileName = PHPWord_Shared_File::realpath($fileName); $fileName = PHPWord_Shared_File::realpath($fileName);
// Apache POI fixes // Apache POI fixes
$contents = $archive->getFromName($fileName); $contents = $archive->getFromName($fileName);
if ($contents === false) if ($contents === false) {
{
$contents = $archive->getFromName(substr($fileName, 1)); $contents = $archive->getFromName(substr($fileName, 1));
} }
@ -128,8 +129,10 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements
{ {
// Check if file exists // Check if file exists
if (!file_exists($pFilename)) { if (!file_exists($pFilename)) {
throw new PHPWord_Exception("Could not open " . $pFilename . throw new PHPWord_Exception(
" for reading! File does not exist."); "Could not open " . $pFilename .
" for reading! File does not exist."
);
} }
// Initialisations // Initialisations
@ -149,15 +152,15 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements
$xmlCore->registerXPathNamespace("dcterms", "http://purl.org/dc/terms/"); $xmlCore->registerXPathNamespace("dcterms", "http://purl.org/dc/terms/");
$xmlCore->registerXPathNamespace("cp", "http://schemas.openxmlformats.org/package/2006/metadata/core-properties"); $xmlCore->registerXPathNamespace("cp", "http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
$docProps = $word->getProperties(); $docProps = $word->getProperties();
$docProps->setCreator((string) self::array_item($xmlCore->xpath("dc:creator"))); $docProps->setCreator((string) self::arrayItem($xmlCore->xpath("dc:creator")));
$docProps->setLastModifiedBy((string) self::array_item($xmlCore->xpath("cp:lastModifiedBy"))); $docProps->setLastModifiedBy((string) self::arrayItem($xmlCore->xpath("cp:lastModifiedBy")));
$docProps->setCreated(strtotime(self::array_item($xmlCore->xpath("dcterms:created")))); $docProps->setCreated(strtotime(self::arrayItem($xmlCore->xpath("dcterms:created"))));
$docProps->setModified(strtotime(self::array_item($xmlCore->xpath("dcterms:modified")))); $docProps->setModified(strtotime(self::arrayItem($xmlCore->xpath("dcterms:modified"))));
$docProps->setTitle((string) self::array_item($xmlCore->xpath("dc:title"))); $docProps->setTitle((string) self::arrayItem($xmlCore->xpath("dc:title")));
$docProps->setDescription((string) self::array_item($xmlCore->xpath("dc:description"))); $docProps->setDescription((string) self::arrayItem($xmlCore->xpath("dc:description")));
$docProps->setSubject((string) self::array_item($xmlCore->xpath("dc:subject"))); $docProps->setSubject((string) self::arrayItem($xmlCore->xpath("dc:subject")));
$docProps->setKeywords((string) self::array_item($xmlCore->xpath("cp:keywords"))); $docProps->setKeywords((string) self::arrayItem($xmlCore->xpath("cp:keywords")));
$docProps->setCategory((string) self::array_item($xmlCore->xpath("cp:category"))); $docProps->setCategory((string) self::arrayItem($xmlCore->xpath("cp:category")));
} }
break; break;
// Extended properties // Extended properties
@ -165,11 +168,13 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements
$xmlCore = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}")); $xmlCore = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}"));
if (is_object($xmlCore)) { if (is_object($xmlCore)) {
$docProps = $word->getProperties(); $docProps = $word->getProperties();
if (isset($xmlCore->Company)) if (isset($xmlCore->Company)) {
$docProps->setCompany((string) $xmlCore->Company); $docProps->setCompany((string) $xmlCore->Company);
if (isset($xmlCore->Manager)) }
if (isset($xmlCore->Manager)) {
$docProps->setManager((string) $xmlCore->Manager); $docProps->setManager((string) $xmlCore->Manager);
} }
}
break; break;
// Custom properties // Custom properties
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties": case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties":
@ -183,9 +188,9 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements
$cellDataOfficeChildren = $xmlProperty->children("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"); $cellDataOfficeChildren = $xmlProperty->children("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes");
$attributeType = $cellDataOfficeChildren->getName(); $attributeType = $cellDataOfficeChildren->getName();
$attributeValue = (string) $cellDataOfficeChildren->{$attributeType}; $attributeValue = (string) $cellDataOfficeChildren->{$attributeType};
$attributeValue = PHPWord_DocumentProperties::convertProperty($attributeValue,$attributeType); $attributeValue = PHPWord_DocumentProperties::convertProperty($attributeValue, $attributeType);
$attributeType = PHPWord_DocumentProperties::convertPropertyType($attributeType); $attributeType = PHPWord_DocumentProperties::convertPropertyType($attributeType);
$docProps->setCustomProperty($propertyName,$attributeValue,$attributeType); $docProps->setCustomProperty($propertyName, $attributeValue, $attributeType);
} }
} }
} }
@ -196,8 +201,9 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements
$archive = "$dir/_rels/" . basename($rel["Target"]) . ".rels"; $archive = "$dir/_rels/" . basename($rel["Target"]) . ".rels";
$relsDoc = simplexml_load_string($this->getFromZipArchive($zip, $archive)); $relsDoc = simplexml_load_string($this->getFromZipArchive($zip, $archive));
$relsDoc->registerXPathNamespace("rel", "http://schemas.openxmlformats.org/package/2006/relationships"); $relsDoc->registerXPathNamespace("rel", "http://schemas.openxmlformats.org/package/2006/relationships");
$xpath = self::array_item($relsDoc->xpath("rel:Relationship[@Type='" . $xpath = self::arrayItem(
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles']")); $relsDoc->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles']")
);
$xmlDoc = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}", true)); $xmlDoc = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}", true));
if (is_object($xmlDoc)) { if (is_object($xmlDoc)) {
$section = $word->createSection(); $section = $word->createSection();
@ -215,14 +221,18 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements
if ($elm->r) { if ($elm->r) {
// w:r = 1? It's a plain paragraph // w:r = 1? It's a plain paragraph
if (count($elm->r) == 1) { if (count($elm->r) == 1) {
$section->addText($elm->r->t, $section->addText(
$this->loadFontStyle($elm->r)); $elm->r->t,
$this->loadFontStyle($elm->r)
);
// w:r more than 1? It's a textrun // w:r more than 1? It's a textrun
} else { } else {
$textRun = $section->createTextRun(); $textRun = $section->createTextRun();
foreach ($elm->r as $r) { foreach ($elm->r as $r) {
$textRun->addText($r->t, $textRun->addText(
$this->loadFontStyle($r)); $r->t,
$this->loadFontStyle($r)
);
} }
} }
// No, it's a textbreak // No, it's a textbreak
@ -457,8 +467,8 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements
* @param mixed $key * @param mixed $key
* @return mixed|null * @return mixed|null
*/ */
private static function array_item($array, $key = 0) { private static function arrayItem($array, $key = 0)
{
return (isset($array[$key]) ? $array[$key] : null); return (isset($array[$key]) ? $array[$key] : null);
} }
} }

View File

@ -425,7 +425,8 @@ class PHPWord_Section
* @param string $text * @param string $text
* @return PHPWord_Section_Footnote * @return PHPWord_Section_Footnote
*/ */
public function createFootnote($styleParagraph = null) { public function createFootnote($styleParagraph = null)
{
$footnote = new PHPWord_Section_Footnote($styleParagraph); $footnote = new PHPWord_Section_Footnote($styleParagraph);
$refID = PHPWord_Footnote::addFootnoteElement($footnote); $refID = PHPWord_Footnote::addFootnoteElement($footnote);
$footnote->setReferenceId($refID); $footnote->setReferenceId($refID);

View File

@ -33,7 +33,8 @@
* @package PHPWord_Section * @package PHPWord_Section
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Section_Footnote { class PHPWord_Section_Footnote
{
/** /**
* Paragraph style * Paragraph style
@ -59,16 +60,17 @@ class PHPWord_Section_Footnote {
/** /**
* Create a new Footnote Element * Create a new Footnote Element
*/ */
public function __construct($styleParagraph = null) { public function __construct($styleParagraph = null)
{
$this->_elementCollection = array(); $this->_elementCollection = array();
// Set paragraph style // Set paragraph style
if(is_array($styleParagraph)) { if (is_array($styleParagraph)) {
$this->_styleParagraph = new PHPWord_Style_Paragraph(); $this->_styleParagraph = new PHPWord_Style_Paragraph();
foreach($styleParagraph as $key => $value) { foreach ($styleParagraph as $key => $value) {
if(substr($key, 0, 1) != '_') { if (substr($key, 0, 1) != '_') {
$key = '_'.$key; $key = '_' . $key;
} }
$this->_styleParagraph->setStyleValue($key, $value); $this->_styleParagraph->setStyleValue($key, $value);
} }
@ -85,7 +87,8 @@ class PHPWord_Section_Footnote {
* @var mixed $styleFont * @var mixed $styleFont
* @return PHPWord_Section_Text * @return PHPWord_Section_Text
*/ */
public function addText($text = null, $styleFont = null) { public function addText($text = null, $styleFont = null)
{
$givenText = $text; $givenText = $text;
$text = new PHPWord_Section_Text($givenText, $styleFont); $text = new PHPWord_Section_Text($givenText, $styleFont);
$this->_elementCollection[] = $text; $this->_elementCollection[] = $text;
@ -100,7 +103,8 @@ class PHPWord_Section_Footnote {
* @param mixed $styleFont * @param mixed $styleFont
* @return PHPWord_Section_Link * @return PHPWord_Section_Link
*/ */
public function addLink($linkSrc, $linkName = null, $styleFont = null) { public function addLink($linkSrc, $linkName = null, $styleFont = null)
{
$link = new PHPWord_Section_Link($linkSrc, $linkName, $styleFont); $link = new PHPWord_Section_Link($linkSrc, $linkName, $styleFont);
$rID = PHPWord_Footnote::addFootnoteLinkElement($linkSrc); $rID = PHPWord_Footnote::addFootnoteLinkElement($linkSrc);
@ -115,7 +119,8 @@ class PHPWord_Section_Footnote {
* *
* @return array * @return array
*/ */
public function getElements() { public function getElements()
{
return $this->_elementCollection; return $this->_elementCollection;
} }
@ -124,7 +129,8 @@ class PHPWord_Section_Footnote {
* *
* @return PHPWord_Style_Paragraph * @return PHPWord_Style_Paragraph
*/ */
public function getParagraphStyle() { public function getParagraphStyle()
{
return $this->_styleParagraph; return $this->_styleParagraph;
} }
@ -133,7 +139,8 @@ class PHPWord_Section_Footnote {
* *
* @return int * @return int
*/ */
public function getReferenceId() { public function getReferenceId()
{
return $this->_refId; return $this->_refId;
} }
@ -142,7 +149,8 @@ class PHPWord_Section_Footnote {
* *
* @param int $refId * @param int $refId
*/ */
public function setReferenceId($refId) { public function setReferenceId($refId)
{
$this->_refId = $refId; $this->_refId = $refId;
} }
} }

View File

@ -292,5 +292,4 @@ class PHPWord_Section_Header
{ {
return $this->_type = PHPWord_Section_Header::EVEN; return $this->_type = PHPWord_Section_Header::EVEN;
} }
} }

View File

@ -616,7 +616,8 @@ class PHPWord_Section_Settings
* *
* @return int * @return int
*/ */
public function getHeaderHeight() { public function getHeaderHeight()
{
return $this->headerHeight; return $this->headerHeight;
} }
@ -625,7 +626,8 @@ class PHPWord_Section_Settings
* *
* @param int $pValue * @param int $pValue
*/ */
public function setHeaderHeight($pValue = '') { public function setHeaderHeight($pValue = '')
{
if (!is_numeric($pValue)) { if (!is_numeric($pValue)) {
$pValue = 720; $pValue = 720;
} }
@ -638,7 +640,8 @@ class PHPWord_Section_Settings
* *
* @return int * @return int
*/ */
public function getFooterHeight() { public function getFooterHeight()
{
return $this->footerHeight; return $this->footerHeight;
} }
@ -647,7 +650,8 @@ class PHPWord_Section_Settings
* *
* @param int $pValue * @param int $pValue
*/ */
public function setFooterHeight($pValue = '') { public function setFooterHeight($pValue = '')
{
if (!is_numeric($pValue)) { if (!is_numeric($pValue)) {
$pValue = 720; $pValue = 720;
} }
@ -660,7 +664,8 @@ class PHPWord_Section_Settings
* *
* @param int $pValue * @param int $pValue
*/ */
public function setColsNum($pValue = '') { public function setColsNum($pValue = '')
{
if (!is_numeric($pValue)) { if (!is_numeric($pValue)) {
$pValue = 1; $pValue = 1;
} }
@ -673,7 +678,8 @@ class PHPWord_Section_Settings
* *
* @return int * @return int
*/ */
public function getColsNum() { public function getColsNum()
{
return $this->_colsNum; return $this->_colsNum;
} }
@ -682,7 +688,8 @@ class PHPWord_Section_Settings
* *
* @param int $pValue * @param int $pValue
*/ */
public function setColsSpace($pValue = '') { public function setColsSpace($pValue = '')
{
if (!is_numeric($pValue)) { if (!is_numeric($pValue)) {
$pValue = 720; $pValue = 720;
} }
@ -695,7 +702,8 @@ class PHPWord_Section_Settings
* *
* @return int * @return int
*/ */
public function getColsSpace() { public function getColsSpace()
{
return $this->_colsSpace; return $this->_colsSpace;
} }
@ -704,7 +712,8 @@ class PHPWord_Section_Settings
* *
* @param string $pValue * @param string $pValue
*/ */
public function setBreakType($pValue = null) { public function setBreakType($pValue = null)
{
$this->_breakType = $pValue; $this->_breakType = $pValue;
return $this; return $this;
} }
@ -714,8 +723,8 @@ class PHPWord_Section_Settings
* *
* @return string * @return string
*/ */
public function getBreakType() { public function getBreakType()
{
return $this->_breakType; return $this->_breakType;
} }
} }

View File

@ -160,5 +160,4 @@ class PHPWord_Section_Table
{ {
return $this->_width; return $this->_width;
} }
} }

View File

@ -116,7 +116,8 @@ class PHPWord_Section_TextRun
* @param mixed $styleFont * @param mixed $styleFont
* @return PHPWord_Section_Image * @return PHPWord_Section_Image
*/ */
public function addImage($imageSrc, $style = null) { public function addImage($imageSrc, $style = null)
{
$image = new PHPWord_Section_Image($imageSrc, $style); $image = new PHPWord_Section_Image($imageSrc, $style);
if (!is_null($image->getSource())) { if (!is_null($image->getSource())) {
@ -136,7 +137,8 @@ class PHPWord_Section_TextRun
* @param string $text * @param string $text
* @return PHPWord_Section_Footnote * @return PHPWord_Section_Footnote
*/ */
public function createFootnote($styleParagraph = null) { public function createFootnote($styleParagraph = null)
{
$footnote = new PHPWord_Section_Footnote($styleParagraph); $footnote = new PHPWord_Section_Footnote($styleParagraph);
$refID = PHPWord_Footnote::addFootnoteElement($footnote); $refID = PHPWord_Footnote::addFootnoteElement($footnote);
$footnote->setReferenceId($refID); $footnote->setReferenceId($refID);

View File

@ -88,5 +88,4 @@ class PHPWord_Shared_Font
{ {
return ($sizeInPoint * 20); return ($sizeInPoint * 20);
} }
} }

View File

@ -266,5 +266,4 @@ class PHPWord_Shared_String
$count = strlen($value); $count = strlen($value);
return $count; return $count;
} }
} }

View File

@ -121,7 +121,7 @@ class PHPWord_Shared_ZipStreamWrapper
/** /**
* Read stream * Read stream
*/ */
function stream_read($count) public function stream_read($count)
{ {
$ret = substr($this->_data, $this->_position, $count); $ret = substr($this->_data, $this->_position, $count);
$this->_position += strlen($ret); $this->_position += strlen($ret);

View File

@ -175,4 +175,3 @@ class PHPWord_Style
} }
} }
} }

View File

@ -123,7 +123,7 @@ class PHPWord_Style_Cell
* *
* @var integer * @var integer
*/ */
private $_gridSpan = NULL; private $_gridSpan = null;
/** /**
* rowspan (restart, continue) * rowspan (restart, continue)
@ -133,7 +133,7 @@ class PHPWord_Style_Cell
* *
* @var string * @var string
*/ */
private $_vMerge = NULL; private $_vMerge = null;
/** /**
* Create a new Cell Style * Create a new Cell Style

View File

@ -81,5 +81,4 @@ class PHPWord_Style_Row
{ {
return $this->_cantSplit ? 1 : 0; return $this->_cantSplit ? 1 : 0;
} }
} }

View File

@ -92,7 +92,7 @@ class PHPWord_Style_Tab
* @param int $position Must be an integer; otherwise defaults to 0. * @param int $position Must be an integer; otherwise defaults to 0.
* @param string $leader Defaults to NULL if value is not possible. * @param string $leader Defaults to NULL if value is not possible.
*/ */
public function __construct($val = NULL, $position = 0, $leader = NULL) public function __construct($val = null, $position = 0, $leader = null)
{ {
// Default to clear if the stop type is not matched // Default to clear if the stop type is not matched
$this->_val = (self::isStopType($val)) ? $val : 'clear'; $this->_val = (self::isStopType($val)) ? $val : 'clear';
@ -101,7 +101,7 @@ class PHPWord_Style_Tab
$this->_position = (is_numeric($position)) ? intval($position) : 0; $this->_position = (is_numeric($position)) ? intval($position) : 0;
// Default to NULL if no tab leader // Default to NULL if no tab leader
$this->_leader = (self::isLeaderType($leader)) ? $leader : NULL; $this->_leader = (self::isLeaderType($leader)) ? $leader : null;
} }
/** /**
@ -109,7 +109,7 @@ class PHPWord_Style_Tab
* *
* @param PHPWord_Shared_XMLWriter $objWriter * @param PHPWord_Shared_XMLWriter $objWriter
*/ */
public function toXml(PHPWord_Shared_XMLWriter &$objWriter = NULL) public function toXml(PHPWord_Shared_XMLWriter &$objWriter = null)
{ {
if (isset($objWriter)) { if (isset($objWriter)) {
$objWriter->startElement("w:tab"); $objWriter->startElement("w:tab");

View File

@ -51,7 +51,7 @@ class PHPWord_Style_Tabs
* *
* @param PHPWord_Shared_XMLWriter $objWriter * @param PHPWord_Shared_XMLWriter $objWriter
*/ */
public function toXml(PHPWord_Shared_XMLWriter &$objWriter = NULL) public function toXml(PHPWord_Shared_XMLWriter &$objWriter = null)
{ {
if (isset($objWriter)) { if (isset($objWriter)) {
$objWriter->startElement("w:tabs"); $objWriter->startElement("w:tabs");

View File

@ -133,7 +133,7 @@ class PHPWord_Template
} }
$replace = htmlspecialchars($replace); $replace = htmlspecialchars($replace);
} else { } else {
foreach($replace as $key=>$value) { foreach ($replace as $key => $value) {
$replace[$key] = htmlspecialchars($value); $replace[$key] = htmlspecialchars($value);
} }
} }
@ -157,7 +157,8 @@ class PHPWord_Template
* *
* @param mixed $offset * @param mixed $offset
*/ */
private function _findRowStart($offset) { private function _findRowStart($offset)
{
$rowStart = strrpos($this->_documentXML, "<w:tr ", ((strlen($this->_documentXML) - $offset) * -1)); $rowStart = strrpos($this->_documentXML, "<w:tr ", ((strlen($this->_documentXML) - $offset) * -1));
if (!$rowStart) { if (!$rowStart) {
$rowStart = strrpos($this->_documentXML, "<w:tr>", ((strlen($this->_documentXML) - $offset) * -1)); $rowStart = strrpos($this->_documentXML, "<w:tr>", ((strlen($this->_documentXML) - $offset) * -1));
@ -174,7 +175,8 @@ class PHPWord_Template
* *
* @param mixed $offset * @param mixed $offset
*/ */
private function _findRowEnd($offset) { private function _findRowEnd($offset)
{
$rowEnd = strpos($this->_documentXML, "</w:tr>", $offset) + 7; $rowEnd = strpos($this->_documentXML, "</w:tr>", $offset) + 7;
return $rowEnd; return $rowEnd;
} }
@ -184,7 +186,8 @@ class PHPWord_Template
* *
* @param mixed $offset * @param mixed $offset
*/ */
private function _getSlice($startPosition, $endPosition = 0) { private function _getSlice($startPosition, $endPosition = 0)
{
if (!$endPosition) { if (!$endPosition) {
$endPosition = strlen($this->_documentXML); $endPosition = strlen($this->_documentXML);
} }
@ -197,8 +200,9 @@ class PHPWord_Template
* @param mixed $search * @param mixed $search
* @param mixed $numberOfClones * @param mixed $numberOfClones
*/ */
public function cloneRow($search, $numberOfClones) { public function cloneRow($search, $numberOfClones)
if(substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') { {
if (substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') {
$search = '${'.$search.'}'; $search = '${'.$search.'}';
} }
@ -216,7 +220,7 @@ class PHPWord_Template
if (preg_match('#<w:vMerge w:val="restart"/>#', $xmlRow)) { if (preg_match('#<w:vMerge w:val="restart"/>#', $xmlRow)) {
$extraRowStart = $rowEnd; $extraRowStart = $rowEnd;
$extraRowEnd = $rowEnd; $extraRowEnd = $rowEnd;
while(true) { while (true) {
$extraRowStart = $this->_findRowStart($extraRowEnd + 1); $extraRowStart = $this->_findRowStart($extraRowEnd + 1);
$extraRowEnd = $this->_findRowEnd($extraRowEnd + 1); $extraRowEnd = $this->_findRowEnd($extraRowEnd + 1);
@ -238,7 +242,7 @@ class PHPWord_Template
$result = $this->_getSlice(0, $rowStart); $result = $this->_getSlice(0, $rowStart);
for ($i = 1; $i <= $numberOfClones; $i++) { for ($i = 1; $i <= $numberOfClones; $i++) {
$result .= preg_replace('/\$\{(.*?)\}/','\${\\1#'.$i.'}', $xmlRow); $result .= preg_replace('/\$\{(.*?)\}/', '\${\\1#'.$i.'}', $xmlRow);
} }
$result .= $this->_getSlice($rowEnd); $result .= $this->_getSlice($rowEnd);
@ -250,7 +254,8 @@ class PHPWord_Template
* *
* @return string * @return string
*/ */
public function save() { public function save()
{
$this->_objZip->addFromString('word/document.xml', $this->_documentXML); $this->_objZip->addFromString('word/document.xml', $this->_documentXML);
// Close zip file // Close zip file
@ -266,7 +271,8 @@ class PHPWord_Template
* *
* @param string $strFilename * @param string $strFilename
*/ */
public function saveAs($strFilename) { public function saveAs($strFilename)
{
$tempFilename = $this->save(); $tempFilename = $this->save();
if (file_exists($strFilename)) { if (file_exists($strFilename)) {

View File

@ -236,7 +236,7 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
* @param string $pPartName Writer part name * @param string $pPartName Writer part name
* @return PHPWord_Writer_ODText_WriterPart * @return PHPWord_Writer_ODText_WriterPart
*/ */
function getWriterPart($pPartName = '') public function getWriterPart($pPartName = '')
{ {
if ($pPartName != '' && isset($this->_writerParts[strtolower($pPartName)])) { if ($pPartName != '' && isset($this->_writerParts[strtolower($pPartName)])) {
return $this->_writerParts[strtolower($pPartName)]; return $this->_writerParts[strtolower($pPartName)];

View File

@ -249,27 +249,27 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
foreach ($_elements as $element) { foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) { if ($element instanceof PHPWord_Section_Text) {
$this->_writeText($objWriter, $element); $this->_writeText($objWriter, $element);
} elseif($element instanceof PHPWord_Section_TextRun) { } elseif ($element instanceof PHPWord_Section_TextRun) {
$this->_writeTextRun($objWriter, $element); $this->_writeTextRun($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextBreak) { } elseif ($element instanceof PHPWord_Section_TextBreak) {
$this->_writeTextBreak($objWriter); $this->_writeTextBreak($objWriter);
/* /*
} elseif($element instanceof PHPWord_Section_Link) { } elseif ($element instanceof PHPWord_Section_Link) {
$this->_writeLink($objWriter, $element); $this->_writeLink($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Title) { } elseif ($element instanceof PHPWord_Section_Title) {
$this->_writeTitle($objWriter, $element); $this->_writeTitle($objWriter, $element);
} elseif($element instanceof PHPWord_Section_PageBreak) { } elseif ($element instanceof PHPWord_Section_PageBreak) {
$this->_writePageBreak($objWriter); $this->_writePageBreak($objWriter);
} elseif($element instanceof PHPWord_Section_Table) { } elseif ($element instanceof PHPWord_Section_Table) {
$this->_writeTable($objWriter, $element); $this->_writeTable($objWriter, $element);
} elseif($element instanceof PHPWord_Section_ListItem) { } elseif ($element instanceof PHPWord_Section_ListItem) {
$this->_writeListItem($objWriter, $element); $this->_writeListItem($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Image || } elseif ($element instanceof PHPWord_Section_Image ||
$element instanceof PHPWord_Section_MemoryImage) { $element instanceof PHPWord_Section_MemoryImage) {
$this->_writeImage($objWriter, $element); $this->_writeImage($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Object) { } elseif ($element instanceof PHPWord_Section_Object) {
$this->_writeObject($objWriter, $element); $this->_writeObject($objWriter, $element);
} elseif($element instanceof PHPWord_TOC) { } elseif ($element instanceof PHPWord_TOC) {
$this->_writeTOC($objWriter); $this->_writeTOC($objWriter);
*/ */
} else { } else {
@ -303,8 +303,8 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
protected function _writeText( protected function _writeText(
PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Shared_XMLWriter $objWriter = null,
PHPWord_Section_Text $text, PHPWord_Section_Text $text,
$withoutP = false) $withoutP = false
{ ) {
$styleFont = $text->getFontStyle(); $styleFont = $text->getFontStyle();
$styleParagraph = $text->getParagraphStyle(); $styleParagraph = $text->getParagraphStyle();
@ -351,9 +351,7 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
* @param PHPWord_Section_TextRun $textrun * @param PHPWord_Section_TextRun $textrun
* @todo Enable all other section types * @todo Enable all other section types
*/ */
protected function _writeTextRun( protected function _writeTextRun(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_TextRun $textrun)
PHPWord_Shared_XMLWriter $objWriter = null,
PHPWord_Section_TextRun $textrun)
{ {
$elements = $textrun->getElements(); $elements = $textrun->getElements();
$objWriter->startElement('text:p'); $objWriter->startElement('text:p');
@ -377,7 +375,7 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
$objWriter->endElement(); $objWriter->endElement();
} }
private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section) private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section = null)
{ {
} }
@ -386,9 +384,7 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
* *
* @todo Create the real function * @todo Create the real function
*/ */
private function _writeSection( private function _writeSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section = null)
PHPWord_Shared_XMLWriter $objWriter = null,
PHPWord_Section $section)
{ {
} }
} }

View File

@ -42,5 +42,4 @@ class PHPWord_Writer_ODText_Mimetype extends PHPWord_Writer_ODText_WriterPart
return 'application/vnd.oasis.opendocument.text'; return 'application/vnd.oasis.opendocument.text';
} }
} }

View File

@ -182,8 +182,8 @@ class PHPWord_Writer_ODText_Styles extends PHPWord_Writer_ODText_WriterPart
} }
$objWriter->endElement(); $objWriter->endElement();
$objWriter->endElement(); $objWriter->endElement();
} // PHPWord_Style_Paragraph } elseif ($style instanceof PHPWord_Style_Paragraph) {
elseif ($style instanceof PHPWord_Style_Paragraph) { // PHPWord_Style_Paragraph
// style:style // style:style
$objWriter->startElement('style:style'); $objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName); $objWriter->writeAttribute('style:name', $styleName);
@ -197,9 +197,8 @@ class PHPWord_Writer_ODText_Styles extends PHPWord_Writer_ODText_WriterPart
$objWriter->endElement(); $objWriter->endElement();
$objWriter->endElement(); $objWriter->endElement();
} elseif ($style instanceof PHPWord_Style_TableFull) {
} // PHPWord_Style_TableFull // PHPWord_Style_TableFull
elseif ($style instanceof PHPWord_Style_TableFull) {
} }
} }
} }

View File

@ -81,7 +81,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
} }
$hFile = fopen($pFilename, 'w') or die("can't open file"); $hFile = fopen($pFilename, 'w') or die("can't open file");
fwrite($hFile, $this->_getData()); fwrite($hFile, $this->getData());
fclose($hFile); fclose($hFile);
// If a temporary file was used, copy it to the correct file stream // If a temporary file was used, copy it to the correct file stream
@ -135,11 +135,11 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
return $this->_drawingHashTable; return $this->_drawingHashTable;
} }
private function _getData() private function getData()
{ {
// PHPWord object : $this->_document // PHPWord object : $this->_document
$this->_fontTable = $this->_getDataFont(); $this->_fontTable = $this->getDataFont();
$this->_colorTable = $this->_getDataColor(); $this->_colorTable = $this->getDataColor();
$sRTFContent = '{\rtf1'; $sRTFContent = '{\rtf1';
// Set the default character set // Set the default character set
@ -180,7 +180,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
$sRTFContent .= '\fs' . (PHPWord::DEFAULT_FONT_SIZE * 2); $sRTFContent .= '\fs' . (PHPWord::DEFAULT_FONT_SIZE * 2);
$sRTFContent .= PHP_EOL; $sRTFContent .= PHP_EOL;
// Body // Body
$sRTFContent .= $this->_getDataContent(); $sRTFContent .= $this->getDataContent();
$sRTFContent .= '}'; $sRTFContent .= '}';
@ -188,7 +188,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
return $sRTFContent; return $sRTFContent;
} }
private function _getDataFont() private function getDataFont()
{ {
$pPHPWord = $this->_document; $pPHPWord = $this->_document;
@ -204,7 +204,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
foreach ($styles as $styleName => $style) { foreach ($styles as $styleName => $style) {
// PHPWord_Style_Font // PHPWord_Style_Font
if ($style instanceof PHPWord_Style_Font) { if ($style instanceof PHPWord_Style_Font) {
if (in_array($style->getName(), $arrFonts) == FALSE) { if (in_array($style->getName(), $arrFonts) == false) {
$arrFonts[] = $style->getName(); $arrFonts[] = $style->getName();
} }
} }
@ -226,7 +226,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
$fStyle = $element->getFontStyle(); $fStyle = $element->getFontStyle();
if ($fStyle instanceof PHPWord_Style_Font) { if ($fStyle instanceof PHPWord_Style_Font) {
if (in_array($fStyle->getName(), $arrFonts) == FALSE) { if (in_array($fStyle->getName(), $arrFonts) == false) {
$arrFonts[] = $fStyle->getName(); $arrFonts[] = $fStyle->getName();
} }
} }
@ -238,7 +238,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
return $arrFonts; return $arrFonts;
} }
private function _getDataColor() private function getDataColor()
{ {
$pPHPWord = $this->_document; $pPHPWord = $this->_document;
@ -254,10 +254,10 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
if ($style instanceof PHPWord_Style_Font) { if ($style instanceof PHPWord_Style_Font) {
$color = $style->getColor(); $color = $style->getColor();
$fgcolor = $style->getFgColor(); $fgcolor = $style->getFgColor();
if (in_array($color, $arrColors) == FALSE && $color != PHPWord::DEFAULT_FONT_COLOR && !empty($color)) { if (in_array($color, $arrColors) == false && $color != PHPWord::DEFAULT_FONT_COLOR && !empty($color)) {
$arrColors[] = $color; $arrColors[] = $color;
} }
if (in_array($fgcolor, $arrColors) == FALSE && $fgcolor != PHPWord::DEFAULT_FONT_COLOR && !empty($fgcolor)) { if (in_array($fgcolor, $arrColors) == false && $fgcolor != PHPWord::DEFAULT_FONT_COLOR && !empty($fgcolor)) {
$arrColors[] = $fgcolor; $arrColors[] = $fgcolor;
} }
} }
@ -279,10 +279,10 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
$fStyle = $element->getFontStyle(); $fStyle = $element->getFontStyle();
if ($fStyle instanceof PHPWord_Style_Font) { if ($fStyle instanceof PHPWord_Style_Font) {
if (in_array($fStyle->getColor(), $arrColors) == FALSE) { if (in_array($fStyle->getColor(), $arrColors) == false) {
$arrColors[] = $fStyle->getColor(); $arrColors[] = $fStyle->getColor();
} }
if (in_array($fStyle->getFgColor(), $arrColors) == FALSE) { if (in_array($fStyle->getFgColor(), $arrColors) == false) {
$arrColors[] = $fStyle->getFgColor(); $arrColors[] = $fStyle->getFgColor();
} }
} }
@ -294,7 +294,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
return $arrColors; return $arrColors;
} }
private function _getDataContent() private function getDataContent()
{ {
$pPHPWord = $this->_document; $pPHPWord = $this->_document;
$sRTFBody = ''; $sRTFBody = '';
@ -309,11 +309,11 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
$_elements = $section->getElements(); $_elements = $section->getElements();
foreach ($_elements as $element) { foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) { if ($element instanceof PHPWord_Section_Text) {
$sRTFBody .= $this->_getDataContent_writeText($element); $sRTFBody .= $this->getDataContentText($element);
} elseif ($element instanceof PHPWord_Section_TextBreak) { } elseif ($element instanceof PHPWord_Section_TextBreak) {
$sRTFBody .= $this->_getDataContent_writeTextBreak(); $sRTFBody .= $this->getDataContentTextBreak();
} elseif ($element instanceof PHPWord_Section_TextRun) { } elseif ($element instanceof PHPWord_Section_TextRun) {
$sRTFBody .= $this->_getDataContent_writeTextRun($element); $sRTFBody .= $this->getDataContentTextRun($element);
/* /*
} elseif($element instanceof PHPWord_Section_Link) { } elseif($element instanceof PHPWord_Section_Link) {
$this->_writeLink($objWriter, $element); $this->_writeLink($objWriter, $element);
@ -346,7 +346,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
/** /**
* Get text * Get text
*/ */
private function _getDataContent_writeText(PHPWord_Section_Text $text, $withoutP = false) private function getDataContentText(PHPWord_Section_Text $text, $withoutP = false)
{ {
$sRTFText = ''; $sRTFText = '';
@ -384,7 +384,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
if ($styleFont) { if ($styleFont) {
if ($styleFont->getColor() != null) { if ($styleFont->getColor() != null) {
$idxColor = array_search($styleFont->getColor(), $this->_colorTable); $idxColor = array_search($styleFont->getColor(), $this->_colorTable);
if ($idxColor !== FALSE) { if ($idxColor !== false) {
$sRTFText .= '\cf' . ($idxColor + 1); $sRTFText .= '\cf' . ($idxColor + 1);
} }
} else { } else {
@ -392,7 +392,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
} }
if ($styleFont->getName() != null) { if ($styleFont->getName() != null) {
$idxFont = array_search($styleFont->getName(), $this->_fontTable); $idxFont = array_search($styleFont->getName(), $this->_fontTable);
if ($idxFont !== FALSE) { if ($idxFont !== false) {
$sRTFText .= '\f' . $idxFont; $sRTFText .= '\f' . $idxFont;
} }
} else { } else {
@ -411,7 +411,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
if ($this->_lastParagraphStyle != '' || $styleFont) { if ($this->_lastParagraphStyle != '' || $styleFont) {
$sRTFText .= ' '; $sRTFText .= ' ';
} }
$sRTFText .= $text->getText(); $sRTFText .= $text->getDataContentText();
if ($styleFont) { if ($styleFont) {
$sRTFText .= '\cf0'; $sRTFText .= '\cf0';
@ -437,7 +437,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
/** /**
* Get text run content * Get text run content
*/ */
private function _getDataContent_writeTextRun(PHPWord_Section_TextRun $textrun) private function getDataContentTextRun(PHPWord_Section_TextRun $textrun)
{ {
$sRTFText = ''; $sRTFText = '';
$elements = $textrun->getElements(); $elements = $textrun->getElements();
@ -446,7 +446,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
foreach ($elements as $element) { foreach ($elements as $element) {
if ($element instanceof PHPWord_Section_Text) { if ($element instanceof PHPWord_Section_Text) {
$sRTFText .= '{'; $sRTFText .= '{';
$sRTFText .= $this->_getDataContent_writeText($element, true); $sRTFText .= $this->getDataContentText($element, true);
$sRTFText .= '}' . PHP_EOL; $sRTFText .= '}' . PHP_EOL;
} }
} }
@ -455,12 +455,10 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
return $sRTFText; return $sRTFText;
} }
private function _getDataContent_writeTextBreak() private function getDataContentTextBreak()
{ {
$this->_lastParagraphStyle = ''; $this->_lastParagraphStyle = '';
return '\par' . PHP_EOL; return '\par' . PHP_EOL;
} }
} }

View File

@ -115,7 +115,8 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
$footnoteLinks = array(); $footnoteLinks = array();
$_footnoteElements = PHPWord_Footnote::getFootnoteLinkElements(); $_footnoteElements = PHPWord_Footnote::getFootnoteLinkElements();
foreach($_footnoteElements as $element) { // loop through footnote link elements // loop through footnote link elements
foreach ($_footnoteElements as $element) {
$footnoteLinks[] = $element; $footnoteLinks[] = $element;
} }
@ -204,8 +205,9 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
$imagetype = image_type_to_mime_type($imagedata[2]); $imagetype = image_type_to_mime_type($imagedata[2]);
$imageext = image_type_to_extension($imagedata[2]); $imageext = image_type_to_extension($imagedata[2]);
$imageext = str_replace('.', '', $imageext); $imageext = str_replace('.', '', $imageext);
if ($imageext == 'jpeg') $imageext = 'jpg'; if ($imageext == 'jpeg') {
$imageext = 'jpg';
}
if (!in_array($imagetype, $this->_imageTypes)) { if (!in_array($imagetype, $this->_imageTypes)) {
$this->_imageTypes[$imageext] = $imagetype; $this->_imageTypes[$imageext] = $imagetype;
} }

View File

@ -108,7 +108,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
$this->_writeLink($objWriter, $element, true); $this->_writeLink($objWriter, $element, true);
} elseif ($element instanceof PHPWord_Section_Image) { } elseif ($element instanceof PHPWord_Section_Image) {
$this->_writeImage($objWriter, $element, true); $this->_writeImage($objWriter, $element, true);
} elseif($element instanceof PHPWord_Section_Footnote) { } elseif ($element instanceof PHPWord_Section_Footnote) {
$this->_writeFootnoteReference($objWriter, $element, true); $this->_writeFootnoteReference($objWriter, $element, true);
} }
} }
@ -875,7 +875,8 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
$objWriter->endElement(); $objWriter->endElement();
} }
protected function _writeFootnote(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote) { protected function _writeFootnote(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote)
{
$objWriter->startElement('w:footnote'); $objWriter->startElement('w:footnote');
$objWriter->writeAttribute('w:id', $footnote->getReferenceId()); $objWriter->writeAttribute('w:id', $footnote->getReferenceId());
@ -884,9 +885,9 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
$objWriter->startElement('w:p'); $objWriter->startElement('w:p');
if($SpIsObject) { if ($SpIsObject) {
$this->_writeParagraphStyle($objWriter, $styleParagraph); $this->_writeParagraphStyle($objWriter, $styleParagraph);
} elseif(!$SpIsObject && !is_null($styleParagraph)) { } elseif (!$SpIsObject && !is_null($styleParagraph)) {
$objWriter->startElement('w:pPr'); $objWriter->startElement('w:pPr');
$objWriter->startElement('w:pStyle'); $objWriter->startElement('w:pStyle');
$objWriter->writeAttribute('w:val', $styleParagraph); $objWriter->writeAttribute('w:val', $styleParagraph);
@ -895,11 +896,11 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
} }
$elements = $footnote->getElements(); $elements = $footnote->getElements();
if(count($elements) > 0) { if (count($elements) > 0) {
foreach($elements as $element) { foreach ($elements as $element) {
if($element instanceof PHPWord_Section_Text) { if ($element instanceof PHPWord_Section_Text) {
$this->_writeText($objWriter, $element, true); $this->_writeText($objWriter, $element, true);
} elseif($element instanceof PHPWord_Section_Link) { } elseif ($element instanceof PHPWord_Section_Link) {
$this->_writeLink($objWriter, $element, true); $this->_writeLink($objWriter, $element, true);
} }
} }
@ -909,7 +910,8 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
$objWriter->endElement(); // w:footnote $objWriter->endElement(); // w:footnote
} }
protected function _writeFootnoteReference(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote, $withoutP = false) { protected function _writeFootnoteReference(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote, $withoutP = false)
{
if (!$withoutP) { if (!$withoutP) {
$objWriter->startElement('w:p'); $objWriter->startElement('w:p');
} }

View File

@ -50,12 +50,16 @@ class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_Write
// Rels // Rels
$this->_writeDefaultContentType( $this->_writeDefaultContentType(
$objWriter, 'rels', 'application/vnd.openxmlformats-package.relationships+xml' $objWriter,
'rels',
'application/vnd.openxmlformats-package.relationships+xml'
); );
// XML // XML
$this->_writeDefaultContentType( $this->_writeDefaultContentType(
$objWriter, 'xml', 'application/xml' $objWriter,
'xml',
'application/xml'
); );
// Add media content-types // Add media content-types
@ -65,62 +69,88 @@ class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_Write
// Add embedding content-types // Add embedding content-types
if (count($_objectTypes) > 0) { if (count($_objectTypes) > 0) {
$this->_writeDefaultContentType($objWriter, 'bin', 'application/vnd.openxmlformats-officedocument.oleObject'); $this->_writeDefaultContentType(
$objWriter,
'bin',
'application/vnd.openxmlformats-officedocument.oleObject'
);
} }
// DocProps // DocProps
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/docProps/app.xml', 'application/vnd.openxmlformats-officedocument.extended-properties+xml' $objWriter,
'/docProps/app.xml',
'application/vnd.openxmlformats-officedocument.extended-properties+xml'
); );
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/docProps/core.xml', 'application/vnd.openxmlformats-package.core-properties+xml' $objWriter,
'/docProps/core.xml',
'application/vnd.openxmlformats-package.core-properties+xml'
); );
// Document // Document
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/word/document.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml' $objWriter,
'/word/document.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'
); );
// Styles // Styles
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/word/styles.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml' $objWriter,
'/word/styles.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml'
); );
// Numbering // Numbering
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/word/numbering.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml' $objWriter,
'/word/numbering.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml'
); );
// Settings // Settings
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/word/settings.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml' $objWriter,
'/word/settings.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml'
); );
// Theme1 // Theme1
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/word/theme/theme1.xml', 'application/vnd.openxmlformats-officedocument.theme+xml' $objWriter,
'/word/theme/theme1.xml',
'application/vnd.openxmlformats-officedocument.theme+xml'
); );
// WebSettings // WebSettings
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/word/webSettings.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml' $objWriter,
'/word/webSettings.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml'
); );
// Font Table // Font Table
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/word/fontTable.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml' $objWriter,
'/word/fontTable.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml'
); );
for ($i = 1; $i <= $_cHdrs; $i++) { for ($i = 1; $i <= $_cHdrs; $i++) {
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/word/header' . $i . '.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml' $objWriter,
'/word/header' . $i . '.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml'
); );
} }
for ($i = 1; $i <= $_cFtrs; $i++) { for ($i = 1; $i <= $_cFtrs; $i++) {
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/word/footer' . $i . '.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml' $objWriter,
'/word/footer' . $i . '.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml'
); );
} }

View File

@ -94,7 +94,7 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base
$this->_writeObject($objWriter, $element); $this->_writeObject($objWriter, $element);
} elseif ($element instanceof PHPWord_TOC) { } elseif ($element instanceof PHPWord_TOC) {
$this->_writeTOC($objWriter); $this->_writeTOC($objWriter);
} elseif($element instanceof PHPWord_Section_Footnote) { } elseif ($element instanceof PHPWord_Section_Footnote) {
$this->_writeFootnoteReference($objWriter, $element); $this->_writeFootnoteReference($objWriter, $element);
} }
} }

View File

@ -26,8 +26,10 @@
*/ */
class PHPWord_Writer_Word2007_Footnotes extends PHPWord_Writer_Word2007_Base { class PHPWord_Writer_Word2007_Footnotes extends PHPWord_Writer_Word2007_Base
public function writeFootnotes($allFootnotesCollection) { {
public function writeFootnotes($allFootnotesCollection)
{
// Create XML writer // Create XML writer
$objWriter = null; $objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) { if ($this->getParentWriter()->getUseDiskCaching()) {
@ -40,8 +42,8 @@ class PHPWord_Writer_Word2007_Footnotes extends PHPWord_Writer_Word2007_Base {
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); $objWriter->startDocument('1.0', 'UTF-8', 'yes');
$objWriter->startElement('w:footnotes'); $objWriter->startElement('w:footnotes');
$objWriter->writeAttribute('xmlns:r','http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:w','http://schemas.openxmlformats.org/wordprocessingml/2006/main'); $objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
// write separator and continuation separator // write separator and continuation separator
$objWriter->startElement('w:footnote'); $objWriter->startElement('w:footnote');
@ -67,8 +69,8 @@ class PHPWord_Writer_Word2007_Footnotes extends PHPWord_Writer_Word2007_Base {
$objWriter->endElement(); // w:footnote $objWriter->endElement(); // w:footnote
foreach($allFootnotesCollection as $footnote) { foreach ($allFootnotesCollection as $footnote) {
if($footnote instanceof PHPWord_Section_Footnote) { if ($footnote instanceof PHPWord_Section_Footnote) {
$this->_writeFootnote($objWriter, $footnote); $this->_writeFootnote($objWriter, $footnote);
} }
} }

View File

@ -26,8 +26,10 @@
*/ */
class PHPWord_Writer_Word2007_FootnotesRels extends PHPWord_Writer_Word2007_WriterPart { class PHPWord_Writer_Word2007_FootnotesRels extends PHPWord_Writer_Word2007_WriterPart
public function writeFootnotesRels($_relsCollection) { {
public function writeFootnotesRels($_relsCollection)
{
// Create XML writer // Create XML writer
$objWriter = null; $objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) { if ($this->getParentWriter()->getUseDiskCaching()) {
@ -37,26 +39,20 @@ class PHPWord_Writer_Word2007_FootnotesRels extends PHPWord_Writer_Word2007_Writ
} }
// XML header // XML header
$objWriter->startDocument('1.0','UTF-8','yes'); $objWriter->startDocument('1.0', 'UTF-8', 'yes');
// Relationships // Relationships
$objWriter->startElement('Relationships'); $objWriter->startElement('Relationships');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
// Relationships to Links // Relationships to Links
foreach($_relsCollection as $relation) { foreach ($_relsCollection as $relation) {
$relationType = $relation['type']; $relationType = $relation['type'];
$relationName = $relation['target']; $relationName = $relation['target'];
$relationId = $relation['rID']; $relationId = $relation['rID'];
$targetMode = ($relationType == 'hyperlink') ? 'External' : ''; $targetMode = ($relationType == 'hyperlink') ? 'External' : '';
$this->_writeRelationship( $this->_writeRelationship($objWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, $relationName, $targetMode);
$objWriter,
$relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/'.$relationType,
$relationName,
$targetMode
);
} }
$objWriter->endElement(); $objWriter->endElement();
@ -65,9 +61,10 @@ class PHPWord_Writer_Word2007_FootnotesRels extends PHPWord_Writer_Word2007_Writ
return $objWriter->getData(); return $objWriter->getData();
} }
private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') { private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
if($pType != '' && $pTarget != '') { {
if(strpos($pId, 'rId') === false) { if ($pType != '' && $pTarget != '') {
if (strpos($pId, 'rId') === false) {
$pId = 'rId' . $pId; $pId = 'rId' . $pId;
} }
@ -77,7 +74,7 @@ class PHPWord_Writer_Word2007_FootnotesRels extends PHPWord_Writer_Word2007_Writ
$objWriter->writeAttribute('Type', $pType); $objWriter->writeAttribute('Type', $pType);
$objWriter->writeAttribute('Target', $pTarget); $objWriter->writeAttribute('Target', $pTarget);
if($pTargetMode != '') { if ($pTargetMode != '') {
$objWriter->writeAttribute('TargetMode', $pTargetMode); $objWriter->writeAttribute('TargetMode', $pTargetMode);
} }