You are here

function render_brilliant_gallery in Brilliant Gallery 6.3

Same name and namespace in other branches
  1. 5.4 brilliant_gallery.module \render_brilliant_gallery()
  2. 5.3 brilliant_gallery.module \render_brilliant_gallery()
  3. 6.4 gallery_showtime.inc \render_brilliant_gallery()
  4. 6 brilliant_gallery.module \render_brilliant_gallery()
  5. 6.2 brilliant_gallery.module \render_brilliant_gallery()
  6. 7.2 brilliant_gallery.inc \render_brilliant_gallery()
  7. 7.2 OLD_brilliant_gallery_showtime.inc \render_brilliant_gallery()
  8. 7 brilliant_gallery_showtime.inc \render_brilliant_gallery()
3 calls to render_brilliant_gallery()
brilliant_gallery_all in ./brilliant_gallery.module
brilliant_gallery_block in ./brilliant_gallery.module
Generate HTML for the Brilliant gallery block
replace_brilliant_gallery_tags in ./brilliant_gallery.module

File

./brilliant_gallery.module, line 566

Code

function render_brilliant_gallery($thisfolder = '', $colcountoverride = '', $widthoverride = '', $sortoverride = '', $maximumnumbertoshow = '', $colouroverride = '', $beginfromoverride = 1, $captionyesnotext = '') {
  $bgcachexpire = variable_get('brilliant_gallery_cache_duration', 90) * 24 * 3600;

  // Cache expiration time in days.
  // Is this a Picasa gallery?
  $picasafolder = false;

  #echo '....'.substr($thisfolder,0,29);
  if (substr($thisfolder, 0, 24) == 'http://picasaweb.google.') {

    // Must work for all variants - http://picasaweb.google.com, http://picasaweb.google.co.uk, etc.
    $picasafolder = true;
  }

  #drupal_add_css(drupal_get_path('module', 'brilliant_gallery') .'/brilliant_gallery.css');

  # Patching a possible problem with i18n
  $langcode = '';
  if (function_exists('i18n_get_lang')) {
    $langcode = i18n_get_lang();
  }

  #$result = '</p>';
  $result = '';
  $galleryfolder = variable_get('brilliant_gallery_folder', '');
  if (substr($galleryfolder, strlen($galleryfolder) - 1, 1) == '/' or substr($galleryfolder, 0, 1) == '/') {

    #watchdog('error', 'failed to notify "weblogs.com" (site)');

    #form_set_error('yemail', t('Header injection attempt detected.  Do not enter line feed characters into the from field!'));
    $bgmsg = 'Main gallery folder path must not begin or end with a slash; please fix it at /admin/settings/brilliant_gallery';
    drupal_set_message($bgmsg);
    watchdog('Brilliant Gal', $bgmsg);
    return;
  }

  /*
  if ($thisfolder <> '') {
  $galleryfolder .= '/'. $thisfolder;
  }
  */
  if ($thisfolder != '') {
    if ($galleryfolder != '') {

      #$galleryfolder .= '/' . $thisfolder;
      $galleryfolder .= (substr($thisfolder, 0, 1) == '/' ? '' : '/') . $thisfolder;

      // See http://drupal.org/node/176939#comment-1494648
    }
    else {
      $galleryfolder = $thisfolder;
    }
  }
  if ($colcountoverride == '') {
    $columns = variable_get('brilliant_gallery_maxcol', 3);
  }
  else {
    $columns = $colcountoverride;
  }
  if ($widthoverride == '') {
    $imagewidth = variable_get('brilliant_gallery_maximagewidth', 150);
  }
  else {
    $imagewidth = $widthoverride;
  }
  if ($sortoverride == '' or strtolower($sortoverride) == 'sort') {
    $brilliant_gallery_sort = variable_get('brilliant_gallery_sort', '1');
  }
  else {
    $brilliant_gallery_sort = $sortoverride;
  }
  if ($colouroverride == '') {
    $bgcolour = variable_get('brilliant_gallery_bcgcolour_textfield', '#000000');
  }
  else {
    $bgcolour = $colouroverride;
  }

  #if ($captionyesornot == 'yes' or $captionyesornot == '' or (variable_get('brilliant_gallery_caption', '') <> '' and $captionyesornot <> 'no')) {
  if (($captionyesnotext == 'yes' or $captionyesnotext == '') and variable_get('brilliant_gallery_caption', '') != '') {
    $showcaption = 'filename';
  }
  else {
    if ($captionyesnotext == 'no' or variable_get('brilliant_gallery_caption', '') == '' and ($captionyesnotext == 'yes' or $captionyesnotext == 'no')) {
      $showcaption = '';
    }
    else {

      #$showcaption = $captionyesornot;
      $showcaption = $captionyesnotext;
    }
  }
  $imagecrop = variable_get('brilliant_gallery_crop', FALSE);
  $padding = variable_get('brilliant_gallery_padding', 3);
  $overbrowser = variable_get('brilliant_gallery_overbrowser', 'lightbox');

  // Totally full resolution display would be impractical, so this is the maximum width of "full" resolution.
  $fullresolutionmaxwidth = variable_get('brilliant_gallery_maxwidth', '1000');
  $path = url(file_directory_path() . '/' . $galleryfolder, array(
    'absolute' => TRUE,
  ));

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

  // Non-clean URLs need removing ?q=
  $path = str_replace("?q=", "", $path);

  // Get absolute path
  if ($picasafolder) {
    $url_to_fetch = $thisfolder;

    #echo '.--..'.$url_to_fetch;
    $mgalleryurl = md5($url_to_fetch);
    $pcachetemp = trim(variable_get('brilliant_gallery_pcache', file_directory_temp()));
    if ($pcachetemp == '' or $pcachetemp == file_directory_temp()) {

      // If there is no cache directory in the files folder, then we need to use the default temp dir
      $pcachetemp = file_directory_temp();
      $beg_realpcachetemp = file_directory_temp();
      $slashpcachetemp = '';
    }
    else {
      $slashpcachetemp = '/' . $pcachetemp;
      $beg_realpcachetemp = realpath(file_directory_path()) . $slashpcachetemp;
    }

    #watchdog('Brilliant Gal','sakr: '.$beg_realpcachetemp);

    #$mkdirek = $pcachetemp . '/bg_picasa_'. $mgalleryurl;
    $mkdirek = $beg_realpcachetemp . '/bg_picasa_' . $mgalleryurl;

    /*
    $timenow = time();
    $lastchanged = $timenow;
    $fdirpath = $mkdirek.'/.'; // Needs a slash and dot to appear as a file to be able to get last mod time.
    $lastchanged = @filemtime($fdirpath);
    $direxpired = false;
    if ($timenow - $lastchanged > $bgcachexpire){
    $direxpired = true;
    // If the image is expired, we need to actively delete it, for the case that it was removed / hidden by the owner.
    #brilliant_gallery_unlinkRecursive($mkdirek); // http://be.php.net/manual/en/function.rmdir.php
    }
    drupal_set_message('dir ... '.$timenow . ' - '.$lastchanged.' == '.($timenow - $lastchanged). ' ('.$bgcachexpire.') '.$dirrmed);
    if (is_dir($mkdirek) and !$direxpired) {
    // If it exists, we assume it is also populated, so we don't create it, and we don't go fetching the remote data!
    #echo 'exists';
    }
    else {
    #echo 'new';
    include ('./'. drupal_get_path('module', 'brilliant_gallery') ."/picasa.inc");
    }
    */

    // We go and look at the images every time we render BG, because it sometimes happens that Picasa does not provide them all at the time of the initial fetching. So we will fetch any missing ones, and also replace the expired ones.
    // Vacilando 20091016: It is ABSOLUTELY CRUCIAL that this uses include_ONCE, otherwise picasa.inc was called twice in some cases.
    include_once './' . drupal_get_path('module', 'brilliant_gallery') . "/picasa.inc";
    $absolpath = $slashpcachetemp . '/bg_picasa_' . $mgalleryurl;

    #echo $absolpath;

    #drupal_set_message(t('absol: '.$absolpath));
  }
  else {

    /*
    $rp = file_directory_path();
    if ($galleryfolder <> '') {
    $rp .= '/'. $galleryfolder;
    }
    $absolpath = realpath($rp);
    */
    $absolpath = '/' . $galleryfolder;
  }

  #$result .= $absolpath;

  #watchdog('Brilliant Gal','absol: '.$absolpath);

  # Make an array with images in this folder, and their properties.

  #$temp              = load_dir_to_array($absolpath, $imagewidth, $fullresolutionmaxwidth, $brilliant_gallery_sort);
  $temp = load_dir_to_array($absolpath, $imagewidth, $fullresolutionmaxwidth, $brilliant_gallery_sort, $imagecrop);
  $retval_dimensions = $temp[0];
  $imagemaxh = $temp[1];
  $maxpoct = count($retval_dimensions);

  #if (arg(2) == 'edit') {

  #print_r( $retval_dimensions );

  #}

  # Get a list of images that are forbidden from display.

  #$uid=$user->uid;

  #echo $user->uid;
  $excludedimgs = array();

  // any checkbox id that starts with user- we remember the current user's settings
  // any other id is global and we use user=0

  /*
  $result=db_query("select qid,state from {brilliant_gallery_checklist} ".
  " where nid='$nid' and qid not like 'user-%' and user=0 ".
  " union ".
  "select qid,state from {brilliant_gallery_checklist} ".
  "where nid='$nid' and qid like 'user-%' and user='$uid' ");
  */
  $dbresult = db_query("select qid from {brilliant_gallery_checklist} where qid like 'user-%' and state='1' ");
  while ($data = db_fetch_object($dbresult)) {
    $excludedimgs[] = $data->qid;
  }

  #print_r($excludedimgs);

  // If $columns is 0, columns will fill up the available space.
  if ($columns != 0) {

    // Total 'width' controls the number of thumbnails in each row. The number, in pixels, should be calculated thusly: [maximum width desired for thumbnails] + [padding - if any, x 2] + [margin - if any, x 2] + [border - if any, x 2] x [number of thumbnails desired in each row]
    $style_ul = "font-size:0; margin:0px; dummy: 0; padding:0px; width: " . ($imagewidth + 2 * $padding) * $columns . "px;";
  }
  $column_count = 0;

  #$pocetobr = 0;
  $setname = mt_rand(1, 9999999);

  #$result .= '<!-- Brilliant Gallery Table Beginning --><table border="0" rules="none" frame="box" cellpadding="0" cellspacing="0" bgcolor="' . $bgcolour . '"';

  #$result .= '<!-- Brilliant Gallery Table Beginning -->';

  #$result .= '<ul class="brilliant_gallery" style="' . $style_ul . '">';
  $result .= '<ul style="' . $style_ul . '">';

  #if ( $thisfolder <> '' ) {

  #$result .= ' align="center"';

  #   }

  #$result .= ' style="width:' . $columns*$imagewidth . 'px;">'; #cell-spacing: 5px;

  #$result .= ' style="width:' . $columns*$imagewidth . 'px;"';

  #$result .= '>' . "\n"; #cell-spacing: 5px;
  $maxpoct_show = '';
  if ($maximumnumbertoshow != '' and is_numeric($maximumnumbertoshow)) {
    $maxpoct_show = $maximumnumbertoshow;
  }

  
  $retval = array();
  $cnt = 0;
  for ($poct = 1; $poct <= $maxpoct; $poct++) {

    # Skip any images that were excluded from display.

    # md5() must be made of the main gallery path etc. ending with the file name (unique identifier). E.g. albums/2008/20080321-25_belgicko_zasypane_snehom/dsc02784_w1000.jpg
    if (array_search('user-' . md5($galleryfolder . '/' . $retval_dimensions[$poct - 1]['file']), $excludedimgs) !== false) {
      continue;
    }
    if ($poct < $beginfromoverride) {
      continue;

      # Begin only from $beginfromoverride image.
    }
    $cnt += 1;
    if ($cnt > $maxpoct_show and $maxpoct_show != '') {
      continue;

      # Do not show more than $maxpoct_show (if defined).
    }
    $retval[$poct - 1] = $retval_dimensions[$poct - 1]['file'];
    $fullimgpath = $path . '/' . $retval[$poct - 1];

    #if ($column_count == 0) { $result .= ('<tr>'); }

    #$result .= ('<td align="center" bgcolor="' . $bgcolour . '" style="padding: ' . $padding . 'px ' . $padding . 'px ' . $padding . 'px ' . $padding . 'px;vertical-align: middle;">');

    #$result .= ('<td align="center" bgcolor="' . $bgcolour . '" style="padding: ' . $padding . 'px ' . $padding . 'px ' . $padding . 'px ' . $padding . 'px;vertical-align: middle;">' . "\n");

    #$pocetobr += 1;
    if (testext($retval[$poct - 1])) {
      $caption = str_replace(array(
        '.',
        '_',
      ), ' ', basename($retval[$poct - 1], strrchr($retval[$poct - 1], '.')));

      #$smallenough = false;
      $imgw = $retval_dimensions[$poct - 1]['imgw'];
      $imgh = $retval_dimensions[$poct - 1]['imgh'];
      $imgwbig = $retval_dimensions[$poct - 1]['imgwbig'];
      $imghbig = $retval_dimensions[$poct - 1]['imghbig'];
      $imgcrop = $retval_dimensions[$poct - 1]['imgcrop'];

      #@$smallenough = $retval_dimensions[$poct - 1]['smallenough'];

      #$style_li = "float: left; list-style: none; background: #000; width: 44px; height: 33px; padding: 4px; text-align: center; margin: 0; border: none;";
      $style_li = "font-size:0; float: left; width: " . $imagewidth . "px; list-style: none; background: " . $bgcolour . "; height: " . $imagemaxh . "px; padding: " . $padding . "px; text-align: center; margin: 0px; border: none;";
      $result .= '<li style="' . $style_li . '">' . "\n";

      # 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 ($langcode != '') {
        $modulepath = str_replace('/' . $langcode . '/', '/', $modulepath);
      }

      # Non-clean URLs need removing ?q=
      $modulepath = str_replace("?q=", "", $modulepath);

      #if ($smallenough === true) {

      #  $result .= '<a href="'. $fullimgpath .'"';

      #}

      #else {

      # Important to begin with the "/" otherwise thumbnails in non-root folders fail. See http://drupal.org/node/175292

      #$result .= '<a href="' . $modulepath .'/image.php?imgp=' . base64_encode( $absolpath . '/' . $retval[$poct-1] ) . '&amp;imgw=' . $imgwbig . '&amp;imgh=' . $imghbig . '"'; #&dummy=.jpg

      #&dummy=.jpg
      $result .= '<a href="' . $modulepath . '/image.php?imgp=' . base64_encode($absolpath . '/' . $retval[$poct - 1]) . '&imgw=' . $imgwbig . '&imgh=' . $imghbig . '"';

      #}
      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 'greybox':
          $result .= ' class="greybox"';
          break;
        default:
          break;
      }
      if ($showcaption != '') {
        if ($showcaption != 'filename') {
          $caption = $showcaption;
        }
        $result .= ' title="' . $caption . '"';
      }
      $result .= '>';

      # Important to begin with the "/" otherwise thumbnails in non-root folders fail. See http://drupal.org/node/175292

      /*
      $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 ( $langcode <> '' ) {
      $modulepath = str_replace( '/' . $langcode . '/', '/', $modulepath );
      }
      # Non-clean URLs need removing ?q=
      $modulepath = str_replace( "?q=", "",  $modulepath );
      */

      #$result .= '<img style="display: block;border:0" src="' . $modulepath .'/image.php?imgp=' . base64_encode( $absolpath . '/' . $retval[$poct-1] ) . '&imgw=' . $imgw . '&imgh=' . $imgh . '" />'; # width="' . $imgw . '"

      #$result .= '<img style="border: 0; margin:0px; padding:0px;" alt="" src="' . $modulepath .'/image.php?imgp=' . base64_encode( $absolpath . '/' . $retval[$poct-1] ) . '&amp;imgw=' . $imgw . '&amp;imgh=' . $imgh . '" />'; # width="' . $imgw . '"

      # width="' . $imgw . '"

      #$result .= '<img style="border: 0; margin:0px; padding:0px;" alt="" src="'. $modulepath .'/image.php?imgp='. base64_encode($absolpath .'/'. $retval[$poct - 1]) .'&imgw='. $imgw .'&imgh='. $imgh .'" />';
      $result .= '<img style="border: 0; margin:0px; padding:0px;" alt="" src="' . $modulepath . '/image.php?imgp=' . base64_encode($absolpath . '/' . $retval[$poct - 1]) . '&imgw=' . $imgw . '&imgh=' . $imgh . '&imgcrop=' . $imgcrop . '" />';

      #$result .= '</a>';
      $result .= '</a>' . "\n";
    }
    else {
      $fosiz = ceil($imagewidth / 13);
      $style_li = "font-size:" . $fosiz . "px; float: left; width: " . $imagewidth . "px; list-style: none; background: " . $bgcolour . "; height: " . $imagemaxh . "px; padding: " . $padding . "px; text-align: center; margin: 0px; border: none;";
      $result .= '<li style="' . $style_li . '">' . "\n";
      $result .= '<a href="' . $fullimgpath . '">';

      #$result .= '<center>' . $retval[$poct-1] . '</center>';
      $result .= $retval[$poct - 1];

      #brokenimage("Error loading PNG");

      #$result .= '</a>';
      $result .= '</a>' . "\n";
    }

    #$result .= '</td>';
    $result .= '</li>' . "\n";
    $column_count += 1;

    #if ($column_count == $columns) { $result .= ("</tr>\n"); $column_count = 0; }
  }

  #if ($column_count <> 0) { $result .= ("</tr>"); }

  #if ($column_count <> 0) { $result .= ("</tr>\n"); }

  #$result .= "</table>\n";
  $result .= "</ul>\n";

  #$result .= '<br style="clear: both;" />';

  #$result .= '<p>';
  return $result;
}