コード例 #1
0
ファイル: functions.php プロジェクト: ntrrgc/jappix
function getFiles($h, $l, $t, $g, $f)
{
    // Define the good path to the Get API
    if (hasStatic()) {
        $path_to = HOST_STATIC . '/';
    } else {
        $path_to = JAPPIX_BASE . '/';
    }
    if (!multiFiles()) {
        $values = array();
        if ($h) {
            $values[] = 'h=' . $h;
        }
        if ($l) {
            $values[] = 'l=' . $l;
        }
        if ($t) {
            $values[] = 't=' . $t;
        }
        if ($g) {
            $values[] = 'g=' . $g;
        }
        if ($f) {
            $values[] = 'f=' . $f;
        }
        return $path_to . 'php/get.php?' . implode('&', $values);
    }
    if ($g && !empty($g) && preg_match('/^(\\S+)\\.xml$/', $g) && preg_match('/^(css|js)$/', $t) && isSafe($g) && file_exists('xml/' . $g)) {
        $xml_data = file_get_contents('xml/' . $g);
        // Any data?
        if ($xml_data) {
            $xml_read = new SimpleXMLElement($xml_data);
            $xml_parse = $xml_read->{$t};
            // Files were added to the list before (with file var)?
            if ($f) {
                $f .= '~' . $xml_parse;
            } else {
                $f = $xml_parse;
            }
        }
    }
    // Explode the f string
    if (strpos($f, '~') != false) {
        $array = explode('~', $f);
    } else {
        $array = array($f);
    }
    $a = array();
    foreach ($array as $file) {
        $a[] = $path_to . $t . '/' . $file;
    }
    if (count($a) == 1) {
        return $a[0];
    }
    return $a;
}
コード例 #2
0
ファイル: functions.php プロジェクト: neurolit/jappix
function staticURL()
{
    if (hasStatic()) {
        // Static URL in hosts.xml
        $url = HOST_STATIC . $_SERVER['REQUEST_URI'];
    } else {
        // Check for HTTPS
        $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
        // Check for port
        $port_section = null;
        $port_value = isset($_SERVER['SERVER_PORT']) && is_numeric($_SERVER['SERVER_PORT']) ? intval($_SERVER['SERVER_PORT']) : null;
        if ($port_value != null && ($protocol == 'http' && $port_value != 80) || $protocol == 'https' && $port_value != 443) {
            $port_section = ':' . $port_value;
        }
        // Full URL
        $url = $protocol . '://' . $_SERVER['HTTP_HOST'] . $port_section . $_SERVER['REQUEST_URI'];
    }
    return $url;
}
コード例 #3
0
 function createChart($datas = array(), $legend = array(), $link, $evolution = FALSE, $type = 'others')
 {
     $this->has_errors = FALSE;
     $max = 0;
     // One or two data arrays
     if (isset($datas[0]) && is_array($datas[0])) {
         $datas_number = count($datas[0]);
         if ($datas_number >= 1) {
             $max = max($datas[0]);
         } else {
             $this->has_errors = TRUE;
         }
     } else {
         $datas_number = count($datas);
         if ($datas_number >= 1) {
             $max = max($datas);
         } else {
             $this->has_errors = TRUE;
         }
     }
     // Set the width of the chart
     if ($datas_number * 55 > 400) {
         $width = $datas_number * 55;
     } else {
         $width = 400;
     }
     $height = 250;
     $this->datas = $datas;
     $this->legend = $legend;
     $this->link = $link;
     $this->evolution = $evolution;
     $this->type = $type;
     $this->xml_elements = array();
     // Scale
     if ($max <= 20) {
         $scale[4] = 20;
         $scale[3] = 15;
         $scale[2] = 10;
         $scale[1] = 5;
     } else {
         $scale[4] = ceil($max / 20) * 20;
         $scale[3] = $scale[4] * 3 / 4;
         $scale[2] = $scale[4] * 2 / 4;
         $scale[1] = $scale[4] * 1 / 4;
     }
     if ($scale[4] == 0 || $max == 0) {
         $this->has_errors = TRUE;
     }
     if ($this->has_errors) {
         return TRUE;
     }
     $this->xml_object = new DOMDocument('1.0', 'utf-8');
     // Process the static file host prefix
     $static_prefix = '.';
     if (hasStatic()) {
         $static_prefix = HOST_STATIC . '/php';
     }
     // Add the stylesheet
     $style = $this->xml_object->createProcessingInstruction("xml-stylesheet", "type='text/css' href='" . getFiles(genHash(getVersion()), '', 'css', '', 'stats-svg.css') . "'");
     $this->xml_object->appendChild($style);
     // Create the root SVG element
     $this->svg = $this->xml_object->createElement('svg');
     $this->svg->setAttribute('xmlns:svg', 'http://www.w3.org/2000/svg');
     $this->svg->setAttribute('xmlns', 'http://www.w3.org/2000/svg');
     $this->svg->setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
     $this->svg->setAttribute('version', '1.1');
     $this->svg->setAttribute('width', $width);
     $this->svg->setAttribute('height', $height);
     $this->svg->setAttribute('id', 'svg');
     $this->xml_object->appendChild($this->svg);
     // Create a definition
     $this->xml_elements['basic_defs'] = $this->xml_object->createElement('defs');
     $path = $this->xml_object->createElement('path');
     $path->setAttribute('id', 'mark');
     $path->setAttribute('d', 'M 0,234 v 4 ');
     $path->setAttribute('stroke', '#596171');
     $path->setAttribute('stroke-width', '2px');
     $this->xml_elements['basic_defs']->appendChild($path);
     // Create the static background
     $this->xml_elements['static_background'] = $this->xml_object->createElement('g');
     $this->xml_elements['static_background']->setAttribute('class', 'static-background');
     // Draw the legend
     $this->drawLegend();
     // Draw the table
     $this->drawTable($scale, $width);
     // Draw the chart
     $this->drawChart($scale, $width);
 }