Folder reorganize 1

This commit is contained in:
Rucus
2026-02-17 12:44:37 -06:00
parent ec99d85bc2
commit f0ae0ab905
17427 changed files with 2071 additions and 1059030 deletions

View File

@@ -0,0 +1,327 @@
<?php
/**
*
* FusionCharts Exporter - 'Image Resource' handles
* FusionCharts (since v3.1) Server Side Export feature that
* helps FusionCharts exported as Image files in various formats.
*
*
* @author FusionCharts
* @description FusionCharts Exporter (Server-Side - PHP)
* @version 2.0 [ 12 February 2009 ]
*
*/
/**
* ChangeLog / Version History:
* ----------------------------
*
*
* 1.1 [ 18 July 2009 ]
* background color was turning black in a few linux distro - fixed . The original code is kept commneted. Line 277
*
*
*
* 1.0 [ 12 February 2009 ]
*
* FEATURES:
* - Integrated with new Export feature of FusionCharts 3.1 & FusionCharts Exporter v 2.0
* - can save to server side directory
* - can provide download or open in browser window/frame other than _self
* - can save in various image formats viz. jpeg, png and gif.
*
*
*/
/**
* Copyright (c) 2016 Infosoft Global Private Limited
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* GENERAL NOTES
* -------------
*
* Chart would POST export data (which consists of encoded image data stream,
* width, height, background color and various other export parameters like
* exportFormat, exportFileName, exportAction, exportTargetWindow) to this script.
*
* The script would process this data using appropriate resource files build
* export binary (PDF/image)
*
* It either saves the binary as file to a server side directory or push it as
* Download or open in a new browser window/frame.
*
*
*/
/**
* @requires FCExporter.php A file that includes this resource
*
*
* Details
* -------
*
* The resource files would have these things as common:
*
* a) a constant - MIMETYPES that would have a string
* containing semicolon separated key value pairs.
* Each key can be a format name specified in the
* HANDLERASSOCIATIONS constant. The associated value
* would be the mimetype for the specified format.
*
* e.g. define("MIMETYPES","jpg=image/jpeg;jpeg=image/jpeg;png=image/png;gif=image/gif");
*
*
* b) a constant - EXTENSIONS that again contain a string of
* semicolon separated key value pair. Each key would again be the
* format name and the extension would be the file extension.
*
* e.g. define("EXTENSIONS","jpg=jpg;jpeg=jpg;png=png;gif=gif");
*
*
* c) a function - exportProcessor ( $stream , $meta )
* It would take the FusionCharts exncoded image string as $stream &
* an associative array $meta containging width, height and bgColor keys.
*
* The function would return an object of mixed type which would contain
* the processed binary/relevant export object.
*
*
* d) a function - exportOutput ( $exportObj, $exportSettings, $quality=1 )
* It would take the processed export object and other export setting as parameter.
* Moreover, it would take an optional parameter - $quality (in scale of 0 to 1).
* By Default, the $quality is passed as 1 (best quality)
*
* The function would return the file path on success or return false on failure.
*
* [ The other code in the resource file can be anything that support this architecture ]
*
*/
// =============================================================================
// == Constants and Variables ==
// =============================================================================
// **** Users are recommended NOT to perform any editing beyond this point. ****
/* ------------------------- EXPORT RESOURCES -------------------------------- */
// This constant lists the mime types related to each export format this resource handles
// The value is semicolon separated key value pair for each format
// Each key is the format and value is the mime type
define( "MIMETYPES", "jpg=image/jpeg;jpeg=image/jpeg;gif=image/gif;png=image/png" );
// This constant lists all the file extensions for the export formats
// The value is semicolon separated key value pair for each format
// Each key is the format and value is the file extension
define( "EXTENSIONS", "jpg=jpg;jpeg=jpg;gif=gif;png=png" );
// =============================================================================
// == Public Functions ==
// =============================================================================
/**
* Gets Export data from FCExporter - main module and build the export binary/objct.
* @param $stream (string) export image data in FusionCharts compressed format
* $meta {array) Image meta data in keys "width", "heigth" and "bgColor"
* $exportParams {array} Export related parameters
* @return image object/binary
*/
function exportProcessor( $stream, $meta, $exportParams )
{
// create a new export object
// here it is an image generator class that handles jpg, png, gif export
// pass all reqiured parameters
$FCExporter = new FCIMGGenerator ( $stream, $meta['width'], $meta['height'], $meta['bgColor'] );
// return export ready image object
return $FCExporter->getImageObject();
}
/**
* exports (save/download) FusinoCharts exported image.
* @param $exportObj (mixed) binary/objct exported by exportProcessor
* @param $exportSettings (array) various server-side export settings stored in keys like
* "type", "ready" "filepath" etc. Required for 'save' expotAction.
* For 'download' action "filepath" is blank (this is checked to find
* whether the action is "download" or not.
* @param $quality (integer) quality factor 0-1 (1 being the best quality). As of now we always pass 1.
*
* @return false is fails. {filepath} if succeeds. Only returned when action is 'save'.
*/
function exportOutput ( $exportObj, $exportSettings , $quality = 1 )
{
// decides image encoding and saving php(GD) function as per export type
switch( strtolower( $exportSettings['type' ]) )
{
// in case of PNG check if 'imagepng' function exists.
// save the image as png
// store saving status in $doneExport which receives false if fails and true on success
case "png" :
if( function_exists ( "imagepng" ) ) {
$doneExport = imagepng ( $exportObj, @$exportSettings ['filepath' ], $quality*9 );
}
break;
// in case of GIF check if 'imagegif' function exists.
// save the image as gif
// store saving status in $doneExport which receives false if fails and true on success
case "gif" :
if( function_exists ( "imagegif" ) ) {
// This is done as a fix to some PHP versions running on IIS
if( trim(@$exportSettings ['filepath']) )
$doneExport = imagegif ( $exportObj, @$exportSettings ['filepath'] );
else
$doneExport = imagegif ( $exportObj );
}
break;
// in case of JPG/JPEG check if 'imagejpeg' function exists.
// save the image as jpg
// store saving status in $doneExport which receives false if fails and true on success
case "jpg" :
case "jpeg":
if( function_exists ( "imagejpeg" ) ) {
$doneExport = imagejpeg ( $exportObj, @$exportSettings ['filepath' ], $quality*100 );
}
break;
default :
raise_error( "Invalid Export Format." , true);
break;
}
// clear memory after saving
imagedestroy( $exportObj );
// check 'filepath'. If it is null - the action is 'download' and hence terminate execution
if ( !@$exportSettings [ 'filepath' ] ) exit();
// check $doneEport and if true sets status to {filepath}'s value
// set false if fails
$status =( @$doneExport ? basename ( @$exportSettings ['filepath'] ) : false );
// return status
return $status;
}
#################################################################################
## ##
## EXPORT CLASS ##
## ##
#################################################################################
class FCIMGGenerator
{
//Array - Stores multiple chart export data
var $arrExportData;
//stores number of pages = length of $arrExportData array
var $numPages=0;
//Constructor - By default the chart export data can be passed to this
function FCIMGGenerator($imageData_FCFormat="", $width="", $height="", $bgcolor="ffffff"){
if($imageData_FCFormat && $width && $height){
$this->setBitmapData($imageData_FCFormat, $width, $height, $bgcolor);
}
}
// Add chart export data
function setBitmapData($imageData_FCFormat, $width, $height, $bgcolor="ffffff"){
$this->arrExportData[$this->numPages]["width"]=$width;
$this->arrExportData[$this->numPages]["height"]=$height;
$this->arrExportData[$this->numPages]["bgcolor"]=$bgcolor;
$this->arrExportData[$this->numPages]["imageData"]=$imageData_FCFormat;
$this->numPages++;
}
function getImageObject($id=0){
//create image
$image = imagecreatetruecolor($this->arrExportData[$id]["width"], $this->arrExportData[$id]["height"]);
// Detect the background color
if (!$this->arrExportData[$id]["bgcolor"]){
$this->arrExportData[$id]["bgcolor"] = "ffffff";
}
//set Background color
// Some linux distro have issues with imagefill
// Hence, using imagefilledrectangle() instead
//imagefill($image, 0, 0, $this->composeColor($image,$this->arrExportData[$id]["bgcolor"]));
imagefilledrectangle($image, 0, 0,($this->arrExportData[$id]["width"]+0)-1, ($this->arrExportData[$id]["height"]+0)-1,$this->composeColor($image,$this->arrExportData[$id]["bgcolor"]));
// Split the data into rows using ; as separator
$rows = explode(";", $this->arrExportData[$id]["imageData"]);
// Iterate through all the rows
for($i= 0; $i<count($rows); $i++){
$x=0;
// Parse all the pixels in this row
$pixels = explode(",", $rows[$i]);
// Iterate through the pixels
for($j=0; $j<count($pixels); $j++){
// Split the pixel into color and repeat value
$thispix = explode("_", $pixels[$j]);
// Reference to color
$c = $thispix[0];
// Reference to repeat factor
$r = (int)$thispix[1];
//If color is empty (i.e., background pixel) skip
if ($c==""){
$x+=$r;
continue;
//$c=$this->arrExportData[$id]["bgcolor"];
}
// get color
$color=$this->composeColor($image,$c);
//draw line
imageline($image, $x, $i, ($x+$r)-1, $i, $color);
//set next x pixel position
$x+=$r;
}
}
return $image;
}
// build color object for GD image object
// Parsee 6 Byte Hex Color string to 3 Byte RGB color
function composeColor($imgObj,$strHexColor){
if (strlen($strHexColor)<6){
//If the hexadecimal code is less than 6 characters, pad with 0
$strHexColor = str_pad($strHexColor, 6, '0', STR_PAD_LEFT);
}
//Convert value from HEX to RRGGBB (3 bytes)
$rr = hexdec(substr($strHexColor, 0, 2));
$gg = hexdec(substr($strHexColor, 2, 2));
$bb = hexdec(substr($strHexColor, 4, 2));
// Allocate the color
return imagecolorallocate($imgObj, $rr, $gg, $bb);
}
}
//needed to validate inclusion of this resource file in main file - FCExporter.php
return 'true';
?>

View File

@@ -0,0 +1,421 @@
<?php
/**
*
* FusionCharts Exporter - 'PDF Resource' handles
* FusionCharts (since v3.1) Server Side Export feature that
* helps FusionCharts exported as PDF file.
*
*
* @author FusionCharts
* @description FusionCharts Exporter (Server-Side - PHP)
* @version 2.0 [ 12 February 2009 ]
*
*/
/**
* ChangeLog / Version History:
* ----------------------------
*
* 1.1 [ 13 March 2009 ]
* Fixed PDF Image data Compressor
*
*
*
* 1.0 [ 12 February 2009 ]
*
* FEATURES:
* - Integrated with new Export feature of FusionCharts 3.1 & FusionCharts Exporter v 2.0
* - can save to server side directory
* - can provide download or open in browser window/frame other than _self
* - can save single or multiple page PDF
*
* ISSUES:
* - best viewed in 72 DPI
* - Each page is of the same pixel size that of the chart
* - no page margin or gutter as of now
* - no custom text or other PDF elements can be incorporated
*
*/
/**
* Copyright (c) 2016 Infosoft Global Private Limited
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* GENERAL NOTES
* -------------
*
* Chart would POST export data (which consists of encoded image data stream,
* width, height, background color and various other export parameters like
* exportFormat, exportFileName, exportAction, exportTargetWindow) to this script.
*
* The script would process this data using appropriate resource files build
* export binary (PDF/image)
*
* It either saves the binary as file to a server side directory or push it as
* Download or open in a new browser window/frame.
*
*
* ISSUES
* ------
* Q> What if someone wishes to open in the same page where the chart existed as postback
* replacing the old page?
*
* A> Not directly supported using any chart attribute or parameter but can do by
* removing/commenting the line containing 'header( content-disposition ...'
*
*/
/**
* @requires FCExporter.php A file that includes this resource
*
*
* Details
* -------
*
* The resource files would have these things as common:
*
* a) a constant - MIMETYPES that would have a string
* containing semicolon separated key value pairs.
* Each key can be a format name specified in the
* HANDLERASSOCIATIONS constant. The associated value
* would be the mimetype for the specified format.
*
* e.g. define("MIMETYPES","jpg=image/jpeg;jpeg=image/jpeg;png=image/png;gif=image/gif");
*
*
* b) a constant - EXTENSIONS that again contain a string of
* semicolon separated key value pair. Each key would again be the
* format name and the extension would be the file extension.
*
* e.g. define("EXTENSIONS","jpg=jpg;jpeg=jpg;png=png;gif=gif");
*
*
* c) a function - exportProcessor ( $stream , $meta )
* It would take the FusionCharts exncoded image string as $stream &
* an associative array $meta containging width, height and bgColor keys.
*
* The function would return an object of mixed type which would contain
* the processed binary/relevant export object.
*
*
* d) a function - exportOutput ( $exportObj, $exportSettings, $quality=1 )
* It would take the processed export object and other export setting as parameter.
* Moreover, it would take an optional parameter - $quality (in scale of 0 to 1).
* By Default, the $quality is passed as 1 (best quality)
*
* The function would return the file path on success or return false on failure.
*
* [ The other code in the resource file can be anything that support this architecture ]
*
*/
// =============================================================================
// == Constants and Variables ==
// =============================================================================
// ==============================================================================
// Users are recommended NOT to perform any editing beyond this point. ==
// ==============================================================================
/* ------------------------- EXPORT RESOURCES -------------------------------- */
// This constant lists the mime types related to each export format this resource handles
// The value is semicolon separated key value pair for each format
// Each key is the format and value is the mime type
define( "MIMETYPES" , "pdf=application/pdf" );
// This constant lists all the file extensions for the export formats
// The value is semicolon separated key value pair for each format
// Each key is the format and value is the file extension
define( "EXTENSIONS", "pdf=pdf" );
// =============================================================================
// == Public Functions ==
// =============================================================================
/**
* Gets Export data from FCExporter - main module and build the export binary/objct.
* @param $stream (string) export image data in FusionCharts compressed format
* $meta {array) Image meta data in keys "width", "heigth" and "bgColor"
* $exportParams {array} Export related parameters
* @return image object/binary
*/
function exportProcessor( $stream , $meta, $exportParams )
{
// create a new export object
// here it is an PDF generator class
// pass all reqiured parameters
$FCExporter = new FCPDFGenerator ( $stream, $meta ['width' ], $meta ['height' ], $meta ['bgColor' ] );
// return export ready PDF binary data
return $FCExporter->getPDFObjects();
}
/**
* exports (save/download) FusinoCharts exported PDF.
* @param $exportObj (mixed) binary/objct exported by exportProcessor
* @param $exportSettings (array) various server-side export settings stored in keys like
* "type", "ready" "filepath" etc. Required for 'save' expotAction.
* For 'download' action "filepath" is blank (this is checked to find
* whether the action is "download" or not.
* @param $quality (integer) quality factor 0-1 (1 being the best quality). As of now we always pass 1.
*
* @return false is fails. {filepath} if succeeds. Only returned when action is 'save'.
*/
function exportOutput ( $exportObj, $exportSettings, $quality = 1 )
{
// calls imagepdf function that saves/downloads PDF binary
// store saving status in $doneExport which receives false if fails and true on success
$doneExport = imagepdf ( $exportObj, @$exportSettings ['filepath'] );
// check $doneEport and if true sets status to {filepath}'s value
// set false if fails
$status =( $doneExport ? basename ( @$exportSettings ['filepath'] ) : false );
// return status
return $status;
}
/**
* emulates imagepng/imagegif/imagejpeg. It saves PDF data to server or to sets to download as per
* the exportAction. exportAction is 'download' when {filepath} is null.
* @param $exportObj (string) PDF binary exported by exportProcessor
* @param $filepath (string) Path where the exported PDF is to be stored
* when the action is "download" it is null.
*
* @return (boolean) false is fails. true if succeeds. Only returned when action is 'save'.
*/
function imagepdf ( $exportObject , $filepath )
{
// when filepath is null the action is 'download'
// hence write the PDF bimary yo response stream and immediately terminate/close/end stream
// to prevent any garbage that might get into response and corrupt the PDF binary
if ( !@$filepath ) die ( $exportObject );
// open file path in write mode
$fp = @fopen ( $filepath , "w" );
if( $fp )
{
// write PDF binary
$status = @fwrite( $fp , $exportObject );
//close file
$fc = @fclose( $fp );
}
// return status
return ( bool ) @$status;
}
#################################################################################
## ##
## EXPORT CLASS ##
## ##
#################################################################################
class FCPDFGenerator
{
//Array - Stores multiple chart export data
var $arrExportData;
//stores number of pages = length of $arrExportData array
var $numPages=0;
//Constructor - By default the chart-export-data can be passed to this
function FCPDFGenerator($imageData_FCFormat="", $width="", $height="", $bgcolor="ffffff"){
if($imageData_FCFormat && $width && $height){
$this->setBitmapData($imageData_FCFormat, $width, $height, $bgcolor);
}
}
// Add chart export data
function setBitmapData($imageData_FCFormat, $width, $height, $bgcolor="ffffff"){
$this->arrExportData[$this->numPages]["width"]=$width;
$this->arrExportData[$this->numPages]["height"]=$height;
$this->arrExportData[$this->numPages]["bgcolor"]=$bgcolor;
$this->arrExportData[$this->numPages]["imageData"]=$imageData_FCFormat;
$this->numPages++;
}
//create image PDF object containing the chart image
function addImageToPDF($id=0,$isCompressed=true){
//PDF Object number
$imgObjNo = 6 + $id*3;
//Get chart Image binary
$baImg=$this->getBitmapData24($id);
//Compress image binary
$imgBinary = $isCompressed?gzcompress($baImg, 9):$baImg;
//get the lenght of the image binary
$len=strlen($imgBinary);
//Build PDF object containing the image binary and other formats required
$imgObj=$imgObjNo." 0 obj\n<<\n/Subtype /Image /ColorSpace /DeviceRGB /BitsPerComponent 8 /HDPI 72 /VDPI 72 ".($isCompressed?"/Filter /FlateDecode ":"")."/Width ".$this->arrExportData[$id]["width"]." /Height ".$this->arrExportData[$id]["height"]." /Length ".$len." >>\nstream\n".$imgBinary."endstream\nendobj\n";
return $imgObj;
}
//Main PDF builder function
function getPDFObjects($isCompressed=true) {
$PDFBytes="";
//Store all PDF objects in this temporary string to be written to ByteArray
$strTmpObj="";
//start xref array
$xRefList[0]="xref\n0 ";
$xRefList[1]="0000000000 65535 f \n"; //Address Refenrece to obj 0
//Build PDF objects sequentially
//version and header
$strTmpObj="%PDF-1.3\n%{FC}\n";
$PDFBytes.=$strTmpObj;
//OBJECT 1 : info (optional)
$strTmpObj="1 0 obj<<\n/Author (FusionCharts)\n/Title (FusionCharts)\n/Creator (FusionCharts)\n>>\nendobj\n";
$xRefList[]=$this->calculateXPos(strlen($PDFBytes)); //refenrece to obj 1
$PDFBytes.=$strTmpObj;
//OBJECT 2 : Starts with Pages Catalogue
$strTmpObj="2 0 obj\n<< /Type /Catalog /Pages 3 0 R >>\nendobj\n";
$xRefList[]=$this->calculateXPos(strlen($PDFBytes)); //refenrece to obj 2
$PDFBytes.=$strTmpObj;
//OBJECT 3 : Page Tree (reference to pages of the catalogue)
$strTmpObj="3 0 obj\n<< /Type /Pages /Kids [";
for($i=0;$i<$this->numPages;$i++){
$strTmpObj.=((($i+1)*3)+1)." 0 R\n";
}
$strTmpObj.="] /Count ".$this->numPages." >>\nendobj\n";
$xRefList[]=$this->calculateXPos(strlen($PDFBytes)); //refenrece to obj 3
$PDFBytes.=$strTmpObj;
//Each image page
for($itr=0;$itr<$this->numPages;$itr++){
$iWidth=$this->arrExportData[$itr]["width"];
$iHeight=$this->arrExportData[$itr]["height"];
//OBJECT 4..7..10..n : Page config
$strTmpObj=((($itr+2)*3)-2)." 0 obj\n<<\n/Type /Page /Parent 3 0 R \n/MediaBox [ 0 0 ".$iWidth." ".$iHeight." ]\n/Resources <<\n/ProcSet [ /PDF ]\n/XObject <</R".($itr+1)." ".(($itr+2)*3)." 0 R>>\n>>\n/Contents [ ".((($itr+2)*3)-1)." 0 R ]\n>>\nendobj\n";
$xRefList[]=$this->calculateXPos(strlen($PDFBytes)); //refenrece to obj 4,7,10,13,16...
$PDFBytes.=$strTmpObj;
//OBJECT 5...8...11...n : Page resource object (xobject resource that transforms the image)
$xRefList[]=$this->calculateXPos(strlen($PDFBytes)); //refenrece to obj 5,8,11,14,17...
$PDFBytes.=$this->getXObjResource($itr);
//OBJECT 6...9...12...n : Binary xobject of the page (image)
$imgBA=$this->addImageToPDF($itr,$isCompressed);
$xRefList[]=$this->calculateXPos(strlen($PDFBytes));//refenrece to obj 6,9,12,15,18...
$PDFBytes.=$imgBA;
}
//xrefs compilation
$xRefList[0].=(count($xRefList)-1)."\n";
//get trailer
$trailer=$this->getTrailer(strlen($PDFBytes) ,count($xRefList)-1);
//write xref and trailer to PDF
$PDFBytes.=implode("",$xRefList);
$PDFBytes.=$trailer;
//write EOF
$PDFBytes.="%%EOF\n";
return $PDFBytes;
}
//Build Image resource object that transforms the image from First Quadrant system to Second Quadrant system
function getXObjResource($itr=0) {
return ((($itr+2)*3)-1)." 0 obj\n<< /Length ".(24+strlen($this->arrExportData[$itr]["width"].$this->arrExportData[$itr]["height"]))." >>\nstream\nq\n".$this->arrExportData[$itr]["width"]." 0 0 ".$this->arrExportData[$itr]["height"]." 0 0 cm\n/R".($itr+1)." Do\nQ\nendstream\nendobj\n";
}
// Calculate the XREF position of eah PDF Object
function calculateXPos($posn){
return (str_pad($posn, 10, '0', STR_PAD_LEFT))." 00000 n \n";
}
// Calculate and build Trailer of PDF
function getTrailer($xrefpos,$numxref=7) {
return "trailer\n<<\n/Size ".$numxref."\n/Root 2 0 R\n/Info 1 0 R\n>>\nstartxref\n".$xrefpos."\n";
}
// Parse Chart Image data in to PDF Ready Image Data
function getBitmapData24($id=0){
$imageData24="";
// Split the data into rows using ; as separator
$rows = explode(";", $this->arrExportData[$id]["imageData"]);
// Detect the background color
if (!($this->arrExportData[$id]["bgcolor"])){
$this->arrExportData[$id]["bgcolor"] = "ffffff";
}
// Iterate through all the rows
for($i= 0; $i<count($rows); $i++){
// Parse all the pixels in this row
$pixels = explode(",", $rows[$i]);
// Iterate through the pixels
for($j=0; $j<count($pixels); $j++){
// Split the pixel into color and repeat value
$thispix = explode("_", $pixels[$j]);
// Reference to color
$c = $thispix[0];
// Reference to repeat factor
$r = ( int ) $thispix[1];
//If color is not empty (i.e., not background pixel)
if ($c==""){
$c=$this->arrExportData[$id]["bgcolor"];
}
if (strlen($c)<6){
//If the hexadecimal code is less than 6 characters, pad with 0
$c = str_pad($c, 6, '0', STR_PAD_LEFT);
}
$rgb = pack("CCC",hexdec(substr($c, 0, 2)),hexdec(substr($c, 2, 2)),hexdec(substr($c, 4, 2)));
$strPixelRGB_hex=str_repeat(($rgb),$r);
// Set the pixel
$imageData24.= $strPixelRGB_hex;
}
}
return $imageData24;
}
}
return 'true';
?>

View File

@@ -0,0 +1,381 @@
<?php
/**
*
* FusionCharts Exporter - 'SVG Conversion Resource' handles
* FusionCharts (since XTT) Server Side Export feature that
* helps FusionCharts JavaScript charts to get exported.
*
*
* @author FusionCharts
* @description FusionCharts Exporter (Server-Side - PHP)
* @version 0.0.0.1 [ 32 December 2012 ]
*
*/
/**
* ChangeLog / Version History:
* ----------------------------
*
*
* 1.0.0.0 [ 31 December 2012 ]
*
*
* FEATURES:
* - Integrated with new Export feature of FusionCharts XT & FusionCharts Exporter v 2.0
* - can save to server side directory
* - can provide download or open in browser window/frame other than _self
*
* ISSUES:
*
*
*
*
*
*/
/**
* Copyright (c) 2016 Infosoft Global Private Limited
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* GENERAL NOTES
* -------------
*
* Chart would POST export data (which consists of encoded image data stream,
* width, height, background color and various other export parameters like
* exportFormat, exportFileName, exportAction, exportTargetWindow) to this script.
*
* The script would process this data using appropriate resource files build
* export binary (PDF/image)
*
* It either saves the binary as file to a server side directory or push it as
* Download or open in a new browser window/frame.
*
*
*/
/**
* @requires index.php A file that includes this resource
* Java 1.3+ & Apache Batik rasterizer class: Export JavaScript charts
* (http://xmlgraphics.apache.org/batik/)
*
*
* Details
* -------
*
* The resource files would have these things as common:
*
* a) a constant - MIMETYPES that would have a string
* containing semicolon separated key value pairs.
* Each key can be a format name specified in the
* HANDLERASSOCIATIONS constant. The associated value
* would be the mimetype for the specified format.
*
* e.g. define("MIMETYPES","jpg=image/jpeg;jpeg=image/jpeg;png=image/png;gif=image/gif");
*
*
* b) a constant - EXTENSIONS that again contain a string of
* semicolon separated key value pair. Each key would again be the
* format name and the extension would be the file extension.
*
* e.g. define("EXTENSIONS","jpg=jpg;jpeg=jpg;png=png;gif=gif");
*
*
* c) a function - exportProcessor ( $stream , $meta )
* It would take the FusionCharts exncoded image string as $stream &
* an associative array $meta containging width, height and bgColor keys.
*
* The function would return an object of mixed type which would contain
* the processed binary/relevant export object.
*
*
* d) a function - exportOutput ( $exportObj, $exportSettings, $quality=1 )
* It would take the processed export object and other export setting as parameter.
* Moreover, it would take an optional parameter - $quality (in scale of 0 to 1).
* By Default, the $quality is passed as 1 (best quality)
*
* The function would return the file path on success or return false on failure.
*
* [ The other code in the resource file can be anything that support this architecture ]
*
*/
// =============================================================================
// == Constants and Variables ==
// =============================================================================
// ==============================================================================
// Users are recommended NOT to perform any editing beyond this point. ==
// ==============================================================================
ini_set('magic_quotes_gpc', 'off');
/* ------------------------- EXPORT RESOURCES -------------------------------- */
// This constant lists the mime types related to each export format this resource handles
// The value is semicolon separated key value pair for each format
// Each key is the format and value is the mime type
define("MIMETYPES", "jpg=image/jpeg;jpeg=image/jpeg;gif=image/gif;png=image/png;pdf=application/pdf;svg=image/svg+xml");
// This constant lists all the file extensions for the export formats
// The value is semicolon separated key value pair for each format
// Each key is the format and value is the file extension
define("EXTENSIONS", "jpg=jpg;jpeg=jpg;gif=gif;png=png;pdf=pdf;svg=svg");
define('TEMP_PATH', 'temp/');
define('BATIK_PATH', 'batik/batik-rasterizer.jar');
define('INKSCAPE_PATH', '/usr/bin/inkscape');
define('CONVERT_PATH', '/usr/bin/convert'); // imagemagic
// =============================================================================
// == Public Functions ==
// =============================================================================
class stitchImageCallback {
private $imageData;
function __construct($imageData) {
$this->imageData = $imageData;
}
public function callback($matches) {
$imageRet = '';
$imageName = explode('/', $matches['2']);
$imageName = array_pop($imageName);
foreach ($this->imageData as $key => $value) {
if ($value->name .'.'.$value->type == $imageName) {
$imageRet = $value->encodedData;
}
}
if ($imageRet == '') {
return '';
}
return $matches[1] . $imageRet;
}
}
/**
* The function is use to stitch the image to the SVG when downloaded as SVG
* @param [string] $svg [SVG with image link]
* @param [array] $imageData [Image datauri array]
* @return [string] [SVG with imageDatauri]
*/
function stitchImageToSvg ($svg, $imageData) {
if($imageData != null) {
$imageData = json_decode($imageData);
$callback = new stitchImageCallback($imageData);
return preg_replace_callback("/(<image[^>]*xlink:href *= *[\"']?)([^\"']*)/i", array($callback, 'callback'), $svg);
} else {
return $svg;
}
}
/**
* Gets Export data from FCExporter - main module and build the export binary/objct.
* @param $stream (string) export image data in FusionCharts compressed format
* $meta {array) Image meta data in keys "width", "heigth" and "bgColor"
* $exportParams {array} Export related parameters
* @return image object/binary
*/
function exportProcessor($stream, $meta, $exportParams, $imageData=null) {
// get mime type list parsing MIMETYPES constant declared in Export Resource PHP file
$ext = strtolower($exportParams["exportformat"]);
$ext2 = '';
$mimeList = bang(@MIMETYPES);
$mimeType = $mimeList[$ext];
// prepare variables
if (get_magic_quotes_gpc()) {
$stream = stripslashes($stream);
}
// create a new export data
$tempFileName = md5(rand());
if ('jpeg' == $ext || 'jpg' == $ext) {
$ext = 'png';
$ext2 = 'jpg';
}
$tempInputSVGFile = realpath(TEMP_PATH) . "/{$tempFileName}.svg";
$tempOutputFile = realpath(TEMP_PATH) . "/{$tempFileName}.{$ext}";
$tempOutputJpgFile = realpath(TEMP_PATH) . "/{$tempFileName}.jpg";
$tempOutputPngFile = realpath(TEMP_PATH) . "/{$tempFileName}.png";
if ($ext != 'svg') {
// width format for batik
$width = @$meta['width'];
$height = @$meta['height'];
$size = '';
if (!empty($width) && !empty($height)) {
$size = "-w {$width} -h {$height}";
}
// override the size in case of pdf output
if ('pdf' == $ext) {
$size = '';
}
//batik bg color format
$bg = @$meta['bgColor'];
if ($bg) {
$bg = " --export-background=".$bg;
}
// generate the temporary file
if (!file_put_contents($tempInputSVGFile, $stream)) {
die("Couldn't create temporary file. Check that the directory permissions for
the " . TEMP_PATH . " directory are set to 777.");
}
// do the conversion
//$command = "java -jar ". BATIK_PATH ." -m $mimeType $width $bg $tempInputSVGFile";
$command = INKSCAPE_PATH . "$bg --without-gui {$tempInputSVGFile} --export-{$ext} $tempOutputFile {$size}";
//echo $command;exit;
$output = shell_exec($command);
if ('jpg' == $ext2) {
$comandJpg = CONVERT_PATH . " -quality 100 $tempOutputFile $tempOutputJpgFile";
$tempOutputFile = $tempOutputJpgFile;
$output .= shell_exec($comandJpg);
}
// catch error
if (!is_file($tempOutputFile) || filesize($tempOutputFile) < 10) {
$return_binary = $output;
raise_error($output, true);
}
// stream it
else {
$return_binary = file_get_contents($tempOutputFile);
}
// delete temp internal image files if exist
$imageData = json_decode($imageData);
if ($imageData) {
foreach ($imageData as $key => $value) {
$tempInternalImage = realpath(TEMP_PATH) . "/{$value->name}.{$value->type}";
if (file_exists($tempInternalImage)) {
unlink($tempInternalImage);
}
}
}
// delete temp files
if (file_exists($tempInputSVGFile)) {
unlink($tempInputSVGFile);
}
if (file_exists($tempOutputFile)) {
unlink($tempOutputFile);
}
if (file_exists($tempOutputPngFile)) {
unlink($tempOutputPngFile);
}
// SVG can be streamed back directly
} else if ($ext == 'svg') {
$stream = stitchImageToSvg($stream, $imageData);
$return_binary = $stream;
} else {
raise_error("Invalid Export Format.", true);
}
// return export ready binary data
return @$return_binary;
}
/**
* exports (save/download) SVG to export formats.
* @param $exportObj (mixed) binary/objct exported by exportProcessor
* @param $exportSettings (array) various server-side export settings stored in keys like
* "type", "ready" "filepath" etc. Required for 'save' expotAction.
* For 'download' action "filepath" is blank (this is checked to find
* whether the action is "download" or not.
* @param $quality (integer) quality factor 0-1 (1 being the best quality). As of now we always pass 1.
*
* @return false is fails. {filepath} if succeeds. Only returned when action is 'save'.
*/
function exportOutput($exportObj, $exportSettings, $quality = 1) {
// calls svgparser function that saves/downloads binary
// store saving status in $doneExport which receives false if fails and true on success
$doneExport = filesaver($exportObj, @$exportSettings ['filepath']);
// check $doneExport and if true sets status to {filepath}'s value
// set false if fails
$status = ( $doneExport ? basename(@$exportSettings ['filepath']) : false );
// return status
return $status;
}
/**
* emulates imagepng/imagegif/imagejpeg. It saves data to server
* @param $exportObj (resource) binary exported by exportProcessor
* @param $filepath (string) Path where the exported is to be stored
* when the action is "download" it is null.
*
* @return (boolean) false is fails. true if succeeds. Only returned when action is 'save'.
*/
function filesaver($exportObject, $filepath) {
// when filepath is null the action is 'download'
// hence write the bimary to response stream and immediately terminate/close/end stream
// to prevent any garbage that might get into response and corrupt the binary
if (!@$filepath)
die($exportObject);
// open file path in write mode
$fp = @fopen($filepath, "w");
if ($fp) {
// write binary
$status = @fwrite($fp, $exportObject);
//close file
$fc = @fclose($fp);
}
// return status
return (bool) @$status;
}
/**
* Converts Hex color values to rgb
*
* @param string $h Hex values
* @param string $sep rgb value separator
* @return string
*/
function hex2rgb($h, $sep = "") {
$h = str_replace("#", "", $h);
if (strlen($h) == 3) {
$r = hexdec(substr($h, 0, 1) . substr($h, 0, 1));
$g = hexdec(substr($h, 1, 1) . substr($h, 1, 1));
$b = hexdec(substr($h, 2, 1) . substr($h, 2, 1));
} else {
$r = hexdec(substr($h, 0, 2));
$g = hexdec(substr($h, 2, 2));
$b = hexdec(substr($h, 4, 2));
}
$rgb = array($r, $g, $b);
if ($sep) {
$rgb = implode($sep, $rgb);
}
return $rgb;
}
return 'true';