Skip to content

Commit

Permalink
Merge remote branch 'jonathanmaron/zend-service-livedocx-1.3' into zf…
Browse files Browse the repository at this point in the history
…2/master
  • Loading branch information
weierophinney committed Jun 8, 2010
2 parents b75f179 + 62bae48 commit ccb08e8
Show file tree
Hide file tree
Showing 31 changed files with 818 additions and 634 deletions.
31 changes: 31 additions & 0 deletions demos/Zend/Service/LiveDocx/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

// Set used namespaces
use Zend\Loader\Autoloader;
use Zend\Locale\Locale;
use Zend\Registry;
use Zend\Service\LiveDocx\Helper;

// Turn up error reporting
error_reporting(E_ALL | E_STRICT);

// Set path to libraries
set_include_path(
__DIR__ . DIRECTORY_SEPARATOR . 'library' . PATH_SEPARATOR .
dirname(dirname(dirname(dirname(__DIR__)))) . DIRECTORY_SEPARATOR . 'library'
);

// Set autoloader to autoload libraries
require_once 'Zend/Loader/Autoloader.php';
Autoloader::getInstance();

// Set default locale
Locale::setDefault(Helper::LOCALE);
$locale = new Locale(Locale::ZFDEFAULT);
Registry::set('Zend_Locale', $locale);

// Ensure LiveDocx credentials are available
if (false === Helper::credentialsAvailable()) {
Helper::printLine(Helper::credentialsHowTo());
exit();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,33 @@
*/

/**
* This file defines configuration for running the Zend_Service_LiveDocx demo
* applications.
* This file defines configuration for running the demo applications, shipped
* with the Zend Framework LiveDocx component.
*
* Do not edit this file. Instead, copy this file to configuration.php,
* Do not edit this file. Instead, copy this file to DemoConfiguration.php,
* and edit the new file. Never commit plaintext passwords to the source
* code repository.
*/

/**
* Zend_Service_LiveDocx configuration
* LiveDocx configuration
*
* Define username and password in order to access LiveDocx web services.
*
*
* Get a username and password here:
*
*
* https://www.livedocx.com/user/account_registration.aspx
*
*/
define('DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME', false);
define('DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD', false);
define('DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD', false);

/**
* [PREMIUM] LiveDocx configuration
*
* Define username and password in order to access LiveDocx premium web services.
*
*/
define('DEMOS_ZEND_SERVICE_LIVEDOCX_PREMIUM_WSDL', false);
define('DEMOS_ZEND_SERVICE_LIVEDOCX_PREMIUM_USERNAME', false);
define('DEMOS_ZEND_SERVICE_LIVEDOCX_PREMIUM_PASSWORD', false);
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php

require_once dirname(__FILE__) . '/../../common.php';
require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Bootstrap.php';


$mailMerge = new Zend_Service_LiveDocx_MailMerge();
use Zend\Date\Date;
use Zend\Service\LiveDocx\MailMerge;

$mailMerge = new MailMerge();

$mailMerge->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)
->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
Expand All @@ -13,8 +16,8 @@
$mailMerge->assign('software', 'Magic Graphical Compression Suite v1.9')
->assign('licensee', 'Daï Lemaitre')
->assign('company', 'Megasoft Co-operation')
->assign('date', Zend_Date::now()->toString(Zend_Date::DATE_LONG))
->assign('time', Zend_Date::now()->toString(Zend_Date::TIME_LONG))
->assign('date', Date::now()->toString(Date::DATE_LONG))
->assign('time', Date::now()->toString(Date::TIME_LONG))
->assign('city', 'Lyon')
->assign('country', 'France');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<?php

require_once dirname(__FILE__) . '/../../common.php';
require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Bootstrap.php';


system('clear');
use Zend\Service\LiveDocx\Helper;
use Zend\Service\LiveDocx\MailMerge;

print(Demos_Zend_Service_LiveDocx_Helper::wrapLine(
Helper::printLine(
PHP_EOL . 'Using Hosted Solution and Fully-Licensed Servers' .
PHP_EOL .
PHP_EOL . 'This sample application illustrates how to use Zend_Service_LiveDocx_MailMerge with hosted and fully-licensed LiveDocx servers, by specifying an alternative SOAP client (must be instance of Zend_Soap_Client).' .
PHP_EOL .
PHP_EOL)
PHP_EOL . 'This sample application illustrates how to use the Zend Framework LiveDocx component with hosted and fully-licensed LiveDocx servers, by specifying the server\'s WSDL.' .
PHP_EOL .
PHP_EOL
);

$mailMerge = new Zend_Service_LiveDocx_MailMerge();
$mailMerge = new MailMerge();

$mailMerge->setWsdl('https://api.example.com/1.2/mailmerge.asmx?WSDL')
->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)
->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
$mailMerge->setWsdl(DEMOS_ZEND_SERVICE_LIVEDOCX_PREMIUM_WSDL)
->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_PREMIUM_USERNAME)
->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PREMIUM_PASSWORD);

$mailMerge->getTemplateFormats(); // then call methods as usual

Expand All @@ -31,4 +32,4 @@
PHP_EOL
);

unset($mailMerge, $mySoapClient);
unset($mailMerge);
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<?php

require_once dirname(__FILE__) . '/../../common.php';
require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Bootstrap.php';


system('clear');
use Zend\Config\Ini;
use Zend\Service\LiveDocx\Helper;
use Zend\Service\LiveDocx\MailMerge;

print(Demos_Zend_Service_LiveDocx_Helper::wrapLine(
PHP_EOL . 'Using the Public LiveDocx Service with Zend_Config' .
Helper::printLine(
PHP_EOL . 'Using the Public LiveDocx Service with \Zend\Config\Config' .
PHP_EOL .
PHP_EOL . 'This sample application illustrates how to use Zend_Service_LiveDocx_MailMerge with a Zend_Config object. This is useful, for example, to store connection credentials in an external ini file.' .
PHP_EOL . 'This sample application illustrates how to use the Zend Framework LiveDocx component with a \Zend\Config\Config object. This is useful, for example, to store connection credentials in an external ini file.' .
PHP_EOL .
PHP_EOL)
PHP_EOL
);

$options = new Zend_Config_Ini('credentials.ini');
$options = new Ini('credentials.ini');

$mailMerge = new Zend_Service_LiveDocx_MailMerge($options);
$mailMerge = new MailMerge($options);

$mailMerge->getTemplateFormats(); // then call methods as usual

Expand Down
15 changes: 8 additions & 7 deletions demos/Zend/Service/LiveDocx/MailMerge/constructors/public.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<?php

require_once dirname(__FILE__) . '/../../common.php';
require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Bootstrap.php';


system('clear');
use Zend\Service\LiveDocx\Helper;
use Zend\Service\LiveDocx\MailMerge;

print(Demos_Zend_Service_LiveDocx_Helper::wrapLine(
Helper::printLine(
PHP_EOL . 'Using the Free Public Server' .
PHP_EOL .
PHP_EOL . 'This sample application illustrates how to use Zend_Service_LiveDocx_MailMerge with the free, public LiveDocx server.' .
PHP_EOL . 'This sample application illustrates how to use the Zend Framework LiveDocx component with the free, public LiveDocx server.' .
PHP_EOL .
PHP_EOL)
PHP_EOL
);

$mailMerge = new Zend_Service_LiveDocx_MailMerge();
$mailMerge = new MailMerge();

$mailMerge->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)
->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
Expand All @@ -36,7 +37,7 @@

// Alternatively, you can pass username and password in the constructor.

$mailMerge = new Zend_Service_LiveDocx_MailMerge(
$mailMerge = new MailMerge(
array (
'username' => DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME,
'password' => DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

require_once dirname(__FILE__) . '/../../common.php';
require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Bootstrap.php';


/**
* Converting documents between supported formats
*
* The primary goal of Zend_Service_LiveDocx_MailMerge is to populate templates
* The primary goal of the Zend Framework LiveDocx component is to populate templates
* with textual data to generate word processing documents. It can, however,
* also be used to convert word processing documents between supported formats.
*
Expand All @@ -18,7 +18,9 @@
* made available.
*/

$mailMerge = new Zend_Service_LiveDocx_MailMerge();
use Zend\Service\LiveDocx\MailMerge;

$mailMerge = new MailMerge();

$mailMerge->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)
->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

set_time_limit(0);

require_once dirname(__FILE__) . '/../../common.php';
require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Bootstrap.php';


/**
* Concatenating PDF files locally - advanced
Expand Down Expand Up @@ -31,6 +32,13 @@
* location. The specified paths are correct for Debian 5.0.3.
*/

use Zend\Date\Date;
use Zend\Log\Logger;
use Zend\Log\Writer\Stream as Writer;
use Zend\Registry;
use Zend\Service\LiveDocx\Helper;
use Zend\Service\LiveDocx\MailMerge;

define('EXEC_PDFTK', '/usr/bin/pdftk');
define('EXEC_GHOSTSCRIPT', '/usr/bin/gs');

Expand Down Expand Up @@ -65,21 +73,21 @@

// Logger to output status messages

$logger = new Zend_Log(new Zend_Log_Writer_Stream('php://output'));
$logger = new Logger(new Writer('php://stdout'));

Zend_Registry::set('logger', $logger);
Registry::set('logger', $logger);

// -----------------------------------------------------------------------------

// Create temporary directory

$tempDirectory = sys_get_temp_dir() . '/' . md5(rand(1, 10000) . __FILE__);
$tempDirectory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(rand(1, 10000) . __FILE__);

if (is_dir($tempDirectory)) {
recursiveRemoveDirectory($tempDirectory);
}

$logger->log(sprintf('Making temporary directory %s.', $tempDirectory), Zend_Log::INFO);
$logger->log(sprintf('Making temporary directory %s.', $tempDirectory), Logger::INFO);

mkdir($tempDirectory);

Expand All @@ -89,7 +97,7 @@

$tempFilenames = array();

$mailMerge = new Zend_Service_LiveDocx_MailMerge();
$mailMerge = new MailMerge();

$mailMerge->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)
->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
Expand All @@ -98,22 +106,22 @@

for ($iteration = 1; $iteration <= $iterations; $iteration ++) {

$tempFilename = sprintf('%s/%010s.pdf', $tempDirectory, $iteration);
$tempFilename = sprintf('%s%s%010s.pdf', $tempDirectory, DIRECTORY_SEPARATOR, $iteration);
$tempFilenames[] = $tempFilename;

$mailMerge->assign('software', randomString())
->assign('licensee', randomString())
->assign('company', randomString())
->assign('date', Zend_Date::now()->toString(Zend_Date::DATE_LONG))
->assign('time', Zend_Date::now()->toString(Zend_Date::TIME_LONG))
->assign('date', Date::now()->toString(Date::DATE_LONG))
->assign('time', Date::now()->toString(Date::TIME_LONG))
->assign('city', randomString())
->assign('country', randomString());

$mailMerge->createDocument();

file_put_contents($tempFilename, $mailMerge->retrieveDocument('pdf'));

$logger->log(sprintf('Generating temporary document %s.', $tempFilename), Zend_Log::INFO);
$logger->log(sprintf('Generating temporary document %s.', $tempFilename), Logger::INFO);
}

unset($mailMerge);
Expand All @@ -122,21 +130,21 @@

// Concatenate temporary documents and write output document

$outputFilename = './document-concat.pdf';
$outputFilename = __DIR__ . DIRECTORY_SEPARATOR . 'document-concat.pdf';

$logger->log('Concatenating temporary documents...', Zend_Log::INFO);
$logger->log('Concatenating temporary documents...', Logger::INFO);

if (true === concatenatePdfFilenames($tempFilenames, $outputFilename, $processor)) {
$logger->log(sprintf('...DONE. Saved output document as %s.', $outputFilename), Zend_Log::INFO);
$logger->log(sprintf('...DONE. Saved output document as %s.', basename($outputFilename)), Logger::INFO);
} else {
$logger->log(sprintf('...ERROR.'), Zend_Log::ERR);
$logger->log(sprintf('...ERROR.'), Logger::ERR);
}

// -----------------------------------------------------------------------------

// Delete temporary directory

$logger->log(sprintf('Deleting temporary directory %s.', $tempDirectory), Zend_Log::INFO);
$logger->log(sprintf('Deleting temporary directory %s.', $tempDirectory), Logger::INFO);

if (is_dir($tempDirectory)) {
recursiveRemoveDirectory($tempDirectory);
Expand Down Expand Up @@ -180,7 +188,7 @@ function recursiveRemoveDirectory($dir)
$files = glob($dir . '*', GLOB_MARK);

foreach ($files as $file) {
if ('/' === substr($file, - 1)) {
if (DIRECTORY_SEPARATOR === substr($file, - 1)) {
recursiveRemoveDirectory($file);
} else {
unlink($file);
Expand All @@ -206,10 +214,10 @@ function concatenatePdfFilenames($inputFilenames, $outputFilename, $processor =
{
$ret = false;

$logger = Zend_Registry::get('logger');
$logger = Registry::get('logger');

if (! (is_file(EXEC_PDFTK) || is_file(EXEC_GHOSTSCRIPT))) {
$logger->log('Either pdftk or ghostscript are required for this sample application.', Zend_Log::CRIT);
$logger->log('Either pdftk or ghostscript are required for this sample application.', Logger::CRIT);
exit();
}

Expand All @@ -234,7 +242,7 @@ function concatenatePdfFilenames($inputFilenames, $outputFilename, $processor =
break;

default:
$logger->log('Invalid concatenation processor - use PROCESSOR_PDFTK or PROCESSOR_GHOSTSCRIPT only.', Zend_Log::CRIT);
$logger->log('Invalid concatenation processor - use PROCESSOR_PDFTK or PROCESSOR_GHOSTSCRIPT only.', Logger::CRIT);
exit();
break;
}
Expand Down
Loading

0 comments on commit ccb08e8

Please sign in to comment.