{DOWNLOAD_STAT} Replacement Tag

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
erich_k4
Posts: 160
Joined: Thu 31. Mar 2005, 10:29
Location: Austria

{DOWNLOAD_STAT} Replacement Tag

Post 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
-----------------------------------------------------
Erich
MadDoctor
Posts: 18
Joined: Tue 25. Jul 2006, 00:46
Contact:

Post by MadDoctor »

cool mod, thanks erich!
selbaer
Posts: 93
Joined: Sun 22. Jan 2006, 02:19
Location: Florida West Coast

Post by selbaer »

thx. it's working great :mrgreen:
Rahner
Posts: 82
Joined: Sat 15. Jul 2006, 18:16

Post by Rahner »

Fine!
Nice Work, easy to setup and easy to use.
PS: It'w working in Pre 1.2.7 :wink:
User avatar
isac
Posts: 410
Joined: Tue 18. Nov 2003, 13:13
Location: Portugal
Contact:

Post by isac »

thank you. well done :D
POR :D TUGAL
igs
Posts: 9
Joined: Sat 9. Sep 2006, 22:41

Post 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...
Ati
Posts: 50
Joined: Fri 19. May 2006, 20:09
Contact:

Re: {DOWNLOAD_STAT} Replacement Tag

Post 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]
"Seien wir realistisch - versuchen wir das Unmögliche" (Chè Guevara)
igs
Posts: 9
Joined: Sat 9. Sep 2006, 22:41

Post 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.
igs
Posts: 9
Joined: Sat 9. Sep 2006, 22:41

Post 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.
nuserXP
Posts: 89
Joined: Mon 28. Mar 2005, 11:37

Post 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?
phalancs
Posts: 793
Joined: Thu 19. Feb 2004, 05:09
Location: Germany

Post by phalancs »

Hallo, keiner der Links funzt. Hat jemand den Code?
2008
User avatar
juergen
Moderator
Posts: 4556
Joined: Mon 10. Jan 2005, 18:10
Location: Weinheim
Contact:

Post 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"]);
  // -------------------------------------------------------------
?>
phalancs
Posts: 793
Joined: Thu 19. Feb 2004, 05:09
Location: Germany

Post by phalancs »

muy danke mister man ;)
2008
nuserXP
Posts: 89
Joined: Mon 28. Mar 2005, 11:37

Post by nuserXP »

Danke.
Post Reply