Skip to content

Commit b58d1c8

Browse files
committed
Merge pull request #104 from ivanlanin/develop
Basic version of Reader for Word2007
2 parents 7044ebc + 530a71c commit b58d1c8

File tree

105 files changed

+2076
-664
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+2076
-664
lines changed

Classes/PHPWord.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,4 @@ public function loadTemplate($strFilename)
267267
trigger_error('Template file ' . $strFilename . ' not found.', E_USER_ERROR);
268268
}
269269
}
270-
}
270+
}

Classes/PHPWord/Autoloader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ public static function autoload($class)
8282
}
8383
}
8484
}
85-
}
85+
}

Classes/PHPWord/DocumentProperties.php

Lines changed: 271 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
*/
3131
class PHPWord_DocumentProperties
3232
{
33+
/** Constants */
34+
const PROPERTY_TYPE_BOOLEAN = 'b';
35+
const PROPERTY_TYPE_INTEGER = 'i';
36+
const PROPERTY_TYPE_FLOAT = 'f';
37+
const PROPERTY_TYPE_DATE = 'd';
38+
const PROPERTY_TYPE_STRING = 's';
39+
const PROPERTY_TYPE_UNKNOWN = 'u';
3340

3441
/**
3542
* Creator
@@ -101,21 +108,36 @@ class PHPWord_DocumentProperties
101108
*/
102109
private $_company;
103110

111+
/**
112+
* Manager
113+
*
114+
* @var string
115+
*/
116+
private $_manager;
117+
118+
/**
119+
* Custom Properties
120+
*
121+
* @var string
122+
*/
123+
private $_customProperties = array();
124+
104125
/**
105126
* Create new PHPWord_DocumentProperties
106127
*/
107128
public function __construct()
108129
{
109-
$this->_creator = '';
130+
$this->_creator = '';
110131
$this->_lastModifiedBy = $this->_creator;
111-
$this->_created = time();
112-
$this->_modified = time();
113-
$this->_title = '';
114-
$this->_subject = '';
115-
$this->_description = '';
116-
$this->_keywords = '';
117-
$this->_category = '';
118-
$this->_company = '';
132+
$this->_created = time();
133+
$this->_modified = time();
134+
$this->_title = '';
135+
$this->_subject = '';
136+
$this->_description = '';
137+
$this->_keywords = '';
138+
$this->_category = '';
139+
$this->_company = '';
140+
$this->_manager = '';
119141
}
120142

121143
/**
@@ -343,4 +365,243 @@ public function setCompany($pValue = '')
343365
$this->_company = $pValue;
344366
return $this;
345367
}
346-
}
368+
369+
/**
370+
* Get Manager
371+
*
372+
* @return string
373+
*/
374+
public function getManager()
375+
{
376+
return $this->_manager;
377+
}
378+
379+
/**
380+
* Set Manager
381+
*
382+
* @param string $pValue
383+
* @return PHPExcel_DocumentProperties
384+
*/
385+
public function setManager($pValue = '')
386+
{
387+
$this->_manager = $pValue;
388+
return $this;
389+
}
390+
391+
/**
392+
* Get a List of Custom Property Names
393+
*
394+
* @return array of string
395+
*/
396+
public function getCustomProperties()
397+
{
398+
return array_keys($this->_customProperties);
399+
}
400+
401+
/**
402+
* Check if a Custom Property is defined
403+
*
404+
* @param string $propertyName
405+
* @return boolean
406+
*/
407+
public function isCustomPropertySet($propertyName)
408+
{
409+
return isset($this->_customProperties[$propertyName]);
410+
}
411+
412+
/**
413+
* Get a Custom Property Value
414+
*
415+
* @param string $propertyName
416+
* @return string
417+
*/
418+
public function getCustomPropertyValue($propertyName)
419+
{
420+
if (isset($this->_customProperties[$propertyName])) {
421+
return $this->_customProperties[$propertyName]['value'];
422+
}
423+
424+
}
425+
426+
/**
427+
* Get a Custom Property Type
428+
*
429+
* @param string $propertyName
430+
* @return string
431+
*/
432+
public function getCustomPropertyType($propertyName)
433+
{
434+
if (isset($this->_customProperties[$propertyName])) {
435+
return $this->_customProperties[$propertyName]['type'];
436+
}
437+
438+
}
439+
440+
/**
441+
* Set a Custom Property
442+
*
443+
* @param string $propertyName
444+
* @param mixed $propertyValue
445+
* @param string $propertyType
446+
* 'i': Integer
447+
* 'f': Floating Point
448+
* 's': String
449+
* 'd': Date/Time
450+
* 'b': Boolean
451+
* @return PHPExcel_DocumentProperties
452+
*/
453+
public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null)
454+
{
455+
if (($propertyType === null) || (!in_array($propertyType, array(
456+
self::PROPERTY_TYPE_INTEGER,
457+
self::PROPERTY_TYPE_FLOAT,
458+
self::PROPERTY_TYPE_STRING,
459+
self::PROPERTY_TYPE_DATE,
460+
self::PROPERTY_TYPE_BOOLEAN
461+
)))) {
462+
if ($propertyValue === null) {
463+
$propertyType = self::PROPERTY_TYPE_STRING;
464+
} elseif (is_float($propertyValue)) {
465+
$propertyType = self::PROPERTY_TYPE_FLOAT;
466+
} elseif (is_int($propertyValue)) {
467+
$propertyType = self::PROPERTY_TYPE_INTEGER;
468+
} elseif (is_bool($propertyValue)) {
469+
$propertyType = self::PROPERTY_TYPE_BOOLEAN;
470+
} else {
471+
$propertyType = self::PROPERTY_TYPE_STRING;
472+
}
473+
}
474+
475+
$this->_customProperties[$propertyName] = array(
476+
'value' => $propertyValue,
477+
'type' => $propertyType
478+
);
479+
return $this;
480+
}
481+
482+
/**
483+
* Convert document propery based on type
484+
*
485+
* @param mixed $propertyValue
486+
* @param string $propertyType
487+
* @return mixed
488+
*/
489+
public static function convertProperty($propertyValue, $propertyType)
490+
{
491+
switch ($propertyType) {
492+
case 'empty': // Empty
493+
return '';
494+
break;
495+
case 'null': // Null
496+
return null;
497+
break;
498+
case 'i1': // 1-Byte Signed Integer
499+
case 'i2': // 2-Byte Signed Integer
500+
case 'i4': // 4-Byte Signed Integer
501+
case 'i8': // 8-Byte Signed Integer
502+
case 'int': // Integer
503+
return (int) $propertyValue;
504+
break;
505+
case 'ui1': // 1-Byte Unsigned Integer
506+
case 'ui2': // 2-Byte Unsigned Integer
507+
case 'ui4': // 4-Byte Unsigned Integer
508+
case 'ui8': // 8-Byte Unsigned Integer
509+
case 'uint': // Unsigned Integer
510+
return abs((int) $propertyValue);
511+
break;
512+
case 'r4': // 4-Byte Real Number
513+
case 'r8': // 8-Byte Real Number
514+
case 'decimal': // Decimal
515+
return (float) $propertyValue;
516+
break;
517+
case 'lpstr': // LPSTR
518+
case 'lpwstr': // LPWSTR
519+
case 'bstr': // Basic String
520+
return $propertyValue;
521+
break;
522+
case 'date': // Date and Time
523+
case 'filetime': // File Time
524+
return strtotime($propertyValue);
525+
break;
526+
case 'bool': // Boolean
527+
return ($propertyValue == 'true') ? true : false;
528+
break;
529+
case 'cy': // Currency
530+
case 'error': // Error Status Code
531+
case 'vector': // Vector
532+
case 'array': // Array
533+
case 'blob': // Binary Blob
534+
case 'oblob': // Binary Blob Object
535+
case 'stream': // Binary Stream
536+
case 'ostream': // Binary Stream Object
537+
case 'storage': // Binary Storage
538+
case 'ostorage': // Binary Storage Object
539+
case 'vstream': // Binary Versioned Stream
540+
case 'clsid': // Class ID
541+
case 'cf': // Clipboard Data
542+
return $propertyValue;
543+
break;
544+
}
545+
546+
return $propertyValue;
547+
}
548+
549+
/**
550+
* Convert document property type
551+
*
552+
* @param string $propertyType
553+
* @return mixed
554+
*/
555+
public static function convertPropertyType($propertyType)
556+
{
557+
switch ($propertyType) {
558+
case 'i1': // 1-Byte Signed Integer
559+
case 'i2': // 2-Byte Signed Integer
560+
case 'i4': // 4-Byte Signed Integer
561+
case 'i8': // 8-Byte Signed Integer
562+
case 'int': // Integer
563+
case 'ui1': // 1-Byte Unsigned Integer
564+
case 'ui2': // 2-Byte Unsigned Integer
565+
case 'ui4': // 4-Byte Unsigned Integer
566+
case 'ui8': // 8-Byte Unsigned Integer
567+
case 'uint': // Unsigned Integer
568+
return self::PROPERTY_TYPE_INTEGER;
569+
break;
570+
case 'r4': // 4-Byte Real Number
571+
case 'r8': // 8-Byte Real Number
572+
case 'decimal': // Decimal
573+
return self::PROPERTY_TYPE_FLOAT;
574+
break;
575+
case 'empty': // Empty
576+
case 'null': // Null
577+
case 'lpstr': // LPSTR
578+
case 'lpwstr': // LPWSTR
579+
case 'bstr': // Basic String
580+
return self::PROPERTY_TYPE_STRING;
581+
break;
582+
case 'date': // Date and Time
583+
case 'filetime': // File Time
584+
return self::PROPERTY_TYPE_DATE;
585+
break;
586+
case 'bool': // Boolean
587+
return self::PROPERTY_TYPE_BOOLEAN;
588+
break;
589+
case 'cy': // Currency
590+
case 'error': // Error Status Code
591+
case 'vector': // Vector
592+
case 'array': // Array
593+
case 'blob': // Binary Blob
594+
case 'oblob': // Binary Blob Object
595+
case 'stream': // Binary Stream
596+
case 'ostream': // Binary Stream Object
597+
case 'storage': // Binary Storage
598+
case 'ostorage': // Binary Storage Object
599+
case 'vstream': // Binary Versioned Stream
600+
case 'clsid': // Class ID
601+
case 'cf': // Clipboard Data
602+
return self::PROPERTY_TYPE_UNKNOWN;
603+
break;
604+
}
605+
return self::PROPERTY_TYPE_UNKNOWN;
606+
}
607+
}

Classes/PHPWord/Exception.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ public static function errorHandlerCallback($code, $string, $file, $line, $conte
4646
$e->file = $file;
4747
throw $e;
4848
}
49-
}
49+
}

Classes/PHPWord/Exceptions/InvalidImageException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
*/
1313
class InvalidImageException extends Exception
1414
{
15-
}
15+
}

Classes/PHPWord/Exceptions/InvalidStyleException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
*/
1313
class InvalidStyleException extends InvalidArgumentException
1414
{
15-
}
15+
}

Classes/PHPWord/Exceptions/UnsupportedImageTypeException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
*/
1313
class UnsupportedImageTypeException extends Exception
1414
{
15-
}
15+
}

0 commit comments

Comments
 (0)