Author Topic: [MOD]-BETA Whole/part category download  (Read 77380 times)

0 Members and 1 Guest are viewing this topic.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[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.... 8O

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.
« Last Edit: October 12, 2010, 02:29:31 AM by V@no »
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline toto1

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
    • http://www.gifanimer.com
[MOD]-BETA Whole/part category download
« Reply #1 on: May 08, 2003, 02:33:46 PM »
yes very good option thk v@eno

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD]-BETA Whole/part category download
« Reply #2 on: May 08, 2003, 08:33:34 PM »
well, yes, but if u look at the word this way...;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Xwall

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.xwall.tk
Re: [MOD]-BETA Whole/part category download
« Reply #3 on: July 03, 2005, 11:13:08 AM »
I have this DB Error when click in Download button.
The problem is here ( LIMIT $offset, $perpage"; )... What is The solution please?

Code: [Select]
ORDER BY ".$config['image_order']." ".$config['image_sort']."
LIMIT $offset, $perpage";

DB Error: Bad SQL Query: SELECT i.image_id, i.cat_id, i.user_id FROM galerias_images i, galerias_categories c LEFT JOIN galerias_users u ON (u.user_id = i.user_id) WHERE i.image_active = 1 AND i.cat_id = 167 AND c.cat_id = i.cat_id ORDER BY image_date DESC LIMIT , 12
Algo está equivocado en su sintax cerca ' 12' en la linea 6

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/localhost/xwall/htdocs/galerias/includes/db_mysql.php on line 231

Code: [Select]
  function get_numrows($query_id = -1) {
    if ($query_id != -1) {
      $this->query_id = $query_id;
    }
    return mysql_num_rows($this->query_id);
  }

DB Error: Bad SQL Query: SELECT cat_id, image_media_file, image_download_url FROM galerias_images WHERE image_active = 1 AND image_id IN (,) AND cat_id IN (0, 520, 15, 554, 626, 262, 121, 549, 458, 318, 491, 16, 263, 35, 34, 636, 131, 651, 366, 633, 61, 56, 264, 122, 170, 132, 195, 2, 14, 650, 647, 617, 102, 348, 30, 145, 154, 308, 313, 101, 103, 558, 31, 389, 315, 646, 185, 113, 464, 365, 624, 622, 471, 40, 345, 163, 197, 81, 209, 114, 104, 265, 33, 248, 133, 63, 569, 28, 411, 410, 58, 266, 349, 631, 123, 614, 299, 130, 280, 615, 124, 71, 134, 80, 55, 269, 254, 359, 526, 363, 259, 337, 597, 364, 146, 548, 388, 100, 118, 161, 105, 67, 619, 106, 26, 268, 606, 566, 612, 70, 270, 595, 584, 621, 394, 466, 79, 135, 152, 153, 155, 162, 156, 157, 158, 159, 151, 271, 272, 72, 369, 216, 107, 609, 41, 387, 628, 361, 635, 632, 147, 571, 403, 48, 119, 68, 481, 412, 66, 358, 553, 610, 422, 205, 126, 167, 601, 296, 568, 567, 649, 604, 342, 346, 99, 371, 115, 547, 234, 494, 534, 630, 83, 120, 75, 642, 1, 274, 620, 192, 117, 18, 128, 127, 76, 627, 367, 19, 275, 194, 98, 521, 556, 69, 20, 276, 207, 24, 160, 77, 38, 141, 111, 78, 368, 144, 150, 32, 43, 89, 142, 277, 125, 625, 44, 82, 27, 29, 47, 39, 60, 603, 508, 404, 279, 377, 198, 116, 17, 468, 616, 62, 37, 186, 282, 456, 84, 648, 563, 140, 178, 305, 401, 137, 409, 284, 643, 335, 551, 640, 602, 252, 261, 210, 25, 285, 360, 465, 641, 644, 148, 479, 623, 591, 564, 109, 618, 85, 138, 139, 57, 637, 362, 168, 639, 129, 21, 287, 149, 110, 634, 420, 599, 49, 86, 645, 434, 74, 629, 638, 370, 112, 249, 244, 164)
Algo está equivocado en su sintax cerca ') AND cat_id IN (0, 520, 15, 554, 626, 262, 121, 549, 458, 318, ' en la linea 3


Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD]-BETA Whole/part category download
« Reply #4 on: July 03, 2005, 06:41:17 PM »
I've updated step 2.2
try now.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Xwall

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.xwall.tk
Re: [MOD]-BETA Whole/part category download
« Reply #5 on: July 04, 2005, 09:50:23 AM »
Thanks V@no for your help, all OK Now.  :D

Offline nyiguinyogui

  • Pre-Newbie
  • Posts: 6
    • View Profile
Re: [MOD]-BETA Whole/part category download
« Reply #6 on: September 01, 2005, 02:22:14 PM »
Hello,
After installing this mod, when you are in a category with no images, if you click the download button you get a DB error ( DB Error: Bad SQL Query: SELECT cat_id, image_media_file, image_download_url FROM images WHERE image_active = 1 AND image_id IN () AND cat_id IN (0, 12, 14, 2, 3, 13, 15, 16, 4, 7, 8, 9, 10, 11) ).
I think if the category contains no images, download button should be hidden. Steps to get this (after having installed the mod):
1) open categories.php
2) Find
Code: [Select]
$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>";3) Add before
Code: [Select]
if ($cat_cache[$cat_id]['num_images'] > 0)That's it.
You could as well decide to show an inactive download button instead of not showing it.
BTW: Useful mod. Thanks V@no.
Regards.

TheOracle

  • Guest
Re: [MOD]-BETA Whole/part category download
« Reply #7 on: September 01, 2005, 02:54:39 PM »
Quote

if ($cat_cache[$cat_id]['num_images'] > 0)


With this type of if statement, never forget to put it like this instead :

Code: [Select]

if ($cat_cache[$cat_id]['num_images'] > 0) {


You missed the opening bracket sign. ;)

The other step is to close the if statement, with a closing bracket sign after the command has been commented out.

Offline Xyu BAM

  • Full Member
  • ***
  • Posts: 145
    • View Profile
Re: [MOD]-BETA Whole/part category download
« Reply #8 on: September 02, 2005, 01:04:19 AM »
With this type of if statement, never forget to put it like this instead :

Code: [Select]

if ($cat_cache[$cat_id]['num_images'] > 0) {


You missed the opening bracket sign. ;)

The other step is to close the if statement, with a closing bracket sign after the command has been commented out.
wrong, its not nececerly.
if you dont use {} brackets, only one line that followed after the condition statement will be used in the condition and the rest of the code will be treated as not related to the condition at all.
http://php.net/manual/en/language.control-structures.php#control-structures.if

TheOracle

  • Guest
Re: [MOD]-BETA Whole/part category download
« Reply #9 on: September 02, 2005, 01:22:28 AM »
Is this with 4images v1.71 ?

Quote

$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>";


since I cannot find it from my categories.php file.

Offline nyiguinyogui

  • Pre-Newbie
  • Posts: 6
    • View Profile
Re: [MOD]-BETA Whole/part category download
« Reply #10 on: September 02, 2005, 08:38:05 AM »
With this type of if statement, never forget to put it like this instead :

Code: [Select]

if ($cat_cache[$cat_id]['num_images'] > 0) {


You missed the opening bracket sign. ;)

The other step is to close the if statement, with a closing bracket sign after the command has been commented out.
wrong, its not nececerly.
if you dont use {} brackets, only one line that followed after the condition statement will be used in the condition and the rest of the code will be treated as not related to the condition at all.
http://php.net/manual/en/language.control-structures.php#control-structures.if

Well, I can agree it is a good programming practice to always put between brackets code within an IF (and a a while, for, etc.), but certainly, as long as there is a single line, brackets are not necessary.

Is this with 4images v1.71 ?

Quote

$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>";


since I cannot find it from my categories.php file.

This line is in categories.php if you have installed the mod. See V@no's post (the one which started this thread).

TheOracle

  • Guest
Re: [MOD]-BETA Whole/part category download
« Reply #11 on: September 02, 2005, 01:23:03 PM »
Ah ! yes, found it. In the else statement. ;)

Offline Steel Rat

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Infinite Realities
Re: [MOD]-BETA Whole/part category download
« Reply #12 on: September 13, 2005, 01:22:51 PM »
Can't see the demo. There's no Zip button near upload.

The description is also contradictory. At one place it says "Download all images in a category" and in another it says "Download pictures displayed on one page". Clearly not the same thing. Which does this do?

Thanks

Offline jaimecb

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Re: [MOD]-BETA Whole/part category download
« Reply #13 on: September 14, 2005, 01:02:23 PM »

1.1. Find:
Code: [Select]
$site_template->register_vars(array(
  "mode" => ((!empty($mode)) ? "&amp;mode=".$mode : ""),  "clickstream" => $clickstream,
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,
  "mode" => ((!empty($mode)) ? "&amp;mode=".$mode : ""),  "clickstream" => $clickstream,

I can´t find this code on categories.php... i have 4images 1.7.1     what can i do??

TheOracle

  • Guest
Re: [MOD]-BETA Whole/part category download
« Reply #14 on: September 15, 2005, 12:29:03 AM »
Correct. In categories.php file,

find :

Quote

//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------
$site_template->register_vars(array(
  "msg" => $msg,
  "clickstream" => $clickstream
));


replace with :

Code: [Select]

/-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------
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(
  "msg" => $msg,
  "download_button" => $download_button,
  "mode" => ((!empty($mode)) ? "&amp;mode=".$mode : ""),  "clickstream" => $clickstream
));