For God so loved the world, that He gave His only begotten Son, that all who believe in Him should not perish but have everlasting life
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 lines
5.0 KiB

  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. }