13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Search_Lucene |
16 * @package Zend_Search_Lucene |
17 * @subpackage Document |
17 * @subpackage Document |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @version $Id: Xlsx.php 24593 2012-01-05 20:35:02Z matthew $ |
20 * @version $Id$ |
21 */ |
21 */ |
22 |
22 |
23 |
23 |
24 /** Zend_Search_Lucene_Document_OpenXml */ |
24 /** Zend_Search_Lucene_Document_OpenXml */ |
25 require_once 'Zend/Search/Lucene/Document/OpenXml.php'; |
25 require_once 'Zend/Search/Lucene/Document/OpenXml.php'; |
|
26 |
|
27 /** Zend_Xml_Security */ |
|
28 require_once 'Zend/Xml/Security.php'; |
26 |
29 |
27 /** |
30 /** |
28 * Xlsx document. |
31 * Xlsx document. |
29 * |
32 * |
30 * @category Zend |
33 * @category Zend |
31 * @package Zend_Search_Lucene |
34 * @package Zend_Search_Lucene |
32 * @subpackage Document |
35 * @subpackage Document |
33 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
36 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
34 * @license http://framework.zend.com/license/new-bsd New BSD License |
37 * @license http://framework.zend.com/license/new-bsd New BSD License |
35 */ |
38 */ |
36 class Zend_Search_Lucene_Document_Xlsx extends Zend_Search_Lucene_Document_OpenXml |
39 class Zend_Search_Lucene_Document_Xlsx extends Zend_Search_Lucene_Document_OpenXml |
37 { |
40 { |
38 /** |
41 /** |
98 $relationsXml = $package->getFromName('_rels/.rels'); |
101 $relationsXml = $package->getFromName('_rels/.rels'); |
99 if ($relationsXml === false) { |
102 if ($relationsXml === false) { |
100 require_once 'Zend/Search/Lucene/Exception.php'; |
103 require_once 'Zend/Search/Lucene/Exception.php'; |
101 throw new Zend_Search_Lucene_Exception('Invalid archive or corrupted .xlsx file.'); |
104 throw new Zend_Search_Lucene_Exception('Invalid archive or corrupted .xlsx file.'); |
102 } |
105 } |
103 $relations = simplexml_load_string($relationsXml); |
106 $relations = Zend_Xml_Security::scan($relationsXml); |
104 foreach ($relations->Relationship as $rel) { |
107 foreach ($relations->Relationship as $rel) { |
105 if ($rel["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_OFFICEDOCUMENT) { |
108 if ($rel["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_OFFICEDOCUMENT) { |
106 // Found office document! Read relations for workbook... |
109 // Found office document! Read relations for workbook... |
107 $workbookRelations = simplexml_load_string($package->getFromName( $this->absoluteZipPath(dirname($rel["Target"]) . "/_rels/" . basename($rel["Target"]) . ".rels")) ); |
110 $workbookRelations = Zend_Xml_Security::scan($package->getFromName( $this->absoluteZipPath(dirname($rel["Target"]) . "/_rels/" . basename($rel["Target"]) . ".rels")) ); |
108 $workbookRelations->registerXPathNamespace("rel", Zend_Search_Lucene_Document_OpenXml::SCHEMA_RELATIONSHIP); |
111 $workbookRelations->registerXPathNamespace("rel", Zend_Search_Lucene_Document_OpenXml::SCHEMA_RELATIONSHIP); |
109 |
112 |
110 // Read shared strings |
113 // Read shared strings |
111 $sharedStringsPath = $workbookRelations->xpath("rel:Relationship[@Type='" . Zend_Search_Lucene_Document_Xlsx::SCHEMA_SHAREDSTRINGS . "']"); |
114 $sharedStringsPath = $workbookRelations->xpath("rel:Relationship[@Type='" . Zend_Search_Lucene_Document_Xlsx::SCHEMA_SHAREDSTRINGS . "']"); |
112 $sharedStringsPath = (string)$sharedStringsPath[0]['Target']; |
115 $sharedStringsPath = (string)$sharedStringsPath[0]['Target']; |
113 $xmlStrings = simplexml_load_string($package->getFromName( $this->absoluteZipPath(dirname($rel["Target"]) . "/" . $sharedStringsPath)) ); |
116 $xmlStrings = Zend_Xml_Security::scan($package->getFromName( $this->absoluteZipPath(dirname($rel["Target"]) . "/" . $sharedStringsPath)) ); |
114 if (isset($xmlStrings) && isset($xmlStrings->si)) { |
117 if (isset($xmlStrings) && isset($xmlStrings->si)) { |
115 foreach ($xmlStrings->si as $val) { |
118 foreach ($xmlStrings->si as $val) { |
116 if (isset($val->t)) { |
119 if (isset($val->t)) { |
117 $sharedStrings[] = (string)$val->t; |
120 $sharedStrings[] = (string)$val->t; |
118 } elseif (isset($val->r)) { |
121 } elseif (isset($val->r)) { |
122 } |
125 } |
123 |
126 |
124 // Loop relations for workbook and extract worksheets... |
127 // Loop relations for workbook and extract worksheets... |
125 foreach ($workbookRelations->Relationship as $workbookRelation) { |
128 foreach ($workbookRelations->Relationship as $workbookRelation) { |
126 if ($workbookRelation["Type"] == Zend_Search_Lucene_Document_Xlsx::SCHEMA_WORKSHEETRELATION) { |
129 if ($workbookRelation["Type"] == Zend_Search_Lucene_Document_Xlsx::SCHEMA_WORKSHEETRELATION) { |
127 $worksheets[ str_replace( 'rId', '', (string)$workbookRelation["Id"]) ] = simplexml_load_string( |
130 $worksheets[ str_replace( 'rId', '', (string)$workbookRelation["Id"]) ] = Zend_Xml_Security::scan( |
128 $package->getFromName( $this->absoluteZipPath(dirname($rel["Target"]) . "/" . dirname($workbookRelation["Target"]) . "/" . basename($workbookRelation["Target"])) ) |
131 $package->getFromName( $this->absoluteZipPath(dirname($rel["Target"]) . "/" . dirname($workbookRelation["Target"]) . "/" . basename($workbookRelation["Target"])) ) |
129 ); |
132 ); |
130 } |
133 } |
131 } |
134 } |
132 |
135 |