You are here

prettyphoto_formatters.module in prettyPhoto Formatters 7

prettyPhoto formatter hooks and callbacks.

File

prettyphoto_formatters.module
View source
<?php

/**
 * @file
 * prettyPhoto formatter hooks and callbacks.
 */

/**
 * Implements hook_libraries_info().
 */
function prettyphoto_formatters_libraries_info() {
  $libraries['jquery.prettyPhoto'] = array(
    'name' => 'prettyPhoto',
    'vendor url' => 'http://www.no-margin-for-errors.com',
    'download url' => 'https://github.com/scaron/prettyphoto',
    'version arguments' => array(
      'file' => 'js/jquery.prettyPhoto.js',
      // Version: 3.1.5
      'pattern' => '/Version: (\\d+\\.+\\d+\\.+\\d+)/',
      'lines' => 5,
    ),
    'files' => array(
      'js' => array(
        'js/jquery.prettyPhoto.js',
      ),
      'css' => array(
        'css/prettyPhoto.css',
      ),
    ),
  );
  return $libraries;
}

/**
 * Implements hook_page_build().
 */
function prettyphoto_formatters_page_build(&$page) {
  if (prettyphoto_formatters_exclude_these_paths() != 1) {

    // Load library.
    $library = libraries_load('jquery.prettyPhoto');

    // If library loaded successfully.
    if ($library && !empty($library['loaded'])) {
      $js_settings = array(
        'animation_speed' => variable_get('prettyphoto_formatters_animation_speed', 'fast'),
        'slideshow' => (int) variable_get('prettyphoto_formatters_slideshow', 5000),
        'autoplay_slideshow' => (bool) variable_get('prettyphoto_autoplay_slideshow', FALSE),
        'opacity' => (double) variable_get('prettyphoto_formatters_opacity', 0.8),
        'show_title' => (bool) variable_get('prettyphoto_formatters_show_title', TRUE),
        'allow_resize' => (bool) variable_get('prettyphoto_formatters_allow_resize', TRUE),
        'default_width' => (int) variable_get('prettyphoto_formatters_default_width', 500),
        'default_height' => (int) variable_get('prettyphoto_formatters_default_height', 344),
        'counter_separator_label' => variable_get('prettyphoto_formatters_counter_separator_label', '/'),
        'theme' => variable_get('prettyphoto_formatters_theme', 'pp_default'),
        'horizontal_padding' => (int) variable_get('prettyphoto_formatters_horizontal_padding', 20),
        'hideflash' => (bool) variable_get('prettyphoto_formatters_hideflash', FALSE),
        'wmode' => variable_get('prettyphoto_formatters_wmode', 'opaque'),
        'autoplay' => (bool) variable_get('prettyphoto_formatters_autoplay', TRUE),
        'modal' => (bool) variable_get('prettyphoto_formatters_modal', FALSE),
        'deeplinking' => (bool) variable_get('prettyphoto_formatters_deeplinking', TRUE),
        'overlay_gallery' => (bool) variable_get('prettyphoto_formatters_overlay_gallery', TRUE),
        'keyboard_shortcuts' => (bool) variable_get('prettyphoto_formatters_keyboard_shortcuts', TRUE),
        'ie6_fallback' => (bool) variable_get('prettyphoto_formatters_ie6_fallback', TRUE),
      );

      // Overrides default markups with templates.
      $js_settings['markup'] = _prettyphoto_formatters_get_tpl('markup');
      $js_settings['gallery_markup'] = _prettyphoto_formatters_get_tpl('gallery_markup');
      $js_settings['image_markup'] = _prettyphoto_formatters_get_tpl('image_markup');
      $js_settings['flash_markup'] = _prettyphoto_formatters_get_tpl('flash_markup');
      $js_settings['quicktime_markup'] = _prettyphoto_formatters_get_tpl('quicktime_markup');
      $js_settings['iframe_markup'] = _prettyphoto_formatters_get_tpl('iframe_markup');
      $js_settings['inline_markup'] = _prettyphoto_formatters_get_tpl('inline_markup');
      $js_settings['custom_markup'] = _prettyphoto_formatters_get_tpl('custom_markup');
      $social = (bool) variable_get('prettyphoto_formatters_social_tools', TRUE);
      if ($social) {
        $js_settings['social_tools'] = _prettyphoto_formatters_get_tpl('social_tools');
      }
      else {
        $js_settings['social_tools'] = FALSE;
      }
      $module_path = drupal_get_path('module', 'prettyphoto_formatters');
      $js = $module_path . '/js/prettyphoto_formatters.js';
      drupal_add_js(array(
        'prettyphoto' => $js_settings,
      ), 'setting');
      drupal_add_js($js, array(
        'scope' => 'footer',
      ));
    }
  }
}

/**
 * Return TRUE if current path is disabled.
 *
 * @return bool
 *   Return TRUE if current path is disabled.
 */
function prettyphoto_formatters_exclude_these_paths() {
  $action = variable_get('prettyphoto_formatters_exclude_action', 'page_disable');
  $paths = variable_get('prettyphoto_formatters_exclude_these_paths', '');
  if (!empty($paths)) {
    $current_path = current_path();

    // Retrieve Drupal alias for the current path (if exists).
    $alias = drupal_get_path_alias($current_path);
    if (drupal_match_path($current_path, $paths) || drupal_match_path($alias, $paths)) {
      return $action == 'page_disable' ? 1 : 0;
    }
  }
  return $action == 'page_disable' ? 0 : 1;
}

/**
 * Implements hook_permission().
 */
function prettyphoto_formatters_permission() {
  return array(
    'administer prettyphoto formatter' => array(
      'title' => t('Administer prettyPhoto Formatter'),
      'description' => t('Allow the user administer prettyPhoto Formatter settings'),
    ),
  );
}

/**
 * Implements hook_menu().
 */
function prettyphoto_formatters_menu() {
  $items = array();
  $items['admin/config/media/prettyphoto-formatters'] = array(
    'title' => 'prettyPhoto Formatters',
    'description' => 'Allows the user to configure the prettyPhoto settings',
    'file' => 'prettyphoto_formatters.admin.inc',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'prettyphoto_formatters_settings_form',
    ),
    'access callback' => 'user_access',
    'access arguments' => array(
      'administer prettyphoto formatter',
    ),
  );
  return $items;
}

/**
 * Implements hook_theme().
 */
function prettyphoto_formatters_theme($existing, $type, $theme, $path) {
  $theme = array();
  $theme['prettyphoto_formatters_markup'] = array(
    'template' => 'templates/prettyphoto_formatters_markup',
  );
  $theme['prettyphoto_formatters_gallery_markup'] = array(
    'template' => 'templates/prettyphoto_formatters_gallery_markup',
  );
  $theme['prettyphoto_formatters_image_markup'] = array(
    'template' => 'templates/prettyphoto_formatters_image_markup',
  );
  $theme['prettyphoto_formatters_flash_markup'] = array(
    'template' => 'templates/prettyphoto_formatters_flash_markup',
  );
  $theme['prettyphoto_formatters_quicktime_markup'] = array(
    'template' => 'templates/prettyphoto_formatters_quicktime_markup',
  );
  $theme['prettyphoto_formatters_iframe_markup'] = array(
    'template' => 'templates/prettyphoto_formatters_iframe_markup',
  );
  $theme['prettyphoto_formatters_inline_markup'] = array(
    'template' => 'templates/prettyphoto_formatters_inline_markup',
  );
  $theme['prettyphoto_formatters_custom_markup'] = array(
    'template' => 'templates/prettyphoto_formatters_custom_markup',
  );
  $theme['prettyphoto_formatters_social_tools'] = array(
    'template' => 'templates/prettyphoto_formatters_social_tools',
  );
  return $theme;
}

/**
 * Create HTML output to override default markups.
 *
 * @param string $name
 *   Name of the markup want to override.
 *
 * @return string
 *   HTML output
 */
function _prettyphoto_formatters_get_tpl($name) {
  switch ($name) {
    case 'markup':
      $html = theme('prettyphoto_formatters_markup', array(
        'expand_title' => t('Expand the image'),
        'expand' => t('Expand'),
        'next' => t('Next'),
        'prev' => t('Previous'),
        'close' => t('Close'),
      ));
      break;
    case 'gallery_markup':
      $html = theme('prettyphoto_formatters_gallery_markup', array(
        'next' => t('Next'),
        'prev' => t('Previous'),
      ));
      break;
    case 'image_markup':
      $html = theme('prettyphoto_formatters_image_markup');
      break;
    case 'flash_markup':
      $html = theme('prettyphoto_formatters_flash_markup');
      break;
    case 'quicktime_markup':
      $html = theme('prettyphoto_formatters_quicktime_markup');
      break;
    case 'iframe_markup':
      $html = theme('prettyphoto_formatters_iframe_markup');
      break;
    case 'inline_markup':
      $html = theme('prettyphoto_formatters_inline_markup');
      break;
    case 'custom_markup':
      $html = theme('prettyphoto_formatters_custom_markup');
      break;
    case 'social_tools':
      $items = variable_get('prettyphoto_formatters_social_items', array());
      $items['tweet'] = t('Tweet');
      $html = theme('prettyphoto_formatters_social_tools', $items);
      break;
    default:
      $html = "";
      break;
  }
  return $html;
}