Migrating to WebClientPrint 3.0 for PHP
Product WebClientPrint for PHP Published 11/26/2016 Updated 11/26/2016 Author Neodynamic
Overview
Due to some new features and customers requests, the brand new WebClientPrint 3.0 for PHP is not backwards compatible with older versions. Please use this article as a general guide to upgrading your server-side code to v3.0
In this article:
- WCPP Client phasing out support for some very old Windows versions
- Changes in WebClientPrint.php file
- WCPP Detection Stuff
- Registering the WebClientPrint Script code generation
A WCPP Client phasing out support for some very old Windows versions
Starting with v3.0, the WCPP Client Utility will not longer support Windows 98, Windows 2000, and Windows ME. So if your client machines are running any of these Windows versions, then you must not migrate to v3.0
B Changes in WebClientPrint.php file
v2.0 requires the following configuration settings in the WebClientPrint.php file of your website:
//IMPORTANT SETTINGS:
//===================
//Set ABSOLUTE URL to WebClientPrint.php file
WebClientPrint::$webClientPrintAbsoluteUrl = Utils::getRoot().'/PrintSample/WebClientPrint.php';
//Set wcpcache folder RELATIVE to WebClientPrint.php file
//FILE WRITE permission on this folder is required!!!
WebClientPrint::$wcpCacheFolder = 'wcpcache/';
//===================
Starting with v3.0, the first setting $webClientPrintAbsoluteUrl is no longer needed and the second one $wcpCacheFolder has been moved to another new php file.
v3.0 requires you to create a new WebClientPrintController.php file (at the same folder where WebClientPrint.php is located in) with the following code:
<?php
//*********************************
// IMPORTANT NOTE
// 1. In this sample we store users related stuff (like
// the list of printers and whether they have the WCPP
// client utility installed) in the wcpcache folder BUT
// you can change it to another different storage (like a DB)!
// which will be required in Load Balacing scenarios
//
// 2. If your website requires user authentication, then
// THIS FILE MUST be set to ALLOW ANONYMOUS access!!!
//
//*********************************
include 'WebClientPrint.php';
use Neodynamic\SDK\Web\WebClientPrint;
//IMPORTANT SETTINGS:
//===================
//Set wcpcache folder RELATIVE to WebClientPrint.php file
//FILE WRITE permission on this folder is required!!!
WebClientPrint::$wcpCacheFolder = getcwd().'/wcpcache/';
//===================
// Clean built-in Cache
// NOTE: Remove it if you implement your own cache system
WebClientPrint::cacheClean(30); //in minutes
// Process WebClientPrint Request
$urlParts = parse_url($_SERVER['REQUEST_URI']);
if (isset($urlParts['query'])){
$query = $urlParts['query'];
parse_str($query, $qs);
//get session id from querystring if any
$sid = NULL;
if (isset($qs[WebClientPrint::SID])){
$sid = $qs[WebClientPrint::SID];
}
try{
//get request type
$reqType = WebClientPrint::GetProcessRequestType($query);
if($reqType == WebClientPrint::GenPrintScript ||
$reqType == WebClientPrint::GenWcppDetectScript){
//Let WebClientPrint to generate the requested script
//Get Absolute URL of this file
$currentAbsoluteURL = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
$currentAbsoluteURL .= $_SERVER["SERVER_NAME"];
if($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443")
{
$currentAbsoluteURL .= ":".$_SERVER["SERVER_PORT"];
}
$currentAbsoluteURL .= $_SERVER["REQUEST_URI"];
$currentAbsoluteURL = substr($currentAbsoluteURL, 0, strrpos($currentAbsoluteURL, '?'));
ob_start();
ob_clean();
header('Content-type: text/javascript');
echo WebClientPrint::generateScript($currentAbsoluteURL, $query);
return;
}
else if ($reqType == WebClientPrint::ClientSetWcppVersion)
{
//This request is a ping from the WCPP utility
//so store the session ID indicating this user has the WCPP installed
//also store the WCPP Version if available
if(isset($qs[WebClientPrint::WCPP_SET_VERSION]) && strlen($qs[WebClientPrint::WCPP_SET_VERSION]) > 0){
WebClientPrint::cacheAdd($sid, WebClientPrint::WCP_CACHE_WCPP_VER, $qs[WebClientPrint::WCPP_SET_VERSION]);
}
return;
}
else if ($reqType == WebClientPrint::ClientSetInstalledPrinters)
{
//WCPP Utility is sending the installed printers at client side
//so store this info with the specified session ID
WebClientPrint::cacheAdd($sid, WebClientPrint::WCP_CACHE_PRINTERS, strlen($qs[WebClientPrint::WCPP_SET_PRINTERS]) > 0 ? base64_decode($qs[WebClientPrint::WCPP_SET_PRINTERS]) : '');
return;
}
else if ($reqType == WebClientPrint::ClientGetWcppVersion)
{
//return the WCPP version for the specified Session ID (sid) if any
ob_start();
ob_clean();
header('Content-type: text/plain');
echo WebClientPrint::cacheGet($sid, WebClientPrint::WCP_CACHE_WCPP_VER);
return;
}
else if ($reqType == WebClientPrint::ClientGetInstalledPrinters)
{
//return the installed printers for the specified Session ID (sid) if any
ob_start();
ob_clean();
header('Content-type: text/plain');
echo WebClientPrint::cacheGet($sid, WebClientPrint::WCP_CACHE_PRINTERS);
return;
}
}
catch (Exception $ex)
{
throw $ex;
}
}
C WCPP Detection Stuff
C. 1. METATAG for Internet Explorer
v2.0 requires the following meta tag in the HEAD section of your webpage.
echo WebClientPrint::getWcppDetectionMetaTag();
Starting with v3.0, this code is no longer needed so you should REMOVE this from your page
C. 2. WCPP Detection Script
v2.0 requires the following code for generating the script code
echo WebClientPrint::createWcppDetectionScript();
Starting with v3.0, this must be replaced by the following code:
//Get Absolute URL of this page
$currentAbsoluteURL = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
$currentAbsoluteURL .= $_SERVER["SERVER_NAME"];
if($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443")
{
$currentAbsoluteURL .= ":".$_SERVER["SERVER_PORT"];
}
$currentAbsoluteURL .= $_SERVER["REQUEST_URI"];
//WebClientPrinController.php is at the same page level as WebClientPrint.php
$webClientPrintControllerAbsoluteURL = substr($currentAbsoluteURL, 0, strrpos($currentAbsoluteURL, '/')).'/WebClientPrintController.php';
// Create WCPP detection script
echo WebClientPrint::createWcppDetectionScript($webClientPrintControllerAbsoluteURL, session_id());
D Registering the WebClientPrint Script code generation
v2.0 requires the following code for generating the script which will allow you to print
echo WebClientPrint::createScript(Utils::getRoot().'/PrintSample/PrintFile.php');
Starting with v3.0, this new code will be required:
//Get Absolute URL of this page
$currentAbsoluteURL = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
$currentAbsoluteURL .= $_SERVER["SERVER_NAME"];
if($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443")
{
$currentAbsoluteURL .= ":".$_SERVER["SERVER_PORT"];
}
$currentAbsoluteURL .= $_SERVER["REQUEST_URI"];
//WebClientPrinController.php is at the same page level as WebClientPrint.php
$webClientPrintControllerAbsoluteURL = substr($currentAbsoluteURL, 0, strrpos($currentAbsoluteURL, '/')).'/WebClientPrintController.php';
//DemoPrintFileProcess.php is at the same page level as WebClientPrint.php
$demoPrintFileProcessAbsoluteURL = substr($currentAbsoluteURL, 0, strrpos($currentAbsoluteURL, '/')).'/DemoPrintFileProcess.php';
//Specify the ABSOLUTE URL to the WebClientPrintController.php and to the file that will create the ClientPrintJob object
echo WebClientPrint::createScript($webClientPrintControllerAbsoluteURL, $demoPrintFileProcessAbsoluteURL, session_id());
That's all. Most of the changes in v3.0 are internal and requires you to make minor modifications in your projects which were created for v2.0
As always, do not hesitate to contact our dev team at http://neodynamic.com/support