Welcome, Guest. Please Login or Register.
November 01, 2024, 11:36:42 PM
Home Help Search Log in Register
News: SMF is the next generation in forum software, almost completely re-written from the ground up, make sure you don't fall for cheap imitations that suffer from feature bloat!

YaBB SE Community  |  Development  |  Completed mods  |  Time limit the attachment uploading « previous next »
Pages: [1] Reply Ignore Print
Author Topic: Time limit the attachment uploading  (Read 1144 times)
fractalbit
Noobie
*
Posts: 18


I'm a llama!

Time limit the attachment uploading
« on: July 02, 2003, 12:01:22 PM »
Reply with quote

Well, this is not exactly a mod as i dont have the knowledge to make it. I actually never have installed a mod before as i always make changes to the code manually.

I have developed a function that can limit the uploading of attachments. It takes 2 parameters. You set the number of attachments that the user is allowed to post in a X period of time. For example you can tell it to let users upload a maximum of 3 photos over a period of 6 days, or any combination you like.

If you are interested i can post the function and the modifications required to make this work (it's not very complicated). I am not doing so now because a) i dont know if i am posting this in the right forum and b) i dont know if other people are interested in this.
Logged
1979Z28
Sr. Member
****
Posts: 324


WWW
Re:Time limit the attachment uploading
« Reply #1 on: July 02, 2003, 01:55:23 PM »
Reply with quote

I'd be interested in this, I've got a few members who are post whores, and like to upload a lot of files ;D
« Last Edit: July 02, 2003, 01:56:36 PM by 1979Z28 » Logged
fractalbit
Noobie
*
Posts: 18


I'm a llama!

Re:Time limit the attachment uploading
« Reply #2 on: July 02, 2003, 04:38:50 PM »
Reply with quote

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 ;D

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 :)
« Last Edit: July 02, 2003, 04:52:21 PM by fractalbit » Logged
Pages: [1] Reply Ignore Print 
YaBB SE Community  |  Development  |  Completed mods  |  Time limit the attachment uploading « previous - next »
 


Powered by MySQL Powered by PHP YaBB SE Community | Powered by YaBB SE
© 2001-2003, YaBB SE Dev Team. All Rights Reserved.
SMF 2.1.4 © 2023, Simple Machines
Valid XHTML 1.0! Valid CSS

Page created in 0.045 seconds with 21 queries.