]> git.mxchange.org Git - friendica-addons.git/blob - jappixmini/jappix/php/stats-svg.php
Merge branch '3.6-release'
[friendica-addons.git] / jappixmini / jappix / php / stats-svg.php
1 <?php
2
3 /*
4
5 Jappix - An open social platform
6 The SVG loader for Jappix statistics
7
8 -------------------------------------------------
9
10 License: AGPL
11 Author: Vanaryon
12 Last revision: 28/12/10
13
14 */
15
16 // PHP base
17 define('JAPPIX_BASE', '..');
18
19 // Get the functions
20 require_once('./functions.php');
21 require_once('./functions-manager.php');
22
23 // Get the configuration
24 require_once('./read-main.php');
25 require_once('./read-hosts.php');
26
27 // Get the libs
28 require_once('./drawsvgchart.php');
29 require_once('./gettext.php');
30
31 // Optimize the page rendering
32 hideErrors();
33 compressThis();
34
35 // Start the session
36 session_start();
37
38 // Check if the user is authorized
39 $is_admin = false;
40
41 if((isset($_SESSION['jappix_user']) && !empty($_SESSION['jappix_user'])) && (isset($_SESSION['jappix_password']) && !empty($_SESSION['jappix_password']))) {
42         // Get the session values
43         $user = $_SESSION['jappix_user'];
44         $password = $_SESSION['jappix_password'];
45         
46         // Checks the user is admin
47         $is_admin = isAdmin($user, $password);
48 }
49
50 // Not admin? Stop the script!
51 if(!$is_admin)
52         exit;
53
54 // Get the graph type
55 if((isset($_GET['g']) && !empty($_GET['g'])))
56         $graph = $_GET['g'];
57 else
58         $graph = 'others';
59
60 // Get the locale
61 if((isset($_GET['l']) && !empty($_GET['l'])))
62         $locale = $_GET['l'];
63 else
64         $locale = 'en';
65
66 // Include the translations
67 includeTranslation($locale, 'main');
68
69 $drawsvgchart = new DrawSVGChart;
70
71 // Generation vars
72 $link = FALSE;
73 $evolution = FALSE;
74
75 // Access graph?
76 if($graph == 'access') {
77         // Values
78         $elements = getMonthlyVisits();
79         $legend = array(array('#5276A9', T_("Visits")));
80         $evolution = TRUE;
81 }
82
83 // Share graph?
84 else if($graph == 'share') {
85         // Values
86         $elements = largestShare(shareStats(), 8);
87         $legend = array(array('#5276A9', T_("Size")));
88 }
89
90 // Others graph?
91 else if($graph == 'others') {
92         // Values
93         $elements = otherStats();
94         $legend = array(array('#5276A9', T_("Size")));
95 }
96
97 // Generate the chart
98 $svgchart = $drawsvgchart->createChart($elements, $legend, $link, $evolution, $graph);
99
100 // No error?
101 if(!$drawsvgchart->has_errors()) {
102         header('Content-Type: image/svg+xml; charset=utf-8');
103         echo $drawsvgchart->getXMLOutput();
104 }
105
106 ?>