Skip to content

Commit

Permalink
Merge pull request #2 from thatandromeda/display_counters
Browse files Browse the repository at this point in the history
Display counters
  • Loading branch information
griffey committed Dec 19, 2013
2 parents aa284ea + 21d1f1d commit 22872a3
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 24 deletions.
2 changes: 1 addition & 1 deletion LibraryBox-landingpage/www_content/dl_statistics.html.php
Expand Up @@ -8,7 +8,7 @@
will be called by display_dl_count.php with an
$resutlt = array (
$result = array (
array ( 'url' => "/Shared/......" , "counter" => 4 ),
array ( 'url' => "/Shared/......" , "counter" => 5 ),
)
Expand Down
20 changes: 7 additions & 13 deletions LibraryBox-landingpage/www_content/index.html
Expand Up @@ -35,25 +35,18 @@
<div id="welcome">
<div class="container">
<h1><img src="img/lbx-logo-small.png">Welcome to LibraryBox v2.0</h1>
<p>Browse and download any of the available files, or chat with other users below.</p><p>LibraryBox is private, no logs or other identifying information is retained.</p>
<p>Browse and download any of the available files, or chat with other users below.</p><p>LibraryBox is private; no logs or other identifying data are retained.</p>
</div>
</div>
<div class="container">
<div class="one-third">
<div id="files-top" class="card">
<h2>Top Downloads</h2>
<ul>
<li>Lorem</li>
<li>Lorem</li>
<li>Lorem</li>
<li>Lorem</li>
<li>Lorem</li>
<li>Lorem</li>
<li>Lorem</li>
<li>Lorem</li>
<li>Lorem</li>
<li>Lorem</li>
</ul>
<!-- default, which will be replaced by files-top.js if applicable -->
<p id="files-top-default">Nothing's been downloaded yet. Why don't
you download something and get this party started?</p>
</div>
<div id="jquery-testing">
</div>
</div>

Expand Down Expand Up @@ -91,5 +84,6 @@ <h3>Text Color:</h3>

<script src="js/jquery.min.js"></script>
<script src="js/main.js"></script>
<script src="js/files-top.js"></script>
</body>
</html>
24 changes: 24 additions & 0 deletions LibraryBox-landingpage/www_content/js/files-top.js
@@ -0,0 +1,24 @@
var $j = jQuery.noConflict();

$j(document).ready(function() {
var top_files_para = $j('#files-top-default');
// We don't need to specify top_max here to get a top 10 list, because
// it defaults to 10.
$j.get( "dl_statistics_display.php?sortBy=counter&list_type=top&output_type=json", function( data ) {
var items = [];
data_json = $j.parseJSON(data);
// just to simplify testing. remove later.
var jquery_testing = $j('#jquery-testing');
jquery_testing.html(data_json)
$.each( data_json, function( url, counter ) {
// more testing
alert("URL is " + url + " and counter is " + counter);
items.push( '<li><a href="' + url '">' + url + '</a> (' + counter + 'download(s))</li>' );
});
var top_files_list = $j( "<ul/>", {
"id": "files-top-generated",
html: items.join( "" )
})
top_files_para.replaceWith(top_files_list);
});
});
2 changes: 1 addition & 1 deletion LibraryBox-landingpage/www_content/vc_statistics.html.php
Expand Up @@ -8,7 +8,7 @@
will be called by vc_display.php with an
$resutlt = array (
$result = array (
array ( 'url' => "/Shared/......" , "counter" => 4 ),
array ( 'url' => "/Shared/......" , "counter" => 5 ),
)
Expand Down
2 changes: 1 addition & 1 deletion customization/www_librarybox/dl_statistics.conf.php
Expand Up @@ -13,7 +13,7 @@ function dl_get_config () {
"HTML_TEMPLATE_FILE" => "content/dl_statistics.html.php" ,
"sortBy" => 'url', #url, count are possibilities
"sortOrder" => 'ASC' , # ASC, DESC
"top_max" => "5", #Display top n on option "top"
"top_max" => "10", #Display top n on option "top"
"output_type" => "html" , # Display HTML per default or only JSON
"list_type" => "all" , #Display "all" or only "top" on default

Expand Down
8 changes: 4 additions & 4 deletions customization/www_librarybox/dl_statistics.func.php
Expand Up @@ -20,11 +20,11 @@ function __do_db_connect() {

function dl_read_stat_per_path_only ( $path="%" ) {
$config = dl_get_config();
return dl_read_stat_per_path ($path , $config["sortBy"] , $config["sortOrder"] , "all" , $config["top_max"] );
return dl_read_stat_per_path ($path , $config["sortBy"] , $config["sortOrder"] , $config["list_type"] , $config["top_max"] );

}

function dl_read_stat_per_path ($path="%" , $sortBy , $sort, $type="all" , $limit ) {
function dl_read_stat_per_path ($path="%" , $sortBy , $sort, $listType , $limit ) {

$config = dl_get_config();
if ( ! isset ( $sortBy ) )
Expand All @@ -39,9 +39,9 @@ function dl_read_stat_per_path ($path="%" , $sortBy , $sort, $type="all" , $lim

$db = __do_db_connect();

if ( $type == "all" ) {
if ( $listType == "all" ) {
$sth = $db->prepare ( " SELECT url, counter FROM dl_statistics WHERE url LIKE :path ORDER by $sortBy $sort ");
} elseif ( $type == "top" ) {
} elseif ( $listType == "top" ) {
$sth = $db->prepare ( "SELECT url, counter FROM dl_statistics WHERE url LIKE :path ORDER by $sortBy $sort LIMIT 0 , :max ");
$sth->bindParam (':max' , $limit, PDO::PARAM_INT );
}
Expand Down
10 changes: 6 additions & 4 deletions customization/www_librarybox/dl_statistics_display.php
Expand Up @@ -11,17 +11,19 @@
sortOrder = ASC / DESC - Ascendening or decsending sort order
sortBy = url/counter Sort by complete "url" to file, or based on download "counter"
list_type = "all" display all data ; "top" - limit display with top n entries
top_max = Limit entry list in "top" mode by that value
output_type = none or html resulsts in a simple html output
top_max = The maximum number of values to return in "top" mode.
output_type = none or html results in a simple html output
"json" results in a json structure
Default values are provided by dl_statistics.conf.php.
The HTML output is based on a file pointed in "dl_statistics.conf.php" to.
That file lays on librarybox in the content folder
http://librarybox.us/content/....
which is in reality on the USB stick. That file can simply exchanged without the need
of touching the logic behind.
Currently I don't have the path filter programmed in that. script
Currently I don't have the path filter programmed in that script.
Expand Down Expand Up @@ -79,7 +81,7 @@
# Detect which statement


$result= dl_read_stat_per_path ( '%' , $sortBy , $sort , $list_type , $top_max );
$result = dl_read_stat_per_path ( '%' , $sortBy , $sort , $list_type , $top_max );

#------------------------------------------------
# Output
Expand Down

0 comments on commit 22872a3

Please sign in to comment.