166
Mods & Plugins (Requests & Discussions) / [MOD]-BETA Whole/part category download
« on: January 08, 2003, 01:58:45 AM »
This mod will let visitors download all images from a category.
Almost the same as Lightbox, exept that it will download pictures that are desplaeyed on one page (u can see what I mean here look at ZIP button near UPLOAD).
Why is it BETA? - because I've tested only on my own server/system, and it didnt work well with too many images or too big filesizes. It might be because of wrong my server configuration....dont know....
so, anyway.
1. Open categories.php file.
1.1. Find:
2. Open download.php file.
2.1 Find:
3. Open /templates/yourtemplate/categories.html
3.1. Add {download_button} anywhere u want.
If u wish make it without limitation (download whole category) then u'll need change code:
Almost the same as Lightbox, exept that it will download pictures that are desplaeyed on one page (u can see what I mean here look at ZIP button near UPLOAD).
Why is it BETA? - because I've tested only on my own server/system, and it didnt work well with too many images or too big filesizes. It might be because of wrong my server configuration....dont know....
so, anyway.
1. Open categories.php file.
1.1. Find:
Code: [Select]
$site_template->register_vars(array(
"msg" => $msg,
Replace with:Code: [Select]
if (!check_permission("auth_download", $cat_id)) {
$download_button = "<img src=\"".get_gallery_image("download_zip_off.gif")."\" border=\"0\" alt=\"\" /></a>";
}
else {
$download_button = "<a href=\"".$site_sess->url(ROOT_PATH."download.php?action=page&cat_id=".$cat_id."&offset=".$offset."")."\"><img src=\"".get_gallery_image("download_zip.gif")."\" border=\"0\" alt=\"\" /></a>";
}
$site_template->register_vars(array(
"download_button" => $download_button,
"msg" => $msg,
2. Open download.php file.
2.1 Find:
Code: [Select]
$user_access = get_permission();
Add after:Code: [Select]
include(ROOT_PATH.'includes/page_header.php');
if (!function_exists('get_file_data'))
{
function get_file_data($filename)
{
return file_get_contents($filename);
}
}
2.2. Find:Code: [Select]
else {
echo $lang['download_error']."\n<!-- EMPTY FILE PATH //-->";
exit;
}
}
Add after:Code: [Select]
elseif ($action == "page") {
if (!function_exists("gzcompress") || !function_exists("crc32")) {
header("Location: ".$site_sess->url($url, "&"));
exit;
}
//-------------------------------------------------------\\
//------- need find out witch pictures are desplayed ----\\
//------ this code was taken from categories.php file ---\\
//----- with some modification-adaption to this script --\\
//------- so, if someone could give me an example --------\\
//------- how to transfer a string from one php file -----\\
//------ to another, I would really appreciated and ------\\
//--------------- modification would be less -------------\\
//----- (I've tryed use global $string; - it didnt work) --\\
//--------------------------------------------------------\\
$additional_sql = "";
if (!empty($additional_image_fields)) {
foreach ($additional_image_fields as $key => $val) {
$additional_sql .= ", i.".$key;
}
}
$sql = "SELECT i.image_id, i.cat_id, i.user_id
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 = $cat_id AND c.cat_id = i.cat_id
ORDER BY ".$config['image_order']." ".$config['image_sort']."
LIMIT ".$_GET['offset'].", $perpage";
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);
$page_download = "";
while ($image_row = $site_db->fetch_array($result)){
$page_download .= ", ".$image_row['image_id'];
}
$image_id_sql = trim($page_download, ", ");
//--------------------------------------------------------------\\
//---- the rest of the code was taken from download-lightbox----\\
//--------------------------------------------------------------\\
$sql = "SELECT cat_id, image_media_file, image_download_url
FROM ".IMAGES_TABLE."
WHERE image_active = 1 AND image_id IN ($image_id_sql) AND cat_id IN (".get_auth_cat_sql("auth_download").")";
$result = $site_db->query($sql);
if ($result) {
include(ROOT_PATH."includes/zip.php");
$zipfile = new zipfile();
$file_added = 0;
while ($image_row = $site_db->fetch_array($result)) {
if (!empty($image_row['image_download_url'])) {
if (is_remote_file($image_row['image_download_url']) || is_local_file($image_row['image_download_url'])) {
$file_path = $image_row['image_download_url'];
$file_name = basename($image_row['image_download_url']);
}
}
elseif (is_remote($image_row['image_media_file'])) {
$file_path = $image_row['image_media_file'];
$file_name = basename($image_row['image_media_file']);
}
else {
$file_path = MEDIA_PATH."/".$image_row['cat_id']."/".$image_row['image_media_file'];
$file_name = $image_row['image_media_file'];
}
if (!empty($file_path)) {
@set_time_limit(120);
if (!$file_data = get_file_data($file_path)) {
continue;
}
$zipfile->add_file($file_data, $file_name);
$file_added = 1;
unset($file_data);
}
}
if ($file_added) {
@set_time_limit(120);
$file['file_name'] = time().".zip";
$file['file_data'] = $zipfile->file();
$file['file_size'] = strlen($file['file_data']);
}
else {
header("Location: ".$site_sess->url($url, "&"));
exit;
}
}
}
3. Open /templates/yourtemplate/categories.html
3.1. Add {download_button} anywhere u want.
If u wish make it without limitation (download whole category) then u'll need change code:
Code: [Select]
ORDER BY ".$config['image_order']." ".$config['image_sort']."
LIMIT $offset, $perpage";
with this:Code: [Select]
ORDER BY ".$config['image_order']." ".$config['image_sort']."";
if u want limit downloaded pictures to your own desired number, change:Code: [Select]
LIMIT $offset, $perpage";
to this:Code: [Select]
LIMIT $offset, X";
where X is number u want.