Make sure EOS classes don't exist before declaring
This commit is contained in:
@@ -438,167 +438,169 @@ class eqEOS {
|
|||||||
* @subpackage EOS
|
* @subpackage EOS
|
||||||
* @version 2.0
|
* @version 2.0
|
||||||
*/
|
*/
|
||||||
class eqGraph extends eqEOS {
|
if ( ! class_exists( 'eqGraph' ) ):
|
||||||
private $width;
|
class eqGraph extends eqEOS {
|
||||||
private $height;
|
private $width;
|
||||||
//GD Image reference
|
private $height;
|
||||||
private $image;
|
//GD Image reference
|
||||||
|
private $image;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* Sets up the Graph class with an image width and height defaults to
|
* Sets up the Graph class with an image width and height defaults to
|
||||||
* 640x480
|
* 640x480
|
||||||
*
|
*
|
||||||
* @param Integer $width Image width
|
* @param Integer $width Image width
|
||||||
* @param Integer $height Image height
|
* @param Integer $height Image height
|
||||||
*/
|
*/
|
||||||
public function __construct($width=640, $height=480) {
|
public function __construct($width=640, $height=480) {
|
||||||
// default width and height equal to that of a poor monitor (in early 2000s)
|
// default width and height equal to that of a poor monitor (in early 2000s)
|
||||||
$this->width = $width;
|
$this->width = $width;
|
||||||
$this->height = $height;
|
$this->height = $height;
|
||||||
//initialize main class variables
|
//initialize main class variables
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
} //end function eqGraph
|
} //end function eqGraph
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create GD Graph Image
|
* Create GD Graph Image
|
||||||
*
|
*
|
||||||
* Creates a GD image based on the equation given with the parameters that are set
|
* Creates a GD image based on the equation given with the parameters that are set
|
||||||
*
|
*
|
||||||
* @param String $eq Equation to use. Needs variable in equation to create graph, all variables are interpreted as 'x'
|
* @param String $eq Equation to use. Needs variable in equation to create graph, all variables are interpreted as 'x'
|
||||||
* @param Integer $xLow Lower x-bound for graph
|
* @param Integer $xLow Lower x-bound for graph
|
||||||
* @param Integer $xHigh Upper x-bound for graph
|
* @param Integer $xHigh Upper x-bound for graph
|
||||||
* @param Float $xStep Stepping points while solving, the lower, the better precision. Slow if lower than .01
|
* @param Float $xStep Stepping points while solving, the lower, the better precision. Slow if lower than .01
|
||||||
* @param Boolean $xyGrid Draw gridlines?
|
* @param Boolean $xyGrid Draw gridlines?
|
||||||
* @param Boolean $yGuess Guess the upper/lower yBounds?
|
* @param Boolean $yGuess Guess the upper/lower yBounds?
|
||||||
* @param Integer $yLow Lower y-bound
|
* @param Integer $yLow Lower y-bound
|
||||||
* @param Integer $yHigh Upper y-bound
|
* @param Integer $yHigh Upper y-bound
|
||||||
* @return Null
|
* @return Null
|
||||||
*/
|
*/
|
||||||
public function graph($eq, $xLow, $xHigh, $xStep, $xyGrid = false, $yGuess = true, $yLow=false, $yHigh=false) {
|
public function graph($eq, $xLow, $xHigh, $xStep, $xyGrid = false, $yGuess = true, $yLow=false, $yHigh=false) {
|
||||||
//create our image and allocate the two colors
|
//create our image and allocate the two colors
|
||||||
$img = ImageCreate($this->width, $this->height);
|
$img = ImageCreate($this->width, $this->height);
|
||||||
$white = ImageColorAllocate($img, 255, 255, 255);
|
$white = ImageColorAllocate($img, 255, 255, 255);
|
||||||
$black = ImageColorAllocate($img, 0, 0, 0);
|
$black = ImageColorAllocate($img, 0, 0, 0);
|
||||||
$grey = ImageColorAllocate($img, 220, 220, 220);
|
$grey = ImageColorAllocate($img, 220, 220, 220);
|
||||||
$xStep = abs($xStep);
|
$xStep = abs($xStep);
|
||||||
//DEVELOPER, UNCOMMENT NEXT LINE IF WANTING TO PREVENT SLOW GRAPHS
|
//DEVELOPER, UNCOMMENT NEXT LINE IF WANTING TO PREVENT SLOW GRAPHS
|
||||||
//$xStep = ($xStep > .01) ? $xStep : 0.01;
|
//$xStep = ($xStep > .01) ? $xStep : 0.01;
|
||||||
if($xLow > $xHigh)
|
if($xLow > $xHigh)
|
||||||
list($xLow, $xHigh) = array($xHigh, $xLow); //swap function
|
list($xLow, $xHigh) = array($xHigh, $xLow); //swap function
|
||||||
|
|
||||||
$xScale = $this->width/($xHigh-$xLow);
|
|
||||||
$counter = 0;
|
|
||||||
for($i=$xLow;$i<=$xHigh;$i+=$xStep) {
|
|
||||||
$tester = sprintf("%10.3f",$i);
|
|
||||||
if($tester == "-0.000") $i = 0;
|
|
||||||
$y = $this->solveIF($eq, $i);
|
|
||||||
|
|
||||||
// If developer asked us to find the upper and lower bounds for y...
|
|
||||||
if($yGuess==true) {
|
|
||||||
$yLow = ($yLow===false || ($y<$yLow)) ? $y : $yLow;
|
|
||||||
$yHigh = ($yHigh===false || $y>$yHigh) ? $y : $yHigh;
|
|
||||||
}
|
|
||||||
$xVars[$counter] = $y;
|
|
||||||
$counter++;
|
|
||||||
}
|
|
||||||
// add 0.01 to each side so that if y is from 1 to 5, the lines at 1 and 5 are seen
|
|
||||||
$yLow-=0.01;$yHigh+=0.01;
|
|
||||||
|
|
||||||
//Now that we have all the variables stored...find the yScale
|
|
||||||
$yScale = $this->height/(($yHigh)-($yLow));
|
|
||||||
|
|
||||||
// if developer wanted a grid on the graph, add it now
|
|
||||||
if($xyGrid==true) {
|
|
||||||
for($i=ceil($yLow);$i<=floor($yHigh);$i++) {
|
|
||||||
$i0 = abs($yHigh-$i);
|
|
||||||
ImageLine($img, 0, $i0*$yScale, $this->width, $i0*$yScale, $grey);
|
|
||||||
}
|
|
||||||
for($i=ceil($xLow);$i<=floor($xHigh);$i++) {
|
|
||||||
$i0 = abs($xLow-$i);
|
|
||||||
ImageLine($img, $i0*$xScale, 0, $i0*$xScale, $this->height, $grey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Now that we have the scales, let's see if we can draw an x/y-axis
|
|
||||||
if($xLow <= 0 && $xHigh >= 0) {
|
|
||||||
//the y-axis is within our range - draw it.
|
|
||||||
$x0 = abs($xLow)*$xScale;
|
|
||||||
ImageLine($img, $x0, 0, $x0, $this->height, $black);
|
|
||||||
for($i=ceil($yLow);$i<=floor($yHigh);$i++) {
|
|
||||||
$i0 = abs($yHigh-$i);
|
|
||||||
ImageLine($img, $x0-3, $i0*$yScale, $x0+3, $i0*$yScale, $black);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if($yLow <= 0 && $yHigh >= 0) {
|
|
||||||
//the x-axis is within our range - draw it.
|
|
||||||
$y0 = abs($yHigh)*$yScale;
|
|
||||||
ImageLine($img, 0, $y0, $this->width, $y0, $black);
|
|
||||||
for($i=ceil($xLow);$i<=floor($xHigh);$i++) {
|
|
||||||
$i0 = abs($xLow-$i);
|
|
||||||
ImageLine($img, $i0*$xScale, $y0-3, $i0*$xScale, $y0+3, $black);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$counter=2;
|
|
||||||
|
|
||||||
//now graph it all ;]
|
|
||||||
for($i=$xLow+$xStep;$i<=$xHigh;$i+=$xStep) {
|
|
||||||
$x1 = (abs($xLow - ($i - $xStep)))*$xScale;
|
|
||||||
$y1 = (($xVars[$counter-1]<$yLow) || ($xVars[$counter-1] > $yHigh)) ? -1 : (abs($yHigh - $xVars[$counter-1]))*$yScale;
|
|
||||||
$x2 = (abs($xLow - $i))*$xScale;
|
|
||||||
$y2 = (($xVars[$counter]<$yLow) || ($xVars[$counter] > $yHigh)) ? -1 : (abs($yHigh - $xVars[$counter]))*$yScale;
|
|
||||||
|
|
||||||
// if any of the y values were found to be off of the y-bounds, don't graph those connecting lines
|
$xScale = $this->width/($xHigh-$xLow);
|
||||||
if($y1!=-1 && $y2!=-1)
|
$counter = 0;
|
||||||
ImageLine($img, $x1, $y1, $x2, $y2, $black);
|
for($i=$xLow;$i<=$xHigh;$i+=$xStep) {
|
||||||
$counter++;
|
$tester = sprintf("%10.3f",$i);
|
||||||
|
if($tester == "-0.000") $i = 0;
|
||||||
|
$y = $this->solveIF($eq, $i);
|
||||||
|
|
||||||
|
// If developer asked us to find the upper and lower bounds for y...
|
||||||
|
if($yGuess==true) {
|
||||||
|
$yLow = ($yLow===false || ($y<$yLow)) ? $y : $yLow;
|
||||||
|
$yHigh = ($yHigh===false || $y>$yHigh) ? $y : $yHigh;
|
||||||
|
}
|
||||||
|
$xVars[$counter] = $y;
|
||||||
|
$counter++;
|
||||||
|
}
|
||||||
|
// add 0.01 to each side so that if y is from 1 to 5, the lines at 1 and 5 are seen
|
||||||
|
$yLow-=0.01;$yHigh+=0.01;
|
||||||
|
|
||||||
|
//Now that we have all the variables stored...find the yScale
|
||||||
|
$yScale = $this->height/(($yHigh)-($yLow));
|
||||||
|
|
||||||
|
// if developer wanted a grid on the graph, add it now
|
||||||
|
if($xyGrid==true) {
|
||||||
|
for($i=ceil($yLow);$i<=floor($yHigh);$i++) {
|
||||||
|
$i0 = abs($yHigh-$i);
|
||||||
|
ImageLine($img, 0, $i0*$yScale, $this->width, $i0*$yScale, $grey);
|
||||||
|
}
|
||||||
|
for($i=ceil($xLow);$i<=floor($xHigh);$i++) {
|
||||||
|
$i0 = abs($xLow-$i);
|
||||||
|
ImageLine($img, $i0*$xScale, 0, $i0*$xScale, $this->height, $grey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Now that we have the scales, let's see if we can draw an x/y-axis
|
||||||
|
if($xLow <= 0 && $xHigh >= 0) {
|
||||||
|
//the y-axis is within our range - draw it.
|
||||||
|
$x0 = abs($xLow)*$xScale;
|
||||||
|
ImageLine($img, $x0, 0, $x0, $this->height, $black);
|
||||||
|
for($i=ceil($yLow);$i<=floor($yHigh);$i++) {
|
||||||
|
$i0 = abs($yHigh-$i);
|
||||||
|
ImageLine($img, $x0-3, $i0*$yScale, $x0+3, $i0*$yScale, $black);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($yLow <= 0 && $yHigh >= 0) {
|
||||||
|
//the x-axis is within our range - draw it.
|
||||||
|
$y0 = abs($yHigh)*$yScale;
|
||||||
|
ImageLine($img, 0, $y0, $this->width, $y0, $black);
|
||||||
|
for($i=ceil($xLow);$i<=floor($xHigh);$i++) {
|
||||||
|
$i0 = abs($xLow-$i);
|
||||||
|
ImageLine($img, $i0*$xScale, $y0-3, $i0*$xScale, $y0+3, $black);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$counter=2;
|
||||||
|
|
||||||
|
//now graph it all ;]
|
||||||
|
for($i=$xLow+$xStep;$i<=$xHigh;$i+=$xStep) {
|
||||||
|
$x1 = (abs($xLow - ($i - $xStep)))*$xScale;
|
||||||
|
$y1 = (($xVars[$counter-1]<$yLow) || ($xVars[$counter-1] > $yHigh)) ? -1 : (abs($yHigh - $xVars[$counter-1]))*$yScale;
|
||||||
|
$x2 = (abs($xLow - $i))*$xScale;
|
||||||
|
$y2 = (($xVars[$counter]<$yLow) || ($xVars[$counter] > $yHigh)) ? -1 : (abs($yHigh - $xVars[$counter]))*$yScale;
|
||||||
|
|
||||||
|
// if any of the y values were found to be off of the y-bounds, don't graph those connecting lines
|
||||||
|
if($y1!=-1 && $y2!=-1)
|
||||||
|
ImageLine($img, $x1, $y1, $x2, $y2, $black);
|
||||||
|
$counter++;
|
||||||
|
}
|
||||||
|
$this->image = $img;
|
||||||
|
} //end function 'graph'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends JPG to browser
|
||||||
|
*
|
||||||
|
* Sends a JPG image with proper header to output
|
||||||
|
*/
|
||||||
|
public function outJPG() {
|
||||||
|
header("Content-type: image/jpeg");
|
||||||
|
ImageJpeg($this->image);
|
||||||
}
|
}
|
||||||
$this->image = $img;
|
|
||||||
} //end function 'graph'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends JPG to browser
|
* Sends PNG to browser
|
||||||
*
|
*
|
||||||
* Sends a JPG image with proper header to output
|
* Sends a PNG image with proper header to output
|
||||||
*/
|
*/
|
||||||
public function outJPG() {
|
function outPNG() {
|
||||||
header("Content-type: image/jpeg");
|
header("Content-type: image/png");
|
||||||
ImageJpeg($this->image);
|
ImagePng($this->image);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends PNG to browser
|
* Output GD Image
|
||||||
*
|
*
|
||||||
* Sends a PNG image with proper header to output
|
* Will give the developer the GD resource for the graph that
|
||||||
*/
|
* can be used to store the graph to the FS or other media
|
||||||
function outPNG() {
|
*
|
||||||
header("Content-type: image/png");
|
* @return Resource GD Image Resource
|
||||||
ImagePng($this->image);
|
*/
|
||||||
}
|
public function getImage() {
|
||||||
|
return $this->image;
|
||||||
/**
|
}
|
||||||
* Output GD Image
|
|
||||||
*
|
/**
|
||||||
* Will give the developer the GD resource for the graph that
|
* Output GD Image
|
||||||
* can be used to store the graph to the FS or other media
|
*
|
||||||
*
|
* Alias for eqGraph::getImage()
|
||||||
* @return Resource GD Image Resource
|
*
|
||||||
*/
|
* @return Resource GD Image resource
|
||||||
public function getImage() {
|
*/
|
||||||
return $this->image;
|
public function outGD() {
|
||||||
}
|
return $this->getImage();
|
||||||
|
}
|
||||||
/**
|
} //end class 'eqGraph'
|
||||||
* Output GD Image
|
endif;
|
||||||
*
|
|
||||||
* Alias for eqGraph::getImage()
|
|
||||||
*
|
|
||||||
* @return Resource GD Image resource
|
|
||||||
*/
|
|
||||||
public function outGD() {
|
|
||||||
return $this->getImage();
|
|
||||||
}
|
|
||||||
} //end class 'eqGraph'
|
|
||||||
?>
|
?>
|
||||||
@@ -13,10 +13,10 @@ License: GPLv3
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Make sure we don't expose any info if called directly
|
// Make sure we don't expose any info if called directly
|
||||||
if ( !function_exists( 'add_action' ) ) {
|
if ( !function_exists( 'add_action' ) ):
|
||||||
echo 'Hi there! I\'m just a plugin, not much I can do when called directly.';
|
echo 'Hi there! I\'m just a plugin, not much I can do when called directly.';
|
||||||
exit;
|
exit;
|
||||||
}
|
endif;
|
||||||
|
|
||||||
define( 'SPORTSPRESS_VERSION', '0.3.3' );
|
define( 'SPORTSPRESS_VERSION', '0.3.3' );
|
||||||
define( 'SPORTSPRESS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
define( 'SPORTSPRESS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
||||||
@@ -24,7 +24,8 @@ define( 'SPORTSPRESS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
|||||||
define( 'SPORTSPRESS_PLUGIN_FILE', __FILE__ );
|
define( 'SPORTSPRESS_PLUGIN_FILE', __FILE__ );
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
require_once dirname( __FILE__ ) . '/lib/eos/eos.class.php' ;
|
if ( ! class_exists( 'eqEOS' ) )
|
||||||
|
require_once dirname( __FILE__ ) . '/lib/eos/eos.class.php' ;
|
||||||
|
|
||||||
// Globals
|
// Globals
|
||||||
require_once dirname( __FILE__ ) . '/admin/globals/continents.php';
|
require_once dirname( __FILE__ ) . '/admin/globals/continents.php';
|
||||||
|
|||||||
Reference in New Issue
Block a user