1<?php
2
3/**
4 * PHPExcel_DocumentProperties
5 *
6 * Copyright (c) 2006 - 2015 PHPExcel
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 *
22 * @category    PHPExcel
23 * @package    PHPExcel
24 * @copyright    Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
26 * @version    ##VERSION##, ##DATE##
27 */
28class PHPExcel_DocumentProperties
29{
30    /** constants */
31    const PROPERTY_TYPE_BOOLEAN = 'b';
32    const PROPERTY_TYPE_INTEGER = 'i';
33    const PROPERTY_TYPE_FLOAT   = 'f';
34    const PROPERTY_TYPE_DATE    = 'd';
35    const PROPERTY_TYPE_STRING  = 's';
36    const PROPERTY_TYPE_UNKNOWN = 'u';
37
38    /**
39     * Creator
40     *
41     * @var string
42     */
43    private $creator = 'Unknown Creator';
44
45    /**
46     * LastModifiedBy
47     *
48     * @var string
49     */
50    private $lastModifiedBy;
51
52    /**
53     * Created
54     *
55     * @var datetime
56     */
57    private $created;
58
59    /**
60     * Modified
61     *
62     * @var datetime
63     */
64    private $modified;
65
66    /**
67     * Title
68     *
69     * @var string
70     */
71    private $title = 'Untitled Spreadsheet';
72
73    /**
74     * Description
75     *
76     * @var string
77     */
78    private $description = '';
79
80    /**
81     * Subject
82     *
83     * @var string
84     */
85    private $subject = '';
86
87    /**
88     * Keywords
89     *
90     * @var string
91     */
92    private $keywords = '';
93
94    /**
95     * Category
96     *
97     * @var string
98     */
99    private $category = '';
100
101    /**
102     * Manager
103     *
104     * @var string
105     */
106    private $manager = '';
107
108    /**
109     * Company
110     *
111     * @var string
112     */
113    private $company = 'Microsoft Corporation';
114
115    /**
116     * Custom Properties
117     *
118     * @var string
119     */
120    private $customProperties = array();
121
122
123    /**
124     * Create a new PHPExcel_DocumentProperties
125     */
126    public function __construct()
127    {
128        // Initialise values
129        $this->lastModifiedBy = $this->creator;
130        $this->created  = time();
131        $this->modified = time();
132    }
133
134    /**
135     * Get Creator
136     *
137     * @return string
138     */
139    public function getCreator()
140    {
141        return $this->creator;
142    }
143
144    /**
145     * Set Creator
146     *
147     * @param string $pValue
148     * @return PHPExcel_DocumentProperties
149     */
150    public function setCreator($pValue = '')
151    {
152        $this->creator = $pValue;
153        return $this;
154    }
155
156    /**
157     * Get Last Modified By
158     *
159     * @return string
160     */
161    public function getLastModifiedBy()
162    {
163        return $this->lastModifiedBy;
164    }
165
166    /**
167     * Set Last Modified By
168     *
169     * @param string $pValue
170     * @return PHPExcel_DocumentProperties
171     */
172    public function setLastModifiedBy($pValue = '')
173    {
174        $this->lastModifiedBy = $pValue;
175        return $this;
176    }
177
178    /**
179     * Get Created
180     *
181     * @return datetime
182     */
183    public function getCreated()
184    {
185        return $this->created;
186    }
187
188    /**
189     * Set Created
190     *
191     * @param datetime $pValue
192     * @return PHPExcel_DocumentProperties
193     */
194    public function setCreated($pValue = null)
195    {
196        if ($pValue === null) {
197            $pValue = time();
198        } elseif (is_string($pValue)) {
199            if (is_numeric($pValue)) {
200                $pValue = intval($pValue);
201            } else {
202                $pValue = strtotime($pValue);
203            }
204        }
205
206        $this->created = $pValue;
207        return $this;
208    }
209
210    /**
211     * Get Modified
212     *
213     * @return datetime
214     */
215    public function getModified()
216    {
217        return $this->modified;
218    }
219
220    /**
221     * Set Modified
222     *
223     * @param datetime $pValue
224     * @return PHPExcel_DocumentProperties
225     */
226    public function setModified($pValue = null)
227    {
228        if ($pValue === null) {
229            $pValue = time();
230        } elseif (is_string($pValue)) {
231            if (is_numeric($pValue)) {
232                $pValue = intval($pValue);
233            } else {
234                $pValue = strtotime($pValue);
235            }
236        }
237
238        $this->modified = $pValue;
239        return $this;
240    }
241
242    /**
243     * Get Title
244     *
245     * @return string
246     */
247    public function getTitle()
248    {
249        return $this->title;
250    }
251
252    /**
253     * Set Title
254     *
255     * @param string $pValue
256     * @return PHPExcel_DocumentProperties
257     */
258    public function setTitle($pValue = '')
259    {
260        $this->title = $pValue;
261        return $this;
262    }
263
264    /**
265     * Get Description
266     *
267     * @return string
268     */
269    public function getDescription()
270    {
271        return $this->description;
272    }
273
274    /**
275     * Set Description
276     *
277     * @param string $pValue
278     * @return PHPExcel_DocumentProperties
279     */
280    public function setDescription($pValue = '')
281    {
282        $this->description = $pValue;
283        return $this;
284    }
285
286    /**
287     * Get Subject
288     *
289     * @return string
290     */
291    public function getSubject()
292    {
293        return $this->subject;
294    }
295
296    /**
297     * Set Subject
298     *
299     * @param string $pValue
300     * @return PHPExcel_DocumentProperties
301     */
302    public function setSubject($pValue = '')
303    {
304        $this->subject = $pValue;
305        return $this;
306    }
307
308    /**
309     * Get Keywords
310     *
311     * @return string
312     */
313    public function getKeywords()
314    {
315        return $this->keywords;
316    }
317
318    /**
319     * Set Keywords
320     *
321     * @param string $pValue
322     * @return PHPExcel_DocumentProperties
323     */
324    public function setKeywords($pValue = '')
325    {
326        $this->keywords = $pValue;
327        return $this;
328    }
329
330    /**
331     * Get Category
332     *
333     * @return string
334     */
335    public function getCategory()
336    {
337        return $this->category;
338    }
339
340    /**
341     * Set Category
342     *
343     * @param string $pValue
344     * @return PHPExcel_DocumentProperties
345     */
346    public function setCategory($pValue = '')
347    {
348        $this->category = $pValue;
349        return $this;
350    }
351
352    /**
353     * Get Company
354     *
355     * @return string
356     */
357    public function getCompany()
358    {
359        return $this->company;
360    }
361
362    /**
363     * Set Company
364     *
365     * @param string $pValue
366     * @return PHPExcel_DocumentProperties
367     */
368    public function setCompany($pValue = '')
369    {
370        $this->company = $pValue;
371        return $this;
372    }
373
374    /**
375     * Get Manager
376     *
377     * @return string
378     */
379    public function getManager()
380    {
381        return $this->manager;
382    }
383
384    /**
385     * Set Manager
386     *
387     * @param string $pValue
388     * @return PHPExcel_DocumentProperties
389     */
390    public function setManager($pValue = '')
391    {
392        $this->manager = $pValue;
393        return $this;
394    }
395
396    /**
397     * Get a List of Custom Property Names
398     *
399     * @return array of string
400     */
401    public function getCustomProperties()
402    {
403        return array_keys($this->customProperties);
404    }
405
406    /**
407     * Check if a Custom Property is defined
408     *
409     * @param string $propertyName
410     * @return boolean
411     */
412    public function isCustomPropertySet($propertyName)
413    {
414        return isset($this->customProperties[$propertyName]);
415    }
416
417    /**
418     * Get a Custom Property Value
419     *
420     * @param string $propertyName
421     * @return string
422     */
423    public function getCustomPropertyValue($propertyName)
424    {
425        if (isset($this->customProperties[$propertyName])) {
426            return $this->customProperties[$propertyName]['value'];
427        }
428
429    }
430
431    /**
432     * Get a Custom Property Type
433     *
434     * @param string $propertyName
435     * @return string
436     */
437    public function getCustomPropertyType($propertyName)
438    {
439        if (isset($this->customProperties[$propertyName])) {
440            return $this->customProperties[$propertyName]['type'];
441        }
442
443    }
444
445    /**
446     * Set a Custom Property
447     *
448     * @param string $propertyName
449     * @param mixed $propertyValue
450     * @param string $propertyType
451     *      'i'    : Integer
452     *   'f' : Floating Point
453     *   's' : String
454     *   'd' : Date/Time
455     *   'b' : Boolean
456     * @return PHPExcel_DocumentProperties
457     */
458    public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null)
459    {
460        if (($propertyType === null) || (!in_array($propertyType, array(self::PROPERTY_TYPE_INTEGER,
461                                                                        self::PROPERTY_TYPE_FLOAT,
462                                                                        self::PROPERTY_TYPE_STRING,
463                                                                        self::PROPERTY_TYPE_DATE,
464                                                                        self::PROPERTY_TYPE_BOOLEAN)))) {
465            if ($propertyValue === null) {
466                $propertyType = self::PROPERTY_TYPE_STRING;
467            } elseif (is_float($propertyValue)) {
468                $propertyType = self::PROPERTY_TYPE_FLOAT;
469            } elseif (is_int($propertyValue)) {
470                $propertyType = self::PROPERTY_TYPE_INTEGER;
471            } elseif (is_bool($propertyValue)) {
472                $propertyType = self::PROPERTY_TYPE_BOOLEAN;
473            } else {
474                $propertyType = self::PROPERTY_TYPE_STRING;
475            }
476        }
477
478        $this->customProperties[$propertyName] = array(
479            'value' => $propertyValue,
480            'type' => $propertyType
481        );
482        return $this;
483    }
484
485    /**
486     * Implement PHP __clone to create a deep clone, not just a shallow copy.
487     */
488    public function __clone()
489    {
490        $vars = get_object_vars($this);
491        foreach ($vars as $key => $value) {
492            if (is_object($value)) {
493                $this->$key = clone $value;
494            } else {
495                $this->$key = $value;
496            }
497        }
498    }
499
500    public static function convertProperty($propertyValue, $propertyType)
501    {
502        switch ($propertyType) {
503            case 'empty':     //    Empty
504                return '';
505                break;
506            case 'null':      //    Null
507                return null;
508                break;
509            case 'i1':        //    1-Byte Signed Integer
510            case 'i2':        //    2-Byte Signed Integer
511            case 'i4':        //    4-Byte Signed Integer
512            case 'i8':        //    8-Byte Signed Integer
513            case 'int':       //    Integer
514                return (int) $propertyValue;
515                break;
516            case 'ui1':       //    1-Byte Unsigned Integer
517            case 'ui2':       //    2-Byte Unsigned Integer
518            case 'ui4':       //    4-Byte Unsigned Integer
519            case 'ui8':       //    8-Byte Unsigned Integer
520            case 'uint':      //    Unsigned Integer
521                return abs((int) $propertyValue);
522                break;
523            case 'r4':        //    4-Byte Real Number
524            case 'r8':        //    8-Byte Real Number
525            case 'decimal':   //    Decimal
526                return (float) $propertyValue;
527                break;
528            case 'lpstr':     //    LPSTR
529            case 'lpwstr':    //    LPWSTR
530            case 'bstr':      //    Basic String
531                return $propertyValue;
532                break;
533            case 'date':      //    Date and Time
534            case 'filetime':  //    File Time
535                return strtotime($propertyValue);
536                break;
537            case 'bool':     //    Boolean
538                return ($propertyValue == 'true') ? true : false;
539                break;
540            case 'cy':       //    Currency
541            case 'error':    //    Error Status Code
542            case 'vector':   //    Vector
543            case 'array':    //    Array
544            case 'blob':     //    Binary Blob
545            case 'oblob':    //    Binary Blob Object
546            case 'stream':   //    Binary Stream
547            case 'ostream':  //    Binary Stream Object
548            case 'storage':  //    Binary Storage
549            case 'ostorage': //    Binary Storage Object
550            case 'vstream':  //    Binary Versioned Stream
551            case 'clsid':    //    Class ID
552            case 'cf':       //    Clipboard Data
553                return $propertyValue;
554                break;
555        }
556        return $propertyValue;
557    }
558
559    public static function convertPropertyType($propertyType)
560    {
561        switch ($propertyType) {
562            case 'i1':       //    1-Byte Signed Integer
563            case 'i2':       //    2-Byte Signed Integer
564            case 'i4':       //    4-Byte Signed Integer
565            case 'i8':       //    8-Byte Signed Integer
566            case 'int':      //    Integer
567            case 'ui1':      //    1-Byte Unsigned Integer
568            case 'ui2':      //    2-Byte Unsigned Integer
569            case 'ui4':      //    4-Byte Unsigned Integer
570            case 'ui8':      //    8-Byte Unsigned Integer
571            case 'uint':     //    Unsigned Integer
572                return self::PROPERTY_TYPE_INTEGER;
573                break;
574            case 'r4':       //    4-Byte Real Number
575            case 'r8':       //    8-Byte Real Number
576            case 'decimal':  //    Decimal
577                return self::PROPERTY_TYPE_FLOAT;
578                break;
579            case 'empty':    //    Empty
580            case 'null':     //    Null
581            case 'lpstr':    //    LPSTR
582            case 'lpwstr':   //    LPWSTR
583            case 'bstr':     //    Basic String
584                return self::PROPERTY_TYPE_STRING;
585                break;
586            case 'date':     //    Date and Time
587            case 'filetime': //    File Time
588                return self::PROPERTY_TYPE_DATE;
589                break;
590            case 'bool':     //    Boolean
591                return self::PROPERTY_TYPE_BOOLEAN;
592                break;
593            case 'cy':       //    Currency
594            case 'error':    //    Error Status Code
595            case 'vector':   //    Vector
596            case 'array':    //    Array
597            case 'blob':     //    Binary Blob
598            case 'oblob':    //    Binary Blob Object
599            case 'stream':   //    Binary Stream
600            case 'ostream':  //    Binary Stream Object
601            case 'storage':  //    Binary Storage
602            case 'ostorage': //    Binary Storage Object
603            case 'vstream':  //    Binary Versioned Stream
604            case 'clsid':    //    Class ID
605            case 'cf':       //    Clipboard Data
606                return self::PROPERTY_TYPE_UNKNOWN;
607                break;
608        }
609        return self::PROPERTY_TYPE_UNKNOWN;
610    }
611}
612