You are here

function brilliant_gallery_views_handler_image_img in Brilliant Gallery 5.3

Same name and namespace in other branches
  1. 5.4 views.inc \brilliant_gallery_views_handler_image_img()
  2. 6.4 views.inc \brilliant_gallery_views_handler_image_img()
  3. 6 views.inc \brilliant_gallery_views_handler_image_img()
  4. 6.2 views.inc \brilliant_gallery_views_handler_image_img()
  5. 6.3 views.inc \brilliant_gallery_views_handler_image_img()
  6. 7.2 OLD_views.inc \brilliant_gallery_views_handler_image_img()
  7. 7 views.inc \brilliant_gallery_views_handler_image_img()

Views handler for displaying the image.

File

./views.inc, line 45

Code

function brilliant_gallery_views_handler_image_img($fieldinfo, $fielddata, $value, $data) {

  /*
    $node = node_load($data->nid);
    return image_display($node, $fielddata['options']);
  */

  /*
    $tmp = '.1. ' . implode( ' // ', $fieldinfo );
    $tmp .= '<br>.2. ' . implode( ' // ', $fielddata );
    $tmp .= '<br>.3. ' . implode( ' // ', $value );
    $tmp .= '<br>.4. ' . implode( ' // ', $data );
    $tmp .= '<br>.5. ' . $data->field_gallery_value;
    #field_gallery_value
  */
  $tmp = $data->nid;
  $query = "SELECT SQL_CACHE `field_gallery_value` FROM `content_type_page` WHERE `nid` = '" . $tmp . "' ORDER BY `vid` DESC LIMIT 1";
  $string = db_result(db_query($query), 0);
  $string = str_replace(array(
    '[bg|',
    ']',
  ), '', $string);
  if (strpos($string, '|') !== false) {
    $string = substr($string, 0, strpos($string, '|'));
  }
  if ($string == '') {
    return;
  }

  # Now get a list of images and choose one of them.
  $absolpath = realpath(file_directory_path() . '/' . variable_get('brilliant_gallery_folder', '') . '/' . $string);

  #$string .= file_directory_path() . '/' . $string;

  # Load Directory Into Array
  $poct = -1;
  $retval = array();
  $handle = opendir($absolpath);
  while ($file = readdir($handle)) {
    $poct += 1;
    $testending = strtolower(substr($file, -4, 4));
    if (strtolower($testending) != '.jpg' and strtolower($testending) != 'jpeg' and strtolower($testending) != '.gif' and strtolower($testending) != '.png') {
      continue;
    }
    $retval[$poct] = $file;
  }
  closedir($handle);

  #print_r( $retval );
  $randimg = mt_rand(0, count($retval));
  $result = $absolpath . '/' . $retval[$randimg];
  $temp = getimagesize($result);

  #$imagewidth = variable_get('brilliant_gallery_maximagewidth', 150);
  $imgh = 100;

  # Hard-coded height for this purpose.
  $imgw = round($temp[0] / $temp[1] * $imgh);

  # Get this module's path:

  # Patching a possible problem with i18n
  $langcode = '';
  if (function_exists('i18n_get_lang')) {
    $langcode = i18n_get_lang();
  }
  $modulepath = url(drupal_get_path('module', 'brilliant_gallery'), NULL, NULL, TRUE);

  # url() ads i18n codes to the URL ... we need to remove them here...
  if ($langcode != '') {
    $modulepath = str_replace('/' . $langcode . '/', '/', $modulepath);
  }

  # Non-clean URLs need removing ?q=
  $modulepath = str_replace("?q=", "", $modulepath);
  $result = '<a href="' . $modulepath . '/image.php?imgp=' . base64_encode($absolpath . '/' . $retval[$randimg]) . '&imgw=' . $imgw * 6 . '&imgh=' . $imgh * 6 . '"';
  $setname = mt_rand(1, 9999999);
  $overbrowser = variable_get('brilliant_gallery_overbrowser', 'thickbox');
  switch ($overbrowser) {
    case 'thickbox':
      $result .= ' class="thickbox"';
      $result .= ' rel="img_' . $setname . '"';

      #$attributes['class'] = $link_class;

      #$attributes['rel'] = 'img_' . ($node->nid? $node->nid: time()); // 'insert' has no $node->nid
      break;
    case 'lightbox':
      $result .= ' rel="lightbox[' . $setname . ']"';

      #$attributes['rel'] = 'lightbox[' . ($node->nid? $node->nid: time()) . ']'; // 'insert' has no $node->nid
      break;
    case 'greyboxr':
      $result .= ' class="greybox"';

      #$result .= ' rel="gb_imageset[' . $setname . ']"';
      break;
    default:
      break;
  }
  if ($showcaption != '') {
    $result .= ' title="' . $caption . '"';
  }
  $result .= '>';
  $result .= '<img style="display: block;border:0;align:right" src="' . $modulepath . '/image.php?imgp=' . base64_encode($absolpath . '/' . $retval[$randimg]) . '&imgw=' . $imgw . '&imgh=' . $imgh . '" />';

  # width="' . $imgw . '"
  $result .= '</a>';
  return $result;
}