1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/jappix_ynh.git synced 2024-09-03 19:26:19 +02:00
jappix_ynh/source/server/stats-svg.php

104 lines
2.2 KiB
PHP
Raw Normal View History

2014-03-12 14:52:47 +01:00
<?php
/*
Jappix - An open social platform
The SVG loader for Jappix statistics
-------------------------------------------------
License: AGPL
Author: Valérian Saliou
*/
// PHP base
define('JAPPIX_BASE', '..');
// Get the functions
require_once('./functions.php');
require_once('./functions-manager.php');
// Get the configuration
require_once('./read-main.php');
require_once('./read-hosts.php');
// Get the libs
require_once('./drawsvgchart.php');
require_once('./gettext.php');
// Prepare application
enableErrorSink();
hideErrors();
compressThis();
// Start the session
session_start();
// Check if the user is authorized
$is_admin = false;
if((isset($_SESSION['jappix_user']) && !empty($_SESSION['jappix_user'])) && (isset($_SESSION['jappix_password']) && !empty($_SESSION['jappix_password']))) {
// Get the session values
$user = $_SESSION['jappix_user'];
$password = $_SESSION['jappix_password'];
// Checks the user is admin
$is_admin = isAdmin($user, $password);
}
// Not admin? Stop the script!
if(!$is_admin) {
exit;
}
// Get the graph type
if((isset($_GET['g']) && !empty($_GET['g']))) {
$graph = $_GET['g'];
} else {
$graph = 'others';
}
// Get the locale
if((isset($_GET['l']) && !empty($_GET['l']))) {
$locale = $_GET['l'];
} else {
$locale = 'en';
}
// Include the translations
includeTranslation($locale, 'main');
$drawsvgchart = new DrawSVGChart;
// Generation vars
$link = FALSE;
$evolution = FALSE;
// Access graph?
if($graph == 'access') {
// Access graph
$elements = getMonthlyVisits();
$legend = array(array('#5276A9', T_("Visits")));
$evolution = TRUE;
} else if($graph == 'share') {
// Share graph
$elements = largestShare(shareStats(), 8);
$legend = array(array('#5276A9', T_("Size")));
} else if($graph == 'others') {
// Others graph
$elements = otherStats();
$legend = array(array('#5276A9', T_("Size")));
}
// Generate the chart
$svgchart = $drawsvgchart->createChart($elements, $legend, $link, $evolution, $graph);
// No error?
if(!$drawsvgchart->has_errors()) {
header('Content-Type: image/svg+xml; charset=utf-8');
echo $drawsvgchart->getXMLOutput();
}
?>