View source
<?php
require_once dirname(__FILE__) . '/includes/lightgallery.field.inc';
function lightgallery_help($path, $arg) {
switch ($path) {
case 'admin/help#lightgallery':
$output = file_get_contents(drupal_get_path('module', 'lightgallery') . '/README.txt');
return '<pre>' . check_plain($output) . '</pre>';
}
}
function lightgallery_libraries_info() {
$libraries['lightgallery'] = array(
'name' => 'Lightgallery',
'vendor url' => 'http://sachinchoolur.github.io/lightGallery/',
'download url' => 'https://github.com/sachinchoolur/lightGallery',
'path' => 'dist',
'version arguments' => array(
'file' => 'dist/js/lightgallery.min.js',
'pattern' => '/- v(1.2.*)/',
'lines' => 5,
),
'files' => array(
'js' => array(
'js/lightgallery.min.js',
'js/lg-autoplay.min.js',
'js/lg-fullscreen.min.js',
'js/lg-thumbnail.min.js',
'js/lg-video.min.js',
'js/lg-zoom.min.js',
'js/lg-hash.min.js',
),
'css' => array(
'css/lightgallery.min.css',
'css/lg-transitions.min.css',
),
),
);
return $libraries;
}
function lightgallery_views_api() {
return array(
'api' => 3.0,
'path' => drupal_get_path('module', 'lightgallery') . '/views',
);
}
function lightgallery_theme() {
return array(
'lightgallery_image_formatter' => array(
'variables' => array(
'items' => NULL,
'entity_type' => NULL,
'entity' => NULL,
'node' => NULL,
'field' => array(),
'display_settings' => array(),
),
'file' => 'includes/lightgallery.theme.inc',
),
'lightgallery_item_list' => array(
'variables' => array(
'items' => array(),
'unque_id' => NULL,
),
'path' => drupal_get_path('module', 'lightgallery') . '/templates',
'template' => 'lightgallery-item-list',
),
);
}
function template_preprocess_lightgallery_view(&$vars) {
$view = $vars['view'];
$result = $vars['rows'];
$vars['rows'] = array();
$options = $view->style_plugin->options['lightgallery'];
$fields =& $view->field;
$handler = $view->style_plugin;
$rendered_rows = $handler
->render_fields($result);
$thumb_field = $options['thumb_field'];
$image_field = $options['image_field'];
$title_field = $options['title'];
foreach ($rendered_rows as $num => $row) {
$rendered_slide = FALSE;
$rendered_thumb = FALSE;
$rendered_title = FALSE;
foreach ($row as $field_name => $field) {
if ($field_name == $thumb_field) {
$rendered_thumb = $field;
}
if ($field_name == $image_field) {
$rendered_slide = $field;
}
if ($field_name == $title_field) {
$rendered_title = $field;
}
$vars['field_labels'][$num] = $fields[$field_name]
->label();
}
$vars['rows'][$num]['slide'] = $rendered_slide;
$vars['rows'][$num]['thumb'] = $rendered_thumb;
$vars['rows'][$num]['title'] = $rendered_title;
$vars['row_styles'][$num] = 'display: block;';
}
$unique_id = uniqid();
$vars['id'] = $unique_id;
$option_set = _lightgallery_build_option_set($options);
lightgallery_add($unique_id, $option_set);
}
function lightgallery_add($id = NULL, $option_set = NULL) {
if (!($library = libraries_load('lightgallery')) || empty($library['loaded'])) {
drupal_set_message(t('Lightgallery library was not found.'), 'error');
return FALSE;
}
if (!empty($id) && !empty($option_set)) {
$js_settings = array(
'instances' => array(
$id => $option_set,
),
);
drupal_add_js(array(
'lightgallery' => $js_settings,
), 'setting');
drupal_add_js(drupal_get_path('module', 'lightgallery') . '/js/lightgallery_load.js', array(
'type' => 'file',
'scope' => 'footer',
));
}
}
function _lightgallery_build_option_set($options) {
$option_set = array(
'mode' => !empty($options['mode']) ? $options['mode'] : 'lg-slide',
'preload' => !empty($options['preload']) ? $options['preload'] : 1,
'loop' => !empty($options['loop']) ? TRUE : FALSE,
'closable' => !empty($options['closable']) ? TRUE : FALSE,
'escKey' => !empty($options['esc_key']) ? TRUE : FALSE,
'keyPress' => !empty($options['key_press']) ? TRUE : FALSE,
'contols' => !empty($options['contols']) ? TRUE : FALSE,
'mousewheel' => !empty($options['mouse_wheel']) ? TRUE : FALSE,
'download' => !empty($options['download']) ? TRUE : FALSE,
'counter' => !empty($options['counter']) ? TRUE : FALSE,
'enableDrag' => !empty($options['drag']) ? TRUE : FALSE,
'enableTouch' => !empty($options['touch']) ? TRUE : FALSE,
'thumbnail' => !empty($options['thumbnails']) ? TRUE : FALSE,
'autoplay' => !empty($options['autoplay']) ? TRUE : FALSE,
'fullScreen' => !empty($options['full_screen']) ? TRUE : FALSE,
'pager' => !empty($options['pager']) ? TRUE : FALSE,
'zoom' => !empty($options['zoom']) ? TRUE : FALSE,
'hash' => !empty($options['hash']) ? TRUE : FALSE,
'selector' => !empty($options['selector']) ? $options['selector'] : FALSE,
);
if ($option_set['thumbnail']) {
$option_set['animateThumb'] = !empty($options['animate_thumb']) ? TRUE : FALSE;
$option_set['currentPagerPosition'] = !empty($options['current_pager_position']) ? $options['current_pager_position'] : 'middle';
$option_set['thumbWidth'] = !empty($options['thumb_width']) ? $options['thumb_width'] : 100;
$option_set['thumbContHeight'] = !empty($options['thumb_cont_height']) ? $options['thumb_cont_height'] : 100;
}
if ($option_set['autoplay']) {
$option_set['pause'] = !empty($options['pause']) ? $options['pause'] : 5000;
$option_set['progressBar'] = !empty($options['progress_bar']) ? TRUE : FALSE;
$option_set['autoplayControls'] = !empty($options['autoplay_controls']) ? TRUE : FALSE;
}
if ($option_set['zoom']) {
$option_set['scale'] = !empty($options['scale']) ? $options['scale'] : 1;
}
if ($option_set['hash']) {
$option_set['galleryId'] = !empty($options['gallery_id']) ? $options['gallery_id'] : 1;
}
if ($option_set['selector']) {
$option_set['selector'] = !empty($options['selector']) ? $options['selector'] : FALSE;
}
return $option_set;
}
function _lightgallery_get_modes() {
return drupal_map_assoc(array(
'lg-slide',
'lg-fade',
'lg-zoom-in',
'lg-zoom-in-big',
'lg-zoom-out',
'lg-zoom-out-big',
'lg-zoom-out-in',
'lg-zoom-in-out',
'lg-soft-zoom',
'lg-scale-up',
'lg-slide-circular',
'lg-slide-circular-vertical',
'lg-slide-vertical',
'lg-slide-vertical-growth',
'lg-slide-skew-only',
'lg-slide-skew-only-rev',
'lg-slide-skew-only-y',
'lg-slide-skew-only-y-rev',
'lg-slide-skew',
'lg-slide-skew-rev',
'lg-slide-skew-cross',
'lg-slide-skew-cross-rev',
'lg-slide-skew-ver',
'lg-slide-skew-ver-rev',
'lg-slide-skew-ver-cross',
'lg-slide-skew-ver-cross-rev',
'lg-lollipop',
'lg-lollipop-rev',
'lg-rotate',
'lg-rotate-rev',
'lg-tube',
));
}