import v2.0.0.0_RC3 | 2012-07-01
https://github.com/lucanos/CommunityID -> http://www.itadmins.net/archives/357
This commit is contained in:
@ -17,7 +17,7 @@
|
||||
* @subpackage Document
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Docx.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
* @version $Id: Docx.php 19035 2009-11-19 14:34:11Z alexander $
|
||||
*/
|
||||
|
||||
/** Zend_Search_Lucene_Document_OpenXml */
|
||||
@ -47,6 +47,7 @@ class Zend_Search_Lucene_Document_Docx extends Zend_Search_Lucene_Document_OpenX
|
||||
*
|
||||
* @param string $fileName
|
||||
* @param boolean $storeContent
|
||||
* @throws Zend_Search_Lucene_Exception
|
||||
*/
|
||||
private function __construct($fileName, $storeContent) {
|
||||
// Document data holders
|
||||
@ -58,7 +59,12 @@ class Zend_Search_Lucene_Document_Docx extends Zend_Search_Lucene_Document_OpenX
|
||||
$package->open($fileName);
|
||||
|
||||
// Read relations and search for officeDocument
|
||||
$relations = simplexml_load_string($package->getFromName('_rels/.rels'));
|
||||
$relationsXml = $package->getFromName('_rels/.rels');
|
||||
if ($relationsXml === false) {
|
||||
require_once 'Zend/Search/Lucene/Exception.php';
|
||||
throw new Zend_Search_Lucene_Exception('Invalid archive or corrupted .docx file.');
|
||||
}
|
||||
$relations = simplexml_load_string($relationsXml);
|
||||
foreach($relations->Relationship as $rel) {
|
||||
if ($rel ["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_OFFICEDOCUMENT) {
|
||||
// Found office document! Read in contents...
|
||||
@ -75,8 +81,8 @@ class Zend_Search_Lucene_Document_Docx extends Zend_Search_Lucene_Document_OpenX
|
||||
$runs = $paragraph->xpath('.//w:r/*[name() = "w:t" or name() = "w:br"]');
|
||||
|
||||
if ($runs === false) {
|
||||
// Paragraph doesn't contain any text or breaks
|
||||
continue;
|
||||
// Paragraph doesn't contain any text or breaks
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($runs as $run) {
|
||||
@ -84,7 +90,7 @@ class Zend_Search_Lucene_Document_Docx extends Zend_Search_Lucene_Document_OpenX
|
||||
// Break element
|
||||
$documentBody[] = ' ';
|
||||
} else {
|
||||
$documentBody[] = (string)$run;
|
||||
$documentBody[] = (string)$run;
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,11 +139,11 @@ class Zend_Search_Lucene_Document_Docx extends Zend_Search_Lucene_Document_OpenX
|
||||
*/
|
||||
public static function loadDocxFile($fileName, $storeContent = false) {
|
||||
if (!is_readable($fileName)) {
|
||||
require_once 'Zend/Search/Lucene/Document/Exception.php';
|
||||
throw new Zend_Search_Lucene_Document_Exception('Provided file \'' . $fileName . '\' is not readable.');
|
||||
require_once 'Zend/Search/Lucene/Document/Exception.php';
|
||||
throw new Zend_Search_Lucene_Document_Exception('Provided file \'' . $fileName . '\' is not readable.');
|
||||
}
|
||||
|
||||
return new Zend_Search_Lucene_Document_Docx($fileName, $storeContent);
|
||||
return new Zend_Search_Lucene_Document_Docx($fileName, $storeContent);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Document
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Html.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
* @version $Id: Html.php 18951 2009-11-12 16:26:19Z alexander $
|
||||
*/
|
||||
|
||||
|
||||
@ -88,28 +88,28 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
|
||||
@$this->_doc->loadHTML($htmlData);
|
||||
|
||||
if ($this->_doc->encoding === null) {
|
||||
// Document encoding is not recognized
|
||||
// Document encoding is not recognized
|
||||
|
||||
/** @todo improve HTML vs HTML fragment recognition */
|
||||
if (preg_match('/<html>/i', $htmlData, $matches, PREG_OFFSET_CAPTURE)) {
|
||||
// It's an HTML document
|
||||
// Add additional HEAD section and recognize document
|
||||
$htmlTagOffset = $matches[0][1] + strlen($matches[0][1]);
|
||||
/** @todo improve HTML vs HTML fragment recognition */
|
||||
if (preg_match('/<html>/i', $htmlData, $matches, PREG_OFFSET_CAPTURE)) {
|
||||
// It's an HTML document
|
||||
// Add additional HEAD section and recognize document
|
||||
$htmlTagOffset = $matches[0][1] + strlen($matches[0][0]);
|
||||
|
||||
@$this->_doc->loadHTML(iconv($defaultEncoding, 'UTF-8//IGNORE', substr($htmlData, 0, $htmlTagOffset))
|
||||
@$this->_doc->loadHTML(iconv($defaultEncoding, 'UTF-8//IGNORE', substr($htmlData, 0, $htmlTagOffset))
|
||||
. '<head><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"/></head>'
|
||||
. iconv($defaultEncoding, 'UTF-8//IGNORE', substr($htmlData, $htmlTagOffset)));
|
||||
|
||||
// Remove additional HEAD section
|
||||
$xpath = new DOMXPath($this->_doc);
|
||||
$head = $xpath->query('/html/head')->item(0);
|
||||
$head->parentNode->removeChild($head);
|
||||
} else {
|
||||
// It's an HTML fragment
|
||||
@$this->_doc->loadHTML('<html><head><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"/></head><body>'
|
||||
. iconv($defaultEncoding, 'UTF-8//IGNORE', $htmlData)
|
||||
. '</body></html>');
|
||||
}
|
||||
$head->parentNode->removeChild($head);
|
||||
} else {
|
||||
// It's an HTML fragment
|
||||
@$this->_doc->loadHTML('<html><head><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"/></head><body>'
|
||||
. iconv($defaultEncoding, 'UTF-8//IGNORE', $htmlData)
|
||||
. '</body></html>');
|
||||
}
|
||||
|
||||
}
|
||||
/** @todo Add correction of wrong HTML encoding recognition processing
|
||||
@ -264,6 +264,9 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
|
||||
*/
|
||||
protected function _highlightTextNode(DOMText $node, $wordsToHighlight, $callback, $params)
|
||||
{
|
||||
/** Zend_Search_Lucene_Analysis_Analyzer */
|
||||
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
|
||||
|
||||
$analyzer = Zend_Search_Lucene_Analysis_Analyzer::getDefault();
|
||||
$analyzer->setInput($node->nodeValue, 'UTF-8');
|
||||
|
||||
@ -301,16 +304,16 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
|
||||
. $highlightedWordNodeSetHtml
|
||||
. '</body></html>');
|
||||
if (!$success) {
|
||||
require_once 'Zend/Search/Lucene/Exception.php';
|
||||
throw new Zend_Search_Lucene_Exception("Error occured while loading highlighted text fragment: '$highlightedNodeHtml'.");
|
||||
require_once 'Zend/Search/Lucene/Exception.php';
|
||||
throw new Zend_Search_Lucene_Exception("Error occured while loading highlighted text fragment: '$highlightedNodeHtml'.");
|
||||
}
|
||||
$highlightedWordNodeSetXpath = new DOMXPath($highlightedWordNodeSetDomDocument);
|
||||
$highlightedWordNodeSet = $highlightedWordNodeSetXpath->query('/html/body')->item(0)->childNodes;
|
||||
|
||||
for ($count = 0; $count < $highlightedWordNodeSet->length; $count++) {
|
||||
$nodeToImport = $highlightedWordNodeSet->item($count);
|
||||
$node->parentNode->insertBefore($this->_doc->importNode($nodeToImport, true /* deep copy */),
|
||||
$matchedWordNode);
|
||||
$nodeToImport = $highlightedWordNodeSet->item($count);
|
||||
$node->parentNode->insertBefore($this->_doc->importNode($nodeToImport, true /* deep copy */),
|
||||
$matchedWordNode);
|
||||
}
|
||||
|
||||
$node->parentNode->removeChild($matchedWordNode);
|
||||
@ -372,7 +375,7 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
|
||||
*/
|
||||
public function highlight($words, $colour = '#66ffff')
|
||||
{
|
||||
return $this->highlightExtended($words, array($this, 'applyColour'), array($colour));
|
||||
return $this->highlightExtended($words, array($this, 'applyColour'), array($colour));
|
||||
}
|
||||
|
||||
|
||||
@ -389,6 +392,9 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
|
||||
*/
|
||||
public function highlightExtended($words, $callback, $params = array())
|
||||
{
|
||||
/** Zend_Search_Lucene_Analysis_Analyzer */
|
||||
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
|
||||
|
||||
if (!is_array($words)) {
|
||||
$words = array($words);
|
||||
}
|
||||
@ -410,8 +416,8 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
|
||||
}
|
||||
|
||||
if (!is_callable($callback)) {
|
||||
require_once 'Zend/Search/Lucene/Exception.php';
|
||||
throw new Zend_Search_Lucene_Exception('$viewHelper parameter mast be a View Helper name, View Helper object or callback.');
|
||||
require_once 'Zend/Search/Lucene/Exception.php';
|
||||
throw new Zend_Search_Lucene_Exception('$viewHelper parameter mast be a View Helper name, View Helper object or callback.');
|
||||
}
|
||||
|
||||
$xpath = new DOMXPath($this->_doc);
|
||||
@ -445,7 +451,7 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
|
||||
|
||||
$outputFragments = array();
|
||||
for ($count = 0; $count < $bodyNodes->length; $count++) {
|
||||
$outputFragments[] = $this->_doc->saveXML($bodyNodes->item($count));
|
||||
$outputFragments[] = $this->_doc->saveXML($bodyNodes->item($count));
|
||||
}
|
||||
|
||||
return implode($outputFragments);
|
||||
|
@ -17,13 +17,14 @@
|
||||
* @subpackage Document
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: OpenXml.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
* @version $Id: OpenXml.php 18951 2009-11-12 16:26:19Z alexander $
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Search_Lucene_Document */
|
||||
require_once 'Zend/Search/Lucene/Document.php';
|
||||
|
||||
|
||||
if (class_exists('ZipArchive', false)) {
|
||||
|
||||
/**
|
||||
@ -82,7 +83,7 @@ abstract class Zend_Search_Lucene_Document_OpenXml extends Zend_Search_Lucene_Do
|
||||
{
|
||||
// Data holders
|
||||
$coreProperties = array();
|
||||
|
||||
|
||||
// Read relations and search for core properties
|
||||
$relations = simplexml_load_string($package->getFromName("_rels/.rels"));
|
||||
foreach ($relations->Relationship as $rel) {
|
||||
@ -103,10 +104,10 @@ abstract class Zend_Search_Lucene_Document_OpenXml extends Zend_Search_Lucene_Do
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $coreProperties;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine absolute zip path
|
||||
*
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Document
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Pptx.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
* @version $Id: Pptx.php 19035 2009-11-19 14:34:11Z alexander $
|
||||
*/
|
||||
|
||||
|
||||
@ -70,6 +70,7 @@ class Zend_Search_Lucene_Document_Pptx extends Zend_Search_Lucene_Document_OpenX
|
||||
*
|
||||
* @param string $fileName
|
||||
* @param boolean $storeContent
|
||||
* @throws Zend_Search_Lucene_Exception
|
||||
*/
|
||||
private function __construct($fileName, $storeContent)
|
||||
{
|
||||
@ -84,7 +85,12 @@ class Zend_Search_Lucene_Document_Pptx extends Zend_Search_Lucene_Document_OpenX
|
||||
$package->open($fileName);
|
||||
|
||||
// Read relations and search for officeDocument
|
||||
$relations = simplexml_load_string($package->getFromName("_rels/.rels"));
|
||||
$relationsXml = $package->getFromName('_rels/.rels');
|
||||
if ($relationsXml === false) {
|
||||
require_once 'Zend/Search/Lucene/Exception.php';
|
||||
throw new Zend_Search_Lucene_Exception('Invalid archive or corrupted .pptx file.');
|
||||
}
|
||||
$relations = simplexml_load_string($relationsXml);
|
||||
foreach ($relations->Relationship as $rel) {
|
||||
if ($rel["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_OFFICEDOCUMENT) {
|
||||
// Found office document! Search for slides...
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage Document
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Xlsx.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
* @version $Id: Xlsx.php 19035 2009-11-19 14:34:11Z alexander $
|
||||
*/
|
||||
|
||||
|
||||
@ -77,6 +77,7 @@ class Zend_Search_Lucene_Document_Xlsx extends Zend_Search_Lucene_Document_OpenX
|
||||
*
|
||||
* @param string $fileName
|
||||
* @param boolean $storeContent
|
||||
* @throws Zend_Search_Lucene_Exception
|
||||
*/
|
||||
private function __construct($fileName, $storeContent)
|
||||
{
|
||||
@ -91,7 +92,12 @@ class Zend_Search_Lucene_Document_Xlsx extends Zend_Search_Lucene_Document_OpenX
|
||||
$package->open($fileName);
|
||||
|
||||
// Read relations and search for officeDocument
|
||||
$relations = simplexml_load_string($package->getFromName("_rels/.rels"));
|
||||
$relationsXml = $package->getFromName('_rels/.rels');
|
||||
if ($relationsXml === false) {
|
||||
require_once 'Zend/Search/Lucene/Exception.php';
|
||||
throw new Zend_Search_Lucene_Exception('Invalid archive or corrupted .xlsx file.');
|
||||
}
|
||||
$relations = simplexml_load_string($relationsXml);
|
||||
foreach ($relations->Relationship as $rel) {
|
||||
if ($rel["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_OFFICEDOCUMENT) {
|
||||
// Found office document! Read relations for workbook...
|
||||
|
Reference in New Issue
Block a user