MOD Lightbox Limit for version 1.7.6This mod allows you to limit the size of all users lightboxes by either total number of images or size of download zip file
This mod does not work on Remote files, I do not use them on my site and have not had the time to research that part of it.
NOTE: the notes with BIG folder references in the function file, you need to change the /big/ to whatever you are using for your big folder.
if you are not using a big folder mod, it should just skip that code and continue if it does not find a big folder.
I do not know if it will work on older version or not.Please backup the following files and your database so things can be fixed easly in case something goes wrong
Modified files includelightbox.php
globals.php
includes/functions.php
lang/english/main.php
Your template/lightbox.html
also you will need to run the attached lightbox_limit_install.php file in the root of your 4images gallery so it can add the new field to your lightbox database
or you can add it yourself by running this command in your phpadmin
ALTER TABLE `4images_lightboxes` ADD `lightbox_file_size` INT(11) NOT NULL DEFAULT '0'
Make sure you delete the lightbox_limit_install.php file from your root folder after you run it!The changes that need to be made in the functions file was tricky and mistakes can be made easly,
so I am just having you replace the entire lightbox functions with the ones I modified.
If you have other mods inside these functions, (add_to_lightbox, remove_from lightbox, clear_lightbox)
you may want to look at my replacing functions file and just put my mods inside of your files,
all my modified lines have "\\ Mod Lightbox Limit" labeled on them.
in
includes/functions.phpsearch for...
function add_to_lightbox($id) {
global $user_info, $site_db;
$id = intval($id);
if (!$id) {
return false;
}
$lightbox_ids = $user_info['lightbox_image_ids'];
$lightbox_array = explode(" ", $lightbox_ids);
if (!in_array($id, $lightbox_array)) {
$lightbox_ids .= " ".$id;
}
$user_info['lightbox_image_ids'] = trim($lightbox_ids);
$user_info['lightbox_lastaction'] = time();
$sql = "UPDATE ".LIGHTBOXES_TABLE."
SET lightbox_lastaction = ".$user_info['lightbox_lastaction'].", lightbox_image_ids = '".$user_info['lightbox_image_ids']."'
WHERE user_id = ".$user_info['user_id'];
return ($site_db->query($sql)) ? 1 : 0;
}
function remove_from_lightbox($id) {
global $user_info, $site_db;
$lightbox_array = explode(" ",$user_info['lightbox_image_ids']);
foreach ($lightbox_array as $key => $val) {
if ($val == $id) {
unset($lightbox_array[$key]);
}
}
$user_info['lightbox_image_ids'] = trim(implode(" ", $lightbox_array));
$user_info['lightbox_lastaction'] = time();
$sql = "UPDATE ".LIGHTBOXES_TABLE."
SET lightbox_lastaction = ".$user_info['lightbox_lastaction'].", lightbox_image_ids = '".$user_info['lightbox_image_ids']."'
WHERE user_id = ".$user_info['user_id'];
return ($site_db->query($sql)) ? 1 : 0;
}
function clear_lightbox() {
global $user_info, $site_db;
$current_time = time();
$sql = "UPDATE ".LIGHTBOXES_TABLE."
SET lightbox_image_ids = '', lightbox_lastaction = $current_time
WHERE user_id = ".$user_info['user_id'];
if ($site_db->query($sql)) {
$user_info['lightbox_image_ids'] = "";
$user_info['lightbox_lastaction'] = $current_time;
return true;
}
else {
return false;
}
}
Replace with...
function add_to_lightbox($id) {
global $user_info, $site_db;
global $lightbox_max_number_images, $lightbox_max_file_size; // Mod Lightbox Limit
$id = intval($id);
if (!$id) {
return false;
}
$lightbox_ids = $user_info['lightbox_image_ids'];
$lightbox_array = explode(" ", $lightbox_ids);
// Mod Lightbox Limit check if max # images reached
if ($lightbox_max_number_images){
$lightbox_count = count($lightbox_array);
if ($lightbox_count == $lightbox_max_number_images){
return false; // would like to see a dialog popup saying max # images reached????
}
}
// End Mod Lightbox Limit
if (!in_array($id, $lightbox_array)) {
// Mod Lightbox Limit check size of lightbox zip file
$sql = "SELECT cat_id, image_media_file
FROM ".IMAGES_TABLE."
WHERE image_id = '".$id."'" ;
$image_info = $site_db->query_firstrow($sql);
if (file_exists(MEDIA_PATH."/".$image_info[cat_id]."/big/".$image_info['image_media_file'])){ // replace big with your big folder lookup
$path = MEDIA_PATH."/".$image_info[cat_id]."/big/".$image_info['image_media_file'];} //use big folder image if found
else {$path = MEDIA_PATH."/".$image_info[cat_id]."/".$image_info['image_media_file'];}
$size = filesize($path);
$max_file_size = $lightbox_max_file_size * 1048576;
if(($user_info['lightbox_file_size'] + $size > $max_file_size) && ($lightbox_max_file_size > 0)){return false;} //would like to see a dialog saying filesize max reached????
$user_info['lightbox_file_size'] += $size;
// End Mod Lightbox Limit
$lightbox_ids .= " ".$id;
}
$user_info['lightbox_image_ids'] = trim($lightbox_ids);
$user_info['lightbox_lastaction'] = time();
// Mod Lightbox Limit(added lighbox_file_size to sql variable)
/*$sql = "UPDATE ".LIGHTBOXES_TABLE."
SET lightbox_lastaction = ".$user_info['lightbox_lastaction'].", lightbox_image_ids = '".$user_info['lightbox_image_ids']."'
WHERE user_id = ".$user_info['user_id'];
*/
$sql = "UPDATE ".LIGHTBOXES_TABLE."
SET lightbox_lastaction = ".$user_info['lightbox_lastaction'].", lightbox_image_ids = '".$user_info['lightbox_image_ids']."', lightbox_file_size = '".$user_info['lightbox_file_size']."'
WHERE user_id = ".$user_info['user_id'];
// End Mod Lightbox Limit
return ($site_db->query($sql)) ? 1 : 0;
}
function remove_from_lightbox($id) {
global $user_info, $site_db;
$lightbox_array = explode(" ",$user_info['lightbox_image_ids']);
foreach ($lightbox_array as $key => $val) {
if ($val == $id) {
unset($lightbox_array[$key]);
// Mod Lightbox Limit
$sql = "SELECT cat_id, image_media_file
FROM ".IMAGES_TABLE."
WHERE image_id = '".$id."'" ;
$image_info = $site_db->query_firstrow($sql);
if (file_exists(MEDIA_PATH."/".$image_info[cat_id]."/big/".$image_info['image_media_file'])){ // your big folder lookup
$path = MEDIA_PATH."/".$image_info[cat_id]."/big/".$image_info['image_media_file'];} //use big folder image if found
else {$path = MEDIA_PATH."/".$image_info[cat_id]."/".$image_info['image_media_file'];}
$size = filesize($path);
$user_info['lightbox_file_size'] = $user_info['lightbox_file_size'] - $size;
if ($user_info['lightbox_file_size']<0){$user_info['lightbox_file_size']=0;}
// End Mod Lightbox Limit
}
}
$user_info['lightbox_image_ids'] = trim(implode(" ", $lightbox_array));
$user_info['lightbox_lastaction'] = time();
// Mod Lightbox Limit (Added lightbox_file_size to sql variable)
/*$sql = "UPDATE ".LIGHTBOXES_TABLE."
SET lightbox_lastaction = ".$user_info['lightbox_lastaction'].", lightbox_image_ids = '".$user_info['lightbox_image_ids']."'
WHERE user_id = ".$user_info['user_id'];
*/
$sql = "UPDATE ".LIGHTBOXES_TABLE."
SET lightbox_lastaction = ".$user_info['lightbox_lastaction'].", lightbox_image_ids = '".$user_info['lightbox_image_ids']."', lightbox_file_size = '".$user_info['lightbox_file_size']."'
WHERE user_id = ".$user_info['user_id'];
// End Mod Lightbox Limit
return ($site_db->query($sql)) ? 1 : 0;
}
function clear_lightbox() {
global $user_info, $site_db;
$current_time = time();
// Mod Lightbox Limit
/*$sql = "UPDATE ".LIGHTBOXES_TABLE."
SET lightbox_image_ids = '', lightbox_lastaction = $current_time
WHERE user_id = ".$user_info['user_id'];
*/
$sql = "UPDATE ".LIGHTBOXES_TABLE."
SET lightbox_image_ids = '', lightbox_lastaction = $current_time, lightbox_file_size = 0
WHERE user_id = ".$user_info['user_id'];
// End Mod Lightbox Limit
if ($site_db->query($sql)) {
$user_info['lightbox_image_ids'] = "";
$user_info['lightbox_lastaction'] = $current_time;
$user_info['lightbox_file_size'] = 0; //Mod Lightbox Limit
return true;
}
else {
return false;
}
}
in
Lightbox.php file
search for
$site_template->register_vars(array(
"msg" => $msg,
insert before// Mod Lightbox Limit
$zip_file_size = round(($user_info['lightbox_file_size']/1048576),1);
// End Mod Lightbox limit
search for
"lang_lightbox_lastaction" => $lang['lighbox_lastaction'],
insert after// Mod Lightbox Limit
"zip_file_size" => $zip_file_size,
"lightbox_max_number_images" => $lightbox_max_number_images,
"lightbox_max_file_size" => $lightbox_max_file_size,
"lang_lightbox_max_img_1" => $lang[lightbox_max_img_1],
"lang_lightbox_max_img_2" => $lang[lightbox_max_img_2],
"lang_lightbox_max_zip_1" => $lang[lightbox_max_zip_1],
"lang_lightbox_max_zip_2" => $lang[lightbox_max_zip_2],
// End Mod Lightbox Limit
in
global.php file
NOTE: this is where you will set your limits for the lightboxes
Search for
?>
insert before// Mod Lightbox Limit
$lightbox_max_number_images = 30; //set to 0 for no limt
$lightbox_max_file_size = 15; // is in MB, set to 0 for no limit
// End Mod Lightbox limit
the next 2 files to be modified are not necessary unless you want the limits posted on your lightbox pages.
See attached screenshot.jpg if you want to decide if you want to see this or not.
in
lang/english/main.php file
search for
?>
insert before// Mod Lightbox Limit
$lang['lightbox_max_img_1'] = "(You can choose up to ";
$lang['lightbox_max_img_2'] = " items for your lightbox)";
$lang['lightbox_max_zip_1'] = " Meg zip file is maximun allowed.<br>Your current zip file size is around ";
$lang['lightbox_max_zip_2'] = " Megs";
// End Mod Lightbox Limit
This mod may depend on your own template, this is just a reference for placing...
in
template/lightbox.html file
search for
<b class="title">{lang_lightbox}</b>
replace with<b class="title">{lang_lightbox}</b>{if lightbox_max_number_images} {lang_lightbox_max_img_1}{lightbox_max_number_images}{lang_lightbox_max_img_2}{endif lightbox_max_number_images}
search for
<td align="right">{download_button}
replace with<td align="right">{download_button}{if lightbox_max_file_size}<br>{lightbox_max_file_size}{lang_lightbox_max_zip_1}{zip_file_size}{lang_lightbox_max_zip_2}{endif lightbox_max_file_size}
The only drawback to this mod is that if you reach the limit it just shows "error adding image" on page refresh...
But if you are like me and using V@no MOD Add/Remove image to/from lightbox without page refresh
http://www.4homepages.de/forum/index.php?topic=5321.0all you will get when limit reached is "you are unable to check the checkbox"
I have added in the // area the words "would like to see" where I feel a dialog or something should popup and tell the user they reached the limit on thier lightbox but I have tried a few tricks I know and they did not work.
Hopefully someone else can add to this mod and really make it nice!
I want to thank everyone that PMed me with ideas and the help along the way, I just took all the ideas and cleaned things up and made it look as good as I could.
Enjoy!
Buddy Duke