PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/common/libraries/plugin/phpexcel/PHPExcel/Worksheet/Drawing.php

https://bitbucket.org/chamilo/chamilo-dev/
PHP | 161 lines | 71 code | 11 blank | 79 comment | 7 complexity | 9db5573a4b9b0f8d184d05d376ba6d0b MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2011 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_Worksheet_Drawing
  23. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.6, 2011-02-27
  26. */
  27. /**
  28. * PHPExcel_Worksheet_Drawing
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Worksheet_Drawing
  32. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Worksheet_Drawing extends PHPExcel_Worksheet_BaseDrawing implements PHPExcel_IComparable
  35. {
  36. /**
  37. * Path
  38. *
  39. * @var string
  40. */
  41. private $_path;
  42. /**
  43. * Create a new PHPExcel_Worksheet_Drawing
  44. */
  45. public function __construct()
  46. {
  47. // Initialise values
  48. $this->_path = '';
  49. // Initialize parent
  50. parent :: __construct();
  51. }
  52. /**
  53. * Get Filename
  54. *
  55. * @return string
  56. */
  57. public function getFilename()
  58. {
  59. return basename($this->_path);
  60. }
  61. /**
  62. * Get indexed filename (using image index)
  63. *
  64. * @return string
  65. */
  66. public function getIndexedFilename()
  67. {
  68. $fileName = $this->getFilename();
  69. $fileName = str_replace(' ', '_', $fileName);
  70. return str_replace('.' . $this->getExtension(), '', $fileName) . $this->getImageIndex() . '.' . $this->getExtension();
  71. }
  72. /**
  73. * Get Extension
  74. *
  75. * @return string
  76. */
  77. public function getExtension()
  78. {
  79. $exploded = explode(".", basename($this->_path));
  80. return $exploded[count($exploded) - 1];
  81. }
  82. /**
  83. * Get Path
  84. *
  85. * @return string
  86. */
  87. public function getPath()
  88. {
  89. return $this->_path;
  90. }
  91. /**
  92. * Set Path
  93. *
  94. * @param string $pValue File path
  95. * @param boolean $pVerifyFile Verify file
  96. * @throws Exception
  97. * @return PHPExcel_Worksheet_Drawing
  98. */
  99. public function setPath($pValue = '', $pVerifyFile = true)
  100. {
  101. if ($pVerifyFile)
  102. {
  103. if (file_exists($pValue))
  104. {
  105. $this->_path = $pValue;
  106. if ($this->_width == 0 && $this->_height == 0)
  107. {
  108. // Get width/height
  109. list($this->_width, $this->_height) = getimagesize($pValue);
  110. }
  111. }
  112. else
  113. {
  114. throw new Exception("File $pValue not found!");
  115. }
  116. }
  117. else
  118. {
  119. $this->_path = $pValue;
  120. }
  121. return $this;
  122. }
  123. /**
  124. * Get hash code
  125. *
  126. * @return string Hash code
  127. */
  128. public function getHashCode()
  129. {
  130. return md5($this->_path . parent :: getHashCode() . __CLASS__);
  131. }
  132. /**
  133. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  134. */
  135. public function __clone()
  136. {
  137. $vars = get_object_vars($this);
  138. foreach ($vars as $key => $value)
  139. {
  140. if (is_object($value))
  141. {
  142. $this->$key = clone $value;
  143. }
  144. else
  145. {
  146. $this->$key = $value;
  147. }
  148. }
  149. }
  150. }