1

Topic: DownloadMod 1.1

##
##        Mod title:  Download Mod
##
##      Mod version:  1.1
##   Works on PunBB:  1.2.* (tested on 1.2.17)
##     Release date:  2008-03-15
##           Author:  Frank Smit (FSX)
##  Project website:  http://code.google.com/p/downloadmod/
##
##      Description:  Adds a download section to your forum.
##
##       Affects DB:  Yes, the config table and the user table
##
##   Affected files:  functions.php, profile.php
##
##            Notes:  This mod only uses the database for the configuration.
##                    All files are fetched from the download folder.
##
##                    If you uninstall this mod you have to manually remove
##                    the downloads folder.
##
##                    This mod doesn't have an upload function, because it
##                    was orginally build for big files ( > 20Mb ).
##
##                    Force download is done by a .htaccess file.
##                    The contents of the .htaccess file are:
##                    <Files *.*>
##                    ForceType applicaton/octet-stream
##                    </Files>
##
##                    This mod has been tested on PHP5, MySQL5 and Apache2.
##
##          Licence:  GPL 2.0
##
##     Generated By:  Auto Read-Me(by Caleb Champlin) - http://www.rscheatnet.com/Auto_Readme.zip
##
##       DISCLAIMER:  Please note that 'mods' are not officially supported by
##                    PunBB. Installation of this modification is done at your
##                    own risk. Backup your forum database and any and all
##                    applicable files before proceeding.

#
#---------[ CHANGELOG 1.0 to 1.1 ]---------------------------------------------------------------
#

 - Fixed bugs and typo's
 - downloadfile.php removed, download file part is added in download.php
 - Added log file, logs what files the user downloads (log can be viewed in the plugin)
 - Added search function
 - Changed category menu
 - Force download is now done with a .htaccess file
 - A index.html file is automaticly placed in a new category
 - Filtering files is now done by one function
 - files that begin with a . [dot] or _ [underscore] are handled like hidden files

Here are some screenshots:
http://code.google.com/p/downloadmod/do … Screenshot

Download at Punres:
http://www.punres.org/viewtopic.php?pid=23308#p23308

Project website:
http://code.google.com/p/downloadmod/

Re: DownloadMod 1.1

View download bandwidth in userlist.

[1. FIND AT LINE ~150]
<?php endif; ?>                <th class="tcr" scope="col"><?php echo $lang_common['Registered'] ?></th>

[2. ADD AFTER]
                <th class="tcr" scope="col">Downloaded</th>

[3. FIND AT LINE ~157]
$result = $db->query('SELECT u.id, u.username, u.title, u.num_posts, u.registered, g.g_id, g.g_user_title FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id>1'.(!empty($where_sql) ? ' AND '.implode(' AND ', $where_sql) : '').' ORDER BY '.$sort_by.' '.$sort_dir.' LIMIT '.$start_from.', 50') or error('Unable to fetch user list', __FILE__, __LINE__, $db->error());

[4. REPLACE WITH]
$result = $db->query('SELECT u.id, u.username, u.title, u.num_posts, u.registered, g.g_id, g.g_user_title, u.dl_total_bandwidth FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id>1'.(!empty($where_sql) ? ' AND '.implode(' AND ', $where_sql) : '').' ORDER BY '.$sort_by.' '.$sort_dir.' LIMIT '.$start_from.', 50') or error('Unable to fetch user list', __FILE__, __LINE__, $db->error());

* NOTE: , u.dl_total_bandwidth is added after g.g_user_title

[5. FIND AT LINE ~170]
                    <td class="tcr"><?php echo format_time($user_data['registered'], true) ?></td>

[6. ADD AFTER]
                    <td class="tcl"><?php echo fsize($user_data['dl_total_bandwidth']); ?></td>

I might add a 'sort by total downloaded' option later.

3

Re: DownloadMod 1.1

Cool addition smile, should I put it on the project website wiki?

Re: DownloadMod 1.1

Go for it.

5

Re: DownloadMod 1.1

Here ^^: http://code.google.com/p/downloadmod/wi … InUserlist

Re: DownloadMod 1.1

I don't feel like writing another 'readme' file.

http://pastebin.com/m65675a24

There's the final output.

Re: DownloadMod 1.1

Put the info in your forums' index (where the stats are):

#
#-------------[ 1. Open File ]----------------
#
~/index.php
#
#-------------[ 2. Find (line: ~156)]----
#
$stats['last_user'] = $db->fetch_assoc($result);
#
#-------------[ 3. Add After ]----------------
#

$result = $db->query('SELECT SUM(dl_total_bandwidth) FROM '.$db->prefix.'users') or error('Unable to fetch download bandwidth', __FILE__, __LINE__, $db->error());
$stats['total_downloaded'] = $db->result($result);

#
#-------------[ 4. Find (line: ~171)]----
#
</dl>
#
#-------------[ 5. Add Before ]---------------
#
<dd><?php echo 'Total Download Bandwidth: <strong>'.fsize($stats['total_downloaded']); ?></strong></dd>

Put the bandwidth usage for the user under his avatar in topics.

#
#-------------[ 1. Open File ]----------------
#
~/viewtopic.php
#
#-------------[ 2. Find (line: ~186)]----
#
$result = $db->query('SELECT u.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id INNER JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id LEFT JOIN '.$db->prefix.'online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.topic_id='.$id.' ORDER BY p.id LIMIT '.$start_from.','.$pun_user['disp_posts'], true) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
#
#-------------[ 3. Replace With ]--------------
#
$result = $db->query('SELECT u.dl_total_bandwidth, u.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id INNER JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id LEFT JOIN '.$db->prefix.'online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.topic_id='.$id.' ORDER BY p.id LIMIT '.$start_from.','.$pun_user['disp_posts'], true) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());

#
#-------------[ 4. Find (line: ~321)]----
#
<dd class="postavatar"><?php echo $user_avatar ?></dd>
#
#-------------[ 5. Add After ]----------------
#
<dd class="usertitle"><strong>DLed: <?php echo pun_htmlspecialchars(fsize($cur_post['dl_total_bandwidth'])); ?></strong></dd>

Put the info in the userlist (with the ability to sort by bandwidth)

#
#-------------[ 1. Open File ]----------------
#
~/userlist.php
#
#-------------[ 2. Find (line: ~46)]----
#
$sort_by = (!isset($_GET['sort_by']) || $_GET['sort_by'] != 'username' && $_GET['sort_by'] != 'registered' && ($_GET['sort_by'] != 'num_posts' || !$show_post_count)) ? 'username' : $_GET['sort_by'];
#
#-------------[ 3. Replace With ]--------------
#
$sort_by = (!isset($_GET['sort_by']) || $_GET['sort_by'] != 'username' && $_GET['sort_by'] != 'registered' && $_GET['sort_by'] != 'dl_total_bandwidth' && ($_GET['sort_by'] != 'num_posts' || !$show_post_count)) ? 'username' : $_GET['sort_by'];
#
#-------------[ 4. Find (line: ~88)]----
#
<option value="registered"<?php if ($sort_by == 'registered') echo ' selected="selected"' ?>><?php echo $lang_common['Registered'] ?></option>
#
#-------------[ 5. Add Before ]--------------
#
<option value="dl_total_bandwidth"<?php if ($sort_by == 'dl_total_bandwidth') echo ' selected="selected"' ?>>Downloaded</option>
#
#-------------[ 6. Find (line: ~151)]----
#
</tr>
#
#-------------[ 7. Add Before ]---------------
#
<th class="tcr" scope="col">Downloaded</th>
#
#-------------[ 8. Find (line: ~157)]----
#
$result = $db->query('SELECT u.id, u.username, u.title, u.num_posts, u.registered, g.g_id, g.g_user_title FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id>1'.(!empty($where_sql) ? ' AND '.implode(' AND ', $where_sql) : '').' ORDER BY '.$sort_by.' '.$sort_dir.' LIMIT '.$start_from.', 50') or error('Unable to fetch user list', __FILE__, __LINE__, $db->error());
#
#-------------[ 9. Replace With ]--------------
#
$result = $db->query('SELECT u.id, u.username, u.title, u.num_posts, u.registered, g.g_id, g.g_user_title, u.dl_total_bandwidth FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id>1'.(!empty($where_sql) ? ' AND '.implode(' AND ', $where_sql) : '').' ORDER BY '.$sort_by.' '.$sort_dir.' LIMIT '.$start_from.', 50') or error('Unable to fetch user list', __FILE__, __LINE__, $db->error());

* NOTE: , u.dl_total_bandwidth is added after g.g_user_title
#
#-------------[ 10. Find (line: ~171)]----
#
</tr>
#
#-------------[ 11. Add Before ]---------------
#
<td class="tcl"><?php echo fsize($user_data['dl_total_bandwidth']); ?></td>

8 (edited by FSX 2008-03-25 18:10)

Re: DownloadMod 1.1

I'll put all this modifications in the package with the next version (1.2) and credit you ofcourse. I still have to add language support ^^ and a option to disable the search function. Also some other stuff, check the project site: http://code.google.com/p/downloadmod/ for the new features.

Re: DownloadMod 1.1

I tried this mod and couldnt get it to work. I edited the profile.php file like the read me suggested but I crashed my forum hmm

10

Re: DownloadMod 1.1

What errors do you have?

Re: DownloadMod 1.1

FSX wrote:

I'll put all this modifications in the package with the next version (1.2) and credit you ofcourse. I still have to add language support ^^ and a option to disable the search function. Also some other stuff, check the project site: http://code.google.com/p/downloadmod/ for the new features.


Hello FSX,

I wish things are moving smoothly with the future version 1.2.

While waiting the highly expected support for multilanguage i wanted to ask if that will fix also the filenames containing special chars like é è à etc., which are actually broken.

If the future version  is not planned to come out anytime soon, do u mind sharing a piece of code that can fix the filenames (it goes without saying only if time allows it smile ) ?

Re: DownloadMod 1.1

Please help i have a problem..

Forbidden

You don't have permission to access /forums/downloads/Tracks/SimpleSX_disp.tga on this server.

13

Re: DownloadMod 1.1

Ensure that the Web-server has the permission to write into folder "forums/downloads/Tracks/"