Quote from: 1979Z28 on July 02, 2003, 01:55:23 PM
I'd be interested in this, I've got a few members who are post whores, and like to upload a lot of files
Lol, this is exactly why i coded this function. Some abused the very usefull feature of uploading and we had to stop offering this functinality until i coded this.
EDIT :
The following instructions only apply to version 1.5.4 of yabbse. You can implement it in other versions but you have to figure it out yourself how to do it.First of all, i am not responsible if you mess up your forum. First take a backup of post.php and use the modification at your own risk. Now on to the code ...
# Time Limit the photo uploading function
# Added by [email protected]
function limit_uploading($limit, $howmany){
// More on the functionality of this function later ...
global $ID_MEMBER, $settings;
function get_time(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$allow = TRUE;
$is_mod = FALSE;
if($settings[7] == "Administrator" || $settings[7] == "Moderator" || $settings[7] == "Global Moderator")
$is_mod = TRUE;
//$is_mod = FALSE;
if(!$is_mod){
$hours = $limit;
$days = floor($limit/24);
$hours = $limit - $days * 24;
$mins = 0;
$more = $howmany;
$limit = $limit * 60 * 60; //in seconds
$current_time = time();
$timelim = $current_time - $limit;
$query = "SELECT attachmentFilename, posterTime FROM yabbse_messages WHERE (ID_MEMBER=$ID_MEMBER AND posterTime>$timelim) ORDER BY posterTime DESC";
$results = mysql_query($query);
$x = 0;
while($data = mysql_fetch_row($results)):
if($data[0] != ""){
$x++;
//if($x == 1) $last_upload = $data[1];
$first_upload = $data[1];
}
endwhile;
if(isset($first_upload)){
$t = $current_time - $first_upload;
$remaining = $limit - $t;
if($x>=$howmany) $allow = FALSE;
$more = $howmany - $x;
$totalmins = round($remaining / 60);
$mins = ($totalmins % 60);
$totalhours = $totalmins / 60;
$days = floor($totalhours/24);
$hours = floor($totalhours - $days * 24);
}
}
return array($allow, $days, $hours, $mins, $more, $is_mod);
}
You should copy this function in the start of your Post.php (or somewhere else but not inside another function).
Second, you must call the function inside the post() function. Search for and find the first line that looks like this :
printPostBox($form_message);
Now, below this add the following code :
// Added by fractalbit
list($allow_photo, $rem_days, $rem_hours, $rem_mins, $un_more, $un_is_mod) = limit_uploading(144, 3);
if($allow_photo) :
$un_info = "You can upload $un_more more photos for the folowing $rem_days days $rem_hours hours and $rem_mins minutes";
else :
$un_info = "You cannot upload any more photos unless $rem_days days. $rem_hours hours and $rem_mins minutes have passed";
endif;
if($un_is_mod) $un_info = "";
//EOM
There is one more final change you should do. i am posting the full code there is in that spot in post.php and the changes you have to make are in bold :
$attachmentFields = '';
if($allow_photo){ if ($modSettings['attachmentEnable'] == 1)
$attachmentFields = '
<tr><td colspan=2 align=center>' . $un_info . '</td></tr> <tr>
<td align="right" valign="top">
<font size="2"><b>' . $txt['yse119'] . ':</b></font><br /><br />
</td>
<td>
<input type="file" size="48" name="attachment" onchange="updateFields();" /><br />
<font size="1">' . $txt['yse120'] . ': ' . $modSettings['attachmentExtensions'] . '<br />
' . $txt['yse121'] . ': ' . $modSettings['attachmentSizeLimit'] . ' KB</font>
<input type="hidden" name="attachmentp" value="" /><br /><br />
</td>
</tr>';
}
else{
$attachmentFields = "<tr><td colspan=2 align=center>$un_info</td></tr>";
} if ($username == 'Guest' && $modSettings['attachmentEnableGuest'] == 0)
$attachmentFields = '';
Thats all. Now some explanations about the use of the function.
The most important part is to set the limit you wish by changing the values in the call of the limit_uploading function:
list($allow_photo, $rem_days, $rem_hours, $rem_mins, $un_more, $un_is_mod) = limit_uploading(144, 3);
The first argument is the X period of time in
hours. The second is the number of allowed uploads for this X period of time.
As it currently stands the limit is a maximum of 3 uploads for a period of 6(=144/24) days. Modify this to your will.
The function excludes from the limit the mods, Global mods and admins. You can exclude other membergroyps from the limit by modifying this line :
if($settings[7] == "Administrator" || $settings[7] == "Moderator" || $settings[7] == "Global Moderator")
You can also include a membergroup to the limitations by simply removing it from this line. For example make this line like this :
if($settings[7] == "Administrator" || $settings[7] == "Global Moderator")
and the limit will aply to moderators and simple users but not for the admins and global mods.
If you want to modify the mesages that the users gets, change the folowing lines to your wish :
if($allow_photo) :
$un_info = "You can upload $un_more more photos for the folowing $rem_days days $rem_hours hours and $rem_mins minutes";
else :
$un_info = "You cannot upload any more photos unless $rem_days days. $rem_hours hours and $rem_mins minutes have passed";
endif;
I hope you will find the function as usefull as i have