DocumentSecurity.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /**
  3. * PHPExcel_DocumentSecurity
  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_DocumentSecurity
  28. {
  29. /**
  30. * LockRevision
  31. *
  32. * @var boolean
  33. */
  34. private $lockRevision;
  35. /**
  36. * LockStructure
  37. *
  38. * @var boolean
  39. */
  40. private $lockStructure;
  41. /**
  42. * LockWindows
  43. *
  44. * @var boolean
  45. */
  46. private $lockWindows;
  47. /**
  48. * RevisionsPassword
  49. *
  50. * @var string
  51. */
  52. private $revisionsPassword;
  53. /**
  54. * WorkbookPassword
  55. *
  56. * @var string
  57. */
  58. private $workbookPassword;
  59. /**
  60. * Create a new PHPExcel_DocumentSecurity
  61. */
  62. public function __construct()
  63. {
  64. // Initialise values
  65. $this->lockRevision = false;
  66. $this->lockStructure = false;
  67. $this->lockWindows = false;
  68. $this->revisionsPassword = '';
  69. $this->workbookPassword = '';
  70. }
  71. /**
  72. * Is some sort of document security enabled?
  73. *
  74. * @return boolean
  75. */
  76. public function isSecurityEnabled()
  77. {
  78. return $this->lockRevision ||
  79. $this->lockStructure ||
  80. $this->lockWindows;
  81. }
  82. /**
  83. * Get LockRevision
  84. *
  85. * @return boolean
  86. */
  87. public function getLockRevision()
  88. {
  89. return $this->lockRevision;
  90. }
  91. /**
  92. * Set LockRevision
  93. *
  94. * @param boolean $pValue
  95. * @return PHPExcel_DocumentSecurity
  96. */
  97. public function setLockRevision($pValue = false)
  98. {
  99. $this->lockRevision = $pValue;
  100. return $this;
  101. }
  102. /**
  103. * Get LockStructure
  104. *
  105. * @return boolean
  106. */
  107. public function getLockStructure()
  108. {
  109. return $this->lockStructure;
  110. }
  111. /**
  112. * Set LockStructure
  113. *
  114. * @param boolean $pValue
  115. * @return PHPExcel_DocumentSecurity
  116. */
  117. public function setLockStructure($pValue = false)
  118. {
  119. $this->lockStructure = $pValue;
  120. return $this;
  121. }
  122. /**
  123. * Get LockWindows
  124. *
  125. * @return boolean
  126. */
  127. public function getLockWindows()
  128. {
  129. return $this->lockWindows;
  130. }
  131. /**
  132. * Set LockWindows
  133. *
  134. * @param boolean $pValue
  135. * @return PHPExcel_DocumentSecurity
  136. */
  137. public function setLockWindows($pValue = false)
  138. {
  139. $this->lockWindows = $pValue;
  140. return $this;
  141. }
  142. /**
  143. * Get RevisionsPassword (hashed)
  144. *
  145. * @return string
  146. */
  147. public function getRevisionsPassword()
  148. {
  149. return $this->revisionsPassword;
  150. }
  151. /**
  152. * Set RevisionsPassword
  153. *
  154. * @param string $pValue
  155. * @param boolean $pAlreadyHashed If the password has already been hashed, set this to true
  156. * @return PHPExcel_DocumentSecurity
  157. */
  158. public function setRevisionsPassword($pValue = '', $pAlreadyHashed = false)
  159. {
  160. if (!$pAlreadyHashed) {
  161. $pValue = PHPExcel_Shared_PasswordHasher::hashPassword($pValue);
  162. }
  163. $this->revisionsPassword = $pValue;
  164. return $this;
  165. }
  166. /**
  167. * Get WorkbookPassword (hashed)
  168. *
  169. * @return string
  170. */
  171. public function getWorkbookPassword()
  172. {
  173. return $this->workbookPassword;
  174. }
  175. /**
  176. * Set WorkbookPassword
  177. *
  178. * @param string $pValue
  179. * @param boolean $pAlreadyHashed If the password has already been hashed, set this to true
  180. * @return PHPExcel_DocumentSecurity
  181. */
  182. public function setWorkbookPassword($pValue = '', $pAlreadyHashed = false)
  183. {
  184. if (!$pAlreadyHashed) {
  185. $pValue = PHPExcel_Shared_PasswordHasher::hashPassword($pValue);
  186. }
  187. $this->workbookPassword = $pValue;
  188. return $this;
  189. }
  190. /**
  191. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  192. */
  193. public function __clone()
  194. {
  195. $vars = get_object_vars($this);
  196. foreach ($vars as $key => $value) {
  197. if (is_object($value)) {
  198. $this->$key = clone $value;
  199. } else {
  200. $this->$key = $value;
  201. }
  202. }
  203. }
  204. }