Example #1
0
function isImgCached($file)
{
    if (!USE_CACHE) {
        return false;
    }
    if ($file == 'auto') {
        $file = GenImgName();
        // imported from jpgraph.php
    }
    $filename = catfile(CACHE_DIR, $file);
    if (file_exists($filename)) {
        if (CACHE_TIMEOUT == 0) {
            return true;
        }
        $diff = time() - filemtime($filename);
        return $diff < CACHE_TIMEOUT * 60;
    }
    return false;
}
Example #2
0
 function PutAndStream(&$aImage, $aCacheFileName, $aInline, $aStrokeFileName)
 {
     // Some debugging code to brand the image with numbe of colors
     // used
     global $gJpgBrandTiming;
     if ($gJpgBrandTiming) {
         global $tim;
         $t = $tim->Pop() / 1000.0;
         $c = $aImage->SetColor("black");
         $t = sprintf(BRAND_TIME_FORMAT, round($t, 3));
         imagestring($this->img->img, 2, 5, $this->img->height - 20, $t, $c);
     }
     // Check if we should stroke the image to an arbitrary file
     if (_FORCE_IMGTOFILE) {
         $aStrokeFileName = _FORCE_IMGDIR . GenImgName();
     }
     if ($aStrokeFileName != "") {
         if ($aStrokeFileName == "auto") {
             $aStrokeFileName = GenImgName();
         }
         if (file_exists($aStrokeFileName)) {
             // Delete the old file
             if (!@unlink($aStrokeFileName)) {
                 JpGraphError::Raise(" Can't delete cached image {$aStrokeFileName}. Permission problem?");
             }
         }
         $aImage->Stream($aStrokeFileName);
         return;
     }
     if ($aCacheFileName != "" && USE_CACHE) {
         $aCacheFileName = $this->cache_dir . $aCacheFileName;
         if (file_exists($aCacheFileName)) {
             if (!$aInline) {
                 // If we are generating image off-line (just writing to the cache)
                 // and the file exists and is still valid (no timeout)
                 // then do nothing, just return.
                 $diff = time() - filemtime($aCacheFileName);
                 if ($diff < 0) {
                     JpGraphError::Raise(" Cached imagefile ({$aCacheFileName}) has file date in the future!!");
                 }
                 if ($this->timeout > 0 && $diff <= $this->timeout * 60) {
                     return;
                 }
             }
             if (!@unlink($aCacheFileName)) {
                 JpGraphError::Raise(" Can't delete cached image {$aStrokeFileName}. Permission problem?");
             }
             $aImage->Stream($aCacheFileName);
         } else {
             $this->MakeDirs(dirname($aCacheFileName));
             if (!is_writeable(dirname($aCacheFileName))) {
                 JpGraphError::Raise('PHP has not enough permissions to write to the cache file ' . $aCacheFileName . '. Please make sure that the user running PHP has write permission for this file if you wan to use the cache system with JpGraph.');
             }
             $aImage->Stream($aCacheFileName);
         }
         $res = true;
         // Set group to specified
         if (CACHE_FILE_GROUP != "") {
             $res = @chgrp($aCacheFileName, CACHE_FILE_GROUP);
         }
         if (CACHE_FILE_MOD != "") {
             $res = @chmod($aCacheFileName, CACHE_FILE_MOD);
         }
         if (!$res) {
             JpGraphError::Raise(" Can't set permission for cached image {$aStrokeFileName}. Permission problem?");
         }
         $aImage->Destroy();
         if ($aInline) {
             if ($fh = @fopen($aCacheFileName, "rb")) {
                 $this->img->Headers();
                 fpassthru($fh);
                 return;
             } else {
                 JpGraphError::Raise(" Cant open file from cache [{$aFile}]");
             }
         }
     } elseif ($aInline) {
         $this->img->Headers();
         $aImage->Stream();
         return;
     }
 }
Example #3
0
 function __construct($aWidth = 300, $aHeight = 200, $aCachedName = '', $aTimeout = 0, $aInline = true)
 {
     if (!is_numeric($aWidth) || !is_numeric($aHeight)) {
         JpGraphError::RaiseL(25008);
         //('Image width/height argument in Graph::Graph() must be numeric');
     }
     // Initialize frame and margin
     $this->InitializeFrameAndMargin();
     // Automatically generate the image file name based on the name of the script that
     // generates the graph
     if ($aCachedName == 'auto') {
         $aCachedName = GenImgName();
     }
     // Should the image be streamed back to the browser or only to the cache?
     $this->inline = $aInline;
     $this->img = new RotImage($aWidth, $aHeight);
     $this->cache = new ImgStreamCache();
     // Window doesn't like '?' in the file name so replace it with an '_'
     $aCachedName = str_replace("?", "_", $aCachedName);
     $this->SetupCache($aCachedName, $aTimeout);
     $this->title = new Text();
     $this->title->ParagraphAlign('center');
     $this->title->SetFont(FF_DEFAULT, FS_NORMAL);
     //FF_FONT2, FS_BOLD
     $this->title->SetMargin(5);
     $this->title->SetAlign('center');
     $this->subtitle = new Text();
     $this->subtitle->ParagraphAlign('center');
     $this->subtitle->SetMargin(3);
     $this->subtitle->SetAlign('center');
     $this->subsubtitle = new Text();
     $this->subsubtitle->ParagraphAlign('center');
     $this->subsubtitle->SetMargin(3);
     $this->subsubtitle->SetAlign('center');
     $this->legend = new Legend();
     $this->footer = new Footer();
     // If the cached version exist just read it directly from the
     // cache, stream it back to browser and exit
     if ($aCachedName != '' && READ_CACHE && $aInline) {
         if ($this->cache->GetAndStream($this->img, $aCachedName)) {
             exit;
         }
     }
     $this->SetTickDensity();
     // Normal density
     $this->tabtitle = new GraphTabTitle();
     if (!$this->isRunningClear) {
         $this->inputValues = array();
         $this->inputValues['aWidth'] = $aWidth;
         $this->inputValues['aHeight'] = $aHeight;
         $this->inputValues['aCachedName'] = $aCachedName;
         $this->inputValues['aTimeout'] = $aTimeout;
         $this->inputValues['aInline'] = $aInline;
         $theme_class = DEFAULT_THEME_CLASS;
         if (class_exists($theme_class)) {
             $this->graph_theme = new $theme_class();
         }
     }
 }
Example #4
0
 function PutAndStream($aImage, $aCacheFileName, $aInline, $aStrokeFileName)
 {
     // Check if we should always stroke the image to a file
     if (_FORCE_IMGTOFILE) {
         $aStrokeFileName = _FORCE_IMGDIR . GenImgName();
     }
     if ($aStrokeFileName != '') {
         if ($aStrokeFileName == 'auto') {
             $aStrokeFileName = GenImgName();
         }
         if (file_exists($aStrokeFileName)) {
             // Wait for lock (to make sure no readers are trying to access the image)
             $fd = fopen($aStrokeFileName, 'w');
             $lock = flock($fd, LOCK_EX);
             // Since the image write routines only accepts a filename which must not
             // exist we need to delete the old file first
             if (!@unlink($aStrokeFileName)) {
                 $lock = flock($fd, LOCK_UN);
                 JpGraphError::RaiseL(25111, $aStrokeFileName);
                 //(" Can't delete cached image $aStrokeFileName. Permission problem?");
             }
             $aImage->Stream($aStrokeFileName);
             $lock = flock($fd, LOCK_UN);
             fclose($fd);
         } else {
             $aImage->Stream($aStrokeFileName);
         }
         return;
     }
     if ($aCacheFileName != '' && USE_CACHE) {
         $aCacheFileName = $this->cache_dir . $aCacheFileName;
         if (file_exists($aCacheFileName)) {
             if (!$aInline) {
                 // If we are generating image off-line (just writing to the cache)
                 // and the file exists and is still valid (no timeout)
                 // then do nothing, just return.
                 $diff = time() - filemtime($aCacheFileName);
                 if ($diff < 0) {
                     JpGraphError::RaiseL(25112, $aCacheFileName);
                     //(" Cached imagefile ($aCacheFileName) has file date in the future!!");
                 }
                 if ($this->timeout > 0 && $diff <= $this->timeout * 60) {
                     return;
                 }
             }
             // Wait for lock (to make sure no readers are trying to access the image)
             $fd = fopen($aCacheFileName, 'w');
             $lock = flock($fd, LOCK_EX);
             if (!@unlink($aCacheFileName)) {
                 $lock = flock($fd, LOCK_UN);
                 JpGraphError::RaiseL(25113, $aStrokeFileName);
                 //(" Can't delete cached image $aStrokeFileName. Permission problem?");
             }
             $aImage->Stream($aCacheFileName);
             $lock = flock($fd, LOCK_UN);
             fclose($fd);
         } else {
             $this->MakeDirs(dirname($aCacheFileName));
             if (!is_writeable(dirname($aCacheFileName))) {
                 JpGraphError::RaiseL(25114, $aCacheFileName);
                 //('PHP has not enough permissions to write to the cache file '.$aCacheFileName.'. Please make sure that the user running PHP has write permission for this file if you wan to use the cache system with JpGraph.');
             }
             $aImage->Stream($aCacheFileName);
         }
         $res = true;
         // Set group to specified
         if (CACHE_FILE_GROUP != '') {
             $res = @chgrp($aCacheFileName, CACHE_FILE_GROUP);
         }
         if (CACHE_FILE_MOD != '') {
             $res = @chmod($aCacheFileName, CACHE_FILE_MOD);
         }
         if (!$res) {
             JpGraphError::RaiseL(25115, $aStrokeFileName);
             //(" Can't set permission for cached image $aStrokeFileName. Permission problem?");
         }
         $aImage->Destroy();
         if ($aInline) {
             if ($fh = @fopen($aCacheFileName, "rb")) {
                 $aImage->Headers();
                 fpassthru($fh);
                 return;
             } else {
                 JpGraphError::RaiseL(25116, $aFile);
                 //(" Cant open file from cache [$aFile]");
             }
         }
     } elseif ($aInline) {
         $aImage->Headers();
         $aImage->Stream();
         return;
     }
 }
<?php

include "../jpgraph.php";
include "../jpgraph_pie.php";
// Some data
$data = array(40, 21, 17, 14, 23);
// Create the Pie Graph.
$graph = new PieGraph(300, 200);
$graph->SetShadow();
// Set A title for the plot
$graph->title->Set("Client side image map");
$graph->title->SetFont(FF_FONT1, FS_BOLD);
// Create
$p1 = new PiePlot($data);
$p1->SetLegends(array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul"));
$targ = array("pie_csimex1.php#1", "pie_csimex1.php#2", "pie_csimex1.php#3", "pie_csimex1.php#4", "pie_csimex1.php#5", "pie_csimex1.php#6");
$alts = array("val=%v", "val=%v", "val=%v", "val=%v", "val=%v", "val=%v");
$p1->SetCSIMTargets($targ, $alts);
$graph->Add($p1);
$graph->Stroke(GenImgName());
echo $graph->GetHTMLImageMap("myimagemap");
echo "<img src=\"" . GenImgName() . "\" ISMAP USEMAP=\"#myimagemap\" border=0>";
?>


Example #6
0
 function Graph($aWidth = 300, $aHeight = 200, $aCachedName = "", $aTimeOut = 0, $aInline = true)
 {
     global $gJpgBrandTiming;
     // If timing is used create a new timing object
     if ($gJpgBrandTiming) {
         global $tim;
         $tim = new JpgTimer();
         $tim->Push();
     }
     if (!is_numeric($aWidth) || !is_numeric($aHeight)) {
         JpGraphError::RaiseL(25008);
         //('Image width/height argument in Graph::Graph() must be numeric');
     }
     // Automatically generate the image file name based on the name of the script that
     // generates the graph
     if ($aCachedName == "auto") {
         $aCachedName = GenImgName();
     }
     // Should the image be streamed back to the browser or only to the cache?
     $this->inline = $aInline;
     $this->img = new RotImage($aWidth, $aHeight);
     $this->cache = new ImgStreamCache($this->img);
     $this->cache->SetTimeOut($aTimeOut);
     $this->title = new Text();
     $this->title->ParagraphAlign('center');
     $this->title->SetFont(FF_FONT2, FS_BOLD);
     $this->title->SetMargin(3);
     $this->title->SetAlign('center');
     $this->subtitle = new Text();
     $this->subtitle->ParagraphAlign('center');
     $this->subtitle->SetMargin(2);
     $this->subtitle->SetAlign('center');
     $this->subsubtitle = new Text();
     $this->subsubtitle->ParagraphAlign('center');
     $this->subsubtitle->SetMargin(2);
     $this->subsubtitle->SetAlign('center');
     $this->legend = new Legend();
     $this->footer = new Footer();
     // Window doesn't like '?' in the file name so replace it with an '_'
     $aCachedName = str_replace("?", "_", $aCachedName);
     // If the cached version exist just read it directly from the
     // cache, stream it back to browser and exit
     if ($aCachedName != "" && READ_CACHE && $aInline) {
         if ($this->cache->GetAndStream($aCachedName)) {
             exit;
         }
     }
     $this->cache_name = $aCachedName;
     $this->SetTickDensity();
     // Normal density
     $this->tabtitle = new GraphTabTitle();
 }
Example #7
0
 function PutAndStream(&$aImage, $aCacheFileName, $aInline, $aStrokeFileName)
 {
     global $gJpgBrandTiming;
     if ($gJpgBrandTiming) {
         global $tim;
         $t = $tim->Pop() / 1000.0;
         $c = $aImage->SetColor("black");
         $t = sprintf(BRAND_TIME_FORMAT, round($t, 3));
         imagestring($this->img->img, 2, 5, $this->img->height - 20, $t, $c);
     }
     if (_FORCE_IMGTOFILE) {
         $aStrokeFileName = _FORCE_IMGDIR . GenImgName();
     }
     if ($aStrokeFileName != "") {
         if ($aStrokeFileName == "auto") {
             $aStrokeFileName = GenImgName();
         }
         if (file_exists($aStrokeFileName)) {
             if (!@unlink($aStrokeFileName)) {
                 JpGraphError::RaiseL(25111, $aStrokeFileName);
             }
         }
         $aImage->Stream($aStrokeFileName);
         return;
     }
     if ($aCacheFileName != "" && USE_CACHE) {
         $aCacheFileName = $this->cache_dir . $aCacheFileName;
         if (file_exists($aCacheFileName)) {
             if (!$aInline) {
                 $diff = time() - filemtime($aCacheFileName);
                 if ($diff < 0) {
                     JpGraphError::RaiseL(25112, $aCacheFileName);
                 }
                 if ($this->timeout > 0 && $diff <= $this->timeout * 60) {
                     return;
                 }
             }
             if (!@unlink($aCacheFileName)) {
                 JpGraphError::RaiseL(25113, $aStrokeFileName);
             }
             $aImage->Stream($aCacheFileName);
         } else {
             $this->MakeDirs(dirname($aCacheFileName));
             if (!is_writeable(dirname($aCacheFileName))) {
                 JpGraphError::RaiseL(25114, $aCacheFileName);
             }
             $aImage->Stream($aCacheFileName);
         }
         $res = true;
         if (CACHE_FILE_GROUP != "") {
             $res = @chgrp($aCacheFileName, CACHE_FILE_GROUP);
         }
         if (CACHE_FILE_MOD != "") {
             $res = @chmod($aCacheFileName, CACHE_FILE_MOD);
         }
         if (!$res) {
             JpGraphError::RaiseL(25115, $aStrokeFileName);
         }
         $aImage->Destroy();
         if ($aInline) {
             if ($fh = @fopen($aCacheFileName, "rb")) {
                 $this->img->Headers();
                 fpassthru($fh);
                 return;
             } else {
                 JpGraphError::RaiseL(25116, $aFile);
             }
         }
     } elseif ($aInline) {
         $this->img->Headers();
         $aImage->Stream();
         return;
     }
 }
Example #8
0
 function Graph($aWidth = 300, $aHeight = 200, $aCachedName = "", $aTimeOut = 0, $aInline = true)
 {
     // If timing is used create a new timing object
     if (BRAND_TIMING) {
         global $tim;
         $tim = new JpgTimer();
         $tim->Push();
     }
     // Automatically generate the image file name based on the name of the script that
     // generates the graph
     if ($aCachedName == "auto") {
         $aCachedName = GenImgName();
     }
     // Should the image be streamed back to the browser or only to the cache?
     $this->inline = $aInline;
     $this->img = new RotImage($aWidth, $aHeight);
     $this->cache = new ImgStreamCache($this->img);
     $this->cache->SetTimeOut($aTimeOut);
     $this->title = new Text("");
     $this->subtitle = new Text("");
     $this->legend = new Legend();
     // If the cached version exist just read it directly from the
     // cache, stream it back to browser and exit
     if ($aCachedName != "" && READ_CACHE && $aInline) {
         if ($this->cache->GetAndStream($aCachedName)) {
             exit;
         }
     }
     $this->cache_name = $aCachedName;
     $this->SetTickDensity();
     // Normal density
 }