You are here

public function JuiceboxGallery::addImage in Juicebox HTML5 Responsive Image Galleries 7.2

Add a new image to the gallery.

Parameters

array $src_data: Associative array containing all attributes needed to define a gallery image. camelCase attribute keys are preferred but underscore-separated (e.g., image_url) and dash-separated (e.g., image-url) values are also accepted when 'process_attributes' legacy support is active (i.e. when the 'process_attributes' setting was activated when the gallery was instantiated). This includes:

  • imageURL (Required): URL to the full image to display.
  • thumbURL (Required): URL to the thumbnail to display for the image.
  • linkURL: The Juicebox "link URL" value for the image.
  • linkTarget: The browser target value to use when following a link URL.

string $title: The title markup to display for the image.

string $caption: The caption markup to display for the image.

boolean $filter_markup: Optional. Whether-or-not to filter the $title and $caption values for syntactic compatibility with Juicebox. This setting applies to this specific image. If NULL the gallery-wide setting specified when the XML is generated will be used (see the renderXML()). This filter is not actually applied until the XML is rendered.

int $override_id: Optional. The id of an existing image, already added to the gallery, to override with new data. If NULL the image will simply be added. This id should match the index for the image as returned by getImages(). Not compatible with $offset.

int $offset: Optional. If offset is positive then the image is inserted at that offset from the beginning of the existing image list. If offset is negative then the image is inserted that far from the end of the image list. Not compatible with $override_id.

Return value

boolean Returns TRUE on successful addition and FALSE on failure.

Overrides JuiceboxGalleryInterface::addImage

1 call to JuiceboxGallery::addImage()
JuiceboxGallery::updateImage in includes/JuiceboxGallery.inc
Update an existing image in the gallery. This duplicates the functionality of addImage() with an $override_id but is included as a separate method for convienence.

File

includes/JuiceboxGallery.inc, line 77
A php-only set of methods to create the script and markup components of a Juicebox gallery.

Class

JuiceboxGallery
Class to generate the script and markup for a Juicebox gallery.

Code

public function addImage($src_data = array(), $title = '', $caption = '', $filter_markup = NULL, $override_id = NULL, $offset = NULL) {

  // If we are anticipating an override, but there is nothing to override,
  // don't do anything. Also, override_id and offset are mutually exclusive.
  if (isset($override_id) && (empty($this->images[$override_id]) || isset($offset))) {
    return FALSE;
  }

  // Make sure we have sufficient image data to work with. If legacy attribute
  // names are supported in the configuration then some names may be coming in
  // different formats (image_url vs. imageURL). In this case we need a
  // canonical form for validation.
  $src_data_canonical = !empty($this->settings['process_attributes']) ? $this
    ->processAttributes($src_data) : $src_data;
  if (!isset($src_data_canonical['imageURL']) || !isset($src_data_canonical['thumbURL'])) {
    return FALSE;
  }

  // Add image to gallery, overriding if necessary.
  $addition = array(
    'src_data' => $src_data,
    'title' => $title,
    'caption' => $caption,
    'filter_markup' => $filter_markup,
  );
  if (isset($override_id)) {
    $this->images[$override_id] = $addition;
  }
  elseif (isset($offset)) {
    array_splice($this->images, $offset, 0, array(
      $addition,
    ));
  }
  else {
    $this->images[] = $addition;
  }
  return TRUE;
}