| Server IP : 87.98.154.146 / Your IP : 216.73.216.101 Web Server : Apache System : Linux webm005.cluster126.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64 User : bsiadvisil ( 110003) PHP Version : 7.3.33 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/bsiadvisil/old/plugins/content/rgraph/lib/ |
Upload File : |
<?php
/**
* @package rgraph Joomla! Plugin
* @version Version 1
* @author Joachim Schmidt - joachim.schmidt@jschmidt-systemberatung.de
* @copyright (C) 2016 Joachim Schmidt. All rights reserved.
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
* @abstract: json php-helper class for rgraph charts package
*
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
include_once 'rgraph_valid_options.php';
class plg_rgraph_options
{
function __construct ($options = null)
{
$this->rgraph_options($options);
}
function rgraph_options ($options)
{
// common options
if (isset($options))
{
$this->set_optionsviaArray($options, false);
}
else
{
$this->gutterTop = 50;
$this->gutterBottom = 50;
$this->gutterLeft = 50;
$this->scaleDecimals = 0;
$this->scalePoint = ".";
$this->scaleThousand = ",";
$this->colors = array(
"rgb(0,0,255)",
"#0f0",
"#00f",
"#ff0",
"#0ff",
"#0f0"
);
}
}
public function get_option ($option)
{
if (isset($this->$option))
return $this->$option;
}
public function set_option ($option, $parm, $force = false)
{
if ($force === true)
{
$this->$option = $parm;
return true;
}
$value = plg_rgraph_valid_options::options($option);
if ($value != - 1)
{
$type = gettype($parm);
if ($type == $value['type'])
{
if ($value['type'] == "array")
{
if ($value['types'] == "integer" || $value['types'] == "double")
$parm = $this->set_numeric($parm);
}
if ($option == "show_labels")
$this->labels = $parm;
if ($option == "contextmenu")
{
if (! is_array($parm[0]))
{
if (isset($parm[1]))
$parm[1] = "JAVA_VAR" . $parm[1] . "JAVA_VAR";
}
else
{
for ($i = 0; $i < count($parm); $i ++)
{
if (isset($parm[$i][1]))
$parm[$i][1] = "JAVA_VAR" . $parm[$i][1] . "JAVA_VAR";
}
}
}
if ($option == "eventsClick" || $option == "eventsMousemove")
$parm = 'JAVA_VAR' . $parm . 'JAVA_VAR';
if ($option == "fill.click" || $option == "fill.mousemove")
$parm = 'JAVA_VAR' . $parm . 'JAVA_VAR';
if ($option == "tooltipsOverride" || $option == "xscaleFormatter")
$parm = 'JAVA_VAR' . $parm . 'JAVA_VAR';
$this->$option = $parm;
return true;
}
elseif ($type == "integer" && $value['type'] == "double")
{
$this->$option = $parm;
return true;
}
elseif ($value['type'] == "double" && is_numeric($parm))
{
settype($parm, "float");
$this->$option = $parm;
return true;
}
elseif ($value['type'] == "integer" && is_numeric($parm))
{
settype($parm, "integer");
$this->$option = $parm;
return true;
}
elseif ($value['type'] == "boolean" && strtolower($parm) == "true")
{
$this->$option = true;
return true;
}
elseif ($value['type'] == "boolean" && strtolower($parm) == "false")
{
$this->$option = false;
return true;
}
elseif ($value['type'] == "boolean" && $parm === "1")
{
$this->$option = true;
return true;
}
elseif ($value['type'] == "boolean" && $parm === "0")
{
$this->$option = false;
return true;
}
elseif ($value['type'] == "array")
{
// echo "<br> option = $option :" . $value['types'];
return false;
}
elseif ($parm === null)
{
$this->$option = null;
}
else
return false;
}
return - 1;
}
public function get_optionType ($option)
{
$value = plg_rgraph_valid_options::options($option);
if ($value != - 1)
{
return $value['type'];
}
return - 1;
}
public function set_tooltip ($data, $string = "#val#", $group = false)
{
$tip = array();
if (! is_array($data))
return - 1;
if (! isset($this->scaleThousand))
$this->scaleThousand = ",";
if (! isset($this->scalePoint))
$this->scalePoint = ".";
if (! isset($this->scaleDecimals))
$this->scaleDecimals = 0;
$sep_thousand = $this->scaleThousand;
$sep_dec = $this->scalePoint;
$num_dec = $this->scaleDecimals;
if (! is_array($data[0]))
{
$total = array_sum($data);
$tips = array_values($data);
if (isset($this->labels) && count($this->labels) < count($tips))
{
do
{
array_push($this->labels, "");
}
while (count($this->labels) < count($tips));
}
for ($i = 0; $i < count($tips); $i ++)
{
if ($total != 0)
$percent = round(100 * $tips[$i] / $total, $num_dec);
else
$percent = "nan";
$tmp = str_replace("#percent#", $percent, $string);
if (isset($this->labels[$i]))
$tmp = str_replace("#label#", $this->labels[$i], $tmp);
$tmp = str_replace("#total#", number_format($total, $num_dec, $sep_dec, $sep_thousand), $tmp);
$tip[$i] = str_replace("#val#", number_format((float) $tips[$i], $num_dec, $sep_dec, $sep_thousand), $tmp);
}
}
else
{
// calculate totals / group
for ($i = 0; $i < count($data); $i ++)
{
$total[$i] = 0;
for ($j = 0; $j < count($data[$i]); $j ++)
$total[$i] += $data[$i][$j];
}
$k = 0;
if ($group == false)
{
for ($i = 0; $i < count($data); $i ++)
{
if (isset($this->labels[$i]))
$tmp = str_replace("#label#", $this->labels[$i], $string);
else
$tmp = $string;
for ($j = 0; $j < count($data[$i]); $j ++)
{
if (isset($this->key[$j]))
$tmp2 = str_replace("#key#", $this->key[$j], $tmp);
else
$tmp2 = $tmp;
$tmp2 = str_replace("#total#", number_format($total[$i], $num_dec, $sep_dec, $sep_thousand), $tmp2);
$tip[$k] = str_replace("#val#", number_format((float) $data[$i][$j], $num_dec, $sep_dec, $sep_thousand), $tmp2);
$k ++;
}
}
}
else
{
for ($i = 0; $i < count($data); $i ++)
{
for ($j = 0; $j < count($data[$i]); $j ++)
{
if (isset($this->labels[$j]))
$tmp = str_replace("#label#", $this->labels[$j], $string);
else
$tmp = $string;
if (isset($this->key[$i]))
$tmp2 = str_replace("#key#", $this->key[$i], $tmp);
else
$tmp2 = $tmp;
$tmp2 = str_replace("#total#", number_format($total[$i], $num_dec, $sep_dec, $sep_thousand), $tmp2);
$tip[$k] = str_replace("#val#", number_format((float) $data[$i][$j], $num_dec, $sep_dec, $sep_thousand), $tmp2);
$k ++;
}
}
}
}
$this->tooltips = $tip;
return true;
}
public static function xlabelsteps ($labels, $num)
{
if (! is_array($labels))
return false;
$new_labels = array();
for ($i = 0; $i < count($labels); $i ++)
{
if ($i % $num == 0)
$new_labels[$i] = $labels[$i];
else
$new_labels[$i] = "";
}
return $new_labels;
}
public function get_colors ()
{
if (isset($this->colors))
return $this->colors;
}
public function set_gradientColors ($colors, $gradients)
{
if (! is_array($colors))
return false;
if (! is_array($gradients))
return false;
$new_colors = array();
if (count($colors) > count($gradients))
{
do
{
array_push($gradients, $gradients[0]);
}
while (count($colors) > count($gradients));
}
for ($i = 0; $i < count($colors); $i ++)
$new_colors[$i] = 'Gradient(' . $colors[$i] . ':' . $gradients[$i] . ':' . $gradients[$i] . ')';
$this->colors = $new_colors;
return true;
}
public function setColorOpacity ($opacity = 0.8)
{
if (! is_array($this->colors))
return false;
for ($i = 0; $i < count($this->colors); $i ++)
$this->colors[$i] = $this->setOpacity($this->colors[$i], $opacity);
return true;
}
public static function setOpacity ($color, $opacity = 1.0)
{
if (empty($color))
return false;
if ($color[0] == '#')
{
$color = substr($color, 1);
}
if (substr($color, 0, 4) == 'rgb(')
{
$tmp = explode(",", $color);
$tmp[0] = str_replace("rgb", "rgba", $tmp[0]);
$tmp[2] = str_replace(")", "", $tmp[2]);
array_push($tmp, $opacity);
$color = implode(",", $tmp) . ")";
return ($color);
}
if (substr($color, 0, 4) == 'rgba')
{
$tmp = explode(",", $color);
$tmp[3] = $opacity . ")";
$color = implode(",", $tmp);
return ($color);
}
if (strlen($color) == 6)
{
$hex = array(
$color[0] . $color[1],
$color[2] . $color[3],
$color[4] . $color[5]
);
}
elseif (strlen($color) == 3)
{
$hex = array(
$color[0] . $color[0],
$color[1] . $color[1],
$color[2] . $color[2]
);
}
else
return $color;
$rgb = array_map('hexdec', $hex);
if (abs($opacity) > 1)
$opacity = 1.0;
$rgba_color = 'rgba(' . implode(",", $rgb) . ',' . $opacity . ')';
return $rgba_color;
}
public function set_optionsviaArray ($parms, $nocheck = false)
{
if (! is_array($parms))
return - 1;
$result = true;
foreach ($parms as $key => $value)
{
$type = $this->get_optionType($key);
if ($type != - 1)
{
if ($type == "array")
{
if ($key == "tooltips" && strpos($value, "function") !== false)
{
$trans = array(
"[" => "{",
"]" => "}"
);
$value = strtr($value, $trans);
$nocheck = true;
}
elseif (strpos($value, "rgb") !== false)
{
$value = $this->buildcolorsArray($value);
}
else
{
if (strpos($value, "|"))
$tmp = explode("|", $value);
else
$value = explode(",", $value);
if (isset($tmp))
{
$value = array();
for ($i = 0; $i < count($tmp); $i ++)
$value[$i] = explode(",", $tmp[$i]);
}
}
}
$rc = true;
if ($value !== null && $value != "")
{
if ($value === "null")
$value = null;
$rc = $this->set_option($key, $value, $nocheck);
}
if ($rc !== true)
$result = 2;
}
else
$result = 2;
}
return $result;
}
public static function buildcolorsArray ($color_values)
{
$tmp = explode(",", $color_values);
$k = 0;
$new_values = array();
for ($i = 0; $i < count($tmp);)
{
if (strpos($tmp[$i], "rgb") !== false)
{
$count = 3;
if (strpos($tmp[$i], "rgba") !== false)
$count = 4;
$rgb_array = array();
for ($j = 0; $j < $count; $j ++)
{
array_push($rgb_array, $tmp[$i]);
$i ++;
}
$new_values[$k] = implode(",", $rgb_array);
}
else
{
$new_values[$k] = $tmp[$i];
$i ++;
}
$k ++;
}
return $new_values;
}
public static function set_numeric ($data)
{
if (! is_array($data[0]))
{
for ($i = 0; $i < count($data); $i ++)
{
$data[$i] = str_replace(",", ".", $data[$i]);
if ($data[$i] == "")
$data[$i] = null;
if (is_numeric($data[$i]))
settype($data[$i], "float");
}
}
else
{
for ($i = 0; $i < count($data); $i ++)
for ($j = 0; $j < count($data[$i]); $j ++)
{
$data[$i][$j] = str_replace(",", ".", $data[$i][$j]);
if ($data[$i][$j] == "")
$data[$i][$j] = null;
if (is_numeric($data[$i][$j]))
settype($data[$i][$j], "float");
}
}
return $data;
}
public static function truncateLabels ($labels, $size, $chars = null)
{
if ($size == '0')
return $labels;
if (! is_array($labels))
return false;
for ($i = 0; $i < count($labels); $i ++)
{
if (strlen($labels[$i]) > $size)
$labels[$i] = mb_substr($labels[$i], 0, $size) . $chars;
}
return $labels;
}
public static function getRandomColor ()
{
$hex_rgb = dechex(rand(0, 255)) . dechex(rand(0, 255)) . dechex(rand(0, 255));
if (strlen($hex_rgb) == 4)
{
$hex_rgb = $hex_rgb . rand(10, 99);
}
elseif (strlen($hex_rgb) == 5)
{
$hex_rgb = $hex_rgb . rand(0, 9);
}
$color = "#" . $hex_rgb;
return $color;
}
public static function getRandomColors ($count = 1)
{
$colors = array();
for ($i = 0; $i < $count; $i ++)
$colors[$i] = getRandomColor();
return $colors;
}
}
?>