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