0
0

DocumentProperties.php 15 KB

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