Преглед изворни кода

Update README.txt. Change _RecordNotExists to _NoRecordExists.

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@15945 44c647ce-9c0f-0410-b52a-842ac1e357ba
alexander пре 16 година
родитељ
комит
53b4299d22

+ 1 - 1
README.txt

@@ -41,7 +41,7 @@ NEW FEATURES
 * Locale support in Zend_Validate_Int and Zend_Validate_Float,
     contributed by Thomas Weidner
 * Phonecode support in Zend_Locale, contributed by Thomas Weidner
-* Zend_Validate_Db_RecordExists and _RecordNotExists, contributed by
+* Zend_Validate_Db_RecordExists and _NoRecordExists, contributed by
     Ryan Mauger
 * Zend_Validate_Iban, contributed by Thomas Weidner
 * Zend_Validate_File_WordCount, contributed by Thomas Weidner

+ 32 - 32
library/Zend/Loader/Autoloader.php

@@ -25,7 +25,7 @@ require_once 'Zend/Loader.php';
 
 /**
  * Autoloader stack and namespace autoloader
- * 
+ *
  * @uses       Zend_Loader_Autoloader
  * @package    Zend_Loader
  * @subpackage Autoloader
@@ -79,7 +79,7 @@ class Zend_Loader_Autoloader
 
     /**
      * Retrieve singleton instance
-     * 
+     *
      * @return Zend_Loader_Autoloader
      */
     public static function getInstance()
@@ -92,7 +92,7 @@ class Zend_Loader_Autoloader
 
     /**
      * Reset the singleton instance
-     * 
+     *
      * @return void
      */
     public static function resetInstance()
@@ -102,8 +102,8 @@ class Zend_Loader_Autoloader
 
     /**
      * Autoload a class
-     * 
-     * @param  string $class 
+     *
+     * @param  string $class
      * @return bool
      */
     public static function autoload($class)
@@ -133,7 +133,7 @@ class Zend_Loader_Autoloader
 
     /**
      * Set the default autoloader implementation
-     * 
+     *
      * @param  string|array $callback PHP callback
      * @return void
      */
@@ -149,7 +149,7 @@ class Zend_Loader_Autoloader
 
     /**
      * Retrieve the default autoloader callback
-     * 
+     *
      * @return string|array PHP Callback
      */
     public function getDefaultAutoloader()
@@ -159,7 +159,7 @@ class Zend_Loader_Autoloader
 
     /**
      * Set several autoloader callbacks at once
-     * 
+     *
      * @param  array $autoloaders Array of PHP callbacks (or Zend_Loader_Autoloader_Interface implementations) to act as autoloaders
      * @return Zend_Loader_Autoloader
      */
@@ -171,7 +171,7 @@ class Zend_Loader_Autoloader
 
     /**
      * Get attached autoloader implementations
-     * 
+     *
      * @return array
      */
     public function getAutoloaders()
@@ -181,7 +181,7 @@ class Zend_Loader_Autoloader
 
     /**
      * Return all autoloaders for a given namespace
-     * 
+     *
      * @param  string $namespace
      * @return array
      */
@@ -196,8 +196,8 @@ class Zend_Loader_Autoloader
 
     /**
      * Register a namespace to autoload
-     * 
-     * @param  string $namespace 
+     *
+     * @param  string $namespace
      * @return Zend_Loader_Autoloader
      */
     public function registerNamespace($namespace)
@@ -218,8 +218,8 @@ class Zend_Loader_Autoloader
 
     /**
      * Unload a registered autoload namespace
-     * 
-     * @param  string $namespace 
+     *
+     * @param  string $namespace
      * @return Zend_Loader_Autoloader
      */
     public function unregisterNamespace($namespace)
@@ -240,7 +240,7 @@ class Zend_Loader_Autoloader
 
     /**
      * Get a list of registered autoload namespaces
-     * 
+     *
      * @return array
      */
     public function getRegisteredNamespaces()
@@ -250,8 +250,8 @@ class Zend_Loader_Autoloader
 
     /**
      * Get or set the value of the "suppress not found warnings" flag
-     * 
-     * @param  null|bool $flag 
+     *
+     * @param  null|bool $flag
      * @return bool|Zend_Loader_Autoloader Returns boolean if no argument is passed, object instance otherwise
      */
     public function suppressNotFoundWarnings($flag = null)
@@ -265,8 +265,8 @@ class Zend_Loader_Autoloader
 
     /**
      * Indicate whether or not this autoloader should be a fallback autoloader
-     * 
-     * @param  bool $flag 
+     *
+     * @param  bool $flag
      * @return Zend_Loader_Autoloader
      */
     public function setFallbackAutoloader($flag)
@@ -277,7 +277,7 @@ class Zend_Loader_Autoloader
 
     /**
      * Is this instance acting as a fallback autoloader?
-     * 
+     *
      * @return bool
      */
     public function isFallbackAutoloader()
@@ -288,11 +288,11 @@ class Zend_Loader_Autoloader
     /**
      * Get autoloaders to use when matching class
      *
-     * Determines if the class matches a registered namespace, and, if so, 
-     * returns only the autoloaders for that namespace. Otherwise, it returns 
+     * Determines if the class matches a registered namespace, and, if so,
+     * returns only the autoloaders for that namespace. Otherwise, it returns
      * all non-namespaced autoloaders.
      *
-     * @param  string $class 
+     * @param  string $class
      * @return array Array of autoloaders to use
      */
     public function getClassAutoloaders($class)
@@ -334,7 +334,7 @@ class Zend_Loader_Autoloader
 
     /**
      * Add an autoloader to the beginning of the stack
-     * 
+     *
      * @param  object|array|string $callback PHP callback or Zend_Loader_Autoloader_Interface implementation
      * @param  string|array $namespace Specific namespace(s) under which to register callback
      * @return Zend_Loader_Autoloader
@@ -357,7 +357,7 @@ class Zend_Loader_Autoloader
 
     /**
      * Append an autoloader to the autoloader stack
-     * 
+     *
      * @param  object|array|string $callback PHP callback or Zend_Loader_Autoloader_Interface implementation
      * @param  string|array $namespace Specific namespace(s) under which to register callback
      * @return Zend_Loader_Autoloader
@@ -380,7 +380,7 @@ class Zend_Loader_Autoloader
 
     /**
      * Remove an autoloader from the autoloader stack
-     * 
+     *
      * @param  object|array|string $callback PHP callback or Zend_Loader_Autoloader_Interface implementation
      * @param  null|string|array $namespace Specific namespace(s) from which to remove autoloader
      * @return Zend_Loader_Autoloader
@@ -418,7 +418,7 @@ class Zend_Loader_Autoloader
      * Constructor
      *
      * Registers instance with spl_autoload stack
-     * 
+     *
      * @return void
      */
     protected function __construct()
@@ -429,8 +429,8 @@ class Zend_Loader_Autoloader
 
     /**
      * Internal autoloader implementation
-     * 
-     * @param  string $class 
+     *
+     * @param  string $class
      * @return bool
      */
     protected function _autoload($class)
@@ -450,9 +450,9 @@ class Zend_Loader_Autoloader
 
     /**
      * Set autoloaders for a specific namespace
-     * 
-     * @param  array $autoloaders 
-     * @param  string $namespace 
+     *
+     * @param  array $autoloaders
+     * @param  string $namespace
      * @return Zend_Loader_Autoloader
      */
     protected function _setNamespaceAutoloaders(array $autoloaders, $namespace = '')

+ 103 - 5
library/Zend/Pdf.php

@@ -94,7 +94,7 @@ class Zend_Pdf
     /**
      * Version number of generated PDF documents.
      */
-    const PDF_VERSION = 1.4;
+    const PDF_VERSION = '1.4';
 
     /**
      * PDF file header.
@@ -164,6 +164,13 @@ class Zend_Pdf
      */
     protected $_trailer = null;
 
+    /**
+     * PDF version specified in the file header
+     *
+     * @var string
+     */
+    protected $_pdfHeaderVersion;
+
 
     /**
      * PDF objects factory.
@@ -289,8 +296,9 @@ class Zend_Pdf
         $this->_objFactory = Zend_Pdf_ElementFactory::createFactory(1);
 
         if ($source !== null) {
-            $this->_parser  = new Zend_Pdf_Parser($source, $this->_objFactory, $load);
-            $this->_trailer = $this->_parser->getTrailer();
+            $this->_parser           = new Zend_Pdf_Parser($source, $this->_objFactory, $load);
+            $this->_pdfHeaderVersion = $this->_parser->getPDFVersion();
+            $this->_trailer          = $this->_parser->getTrailer();
             if ($this->_trailer->Encrypt !== null) {
                 require_once 'Zend/Pdf/Exception.php';
                 throw new Zend_Pdf_Exception('Encrypted document modification is not supported');
@@ -328,7 +336,9 @@ class Zend_Pdf
                 $this->_originalProperties = $this->properties;
             }
         } else {
-            $trailerDictionary = new Zend_Pdf_Element_Dictionary();
+        	$this->_pdfHeaderVersion = Zend_Pdf::PDF_VERSION;
+
+        	$trailerDictionary = new Zend_Pdf_Element_Dictionary();
 
             /**
              * Document id
@@ -463,10 +473,13 @@ class Zend_Pdf
      */
     protected function _dumpPages()
     {
-        $pagesContainer = $this->_trailer->Root->Pages;
+    	$root = $this->_trailer->Root;
+        $pagesContainer = $root->Pages;
+
         $pagesContainer->touch();
         $pagesContainer->Kids->items->clear();
 
+        $pageReferences = array();
         foreach ($this->pages as $page ) {
             $page->render($this->_objFactory);
 
@@ -475,8 +488,93 @@ class Zend_Pdf
             $pageDictionary->Parent = $pagesContainer;
 
             $pagesContainer->Kids->items[] = $pageDictionary;
+
+            // Collect page references
+            $pageReferences[$pageDictionary->toString($this->_objFactory)] = 1;
+        }
+
+        // Collect named destinations (exclude not referenced pages)
+        $namedDestinations = array();
+
+        // Walk through destinations structure
+        if ($root->Version !== null  &&  version_compare($root->Version->value, $this->_pdfHeaderVersion, '>')) {
+        	$versionIs_1_2_plus = version_compare($root->Version->value,    '1.1', '>');
+        } else {
+        	$versionIs_1_2_plus = version_compare($this->_pdfHeaderVersion, '1.1', '>');
         }
 
+        if ($versionIs_1_2_plus) {
+        	// PDF version is 1.2+
+        	// Look for Destinations structure at Name dictionary
+        } else {
+        	// PDF version is 1.1 (or earlier)
+        	// Look for Destinations sructure at Dest entry of document catalog
+        	if ($root->Dests !== null) {
+        		if ($root->Dests->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
+                    require_once 'Zend/Pdf/Exception.php';
+                    throw new Zend_Pdf_Exception( 'Document catalog Dests entry must be a dictionary.' );
+        		}
+
+        		foreach ($root->Dests->getKeys() as $destKey) {
+        			$destination = $root->Dests->$destKey;
+        			if ($destination->getType() == Zend_Pdf_Element::TYPE_ARRAY) {
+        				// Destination is an array, just treat it as an explicit destination array
+        				$destinationArray = $destination;
+        			} else if ($destination->getType() == Zend_Pdf_Element::TYPE_DICTIONARY) {
+        				// Destination is a dictionary, treat it as (remote) go-to action
+
+        				// Get 'D' entry (an explicit destination array)
+        				if ($destination->D === null  ||  $destination->D->getType() != Zend_Pdf_Element::TYPE_ARRAY) {
+                            require_once 'Zend/Pdf/Exception.php';
+                            throw new Zend_Pdf_Exception( 'Named destination dictionary must have \'D\' array entry.' );
+        				}
+
+                        $destinationArray = $destination->D;
+                        if ($destination->F !== null) {
+                            // It's a remote Go-To action
+                            // So we don't check page for existance, only check that it's an inderect object reference
+                            rewind($destinationArray->items);
+                            $pageDictionaryObject = current($destinationArray->items);
+                            if ($pageDictionaryObject === false  ||  !$pageDictionaryObject instanceof Zend_Pdf_Element_Object) {
+                                require_once 'Zend/Pdf/Exception.php';
+                                throw new Zend_Pdf_Exception( 'First element of explicit destination array must be an indirect object.' );
+                            }
+
+                            $namedDestinations[$destKey] = 1;
+                            continue;
+        				} else {
+                            require_once 'Zend/Pdf/Exception.php';
+                            throw new Zend_Pdf_Exception( 'PDF 1.1 named destination entry must be an array or dictionary with \'D\' entry.' );
+        				}
+        			} else {
+                        require_once 'Zend/Pdf/Exception.php';
+                        throw new Zend_Pdf_Exception( 'PDF 1.1 named destination entry must be an array or dictionary.' );
+        			}
+
+        			rewind($destinationArray->items);
+        			$pageDictionaryObject = current($destinationArray->items);
+        			if ($pageDictionaryObject === false  ||  !$pageDictionaryObject instanceof Zend_Pdf_Element_Object) {
+                        require_once 'Zend/Pdf/Exception.php';
+                        throw new Zend_Pdf_Exception( 'First element of explicit destination array must be an indirect object.' );
+        			}
+
+        			if (isset($pageReferences[$pageDictionaryObject->toString($this->_objFactory)])) {
+        				// Collect named destination if referenced page is listed within current pages set.
+                        $namedDestinations[$destKey] = 1;
+        			} else {
+        				// Remove named destination from Dest dictionary
+        				$root->Dests->touch();
+        			}
+        		}
+        	}
+        }
+
+        if ($root->OpenAction !== null) {
+//        	if ()
+
+        }
+
+
         $pagesContainer->Count->touch();
         $pagesContainer->Count->value = count($this->pages);
     }

+ 22 - 2
library/Zend/Pdf/Parser.php

@@ -98,6 +98,13 @@ class Zend_Pdf_Parser
      */
     private $_trailer;
 
+    /**
+     * PDF version specified in the file header
+     *
+     * @var string
+     */
+    private $_pdfVersion;
+
 
     /**
      * Get length of source PDF
@@ -120,6 +127,16 @@ class Zend_Pdf_Parser
     }
 
     /**
+     * PDF version specified in the file header
+     *
+     * @return string
+     */
+    public function getPDFVersion()
+    {
+    	return $this->_pdfVersion;
+    }
+
+    /**
      * Load XReference table and referenced objects
      *
      * @param integer $offset
@@ -398,8 +415,10 @@ class Zend_Pdf_Parser
             throw new Zend_Pdf_Exception('File is not a PDF.');
         }
 
-        $pdfVersion = (float)substr($pdfVersionComment, 5);
-        if ($pdfVersion < 0.9 || $pdfVersion >= 1.61) {
+        $pdfVersion = substr($pdfVersionComment, 5);
+        if (version_compare($pdfVersion, '0.9',  '<')  ||
+            version_compare($pdfVersion, '1.61', '>=')
+           ) {
             /**
              * @todo
              * To support PDF versions 1.5 (Acrobat 6) and PDF version 1.7 (Acrobat 7)
@@ -408,6 +427,7 @@ class Zend_Pdf_Parser
              */
             throw new Zend_Pdf_Exception(sprintf('Unsupported PDF version. Zend_Pdf supports PDF 1.0-1.4. Current version - \'%f\'', $pdfVersion));
         }
+        $this->_pdfVersion = $pdfVersion;
 
         $this->_stringParser->offset = strrpos($this->_stringParser->data, '%%EOF');
         if ($this->_stringParser->offset === false ||

+ 1 - 1
library/Zend/Search/Lucene.php

@@ -1148,7 +1148,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
 
         if (count($subResults) == 0) {
             return array();
-        } else if (count($subResults) == 0) {
+        } else if (count($subResults) == 1) {
             // Index is optimized (only one segment)
             // Do not perform array reindexing
             return reset($subResults);

+ 7 - 3
library/Zend/Search/Lucene/Document/Html.php

@@ -93,11 +93,11 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
         	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]);
+        		$htmlTagEndOffset = $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, $htmlTagEndOffset))
                                      . '<head><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"/></head>'
-                                     . iconv($defaultEncoding, 'UTF-8//IGNORE', substr($htmlData, $htmlTagOffset)));
+                                     . iconv($defaultEncoding, 'UTF-8//IGNORE', substr($htmlData, $htmlTagEndOffset)));
 
                 // Remove additional HEAD section
                 $xpath = new DOMXPath($this->_doc);
@@ -281,12 +281,16 @@ class Zend_Search_Lucene_Document_Html extends Zend_Search_Lucene_Document
         $matchedTokens = array_reverse($matchedTokens);
 
         foreach ($matchedTokens as $token) {
+//        	$endOffsetBinary = strlen(iconv_substr());
+
             // Cut text after matched token
             $node->splitText($token->getEndOffset());
 
             // Cut matched node
             $matchedWordNode = $node->splitText($token->getStartOffset());
 
+//            printf("%s - %d, %d\n", $token->getTermText(), $token->getStartOffset(), $token->getEndOffset());
+
             // Retrieve HTML string representation for highlihted word
             $fullCallbackparamsList = $params;
             array_unshift($fullCallbackparamsList, $matchedWordNode->nodeValue);

+ 6 - 6
library/Zend/Search/Lucene/Index/SegmentInfo.php

@@ -967,9 +967,9 @@ class Zend_Search_Lucene_Index_SegmentInfo implements Zend_Search_Lucene_Index_T
 // ---------------------------------------------------------------
                     $updatedFilterData = array();
 
-                    for( $count=0; $count < $termInfo->docFreq; $count++ ) {
+                    for ($count = 0; $count < $termInfo->docFreq; $count++) {
                         $docDelta = $frqFile->readVInt();
-                        if( $docDelta % 2 == 1 ) {
+                        if ($docDelta % 2 == 1) {
                             $docId += ($docDelta-1)/2;
                         } else {
                             $docId += $docDelta/2;
@@ -988,9 +988,9 @@ class Zend_Search_Lucene_Index_SegmentInfo implements Zend_Search_Lucene_Index_T
                     // Perform full scan
                     $updatedFilterData = array();
 
-                    for( $count=0; $count < $termInfo->docFreq; $count++ ) {
+                    for ($count = 0; $count < $termInfo->docFreq; $count++) {
                         $docDelta = $frqFile->readVInt();
-                        if( $docDelta % 2 == 1 ) {
+                        if ($docDelta % 2 == 1) {
                             $docId += ($docDelta-1)/2;
                         } else {
                             $docId += $docDelta/2;
@@ -1008,7 +1008,7 @@ class Zend_Search_Lucene_Index_SegmentInfo implements Zend_Search_Lucene_Index_T
             } else {
                 // Filter is present, but doesn't has data for the current segment yet
                 $filterData = array();
-                for( $count=0; $count < $termInfo->docFreq; $count++ ) {
+                for ($count = 0; $count < $termInfo->docFreq; $count++) {
                     $docDelta = $frqFile->readVInt();
                     if( $docDelta % 2 == 1 ) {
                         $docId += ($docDelta-1)/2;
@@ -1024,7 +1024,7 @@ class Zend_Search_Lucene_Index_SegmentInfo implements Zend_Search_Lucene_Index_T
                 $docsFilter->segmentFilters[$this->_name] = $filterData;
             }
         } else {
-            for( $count=0; $count < $termInfo->docFreq; $count++ ) {
+            for ($count = 0; $count < $termInfo->docFreq; $count++) {
                 $docDelta = $frqFile->readVInt();
                 if( $docDelta % 2 == 1 ) {
                     $docId += ($docDelta-1)/2;

+ 4 - 0
library/Zend/Search/Lucene/Search/Query/MultiTerm.php

@@ -465,6 +465,10 @@ class Zend_Search_Lucene_Search_Query_MultiTerm extends Zend_Search_Lucene_Searc
         $score = 0.0;
 
         foreach ($this->_terms as $termId => $term) {
+if (!isset($this->_termsFreqs[$termId][$docId])) {
+	echo "Undefined offset! - $termId:$docId\n";
+}
+
             /**
              * We don't need to check that term freq is not 0
              * Score calculation is performed only for matched docs

BIN
tests/Zend/Paginator/_files/test.sqlite


+ 10 - 2
tests/Zend/Search/Lucene/SearchHighlightTest.php

@@ -66,7 +66,7 @@ class Zend_Search_Lucene_SearchHighlightTest extends PHPUnit_Framework_TestCase
 
 //    public function testHtmlFragmentHighlightMatchesCyrillic()
 //    {
-//        $query = Zend_Search_Lucene_Search_QueryParser::parse('title:"некоторый текст" AND text:поехали');
+//        $query = Zend_Search_Lucene_Search_QueryParser::parse('title:"некоторый текст" AND text:поехали', 'UTF-8');
 //
 //        $highlightedHtmlFragment = $query->htmlFragmentHighlightMatches('Подсвечиваем некоторый текст с использованием Zend_Search_Lucene. Поехали!');
 //
@@ -74,8 +74,14 @@ class Zend_Search_Lucene_SearchHighlightTest extends PHPUnit_Framework_TestCase
 //                            'Text highlighting using Zend_Search_Lucene is <b style="color:black;background-color:#66ffff">the</b> <b style="color:black;background-color:#66ffff">right</b> <b style="color:black;background-color:#66ffff">way</b> to <b style="color:black;background-color:#ff66ff">go</b>!');
 //    }
 //
-//    public function testHtmlFragmentHighlightMatchesCyrillicWindows()
+//    public function testHtmlFragmentHighlightMatchesCyrillicWin1251()
 //    {
+//    	$analyzer = Zend_Search_Lucene_Analysis_Analyzer::getDefault();
+//    	Zend_Search_Lucene_Analysis_Analyzer::setDefault(
+//    	    new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive()
+//    	   );
+//
+//
 //        $query = Zend_Search_Lucene_Search_QueryParser::parse('title:"Некоторый текст" AND text:поехали');
 //
 //        $highlightedHtmlFragment =
@@ -84,6 +90,8 @@ class Zend_Search_Lucene_SearchHighlightTest extends PHPUnit_Framework_TestCase
 //                                                           'Подсвечиваем некоторый текст с использованием Zend_Search_Lucene. Поехали!'),
 //                                                     'Windows-1251');
 //
+//        Zend_Search_Lucene_Analysis_Analyzer::setDefault($analyzer);
+//
 //        $this->assertEquals($highlightedHtmlFragment,
 //                            'Text highlighting using Zend_Search_Lucene is <b style="color:black;background-color:#66ffff">the</b> <b style="color:black;background-color:#66ffff">right</b> <b style="color:black;background-color:#66ffff">way</b> to <b style="color:black;background-color:#ff66ff">go</b>!');
 //    }