{DOWNLOAD_STAT} Replacement Tag
{DOWNLOAD_STAT} Replacement Tag
Hi all!
Here is a simple download stats replacement tag to display the number of downloads for specific files, download traffic and top 10 lists.
Download and info:
http://www.kmedv.at/wcms/index.php?download_stat
Top10 sample:
http://www.kmedv.at/wcms/index.php?ds_sample
VERSION 1.0, 9.04.2006
-----------------------------------------------------
REQ: phpwcms ver 1.2.6 DEV
-----------------------------------------------------
INSTALL: copy the file downloads_stats.php to phpwcms_template\inc_script\frontend_render
-----------------------------------------------------
Here is a simple download stats replacement tag to display the number of downloads for specific files, download traffic and top 10 lists.
Download and info:
http://www.kmedv.at/wcms/index.php?download_stat
Top10 sample:
http://www.kmedv.at/wcms/index.php?ds_sample
VERSION 1.0, 9.04.2006
-----------------------------------------------------
REQ: phpwcms ver 1.2.6 DEV
-----------------------------------------------------
INSTALL: copy the file downloads_stats.php to phpwcms_template\inc_script\frontend_render
-----------------------------------------------------
Erich
Re: {DOWNLOAD_STAT} Replacement Tag
Isn´t it the answer on the Questions ?-----------------------------------------------------
INSTALL: copy the file downloads_stats.php to phpwcms_template\inc_script\frontend_render
-----------------------------------------------------
[/quote]
"Seien wir realistisch - versuchen wir das Unmögliche" (Chè Guevara)
Aus der Handbibliothek

Code: Select all
<?php
// DOWNLOAD_STAT replacementtag (by Erich Munz, 2006)
// -----------------------------------------------------
// AUTHOR Erich Munz, erich_k4
// -----------------------------------------------------
// VERSION 1.0, 9.04.2006
// -----------------------------------------------------
// REQ: phpwcms ver 1.2.6 DEV
// -----------------------------------------------------
// INSTALL: copy this file to phpwcms_template\inc_script\frontend_render
// -----------------------------------------------------
// SYNTAX: {DOWNLOAD_STAT:stat_type:admin_mode:outputstring_key:tablecaptions_key:stat_options}
//
// stat_type the filename (e.g myfile.zip or mydoc.pdf) or TOP10 to display the top 10 downloads
// ------------------
// admin_mode 0: all visitors will see the stats, 1: only admin logged in the backend will see the stats
// ------------------
// outputstring_key array key of the frmtstring array -> see the samples and setup below
// ------------------
// tablecaptions_key array key of the frmtstring array -> see the samples and setup below
// ------------------
// stat_options xxx
// |||____ 1: include only public files, 0: include public and non public files
// ||
// ||_____ 1: include deleted files, 1: dont include deleted files
// |
// |______ 1: include only aktiv files, 0: include activ and inactiv files
//
// -----------------------------------------------------
// SAMPLES:
// single file statistic, only visible for admin logged in backend:
// {DOWNLOAD_STAT:myfile.zip:1:singleline::111}
//
// statistic for files with wildcards:
// {DOWNLOAD_STAT:my%.zip:1:line_withbreak::111}
//
// top 10 list, visible for all site-visitors:
// {DOWNLOAD_STAT:TOP10:0:top10_colums:top10_captions:111}
//
// single file statistic, visible for all site-visitors:
// {DOWNLOAD_STAT:myfile.zip:0:my_sample_string::111}
//
// No_Stats_available string
define('NO_STATS', '<small>hidden</small>');
// SETUP THE FORMATSTRINGS
// (edit or add strings as you like)
//
// available placeholders:
// [NUM].........number, useful for TOP10 numbering
// [FILENAME]...the file name
// [COUNT]......x times downloaded
// [TRAFFIC]....download traffic
//
$frmtstring['singleline'] = "file [FILENAME] downloaded <b>[COUNT]</b> times, traffic [TRAFFIC] kb";
$frmtstring['line_withbreak'] = "file [FILENAME] downloaded <b>[COUNT]</b> times, traffic [TRAFFIC] kb<br \>";
$frmtstring['my_sample_string'] = "this file ([FILENAME]) was downloaded <b>[COUNT]</b> times";
$frmtstring['top10_colums'] = "[NUM].|<b>[FILENAME]</b>|<b>[COUNT]</b> |[TRAFFIC] KB"; // syntax: column1|column2|column3|column4|
$frmtstring['top10_captions'] = "Pos|file|count|traffic"; // syntax: caption1|caption2|caption3|caption4|
// Main start----------------------------------------------------------------------------------------
//
function get_downloadstats($stat_type, $admin_mode, $outputstr, $tablecaptions, $visible_mode, $db)
{
global $frmtstring;
$dl_stats = '';
$sql_where = '';
if((isset($_SESSION["wcs_user_admin"]) && $_SESSION["wcs_user_admin"] == 1 && $admin_mode == 1) OR $admin_mode == 0)
{
$traffic_total = 0;
$placeholders = array('[FILENAME]', '[COUNT]', '[TRAFFIC]', '[NUM]');
$sql_where .= ($visible_mode[0] == 1)?' AND f_aktiv=1 ':' AND f_aktiv=0 ';
$sql_where .= ($visible_mode[1] == 1)?' AND f_trash>=0 ':' AND f_trash=0 ';
$sql_where .= ($visible_mode[2] == 1)?' AND f_public=1 ':' AND f_public=0 ';
if ($admin_mode == 1)
$dl_stats .= '<p style="text-align:center;width:120px; padding:2px; background-color:#FF3300; color:white;">admin mode</p>';
if (strtoupper($stat_type) == 'TOP10')
{
$sql_limit = ' LIMIT 10';
}
else
{
$sql_where .= (strpos($stat_type, '%') === false)?' AND f_name = "'.$stat_type.'" ':' AND f_name LIKE "'.$stat_type.'" ';
$sql_limit = '';
}
$sql = "SELECT
f_name,
SUM(f_dlfinal) AS dw_count,
SUM(ROUND(f_size*f_dlfinal/1024, 2)) AS traffic
FROM ".DB_PREPEND."phpwcms_file
WHERE f_dlfinal > 0 ".
$sql_where.
" GROUP BY f_name
ORDER BY dw_count DESC ".
$sql_limit;
if($result = @mysql_query($sql, $db) or die ("error while retrieving file download infos<br>".mysql_error($db)) )
{
if (strtoupper($stat_type) == 'TOP10')
{
$captions = explode("|", $frmtstring[$tablecaptions]);
$dl_stats .= '<table class="top10table">';
if (count($captions) > 1)
for ($i = 0; $i <= count($captions)-1; $i++)
{
$dl_stats .= '<td class="top10tablecaption">'.$captions[$i].'</td>';
}
$rowno = 1;
while ($row = mysql_fetch_assoc($result))
{
$dl_stats .= '<tr>';
$row['number'] = $rowno;
$columns = explode("|", str_replace($placeholders, $row, $frmtstring[$outputstr] ));
for ($i = 0; $i <= count($columns)-1; $i++)
{
$dl_stats .= '<td class="top10tablecell_'.$i.'">'.$columns[$i].'</td>';
}
$rowno ++;
$traffic_total += $row['traffic'];
$dl_stats .= '</tr>';
}
$dl_stats .= '</table>';
}
else
{
$rowno = 1;
while ($row = mysql_fetch_assoc($result))
{
$row['number'] = $rowno;
$dl_stats .= str_replace($placeholders, $row, $frmtstring[$outputstr]);
$rowno ++;
$traffic_total += $row['traffic'];
}
}
}
if (strtoupper($stat_type) == 'TOP10')
{
$dl_stats .= '<p style="margin-top:10px; font-weight:bold;">Total Traffic: '.$traffic_total.'kb</p>';
}
}
else $dl_stats = NO_STATS;
return html_parser($dl_stats);
}
// -------------------------------------------------------------
$content["all"] = preg_replace('/\{DOWNLOAD_STAT:(.*?):(.*?):(.*?):(.*?):(.*?)\}/ie', 'get_downloadstats("$1", "$2", "$3", "$4", "$5", $db);', $content["all"]);
// -------------------------------------------------------------
?>