Bläddra i källkod

At the request of the backend developers, setDocumentProperties() has been removed. In a future version of LiveDocx, there will be an official setDocumentProperties() that should work with all file formats.

The previously implemented setDocumentProperties() -- based on Zend_Pdf -- only worked with PDFs. Furthermore, Zend_Pdf currently does not offer any way to add document properties to encrypted PDFs. Since LiveDocx 1.2 Premium setDocumentAccessPermissions() and setDocumentPassword() are available. Data returned from these methods cannot be read with Zend_Pdf.

getDocumentAccessOptions() has been implemented in place of the class constants introduced in the last commit. Again, the backend developers would prefer end-users to get information about which document access options are available using the LiveDocx method. For performance reasons, it is suggested that end-users cache the returned array.




git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19656 44c647ce-9c0f-0410-b52a-842ac1e357ba
jonathan_maron 16 år sedan
förälder
incheckning
69041b097a

+ 0 - 9
demos/Zend/Service/LiveDocx/MailMerge/license-agreement/generate-document.php

@@ -58,15 +58,6 @@ $fieldValues = array (
 $phpLiveDocx->assign($fieldValues);
 */
 
-$documentProperties = array (
-    'title'    => 'License Agreement',
-    'author'   => 'Megasoft Co-operation',
-    'subject'  => 'Magic Graphical Compression Suite v1.9',
-    'keywords' => 'graphics, magical, compression, license'
-);
-
-$phpLiveDocx->setDocumentProperties($documentProperties);
-
 $phpLiveDocx->createDocument();
 
 $document = $phpLiveDocx->retrieveDocument('pdf');

+ 5 - 5
demos/Zend/Service/LiveDocx/MailMerge/pdf-security/generate-document.php

@@ -6,7 +6,7 @@ require_once dirname(__FILE__) . '/../../common.php';
 $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
 
 // Set WSDL of your premium service server
-$phpLiveDocx->setWsdl('https://api.example.com/1.2/mailmerge.asmx?WSDL');
+$phpLiveDocx->setWsdl('https://api.livedocx.com/dev/mailmerge.asmx?wsdl');
 
 $phpLiveDocx->setUsername(Demos_Zend_Service_LiveDocx_Helper::USERNAME)
             ->setPassword(Demos_Zend_Service_LiveDocx_Helper::PASSWORD);
@@ -26,10 +26,10 @@ $phpLiveDocx->setDocumentPassword('aaaaaaaaaa');
 
 // Available on premium service only
 $phpLiveDocx->setDocumentAccessPermissions(
-    array (
-        Zend_Service_LiveDocx_MailMerge::DOCUMENT_ACCESS_PERMISSION_ALLOW_PRINTING_HIGH_LEVEL,
-        Zend_Service_LiveDocx_MailMerge::DOCUMENT_ACCESS_PERMISSION_ALLOW_EXTRACT_CONTENTS
-    ),
+    array(
+        'AllowHighLevelPrinting' ,  // getDocumentAccessOptions() returns
+        'AllowExtractContents'      // array of permitted values
+    ),   
     'myDocumentAccessPassword'
 );
 

+ 0 - 10
demos/Zend/Service/LiveDocx/MailMerge/telephone-bill/generate-document.php

@@ -74,16 +74,6 @@ $billConnections = array(
 $phpLiveDocx->assign('connection', $billConnections);
 
 
-$documentProperties = array (
-    'title'    => sprintf('Telephone Invoice (%s)', $billData['name']),
-    'author'   => 'TIS Telecom', 
-    'subject'  => sprintf('Your telephone invoice for %s', $billData['month']),
-    'keywords' => sprintf('Telephone, Payment, Invoice, %s', $billData['month'])
-);
-
-$phpLiveDocx->setDocumentProperties($documentProperties);
-
-
 $phpLiveDocx->createDocument();
 
 $document = $phpLiveDocx->retrieveDocument('pdf');

+ 20 - 176
library/Zend/Service/LiveDocx/MailMerge.php

@@ -41,65 +41,6 @@ class Zend_Service_LiveDocx_MailMerge extends Zend_Service_LiveDocx
      * @since LiveDocx 1.0 
      */
     const WSDL = 'https://api.livedocx.com/1.2/mailmerge.asmx?WSDL';
-    
-    /**
-     * Document access permission: After the document has been opened no further
-     * document access is restricted
-     * @since LiveDocx 1.2 Premium 
-     */
-    const DOCUMENT_ACCESS_PERMISSION_ALLOW_ALL = 'AllowAll';
-
-    /**
-     * Document access permission: Allow comments to be added and interactive
-     * form fields (including signature fields) to be filled in
-     * @since LiveDocx 1.2 Premium 
-     */    
-    const DOCUMENT_ACCESS_PERMISSION_ALLOW_AUTHORING = 'AllowAuthoring';
-    
-    /**
-     * Document access permission: Allow existing interactive form fields
-     * (including signature fields) to be filled in
-     * @since LiveDocx 1.2 Premium 
-     */    
-    const DOCUMENT_ACCESS_PERMISSION_ALLOW_AUTHORING_FIELDS = 'AllowAuthoringFields';
-    
-    /**
-     * Document access permission: Allow content access for the visually
-     * impaired only
-     * @since LiveDocx 1.2 Premium
-     */    
-    const DOCUMENT_ACCESS_PERMISSION_ALLOW_CONTENT_ACCESSIBILITY = 'AllowContentAccessibility';
-    
-    /**
-     * Document access permission: Allow the document to be to assembled
-     * (insert, rotate or delete pages and create bookmarks or thumbnails)
-     * @since LiveDocx 1.2 Premium
-     */    
-    const DOCUMENT_ACCESS_PERMISSION_ALLOW_DOCUMENT_ASSEMBLY = 'AllowDocumentAssembly';
-    
-    /**
-     * Document access permission: Allow text and/or graphics to be extracted
-     * @since LiveDocx 1.2 Premium 
-     */    
-    const DOCUMENT_ACCESS_PERMISSION_ALLOW_EXTRACT_CONTENTS = 'AllowExtractContents';
-    
-    /**
-     * Document access permission: Allow the document contents to be modified
-     * @since LiveDocx 1.2 Premium
-     */    
-    const DOCUMENT_ACCESS_PERMISSION_ALLOW_GENERAL_EDITING = 'AllowGeneralEditing';
-    
-    /**
-     * Document access permission: Allow the document to be printed
-     * @since LiveDocx 1.2 Premium
-     */    
-    const DOCUMENT_ACCESS_PERMISSION_ALLOW_PRINTING_HIGH_LEVEL = 'AllowHighLevelPrinting';
-    
-    /**
-     * Document access permission: Allow the document to be printed (low-level)
-     * @since LiveDocx 1.2 Premium
-     */    
-    const DOCUMENT_ACCESS_PERMISSION_ALLOW_PRINTING_LOW_LEVEL = 'AllowLowLevelPrinting';    
 
     /**
      * Field values
@@ -118,14 +59,6 @@ class Zend_Service_LiveDocx_MailMerge extends Zend_Service_LiveDocx
     protected $_blockFieldValues;
 
     /**
-     * Document properties of PDF file (only)
-     *
-     * @var   array
-     * @since LiveDocx 1.0
-     */
-    protected $_documentProperties;
-
-    /**
      * Constructor (LiveDocx.MailMerge SOAP Service)
      *
      * @return void
@@ -138,8 +71,6 @@ class Zend_Service_LiveDocx_MailMerge extends Zend_Service_LiveDocx
         $this->_fieldValues      = array();
         $this->_blockFieldValues = array();
         
-        $this->_setDefaultDocumentProperties();
-        
         parent::__construct($options);
     }
 
@@ -334,8 +265,6 @@ class Zend_Service_LiveDocx_MailMerge extends Zend_Service_LiveDocx
             );
         }
         
-        $this->_documentProperties['Encrypted'] = true;
-        
         return $this;        
     }
     
@@ -367,28 +296,6 @@ class Zend_Service_LiveDocx_MailMerge extends Zend_Service_LiveDocx
      */
     public function setDocumentAccessPermissions($permissions, $password)
     {
-        $validPermissions = array(
-            self::DOCUMENT_ACCESS_PERMISSION_ALLOW_ALL ,
-            self::DOCUMENT_ACCESS_PERMISSION_ALLOW_AUTHORING ,
-            self::DOCUMENT_ACCESS_PERMISSION_ALLOW_AUTHORING_FIELDS ,
-            self::DOCUMENT_ACCESS_PERMISSION_ALLOW_CONTENT_ACCESSIBILITY ,
-            self::DOCUMENT_ACCESS_PERMISSION_ALLOW_DOCUMENT_ASSEMBLY ,
-            self::DOCUMENT_ACCESS_PERMISSION_ALLOW_EXTRACT_CONTENTS ,
-            self::DOCUMENT_ACCESS_PERMISSION_ALLOW_GENERAL_EDITING ,
-            self::DOCUMENT_ACCESS_PERMISSION_ALLOW_PRINTING_HIGH_LEVEL ,
-            self::DOCUMENT_ACCESS_PERMISSION_ALLOW_PRINTING_LOW_LEVEL
-        );      
-        
-        foreach ($permissions as $permission) {
-            if (! in_array($permission, $validPermissions)) {
-                require_once 'Zend/Service/LiveDocx/Exception.php';
-                throw new Zend_Service_LiveDocx_Exception(
-                    'Invalid document access permission. '
-                  . 'Must be one of Zend_Service_LiveDocx_MailMerge::DOCUMENT_ACCESS_PERMISSION_* class constants'
-                );
-            }
-        }
-        
         $this->logIn();
         
         try {
@@ -403,8 +310,6 @@ class Zend_Service_LiveDocx_MailMerge extends Zend_Service_LiveDocx
             );
         }
         
-        $this->_documentProperties['Encrypted'] = true;
-        
         return $this;        
     }    
     
@@ -465,15 +370,6 @@ class Zend_Service_LiveDocx_MailMerge extends Zend_Service_LiveDocx
 
         $ret = base64_decode($result->RetrieveDocumentResult);
         
-        // @todo: Move this logic to backend server in future version
-        if ('pdf' === $format &&
-            false === $this->_documentProperties['Encrypted']) {
-            require_once 'Zend/Pdf.php';
-            $pdf = Zend_Pdf::parse($ret);
-            $pdf->properties = $this->_getDocumentProperties();
-            $ret = $pdf->render();
-        }
-
         return $ret;
     }
 
@@ -689,78 +585,6 @@ class Zend_Service_LiveDocx_MailMerge extends Zend_Service_LiveDocx
     }
 
     /**
-     * Set the default document properties
-     *
-     * @return null
-     * @since  LiveDocx 1.0
-     */
-    protected function _setDefaultDocumentProperties()
-    {
-        $date = new Zend_Date();
-
-        $this->_documentProperties = array();
-
-        $projectName  = sprintf('phpLiveDocx %s', self::getVersion());
-        $projectUrl   = 'http://www.phpLiveDocx.org';
-        $creationDate = sprintf('D:%s', $date->toString('YYYYMMddHHmmss'));
-        
-        // Zend_Pdf expects keys with uppercase first letter
-        $this->_documentProperties['Creator']      = $projectName;
-        $this->_documentProperties['Producer']     = $projectUrl;
-        $this->_documentProperties['CreationDate'] = $creationDate;
-        $this->_documentProperties['ModDate']      = $creationDate;
-        
-        // Set to true, if contents are password protected or encrypted
-        $this->_documentProperties['Encrypted'] = false; 
-    }
-
-    /**
-     * Set the document properties
-     *
-     * $properties is an assoc array with the following format:
-     *
-     * {code}
-     * $properties = array (
-     *     'title'        => '', // (string)
-     *     'author'       => '', // (string)
-     *     'subject'      => '', // (string)
-     *     'keywords'     => '', // (string)
-     * );
-     * {code}
-     * 
-     * This method can only be used for PDF documents
-     *
-     * @param  array $properties
-     * @return Zend_Service_LiveDocx_MailMerge
-     * @since  LiveDocx 1.0
-     */
-    public function setDocumentProperties($properties)
-    {
-        // For consistency, keys in $properties are lowercase.
-        // Zend_Pdf expects keys with uppercase first letter
-        $keys = array('Title', 'Author', 'Subject', 'Keywords');
-        foreach ($keys as $key) {
-            $lowerCaseKey = strtolower($key);
-            if (isset($properties[$lowerCaseKey])) {
-                $this->_documentProperties[$key] = $properties[$lowerCaseKey];
-            }
-        }
-
-        return $this;
-    }
-
-    /**
-     * Return currently set document properties
-     *
-     * @return array
-     * @since  LiveDocx 1.0
-     */
-    protected function _getDocumentProperties()
-    {
-        return $this->_documentProperties;
-    }
-
-    /**
      * Upload a template file to LiveDocx service
      *
      * @param  string $filename
@@ -1057,6 +881,26 @@ class Zend_Service_LiveDocx_MailMerge extends Zend_Service_LiveDocx
 
         return $ret;
     }    
+    
+    /**
+     * Return supported document access options
+     *
+     * @return array
+     * @since  LiveDocx 1.2 Premium
+     */
+    public function getDocumentAccessOptions()
+    {
+        $this->logIn();
+        
+        $ret    = array();
+        $result = $this->getSoapClient()->GetDocumentAccessOptions();
+
+        if (isset($result->GetDocumentAccessOptionsResult->string)) {
+            $ret = $result->GetDocumentAccessOptionsResult->string;
+        }
+
+        return $ret;
+    }    
 
     /**
      * Convert LiveDocx service return value from list methods to consistent PHP array

+ 9 - 27
tests/Zend/Service/LiveDocx/MailMergeTest.php

@@ -360,36 +360,32 @@ class Zend_Service_LiveDocx_MailMergeTest extends PHPUnit_Framework_TestCase
     }
 
     // -------------------------------------------------------------------------
-
+    
     public function testGetTemplateFormats()
     {
-        $expectedResults = array('doc', 'docx', 'rtf', 'txd');
+        $expectedResults = array('doc' , 'docx' , 'rtf' , 'txd');
         $this->assertEquals($expectedResults, $this->phpLiveDocx->getTemplateFormats());
     }
 
     public function testGetDocumentFormats()
     {
-        $expectedResults = array('doc', 'docx', 'html', 'pdf', 'rtf', 'txd', 'txt');
+        $expectedResults = array('doc' , 'docx' , 'html' , 'pdf' , 'rtf' , 'txd' , 'txt');
         $this->assertEquals($expectedResults, $this->phpLiveDocx->getDocumentFormats());
     }
 
     public function testGetImageFormats()
     {
-        $expectedResults = array('bmp', 'gif', 'jpg', 'png', 'tiff');
+        $expectedResults = array('bmp' , 'gif' , 'jpg' , 'png' , 'tiff');
         $this->assertEquals($expectedResults, $this->phpLiveDocx->getImageFormats());
     }
 
-    // -------------------------------------------------------------------------
-
-    public function testGetMetafiles()
+    public function testGetDocumentAccessOptions()
     {
-        $this->markTestIncomplete();
-    }
-
-    public function testGetAllMetafiles()
-    {
-        $this->markTestIncomplete();
+        $expectedResults = array('AllowAuthoring' , 'AllowAuthoringFields' , 'AllowContentAccessibility' , 'AllowDocumentAssembly' , 'AllowExtractContents' , 'AllowGeneralEditing' , 'AllowHighLevelPrinting' , 'AllowLowLevelPrinting' , 'AllowAll');
+        $this->assertEquals($expectedResults, $this->phpLiveDocx->getDocumentAccessOptions());
     }
+    
+    // -------------------------------------------------------------------------
 
     public function testGetBitmaps()
     {
@@ -512,20 +508,6 @@ class Zend_Service_LiveDocx_MailMergeTest extends PHPUnit_Framework_TestCase
 
     // -------------------------------------------------------------------------
 
-    public function testSetDocumentProperties()
-    {
-        $testValues = array(
-            'title'    => 'phpunit',
-            'author'   => 'phpunit',
-            'subject'  => 'phpunit',
-            'keywords' => 'phpunit',
-        );
-
-        $this->assertTrue(is_a($this->phpLiveDocx->setDocumentProperties($testValues), 'Zend_Service_LiveDocx_MailMerge'));
-    }
-
-    // -------------------------------------------------------------------------
-
     public function testUploadTemplate()
     {
         $this->phpLiveDocx->deleteTemplate(self::TEST_TEMPLATE_2);