Skip to content

Commit 8d8d8b7

Browse files
committed
bugfixes and first tiny output
1 parent 0c92b26 commit 8d8d8b7

File tree

4 files changed

+186
-3
lines changed

4 files changed

+186
-3
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
2+
<?php
3+
4+
/********************************
5+
6+
HTML Generation function for PHP-Download-Counter Statistics
7+
8+
will be called by vc_display.php with an
9+
10+
11+
$resutlt = array (
12+
array ( 'url' => "/Shared/......" , "counter" => 4 ),
13+
array ( 'url' => "/Shared/......" , "counter" => 5 ),
14+
)
15+
16+
17+
(optional) $arguments = array (
18+
....
19+
);
20+
21+
The HTML is separated in that file, to enable easy exchangable looks
22+
23+
*******************************/
24+
25+
26+
function print_header () {
27+
28+
29+
echo <<<EOD
30+
31+
<html>
32+
<head><title>Download-Statistics</title></head>
33+
<body>
34+
EOD;
35+
36+
37+
}
38+
39+
function print_table_head() {
40+
41+
echo <<<EOD
42+
<table>
43+
<tr><th></th><th><a href="vc_display.php?sortBy=day">Day:</a></th><th><a href="vc_display.php?sortBy=counter&sortOrder=DESC">Visitors:</th></tr>
44+
EOD;
45+
}
46+
47+
function print_table_line($no , $day = "" , $count = 0) {
48+
49+
echo <<<EOD
50+
<tr><td></td><td>$day</td><td>$count</td></tr>
51+
EOD;
52+
53+
}
54+
55+
function print_footer() {
56+
57+
echo <<<EOD
58+
</table>
59+
</body>
60+
</html>
61+
EOD;
62+
63+
}
64+
65+
function output_html ( $result = array () , $arguments = array () ) {
66+
67+
print_header();
68+
print_table_head();
69+
70+
71+
foreach ( $result as $no => $line ) {
72+
print_table_line ( $no, $line['day'], $line['counter'] );
73+
74+
}
75+
76+
print_footer();
77+
}
78+
?>

customization/www_librarybox/vc.conf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function vc_get_config () {
1212
"SQLITE_FILE" => "sqlite:/opt/piratebox/share/vc_statistics.sqlite",
1313
"HTML_TEMPLATE_FILE" => "content/vc_statistics.html.php" ,
1414
"sortBy" => "day" ,
15-
"sortOrder" => 'DESV' , # ASC, DESC
15+
"sortOrder" => 'DESC' , # ASC, DESC
1616
"top_max" => "5", #Display top n on option "top"
1717
"output_type" => "html" , # Display HTML per default or only JSON
1818
"list_type" => "top" , #Display "all" or only "top" on default

customization/www_librarybox/vc.func.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ function vc_read_stat_sum_per_day ($path="%" , $sortBy , $sort, $type="all" , $
7676
$db = vc_do_db_connect();
7777

7878
if ( $type == "all" ) {
79-
$sth = $db->prepare ( " SELECT day, count( visitor) FROM vc_statistics WHERE day LIKE :day ORDER by $sortBy $sort GROUP BY day ");
79+
$sth = $db->prepare ( " SELECT day, count( visitor) as counter FROM vc_statistics WHERE day LIKE :day GROUP BY day ORDER by $sortBy $sort ");
8080
} elseif ( $type == "top" ) {
81-
$sth = $db->prepare ( " SELECT day, count(visitor) FROM vc_statistics WHERE day LIKE :day ORDER by $sortBy $sort GROUP BY day LIMIT 1 , :max ");
81+
$sth = $db->prepare ( " SELECT day, count(visitor) as counter FROM vc_statistics WHERE day LIKE :day GROUP BY day ORDER by $sortBy $sort LIMIT 0 , :max ");
8282
$sth->bindParam (':max' , $limit, PDO::PARAM_INT );
8383
}
8484

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
/******* Display Visitor - statistics *****
4+
5+
VERSION 0.1 - Matthias Strubel (c) 2013 - GPL3
6+
7+
Very simple script to get access to the statistic data.
8+
9+
Following GET-Options are possible:
10+
11+
sortOrder = ASC / DESC - Ascendening or decsending sort order
12+
sortBy =
13+
list_type = "all" display all data ; "top" - limit display with top n entries
14+
top_max = Limit entry list in "top" mode by that value
15+
output_type = none or html resulsts in a simple html output
16+
"json" results in a json structure
17+
18+
The HTML output is based on a file pointed in "vc.conf.php" to.
19+
That file lays on librarybox in the content folder
20+
http://librarybox.us/content/....
21+
which is in reality on the USB stick. That file can simply exchanged without the need
22+
of touching the logic behind.
23+
24+
Currently I don't have the path filter programmed in that. script
25+
26+
27+
CHANGELOG:
28+
0.1 RELEASE
29+
30+
********************************************/
31+
32+
require_once "vc.conf.php";
33+
include "vc.func.php";
34+
35+
$config=vc_get_config();
36+
37+
$sort=$config["sortOrder"];
38+
$sortBy=$config["sortBy"];
39+
$top_max=$config["top_max"];
40+
$output_type=$config["output_type"];
41+
$list_type=$config["list_type"];
42+
43+
if ( isset ($_GET['sortOrder'] )) {
44+
if ( $_GET['sortOrder'] == 'ASC' ) {
45+
$sort='ASC';
46+
} else {
47+
$sort='DESC';
48+
}
49+
}
50+
51+
if ( isset ($_GET['sortBy']) ) {
52+
if ( $_GET["sortBy"] == "url" ) {
53+
$sortBy="url";
54+
} elseif ( $_GET["sortBy"] == "counter" ) {
55+
$sortBy="counter";
56+
}
57+
}
58+
59+
if ( isset ($_GET['top_max'] )) {
60+
$top_max = $_GET['top_max'];
61+
}
62+
63+
64+
if ( isset ($_GET['output_type'] )) {
65+
if ( $_GET["output_type"] == "json" ) {
66+
$output_type= "json";
67+
} elseif ( $_GET["output_type"] == "html" ) {
68+
$output_type="html";
69+
}
70+
}
71+
72+
73+
if ( isset ( $_GET['list_type'] )) {
74+
$list_type= $_GET['list_type'];
75+
}
76+
77+
#----------------------------------
78+
# Detect which statement
79+
80+
81+
$result= vc_read_stat_sum_per_day ( '%' , $sortBy , $sort , $list_type , $top_max );
82+
83+
#------------------------------------------------
84+
# Output
85+
86+
if ( is_array ( $result ) ) {
87+
if ( $output_type == "html" ) {
88+
# Template file for HTML output
89+
include $config["HTML_TEMPLATE_FILE"];
90+
output_html ( $result, array (
91+
'list_type' => $list_type,
92+
'top_max' => $top_max ,
93+
"sortBy" => $sortBy ,
94+
"sortOrder" => $sort,
95+
"filter_path" => false ,
96+
"script_url" => $_ENV['REQUEST_URI'],
97+
));
98+
} elseif ( $output_type == "json" ) {
99+
header('Content-Type: application/json');
100+
print json_encode ( $result );
101+
}
102+
103+
}
104+
105+
?>

0 commit comments

Comments
 (0)