• [MOD] Multi Size Download of same image [ver 4.7] 5 0 5 1
Currently:  

Author Topic: [MOD] Multi Size Download of same image [ver 4.7]  (Read 431379 times)

0 Members and 1 Guest are viewing this topic.

Offline budduke

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • http://www.budduke.com
[MOD] Multi Size Download of same image [ver 4.7]
« on: September 16, 2008, 11:41:46 PM »
[MOD] Multi download size ver 4.7
This MOD will allow your users to download multiple different sizes of one image.
see the attached screenshot to see what it looks like.

* You can modify the sizes in the Global.php file to set the range you want your users to download.
* Added variables in the global.php file for easy customizing of mod for your site.(New to ver 2.1)
* Added variables that you can now set crop settings to get actual size when resizing (New to ver 3.0)
* You can now have text links and image links instead of dropdown list (New to ver 2.1)
* You can select if the catagory uses this option or the normal download/zip option instead.
* You can set the category to only allow sizes smaller then original to be downloaded (New to ver 2.0)
* Original file is an option on the list, if your user does not want it resized. (New to ver 2.0)
* You only need to upload one size of the file and the server will do the rest for you (I am lazy)
  all the other mods I saw wanted you to create all the different sizes before you uploaded them.
  This mod will create the resized images at the time the user is asking for them.
* Also, if nobody ever downloads a 640X480 image then you do not have the extra images on your server.
* The MOD does check to see if it already created the size so it does not have to create it twice.
* If file is not an image you will get the normal download button instead.(New to ver 3.1)
* You can now group the button/links/dropdown for easier navigation. (New to ver 4.0)
* Now instead of downloading the images, you can have a popup window instead if you choose. (New to ver 4.0)
* Have added where it will detect the users screen resolution for easier choosing. (New to ver 4.0)
* added more selections in default list for mobile phones (New to ver 4.0)
* added exact ratio selection taken from original file for size selections. is turned off by default (New to ver 4.2)
* added a template for popup window (New to ver 4.4)

I was having a hard time creating a way to remove the extra files if you delete images/or move them.
I wound up just making a plugin that you run in the admin cp that will erase all resized images from the server.

This MOD was tested on a fresh install of 1.7.11 and everything worked fine

Changes made in Version 4.7
--Fixed a problem where not downloading on mobile devices using the dropdown list.

Changes made in Version 4.6
--Fixed a problem where not displaying image name in popup window.

Changes made in Version 4.5
--Fixed a problem where it was pulling the sizes from the random image instead of the main image on detail page

Changes made in Version 4.4
--I fixed a division by 0 error warning that I was getting with this mod.
--Added template for popup window.
--Added annotation link to resized image (if using that mod)
Changes made in Version 4.3
--I had a major problem with dealing with sessions on my links. They are repaired on this release.
--Good news, you only have to replace the insert in the includes/functions.php file to fix this error.

backup your database in case something goes wrong and also backup these files before you proceed.
I would also suggest using it on a testing site and not your main one in case something crashes
These are the files that will be modified...
details.php
download.php
global.php
admin/categories.php
includes/constants.php
includes/functions.php
lang/english/admin.php
lang/english/main.php
template/your template you are using/details.html

The zip file attached contains the plugin and the installer and the graphic buttons for your site.

The plugin needs to be placed in the
admin/plugins folder

place the multi_download_install.php in your root folder of your gallery and run it once so it can install the
new multi_download field into your categories table.
Make sure you delete it afterward for security.

in the global.php file

look for
Code: [Select]
 $sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcommentreplace with
Code: [Select]
 $sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, multi_download
look for
Code: [Select]
?>insert Before (changed in version 2) (updated in version 4.0) (updated in version 4.2)
Code: [Select]
// MOD multi download
$download_multi_sizes= array(
array('group1',0,0), //Groups are created in this format, group1 name is associated with a language entry with the same name (the 0,0 is important!)
array('800x600',800,600),
array('1024x768',1024,768),
array('1280x960',1280,960),
array('1400x1050',1400,1050),
array('1600x1200',1600,1200),
array('2048x1536',2048,1536),
array('group2',0,0),
array('1280x720',1280,720),
array('1366x768',1366,768),
array('1920x1080',1920,1080),
array('2560x1440',2560,1440),
array('group3',0,0),
array('1280x800',1280,800),
array('1440x900',1440,900),
array('1680x1050',1680,1050),
array('1920x1200',1920,1200),
array('2560x1600',2560,1600),
array('group4',0,0),
array('96x65',96,65),
array('101x80',101,80),
array('128x128',128,128),
array('128x160',128,160),
array('174x132',174,132),
array('240x320',240,320),
array('group5',0,0),
array('240x160',240,160),
array('240x260',240,260),
array('240x240',240,240),
array('320x240',320,240)
);
// the first field is the name that is shown in the list that you choose from
// the second field is the width
// the third field is the height
$multi_download_var['type'] = 0; //0=dropdown, 1=text links, 2=image links
$multi_download_var['columns'] = 4; // #of columns in table for links, not used for dropdown
$multi_download_var['button']="gif"; //type of file for your image link buttons gif,jpg,png
$multi_download_var['bold_groups']=1; //Bold option group labels (only for text links and buttons), 1=yes, 0=no
$multi_download_var['center_groups']=1; //Center option group labels (only for text links and buttons), 1=yes, 0=no
$multi_download_var['show_resolution']=1;// Display user's display resolution, 1=yes, 0=no
$multi_download_var['download']=1; //display "select size to download at top of table" 1=yes, 0=no
$multi_download_var['table']=220; //width of table that will house this MOD, 220 is good for dropdown, 420 is good for others
$multi_download_var['show_table']=1; //show border and shading in back of MOD, 1=yes,0=no
$multi_download_var['show_original']=1; //display "original image" as an option 1=yes, 0=no
$multi_download_var['newline_original']=1; //place 'original size' button on its own line, 1=yes, 0=no
$multi_download_var['center_original']=1; //center 'original size' button with space that is left in row, 1=yes, 0=no
$multi_download_var['alt_image']=1; //Use Alt variable with image links, 1=yes,0=no
$multi_download_var['crop']=0; //crop image after resize  (see below)
/* what crop will do is resize image larger then size that is asked for unless it detects it will resize without and extra space.
then it will crop off the extra area to give you the actual size asked for (loosing part of your image)
0= do not crop
1= crop equally on both sides
2= crop top or left side
3= crop bottom or right side
4= resize and stretch to fit requested size (no crop)
*/
$multi_download_var['quality']= 90; //quality settings for resizing/cropping 10-100 (10=high compression, 100= lowest compression)
$multi_download_var['target']="";// for popup window instead of download replace the quote with  "TARGET = '_blank' "  
// You can also replace _blank with a name like mypopup and then all images will open in same popup window
$multi_download_var['ratio']=0; //Only sizes that fit size ratio of original will be available (must be exact match on ratio!)
// END MOD multi download
this was the original insert for removal purposes if upgrading from beta to ver 2 or above
Code: [Select]
// MOD multi download
$download_multi_sizes= array(
array('640X480',640,480),
array('800X600',800,600),
array('1024X768',1024,768),
array('1280X960',1280,960),
array('1400X1050',1400,1050),
array('1600X1200',1600,1200),
array('1280X800-wide',1280,800),
array('1440X900-wide',1440,900),
array('1680X1050-wide',1680,1050),
array('1920X1200-wide',1920,1200)
);
// the first field is the name that is shown in the list that you choose from
// the second field is the width
// the third field is the height

$multi_download_options_string="<BR><BR>
<form action='".ROOT_PATH.'download.php'."' method='post'>
<table border='0' cellspacing='1' cellpadding='0' width='210'  class='head1'>
<tr><td><table border='0' cellspacing='0' cellpadding='0' width='210' class='row2'><tr>
<td colspan='2' align='center'>".$lang['multi_select']."</TD></TR>
<TR class='row1'><TD><select name='multi_download_select'>";
$var=0;
while ($var < count($download_multi_sizes)){
$multi_download_options_string .="<option value='".$var."'>".$download_multi_sizes[$var][0]."</option>";
$var = $var +1;
}
$multi_download_options_string .="</select>";
// END Multi Download

in the admin/categories.php file

look for
Code: [Select]
$access_array = array(
  AUTH_ALL => $lang['all'],
  AUTH_USER => $lang['userlevel_registered'],
  AUTH_ACL => $lang['private'],
  AUTH_ADMIN => $lang['userlevel_admin']
);

insert after (new for ver2.0)
Code: [Select]
// MOD multi download
function show_radio_row_multi($title, $name, $value = 0) {
  global $HTTP_POST_VARS, $lang, $multi_download_optionlist;
  if (isset($HTTP_POST_VARS[$name])) {
    $value = $HTTP_POST_VARS[$name];
  }
  echo "<tr class=\"".get_row_bg()."\">\n";
  echo "<td><p class=\"rowtitle\">".$title."</p></td>\n<td><p>";
  foreach ($multi_download_optionlist as $key => $val) {
    echo "<input type=\"radio\" name=\"".$name."\" value=\"$key\"";
    if ($value == $key) {
      echo " checked=\"checked\"";
    }
    echo "> ".$val."<br />";
  }
  echo "</p></td>\n</tr>";
}
// END MOD multi download

look for 2 times
Code: [Select]
$auth_postcomment = $HTTP_POST_VARS['auth_postcomment'];insert after Both places
Code: [Select]
// MOD Multi Download
  $multi_download = (isset($HTTP_POST_VARS['multi_download'])) ? intval($HTTP_POST_VARS['multi_download']) : 0;
// END MOD Multi download

look for
Code: [Select]
(cat_name, cat_description, cat_parent_id, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcommentreplace with
Code: [Select]
(cat_name, cat_description, cat_parent_id, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, multi_download
look for
Code: [Select]
('$cat_name', '$cat_description', $cat_parent_id, $cat_order, $auth_viewcat, $auth_viewimage, $auth_download, $auth_upload, $auth_directupload, $auth_vote, $auth_sendpostcard, $auth_readcomment, $auth_postcommentreplace with
Code: [Select]
('$cat_name', '$cat_description', $cat_parent_id, $cat_order, $auth_viewcat, $auth_viewimage, $auth_download, $auth_upload, $auth_directupload, $auth_vote, $auth_sendpostcard, $auth_readcomment, $auth_postcomment, $multi_download
look for
Code: [Select]
 $permission_headline = $lang['permissions'];insert before (changed insert for ver 2.0)
Code: [Select]
// MOD multi download
  $value = intval($cat_row['multi_download']);
  show_radio_row_multi($lang['multi_option'],'multi_download',$value);
// END MOD multi download

look for
Code: [Select]
   $sql = "SELECT cat_name, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcommentreplace with
Code: [Select]
   $sql = "SELECT cat_name, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, multi_download

look for
Code: [Select]
SET cat_name = '$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_order = $cat_order, cat_hits = $cat_hits, auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcommentreplace with
Code: [Select]
SET cat_name = '$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_order = $cat_order, cat_hits = $cat_hits, auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment, multi_download = $multi_download
look for
Code: [Select]
 $sql = "SELECT cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcommentreplace with
Code: [Select]
 $sql = "SELECT cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, multi_download
look for
Code: [Select]
 show_table_separator($lang['permissions'], 2);insert before (changed insert for ver 2.0)
Code: [Select]
// MOD multi download
$value = intval($cat_row['multi_download']);
show_radio_row_multi($lang['multi_option'],'multi_download',$value);
// END MOD multi download

in the details.php file

look for
Code: [Select]
$sql = "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits".$additional_sql.", c.cat_name".get_user_table_field(", u.", "user_name").get_user_table_field(", u.", "user_email")."replace with
Code: [Select]
$sql = "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits".$additional_sql.", c.cat_name".get_user_table_field(", u.", "user_name").get_user_table_field(", u.", "user_email").", c.multi_download
look for
Code: [Select]
$is_image_owner = ($image_row['user_id'] > USER_AWAITING && $user_info['user_id'] == $image_row['user_id']) ? 1 : 0;insert after (Updated insert for ver 3.1)
Code: [Select]
// MOD multi download
$multi_download = $image_row['multi_download'];
if($multi_download){
if(!strpos(",jpg,jpeg,JPG,JPEG,png,gif",pathinfo($image_row['image_media_file'], PATHINFO_EXTENSION))){
$multi_download=0;
}
}
// END MOD multi download

look for
Code: [Select]
//-----------------------------------------------------
//---Clickstream---------------------------------------
//-----------------------------------------------------
insert before
Code: [Select]
//MOD multi download
if (!$multi_download){
$site_template->register_vars("yes_multi_download", 0);
$site_template->register_vars("not_multi_download", 1);
}
else{
$site_template->register_vars("yes_multi_download", 1);
$site_template->register_vars("not_multi_download", 0);
}
//END MOD multi download

in the download.php file

look for
Code: [Select]
 $sql = "SELECT image_id, cat_id, user_id, image_media_file, image_download_url, image_downloads
          FROM ".IMAGES_TABLE."
          WHERE image_id = $image_id AND image_active = 1";
  $image_row = $site_db->query_firstrow($sql);
insert before (updated insert for version 2.1)
Code: [Select]
// MOD multi download
  if ($_POST['action'] == "resize" || $_GET['action'] == "resize"){
$multi_download_select = (isset($HTTP_GET_VARS['multi_download_select'])) ? intval($HTTP_GET_VARS['multi_download_select']) : intval($HTTP_POST_VARS['multi_download_select']);
$size = MULTI_DOWNLOAD_SEP.$download_multi_sizes[$multi_download_select][0];
}
// END MOD multi download
Also on the first line of the "look for" code above (new replace for version 4.4)
add new code to the end of the first line so it looks like this (Updated the code for version 4.6)
Code: [Select]
 $sql = "SELECT image_id, cat_id, user_id, image_media_file, image_download_url, image_downloads, image_keywords, image_description, image_name

look for
Code: [Select]
 if ($user_info['user_level'] != ADMIN) {
    $sql = "UPDATE ".IMAGES_TABLE."
            SET image_downloads = image_downloads + 1
            WHERE image_id = $image_id";
    $site_db->query($sql);
insert before (Updated insert for ver 3.0)(Updated insert for ver 4.4)
Code: [Select]
// MOD multi download
if ($size){
$multi_resize=get_file_path($regs[1].'.'.$regs[2], "big", $image_row['cat_id'], 0, 1);
if (!file_exists($multi_resize)){
$multi_resize = (is_local_file($image_row['image_media_file'])) ? dirname($image_row['image_media_file'])."/".$regs[1].'.'.$regs[2] : MEDIA_PATH."/".$image_row['cat_id']."/".$regs[1].'.'.$regs[2];
}
$file['file_name'] = $file_name.(($size) ? "_".$size : "").".".$file_extension;
$multi_new_image=(is_local_file($image_row['image_media_file'])) ? dirname($image_row['image_media_file'])."/".MULTI_BIG_FOLDER."/".$file['file_name'] : MEDIA_PATH."/".$image_row['cat_id']."/".MULTI_BIG_FOLDER."/".$file['file_name'];
$file['file_path'] = $multi_new_image;
$multi_dir=dirname($multi_new_image);
if (!file_exists($multi_new_image)){
if (!@is_dir($multi_dir)){
$oldumask = umask(0);
$result = mkdir($multi_dir);
umask($oldumask);
if (!@is_dir($multi_dir) || !$result) {
$result = mkdir($multi_dir, 0755);
}
}
$multi_var = multi_download_resize($multi_resize,$multi_new_image,$multi_download_var['quality'],$download_multi_sizes[$multi_download_select][1],$download_multi_sizes[$multi_download_select][2]);
if ($multi_var !== $multi_resize){
$file['file_path'] = $multi_new_image;
//-------------------------------------------------------------------------------------------
// --- Annotate Resized Images ----------------------------------------------------------------------
//-------------------------------------------------------------------------------------------
if ($config['annotation_use'] && strtolower($file_extension == jpg)) {
require(ROOT_PATH.'includes/annotate.php');
$ann_user_name = ($user_info['user_name']);
annotate_image($file['file_path']);
}
//-------------------------------------------------------------------------------------------
}
else {
$file['file_name'] = $file_name.".".$file_extension;
$file['file_path'] = $multi_resize;
}
}
}

// END MOD multi download

look for (New for ver 4.0- only needed if you want a popup window instead of download)(Updated for V4.4 to include template)
Code: [Select]
send_file($file['file_name'], $file['file_path']);
Replace with (Updated in V4.6)
Code: [Select]
//MOD multi download for popup window
if (($multi_download_var['target']<>"") && $size){
   $meta_keywords  = !empty($image_row['image_keywords']) ? implode(", ", explode(",", $image_row['image_keywords'])) : "";
$meta_description = !empty($image_row['image_description']) ? strip_tags($image_row['image_description']) . ". " : "";
$image_name = format_text($image_row['image_name'], 2);
                                  $site_template->register_vars(array(
"img_url" => $file["file_path"],
"site_name" => $config['site_name'],
"charset" => $lang['charset'],
"direction" => $lang['direction'],
"detail_meta_description"   => $meta_description,
            "detail_meta_keywords"      => $meta_keywords,
            "prepend_head_title"        => $image_name . " - "
));
$site_template->print_template($site_template->parse_template("multi_popup"));
}
else{
        send_file($file['file_name'], $file['file_path']);
    }
//END MOD multi download for popup window

in the includes\constants.php file

look for
Code: [Select]
?>insert before
Code: [Select]
// MOD multi download
define ('MULTI_BIG_FOLDER' , 'big'); //This is the name of the 'big' folder or the name of a seperate subfolder for resizing of images.
define ("MULTI_DOWNLOAD_SEP","_resized_");//an underscore will be added to this variable before it is attached (which in this case will make 2 underscores)
//this is what this Mod uses as a seperator from all the files it creates on your server.
// the format will be 'yourfilename_ (whatever the sep is set for)(and the names of your option for that size).jpg'
//example: if I have an option for 1024X768 the new name would be 'yourfilename__resized_1024X768.jpg' notice the 2 underscores in a row at the beginning, one is built in and the other is an option that you can take away if needed.
//NOTE: when this mod is cleaning up it is looking for any file with '_ (whatever the sep is set for)' [example '__resized_'] is what the mod is looking for, (notice the 2 underscores in a row at the beginning)
//             I am assuming that you will not EVER have '__resized_' in any of your normal filenames, if you do, then you need to change the SEP variable to something that you will never use in a filename or you can have the MOD store the
//             resized images in a different subfolder then the 'big' folder that is above and then the seperator will not matter. The Mod will create the new subfolder on the fly while it is running.
// END MOD multi download

in the includes\functions.php file

look for
Code: [Select]
function show_image($image_row, $mode = "", $show_link = 1, $detailed_view = 0) {
  global $self_url, $site_template, $site_sess, $user_info, $config, $cat_cache, $lang, $additional_image_fields, $user_table_fields, $url_show_profile;
insert after (changed insert for ver 2.0) (updated insert for ver 2.1)
Code: [Select]
 global $download_multi_sizes, $multi_download_var, $site_db;// MOD multi downloadoriginal insert that needs replaced if upgrading from beta to ver 2.0
Code: [Select]
 global $multi_download_options_string;// MOD multi download
ONLY ADD THIS MODIFICATION IF IT IS NOT ALREADY THERE FROM THE BIG MOD! (NEW TO VER 2.0 and above)
look for
Code: [Select]
   $check_handle = "check_".$image_type."_type";
    $path = (($image_type == "media") ? (($cat_id) ? MEDIA_PATH."/".$cat_id : MEDIA_TEMP_PATH) : (($cat_id) ? THUMB_PATH."/".$cat_id : THUMB_TEMP_PATH))."/".$file_name;
    return ($check_handle($file_name) && file_exists($path)) ? (($in_admin && !preg_match("#(gif|jpg|jpeg|png)$#is", $file_name)) ? ICON_PATH."/".get_file_extension($file_name).".gif" : $path) : $return_code;
replace with
Code: [Select]
// MOD multi download (with needed info for big directory if not using that mod)
    $check_handle = "check_".$image_type."_type";
//    $path = (($image_type == "media") ? (($cat_id) ? MEDIA_PATH."/".$cat_id : MEDIA_TEMP_PATH) : (($cat_id) ? THUMB_PATH."/".$cat_id : THUMB_TEMP_PATH))."/".$file_name;
//    return ($check_handle($file_name) && file_exists($path)) ? (($in_admin && !preg_match("#(gif|jpg|jpeg|png)$#is", $file_name)) ? ICON_PATH."/".get_file_extension($file_name).".gif" : $path) : $return_code;
// Download file block insert BEGIN
    switch( $image_type ) {
 case "media":
   if( $cat_id ){
     $path = MEDIA_PATH."/".$cat_id;
}else{
 $path = MEDIA_TEMP_PATH;
                        }
   break;
      case "big":
        $path = MEDIA_PATH."/".$cat_id."/big";
   break;
      case "download":
        $path = MEDIA_PATH."/".$cat_id."/download";
   break;
 default:
   if( $cat_id ){
     $path = THUMB_PATH."/".$cat_id;
}else{
 $path = THUMB_TEMP_PATH;
                        }
   break;
}
$path .= "/".$file_name;
// Download file block insert END
    return ($check_handle($file_name) && file_exists($path)) ? (($in_admin && !preg_match("#(gif|jpg|jpeg|png)$#is", $file_name)) ? ICON_PATH."/".get_file_extension($file_name).".gif" : $path) : (($image_type != "big" && $image_type != "big") ? $return_code : ""); // Download file :: V@no big mod
// END MOD multi download (with needed info for big directory if not using that mod)

look for (new to ver 2.0)(Changed in ver 4.5, read this posthttp://www.4homepages.de/forum/index.php?topic=22741.msg163311;topicseen#msg163311 )
Code: [Select]
 $rate_form = "";
  if (check_permission("auth_vote", $image_row['cat_id'])) {
    $site_template->register_vars("rate", $lang['rate']);
    $rate_form = $site_template->parse_template("rate_form");
  }
  $site_template->register_vars("rate_form", $rate_form);
  $site_template->register_vars(array(
    "image" => get_media_code($image_row['image_media_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode, $show_link, $detailed_view),
  ));
insert After (updated insert for ver 3.1) (updated for ver 4.1) (updated for ver 4.2)(updated/repaired for ver 4.3)(updated for ver 4.5)(updated for ver 4.7)
Code: [Select]
// MOD multi download
if ($detailed_view){
 $sql = "SELECT multi_download
        FROM ".CATEGORIES_TABLE."
        WHERE cat_id = ".$image_row['cat_id']." ";
 $result = $site_db->query_firstrow($sql);
 $multi_download = $result['multi_download'];
}
if ($multi_download && $detailed_view){
if (!check_permission("auth_download", $image_row['cat_id'])) {
$multi_download_options="&nbsp;&nbsp;<img src=\"".get_gallery_image("download_off.gif")."\" border=\"0\" alt=\"\" />";
$allow_download = 0;
clear_download_token($image_row['image_id']);
}
else{
$multi_download_colvar = 0;
if ($multi_download_var['show_table']){
$multi_download_class1 = "class='head1'";
$multi_download_class2 = "class='row1'";
$multi_download_class3 = "class='row2'";
}
else {
$multi_download_class1 = "";
$multi_download_class2 = "";
$multi_download_class3 = "";
}
$multi_download_group0 = ($multi_download_var['center_groups'] ? "align='center'" : "");
// change the code below to change how your monitor resolution is displayed
$multi_download_resolution = "<TR ".$multi_download_class3."><TD colspan='".$multi_download_var['columns']."' align='center'><B>".$lang['multi_resolution']."<script type='text/javascript'>document.write(screen.width+'X'+screen.height)</script></B></TD></TR>";
if ($multi_download_var['bold_groups']){
$multi_download_group1= "<B>";
$multi_download_group2= "</B>";
}
else{
$multi_download_group1= "";
$multi_download_group2= "";
}
if (!$multi_download_var['type']){
$multi_download_options = "<BR><BR><form action='".$site_sess->url(ROOT_PATH."download.php")."' method='get'".$multi_download_var['target']."><table border='0' cellspacing='1' cellpadding='0' width='".$multi_download_var['table']."'  ".$multi_download_class1."><tr><td><table border='0' cellspacing='0' cellpadding='0' width='".$multi_download_var['table']."'>";
if ($multi_download_var['show_resolution']){
$multi_download_options .= $multi_download_resolution;
}
if ($multi_download_var['download']){
$multi_download_options .="<TR ".$multi_download_class3."><TD colspan='".$multi_download_var['columns']."' align='center'>".$lang['multi_select']."</TD></TR>";
}
$multi_download_options .="<TR ".$multi_download_class2."><TD><select name='multi_download_select'>";
}
else{
$multi_download_options = "<table border='0' cellspacing='1' cellpadding='0' width='".$multi_download_var['table']."' ".$multi_download_class1."><tr><td><table border='0' cellspacing='0' cellpadding='0' width='".$multi_download_var['table']."'>";
if ($multi_download_var['show_resolution']){
$multi_download_options .= $multi_download_resolution;
}
if ($multi_download_var['download']){
$multi_download_options .= "<tr ".$multi_download_class3."><TD colspan='".$multi_download_var['columns']."' align='center'>".$lang['multi_select']."</TD>";
}
}
$var=0;
$down_group=0;
$down_group_flag=0;
$multi_download_group="";
$multi_download_colvar=0;
if (ISSET($site_template->val_cache['download_width'])){
$max_width = $site_template->val_cache['download_width'];
$max_height = $site_template->val_cache['download_height'];
}
else {
$max_width = $site_template->val_cache['width'];
$max_height = $site_template->val_cache['height'];
}
$varcount= count($download_multi_sizes);
while ($var < $varcount){
if ($download_multi_sizes[$var][1] == '0'){
if ((!$down_group) && ($multi_download_group<>"")){
if (!$multi_download_var['type']) {
$multi_download_options .=$multi_download_group;
}
else{
if ($multi_download_colvar < $multi_download_var['columns']){
$multi_download_colvar1=($multi_download_var['columns'] - $multi_download_colvar);
$multi_download_group .= "<td align='center' colspan='".$multi_download_colvar1."'></td>";
}
$multi_download_options .= "<tr ".$multi_download_class2.">".$multi_download_group."</tr>";
}
}
if ($down_group && $down_group_flag){
if (!$multi_download_var['type']) {
$multi_download_group .= "</optgroup>";
}
else{
if ($multi_download_colvar < $multi_download_var['columns']){
$multi_download_colvar1=($multi_download_var['columns'] - $multi_download_colvar);
$multi_download_group .= "<td align='center' colspan='".$multi_download_colvar1."'></td>";
}
}
$multi_download_options .= $multi_download_group;
}
$down_group=1;
$down_group_flag=0;
if (!$multi_download_var['type']) {
$multi_download_group ="<optgroup label='".$lang['multi_down_'.$download_multi_sizes[$var][0]]."'>";
}
else{
$multi_download_group ="</tr><tr ".$multi_download_class3."><td colspan='".$multi_download_var['columns']."' ".$multi_download_group0.">".$multi_download_group1.$lang['multi_down_'.$download_multi_sizes[$var][0]].$multi_download_group2."</TD></TR><tr ".$multi_download_class2.">";
$multi_download_colvar = 0;
}
}
else{
if ((($download_multi_sizes[$var][1] <= $max_width && $download_multi_sizes[$var][2] <= $max_height)&&($multi_download =='2'))||($multi_download=='1')){
 if (((($max_width/$max_height)==($download_multi_sizes[$var][1]/$download_multi_sizes[$var][2]))&&($multi_download_var['ratio']))||(!$multi_download_var['ratio'])){
switch($multi_download_var['type']){
case (1) :
$multi_download_group .="<td align='center'><a href='".$site_sess->url(ROOT_PATH."download.php?action=resize&".URL_IMAGE_ID."=".$image_row['image_id']."&multi_download_select=".$var)."'".$multi_download_var['target'].">".$download_multi_sizes[$var][0]."</a></td>";
break;
case (2) :
$multi_download_group .="<td align='center'><a href='".$site_sess->url(ROOT_PATH."download.php?action=resize&".URL_IMAGE_ID."=".$image_row['image_id']."&multi_download_select=".$var)."'".$multi_download_var['target']."><img src='".get_gallery_image($download_multi_sizes[$var][0].".".$multi_download_var['button'])."' ";
if ($multi_download_var['alt_image']){
$multi_download_group .= "alt='".$download_multi_sizes[$var][0]."' ";
}
$multi_download_group .="border='0'></a></td>";
break;
case (0) :
default:
$multi_download_group .="<option value='".$var."'>".$download_multi_sizes[$var][0]."</option>";
break;
}
$down_group_flag=1;
$multi_download_colvar++;
 }
}
if (($multi_download_colvar == $multi_download_var['columns']) && ($multi_download_var['type']>0)){
$multi_download_colvar = 0;
$multi_download_group .="</tr><tr ".$multi_download_class2.">";
}
}
$var++;
}
if (($down_group==1) && (!$multi_download_var['type'])){
$multi_download_group .="</optgroup>";
}
if($down_group_flag){
$multi_download_options .=$multi_download_group;
}else{
$multi_download_colvar = 1;
}
$multi_download_colvar2= $multi_download_colvar;
$multi_download_colvar = $multi_download_var['columns'] - $multi_download_colvar;
if ($multi_download_var['center_original']){
$multi_download_colvar1= $multi_download_colvar;
}
else{
$multi_download_colvar1= 1;
$multi_download_colvar--;
}
switch ($multi_download_var['type']){
case(1):
if ($multi_download_var['newline_original']){
if ($multi_download_colvar2){
$multi_download_colvar1 = $multi_download_var['columns'] - $multi_download_colvar2;
$multi_download_options .="<td align='center' colspan='".$multi_download_colvar1."'></td>";
$multi_download_options .="</tr><tr ".$multi_download_class2.">";
}
if ($multi_download_var['center_original']){
$multi_download_colvar1=$multi_download_var['columns'];
}
else{
$multi_download_colvar1 =1 ;
$multi_download_colvar=$multi_download_var['columns'];
}
}
$multi_download_options .="<td align='center' colspan='".$multi_download_colvar1."'>";
if ($multi_download_var['show_original']){
$multi_download_options .= "<a href='".$site_sess->url(ROOT_PATH."download.php?action=resize&".URL_IMAGE_ID."=".$image_row['image_id']."&multi_download_select=".$var)."' ".$multi_download_var['target'].">".$lang['original_size']."</a>";
}
$multi_download_options .= "</td>";
if (!$multi_download_var['center_original']){
$multi_download_options .= "<td colspan='".$multi_download_colvar."'></td>";
}
$multi_download_options .="</tr></table></td></tr></table>";
break;
case(2):
if ($multi_download_var['newline_original']){
if ($multi_download_colvar2){
$multi_download_colvar1 = $multi_download_var['columns'] - $multi_download_colvar2;
$multi_download_options .="<td align='center' colspan='".$multi_download_colvar1."'></td>";
$multi_download_options .="</tr><tr ".$multi_download_class2.">";
}
if ($multi_download_var['center_original']){
$multi_download_colvar1=$multi_download_var['columns'];
}
else{
$multi_download_colvar1 =1 ;
$multi_download_colvar=$multi_download_var['columns'];
}
}
$multi_download_options .="<td align='center' colspan='".$multi_download_colvar1."'>";
if ($multi_download_var['show_original']){
$multi_download_options .= "<a href='".$site_sess->url(ROOT_PATH."download.php?action=resize&".URL_IMAGE_ID."=".$image_row['image_id']."&multi_download_select=".$var)."' ".$multi_download_var['target']."><img src='".get_gallery_image("original_size.".$multi_download_var['button'])."' ";
if($multi_download_var['alt_image']){
$multi_download_options .= "alt='".$lang['original_size']."' ";
}
$multi_download_options .="border='0'></a>";
}
$multi_download_options .= "</td>";
if (!$multi_download_var['center_original']){
$multi_download_options .= "<td colspan='".$multi_download_colvar."'></td>";
}
$multi_download_options .="</tr></table></td></tr></table>";
break;
case(0):
default:
if ($multi_download_var['show_original']){
$multi_download_options .="<option value='".$var."'>".$lang['original_size']."</option>";
}
$multi_download_options .="</select>";
$multi_download_options .= "</td><td><input type='submit' name='download' value='".$lang['download']."' class='button' />
</TD></TR></TABLE></TABLE><input type='hidden' name='action' value='resize' />
<input type='hidden' name='image_id' value='".$image_row['image_id']."' /></form>";
break;
}
$allow_download = 1;
set_download_token($image_row['image_id']);
}
$site_template->register_vars("multi_download_options", $multi_download_options);
unset($multi_download_options);
}

// END MOD multi download

look for (this insert no longer needed in ver 2.0 or above) (left here so upgrade users can delete)
Code: [Select]
if (!check_permission("auth_sendpostcard", $image_row['cat_id'])) {insert before(remove this insert if upgrading from beta to ver 2.0)
Code: [Select]
// MOD multi download

if (!check_permission("auth_download", $image_row['cat_id'])) {
$multi_download_options="&nbsp;&nbsp;<img src=\"".get_gallery_image("download_off.gif")."\" border=\"0\" alt=\"\" />";
$allow_download = 0;
clear_download_token($image_row['image_id']);
}
else{
$multi_download_options = $multi_download_options_string;
    $multi_download_options .= "</td><td><input type='submit' name='download' value='".$lang['download']."' class='button' />
                   </TD></TR></TABLE></TABLE><input type='hidden' name='action' value='resize' />
                    <input type='hidden' name='image_id' value='".$image_row['image_id']."' /></form>";
//
$allow_download = 1;
    set_download_token($image_row['image_id']);

}
$site_template->register_vars("multi_download_options", $multi_download_options);
// END MOD multi download

look for
Code: [Select]
?>insert before (updated insert for ver 3.1)
Code: [Select]
// MOD multi download
function multi_download_resize($file, $new_file, $quality, $resize_width, $resize_height) {
  global $convert_options,$download_multi_sizes,$multi_download_var;
  if (!function_exists(init_convert_options)) {
require(ROOT_PATH.'includes/image_utils.php');
  }

  $convert_options = init_convert_options();
  $image_info = (defined("IN_CP")) ? getimagesize($file) : @getimagesize($file);
  if (!$image_info) {
    return false;
  }
  if ($resize_width==0){$resize_width=$image_info[0];}
  if ($resize_height==0){$resize_height=$image_info[1];}
  if ($multi_download_var['crop']){
$scale = max($resize_width/$image_info[0], $resize_height/$image_info[1]);
  }
  else{
$scale = min($resize_width/$image_info[0], $resize_height/$image_info[1]);
  }
$new_width = floor($scale*$image_info[0]);
$new_height = floor($scale*$image_info[1]);
$resize_handle = "resize_image_".$convert_options['convert_tool'];
if ((($scale == '1' || $scale == '0') && !$multi_download_var['crop']) || (($resize_width==$image_info[0]) && ($resize_height==$image_info[1]))){
return $file;
}
if (!$multi_download_var['crop']){
if($resize_handle($file, $new_file, $quality, $new_width, $new_height, $image_info)) {
@chmod($new_file, CHMOD_FILES);
return true;
}
else {
return false;
}
}
$crop_handle = "multi_download_resize_crop_image_".$convert_options['convert_tool'];
if ($resize_width == $new_width){
$multi_crop_st_w='0';
$multi_crop_end_w=$image_info['0'];
$multi_crop_end_h = (($image_info['0']*$resize_height)/$resize_width);
switch($multi_download_var['crop']){
case (2) :
$multi_crop_st_h= ($image_info['1']-$multi_crop_end_h);
break;
case (3) :
$multi_crop_st_h= '0';
break;
case (4) :
$multi_crop_st_h = '0';
$multi_crop_end_h = $image_info[1];
break;
case (1) :
default:
$multi_crop_st_h= (($image_info['1']-$multi_crop_end_h)/2);
break;
}
}
else{
$multi_crop_st_h='0';
$multi_crop_end_h=$image_info['1'];
$multi_crop_end_w = (($image_info['1']*$resize_width)/$resize_height);
switch($multi_download_var['crop']){
case (2) :
$multi_crop_st_w= ($image_info['0']-$multi_crop_end_w);
break;
case (3) :
$multi_crop_st_w= '0';
break;
case (4) :
$multi_crop_st_w = '0';
$multi_crop_end_w = $image_info[0];
break;
case (1) :
default:
$multi_crop_st_w = (($image_info['0']-$multi_crop_end_w)/2);
break;
}
}
if($crop_handle($file, $new_file, $quality, $resize_width, $resize_height, $image_info, $multi_crop_st_w,$multi_crop_st_h,$multi_crop_end_w,$multi_crop_end_h)) {
@chmod($new_file, CHMOD_FILES);
return true;
}
else {
return false;
}

}

function multi_download_resize_crop_image_gd($src, $dest, $quality, $width, $height, $image_info, $multi_crop_st_w, $multi_crop_st_h, $multi_crop_end_w, $multi_crop_end_h) {
  global $convert_options,$multi_download_var;

  $types = array(1 => "gif", 2 => "jpeg", 3 => "png");
  if ($convert_options['convert_gd2']) {
    $thumb = imagecreatetruecolor($width, $height);
  }
  else {
    $thumb = imagecreate($width, $height);
  }
  $image_create_handle = "imagecreatefrom".$types[$image_info[2]];
  if ($image = $image_create_handle($src)) {
    if ($convert_options['convert_gd2']) {
      imagecopyresampled($thumb, $image, 0, 0, $multi_crop_st_w,$multi_crop_st_h, $width, $height, $multi_crop_end_w, $multi_crop_end_h);
    }
    else {
      imagecopyresized($thumb, $image, 0, 0, $multi_crop_st_w,$multi_crop_st_h, $width, $height, $multi_crop_end_w, $multi_crop_end_h);
    }

    if ($image_info[2] == 3) {
      $quality = 9;
    }

    $image_handle = "image".$types[$image_info[2]];
    $image_handle($thumb, $dest, $quality);
    imagedestroy($image);
    imagedestroy($thumb);
  }
  return (file_exists($dest)) ? 1 : 0;
}

function multi_download_resize_crop_image_im($src, $dest, $quality, $width, $height, $image_info, $multi_crop_st_w, $multi_crop_st_h, $multi_crop_end_w, $multi_crop_end_h) {
  global $convert_options,$multi_download_var;
  if ($multi_download_var['crop']==4){
$command = $convert_options['convert_path'];
$command .= " \"$src\" -quality ".$quality." -antialias -geometry $width"."x"."$height! -profile '*' -unsharp 0.5x1 \"$dest\"";
  }
  else{
$command = $convert_options['convert_path'];
$command .= " \"$src\" -crop ".$multi_crop_end_w."X".$multi_crop_end_h."+".$multi_crop_st_w."+".$multi_crop_st_h;
$command .= " -quality ".$quality." -antialias -geometry $width"."x"."$height -profile '*' -unsharp 0.5x1 \"$dest\"";
  }
  system($command);
  return (file_exists($dest)) ? 1 : 0;
}

function multi_download_resize_crop_image_netpbm($src, $dest, $quality, $width, $height, $image_info, $multi_crop_st_w,$multi_crop_st_h,$multi_crop_end_w,$multi_crop_end_h) {
  global $convert_options,$multi_download_var;

  $convert_path = $convert_options['convert_path'];
  $types = array(1 => "gif", 2 => "jpeg", 3 => "png");
  $target = ($width > $height) ? $width : $height;
  $command = $convert_path."/".check_executable($types[$image_info[2]]."topnm")." ".$src." | ";
  if ($multi_download_var['crop']==4){
$command .= $convert_path."/".check_executable("pnmscale")." --quiet -xsize=".$width." -ysize=".$height." | ";
  }
  else{
$command .= $convert_path."/".check_executable("pnmcut")."  --quiet ".$multi_crop_st_w." ".$multi_crop_st_h." ".$multi_crop_end_w." ".$multi_crop_end_h." | ";
$command .= $convert_path."/".check_executable("pnmscale")." --quiet -xysize ".$width." ".$height." | ";
  }
  if ($image_info[2] == 1) {
    $command .= $convert_path."/".check_executable("ppmquant")." 256 | " . $convert_path."/".check_executable("ppmtogif")." > ".$dest;
  }
  elseif ($image_info[2] == 3) {
    $command .= $convert_path."/".check_executable("pnmtopng")." > ".$dest;
  }
  else {
    $jpeg_exec = (file_exists($convert_path."/".check_executable("pnmtojpeg"))) ? check_executable("pnmtojpeg") : check_executable("ppmtojpeg");
    $command .= $convert_path."/".$jpeg_exec." --quality=".$quality." > ".$dest;
  }
  system($command);
  return (file_exists($dest)) ? 1 : 0;
}

if (!function_exists('check_big_type')) {  
function check_big_type($file_name) {
global $config;
return (in_array(get_file_extension($file_name), $config['allowed_mediatypes_array'])) ? 1 : 0;
}
function check_remote_big($remote_media_file) {
global $config;
return (preg_match("#^(https?:\/\/[a-z0-9\-]+?\.([a-z0-9\-]+\.)*[a-z]+(:[0-9]+)*\/.*?\.(".$config['allowed_mediatypes_match'].")$)#is", $remote_media_file)) ? 1 : 0;
}
function check_local_big($local_media_file) {
global $config;
return (preg_match("#^((\.)*\/.*?\.(".$config['allowed_mediatypes_match'].")$)#is", $local_media_file)) ? 1 : 0;
}
}

// END MOD multi download
this is the old insert that needs to be replaced if upgrading from beta to ver 2.0 or above
Code: [Select]
// MOD multi download
function multi_download_resize($file, $new_file, $quality, $resize_width, $resize_height) {
  global $convert_options;
  if (!function_exists(init_convert_options)) {
require(ROOT_PATH.'includes/image_utils.php');
  }
  $convert_options = init_convert_options();
  $image_info = (defined("IN_CP")) ? getimagesize($file) : @getimagesize($file);
  if (!$image_info) {
    return false;
  }
$scale = min($resize_width/$image_info[0], $resize_height/$image_info[1]);
$new_width = floor($scale*$image_info[0]);
$new_height = floor($scale*$image_info[1]);
$resize_handle = "resize_image_".$convert_options['convert_tool'];
if ($scale == '1'){
return $file;
}
elseif($resize_handle($file, $new_file, $quality, $new_width, $new_height, $image_info)) {
@chmod($new_file, CHMOD_FILES);
return true;
}
else {
return false;
}
}
// END MOD multi download

in the lang\english\admin.php file

look for
Code: [Select]
?>insert before (updated insert for ver 2.0)
Code: [Select]
//MOD multi downloads
$lang['multi_option'] = "Would you like to use multi-size download option for this category?";
$multi_download_optionlist = array(
  "0"  => "No",
  "1"  => "Yes, Allow all sizes to be selectable",
  "2"  => "Yes, Only allow smaller sizes then original to be selectable"
);
//END MOD multi downloads
original insert that needs to be replaced if upgrading from beta to ver 2.0
Code: [Select]
//MOD Multi Downloads
$lang['multi_option'] = "Are you using multi download option for this category?"
//END MOD Multi Downloads

in the lang\english\main.php file

look for
Code: [Select]
?>insert before (updated insert for version 2.1) (updated for ver 4.0)
Code: [Select]
// MOD multi download
$lang['download'] = "Download";
$lang['multi_select'] = "Select Size to Download";
$lang['original_size'] = "Original Size";
$lang['multi_resolution'] = "Your Screen Resolution is : ";
$lang['multi_down_group1'] = "4:3 Display";//create an entry for each one or your groups from the global.php file in this manor
$lang['multi_down_group2'] = "16:9 Display";
$lang['multi_down_group3'] = "16:10 Display";
$lang['multi_down_group4'] = "Mobile";
$lang['multi_down_group5'] = "Blackberry";
// END MOD multi download

in the template\your template\details.html file
the fun part.
my file I had something like this...
Code: [Select]
{lightbox_button}&nbsp;&nbsp;{postcard_button}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{download_button}&nbsp;&nbsp;{download_zip_button}I replaced this with
Code: [Select]
{lightbox_button}&nbsp;&nbsp;{postcard_button}{if not_multi_download}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{download_button}&nbsp;&nbsp;{download_zip_button}
{endif not_multi_download}
<!-- Mod multi downloads -->
{if yes_multi_download}
{multi_download_options}
{endif yes_multi_download}
<!-- end mod-->

what you are trying to do is to remove the download and zip buttons if you are using the multi download and display the multi download option instead.
different templates may be setup differently.

(New to version 4.4)
To create the template used for the popup window...
Create a file in your templates folder and call it "multi_popup.html"
Copy the following code into that file and save the file
Code: [Select]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html dir="{direction}">
<head>
<title>{prepend_head_title}{site_name}</title>
<meta http-equiv="content-type" content="text/html; charset={charset}">
<meta name="description" content="{detail_meta_description}{site_name}">
<meta name="keywords" content="{detail_meta_keywords}">
</head>
<body>
<img src="{img_url}"></img>
</body>
</html>

and you should be ready to go.
« Last Edit: April 24, 2013, 01:20:16 AM by budduke »
Buddy Duke
www.budduke.com

Offline Sunny C.

  • Addicted member
  • ******
  • Posts: 1.804
  • I ♥ 4I
    • View Profile
Re: [BETA MOD] Multi Download of same image
« Reply #1 on: September 17, 2008, 01:28:21 AM »
NICE Mod!!!!

rinaldos

  • Guest
Re: [BETA MOD] Multi Download of same image
« Reply #2 on: September 17, 2008, 10:14:21 PM »
Wonderfull MOD, works fine with 1.76 :-)
Thank you for posting:-)

Ingo

Offline mawenzi

  • Moderator
  • 4images Guru
  • *****
  • Posts: 4.500
    • View Profile
Re: [BETA MOD] Multi Download of same image
« Reply #3 on: September 17, 2008, 10:27:12 PM »
... no one with problems ... ;)
... so I moved it to Mods & Plugins (Releases & Support) ...
Your first three "must do" before you ask a question ! ( © by V@no )
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

You are on search for top 4images MOD's ?
- then please search here ... Mawenzi's Top 100+ MOD List (unsorted sorted) ...

Offline satine88

  • Sr. Member
  • ****
  • Posts: 265
    • View Profile
Re: [MOD] Multi Download of same image
« Reply #4 on: September 26, 2008, 06:26:17 PM »
Hello,
Does this mod resize the image to the desired size?

Offline budduke

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • http://www.budduke.com
Re: [MOD] Multi Download of same image
« Reply #5 on: September 26, 2008, 08:35:50 PM »
No, this mod does not change your original file at all.
it creates a new file at the size that you user is wanting to download from your site.
Creating a new file with a __resized_1024X768.jpg attached to the original name.

look for this line in the code above
$download_multi_sizes= array

the information there will tell you how to modify it to suit your site and sizes.

Let me know if that is not what you are asking...
Buddy Duke
www.budduke.com

Offline batu544

  • Sr. Member
  • ****
  • Posts: 336
    • View Profile
    • Free Celebrity wallpapers
Re: [MOD] Multi Download of same image
« Reply #6 on: September 26, 2008, 09:27:17 PM »
Wow !!! This is the MOD I was looking for..  :)  Here I have one question before putting this in my website ..

If I have an image of size 1024x768  and the user selected to download 1280x960 or bigger size , then what will happen ??


Thanks


Just tested this in my test server..  but I got the following error.

Fatal error: Call to undefined function check_big_type() in C:\wamp\www\bhwallpaers\includes\functions.php on line 215

I am using 1.7.4 version and also NOT using BIG mod..   :(


« Last Edit: September 26, 2008, 10:41:15 PM by batu544 »

Offline budduke

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • http://www.budduke.com
Re: [MOD] Multi Download of same image
« Reply #7 on: September 27, 2008, 12:48:02 AM »
Wow !!! This is the MOD I was looking for..  :)  Here I have one question before putting this in my website ..

If I have an image of size 1024x768  and the user selected to download 1280x960 or bigger size , then what will happen ??


Thanks


Just tested this in my test server..  but I got the following error.

Fatal error: Call to undefined function check_big_type() in C:\wamp\www\bhwallpaers\includes\functions.php on line 215

I am using 1.7.4 version and also NOT using BIG mod..   :(




I have some wallpapers that are 800X600 and when it makes them 1280x960 or larger they look blurry, just like if you blow them up in you graphics program. that is why you should have the largest size possible and let it downsize to keep the quality.
but it does make it bigger just not as good of quality.

your error,check_big_type() , I do not see that in my functions.php file anywhere. Can you PM the file to me or post your functions.php so I can take a closer look at it? I do not have 1.7.4 to compare it with...
I did a quick search for that function and it looks like you are using either one of these mods...
http://www.4homepages.de/forum/index.php?topic=3236.0
or
http://www.4homepages.de/forum/index.php?topic=8018.0

is this mod working ok before you added my mod?
If you can send me the functions file I will see if maybe something got placed in the wrong spot when you was inserting some of the code.

« Last Edit: September 27, 2008, 12:58:04 AM by budduke »
Buddy Duke
www.budduke.com

Offline batu544

  • Sr. Member
  • ****
  • Posts: 336
    • View Profile
    • Free Celebrity wallpapers
Re: [MOD] Multi Download of same image
« Reply #8 on: September 28, 2008, 04:51:03 PM »
HI,
    Sorry for late reply ...   Its sunday here .. :)  As far as I can remember .. I have not install the MOD's mentioned by you. Here I am posting my functions.php  file .. Please look into it and let me know if I have done some mistake.

Code: [Select]
<?php
/**************************************************************************
 *                                                                        *
 *    4images - A Web Based Image Gallery Management System               *
 *    ----------------------------------------------------------------    *
 *                                                                        *
 *             File: functions.php                                        *
 *        Copyright: (C) 2002 Jan Sorgalla                                *
 *            Email: jan@4homepages.de                                    *
 *              Web: http://www.4homepages.de                             *
 *    Scriptversion: 1.7.4                                                *
 *                                                                        *
 *    Never released without support from: Nicky (http://www.nicky.net)   *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
 *    bedingungen (Lizenz.txt) für weitere Informationen.                 *
 *    ---------------------------------------------------------------     *
 *    This script is NOT freeware! Please read the Copyright Notice       *
 *    (Licence.txt) for further information.                              *
 *                                                                        *
 *************************************************************************/
if (!defined('ROOT_PATH')) {
  die(
"Security violation");
}
// MOD ADDED TO GET DIFFERENT DETAIL PAGE STARTS HERE
function get_cat_template($tpl_name$cat_id 0) {
  global 
$cat_cache;
  if (!
$cat_id) {
    
$new_tpl_name $tpl_name;
  }
  elseif (
file_exists(TEMPLATE_PATH."/".$tpl_name."_".$cat_id.".html")) {
    
$new_tpl_name $tpl_name."_".$cat_id;
  }
  else {
    
$new_tpl_name get_cat_template($tpl_name$cat_cache[$cat_id]['cat_parent_id']);
  }
  return 
$new_tpl_name;
}
// MOD ADDED TO GET DIFFERENT DETAIL PAGE ENDS HERE

function set_download_token($token) {
  global 
$site_sess$user_info;

  if (
$user_info['user_level'] == ADMIN) {
    return;
  }

  
$download_token = @unserialize($site_sess->get_session_var('download_token'));

  if (!
$download_token) {
    
$download_token = array();
  }

  
$download_token[serialize(md5($token))] = 1;

  
$site_sess->set_session_var('download_token'serialize($download_token));
}

function 
clear_download_token($token) {
  global 
$site_sess$user_info;

  if (
$user_info['user_level'] == ADMIN) {
    return;
  }

  
$download_token = @unserialize($site_sess->get_session_var('download_token'));

  if (!
$download_token) {
    return;
  }

  
$token serialize(md5($token));

  if (isset(
$download_token[$token])) {
    unset(
$download_token[$token]);
    
$site_sess->set_session_var('download_token'serialize($download_token));
  }
}

function 
check_download_token($token) {
  global 
$site_sess$user_info;

  if (
$user_info['user_level'] == ADMIN) {
    return 
true;
  }

  
$download_token = @unserialize($site_sess->get_session_var('download_token'));

  if (isset(
$download_token[serialize(md5($token))])) {
    return 
true;
  }

  return 
false;
}

function 
get_gallery_image($image_name) {
  global 
$config;
  if (
file_exists(TEMPLATE_PATH."/images_".$config['language_dir']."/".$image_name)) {
    return 
TEMPLATE_PATH."/images_".$config['language_dir']."/".$image_name;
  }
  else {
    return 
TEMPLATE_PATH."/images/".$image_name;
  }
}

function 
get_basename($path) {
  
$path str_replace("\\""/"$path);
  
$name substr(strrchr($path"/"), 1);
  return 
$name $name $path;
}

function 
get_basefile($path) {
  
$basename get_basename($path);
  
ereg("(.+)\?(.+)"$basename$regs);
  return isset(
$regs[1]) ? $regs[1] : $basename;
}

function 
redirect($url) {
  global 
$script_url$site_sess;
  if (
strpos($url'://') === false) {
    
$url $script_url.'/'.$url;
  }
  
$location = @preg_match('/Microsoft|WebSTAR|Xitami/'getenv('SERVER_SOFTWARE')) ? 'Refresh: 0; URL=' 'Location: ';
  if (
is_object($site_sess)) {
    
$url $site_sess->url($url"&");
  }
  
header($location.$url);
  exit;
}

function 
is_remote($file_name) {
  return 
strpos($file_name'://') > 0;
}

function 
is_remote_file($file_name) {
  return 
is_remote($file_name) && preg_match("#\.[a-zA-Z0-9]{1,4}$#"$file_name) ? 0;
}

function 
is_local_file($file_name) {
  return !
is_remote($file_name) && get_basefile($file_name) != $file_name && preg_match("#\.[a-zA-Z0-9]{1,4}$#"$file_name) ? 0;
}

function 
check_remote_media($remote_media_file) {
  global 
$config;
  return 
is_remote($remote_media_file) && preg_match("#\.[".$config['allowed_mediatypes_match']."]+$#i"$remote_media_file) ? 0;
}

function 
check_local_media($local_media_file) {
  global 
$config;
  return !
is_remote($local_media_file) && get_basefile($local_media_file) != $local_media_file && preg_match("#\.[".$config['allowed_mediatypes_match']."]+$#i"$local_media_file) ? 0;
}

function 
check_remote_thumb($remote_thumb_file) {
  return 
is_remote($remote_thumb_file) && preg_match("#\.[gif|jpg|jpeg|png]+$#is"$remote_thumb_file) ? 0;
}

function 
check_local_thumb($local_thumb_file) {
  return !
is_remote($local_thumb_file) && get_basefile($local_thumb_file) != $local_thumb_file && preg_match("#\.[gif|jpg|jpeg|png]+$#i"$local_thumb_file) ? 0;
}

function 
get_file_extension($file_name) {
  
ereg("(.+)\.(.+)"get_basefile($file_name), $regs);
  return 
strtolower($regs[2]);
}

function 
get_file_name($file_name) {
  
ereg("(.+)\.(.+)"get_basefile($file_name), $regs);
  return 
$regs[1];
}

function 
check_media_type($file_name) {
  global 
$config;
  return (
in_array(get_file_extension($file_name), $config['allowed_mediatypes_array'])) ? 0;
}

function 
check_thumb_type($file_name) {
  return (
preg_match("#(gif|jpg|jpeg|png)$#is"$file_name)) ? 0;
}

function 
check_executable($file_name) {
  if (
substr(PHP_OS03) == "WIN" && !eregi("\.exe$"$file_name)) {
    
$file_name .= ".exe";
  }
  elseif (
substr(PHP_OS03) != "WIN") {
    
$file_name eregi_replace("\.exe$"""$file_name);
  }
  return 
$file_name;
}

function 
get_file_path($file_name ""$image_type "media"$cat_id 0$in_admin 0$return_icon 1$check_remote CHECK_REMOTE_FILES) {
  
$return_code = ($return_icon) ? ICON_PATH."/404.gif" 0;
  if (empty(
$file_name)) {
    return 
$return_code;
  }
  if (
is_remote($file_name)) {
    
$check_handle "check_remote_".$image_type;
    return (
$check_handle($file_name) && remote_file_exists($file_name$check_remote)) ? (($in_admin && !preg_match("#(gif|jpg|jpeg|png)$#is"$file_name)) ? ICON_PATH."/".get_file_extension($file_name).".gif" $file_name) : $return_code;
  }
  elseif (
is_local_file($file_name)) {
    
$check_handle "check_local_".$image_type;
    
$file_name = ($in_admin && preg_match("/^([\.]+|[^\/])/"$file_name)) ? "../".$file_name $file_name;
    if (!
file_exists($file_name)) {
      
$file_path preg_replace("/\/{2,}/""/"get_document_root()."/".$file_name);
      return (
$check_handle($file_name) && file_exists($file_path)) ? (($in_admin && !preg_match("#(gif|jpg|jpeg|png)$#is"$file_name)) ? ICON_PATH."/".get_file_extension($file_name).".gif" $file_name) : $return_code;
    }
    else {
      return 
$file_name;
    }
  }
  else {
    
$check_handle "check_".$image_type."_type";
    
$path = (($image_type == "media") ? (($cat_id) ? MEDIA_PATH."/".$cat_id MEDIA_TEMP_PATH) : (($cat_id) ? THUMB_PATH."/".$cat_id THUMB_TEMP_PATH))."/".$file_name;
    return (
$check_handle($file_name) && file_exists($path)) ? (($in_admin && !preg_match("#(gif|jpg|jpeg|png)$#is"$file_name)) ? ICON_PATH."/".get_file_extension($file_name).".gif" $path) : $return_code;
  }
}
function 
safe_htmlspecialchars($chars) {
  
// Translate all non-unicode entities
  
$chars preg_replace(
    
'/&(?!(#[0-9]+|[a-z]+);)/si',
    
'&amp;',
    
$chars
  
);

  
$chars str_replace(">""&gt;",   $chars);
  
$chars str_replace("<""&lt;",   $chars);
  
$chars str_replace('"'"&quot;"$chars);
  return 
$chars;
}

function 
un_htmlspecialchars($text) {
  
$text str_replace(
    array(
'&lt;''&gt;''&quot;''&amp;'),
    array(
'<',    '>',    '"',      '&'),
    
$text
  
);

  return 
$text;
}

function 
get_iptc_info($info) {
  
$iptc_match = array();
  
$iptc_match['2#120'] = "caption";
  
$iptc_match['2#122'] = "caption_writer";
  
$iptc_match['2#105'] = "headline";
  
$iptc_match['2#040'] = "special_instructions";
  
$iptc_match['2#080'] = "byline";
  
$iptc_match['2#085'] = "byline_title";
  
$iptc_match['2#110'] = "credit";
  
$iptc_match['2#115'] = "source";
  
$iptc_match['2#005'] = "object_name";
  
$iptc_match['2#055'] = "date_created";
  
$iptc_match['2#090'] = "city";
  
$iptc_match['2#095'] = "state";
  
$iptc_match['2#101'] = "country";
  
$iptc_match['2#103'] = "original_transmission_reference";
  
$iptc_match['2#015'] = "category";
  
$iptc_match['2#020'] = "supplemental_category";
  
$iptc_match['2#025'] = "keyword";
  
$iptc_match['2#116'] = "copyright_notice";

  
$iptc iptcparse($info);
  
$iptc_array = array();
  if (
is_array($iptc)) {
    foreach (
$iptc as $key => $val) {
      if (isset(
$iptc_match[$key])) {
        
$iptc_info "";
        foreach (
$val as $val2) {
          
$iptc_info .= (($iptc_info != "" ) ? ", " "").$val2;
        }
        if (
$key == "2#055") {
          
$iptc_array[$iptc_match[$key]] = preg_replace("/([0-9]{4})([0-9]{2})([0-9]{2})/""\\3.\\2.\\1"$iptc_info);
        }
        else {
          
$iptc_array[$iptc_match[$key]] = $iptc_info;
        }
      }
    }
  }
  return 
$iptc_array;
}

function 
get_exif_info($exif) {
  
$exif_match = array();
  
$exif_match['Make'] = "make";
  
$exif_match['Model'] = "model";
  
$exif_match['DateTimeOriginal'] = "datetime";
  
$exif_match['ISOSpeedRatings'] = "isospeed";
  
$exif_match['ExposureTime'] = "exposure";
  
$exif_match['FNumber'] = "aperture";
  
$exif_match['FocalLength'] = "focallen";

  
$exif_array = array();
  if (
is_array($exif)) {
    foreach (
$exif as $key => $val) {
      if (isset(
$exif_match[$key])) {
        
$exif_info $val;
        if (
$key == "DateTimeOriginal") {
          
$exif_array[$exif_match[$key]] = preg_replace("/([0-9]{4}):([0-9]{2}):([0-9]{2})/""\\3.\\2.\\1"$exif_info);
        }
        elseif (
$key == "ExposureTime") {
  $exposure explode("/"$exif_info);
          
$exif_array[$exif_match[$key]] = "1/" . ($exposure[1] / $exposure[0]);
        }
        elseif (
$key == "FNumber") {
  $aperture explode("/"$exif_info);
          
$exif_array[$exif_match[$key]] = "F/" . ($aperture[0] / $aperture[1]);
        }
        elseif (
$key == "FocalLength") {
  $focalLen explode("/"$exif_info);
          
$exif_array[$exif_match[$key]] = ($focalLen[0] / $focalLen[1]) . "mm";
        }
        else {
          
$exif_array[$exif_match[$key]] = $exif_info;
        }
      }
    }
  }
  return 
$exif_array;
}

function 
show_image($image_row$mode ""$show_link 1$detailed_view 0) {
  global 
$self_url$site_template$site_sess$user_info$config$cat_cache$lang$additional_image_fields$user_table_fields$url_show_profile$image_row_temp;
  global 
$multi_download_options_string;// MOD multi download
$image_row_temp $image_row;

  
$is_new = ($image_row['image_date'] >= (time() - 60 60 24 $config['new_cutoff'])) ? 0;
  
$description = (!empty($image_row['image_description'])) ? format_text($image_row['image_description'], 101) : REPLACE_EMPTY;

  if (!empty(
$image_row['image_keywords'])) {
    
$split_keywords explode(" "$image_row['image_keywords']);
    
$keywords "";
    foreach (
$split_keywords as $key => $val) {
      
$keywords .= (($keywords != "" ) ? ", " "")."<a href=\"".$site_sess->url(ROOT_PATH."search.php?search_keywords=".urlencode($val))."\">".format_text($val2)."</a>";
    }
  }
  else {
    
$keywords REPLACE_EMPTY;
  }

  if (!
check_permission("auth_readcomment"$image_row['cat_id'])) {
    
$image_row['image_allow_comments'] = 0;
  }

  
$num_comments = ($image_row['image_allow_comments'] == 1) ? $image_row['image_comments'] : "";

  if (
$user_info['user_level'] != GUEST) {
    
$lightbox_url $self_url;
    
$lightbox_url .= (!empty($mode)) ? ((strpos($lightbox_url'?') !== false) ? "&amp;" "?")."mode=".$mode "";
    
$lightbox_url .= strpos($lightbox_url'?') !== false "&amp;" "?";
    if (
check_lightbox($image_row['image_id'])) {
      
$lightbox_url .= "action=removefromlightbox&amp;id=".$image_row['image_id'];
      
$lightbox_button "<a href=\"".$site_sess->url($lightbox_url)."\"><img src=\"".get_gallery_image("lightbox_yes.gif")."\" border=\"0\" alt=\"\" /></a>";
    }
    else {
      
$lightbox_url .= "action=addtolightbox&amp;id=".$image_row['image_id'];
      
$lightbox_button "<a href=\"".$site_sess->url($lightbox_url)."\"><img src=\"".get_gallery_image("lightbox_no.gif")."\" border=\"0\" alt=\"\" /></a>";
    }
  }
  else {
    
$lightbox_button "<img src=\"".get_gallery_image("lightbox_off.gif")."\" border=\"0\" alt=\"\" />";
  }

  if (!
check_permission("auth_download"$image_row['cat_id'])) {
    
$download_button "<img src=\"".get_gallery_image("download_off.gif")."\" border=\"0\" alt=\"\" />";
    
$download_zip_button = (function_exists("gzcompress") && function_exists("crc32")) ? "<img src=\"".get_gallery_image("download_zip_off.gif")."\" border=\"0\" alt=\"\" />" "";
    
$allow_download 0;
    
clear_download_token($image_row['image_id']);
  }
  else {
    
$target = (!empty($image_row['image_download_url']) && !is_remote_file($image_row['image_download_url']) && !is_local_file($image_row['image_download_url'])) ? "target=\"_blank\"" "";
    
$download_button "<a href=\"".$site_sess->url(ROOT_PATH."download.php?".URL_IMAGE_ID."=".$image_row['image_id'])."\"".$target."><img src=\"".get_gallery_image("download.gif")."\" border=\"0\" alt=\"\" /></a>";
    
$download_zip_button = ($target == "" && function_exists("gzcompress") && function_exists("crc32")) ? "<a href=\"".$site_sess->url(ROOT_PATH."download.php?action=zip&amp;".URL_IMAGE_ID."=".$image_row['image_id'])."\"".$target."><img src=\"".get_gallery_image("download_zip.gif")."\" border=\"0\" alt=\"\" /></a>" "";
    
$allow_download 1;
    
set_download_token($image_row['image_id']);
  }

// MOD multi download

if (!check_permission("auth_download"$image_row['cat_id'])) {
$multi_download_options="&nbsp;&nbsp;<img src=\"".get_gallery_image("download_off.gif")."\" border=\"0\" alt=\"\" />";
$allow_download 0;
clear_download_token($image_row['image_id']);
}
else{
$multi_download_options $multi_download_options_string;
    
$multi_download_options .= "</td><td><input type='submit' name='download' value='".$lang['download']."' class='button' />
                   </TD></TR></TABLE></TABLE><input type='hidden' name='action' value='resize' />
                    <input type='hidden' name='image_id' value='"
.$image_row['image_id']."' /></form>";
//
$allow_download 1;
    
set_download_token($image_row['image_id']);

}
$site_template->register_vars("multi_download_options"$multi_download_options);
// END MOD multi download

  
if (!check_permission("auth_sendpostcard"$image_row['cat_id'])) {
    
$postcard_button "<img src=\"".get_gallery_image("postcard_off.gif")."\" border=\"0\" alt=\"\" />";
  }
  else {
    
$postcard_button "<a href=\"".$site_sess->url(ROOT_PATH."postcards.php?".URL_IMAGE_ID."=".$image_row['image_id'].((!empty($mode)) ? "&amp;mode=".$mode ""))."\"><img src=\"".get_gallery_image("postcard.gif")."\" border=\"0\" alt=\"\" /></a>";
  }

  if (!
check_permission("auth_viewimage"$image_row['cat_id']) || !check_permission("auth_viewcat"$image_row['cat_id'])) {
    
$show_link 0;
  }

  
$file_size "n/a";
  if (!
is_remote($image_row['image_media_file'])) {
    if (
$file_size = @filesize(MEDIA_PATH."/".$image_row['cat_id']."/".$image_row['image_media_file'])) {
      
$file_size format_file_size($file_size);
    }
  }
  elseif (
$detailed_view) {
    
$file_size get_remote_file_size($image_row['image_media_file']);
  }

  if (isset(
$image_row[$user_table_fields['user_name']]) && $image_row['user_id'] != GUEST) {
    
$user_name format_text($image_row[$user_table_fields['user_name']], 2);

    
$user_profile_link = (!empty($url_show_profile)) ? str_replace("{user_id}"$image_row['user_id'], $url_show_profile) : ROOT_PATH."member.php?action=showprofile&amp;".URL_USER_ID."=".$image_row['user_id'];
    
$user_name_link "<a href=\"".$site_sess->url($user_profile_link)."\">".$user_name."</a>";
  }
  else {
    
$user_name format_text($lang['userlevel_guest'], 2);
    
$user_name_link $user_name;
  }

  
$site_template->register_vars(array(
    
"image_id" => $image_row['image_id'],
    
"user_id" => $image_row['user_id'],
    
"user_name" => $user_name,
    
"user_name_link" => $user_name_link,
    
"image_name" => format_text($image_row['image_name'], 2),
    
"image_description" => $description,
    
"image_keywords" => $keywords,
    
"image_date" => format_date($config['date_format']." ".$config['time_format'],$image_row['image_date']),
    
"image_is_new" => $is_new,
    
"lang_new" => $lang['new'],
    
"image_active" => $image_row['image_active'],
    
"cat_id" => $image_row['cat_id'],
    
"cat_name" => format_text($image_row['cat_name'], 2),
    
"cat_url" => $site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$image_row['cat_id']),
    
"image_downloads" => $image_row['image_downloads'],
    
"image_votes" => $image_row['image_votes'],
    
"image_rating" => $image_row['image_rating'],
    
"image_hits" => $image_row['image_hits'],
    
"allow_comments" => $image_row['image_allow_comments'],
    
"lang_comments" => $lang['comments'],
    
"image_comments" => $num_comments,
    
"lightbox_button" => $lightbox_button,
    
"postcard_button" => $postcard_button,
    
"download_button" => $download_button,
    
"download_zip_button" => $download_zip_button,
    
"image_download_url" => $image_row['image_download_url'],
    
"allow_download" => $allow_download,
    
"url_download" => $site_sess->url(ROOT_PATH."download.php?".URL_IMAGE_ID."=".$image_row['image_id']),
    
"image_file_size" => $file_size,
    
"image_url" => ($show_link) ? $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_row['image_id'].((!empty($mode)) ? "&amp;mode=".$mode "")) : "",
    
"image" => get_media_code($image_row['image_media_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode$show_link$detailed_view),
    
"thumbnail" => get_thumbnail_code($image_row['image_media_file'], $image_row['image_thumb_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode$show_link),
    
"thumbnail_openwindow" => get_thumbnail_code($image_row['image_media_file'], $image_row['image_thumb_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode$show_link1),
    
"image_file_name" => $image_row['image_media_file'],
    
"thumbnail_file_name" => $image_row['image_thumb_file']
  ));

  if (!empty(
$additional_image_fields)) {
    
$additional_field_array = array();
    foreach (
$additional_image_fields as $key => $val) {
      
$additional_field_array[$key] = (!empty($image_row[$key])) ? format_text($image_row[$key], 1) : REPLACE_EMPTY;
      
$additional_field_array['lang_'.$key] = $val[0];
    }
    if (!empty(
$additional_field_array)) {
      
$site_template->register_vars($additional_field_array);
    }
  }

  
$rate_form "";
  if (
check_permission("auth_vote"$image_row['cat_id'])) {
    
$site_template->register_vars("rate"$lang['rate']);
    
$rate_form $site_template->parse_template("rate_form");
  }
  
$site_template->register_vars("rate_form"$rate_form);
  return 
true;
}

/******************** original code commented for popup

function get_thumbnail_code($media_file_name, $thumb_file_name = "", $image_id, $cat_id, $image_name = "", $mode = "", $show_link = 1, $open_window = 0) {
  global $site_sess, $config;

  if (!check_media_type($media_file_name)) {
    $thumb = "<img src=\"".ICON_PATH."/404.gif\" border=\"0\" alt=\"\" />";
  }
  else {
    if (!get_file_path($thumb_file_name, "thumb", $cat_id, 0, 0)) {
      $file_src = ICON_PATH."/".get_file_extension($media_file_name).".gif";
      $image_info = @getimagesize($file_src);
      $width_height = (!empty($image_info[3])) ? " ".$image_info[3] : "";
      $thumb = "<img src=\"".$file_src."\" border=\"0\"".$width_height." alt=\"".$image_name."\" />";
    }
    else {
      $file_src = get_file_path($thumb_file_name, "thumb", $cat_id, 0, 1);
      $image_info = @getimagesize($file_src);
      $width_height = (!empty($image_info[3])) ? " ".$image_info[3] : "";
      $thumb = "<img src=\"".$file_src."\" border=\"".$config['image_border']."\"".$width_height." alt=\"".$image_name."\" />";
    }
  }

  if ($show_link) {
    if ($open_window) {
      $thumb = "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_id.((!empty($mode)) ? "&amp;mode=".$mode : ""))."\" onclick=\"opendetailwindow()\" target=\"detailwindow\">".$thumb."</a>";
    }
    else {
      $thumb = "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_id.((!empty($mode)) ? "&amp;mode=".$mode : ""))."\">".$thumb."</a>";
    }
  }
  return $thumb;
}
   Original code commented for popup
****************/
function get_thumbnail_code($media_file_name$thumb_file_name ""$image_id$cat_id$image_name ""$mode ""$show_link 1$open_window 0) {
  global 
$site_sess$config$lang;;

  if (!
check_media_type($media_file_name)) {
    
$thumb "<img ".(($show_link) ? "" "onClick=\"alert('".$lang['members_only']."');\"")."src=\"".ICON_PATH."/404.gif\" border=\"0\" alt=\"\" />";
  }
  else {
    if (!
get_file_path($thumb_file_name"thumb"$cat_id00)) {
      
$file_src ICON_PATH."/".get_file_extension($media_file_name).".gif";
      
$image_info = @getimagesize($dummy);
      
$width_height = (!empty($image_info[3])) ? " ".$image_info[3] : "";

      
$thumb "<img src=\"".$file_src."\" ".(($show_link) ? "" "onClick=\"alert('".$lang['members_only']."'); \"")."border=\"0\"".$width_height." alt=\"".$image_name."\" />";
    }
    else {
      
$file_src get_file_path($thumb_file_name"thumb"$cat_id01);
      
$image_info = @getimagesize($file_src);
      
$width_height = (!empty($image_info[3])) ? " ".$image_info[3] : "";

global $image_row_temp;
if (!terms_check($cat_id, (($image_row_temp['terms']) ? $image_row_temp "")))
{
$file_src "thumb.php?file=".urlencode(str_replace(THUMB_DIR."/"""$file_src))."&folder=blur";
$thumb "<img src=\"".$file_src."\" ".(($show_link) ? "" "onClick=\"alert('".$lang['members_only']."'); \"")."border=\"".$config['image_border']."\"".$width_height." class=\"reflect rheight33 ropacity20\" alt=\"".$image_name."\" />";
}
else
{
$thumb "<img src=\"".$file_src."\" ".(($show_link) ? "" "onClick=\"alert('".$lang['members_only']."'); \"")."border=\"".$config['image_border']."\"".$width_height." class=\"reflect rheight33 ropacity20\" alt=\"".$image_name."\" />";
}
//    global $site_db;
//    $sql = "SELECT terms
//              FROM ".IMAGES_TABLE."
//              WHERE image_id = $image_id";
//    $result=$site_db->query($sql);
//    $row = $site_db->fetch_array($result);
//    $terms1 = $row['terms'];

//   if ($terms1['terms'] == 2) {

//  $file_src = "thumb.php?file=".urlencode(str_replace(THUMB_DIR."/", "", $file_src))."&folder=blur";
//  $thumb = "<img src=\"".$file_src."\" ".(($show_link) ? "" : "onClick=\"alert('".$lang['members_only']."'); \"")."border=\"".$config['image_border']."\"".$width_height." alt=\"".$image_name."\" />";
//     $thumb = "<img src=\"./data/thumbnails/test.jpg\" />";

//   }
//   else {
//   $thumb = "<img src=\"".$file_src."\" ".(($show_link) ? "" : "onClick=\"alert('".$lang['members_only']."'); \"")."border=\"".$config['image_border']."\"".$width_height." class=\"reflect rheight33 ropacity20\" alt=\"".$image_name."\" />";
//   }

    
}
  }

  if (
$show_link) {
    if (
$open_window) {
      
$thumb "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_id.((!empty($mode)) ? "&amp;mode=".$mode ""))."\" onclick=\"opendetailwindow()\" target=\"detailwindow\" scrollbars=\"yes\" top=\"0\" screenY=\"0\" left=\"0\" screenx=\"0\" width=\"1012\" height=\"732\">".$thumb."</a>";
    }
    else {
      
$thumb "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_id.((!empty($mode)) ? "&amp;mode=".$mode ""))."\">".$thumb."</a>";
    }
  }
  return 
$thumb;
}

function 
get_media_code($media_file_name$image_id 0$cat_id 0$image_name ""$mode ""$show_link 0$detailed_view 0) {
  global 
$site_template$site_sess$lang$mode;

  if (!
get_file_path($media_file_name"media"$cat_id00)) {
    
$media "<img src=\"".ICON_PATH."/404.gif\" border=\"0\" alt=\"\" />";
    
$site_template->register_vars("iptc_info""");
    
$site_template->register_vars("exif_info""");
  }
  else {
    
$media_src get_file_path($media_file_name"media"$cat_id01);
    
$media_src1 ROOT_PATH."image.php?w=650&img=".get_file_path($media_file_name"media"$cat_id01);
//    echo "$media_src1";
    
$file_extension get_file_extension($media_file_name);
    
$media_icon "<img src=\"".ICON_PATH."/".$file_extension.".gif\" border=\"0\" alt=\"".$image_name."\" />";
    if (
$show_link) {
      
$media_icon "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_id.((!empty($mode)) ? "&amp;mode=".$mode ""))."\">".$media_icon."</a>";
    }
    
$width_height "";
    
$width "";
    
$height "";
    
$iptc_info "";
    
$exif_info "";
    if (!
is_remote($media_src)) {
      
$src = (!file_exists($media_src) && file_exists(preg_replace("/\/{2,}/""/"get_document_root()."/".$media_src))) ? preg_replace("/\/{2,}/""/"get_document_root()."/".$media_src) : $media_src;
      if (
$image_info = @getimagesize($src$info)) {
        
$width_height " ".$image_info[3];
        
$width $image_info[0];
        
$height $image_info[1];
        if (
$detailed_view && isset($info['APP13'])) {
          
$iptc_array get_iptc_info($info['APP13']);
          
$bgcounter 0;
          foreach (
$iptc_array as $key => $val) {
            
$row_bg_number = ($bgcounter++ % == 0) ? 2;
            
$site_template->register_vars(array(
              
"iptc_value" => format_text($val),
              
"iptc_name" => $lang['iptc_'.$key],
              
"row_bg_number" => $row_bg_number
            
));
            
$iptc_info .= $site_template->parse_template("iptc_bit");
          }
        }
        if (
$detailed_view && $image_info[2] == && function_exists('exif_read_data') && $exif_data = @exif_read_data($src'EXIF')) {
          
$exif_array get_exif_info($exif_data);
          
$bgcounter 0;
          foreach (
$exif_array as $key => $val) {
            
$row_bg_number = ($bgcounter++ % == 0) ? 2;
            
$site_template->register_vars(array(
              
"exif_value" => format_text($val),
              
"exif_name" => $lang['exif_'.$key],
              
"row_bg_number" => $row_bg_number
            
));
            
$exif_info .= $site_template->parse_template("exif_bit");
          }
        }
      }
    }
    
$site_template->register_vars(array(
      
"media_src" => $media_src,
      
"media_src1" => $media_src1,
      
"media_icon" => $media_icon,
      
"image_name" => $image_name,
      
"width_height" => $width_height,
      
"width" => $width,
      
"height" => $height,
      
"iptc_info" => $iptc_info,
      
"exif_info" => $exif_info
    
));
    
$media $site_template->parse_template("media/".$file_extension);
  }
  return 
$media;
}

function 
get_random_image_cache() {
  global 
$site_db$cat_cache$total_images;

  
$random_image_cache = array();
  
$cat_id_sql get_auth_cat_sql("auth_viewcat""NOTIN");

  if (
SHOW_RANDOM_CAT_IMAGE) {
    
$sql "SELECT DISTINCT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits, c.cat_name".get_user_table_field(", u.""user_name")."
            FROM ("
.IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
            LEFT JOIN "
.USERS_TABLE." u ON (".get_user_table_field("u.""user_id")." = i.user_id)
            WHERE i.image_active = 1 AND i.cat_id NOT IN (
$cat_id_sql) AND c.cat_id = i.cat_id
            ORDER BY RAND()"
;
    
$result $site_db->query($sql);
    while (
$row $site_db->fetch_array($result)) {
      
$random_image_cache[$row['cat_id']] = $row;
    }
  }
  else {
    if (empty(
$total_images)) {
      
$sql "SELECT COUNT(*) as total_images
              FROM "
.IMAGES_TABLE."
              WHERE image_active = 1 AND cat_id NOT IN (
$cat_id_sql)";
      
$row $site_db->query_firstrow($sql);
      
$total_images $row['total_images'];
    }
    if (empty(
$total_images)) {
      return 
$random_image_cache;
    }
    
mt_srand((double)microtime() * 1000000);
    
$number = ($total_images 1) ? mt_rand(0$total_images 1) : 0;

    
$sql "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits, c.cat_name".get_user_table_field(", u.""user_name")."
            FROM ("
.IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
            LEFT JOIN "
.USERS_TABLE." u ON (".get_user_table_field("u.""user_id")." = i.user_id)
            WHERE i.image_active = 1 AND i.cat_id NOT IN (
$cat_id_sql) AND c.cat_id = i.cat_id
            LIMIT 
$number, 1";
    
$random_image_cache[0] = $site_db->query_firstrow($sql);
  }
  return 
$random_image_cache;
}

function 
get_random_image($cat_id 0$show_link 1$return_file 0) {
  global 
$site_template$random_image_cache;

  if (!isset(
$random_image_cache)) {
    
$random_image_cache get_random_image_cache();
  }

  if (
$cat_id && SHOW_RANDOM_CAT_IMAGE) {
    
$template 'random_cat_image';
    
$category_id $cat_id;
  }
  else {
    
$template 'random_image';
    if (
SHOW_RANDOM_CAT_IMAGE) {
      
srand((float)microtime() * 1000000);
      
$category_id array_rand($random_image_cache);
    }
    else {
      
$category_id 0;
    }
  }

  if (!empty(
$random_image_cache[$category_id])) {
    if (!
$return_file) {
      
show_image($random_image_cache[$category_id], ""$show_link);
      
$random_image $site_template->parse_template($template);
      return 
$random_image;
    }
    else {
      return 
get_file_path($random_image_cache[$category_id]['image_thumb_file'], "thumb"$category_id01);
    }
  }
}

function 
format_file_size($file_size 0) {
  
//$file_size = intval($file_size);
  
if (!$file_size) {
    return 
"n/a";
  }
  if (
strlen($file_size) <= && strlen($file_size) >= 7) {
    
$file_size number_format($file_size 1048576,1);
    return 
$file_size."&nbsp;MB";
  }
  elseif (
strlen($file_size) >= 10) {
    
$file_size number_format($file_size 1073741824,1);
    return 
$file_size."&nbsp;GB";
  }
  else {
    
$file_size number_format($file_size 1024,1);
    return 
$file_size."&nbsp;KB";
  }
}

function 
get_remote_file_size($file_path) {
  if (!
CHECK_REMOTE_FILES) {
    return 
'n/a';
  }
  
ob_start();
  @
readfile($file_path);
  
$file_data ob_get_contents();
  
ob_end_clean();
  return 
format_file_size(strlen($file_data));
}

function 
update_comment_count($image_id 0$user_id 0) {
  global 
$site_db$user_table_fields;
  if (
$image_id) {
    
$sql "SELECT COUNT(comment_id) AS comments
            FROM "
.COMMENTS_TABLE."
            WHERE image_id = 
$image_id";
    
$countcomments $site_db->query_firstrow($sql);
    
$sql "UPDATE ".IMAGES_TABLE."
            SET image_comments = "
.$countcomments['comments']."
            WHERE image_id = 
$image_id";
    
$site_db->query($sql);
  }
  if (
$user_id != GUEST && $user_id && !empty($user_table_fields['user_comments'])) {
    
$sql "SELECT COUNT(comment_id) AS comments
            FROM "
.COMMENTS_TABLE."
            WHERE user_id = 
$user_id";
    
$countcomments $site_db->query_firstrow($sql);
    
$sql "UPDATE ".USERS_TABLE."
            SET "
.get_user_table_field("""user_comments")." = ".$countcomments['comments']."
            WHERE "
.get_user_table_field("""user_id")." = $user_id";
    
$site_db->query($sql);
  }
}

function 
update_image_rating($image_id$rating) {
  global 
$site_db;
  
$sql "SELECT cat_id, image_votes, image_rating
          FROM "
.IMAGES_TABLE."
          WHERE image_id = 
$image_id";
  
$image_row $site_db->query_firstrow($sql);
  if (
check_permission("auth_vote"$image_row['cat_id'])) {
    
$old_votes $image_row['image_votes'];
    
$old_rating $image_row['image_rating'];
    
$new_rating = (($old_rating $old_votes) + $rating) / ($old_votes 1);
    
$new_rating sprintf("%.2f"$new_rating);
    
$sql "UPDATE ".IMAGES_TABLE."
            SET image_votes = (
$old_votes + 1), image_rating = '$new_rating'
            WHERE image_id = 
$image_id";
    
$site_db->query($sql);
  }
}

function 
check_email($email) {
  return (
preg_match('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+@([-0-9A-Z]+\.)+([0-9A-Z]){2,4}$/i'$email)) ? 0;
}

function 
format_date($format$timestamp) {
  global 
$user_info;
  
$timezone_offset = (defined("TIME_OFFSET")) ? TIME_OFFSET 0;
  return 
date($format$timestamp + (3600 $timezone_offset));
}

function 
format_url($url) {
  if (empty(
$url)) {
    return 
'';
  }

  if (!
preg_match("/^https?:\/\//i"$url)) {
    
$url "http://".$url;
  }

  return 
$url;
}

function 
replace_url($text) {
  
$text " ".$text." ";
  
$url_search_array = array(
    
"#([^]_a-z0-9-=\"'\/])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^, \(\)<>\n\r]*)?)#si",
    
"#([^]_a-z0-9-=\"'\/])([a-z]+?)://([^, \(\)<>\n\r]+)#si"
  
);

  
$url_replace_array = array(
    
"\\1<a href=\"http://www.\\2.\\3\\4\" target=\"_blank\" rel=\"nofollow\">www.\\2.\\3\\4</a>",
    
"\\1<a href=\"\\2://\\3\" target=\"_blank\" rel=\"nofollow\">\\2://\\3</a>",
  );
  
$text preg_replace($url_search_array$url_replace_array$text);

  if (
strpos($text"@")) {
    
$text preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i""\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>"$text);
  }
  return 
substr($text1, -1);
}

function 
replace_badwords($text) {
  global 
$config$split_badwords;
  if (
$config['badword_list'] != "") {
    if (!isset(
$split_badwords)) {
      
$badwords trim($config['badword_list']);
      
$badwords preg_replace("/[\n\r]/is"" "$badwords);
      
$badwords str_replace(","," ",$badwords);
      
$badwords preg_quote($badwords);
      
$badwords str_replace('/''\\/'$badwords);
      
$split_badwords preg_split("/\s+/"$badwords);
    }

    foreach (
$split_badwords as $key => $val) {
      if (
$val != "") {
        if (
substr($val02) == "\\{") {
          
$val substr($val2, -2);
          
$text trim(preg_replace("/([^A-Za-z])".$val."(?=[^A-Za-z])/si""\\1".str_repeat($config['badword_replace_char'], strlen($val)), $text "));
        }
        else {
          
$text trim(preg_replace("/$val/si"str_repeat($config['badword_replace_char'], strlen($val)), $text "));
        }
      }
    }
  }
  return 
$text;
}

function 
format_text($text$html 0$word_wrap 0$bbcode 0$bbcode_img 0) {
  if (
$word_wrap && $text != "") {
    
$text preg_replace("/([^\n\r ?&\.\/<>\"\\-]{".$word_wrap."})/i"" \\1\n"$text);
  }

  if (
$html == || $html == 2) {
    
$text safe_htmlspecialchars($text);
  }

  if (
$html !== 2) {
    
$text nl2br(trim($text));
    
$text replace_url($text);
  }

  if (
$bbcode == 1) {
    
$search_array = array(
      
"/(\[)(list)(=)(['\"]?)([^\"']*)(\\4])(.*)(\[\/list)(((=)(\\4)([^\"']*)(\\4]))|(\]))/siU",
      
"/(\[)(list)(])(.*)(\[\/list\])/siU",
      
"/(\[\*\])/siU",
      
"/(\[\/\*\])/siU",
      
"/(\[)(url)(=)(['\"]?)(www\.)([^\"']*)(\\4])(.*)(\[\/url\])/siU",
      
"/(\[)(url)(=)(['\"]?)([^\"']*)(\\4])(.*)(\[\/url\])/siU",
      
"/(\[)(url)(])(www\.)([^\"]*)(\[\/url\])/siU",
      
"/(\[)(url)(])([^\"]*)(\[\/url\])/siU",
      
"/(\[)(code)(])(\r\n)*(.*)(\[\/code\])/siU",
      
"/javascript:/si",
      
"/about:/si"
    
);
    
$replace_array = array(
      
"<ol type=\"\\5\">\\7</ol>",
      
"<ul>\\4</ul>",
      
"<li>",
      
"</li>",
      
"<a href=\"http://www.\\6\" target=\"_blank\" rel=\"nofollow\">\\8</a>",
      
"<a href=\"\\5\" target=\"_blank\" rel=\"nofollow\">\\7</a>",
      
"<a href=\"http://www.\\5\" target=\"_blank\" rel=\"nofollow\">www.\\5</a>",
      
"<a href=\"\\4\" target=\"_blank\" rel=\"nofollow\">\\4</a>",
      
"<pre>Code:<hr size=1>\\5<hr size=1></pre>",
      
"java script:",
      
"about :"
    
);
    
$text preg_replace($search_array$replace_array$text);
    if (!
$bbcode_img)  {
      
$text preg_replace("/(\[)(img)(])(\r\n)*([^\"]*)(\[\/img\])/siU""<a href=\"\\5\" target=\"_blank\">\\5</a>"$text);
    }
    else  {
      
$text preg_replace("/(\[)(img)(])(\r\n)*([^\"]*)(\[\/img\])/siU""<img src=\"\\5\">"$text);
    }
    
$text preg_replace("/(\[)(b)(])(\r\n)*([^\"]*)(\[\/b\])/siU""<b>\\5</b>"$text);
    
$text preg_replace("/(\[)(i)(])(\r\n)*([^\"]*)(\[\/i\])/siU""<i>\\5</i>"$text);
    
$text preg_replace("/(\[)(u)(])(\r\n)*([^\"]*)(\[\/u\])/siU""<u>\\5</u>"$text);

    
$text replace_badwords($text);
  }

  
$text str_replace("\\'""'"$text);

  return 
$text;
}

function 
utf8_to_htmlentities($source) {
  
// array used to figure what number to decrement from character order
  // value
  // according to number of characters used to map unicode to ascii by
  // utf-8
  
$decrement = array();
  
$decrement[4] = 240;
  
$decrement[3] = 224;
  
$decrement[2] = 192;
  
$decrement[1] = 0;

  
// the number of bits to shift each charNum by
  
$shift = array();
  
$shift[1][0] = 0;
  
$shift[2][0] = 6;
  
$shift[2][1] = 0;
  
$shift[3][0] = 12;
  
$shift[3][1] = 6;
  
$shift[3][2] = 0;
  
$shift[4][0] = 18;
  
$shift[4][1] = 12;
  
$shift[4][2] = 6;
  
$shift[4][3] = 0;

  
$pos 0;
  
$len strlen($source);
  
$str '';
  while (
$pos $len) {
    
$asciiPos ord(substr($source$pos1));
    if ((
$asciiPos >= 240) && ($asciiPos <= 255)) {
      
// 4 chars representing one unicode character
      
$thisLetter substr($source$pos4);
      
$pos += 4;
    }
    elseif ((
$asciiPos >= 224) && ($asciiPos <= 239)) {
      
// 3 chars representing one unicode character
      
$thisLetter substr($source$pos3);
      
$pos += 3;
    }
    else if ((
$asciiPos >= 192) && ($asciiPos <= 223)) {
      
// 2 chars representing one unicode character
      
$thisLetter substr($source$pos2);
      
$pos += 2;
    }
    else {
      
// 1 char (lower ascii)
      
$thisLetter substr($source$pos1);
      
$pos += 1;
    }

    
// process the string representing the letter to a unicode entity
    
$thisLen strlen($thisLetter);
    
$thisPos 0;
    
$decimalCode 0;

    while (
$thisPos $thisLen) {
      
$thisCharOrd ord(substr($thisLetter$thisPos1));
      if (
$thisPos == 0) {
        
$charNum intval($thisCharOrd $decrement[$thisLen]);
        
$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
      } else {
        
$charNum intval($thisCharOrd 128);
        
$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
      }
      
$thisPos++;
    }
    if ((
$thisLen == 1) && ($decimalCode <= 128)) {
      
$encodedLetter $thisLetter;
    }
    else {
      
$encodedLetter '&#38;#' $decimalCode ';';
    }
    
$str .= $encodedLetter;
  }
  return 
$str;
}

function 
uni_to_utf8($char) {
  
$char intval($char);

  switch (
$char) {
    case (
$char 128) :
      
// its an ASCII char no encoding needed
      
return chr($char);

    case (
$char << 11) :
      
// its a 2 byte UTF-8 char
      
return chr(192 + ($char >> 6)) .
             
chr(128 + ($char 63));

    case (
$char << 16) :
      
// its a 3 byte UTF-8 char
      
return chr(224 + ($char >> 12)) .
             
chr(128 + (($char >> 6) & 63)) .
             
chr(128 + ($char 63));

    case (
$char << 21) :
      
// its a 4 byte UTF-8 char
      
return chr(240 + ($char >> 18)) .
             
chr(128 + (($char >> 12) & 63)) .
             
chr(128 + (($char >>  6) & 63)) .
             
chr(128 + ($char 63));

    case (
$char << 26) :
      
// its a 5 byte UTF-8 char
      
return chr(248 + ($char >> 24)) .
             
chr(128 + (($char >> 18) & 63)) .
             
chr(128 + (($char >> 12) & 63)) .
             
chr(128 + (($char >> 6) & 63)) .
             
chr(128 + ($char 63));
    default:
      
// its a 6 byte UTF-8 char
      
return chr(252 + ($char >> 30)) .
             
chr(128 + (($char >> 24) & 63)) .
             
chr(128 + (($char >> 18) & 63)) .
             
chr(128 + (($char >> 12) & 63)) .
             
chr(128 + (($char >> 6) & 63)) .
             
chr(128 + ($char 63));
  }
}

function 
get_user_info($user_id 0) {
  global 
$site_db$user_table_fields;
  
$user_info 0;
  if (
$user_id != && $user_id != GUEST) {
    
$sql "SELECT *
            FROM "
.USERS_TABLE."
            WHERE "
.get_user_table_field("""user_id")." = $user_id";
    if (
$user_info $site_db->query_firstrow($sql)) {
      foreach (
$user_table_fields as $key => $val) {
        if (isset(
$user_info[$val])) {
          
$user_info[$key] = $user_info[$val];
        }
        elseif (!isset(
$user_info[$key])) {
          
$user_info[$key] = "";
        }
      }
    }
  }
  return 
$user_info;
}

function 
get_icq_status($uin) {
  if (!
is_numeric($uin)) return false;

  
$fp = @fsockopen('status.icq.com'80$errno$errstr8);
  if (!
$fp) return false;

  
$request "HEAD /online.gif?icq=$uin&img=3 HTTP/1.0\r\n"
            
."Host: status.icq.com\r\n"
            
."Connection: close\r\n\r\n";
  
fputs($fp$request);

  do {
     
$response fgets($fp1024);
  }
  while (!
feof($fp) && !stristr($response'Location'));

  
fclose($fp);
  if (
strstr($response'online1')) return 'online';
  if (
strstr($response'online0')) return 'offline';
  if (
strstr($response'online2')) return 'disabled';
  return 
FALSE;
}

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)) ? 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)) ? 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;
  }
}

function 
check_lightbox($id) {
  global 
$user_info;
  
$lightbox_array explode(" "$user_info['lightbox_image_ids']);
  return 
in_array($id$lightbox_array);
}

function 
get_random_key($db_table ""$db_column "") {
  global 
$site_db;
  
$key md5(uniqid(microtime()));
  if (
$db_table != "" && $db_column != "") {
    
$i 0;
    while (
$i == 0) {
      
$sql "SELECT ".$db_column."
              FROM "
.$db_table."
              WHERE "
.$db_column." = '$key'";
      if (
$site_db->is_empty($sql)) {
        
$i 1;
      }
      else {
        
$i 0;
        
$key md5(uniqid(microtime()));
      }
    }
  }
  return 
$key;
}

function 
get_subcat_ids($cid 0$cat_id 0$cat_parent_cache) {
  global 
$subcat_ids;

  if (!isset(
$cat_parent_cache[$cid])) {
    return 
false;
  }
  foreach (
$cat_parent_cache[$cid] as $key => $val) {
    if (
check_permission("auth_viewcat"$val)) {
      
$subcat_ids[$cat_id][] = $val;
      
get_subcat_ids($val$cat_id$cat_parent_cache);
    }
  }
  return 
$subcat_ids;
}

function 
get_subcategories($parent_id) {
  global 
$cat_parent_cache$cat_cache$site_sess$config;

  if (!isset(
$cat_parent_cache[$parent_id]) || $config['num_subcats'] < 1) {
    return 
"";
  }

  
$visible_cat_cache = array();
  foreach (
$cat_parent_cache[$parent_id] as $key => $val) {
    if (
check_permission("auth_viewcat"$val)) {
      
$visible_cat_cache[$key] = $val;
    }
  }

  
$num_subs sizeof($visible_cat_cache);
  
$sub_cat_list "";
  
$i 1;
  foreach (
$visible_cat_cache as $subcat_id) {
    if (
$i <= $num_subs && $i <= $config['num_subcats']) {
      
$sub_url $site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$subcat_id);
      
$sub_cat_list .= "<a href=\"".$sub_url."\" class=\"subcat\">".format_text($cat_cache[$subcat_id]['cat_name'], 2)."</a>";
      if (
$i != $config['num_subcats'] && $i $config['num_subcats'] && $i $num_subs) {
        
$sub_cat_list .= ", ";
      }
      if (
$i == $config['num_subcats'] && $i $num_subs) {
        
$sub_cat_list .= " ...\n";
      }
    }
    
$i++;
  }
  return 
$sub_cat_list;
}

function 
get_categories($cat_id 0) {
  global 
$site_template$site_db$site_sess$config$lang;
  global 
$cat_cache$cat_parent_cache$new_image_cache$subcat_ids;

  
$cattable_width ceil((intval($config['cat_table_width'])) / $config['cat_cells']);
  if ((
substr($config['cat_table_width'],-1)) == "%") {
    
$cattable_width .= "%";
  }

  if (!isset(
$cat_parent_cache[$cat_id])) {
    return 
"";
  }

  
$visible_cat_cache = array();
  foreach (
$cat_parent_cache[$cat_id] as $key => $val) {
    if (
check_permission("auth_viewcat"$val)) {
      
$visible_cat_cache[$key] = $val;
    }
  }

  if (empty(
$visible_cat_cache)) {
    return 
"";
  }

  
$total sizeof($visible_cat_cache);
  
$table_columns = (intval($config['cat_cells'])) ? intval($config['cat_cells']) : 2;
  if (
$total <= $table_columns) {
    
$table_rows 1;
  }
  else {
    
$table_rows $total $table_columns;
    if (
$total >= $table_columns && !is_integer($table_rows)) {
      
$table_rows intval($table_rows) + 1;
    }
  }

  
$categories "\n<table width=\"".$config['cat_table_width']."\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n<td valign=\"top\" width=\"".$cattable_width."\" class=\"catbgcolor\">\n";
  
$categories .= "<table border=\"0\" cellpadding=\"".$config['cat_table_cellpadding']."\" cellspacing=\"".$config['cat_table_cellspacing']."\">\n";
  
$count 0;
  
$count2 0;
  foreach (
$visible_cat_cache as $key => $category_id) {
    
$categories .= "<tr>\n<td valign=\"top\">\n";

    
$is_new = (isset($new_image_cache[$category_id]) && $new_image_cache[$category_id] > 0) ? 0;
    
$num_images = (isset($cat_cache[$category_id]['num_images'])) ? $cat_cache[$category_id]['num_images'] : 0;

    
$subcat_ids = array();
    
get_subcat_ids($category_id$category_id$cat_parent_cache);

    if (isset(
$subcat_ids[$category_id])) {
      foreach (
$subcat_ids[$category_id] as $val) {
        if (isset(
$new_image_cache[$val]) && $new_image_cache[$val] > 0) {
          
$is_new 1;
        }
        if (isset(
$cat_cache[$val]['num_images'])) {
          
$num_images += $cat_cache[$val]['num_images'];
        }
      }
    }

    if (
defined("SHOW_RANDOM_IMAGE") && SHOW_RANDOM_IMAGE == || defined("SHOW_RANDOM_CAT_IMAGE") && SHOW_RANDOM_CAT_IMAGE == 0) {
      
$random_cat_image_file "";
    }
    else {
      
$random_cat_image_file get_random_image($category_id01);
    }

    
$site_template->register_vars(array(
      
"cat_id" => $category_id,
      
"cat_name" => format_text($cat_cache[$category_id]['cat_name'], 2),
      
"cat_description" => format_text($cat_cache[$category_id]['cat_description'], 1),
      
"cat_hits" => $cat_cache[$category_id]['cat_hits'],
      
"cat_is_new" => $is_new,
      
"lang_new" => $lang['new'],
      
"sub_cats" => get_subcategories($category_id),
      
"cat_url" => $site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$category_id),
      
"random_cat_image_file" => $random_cat_image_file,
      
"num_images" => $num_images
    
));
    
$categories .= $site_template->parse_template("category_bit");
    
$count++;
    
$count2++;
    
$categories .= "</td>\n</tr>\n";

    if (
$count == $table_rows && $count2 sizeof($visible_cat_cache)) {
      
$categories .= "</table></td>\n";
      
$categories .= "<td valign=\"top\" width=\"".$cattable_width."\" class=\"catbgcolor\">\n";
      
$categories .= "<table border=\"0\" cellpadding=\"".$config['cat_table_cellpadding']."\" cellspacing=\"".$config['cat_table_cellspacing']."\">\n";

      
$total $total $count2;
      
$table_columns $table_columns 1;
      
/*if ($total <= $table_columns && $table_columns > 1) {
        $table_rows = 1;
      }
      else {
        $table_rows = $total / $table_columns;
        if ($total >= $table_columns && !is_integer($table_rows)) {
          $table_rows = intval($table_rows) + 1;
        }
      }*/
      
$count 0;
    }
  }

  
$categories .= "</table>\n</td>\n</tr>\n</table>\n";
  return 
$categories;
}

function 
get_category_path($cat_id 0$detail_path 0) {
  global 
$site_sess$config$cat_cache$url;
  
$parent_id 1;
  while (
$parent_id) {
    if (!isset(
$cat_cache[$cat_id]['cat_parent_id'])) {
      return 
false;
    }
    
$parent_id $cat_cache[$cat_id]['cat_parent_id'];

    if (empty(
$path)) {
      if (
$detail_path) {
        
$cat_url ROOT_PATH."categories.php?".URL_CAT_ID."=".$cat_id;
        if (
preg_match("/".URL_PAGE."=([0-9]+)/"$url$regs)) {
          if (!empty(
$regs[1]) && $regs[1] != 1) {
            
$cat_url .= "&amp;".URL_PAGE."=".$regs[1];
          }
        }
        
$path "<a href=\"".$site_sess->url($cat_url)."\" class=\"clickstream\">".format_text($cat_cache[$cat_id]['cat_name'], 2)."</a>";
      }
      else  {
        
$path format_text($cat_cache[$cat_id]['cat_name'], 2);
      }
    }
    else {
      
$path "<a href=\"".$site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$cat_id)."\" class=\"clickstream\">".format_text($cat_cache[$cat_id]['cat_name'], 2)."</a>".$config['category_separator'].$path;
    }
    
$cat_id $parent_id;
  } 
// end while
  
return $path;
}

function 
get_category_path_nohtml($cat_id 0) {  // MOD: Dynamic page title
  
global $config$cat_cache;
  
$parent_id 1;
  while (
$parent_id) {
    if (!isset(
$cat_cache[$cat_id]['cat_parent_id'])) {
      return 
false;
    }
    
$parent_id $cat_cache[$cat_id]['cat_parent_id'];

    if (empty(
$path)) {
      
$path $cat_cache[$cat_id]['cat_name'];
    }
    else {
      
$path $cat_cache[$cat_id]['cat_name'].$config['category_separator'].$path;
    }
    
$cat_id $parent_id;
  } 
// end while
  
return $path;
}

function 
get_category_dropdown_bits($cat_id$cid 0$depth 1) {
  global 
$site_db$drop_down_cat_cache$cat_cache;

  if (!isset(
$drop_down_cat_cache[$cid])) {
    return 
"";
  }
  
$category_list "";
  foreach (
$drop_down_cat_cache[$cid] as $key => $category_id) {
    if (
check_permission("auth_viewcat"$category_id)) {
      
$category_list .= "<option value=\"".$category_id."\"";
      if (
$cat_id == $category_id) {
        
$category_list .= " selected=\"selected\"";
      }
      if (
$cat_cache[$category_id]['cat_parent_id'] == 0) {
        
$category_list .= " class=\"dropdownmarker\"";
      }

      if (
$depth 1) {
        
$category_list .= ">".str_repeat("--"$depth 1)." ".format_text($cat_cache[$category_id]['cat_name'], 2)."</option>\n";
      }
      else {
        
$category_list .= ">".format_text($cat_cache[$category_id]['cat_name'], 2)."</option>\n";
      }
      
$category_list .= get_category_dropdown_bits($cat_id$category_id$depth 1);
    }
  }
  unset(
$drop_down_cat_cache[$cid]);
  return 
$category_list;
}

function 
get_category_dropdown($cat_id$jump 0$admin 0$i 0) {
  global 
$lang$drop_down_cat_cache$cat_parent_cache;
  
// $admin = 1  Main Cat (update/add cats)
  // $admin = 2  All Cats (find/validate images...)
  // $admin = 3  Select Cat (update/add image)
  // $admin = 4  No Cat (check new images)

  
switch ($admin) {
  case 
1:
    
$category "\n<select name=\"cat_parent_id\" class=\"categoryselect\">\n";
    
$category .= "<option value=\"0\">".$lang['main_category']."</option>\n";
    
$category .= "<option value=\"0\">--------------</option>\n";
    break;

  case 
2:
    
$category "\n<select name=\"cat_id\" class=\"categoryselect\">\n";
    
$category .= "<option value=\"0\">".$lang['all_categories']."</option>\n";
    
$category .= "<option value=\"0\">-------------------------------</option>\n";
    break;

  case 
3:
    
$i = ($i) ? "_".$i "";
    
$category "\n<select name=\"cat_id".$i."\" class=\"categoryselect\">\n";
    
$category .= "<option value=\"0\">".$lang['select_category']."</option>\n";
    
$category .= "<option value=\"0\">-------------------------------</option>\n";
    break;

  case 
4:
    
$category "\n<select name=\"cat_id\" class=\"categoryselect\">\n";
    
$category .= "<option value=\"0\">".$lang['no_category']."</option>\n";
    
$category .= "<option value=\"0\">-------------------------------</option>\n";
    break;

  case 
0:
  default:
    if (
$jump) {
      
$category "\n<select name=\"".URL_CAT_ID."\" onchange=\"if (this.options[this.selectedIndex].value != 0){ forms['jumpbox'].submit() }\" class=\"categoryselect\">\n";
    }
    else {
      
$category "\n<select name=\"".URL_CAT_ID."\" class=\"categoryselect\">\n";
    }
    
$category .= "<option value=\"0\">".$lang['select_category']."</option>\n";
    
$category .= "<option value=\"0\">-------------------------------</option>\n";
  } 
// end switch

  
$drop_down_cat_cache = array();
  
$drop_down_cat_cache $cat_parent_cache;
  
$category .= get_category_dropdown_bits($cat_id);
  
$category .= "</select>\n";
  return 
$category;
}

function 
show_error_page($error_msg$clickstream "") {
  global 
$site_template$site_sess$lang$config;
  if (empty(
$clickstream)) {
    
$clickstream "<a href=\"".$site_sess->url(ROOT_PATH."index.php")."\">".$lang['home']."</a>".$config['category_separator'].$lang['error'];
  }
  
$site_template->register_vars(array(
    
"error_msg" => $error_msg,
    
"lang_error" => $lang['error'],
    
"clickstream" => $clickstream,
    
"random_image" => ""
  
));
  
// MOD: Dynamic page title BLOCK BEGIN
  
$header $site_template->parse_template("header");
  
$footer $site_template->parse_template("footer");
  
$site_template->register_vars(array(
    
"header" => $header,
    
"footer" => $footer
  
));
  unset(
$header);
  unset(
$footer);
  
// MOD: Dynamic page title BLOCK END
  
$site_template->print_template($site_template->parse_template("error"));
  exit;
}

function 
get_mysql_version() {
  global 
$global_info$site_db;
  if (!empty(
$global_info['mysql_version'])) {
    return 
$global_info['mysql_version'];
  }
  
$split_info = array();
  if (
$row $site_db->query_firstrow("SELECT VERSION() AS version")) {
    
$split_info explode('.'$row['version']);
  }
  else {
    if (
$row $site_db->query_firstrow("SHOW VARIABLES LIKE 'version'")){
      
$split_info explode('.'$row[1]);
    }
  }
  
$first  = (empty($split_info) || empty($split_info[0])) ? intval($split_info[0]);
  
$second = (empty($split_info[1])) ? 21 intval($split_info[1]);
  
$third  = (empty($split_info[2])) ? intval($split_info[2]);
  
$global_info['mysql_version'] = sprintf('%d%02d%02d'$first$second$third);
  return 
$global_info['mysql_version'];
}

function 
get_php_version() {
  global 
$global_info;
  if (!empty(
$global_info['php_version'])) {
    return 
$global_info['php_version'];
  }
  
$split_info = array();
  
preg_match("/([0-9]{1,2})\.([0-9]{1,2})(\.([0-9]{1,2}))?/"phpversion(), $split_info);

  
$global_info['php_version'] = 0;
  if (!empty(
$split_info) && !empty($split_info[1])) {
    
$first  intval($split_info[1]);
    
$second = (empty($split_info[2])) ? intval($split_info[2]);
    
$third  = (empty($split_info[4])) ? intval($split_info[4]);
    
$global_info['php_version'] = sprintf('%d%02d%02d'$first$second$third);
  }
  return 
$global_info['php_version'];
}

function 
get_user_os() {
  global 
$global_info$HTTP_USER_AGENT$HTTP_SERVER_VARS;
  if (!empty(
$global_info['user_os'])) {
    return 
$global_info['user_os'];
  }
  if (!empty(
$HTTP_SERVER_VARS['HTTP_USER_AGENT'])) {
    
$HTTP_USER_AGENT $HTTP_SERVER_VARS['HTTP_USER_AGENT'];
  }
  elseif (
getenv("HTTP_USER_AGENT")) {
    
$HTTP_USER_AGENT getenv("HTTP_USER_AGENT");
  }
  elseif (empty(
$HTTP_USER_AGENT)) {
    
$HTTP_USER_AGENT "";
  }
  if (
eregi("Win"$HTTP_USER_AGENT)) {
    
$global_info['user_os'] = "WIN";
  }
  elseif (
eregi("Mac"$HTTP_USER_AGENT)) {
    
$global_info['user_os'] = "MAC";
  }
  else {
    
$global_info['user_os'] = "OTHER";
  }
  return 
$global_info['user_os'];
}

function 
get_browser_info() {
  global 
$global_info$HTTP_USER_AGENT$HTTP_SERVER_VARS;
  if (!empty(
$global_info['browser_agent'])) {
    return 
$global_info['browser_agent'];
  }
  if (!empty(
$HTTP_SERVER_VARS['HTTP_USER_AGENT'])) {
    
$HTTP_USER_AGENT $HTTP_SERVER_VARS['HTTP_USER_AGENT'];
  }
  elseif (
getenv("HTTP_USER_AGENT")) {
    
$HTTP_USER_AGENT getenv("HTTP_USER_AGENT");
  }
  elseif (empty(
$HTTP_USER_AGENT)) {
    
$HTTP_USER_AGENT "";
  }
  if (
eregi("MSIE ([0-9].[0-9]{1,2})"$HTTP_USER_AGENT$regs)) {
    
$global_info['browser_agent'] = "MSIE";
    
$global_info['browser_version'] = $regs[1];
  }
  elseif (
eregi("Mozilla/([0-9].[0-9]{1,2})"$HTTP_USER_AGENT$regs)) {
    
$global_info['browser_agent'] = "MOZILLA";
    
$global_info['browser_version'] = $regs[1];
  }
  elseif (
eregi("Opera(/| )([0-9].[0-9]{1,2})"$HTTP_USER_AGENT$regs)) {
    
$global_info['browser_agent'] = "OPERA";
    
$global_info['browser_version'] = $regs[2];
  }
  else {
    
$global_info['browser_agent'] = "OTHER";
    
$global_info['browser_version'] = 0;
  }
  return 
$global_info['browser_agent'];
}

function 
get_document_root() {
  global 
$global_info$DOCUMENT_ROOT$HTTP_SERVER_VARS;
  if (!empty(
$global_info['document_root'])) {
    return 
$global_info['document_root'];
  }
  if (!empty(
$HTTP_SERVER_VARS['DOCUMENT_ROOT'])) {
    
$DOCUMENT_ROOT $HTTP_SERVER_VARS['DOCUMENT_ROOT'];
  }
  elseif (
getenv("DOCUMENT_ROOT")) {
    
$DOCUMENT_ROOT getenv("DOCUMENT_ROOT");
  }
  elseif (empty(
$DOCUMENT_ROOT)) {
    
$DOCUMENT_ROOT "";
  }
  return 
$global_info['document_root'] = $DOCUMENT_ROOT;
}

function 
remote_file_exists($url$check_remote CHECK_REMOTE_FILES) { // similar to file_exists(), checks existence of remote files
  
if (!$check_remote || !CHECK_REMOTE_FILES) {
    return 
true;
  }
  
$url trim($url);
  if (!
preg_match("=://="$url)) $url "http://$url";
  if (!(
$url = @parse_url($url))) {
    return 
false;
  }
  if (!
eregi("http"$url['scheme'])) {
    return 
false;
  }
  
$url['port'] = (!isset($url['port'])) ? 80 $url['port'];
  
$url['path'] = (!isset($url['path'])) ? "/" $url['path'];
  
$fp fsockopen($url['host'], $url['port'], $errno$errstr30);
  if (!
$fp) {
    return 
false;
  }
  else {
    
$head "";
    
$httpRequest "HEAD ".$url['path']." HTTP/1.1\r\n"
                  
."HOST: ".$url['host']."\r\n"
                  
."Connection: close\r\n\r\n";
    
fputs($fp$httpRequest);
    while (!
feof($fp)) {
      
$head .= fgets($fp1024);
    }
    
fclose($fp);

    
preg_match("=^(HTTP/\d+\.\d+) (\d{3}) ([^\r\n]*)="$head$matches);
    if (
$matches[2] == 200) {
      return 
true;
    }
  }
}

if (!
function_exists('is_executable')) {
  function 
is_executable($file) {
    return 
is_file($file);
  }
}

if (!
function_exists('session_regenerate_id')) {
  function 
session_regenerate_id() {
   
$id md5(uniqid(microtime()));
   if (
session_id($id)) {
     return 
true;
   } else {
     return 
false;
   }
  }
}

function 
get_mime_content_type($file) {
    if (
function_exists('mime_content_type')) {
      
$type mime_content_type($file);
      if (
$type) {
        return 
$type;
      }
    }

    
$info = @getimagesize($file);

    if (isset(
$info['mime'])) {
      return 
$info['mime'];
    }

    
$type = @exec(trim('file -bi '.escapeshellarg($file)));

    if (
strpos($type';') !== false) {
      list(
$type) = explode(';'$type);
    }

    if (
$type) {
      return 
$type;
    }

    static 
$types = array(
      
'ai' => 'application/postscript',
     
'aif' => 'audio/x-aiff',
    
'aifc' => 'audio/x-aiff',
    
'aiff' => 'audio/x-aiff',
     
'asc' => 'text/plain',
      
'au' => 'audio/basic',
     
'avi' => 'video/x-msvideo',
   
'bcpio' => 'application/x-bcpio',
     
'bin' => 'application/octet-stream',
       
'c' => 'text/plain',
      
'cc' => 'text/plain',
    
'ccad' => 'application/clariscad',
     
'cdf' => 'application/x-netcdf',
   
'class' => 'application/octet-stream',
    
'cpio' => 'application/x-cpio',
     
'cpt' => 'application/mac-compactpro',
     
'csh' => 'application/x-csh',
     
'css' => 'text/css',
     
'dcr' => 'application/x-director',
     
'dir' => 'application/x-director',
     
'dms' => 'application/octet-stream',
     
'doc' => 'application/msword',
     
'drw' => 'application/drafting',
     
'dvi' => 'application/x-dvi',
     
'dwg' => 'application/acad',
     
'dxf' => 'application/dxf',
     
'dxr' => 'application/x-director',
     
'eps' => 'application/postscript',
     
'etx' => 'text/x-setext',
     
'exe' => 'application/octet-stream',
      
'ez' => 'application/andrew-inset',
       
'f' => 'text/plain',
     
'f90' => 'text/plain',
     
'fli' => 'video/x-fli',
     
'gif' => 'image/gif',
    
'gtar' => 'application/x-gtar',
      
'gz' => 'application/x-gzip',
       
'h' => 'text/plain',
     
'hdf' => 'application/x-hdf',
      
'hh' => 'text/plain',
     
'hqx' => 'application/mac-binhex40',
     
'htm' => 'text/html',
    
'html' => 'text/html',
     
'ice' => 'x-conference/x-cooltalk',
     
'ief' => 'image/ief',
    
'iges' => 'model/iges',
     
'igs' => 'model/iges',
     
'ips' => 'application/x-ipscript',
     
'ipx' => 'application/x-ipix',
     
'jpe' => 'image/jpeg',
    
'jpeg' => 'image/jpeg',
     
'jpg' => 'image/jpeg',
      
'js' => 'application/x-javascript',
     
'kar' => 'audio/midi',
   
'latex' => 'application/x-latex',
     
'lha' => 'application/octet-stream',
     
'lsp' => 'application/x-lisp',
     
'lzh' => 'application/octet-stream',
       
'm' => 'text/plain',
     
'man' => 'application/x-troff-man',
      
'me' => 'application/x-troff-me',
    
'mesh' => 'model/mesh',
     
'mid' => 'audio/midi',
    
'midi' => 'audio/midi',
     
'mif' => 'application/vnd.mif',
    
'mime' => 'www/mime',
     
'mov' => 'video/quicktime',
   
'movie' => 'video/x-sgi-movie',
     
'mp2' => 'audio/mpeg',
     
'mp3' => 'audio/mpeg',
     
'mpe' => 'video/mpeg',
    
'mpeg' => 'video/mpeg',
     
'mpg' => 'video/mpeg',
    
'mpga' => 'audio/mpeg',
      
'ms' => 'application/x-troff-ms',
     
'msh' => 'model/mesh',
      
'nc' => 'application/x-netcdf',
     
'oda' => 'application/oda',
     
'pbm' => 'image/x-portable-bitmap',
     
'pdb' => 'chemical/x-pdb',
     
'pdf' => 'application/pdf',
     
'pgm' => 'image/x-portable-graymap',
     
'pgn' => 'application/x-chess-pgn',
     
'png' => 'image/png',
     
'pnm' => 'image/x-portable-anymap',
     
'pot' => 'application/mspowerpoint',
     
'ppm' => 'image/x-portable-pixmap',
     
'pps' => 'application/mspowerpoint',
     
'ppt' => 'application/mspowerpoint',
     
'ppz' => 'application/mspowerpoint',
     
'pre' => 'application/x-freelance',
     
'prt' => 'application/pro_eng',
      
'ps' => 'application/postscript',
      
'qt' => 'video/quicktime',
      
'ra' => 'audio/x-realaudio',
     
'ram' => 'audio/x-pn-realaudio',
     
'ras' => 'image/cmu-raster',
     
'rgb' => 'image/x-rgb',
      
'rm' => 'audio/x-pn-realaudio',
    
'roff' => 'application/x-troff',
     
'rpm' => 'audio/x-pn-realaudio-plugin',
     
'rtf' => 'text/rtf',
     
'rtx' => 'text/richtext',
     
'scm' => 'application/x-lotusscreencam',
     
'set' => 'application/set',
     
'sgm' => 'text/sgml',
    
'sgml' => 'text/sgml',
      
'sh' => 'application/x-sh',
    
'shar' => 'application/x-shar',
    
'silo' => 'model/mesh',
     
'sit' => 'application/x-stuffit',
     
'skd' => 'application/x-koan',
     
'skm' => 'application/x-koan',
     
'skp' => 'application/x-koan',
     
'skt' => 'application/x-koan',
     
'smi' => 'application/smil',
    
'smil' => 'application/smil',
     
'snd' => 'audio/basic',
     
'sol' => 'application/solids',
     
'spl' => 'application/x-futuresplash',
     
'src' => 'application/x-wais-source',
    
'step' => 'application/STEP',
     
'stl' => 'application/SLA',
     
'stp' => 'application/STEP',
'sv4cpio' => 'application/x-sv4cpio',
  
'sv4crc' => 'application/x-sv4crc',
     
'swf' => 'application/x-shockwave-flash',
       
't' => 'application/x-troff',
     
'tar' => 'application/x-tar',
     
'tcl' => 'application/x-tcl',
     
'tex' => 'application/x-tex',
    
'texi' => 'application/x-texinfo',
  
'texinfo -  application/x-texinfo',
     
'tif' => 'image/tiff',
    
'tiff' => 'image/tiff',
      
'tr' => 'application/x-troff',
     
'tsi' => 'audio/TSP-audio',
     
'tsp' => 'application/dsptype',
     
'tsv' => 'text/tab-separated-values',
     
'txt' => 'text/plain',
     
'unv' => 'application/i-deas',
   
'ustar' => 'application/x-ustar',
     
'vcd' => 'application/x-cdlink',
     
'vda' => 'application/vda',
     
'viv' => 'video/vnd.vivo',
    
'vivo' => 'video/vnd.vivo',
    
'vrml' => 'model/vrml',
     
'wav' => 'audio/x-wav',
     
'wrl' => 'model/vrml',
     
'xbm' => 'image/x-xbitmap',
     
'xlc' => 'application/vnd.ms-excel',
     
'xll' => 'application/vnd.ms-excel',
     
'xlm' => 'application/vnd.ms-excel',
     
'xls' => 'application/vnd.ms-excel',
     
'xlw' => 'application/vnd.ms-excel',
     
'xml' => 'text/xml',
     
'xpm' => 'image/x-xpixmap',

     
'xwd' => 'image/x-xwindowdump',
     
'xyz' => 'chemical/x-pdb',
     
'zip' => 'application/zip',
    );

    
$ext get_file_extension($file);

    if (isset(
$types[$ext])) {
        return 
$types[$ext];
    }

    return 
'application/octet-stream';
}
// DROPDOWN MOD STARTS HERE  12/07/2008 ---------------------------
function get_dropdown_options($name$options = array(), $value ""$multi_dim 1$number 0$auto 0$keypress 0$extra ""$class ""$i_start 0$i_step 1$i_stop 1) {
  
$keypress = ($keypress) ? " onkeypress=\"if(window.event.keyCode==13)this.form.submit();\"" "";
  
$auto = ($auto) ? " onchange=\"this.form.submit();\"" "";
    
$dropdown "<SELECT name=\"".$name."\"".$auto.$keypress." class=\"".(($class) ? $class "select")."\"".$extra.">\n";
   
$i $i_start;
  if (
count($options)) {
    foreach (
$options as $key => $val) {
       
$what = (($number) ? $i : (($multi_dim) ? $key $val));
        
$dropdown .= "<option value=\"".$what."\"".(($value == $what) ? " selected" "").">".preg_replace (array("/{key}/siU""/{val}/siU""/{what}/siU""/{value}/siU"), array($key$val$what$value), $val)."</option>\n";
        
$i $i $i_step;
     }
  }else{
    for (
$i $i_start$i <= $i_stop$i += $i_step) {
        
$dropdown .= "<option value=\"".$i."\"".(($value == $i) ? " selected" "").">".$i."</option>\n";
    }
  }
   
$dropdown .= "</select>\n";
  return 
$dropdown;
}
function 
get_db_fields_dropdown($key$val$value) {
  return 
get_dropdown_options($key$val[3], $value$val[4], $val[5], $val[7], 1"""select"$val[6]);
}
// DROPDOWN MOD ENDS HERE  12/07/2008 -------------------------------
//-----------------------------------------------------
//--- Image Terms  MOD 12/07/2008----------------------
//-----------------------------------------------------
function terms_check($id$image = array())
{
  global 
$HTTP_COOKIE_VARS$site_sess$user_info$cat_cache;
  if (
$user_info['user_level'] == ADMIN || (!empty($image) && (($image['terms'] == && $user_info['user_level'] > GUEST) || ($image['terms'] == && $user_info['user_level'] > USER))) || (empty($image) && empty($cat_cache[$id]['terms']) || ($cat_cache[$id]['terms'] && (($cat_cache[$id]['terms'] == && $user_info['user_level'] > GUEST) || ($cat_cache[$id]['terms'] == && $user_info['user_level'] > USER)))))
  {
    return 
true;
  }
  
$name "terms";
  if (!empty(
$image))
  {
    
$id $image['image_id'];
    
$name .= "img";
  }
  if (
TERMS_COOKIES)
  {
    
$cookie_name = (defined("COOKIE_NAME")) ? COOKIE_NAME "4images_";
    
$cookie_name .= $name.$user_info['user_id'];
    
$split_list = isset($HTTP_COOKIE_VARS[$cookie_name]) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$cookie_name])) : array();
    
$terms in_array($id$split_list);
  }
  if (!isset(
$site_sess->session_info[$name]))
  {
    
$site_sess->session_info[$name] = $site_sess->get_session_var($name);
  }
  
$split_list = array();
  if (!empty(
$site_sess->session_info[$name]))
  {
    
$split_list explode(" "$site_sess->session_info[$name]);
  }
  return ((
TERMS_COOKIES && $terms) || in_array($id$split_list));
}

function 
terms_add($id$image "")
{
  global 
$HTTP_COOKIE_VARS$site_sess$user_info$cat_cache;
  
$name "terms";
  if (
$image)
  {
    
$id $image;
    
$name .= "img";
  }
  if (
TERMS_COOKIES)
  {
    
$cookie_name = (defined("COOKIE_NAME")) ? COOKIE_NAME "4images_";
    
$cookie_name .= $name.$user_info['user_id'];
    
$split_list = isset($HTTP_COOKIE_VARS[$cookie_name]) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$cookie_name])) : array();
    if (!
in_array($id$split_list)) {
      
$cookie_termsid[] = $id;
      
setcookie($cookie_nameserialize($cookie_termsid), time() + TERMS_COOKIES_EXPIRECOOKIE_PATHCOOKIE_DOMAINCOOKIE_SECURE);
    }
  }
  if (!isset(
$site_sess->session_info[$name]))
  {
    
$site_sess->session_info[$name] = $site_sess->get_session_var($name);
  }
  
$split_list = array();
  if (!empty(
$site_sess->session_info[$name]))
  {
    
$split_list explode(" "$site_sess->session_info[$name]);
  }
  if (!
in_array($id$split_list))
  {
    
$site_sess->session_info[$name] .= " ".$id;
    
$site_sess->session_info[$name] = trim($site_sess->session_info[$name]);
    
$site_sess->set_session_var($name$site_sess->session_info[$name]);
  }
}
//--- End Image Terms -------------------------------------
// MOD multi download
function multi_download_resize($file$new_file$quality$resize_width$resize_height) {
  global 
$convert_options;
  if (!
function_exists(init_convert_options)) {
require(ROOT_PATH.'includes/image_utils.php');
  }
  
$convert_options init_convert_options();
  
$image_info = (defined("IN_CP")) ? getimagesize($file) : @getimagesize($file);
  if (!
$image_info) {
    return 
false;
  }
$scale min($resize_width/$image_info[0], $resize_height/$image_info[1]);
$new_width floor($scale*$image_info[0]);
$new_height floor($scale*$image_info[1]);
$resize_handle "resize_image_".$convert_options['convert_tool'];
if ($scale == '1'){
return $file;
}
elseif($resize_handle($file$new_file$quality$new_width$new_height$image_info)) {
@chmod($new_fileCHMOD_FILES);
return true;
}
else {
return false;
}
}
// END MOD multi download
?>




One more point .. Is it possible to disable to download higher size pictures when the size is small ? If the size is 1024x768 the automatically 1600x1200 and other big sizes will be disabled.. but user can download 800x600 size ..


Thanks,
batu

Offline budduke

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • http://www.budduke.com
Re: [MOD] Multi Download of same image
« Reply #9 on: September 28, 2008, 06:53:52 PM »
regarding batu544,

I just PM'd you a link to the modified functions file.
Let me know if this fixes the error or not.
It seems my MOD is calling routines that are not native to 1.7.4,
In case someone else is using 1.7.4 these are the functions that I added at the end of the functions.php file
Code: [Select]
// MOD multi download additional function for test
function check_remote_big($remote_media_file) {
  global $config;
  return (preg_match("#^(https?:\/\/[a-z0-9\-]+?\.([a-z0-9\-]+\.)*[a-z]+(:[0-9]+)*\/.*?\.(".$config['allowed_mediatypes_match'].")$)#is", $remote_media_file)) ? 1 : 0;
}
function check_local_big($local_media_file) {
  global $config;
  return (preg_match("#^((\.)*\/.*?\.(".$config['allowed_mediatypes_match'].")$)#is", $local_media_file)) ? 1 : 0;
}
function check_big_type($file_name) {
  global $config;
  return (in_array(get_file_extension($file_name), $config['allowed_mediatypes_array'])) ? 1 : 0;
}
// END MOD multi download additional function for test

Your other question about not letting bigger size downloads...
Will have to think about it. it seems doable. because the fomula for a bigger size will give a number above 1 on percent to resize and
I would think you could block it at the point, but would have to redo how it make the option list on the fly.
not sure about speed. Will look into that at some point when I get a chance.
Buddy Duke
www.budduke.com

Offline lona_jasty

  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: [MOD] Multi Download of same image
« Reply #10 on: October 12, 2008, 11:08:39 PM »
WOW, I was looking this mod from around 6months & now, I got it, Thanks for making this mod.

Long Live 4image, Long Live budduke


Thanks again

EDIT: I am getting this error
Quote
Parse error: syntax error, unexpected ',' in C:\xampp\htdocs\4images\global.php on line 465

My 465 line is
Quote
  $result = $site_db->query($sql);,multi_download

When I remove ,multi_download this from line, My gallery become ok. I am also not seeing this one ( after removing ,multi_download from line 465)




Please let me know, what should I do ?

Thanks in advance

« Last Edit: October 12, 2008, 11:44:51 PM by lona_jasty »

Offline budduke

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • http://www.budduke.com
Re: [MOD] Multi Download of same image
« Reply #11 on: October 13, 2008, 12:14:08 AM »
You placed it in the wrong place for that insert...
It does not get inserted after the sql line but actually inside it.
The line that starts with
Code: [Select]
$sql = "SELECTAt the end of that line place the
Code: [Select]
,multi_downloadIt get placed before the second line that starts with
Code: [Select]
FROM
My actual line reads like this, it may not look like yours because of different mods I am using...
Code: [Select]
  $sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, cat_image, multi_download
Buddy Duke
www.budduke.com

Offline lona_jasty

  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: [MOD] Multi Download of same image
« Reply #12 on: October 13, 2008, 08:56:29 AM »
My 465 line is this one. Yes, I have installed too many mods, Yes, I think line variation is due to this.

Quote
$result = $site_db->query($sql);

Please tell me how should I change this please, in the global.php file

Quote
if (defined("GET_CACHES")) {
  $sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
          FROM ".CATEGORIES_TABLE."
          ORDER BY cat_order, cat_name ASC";
  $result = $site_db->query($sql,);

Where should I add ,multi_download. Please insert ,multi_download in above code, for sample

Thanks for your help

rinaldos

  • Guest
Re: [MOD] Multi Download of same image
« Reply #13 on: October 13, 2008, 09:04:04 AM »
My 465 line is this one. Yes, I have installed too many mods, Yes, I think line variation is due to this.
Quote
$result = $site_db->query($sql);

Please tell me how should I change this please, in the global.php file

Quote
if (defined("GET_CACHES")) {
  $sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
          FROM ".CATEGORIES_TABLE."
          ORDER BY cat_order, cat_name ASC";
  $result = $site_db->query($sql,);

Where should I add ,multi_download. Please insert ,multi_download in above code, for sample

Code: [Select]
if (defined("GET_CACHES")) {
  $sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, multi_download
          FROM ".CATEGORIES_TABLE."
          ORDER BY cat_order, cat_name ASC";
  $result = $site_db->query($sql);

Here is the code :-)

Ingo

[EDIT by V@no]
removed extra comma in last line.
« Last Edit: October 13, 2008, 03:26:42 PM by V@no »

Offline lona_jasty

  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: [MOD] Multi Download of same image
« Reply #14 on: October 14, 2008, 11:00:44 PM »
HI,

This is my files, can you please modify these for me

Code: [Select]
http://rapidshare.com/files/154050831/4images.zip.html
I will be very thankful to you :)