You are here

function brilliant_gallery_views_handler_image_img in Brilliant Gallery 7

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

Views handler for displaying the image.

File

./views.inc, line 95

Code

function brilliant_gallery_views_handler_image_img($fieldinfo, $fielddata, $value, $data) {
  $tmp = $data->nid;

  // TODO Please convert this statement to the D7 database API syntax.
  $string = db_query("SELECT SQL_CACHE `field_gallery_value` FROM `content_type_page` WHERE `nid` = :tmp ORDER BY `vid` DESC LIMIT 1", array(
    ':tmp' => $tmp,
  ))
    ->fetchField();
  $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);

  # 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);

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

  # Get this module's path:
  $modulepath = url(drupal_get_path('module', 'brilliant_gallery'), array(
    'absolute' => TRUE,
  ));

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

  # Non-clean URLs need removing ?q=
  $modulepath = str_replace("?q=", "", $modulepath);
  $result = '<a href="' . file_create_url($modulepath . '/image.php?imgp=' . base64_encode($absolpath . '/' . $retval[$randimg]) . '&imgw=' . $imgw * 6 . '&imgh=' . $imgh * 6) . '"';

  //$setname = mt_rand(1, 9999999);
  $setname = md5($absolpath);
  $overbrowser = variable_get('brilliant_gallery_overbrowser', 'colorbox');
  switch ($overbrowser) {
    case 'colorbox':
      $result .= ' class="colorbox" rel="bg-' . $setname . '"';
      break;
    case 'lightbox':
      $result .= ' rel="lightbox[' . $setname . ']"';
      break;
    default:
      break;
  }
  if ($showcaption != '') {
    $result .= ' title="' . $caption . '"';
  }
  $result .= '>';

  # width="' . $imgw . '"
  $result .= '<img style="display: block;border:0;align:right" src="' . file_create_url($modulepath . '/image.php?imgp=' . base64_encode($absolpath . '/' . $retval[$randimg]) . '&imgw=' . $imgw . '&imgh=' . $imgh) . '" />';
  $result .= '</a>';
  return $result;
}