You are here

OLD_brilliant_gallery.module in Brilliant Gallery 7.2

File

OLD_brilliant_gallery.module
View source
<?php

// See http://api.drupal.org/api/drupal/includes--file.inc/function/file_directory_path/6#comment-12954
define('FILE_DIRECTORY_PATH', variable_get('file_public_path', conf_path() . '/files'));

// Patching a possible problem with i18n

/**
 * Implements hook_block_info().
 */
function brilliant_gallery_block_info() {
  $block = array();

  // if (TRUE) {
  $block[0]["info"] = t("Brilliant Gallery");
  return $block;

  // }
}

/**
 * Implements hook_block_view().
 */
function brilliant_gallery_block_view($delta) {
  $block_content = '';
  $block_content .= render_brilliant_gallery();
  $block = array();

  // set up the block
  $block['subject'] = 'Brilliant gallery';
  $block['content'] = $block_content;
  return $block;
}

/**
 * @todo Please document this function.
 * @see http://drupal.org/node/1354
 */
function brilliant_gallery_all($switch = '') {
  $page_content = '';
  if ($switch == '') {
    $page_content .= render_brilliant_gallery();
  }
  else {
    if ($switch == 'edit') {
      $page_content .= render_brilliant_gallery_edit();
    }
  }
  return $page_content;
}

/**
 * Function to load the settings of all the checkboxes on this node.
 * Note that checkboxes that have never been checked will not have an entry in the database.
 */
function brilliant_gallery_checklist_loadall($nid = '') {
  global $user;
  $GLOBALS['devel_shutdown'] = FALSE;
  $uid = $user->uid;
  $dcvals = 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
  // TODO Please convert this statement to the D7 database API syntax.
  $result = db_query("select qid,state from {brilliant_gallery_checklist} where nid=:nid1 and qid not like 'user-%' and user=0 " . " union " . "select qid,state from {brilliant_gallery_checklist} where nid=:nid2 and qid like 'user-%' and user=:uid ", array(
    ':nid1' => $nid,
    ':nid2' => $nid,
    ':uid' => $uid,
  ));
  $count = 0;
  foreach ($result as $data) {
    $dcvals[$count] = array(
      'qid' => $data->qid,
      'state' => $data->state,
    );
    $count++;
  }
  print drupal_json_encode($dcvals);
  exit;
}

/**
 * Function to save/update the state of a checkbox when toggled
 */
function brilliant_gallery_checklist_save($nid, $qid, $state) {
  global $user;
  $GLOBALS['devel_shutdown'] = FALSE;
  if (preg_match("/^user-/", $qid) == 1) {
    $uid = $user->uid;
  }
  else {
    $uid = 0;
  }

  // TODO Please convert this statement to the D7 database API syntax.
  $existing = db_query("select count(state) from {brilliant_gallery_checklist} " . "where nid=:nid and user=:uid and qid=:qid", array(
    ':nid' => $nid,
    ':uid' => $uid,
    ':qid' => $qid,
  ))
    ->fetchField();
  if ($existing == 0) {

    // TODO Please convert this statement to the D7 database API syntax.
    db_query("insert into {brilliant_gallery_checklist} (nid,user,qid,state) " . "values (:nid,:uid,:qid,:state)", array(
      ':nid' => $nid,
      ':uid' => $uid,
      ':qid' => $qid,
      ':state' => $state,
    ));
  }
  else {

    // TODO Please convert this statement to the D7 database API syntax.
    $current = db_query("select state from {brilliant_gallery_checklist} " . " where nid=:nid and user=:uid and qid=:qid", array(
      ':nid' => $nid,
      ':uid' => $uid,
      ':qid' => $qid,
    ))
      ->fetchField();
    if ($current != $state) {

      // TODO Please convert this statement to the D7 database API syntax.
      db_query("update {brilliant_gallery_checklist} " . "set state=:state where nid=:nid and user=:uid and qid=:qid", array(
        ':state' => $state,
        ':nid' => $nid,
        ':uid' => $uid,
        ':qid' => $qid,
      ));
    }
  }
  print drupal_json_encode("1");
  exit;
}

/**
 * Helper function for preg_replace_callback to generate the html for each checkbox
 * Form API not used as that would float all the checkboxes to the top/bottom of the page.
 */
function brilliant_gallery_checklist_docheckbox($matches) {
  global $brilliant_gallery_checklist_matchcount;
  $brilliant_gallery_checklist_matchcount++;
  $name = check_plain($matches[1]);
  $label = filter_xss($matches[2]);
  $output = <<<OUTPUT
    <div class="bgchecklist"> <div class="form-item"> <input name="{<span class="php-variable">$name</span>}" id="{<span class="php-variable">$name</span>}" value="1" class="form-brilliant_gallery_checklist-checkbox" type="checkbox"> <label class="option"> {<span class="php-variable">$label</span>} </label> </div></div>
OUTPUT;
  return $output;
}

/**
 * @todo Please document this function.
 * @see http://drupal.org/node/1354
 */
function brilliant_gallery_admin($form, &$form_state) {
  $form['brilliant_gallery_maxcol'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum number of table columns'),
    '#default_value' => variable_get('brilliant_gallery_maxcol', 5),
    '#size' => 2,
    '#maxlength' => 2,
    '#description' => t("The maximum number of columns displayed in the table. If this is zero, the images will fill the row and continue on a next one."),
  );
  $form['brilliant_gallery_maximagewidth'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum width of table images'),
    '#default_value' => variable_get('brilliant_gallery_maximagewidth', 150),
    '#size' => 3,
    '#maxlength' => 4,
    '#description' => t("The maximum width of thumbnails in the table (height calculated automatically)."),
  );
  $form['brilliant_gallery_crop'] = array(
    '#type' => 'select',
    '#title' => t('Crop thumbnails to square shape'),
    '#required' => FALSE,
    '#options' => array(
      'yes' => t('yes'),
      'no' => t('no'),
    ),
    '#default_value' => variable_get('brilliant_gallery_crop', 'no'),
    '#description' => t("If selected, all image thumbnails will have the same square shape."),
  );
  $color_field_type = (function_exists('colorpicker_2_or_later') ? 'colorpicker_' : '') . 'textfield';
  $form['brilliant_gallery_bcgcolour_textfield'] = array(
    '#type' => $color_field_type,
    '#title' => t('Background colour'),
    '#description' => t('Please enter a color value in the form #RRGGBB'),
    '#default_value' => variable_get('brilliant_gallery_bcgcolour_textfield', '#000000'),
  );
  $form['brilliant_gallery_padding'] = array(
    '#type' => 'textfield',
    '#title' => t('Table cell padding'),
    '#default_value' => variable_get('brilliant_gallery_padding', 3),
    '#size' => 3,
    '#maxlength' => 3,
    '#description' => t("Cell padding (around each image) in pixels."),
  );
  $form['brilliant_gallery_overbrowser'] = array(
    '#type' => 'select',
    '#title' => t('Overlay browser'),
    '#required' => FALSE,
    '#options' => array(
      'colorbox' => t('Colorbox'),
      'lightbox' => t('Lightbox'),
      'none' => t('None'),
    ),
    '#default_value' => variable_get('brilliant_gallery_overbrowser', 'colorbox'),
    '#description' => t('Select the overlay image browser (the relevant module must be installed, of course).'),
  );
  $form['brilliant_gallery_maxwidth'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum width of full image'),
    '#default_value' => variable_get('brilliant_gallery_maxwidth', '1920'),
    '#size' => 5,
    '#maxlength' => 5,
    '#description' => t("Very large images will be scaled down to this width (in pixels) for display before they get displayed by the overlay browser."),
  );
  $form['brilliant_gallery_caption'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display file name as caption'),
    '#default_value' => variable_get('brilliant_gallery_caption', ''),
    #'#size' => 5,

    #'#maxlength' => 5,
    '#description' => t("Check this if you want the overlay browser to display a caption based on the image file name (dots and underscores are automatically replaced by spaces)."),
  );
  $form['brilliant_gallery_sort'] = array(
    '#type' => 'radios',
    '#title' => t('Sort or randomize image order'),
    '#default_value' => variable_get('brilliant_gallery_sort', '1'),
    '#options' => array(
      '1' => t('Sort images by their file names alphabetically.'),
      '' => t('The order of your gallery images will always be randomized (on each page load or cache refresh).'),
    ),
  );
  return system_settings_form($form);
}
function bg_iterative_recurse_dir($from = '.') {
  if (!is_dir($from)) {
    return FALSE;
  }
  $files = array();
  $dirs = array(
    $from,
  );
  while (NULL !== ($dir = array_pop($dirs))) {
    if ($dh = opendir($dir)) {
      while (FALSE !== ($file = readdir($dh))) {
        if ($file == '.' || $file == '..') {
          continue;
        }
        $path = $dir . '/' . $file;
        if (is_dir($path)) {
          $dirs[] = $path;
        }
        else {
          $files[] = $path;
        }
      }
      closedir($dh);
    }
  }
  return $files;
}

/**
 * @todo Please document this function.
 * @see http://drupal.org/node/1354
 */
function brilliant_gallery_filter_XXX($op, $delta = 0, $format = -1, $text = '') {
}

Functions

Namesort descending Description
bg_iterative_recurse_dir
brilliant_gallery_admin @todo Please document this function.
brilliant_gallery_all @todo Please document this function.
brilliant_gallery_block_info Implements hook_block_info().
brilliant_gallery_block_view Implements hook_block_view().
brilliant_gallery_checklist_docheckbox Helper function for preg_replace_callback to generate the html for each checkbox Form API not used as that would float all the checkboxes to the top/bottom of the page.
brilliant_gallery_checklist_loadall Function to load the settings of all the checkboxes on this node. Note that checkboxes that have never been checked will not have an entry in the database.
brilliant_gallery_checklist_save Function to save/update the state of a checkbox when toggled
brilliant_gallery_filter_XXX @todo Please document this function.

Constants