First of all thank you for this module I have added it allready to my image page in the gallery i have created using views and field_gallery_image.

I have created a CCK field that contains the foldername to a folder with all the images in a gallery.

Is it possible somehow to:
1 Make the download icon appear on that page if that field has been filled out?
2 Make it zip the folder?

Comments

weaponx’s picture

After some experiments i took the liberty of making a copy of your module in order to understand the code behind.
The codes of my (working) experiment is posted below. Please take note that i am beginner in php and i can not guarantee the quality of this php code below.

The code changes assumes that you store all gallery files for each gallery in a folder with the node id as name.
I ended up with theese modifcations.

Rename folder "pclzip_zip_node_files" -> "pclzip_zipfolder_galleries"
Delete files "pclzip_zip_node_files.info", "pclzip_zip_node_files.install", "pclzip_zip_node_files.module"

Create file "pclzip_zipfolder_galleries.info" with this content:

; $Id: pclzip_zipfolder_galleries.info,v 1.0b 2009/02/12 19:24:36 weaponx Exp $

name = PclZip Zip Folders Galleries
description = Gives the ability to zip the files contained in a gallery
dependencies[] = pclzip
package = PclZip
core = 6.x
; Information added by drupal.org packaging script on 2009-03-19
version = "6.x-1.0"
core = "6.x"
project = "pclzip_zipfolder_galleries"
datestamp = "1264251660"

Create file "pclzip_zipfolder_galleries.install" with this content:

<?php
// $Id: pclzip_zipfolder_galleries.install,v 1.0b 2010/23/01 19:24:36 weaponx Exp $

/**
* Implementation of hook_install().
*/
function pclzip_zipfolder_galleries_install() {
  // Create tables.
  drupal_install_schema('pclzip_zipfolder_galleries');
}

/**
* Implementation of hook_uninstall().
*/
function pclzip_zipfolder_galleries_files_uninstall() {
  // Remove tables.
  drupal_uninstall_schema('pclzip_zipfolder_galleries');
  // Remove variables.
  db_query("DELETE FROM {variable} WHERE name LIKE 'pclzip_zipfolder_galleries%%'");
}

/**
* Implementation of hook_schema().
*/
function pclzip_zipfolder_galleries_schema() {
  $schema['pclzip_zipfolder_galleries'] = array(
    'fields' => array(
      'nid'      => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
      'show_download_link' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'),
      'show_download_link_teaser' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'),
    ),
    'primary key' => array('nid'),
  );
  return $schema;
}

Create file "pclzip_zipfolder_galleries.module" with this content:

<?php
// $Id: pclzip_zipfolder_galleries.module,v 1.0b 2010/23/01 19:24:36 weaponx Exp $

/**
* Implementation of hook_menu
*/
function pclzip_zipfolder_galleries_menu() {
  $items = array();

  $items['node/%node/get_zip_gallery'] = array(
    'title'                       => 'Get gallery files',
    'page callback'         => 'pclzip_zipfolder_galleries_getzip',
    'page arguments'     => array(1),
    'access arguments'   => array('access pclzip_zipfolder_galleries'),
    'type'                       => MENU_CALLBACK
  );

  $items['admin/settings/pclzip/zip_gallery_files'] = array(
    'title'                       => t('Zip gallery files'),
    'description'             => t('Settings for the zipfolder galleries module.'),
    'page callback'          => 'drupal_get_form',
    'page arguments'      => array('pclzip_zipfolder_galleries_settings'),
    'access arguments'    => array('administer site configuration'),
    'type'                         => MENU_NORMAL_ITEM,
  );

  return $items;
}

/**
* Admin settings
*/
function pclzip_zipfolder_galleries_settings() {

  if (pclzip_library_exists()) {

    // build the admin form
    $form = array();

    $form['pclzip_zipfolder_galleries']['content_type'] = array(
      '#type'           => 'fieldset',
      '#title'            => t('Content Type to show icon'),
      '#collapsible'  => TRUE,
      '#collapsed'    => TRUE,
    );

    // get the content types
    $options = array();
    $query = "SELECT type, name FROM {node_type}";
    $result = db_query($query);
    while ($field = db_fetch_object($result)) {
      $options[$field->type] = $field->name;
    }
    $form['pclzip_zipfolder_galleries']['content_type']['pclzip_zipfolder_galleries_content_type'] = array(
      '#type'                 => 'checkboxes',
      '#title'                  => t('Content Type for nodes'),
      '#options'             => $options,
      '#default_value'  => variable_get('pclzip_zipfolder_galleries_content_type', array('page' =>'page')),
      '#description'       => t('Select the node type where you want the link to appear.'),
    );
    $form['pclzip_zipfolder_galleries']['content_type']['pclzip_zipfolder_galleries_content_type_teaser'] = array(
      '#type'                 => 'checkboxes',
      '#title'                  => t('Content Type for teaser'),
      '#options'             => $options,
      '#default_value'  => variable_get('pclzip_zipfolder_galleries_content_type_teaser', array('page' =>'page')),
      '#description'       => t('Select the node type where you want the link to appear in teaser.'),
    );



    return system_settings_form($form);
  }
}

/**
 * Implementation of hook_nodeapi().
 */
function pclzip_zipfolder_galleries_nodeapi(&$node, $op, $teaser) {

  switch ($op) {

    case 'insert':
    case 'update':
      pclzip_zipfolder_galleries_link_save($node->nid, $node->show_download_link, $node->show_download_link_teaser);
      break;

    case 'delete':
      pclzip_zipfolder_galleries_link_delete($node->nid);
      break;

    case 'view':
		
      // get download link infos
      $show_link = pclzip_zipfolder_galleries_link_load($node->nid);
      // display the link
	  if (pclzip_zipfolder_galleries_is_type($node->type, 'node')) {
          if ($teaser && (!pclzip_zipfolder_galleries_is_type($node->type, 'teaser') || !$show_link->show_download_link_teaser)) {
            return;
          }
          if (pclzip_library_exists()) {
            $node->content['pclzip_zipfolder_galleries'] = array(
              '#value' => l(theme('pclzip_zipfolder_galleries_download_link'), 'node/'. $node->nid. '/get_zip_gallery', array('html' =>TRUE)),
              '#weight' => 50,
            );
          }
     }   
      
      break;
  }
}

/**
* Load the download link value
*/
function pclzip_zipfolder_galleries_link_load($nid) {
  return db_fetch_object(db_query('SELECT * FROM {pclzip_zipfolder_galleries} WHERE nid=%d', $nid));
}

/**
* Save the download link value
*/
function pclzip_zipfolder_galleries_link_save($nid, $show_download_link, $show_download_link_teaser) {

  $values = new stdclass;
  $values->nid = $nid;
  $values->show_download_link = $show_download_link;
  $values->show_download_link_teaser = $show_download_link_teaser;
  $show_link = pclzip_zipfolder_galleries_link_load($nid);
  if ($show_link->nid) {
    // update entry
    drupal_write_record('pclzip_zipfolder_galleries', $values, 'nid');
  }
  else {
    // insert new entry
    drupal_write_record('pclzip_zipfolder_galleries', $values);
  }
}

/**
* Delete the download link value
*/
function pclzip_zipfolder_galleries_link_delete($nid) {
  db_query('DELETE FROM {pclzip_zipfolder_galleries} WHERE nid=%d', $nid);
}

/**
 * Check if node type is selected
 */
function pclzip_zipfolder_galleries_is_type($type, $place) {
  switch ($place) {
    case 'node':
      $types = variable_get('pclzip_zipfolder_galleries_content_type', array('page' =>'page'));
      break;
    case 'teaser':
      $types = variable_get('pclzip_zipfolder_galleries_content_type_teaser', array('page' =>'page'));
      break;
  }
  // rebuild content types
  $allowed_contents = array();
  foreach ($types as $value) {
    array_push($allowed_contents, $value);
  }
  return in_array($type, $allowed_contents, TRUE);
}

/**
 * Implementation of hook_theme().
 */
function pclzip_zipfolder_galleries_theme() {
  return array(
    'pclzip_zipfolder_galleries_download_link'  => array(
      'arguments'     => array(),
      'template'        =>'download_link',
    ),
  );
}

/**
* Main function
*/
function pclzip_zipfolder_galleries_getzip($node) {
  if (pclzip_library_exists()) {
    $basepath = file_directory_path();

    // get the path
    $path = 'photos/'. $node->nid;
    if ($path == '') {
      drupal_set_message(t('No path defined. The file can not been sent.'), 'error');
      drupal_goto();
      return;
    }
    //$path = pclzip_zipfolder_str_replacevars($path);
    // get the filename
    $filename = clean_title($node->title. '.zip');

    // get the folder path
    $dir = $basepath. '/'. $path;
    if (!is_dir($dir)) {
      drupal_set_message(t("You don't have any files on this server."), 'error');
      drupal_goto();
      return;
    }

    // create the archive
    $archive =& module_invoke("pclzip", 'build_archive', $filename);
    $v_list = $archive->create($dir, PCLZIP_OPT_REMOVE_PATH, $basepath);
    if ($v_list == 0) {
      drupal_set_message($archive->errorInfo(true), 'error');
      drupal_goto('node');
      return;
    }

    // send the archive
    module_invoke("pclzip", 'send_file', $filename);
  }
}
function clean_title($string)
{
    $replace_chars = array("&", ":", ",", "'");
    $cleanString = htmlspecialchars_decode( strtolower(trim($string)), ENT_QUOTES );
    $cleanString = str_replace($replace_chars, "", $cleanString);
    return str_replace(' ', '_', $cleanString );;
}

If you have trouble with code try the following in the module as well as in your filestructure.

Line 184:

$basepath = file_directory_path();

Is the basepath the correct place to look for your picture folder? The usual path for basepath is "(drupal root)/sites/default/files".

Line 187:

$path = 'photos/'. $node->nid;

Is this the correct path below basepath? Example: "(drupal root)/sites/default/files/photos/32".

Enjoy

ssm2017 Binder’s picture

thank you a lot for your contribution
maybe you can create a project on the drupal website and then commit your own module :)
i havent read or tested your code yet

Aurochs’s picture

this is great if it works with gallery assist galleries

30equals’s picture

Status: Active » Closed (won't fix)

Old threat clean up.