Page 1 of 1

{DOWNLOAD_STAT} Replacement Tag

Posted: Thu 13. Apr 2006, 17:13
by erich_k4
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
-----------------------------------------------------

Posted: Tue 25. Jul 2006, 00:48
by MadDoctor
cool mod, thanks erich!

Posted: Tue 25. Jul 2006, 04:48
by selbaer
thx. it's working great :mrgreen:

Posted: Tue 25. Jul 2006, 09:54
by Rahner
Fine!
Nice Work, easy to setup and easy to use.
PS: It'w working in Pre 1.2.7 :wink:

Posted: Tue 25. Jul 2006, 20:07
by isac
thank you. well done :D

Posted: Sun 10. Sep 2006, 11:45
by igs
really stupid question - where do i put the code??
i tried to add different mods to an article, but PHP Variable does not display anything and the rest do not work either...

Re: {DOWNLOAD_STAT} Replacement Tag

Posted: Sun 10. Sep 2006, 12:39
by Ati
-----------------------------------------------------
INSTALL: copy the file downloads_stats.php to phpwcms_template\inc_script\frontend_render
-----------------------------------------------------
Isn´t it the answer on the Questions ?
[/quote]

Posted: Tue 12. Sep 2006, 03:31
by igs
the answer was, that the stats are not displayed until someone actually downloaded the file in full!!!

it took a while to figure out.

if the file has not been downloaded, it would be better to show a zero-traffic, instead of simply not displaying it at all.

Posted: Tue 26. Sep 2006, 18:09
by igs
ps - the stats do not seem to work if download managers are used...

apparently, file cc63.rar downloaded 9416 times, traffic 4245599255.91 kb (in 3 days)

but i think around 500-600 people only downloaded it. According to website traffic anyway.

Posted: Thu 22. Nov 2007, 10:18
by nuserXP
Keiner der o.a. Links funktioniert mehr. Bin dennoch auf der Suche nach einer Möglichkeit z.B. die Top 10 Downloads anzuzeigen.

Gibt es eine aktuelle Lösung?

Posted: Sat 24. Nov 2007, 18:02
by phalancs
Hallo, keiner der Links funzt. Hat jemand den Code?

Posted: Sat 24. Nov 2007, 18:58
by juergen
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"]);
  // -------------------------------------------------------------
?>

Posted: Sat 24. Nov 2007, 20:56
by phalancs
muy danke mister man ;)

Posted: Mon 26. Nov 2007, 09:28
by nuserXP
Danke.