gallery = $gallery; $this->library = $library; } /** * {@inheritdoc} */ public function init($id_args, $settings = array(), $data = NULL) { // Set path for reference. $this->idArgs = $id_args; $this->settings = $settings; $this->data = $data; // Calculate and set the gallery ID. $id = ''; foreach ($id_args as $arg) { $id .= $arg . '--'; } // Make sure no special characters slipped through inside individual args. $id = trim(preg_replace('/[^0-9a-zA-Z-]/', '-', $id), '- '); $this->setId($id); $this->initialized = TRUE; } /** * {@inheritdoc} */ public function isInitialized() { if ($this->initialized) { return TRUE; } return FALSE; } /** * {@inheritdoc} */ public function getIdArgs() { return $this->idArgs; } /** * {@inheritdoc} */ public function getSettings() { return $this->settings; } /** * {@inheritdoc} */ public function runCommonBuild() { // Add all gallery options directly from the settings. $this->setGalleryOptions(); // Also attempt to translate interface strings. if (variable_get('juicebox_translate_interface', FALSE)) { $base_string = variable_get('juicebox_translate_base_languagelist', ''); if (!empty($base_string)) { $this->addOption('languagelist', check_plain(t($base_string)), FALSE); } } // Allow other modules to alter the built gallery data before it's // rendered. After this point the gallery should no longer change. drupal_alter('juicebox_gallery', $this, $this->data); } /** * {@inheritdoc} */ public function buildEmbed($xml_path = '', $add_js = TRUE, $context = array(), $add_xml = FALSE) { // Prep the ids that may be referenced. $embed_id = $this->getId(); $embed_xml_id = 'xml--' . $embed_id; // If we are embedding the XML we also want to set some query string values // on the XML URL that will allow the XML build methods to fetch it later. $embed_query_additions = array(); if ($add_xml) { $embed_query_additions['xml-source-path'] = current_path(); $embed_query_additions['xml-source-id'] = $embed_xml_id; } // Pass-through the current query paramaters and a checksum on the XML URL. $current_query = drupal_get_query_parameters(); $xml_query = array_merge($current_query, array('checksum' => $this->getChecksum()), $embed_query_additions); $xml = array( 'path' => $xml_path, 'options' => array('query' => $xml_query), ); // The returned render array will contain some common values no matter what // output we produce (normal and debug). $output = array( '#c_links' => $this->buildContextualLinks($xml_path, $context, $add_xml), '#gallery_id' => $embed_id, '#gallery_images' => $this->getImages(TRUE), '#gallery_options' => $this->getOptions(TRUE), '#xml' => $xml, '#settings' => $this->settings, '#suffix' => '', ); // If "jb-debug" is active in the query we display debug info in place of // the actual gallery. if (array_key_exists('jb-debug', $current_query) && $this->accessDebugDisplay()) { $output['#theme'] = 'juicebox_debug_markup'; $output['#attached']['css'] = array(drupal_get_path('module', 'juicebox') . '/css/admin_styles.css'); } // Otherwise we display the gallery as normal. else { $output['#theme'] = 'juicebox_embed_markup'; if ($add_js) { // Add the main library via libraries API. $output['#attached']['libraries_load'][] = array('juicebox'); // Add the JS gallery details as Drupal.settings. $output['#attached']['js'][] = array( 'data' => array('juicebox' => array($embed_id => $this->getJavascriptVars(url($xml['path'], $xml['options'])))), 'type' => 'setting', ); // Add some local JS (implementing Drupal.behaviors) that will process // the Drupal.settings above into a new client-side juicebox object. $output['#attached']['js'][] = drupal_get_path('module', 'juicebox') . '/js/juicebox_load.js'; } if ($add_xml) { $output['#suffix'] .= $this->renderXml($embed_xml_id); } } return $output; } /** * {@inheritdoc} */ public function styleImageSrcData($image_item, $image_style, $thumb_item, $thumb_style) { $settings = $this->settings; // Make sure that we have proper file field items to work with. if (!isset($image_item['fid']) || !isset($thumb_item['fid'])) { throw new Exception(t('Invalid image or thumbnail item detected while extracting Juicebox gallery source information.')); } $check_incompatible = (!empty($settings['incompatible_file_action'])); $src_data = array(); // Style the main item. $this->styleImage($image_item, $image_style, $check_incompatible); $src_data = $image_item['juicebox_src_data']; // Style the thumb. if (!$image_item['juicebox_compatible'] && $image_item['fid'] == $thumb_item['fid']) { $src_data['thumb_url'] = $src_data['image_url']; } else { $this->styleImage($thumb_item, $thumb_style, $check_incompatible); $src_data['thumb_url'] = $thumb_item['juicebox_src_data']['image_url']; } // Check if the linkURL should be customized based on settings. $src_data['link_url'] = $image_item['unstyled_src']; if ($image_item['juicebox_compatible'] && !empty($settings['linkurl_source']) && $settings['linkurl_source'] == 'image_styled') { $src_data['link_url'] = $src_data['image_url']; } // Set the link target directly from the gallery settings. $src_data['link_target'] = !empty($settings['linkurl_target']) ? $settings['linkurl_target'] : '_blank'; // Also set a flag for incompatible files. $src_data['juicebox_compatible'] = $image_item['juicebox_compatible']; return $src_data; } /** * Utility to style an individual image/file field item for use in a Juicebox * gallery. * * This method can detect if the passed item is incompatible with Juicebox. * If so it styles the output as a mimetype image icon representing the file * type. Otherwise the item is styled normally with the passed image style. * * @param array $item * An associative array of file field item data to append Juicebox styled * image data to. * @param string $style * The Drupal image style to apply to the item. * @param boolean $check_compatible * Whether-or-not to detect if the item is compatible with Juicebox, and if * so, substitute a mimetype icon for its output. */ protected function styleImage(&$item, $style, $check_compatible = TRUE) { $item['juicebox_compatible'] = TRUE; // Set the normal, unstyled, url for reference. $item['unstyled_src'] = file_create_url($item['uri']); // Check compatibility if configured and if the library info contains // mimetype compatibitly information. if ($check_compatible && !empty($this->library['compatible_mimetypes']) && !in_array($item['filemime'], $this->library['compatible_mimetypes'])) { // If the item is not compatible, find the substitute mimetype icon. $item['juicebox_compatible'] = FALSE; $icon_dir = drupal_get_path('module', 'juicebox') . '/images/mimetypes'; $icon_path = file_icon_path((object) $item, $icon_dir); if ($icon_path) { $item['juicebox_src_data']['image_url'] = file_create_url($icon_path); } else { $item['juicebox_src_data']['image_url'] = file_create_url($icon_dir . '/image-x-generic.png'); } } // If the item is compatible, style it. else { $sizes = array('image_url' => $style); // The "juicebox_multisize" style is special, and actually consists of 3 // individual styles configured globally. if ($style == 'juicebox_multisize') { $sizes = array( 'image_url_small' => variable_get('juicebox_multisize_small', 'juicebox_small'), 'image_url' => variable_get('juicebox_multisize_medium', 'juicebox_medium'), 'image_url_large' => variable_get('juicebox_multisize_large', 'juicebox_large'), ); } foreach ($sizes as $size => $style_each) { if (!empty($style_each)) { $item['juicebox_src_data'][$size] = image_style_url($style_each, $item['uri']); } else { $item['juicebox_src_data'][$size] = $item['unstyled_src']; } } } } /** * Utility to build a render array of contextual links that can be used to * administer a gallery. * * @param string $xml_path * The path to the Juicebox XML for this gallery. * @param array $context * Optional contextual information that may be used in the links: * - conf_path: A Drupal path within the admin interface where the gallery * can be configured. * @param boolean $omit_xml_link * Whether-or-not to omit a contextul link to the gallery XML. * @return array * Drupal render array for the contextual links. * * @see JuiceboxGalleryDrupalInterface::buildGallery() */ protected function buildContextualLinks($xml_path = '', $context = array(), $omit_xml_link = FALSE) { $c_links = array(); if (module_exists('contextual') && user_access('access contextual links')) { $links = array(); // Add link to the gallery-specific configuration if we have it. if (!empty($context['conf_path']) && drupal_valid_path($context['conf_path'])) { $links['gallery_config'] = array('title' => t('Configure galleries of this type'), 'href' => $context['conf_path'], 'query' => drupal_get_destination()); } // Add a link to the global Juicebox options. if (drupal_valid_path('admin/config/media/juicebox')) { $links['global_config'] = array('title' => t('Configure global Juicebox options'), 'href' => 'admin/config/media/juicebox', 'query' => drupal_get_destination()); } if (!$omit_xml_link) { $links['xml'] = array('title' => t('View gallery XML'), 'href' => $xml_path); } // Add link to toggle debug view. if ($this->accessDebugDisplay()) { $query = drupal_get_query_parameters(); if (empty($query['jb-debug'])) { $query['jb-debug'] = 1; $title = t('Toggle debug info on'); } else { unset($query['jb-debug']); $title = t('Toggle debug info off'); } $links['toggle_debug'] = array('title' => $title, 'href' => current_path(), 'query' => $query, 'fragment' => $this->getId()); } // If we have links, build a render array for the contextual links. if ($links) { // Add the contextual-links-region wrapper to the Juicebox parent. $this->settings['custom_parent_classes'] = trim($this->settings['custom_parent_classes'] . ' contextual-links-region'); $c_links = array( '#prefix' => '
' . $notification_top . '
' : '', '#weight' => 10, ); $form['jlib_galleryWidth'] = array( '#jb_fieldset' => 'juicebox_config', '#type' => 'textfield', '#title' => t('Gallery Width'), '#description' => t('Set the gallery width in a standard numeric format (such as 100% or 300px).'), '#element_validate' => array('juicebox_element_validate_dimension'), ); $form['jlib_galleryHeight'] = array( '#jb_fieldset' => 'juicebox_config', '#type' => 'textfield', '#title' => t('Gallery Height'), '#description' => t('Set the gallery height in a standard numeric format (such as 100% or 300px).'), '#element_validate' => array('juicebox_element_validate_dimension'), ); $form['jlib_backgroundColor'] = array( '#jb_fieldset' => 'juicebox_config', '#type' => 'textfield', '#title' => t('Background Color'), '#description' => t('Set the gallery background color as a CSS3 color value (such as rgba(10,50,100,0.7) or #FF00FF).'), ); $form['jlib_textColor'] = array( '#jb_fieldset' => 'juicebox_config', '#type' => 'textfield', '#title' => t('Text Color'), '#description' => t('Set the color of all gallery text as a CSS3 color value (such as rgba(255,255,255,1) or #FF00FF).'), ); $form['jlib_thumbFrameColor'] = array( '#jb_fieldset' => 'juicebox_config', '#type' => 'textfield', '#title' => t('Thumbnail Frame Color'), '#description' => t('Set the color of the thumbnail frame as a CSS3 color value (such as rgba(255,255,255,.5) or #FF00FF).'), ); $form['jlib_showOpenButton'] = array( '#jb_fieldset' => 'juicebox_config', '#type' => 'checkbox', '#title' => t('Show Open Image Button'), '#description' => t('Whether to show the "Open Image" button. This will link to the full size version of the image within a new tab to facilitate downloading.'), ); $form['jlib_showExpandButton'] = array( '#jb_fieldset' => 'juicebox_config', '#type' => 'checkbox', '#title' => t('Show Expand Button'), '#description' => t('Whether to show the "Expand" button. Clicking this button expands the gallery to fill the browser window.'), ); $form['jlib_useFullscreenExpand'] = array( '#jb_fieldset' => 'juicebox_config', '#type' => 'checkbox', '#title' => t('Use Fullscreen Expand'), '#description' => t('Whether to trigger fullscreen mode when clicking the expand button (for supported browsers).'), ); $form['jlib_showThumbsButton'] = array( '#jb_fieldset' => 'juicebox_config', '#type' => 'checkbox', '#title' => t('Show Thumbs Button'), '#description' => t('Whether to show the "Toggle Thumbnails" button.'), ); $form['jlib_useThumbDots'] = array( '#jb_fieldset' => 'juicebox_config', '#type' => 'checkbox', '#title' => t('Show Thumbs Dots'), '#description' => t('Whether to replace the thumbnail images with small dots.'), ); $form['juicebox_manual_config'] = array( '#type' => 'fieldset', '#title' => t('Juicebox Library - Pro / Manual Config'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#description' => '' . t('Specify any additional Juicebox library configuration options (such as "Pro" options) here.
Options set here always take precedence over those set in the "Lite" options above if there is a conflict.') . '