You are here

function gallery_assist_load in Gallery Assist 6

Implementation of hook_load()

2 calls to gallery_assist_load()
gallery_assist_nodeapi in ./gallery_assist.module
Implementation of hook_nodeapi().
_get_ga_form in ./gallery_assist.module

File

./gallery_assist.module, line 2178
Drupal content type with gallery functionality.

Code

function gallery_assist_load(&$node, $revisions = NULL, $reset = FALSE) {
  if (!isset($node->nid)) {
    return;
  }
  global $user;
  $nt_conf = variable_get('gallery_assist_' . $node->type . '_data', array());
  $args_values = arg();
  $pager_limit = arg(3) == 'ga_sort' ? arg(3) : variable_get('gallery_assist_editform_pager_limit', 25);
  $ga_c = array();
  $nt_ic_conf = array();
  if (arg(0) == 'node' && arg(2) == 'edit') {
    $reset = TRUE;
  }

  //$reset = TRUE;
  if (!$reset) {
    $cache = cache_get($node->nid, 'cache_gallery_assist_data');
  }
  if (!$reset && !empty($cache->data)) {
    $additions = $cache->data;
  }
  else {

    // additions for the node object
    $additions = db_fetch_object(db_query("SELECT * FROM {gallery_assist} WHERE nid = %d", $node->nid));
    $additions->ga_count = $additions->items;
    unset($additions->nid);

    // Do nothing when not match's
    if (count($additions) == 0) {
      return FALSE;
    }
    $udata = array();
    $udata = unserialize($additions->data);
    unset($additions->data);
    if (empty($udata['ga_db_order_field'])) {
      $udata['ga_db_order_field'] = $nt_conf['ga_db_order_field'];
    }
    if (empty($udata['ga_db_order'])) {
      $udata['ga_db_order'] = $nt_conf['ga_db_order'];
    }
    if ($nt_conf['common_settings_allowed']) {
      if ($nt_conf['gallery_public_status_allowed'] != 1) {
        $additions->ga_public_status = $nt_conf['ga_public_status'];
      }
      if (!$nt_conf['container_format_allowed']) {
        $udata['show_layout'] = $nt_conf['show_layout'];
      }
      if (!$nt_conf['gallery_container_weight_allowed']) {
        $udata['gallery_container_weight'] = $nt_conf['gallery_container_weight'];
      }
      if (!$nt_conf['show_in_homepage_block_allowed']) {
        $udata['show_in_homepage_block'] = $nt_conf['show_in_homepage_block'];
      }
      if (!$nt_conf['gallery_public_status_allowed']) {
        $additions->ga_public_status = $nt_conf['show_in_homepage_block'];
      }
      if (!$nt_conf['show_titles_allowed']) {
        $udata['show_titles'] = $nt_conf['show_titles'];
        $udata['ga_item_title_type'] = $nt_conf['ga_item_title_type'];
      }
      if (!$nt_conf['show_in_userprofile_allowed']) {
        $udata['show_in_userprofile'] = $nt_conf['show_in_userprofile'];
      }
      if (!$nt_conf['gallery_items_shadow_allowed']) {
        $udata['gallery_items_shadow'] = $nt_conf['gallery_items_shadow'];
      }
    }
    if ($nt_conf['extra_layout_settings_allowed'] == 1) {
      if (!$nt_conf['hide_teaser_container_allowed']) {
        $udata['hide_in_teaser'] = $nt_conf['hide_teaser_container_allowed'];
      }
      if (!$nt_conf['show_download_link_allowed']) {
        $udata['show_download_link'] = $nt_conf['show_download_link'];
      }
    }
    else {
      $udata['ga_align'] = $nt_conf['ga_align'];
      $udata['gap_align'] = $nt_conf['gap_align'];
      $udata['t_ga_float'] = $nt_conf['t_ga_float'];
      $udata['p_ga_float'] = $nt_conf['p_ga_float'];
      $udata['t_thm_link_format'] = $nt_conf['t_thm_link_format'];
    }
    $additions->ga_rebuild_items_alias = $udata['ga_rebuild_items_alias'];
    unset($udata['ga_rebuild_items_alias']);

    // Get gallery items data.
    $query_args = array(
      $additions->gref,
      $node->language,
    );
    $ga_db_order_field = isset($udata['ga_db_order_field']) ? $udata['ga_db_order_field'] : 'a.weight';
    $ga_db_order = isset($udata['ga_db_order']) ? $udata['ga_db_order'] : 'ASC';
    $ga_cover_sticky = $nt_conf['ga_cover_sticky'] == 1 ? 'a.cover DESC, ' : '';
    $query = "SELECT a.pid, a.nid, a.ref, a.gid, a.gref, a.sid, a.uid, a.fid, a.filename, a.opath,\n    a.ppath, a.tpath, a.copyright, a.weight, a.cover, a.aid, f.timestamp, tp.lang, tp.ptitle, tp.palt, tp.pdescription, tp.format,\n    tp.did FROM {gallery_assist_item} a JOIN {gallery_assist_translated} tp ON a.pid = tp.pid\n    JOIN {files} f ON f.fid = a.fid\n    WHERE a.gref=%d AND tp.lang = '%s'";
    $query .= " ORDER BY {$ga_cover_sticky} {$ga_db_order_field} {$ga_db_order}";
    $query_count = "SELECT count( * ) FROM {gallery_assist_item} a WHERE a.gref=%d";
    $items_count = db_result(db_query($query_count, $additions->gref));
    if ($pager_limit == arg(3)) {
      $pager_limit = $nt_conf['items_per_row'] * $nt_conf['rows_per_page'];
    }
    if (arg(0) == 'node' && arg(2) == 'edit' && (!isset($args_values[4]) || $args_values[4] != 'no_jquery') && !isset($_GET['unlimited']) && is_numeric(variable_get('gallery_assist_editform_pager_limit', 'none'))) {
      if ($items_count > 0) {
        $result = pager_query($query, $pager_limit, 0, $query_count, $query_args);
      }
    }
    else {
      if ($items_count > 0) {
        $result = db_query($query, $query_args);
      }
    }

    // Active languages.
    $languages = language_list();
    $languages[] = '';
    $additions->languages = $languages;

    // Build gallconf.
    if (variable_get('gallery_assist_' . $node->type, 0) == 1) {
      $nt_conf_data = unserialize($nt_conf['data']);
      if (function_exists('imagecache_preset') && variable_get('gallery_assist_use_imagecache', 0) == 1) {
        $nt_ic_conf = variable_get('gallery_assist_' . $node->type . '_ic_data', array());
        $thm_preset = imagecache_preset($nt_ic_conf['thm_presetid']);
        $thm_w = $thm_preset['actions'][count($thm_preset['actions']) - 1]['data']['width'];
        $thm_h = $thm_preset['actions'][count($thm_preset['actions']) - 1]['data']['height'];
        $prev_preset = imagecache_preset($nt_ic_conf['prev_presetid']);
        $prev_w = $prev_preset['actions'][count($prev_preset['actions']) - 1]['data']['width'];
        $prev_h = $prev_preset['actions'][count($prev_preset['actions']) - 1]['data']['height'];
        $nt_conf['thumbnail_size'] = $thm_w >= $thm_h ? $thm_w : $thm_h;
        $nt_conf['thumbnail_width_size'] = $thm_w;
        $nt_conf['thumbnail_height_size'] = $thm_h;
        $nt_conf['preview_size'] = $prev_w >= $prev_w ? $prev_w : $prev_h;
      }
      else {
        $nt_ic_conf = array();
      }
    }
    $ga_c[$node->type] = array_merge($nt_conf, $nt_ic_conf);
    $ga_c[$node->type]['ga_counter'] = db_result(db_query("SELECT count( * ) FROM {gallery_assist_item} a WHERE a.gref=%d", $additions->gref));
    $ga_c[$node->type]['gallery_items_shadow'] = $udata['gallery_items_shadow'];
    $ga_c[$node->type]['ga_item_title_type'] = $udata['ga_item_title_type'];
    while ($item = db_fetch_object($result)) {
      if ($item->cover == 1) {
        $additions->has_cover = $item->pid;
      }
      $additions->gallitems[$item->pid] = $item;
      $additions->gallitems[$item->pid]->thmb_path = preg_replace('/thm\\//', 'img/', $item->tpath);
      $additions->gallitems[$item->pid]->download_path = $item->opath;
      if (module_exists('transliteration')) {
        $additions->gallitems[$item->pid]->tpath = transliteration_get($item->tpath);
        $additions->gallitems[$item->pid]->ppath = transliteration_get($item->ppath);
        $additions->gallitems[$item->pid]->opath = transliteration_get($item->opath);
        $additions->gallitems[$item->pid]->thmb_path = transliteration_get($additions->gallitems[$item->pid]->thmb_path);
      }
      if (!empty($item->exif)) {
        $additions->gallitems[$item->pid]->exif_data = unserialize($additions->gallitems[$item->pid]->exif);
      }

      // Gallery Assist with imagecache.
      if (function_exists('imagecache_preset') && variable_get('gallery_assist_use_imagecache', 0) == 1) {

        // Change the thumbnail path to obtain later by display the picture dimentions (margin top).
        $additions->gallitems[$item->pid]->tpath = preg_replace('/thm\\//', '', $additions->gallitems[$item->pid]->tpath);
        $additions->gallitems[$item->pid]->ppath = preg_replace('/prev\\//', '', $additions->gallitems[$item->pid]->ppath);
        $additions->gallitems[$item->pid]->tpath = preg_replace('/files\\/gallery_assist/', 'files/imagecache/' . $ga_c[$node->type]['thm_presetname'] . '/gallery_assist', $additions->gallitems[$item->pid]->tpath);
        $additions->gallitems[$item->pid]->ppath = preg_replace('/files\\/gallery_assist/', 'files/imagecache/' . $ga_c[$node->type]['prev_presetname'] . '/gallery_assist', $additions->gallitems[$item->pid]->ppath);
        if (!is_file($additions->gallitems[$item->pid]->tpath)) {
          $only_load = theme('imagecache', $ga_c[$node->type]['thm_presetname'], $additions->gallitems[$item->pid]->opath);
        }
      }

      // This part repair, recreate thumbnails or preview images if thes are missing or was not created or was deleted etc (gone).
      // It is possible only if original images exists.
      if (file_exists($additions->gallitems[$item->pid]->opath) && !file_exists($additions->gallitems[$item->pid]->tpath) || !file_exists($additions->gallitems[$item->pid]->ppath) && (variable_get('gallery_assist_use_imagecache', FALSE) == 0 || variable_get('gallery_assist_imagecache_uninstalled', 0) == 1)) {

        // drupal_set_message($additions->gallitems[$item->pid]->ptitle .' wurde nicht gefunden', 'warning');
        $imageinfo = image_get_info($additions->gallitems[$item->pid]->opath);
        $my_dim_ref = $imageinfo['width'] > $imageinfo['height'] ? $imageinfo['width'] : $imageinfo['height'];
        $thmb_size = $ga_c[$node->type]['upload_thm'];
        $prev_size = $ga_c[$node->type]['upload_prev'];
        if (!file_exists($additions->gallitems[$item->pid]->tpath)) {
          if ($thmb_size < $my_dim_ref) {
            @image_scale($additions->gallitems[$item->pid]->opath, $additions->gallitems[$item->pid]->tpath, $thmb_size, $thmb_size);
          }
          else {
            @copy($additions->gallitems[$item->pid]->opath, $additions->gallitems[$item->pid]->tpath);
          }
          @chmod($additions->gallitems[$item->pid]->tpath, 0664);
        }
        if (!file_exists($additions->gallitems[$item->pid]->ppath)) {
          if ($prev_size < $my_dim_ref) {
            @image_scale($additions->gallitems[$item->pid]->opath, $additions->gallitems[$item->pid]->ppath, $prev_size, $prev_size);
          }
          else {
            @copy($additions->gallitems[$item->pid]->opath, $additions->gallitems[$item->pid]->ppath);
          }
          @chmod($additions->gallitems[$item->pid]->ppath, 0664);
        }
      }
    }

    // Get gallery data.
    if (!$additions->ganame) {
      $additions->ganame = 'gallery_assist' . isset($additions->ref) ? $additions->ref : $node->nid;
    }
    $additions->gallery_items_shadow = $udata['gallery_items_shadow'];
    $ga_c[$node->type]['show_layout'] = $udata['show_layout'] ? $udata['show_layout'] : $nt_conf['show_layout'];
    $ga_c[$node->type]['hide_in_teaser'] = $udata['hide_in_teaser'] ? $udata['hide_in_teaser'] : $nt_conf['hide_in_teaser'];

    //$ga_c[$node->type]['show_download_link'] = isset($udata['show_download_link']) ? $udata['show_download_link'] : $nt_conf['show_download_link'];
    $ga_c[$node->type]['show_download_link'] = $udata['show_download_link'];
    $ga_c[$node->type]['ga_db_order_field'] = $udata['ga_db_order_field'] ? $udata['ga_db_order_field'] : 'weight';
    $ga_c[$node->type]['ga_db_order'] = $udata['ga_db_order'] ? $udata['ga_db_order'] : 'DESC';
    $ga_c[$node->type]['comments'] = $additions->comments;
    $ga_c[$node->type]['ga_align'] = $udata['ga_align'];
    $ga_c[$node->type]['gap_align'] = $udata['gap_align'];
    $ga_c[$node->type]['t_ga_float'] = $udata['t_ga_float'];
    $ga_c[$node->type]['p_ga_float'] = $udata['p_ga_float'];
    $ga_c[$node->type]['item_effect'] = $udata['item_effect'] ? $udata['item_effect'] : '';
    $ga_c[$node->type]['t_thm_link_format'] = $udata['t_thm_link_format'] ? $udata['t_thm_link_format'] : 'item';

    // Calculate needed display format values.
    $ga_c[$node->type]['spaces'] = ($ga_c[$node->type]['item_padding'] + $ga_c[$node->type]['item_margin'] + $ga_c[$node->type]['item_border']) * 2;
    $ga_c[$node->type]['show_title'] = $additions->show_title;
    $ga_c[$node->type]['old_path'] = $udata['old_path'];
    if (count($additions->gallitems) < $ga_c[$node->type]['items_per_row']) {
      $ga_c[$node->type]['items_per_row'] = count($additions->gallitems);
    }
    $iprws = is_numeric($ga_c[$node->type]['items_per_row']) ? $ga_c[$node->type]['items_per_row'] : 3;
    $t_iprws = is_numeric($ga_c[$node->type]['t_items_per_row']) ? $ga_c[$node->type]['t_items_per_row'] : $iprws;
    if ($ga_c[$node->type]['thumbnail_size_plus'] > 0) {
      $wplus = $ga_c[$node->type]['thumbnail_size_plus'] * $iprws;
      $t_wplus = $ga_c[$node->type]['thumbnail_size_plus'] * $t_iprws;
    }
    else {
      $wplus = 0;
    }
    $ga_c[$node->type]['container_width'] = ($ga_c[$node->type]['thumbnail_size'] + $ga_c[$node->type]['spaces']) * $iprws + $wplus;

    // + 10;
    $ga_c[$node->type]['t_container_width'] = ($ga_c[$node->type]['thumbnail_size'] + $ga_c[$node->type]['spaces']) * $t_iprws + 10 + $t_wplus;
    if (module_exists('i18n')) {
      $ga_c[$node->type]['translation_behavior'] = $udata['translation_behavior'];
    }
    $additions->gallconf = $ga_c;
    if (!$reset) {
      cache_set($node->nid, $additions, 'cache_gallery_assist_data');
    }
  }

  // Load the settings of modules which are working with Gallery Assist.
  $exteds_result = db_query("SELECT * FROM {gallery_assist_modules_settings} WHERE nid = %d", $node->nid);
  while ($r = db_fetch_array($exteds_result)) {
    $additions->gallconf[$node->type]['modules'][$r['module']] = $r;
  }
  return $additions;
}