Before the hack we had "Download limit" mod, I belive it was made by rproctor
: At that time I didnt need such mod, so I didnt install it, and now its lost after the hack...
Here is my version of that mod. With this mod admin can set download limit per
XX hours. The
XX time begin count after first image download.
Tested on 4images v1.7 - v1.7.6
----------- [ Changed files ] -------------details.php
download.php
admin/settings.php
includes/db_field_definitions.php
includes/page_header.php
includes/sessions.php
lang/<your language>/admin.php
lang/<your language>/main.php
templates/<your template>/details.html (or any other template)
------------- [ Installation ] --------------NOTE: if you see a 4images version number next to a step, it means, that particular step meant for that 4images version only and if you have different version, you should skip this step and see if next step is for your version.Step 1Open
details.phpFind:
show_image($image_row, $mode, 0, 1);
Insert
↑ABOVE↑:
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT
*/
if ($msg_error = $site_sess->get_session_var("msg_error"))
{
$msg .= ((empty($msg)) ? "" : "<br />").stripslashes($msg_error);
$site_sess->drop_session_var("msg_error");
}
/*
MOD DOWNLOAD LIMIT
END INSERT
*/
Step 2Open
download.phpFind:
$user_access = get_permission();
Insert
↓BELOW↓:
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT
*/
$dl = 0;
function check_dl_limit($dl)
{
global $user_info, $config;
if ($user_info['user_level'] != ADMIN && $user_info['user_dl_limit'] != -1 && $user_info['user_dl_limit'] && time() - $user_info['user_dl_time'] <= 60*60*$config['user_dl_time'] && $user_info['user_dl_count'] + $dl >= $user_info['user_dl_limit'])
{
return false;
}
elseif ($user_info['user_level'] != ADMIN && $user_info['user_dl_limit'] != -1 && $user_info['user_dl_limit'] && time() - $user_info['user_dl_time'] > 60*60*$config['user_dl_time'] && $dl >= $user_info['user_dl_limit'])
{
return false;
}
return true;
}
function update_dl_limit($dl)
{
global $user_info, $site_db, $site_sess, $config;
if ($user_info['user_level'] == ADMIN) return;
$time = time();
if (!$user_info['user_dl_time'] || $time - $user_info['user_dl_time'] > 60*60*$config['user_dl_time'])
{
$time_sql = ", user_dl_time = ".$time;
$user_info['user_dl_count'] = $dl;
$user_info['user_dl_time'] = $time;
}
else
{
$time_sql = "";
$user_info['user_dl_count'] += $dl;
}
if ($user_info['user_level'] > GUEST)
{
$sql = "UPDATE ".USERS_TABLE."
SET user_dl_count = ".$user_info['user_dl_count'].$time_sql."
WHERE user_id = ".$user_info['user_id'];
$site_db->query($sql);
}
$site_sess->set_cookie_data('data', base64_encode($user_info['user_dl_count']." ".$user_info['user_dl_time']), 1, 60*60*$config['user_dl_time']);
}
/*
MOD DOWNLOAD LIMIT
END INSERT
*/
Step 2.1Find:
while ($image_row = $site_db->fetch_array($result)) {
Insert
↓BELOW↓:
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT
*/
if (!check_dl_limit($dl)) break;
/*
MOD DOWNLOAD LIMIT
END INSERT
*/
Step 2.2Find:
$file_added = 1;
Insert
↑ABOVE↑:
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT
*/
$dl++;
/*
MOD DOWNLOAD LIMIT
END INSERT
*/
Step 2.3 (
v1.7/v1.7.1)
Find:
$file['file_size'] = strlen($file['file_data']);
}
else {
header("Location: ".$site_sess->url($url, "&"));
Replace it with:
/*
MOD DOWNLOAD LIMIT
END ORIGINAL CODE BLOCK
*/
/*
MOD DOWNLOAD LIMIT
BEGIN REPLACE
*/
$file['file_size'] = strlen($file['file_data']);
}
else {
if (!check_dl_limit(0))
{
$site_sess->set_session_var("msg_error", addslashes($lang['dl_limit_reached']));
}
header("Location: ".$site_sess->url($url, "&"));
/*
MOD DOWNLOAD LIMIT
END REPLACE
*/
Step 2.3 (
v1.7.2)
Find:
$file['file_data'] = $zipfile->send(time().".zip");
exit;
}
else {
redirect($url);
Replace with:
/*
MOD DOWNLOAD LIMIT
BEGIN REPLACE
*/
$file['file_data'] = $zipfile->send(time().".zip");
exit;
}
else {
if (!check_dl_limit(0))
{
$site_sess->set_session_var("msg_error", addslashes($lang['dl_limit_reached']));
}
redirect($url);
/*
MOD DOWNLOAD LIMIT
END REPLACE
*/
Step 2.3 (
v1.7.6)
Find:
redirect("lightbox.php?empty=1");
Insert
↑ABOVE↑:
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT ABOVE
*/
if (!check_dl_limit(0))
{
$site_sess->set_session_var("msg_error", addslashes($lang['dl_limit_reached']));
}
/*
MOD DOWNLOAD LIMIT
END INSERT ABOVE
*/
Step 2.4 (
v1.7/v1.7.1)
Find:
$remote_url = 0;
Insert
↑ABOVE↑:
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT
*/
if (!check_dl_limit(0))
{
$site_sess->set_session_var("msg_error", addslashes($lang['dl_limit_reached']));
header("Location: ".$site_sess->url($url, "&"));
exit;
}
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT
*/
Step 2.4 (
v1.7.2 - v1.7.x)
Find:
$remote_url = 0;
Insert
↑ABOVE↑:
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT
*/
if (!check_dl_limit(0))
{
$site_sess->set_session_var("msg_error", addslashes($lang['dl_limit_reached']));
redirect($url);
exit;
}
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT
*/
Step 2.5 (
v1.7/v1.7.1)
Find:
if (!empty($file['file_path'])) {
Insert
↓BELOW↓:
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT
*/
$dl++;
/*
MOD DOWNLOAD LIMIT
END INSERT
*/
Step 2.5 (
v1.7.2 - v1.7.x)
Find:
if (!empty($file['file_path'])) {
Insert
↓BELOW↓:
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT
*/
$dl++;
update_dl_limit($dl);
/*
MOD DOWNLOAD LIMIT
END INSERT
*/
Step 2.6 (
v1.7/v1.7.1)
Find:
if ($remote_url) {
Insert
↓BELOW↓:
/*
MOD DOWNLOAD LIMIT
START INSERT
*/
update_dl_limit($dl);
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT
*/
Step 2.7 (
v1.7/v1.7.1)
Find:
if (!empty($file['file_data'])) {
Insert
↓BELOW↓:
/*
MOD DOWNLOAD LIMIT
START INSERT
*/
update_dl_limit($dl);
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT
*/
Step 2.8Find:
if ($file_added) {
Insert
below::
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT
*/
update_dl_limit($dl);
/*
MOD DOWNLOAD LIMIT
END INSERT
*/
Step 3Open
admin/settings.phpFind:
show_form_footer($lang['save_changes'], "", 2);
Insert
↑ABOVE↑:
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT
*/
show_table_separator($setting_group[XX], 2, "#setting_group_XX");
show_setting_row("user_dl_limit");
show_setting_row("user_dl_time");
/*
MOD DOWNLOAD LIMIT
END INSERT
*/
Replace
XX with 8 if u havent install any mods that changed this file, othwise look up the number in the the last section that starts with
show_table_separator($setting_group[ and add one to that number.
Write down that number, you will needed it in another step!
Step 4Open
includes/db_field_definitions.phpAt the end,
↑ABOVE↑ closing
?> insert:
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT
*/
$additional_user_fields['user_dl_limit'] = array(&$lang['user_dl_limit'], "text", 0);
$additional_user_fields['user_dl_time'] = array($lang['user_dl_time'], "text", 0);
$additional_user_fields['user_dl_count'] = array($lang['user_dl_count'], "text", 0);
/*
MOD DOWNLOAD LIMIT
END INSERT
*/
Step 5Open
includes/page_header.phpFind first entry of:
$site_template->register_vars(array(
Insert
↑ABOVE↑:
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT
*/
$left = "";
if ($user_info['user_level'] == ADMIN || $user_info['user_dl_limit'] == -1)
{
$dl_limit = $lang['user_dl_limit_unlimited'];
}
else
{
$t = ($config['user_dl_time']*60*60) - (time() - $user_info['user_dl_time']);
if ($t > 0)
{
$years = floor($t/31536000);
$days = floor(($t %= 31536000)/86400);
$hours = floor(($t %= 86400)/3600);
$minutes = floor(($t %= 3600)/60);
$seconds = $t %= 60;
$t = array($years, $days, $hours, $minutes, $seconds);
$s = 0;
for ($i = 0; $i < 5; $i++) {
if ($t[$i]) {
$left .= $t[$i]." ".$lang['dates_short'][($t[$i] != 1)][$i];
$s++;
$c = 0;
for ($j = $i + 1; $j < 5; $j++) {
if ($t[$j]) $c++;
}
$left .= " ";
}
}
$left = trim ($left, " ");
}
if ($user_info['user_dl_limit'] > $user_info['user_dl_count'] || !$left)
{
$dl_limit = preg_replace("/".$site_template->start."dlcount".$site_template->end."/siU", $user_info['user_dl_count'], preg_replace("/".$site_template->start."dltottal".$site_template->end."/siU", $user_info['user_dl_limit'], preg_replace("/".$site_template->start."dltime".$site_template->end."/siU", $left, $lang['user_dl_limit_status'])));
}
else
{
$dl_limit = preg_replace("/".$site_template->start."dltime".$site_template->end."/siU", $left, $lang['user_dl_limit_reached']);
}
}
$site_template->register_vars(array(
"user_dl_count" => ($user_info['user_dl_limit'] == -1) ? 0 : $user_info['user_dl_count'],
"user_dl_time" => $left,
"user_dl_limit" => $dl_limit
));
/*
MOD DOWNLOAD LIMIT
END INSERT
*/
Step 6Open
includes/sessions.phpFind:
$this->delete_old_sessions();
}
}
Insert
↓BELOW↓:
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT
*/
global $config;
if ($this->user_info['user_level'] > GUEST)
{
if (!$this->user_info['user_dl_limit'] && $this->user_info['user_dl_limit'] != -1)
{
$this->user_info['user_dl_limit'] = $config['user_dl_limit'];
}
if (!$this->user_info['user_dl_time'])
{
$this->user_info['user_dl_time'] = 0;
}
}
if ($dl = $this->read_cookie_data('data'))
{
$dl = explode(" ", base64_decode($dl));
if (isset($dl[1]) && $dl[1] && $config['user_dl_time']*60*60 > (time() - $dl[1]))
{
$this->user_info['user_dl_time'] = $dl[1];
$this->user_info['user_dl_count'] = (isset($dl[0]) && $dl[0]) ? $dl[0] : 0;
}
else
{
$this->user_info['user_dl_time'] = 0;
$this->user_info['user_dl_count'] = 0;
}
}
elseif ($this->user_info['user_level'] == GUEST)
{
$this->user_info['user_dl_count'] = 0;
$this->user_info['user_dl_time'] = 0;
}
if ($this->user_info['user_level'] == GUEST)
{
$this->user_info['user_dl_limit'] = $config['user_dl_limit'];
}
/*
MOD DOWNLOAD LIMIT
END INSERT
*/
Make sure you inserted the code below two closing brackets and one last (third) bracket must be at the end of the inserted code!
Step 7Open
lang/<your language>/admin.phpAt the end,
↑ABOVE↑ closing
?> insert:
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT
*/
/*-- Setting-Group XX --*/
$setting_group[XX]="User download limit";
$setting['user_dl_limit'] = "Download limit<span class=\"smalltext\"><br />set to <font color=red><b>0</b></font> for unlimited</span>";
$setting['user_dl_time'] = "Reset time<span class=\"smalltext\"><br />(in hours)</span>";
$lang['user_dl_limit'] = "Download limit<span class=\"smalltext\"><br />set to <font color=red><b>0</b></font> to use global settings<br>or <font color=red><b>-1</b></font> for unlimited</span>";
$lang['user_dl_time'] = "Start time";
$lang['user_dl_count'] = "Download count";
/*
MOD DOWNLOAD LIMIT
END INSERT
*/
Replace
XX with the number from
Step 3
Step 8Open
lang/<your language>/main.phpAt the end,
↑ABOVE↑ closing
?> insert:
/*
MOD DOWNLOAD LIMIT
BEGIN INSERT
*/
$lang['user_dl_limit'] = "Download limit";
$lang['user_dl_time'] = "Start time";
$lang['user_dl_count'] = "Downloads count";
$lang['user_dl_limit_reached'] = "Your download quota per ".$config['user_dl_time']." hours has been reached. You won't be able download for next {dltime}";
$lang['user_dl_limit_unlimited'] = "Your download quota is unlimited";
$lang['user_dl_limit_status'] = "You have downloaded {dlcount} of {dltottal} files, allowed per ".$config['user_dl_time']." hours";
$lang['dl_limit_reached'] = "Sorry, you've reached the download limit per ".$config['user_dl_time']." hours";
$lang['dates_short'] = array(
array("yr", "day", "hr", "min", "sec"),
array("yrs", "days", "hrs", "min", "sec")
);
/*
MOD DOWNLOAD LIMIT
END INSERT
*/
Step 9Open
templates/<your template>/details.html (or any other template, i.e. user_loginform.html/user_logininfo.html)
Insert
{user_dl_limit} tag in the place you want to display to the visitors the information about their download limit status. (design is your job
)
Step 10Download
this installer.
Unpack it and upload
dl_limit_install.php file into your 4images root dir.
Execute the installer by typing in your browser's address bar:
http://yoursiteaddress/path/to/4images/dl_limit_install.php (make sure you've logged in as admin, otherwise it will not work)
NOTE: during the database installation u might see some "warning" messages on top of the page, that is normal and they should go away after the database updated.