View source
<?php
define('ROYALSLIDER_VERSION', '9.4.92');
function royalslider_permission() {
return array(
'administer royalslider' => array(
'title' => t('Administer the RoyalSlider module'),
),
);
}
function royalslider_libraries_info() {
$libraries['royalslider'] = array(
'name' => 'RoyalSlider',
'vendor url' => 'http://dimsemenov.com/plugins/royal-slider/',
'download url' => 'http://dimsemenov.com/plugins/royal-slider/pricing/',
'version arguments' => array(
'file' => 'jquery.royalslider.min.js',
'pattern' => '/jquery.royalslider v(\\d+\\.+\\d+\\.+\\d+)/',
'lines' => 3,
),
'files' => array(
'js' => array(
'jquery.royalslider.min.js',
),
'css' => array(
'royalslider.css',
),
),
);
return $libraries;
}
function royalslider_libraries_info_alter(&$libraries) {
if (module_exists('jqeasing')) {
$libraries['royalslider']['dependencies'][] = 'easing (>=1.3)';
}
}
function royalslider_library() {
$library_path = libraries_get_path('royalslider');
$libraries['royalslider'] = array(
'title' => 'RoyalSlider',
'website' => 'http://dimsemenov.com/plugins/royal-slider/',
'version' => ROYALSLIDER_VERSION,
'js' => array(
$library_path . '/jquery.royalslider.min.js' => array(
'scope' => 'footer',
),
),
'css' => array(
$library_path . '/royalslider.css' => array(
'type' => 'file',
'media' => 'screen',
),
),
);
return $libraries;
}
function royalslider_theme($existing, $type, $theme, $path) {
return array(
'royalslider' => array(
'variables' => array(
'royalslider_id' => '',
'optionset' => 'default',
'skin' => '',
'items' => array(),
),
'path' => $path . '/theme',
'template' => 'royalslider',
'file' => 'royalslider.theme.inc',
),
'royalslider_item' => array(
'variables' => array(
'royalslider_id' => '',
'optionset' => 'default',
'item' => NULL,
),
'path' => $path . '/theme',
'template' => 'royalslider-item',
'file' => 'royalslider.theme.inc',
),
);
}
function royalslider_help($path, $arg) {
switch ($path) {
case 'admin/config/media/royalslider/edit/%':
return '<p>' . t('An <em>option set</em> defines exactly how a royalslider image gallery looks like on your site. ' . 'It is s a combination of <a href="@styles">image styles</a> for the various image sizes and RoyalSlider library options.', array(
'@styles' => url('admin/config/media/image-styles'),
)) . '<br />' . t('For a full documentation of all options, refer to the official @docs.', array(
'@docs' => l(t('RoyalSlider documentation'), 'http://dimsemenov.com/plugins/royal-slider/'),
)) . '</p>';
}
}
function royalslider_ctools_plugin_api($owner, $api) {
if ($owner == 'royalslider' && $api == 'royalslider_default_preset') {
return array(
'version' => 1,
);
}
}
function royalslider_ctools_plugin_directory($module, $type) {
if ($type == 'export_ui') {
return 'plugins/export_ui';
}
}
function royalslider_optionset_create($values = array()) {
ctools_include('export');
$optionset = ctools_export_crud_new('royalslider_optionset');
$optionset->options = array();
if (isset($values['name'])) {
$optionset->name = $values['name'];
}
if (isset($values['title'])) {
$optionset->title = $values['title'];
}
if (isset($values['skin'])) {
$optionset->skin = $values['skin'];
}
if (isset($values['imagestyle_fullscreen'])) {
$optionset->imagestyle_fullscreen = $values['imagestyle_fullscreen'];
}
if (isset($values['imagestyle_normal'])) {
$optionset->imagestyle_normal = $values['imagestyle_normal'];
}
if (isset($values['imagestyle_thumbnail'])) {
$optionset->imagestyle_thumbnail = $values['imagestyle_thumbnail'];
}
if (isset($values['options']) and is_array($values['options'])) {
$optionset->options = $values['options'];
}
$optionset_defaults = _royalslider_optionset_defaults();
$optionset->options = $optionset_defaults += $optionset->options;
return $optionset;
}
function royalslider_optionset_load_all() {
ctools_include('export');
$optionsets = ctools_export_crud_load_all('royalslider_optionset');
foreach ($optionsets as $optionset) {
_royalslider_typecast_optionset($optionset->options);
}
return $optionsets;
}
function royalslider_optionset_load($optionset_name) {
ctools_include('export');
$optionset = ctools_export_crud_load('royalslider_optionset', $optionset_name);
_royalslider_typecast_optionset($optionset->options);
return $optionset;
}
function royalslider_optionset_exists($optionset_name) {
ctools_include('export');
$optionset = ctools_export_crud_load('royalslider_optionset', $optionset_name);
return isset($optionset->name);
}
function royalslider_optionset_save($optionset, $new = FALSE) {
if (empty($optionset->name) or FALSE != royalslider_optionset_exists($optionset->name) and $new) {
return FALSE;
}
if (isset($optionset->options) and !is_array($optionset->options)) {
return FALSE;
}
if (empty($optionset->title)) {
$optionset->title = $optionset->name;
}
$optionset_defaults = _royalslider_optionset_defaults();
$optionset->options = $optionset_defaults += $optionset->options;
$db_values = array(
'name' => $optionset->name,
'title' => $optionset->title,
'options' => _royalslider_typecast_optionset($optionset->options),
);
if ($new) {
$result = drupal_write_record('royalslider_optionset', $db_values);
}
else {
$result = drupal_write_record('royalslider_optionset', $db_values, 'name');
}
if ($new and SAVED_NEW == $result or !$new and SAVED_UPDATED == $result) {
return $optionset;
}
return FALSE;
}
function royalslider_optionset_delete($optionset) {
if (isset($optionset->name)) {
$name = $optionset->name;
}
else {
$name = $optionset;
}
db_delete('royalslider_optionset')
->condition('name', $name)
->execute();
}
function _royalslider_optionset_defaults($key = NULL) {
$defaults = array(
'manuallyInit' => FALSE,
'loop' => FALSE,
'loopRewind' => FALSE,
'randomizeSlides' => FALSE,
'usePreloader' => TRUE,
'numImagesToPreload' => 4,
'slidesOrientation' => 'horizontal',
'globalCaption' => FALSE,
'fullscreen' => array(
'enabled' => FALSE,
'keyboardNav' => TRUE,
'buttonFS' => TRUE,
'nativeFS' => FALSE,
),
'controlNavigation' => 'bullets',
'controlsInside' => TRUE,
'sliderDrag' => TRUE,
'sliderTouch' => TRUE,
'keyboardNavEnabled' => FALSE,
'navigateByClick' => TRUE,
'arrowsNav' => TRUE,
'arrowsNavAutoHide' => TRUE,
'arrowsNavHideOnTouch' => FALSE,
'thumbs' => array(
'drag' => TRUE,
'touch' => TRUE,
'orientation' => 'horizontal',
'arrows' => TRUE,
'spacing' => 4,
'arrowsAutoHide' => FALSE,
'autoCenter' => TRUE,
'transitionSpeed' => 600,
'fitInViewport' => TRUE,
'firstMargin' => TRUE,
'arrowLeft' => NULL,
'arrowRight' => NULL,
'appendSpan' => FALSE,
),
'transitionType' => 'move',
'transitionSpeed' => 600,
'easeInOut' => 'easeInOutSine',
'easeOut' => 'easeOutSine',
'allowCSS3' => TRUE,
'addActiveClass' => FALSE,
'fadeinLoadedSlide' => TRUE,
'autoScaleSlider' => FALSE,
'autoScaleSliderWidth' => 800,
'autoScaleSliderHeight' => 400,
'autoHeight' => FALSE,
'imageScaleMode' => 'fit-if-smaller',
'imageScalePadding' => 4,
'imageAlignCenter' => TRUE,
'imgWidth' => NULL,
'imgHeight' => NULL,
'slidesSpacing' => 8,
'autoplay' => array(
'enabled' => FALSE,
'stopAtAction' => TRUE,
'pauseOnHover' => TRUE,
'delay' => 300,
),
'visibleNearby' => array(
'enabled' => TRUE,
'centerArea' => 0.6,
'center' => TRUE,
'navigateByCenterClick' => TRUE,
'breakpoint' => 0,
'breakpointCenterArea' => 0.8,
),
'deeplinking' => array(
'enabled' => FALSE,
'change' => FALSE,
'prefix' => '',
),
'video' => array(
'autoHideArrows' => TRUE,
'autoHideControlNav' => FALSE,
'autoHideBlocks' => FALSE,
'youTubeCode' => '<iframe src="http://www.youtube.com/embed/%id%?rel=1&autoplay=1&showinfo=0" frameborder="no"></iframe>',
'vimeoCode' => '<iframe src="http://player.vimeo.com/video/%id%?byline=0&portrait=0&autoplay=1" frameborder="no" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>',
),
'drupalAutoSetSliderDimensions' => FALSE,
'drupalAutoSetImageDimensions' => TRUE,
);
_royalslider_typecast_optionset($defaults);
if (isset($key) and array_key_exists($key, $defaults)) {
return $defaults[$key];
}
return $defaults;
}
function _royalslider_typecast_optionset(&$options) {
if (isset($options) && !empty($options)) {
foreach ($options as $key => $value) {
switch ($key) {
case 'slidesOrientation':
case 'controlNavigation':
case 'transitionType':
case 'easeInOut':
case 'easeOut':
case 'imageScaleMode':
$options[$key] = (string) $value;
break;
case 'numImagesToPreload':
case 'transitionSpeed':
case 'autoScaleSliderWidth':
case 'autoScaleSliderHeight':
case 'imageScalePadding':
case 'slidesSpacing':
$options[$key] = (int) $value;
break;
case 'manuallyInit':
case 'loop':
case 'loopRewind':
case 'randomizeSlides':
case 'usePreloader':
case 'globalCaption':
case 'controlsInside':
case 'sliderDrag':
case 'sliderTouch':
case 'keyboardNavEnabled':
case 'navigateByClick':
case 'arrowsNav':
case 'arrowsNavAutoHide':
case 'arrowsNavHideOnTouch':
case 'allowCSS3':
case 'addActiveClass':
case 'fadeinLoadedSlide':
case 'autoScaleSlider':
case 'autoHeight':
case 'imageAlignCenter':
case 'drupalAutoSetSliderDimensions':
case 'drupalAutoSetImageDimensions':
$options[$key] = (bool) $value;
break;
case 'imgWidth':
case 'imgHeight':
$options[$key] = empty($value) ? NULL : $value;
break;
case 'fullscreen':
foreach ($value as $k => $v) {
switch ($k) {
case 'enabled':
case 'keyboardNav':
case 'buttonFS':
case 'nativeFS':
$options['fullscreen'][$k] = (bool) $v;
break;
}
}
break;
case 'thumbs':
foreach ($value as $k => $v) {
switch ($k) {
case 'orientation':
$options['thumbs'][$k] = (string) $v;
break;
case 'spacing':
case 'transitionSpeed':
$options['thumbs'][$k] = (int) $v;
break;
case 'drag':
case 'touch':
case 'arrows':
case 'arrowsAutoHide':
case 'autoCenter':
case 'fitInViewport':
case 'firstMargin':
case 'appendSpan':
$options['thumbs'][$k] = (bool) $v;
break;
case 'arrowLeft':
case 'arrowRight':
$options['thumbs'][$k] = empty($v) ? NULL : $v;
break;
}
}
break;
case 'autoplay':
foreach ($value as $k => $v) {
switch ($k) {
case 'enabled':
case 'stopAtAction':
case 'pauseOnHover':
$options['autoplay'][$k] = (bool) $v;
break;
case 'delay':
$options['autoplay'][$k] = (int) $v;
break;
}
}
break;
case 'visibleNearby':
foreach ($value as $k => $v) {
switch ($k) {
case 'enabled':
case 'center':
case 'navigateByCenterClick':
$options['visibleNearby'][$k] = (bool) $v;
break;
case 'centerArea':
case 'breakpoint':
case 'breakpointCenterArea':
$options['visibleNearby'][$k] = (double) $v;
break;
}
}
break;
case 'deeplinking':
foreach ($value as $k => $v) {
switch ($k) {
case 'enabled':
case 'change':
$options['deeplinking'][$k] = (bool) $v;
break;
case 'prefix':
$options['deeplinking'][$k] = (string) $v;
break;
}
}
break;
case 'video':
foreach ($value as $k => $v) {
switch ($k) {
case 'autoHideArrows':
case 'autoHideControlNav':
case 'autoHideBlocks':
$options['video'][$k] = (bool) $v;
break;
case 'youTubeCode':
case 'vimeoCode':
$options['video'][$k] = (string) $v;
break;
}
}
break;
}
}
}
}
function _royalslider_jqeasing_options() {
$easing_methods =& drupal_static(__FUNCTION__);
if (!isset($easing_methods)) {
$easing_methods = array(
'jswing',
'def',
'easeInQuad',
'easeOutQuad',
'easeInOutQuad',
'easeInCubic',
'easeOutCubic',
'easeInOutCubic',
'easeInQuart',
'easeOutQuart',
'easeInOutQuart',
'easeInQuint',
'easeOutQuint',
'easeInOutQuint',
'easeInSine',
'easeOutSine',
'easeInOutSine',
'easeInExpo',
'easeOutExpo',
'easeInOutExpo',
'easeInCirc',
'easeOutCirc',
'easeInOutCirc',
'easeInElastic',
'easeOutElastic',
'easeInOutElastic',
'easeInBack',
'easeOutBack',
'easeInOutBack',
'easeInBounce',
'easeOutBounce',
'easeInOutBounce',
);
drupal_alter('royalslider_easing', $easing_methods);
$easing_methods = drupal_map_assoc($easing_methods);
}
return $easing_methods;
}
function royalslider_add($id = NULL, $optionset = NULL, $skin = '') {
if (is_string($optionset)) {
if (!($optionset = royalslider_optionset_load($optionset))) {
watchdog('royalslider', 'Invalid optionset name supplied to royalslider_add: @name', array(
'@name' => $name,
), WATCHDOG_WARNING);
return;
}
}
if (!empty($id) && !empty($optionset)) {
$js_options = _royalslider_remove_default_optionset_options($optionset->options);
$js_settings = array(
'optionsets' => array(
$optionset->name => $js_options,
),
'instances' => array(
$id => array(
'optionset' => $optionset->name,
),
),
);
drupal_alter('royalslider_settings', $js_settings, $id, $optionset);
drupal_add_js(array(
'royalslider' => $js_settings,
), 'setting');
}
libraries_load('royalslider');
$loaded =& drupal_static(__FUNCTION__, array());
if (empty($skin)) {
$skin = !empty($optionset) ? $optionset->skin : 'default';
}
if (!array_key_exists($skin, $loaded)) {
drupal_add_css(libraries_get_path('royalslider') . "/skins/{$skin}/rs-{$skin}.css");
$loaded[] = $skin;
}
if (!array_key_exists('royalslider.load', $loaded)) {
drupal_add_js(drupal_get_path('module', 'royalslider') . '/js/royalslider.load.js', array(
'type' => 'file',
'scope' => 'footer',
));
$loaded[] = 'royalslider.load';
}
}
function royalslider_skins() {
$skins =& drupal_static(__FUNCTION__, NULL);
if (!isset($skins)) {
$skins = array(
'default' => array(
'name' => t('Default'),
'class' => 'rsDefault',
),
'default-inverted' => array(
'name' => t('Default inverted'),
'class' => 'rsDefaultInv',
),
'minimal-white' => array(
'name' => t('Minimal white'),
'class' => 'rsMinW',
),
'universal' => array(
'name' => t('Universal'),
'class' => 'rsUni',
),
);
drupal_alter('royalslider_skins', $skins);
}
return $skins;
}
function _royalslider_optionsets() {
$optionsets = array();
foreach (royalslider_optionset_load_all() as $name => $info) {
$optionsets[$name] = $info->title;
}
return $optionsets;
}
function _royalslider_skins() {
$skins = array(
'' => t('Use Option Set skin'),
);
foreach (royalslider_skins() as $name => $info) {
$skins[$name] = $info['name'];
}
return $skins;
}
function royalslider_field_formatter_info() {
$return = array();
$return['royalslider'] = array(
'label' => t('Royalslider'),
'description' => t('Display images in a RoyalSlider slideshow.'),
'field types' => array(
'image',
),
'settings' => array(
'optionset' => 'default',
'skin' => '',
'max' => '#',
),
);
return $return;
}
function royalslider_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$element = array();
switch ($display['type']) {
case 'royalslider':
$element['optionset'] = array(
'#title' => t('Option Set'),
'#description' => t('All RoyalSlider settings are stored in Option Sets.'),
'#type' => 'select',
'#options' => _royalslider_optionsets(),
'#default_value' => $settings['optionset'],
);
$element['skin'] = array(
'#title' => t('Skin'),
'#description' => t('Override the Option Set\'s skin.'),
'#type' => 'select',
'#options' => _royalslider_skins(),
'#default_value' => $settings['skin'],
);
$element['max'] = array(
'#title' => t('Max Images'),
'#description' => t('Limit the number of images displayed.'),
'#type' => 'textfield',
'#size' => 3,
'#default_value' => $settings['max'],
);
break;
}
return $element;
}
function royalslider_field_formatter_settings_summary($field, $instance, $view_mode) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$return = array();
switch ($display['type']) {
case 'royalslider':
$optionsets = _royalslider_optionsets();
$return[] = t('Option Set: @optionset', array(
'@optionset' => $optionsets[$settings['optionset']],
));
if (!empty($settings['skin'])) {
$skins = _royalslider_skins();
$return[] = t('Skin override: @skin', array(
'@skin' => $skins[$settings['skin']],
));
}
$return[] = t('Max Images: @max', array(
'@max' => $settings['max'],
));
break;
}
return implode('<br />', $return);
}
function royalslider_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, &$items, $display) {
$settings = $display['settings'];
$element = array();
switch ($display['type']) {
case 'royalslider':
list($id, , $bundle) = entity_extract_ids($entity_type, $entity);
$images = $settings['max'] === '#' ? $items : array_slice($items, 0, $settings['max']);
$element[0] = array(
'#theme' => 'royalslider',
'#royalslider_id' => "royalslider-{$entity_type}-{$bundle}-{$instance['field_name']}-{$id}",
'#optionset' => $settings['optionset'],
'#skin' => $settings['skin'],
'#items' => $images,
);
break;
}
return $element;
}
function _royalslider_remove_default_optionset_options($options) {
$defaults = _royalslider_optionset_defaults();
foreach ($options as $key => $value) {
if (array_key_exists($key, $defaults)) {
if (is_array($value)) {
foreach ($value as $k => $v) {
if ($k === 'enabled' && $v === FALSE) {
unset($options[$key]);
if ($key === 'visibleNearby') {
$options[$key][$k] = $v;
}
}
else {
if ($key === 'visibleNearby' && $k === 'enabled' && $v === TRUE) {
}
else {
if ($v === $defaults[$key][$k]) {
unset($options[$key][$k]);
}
}
}
}
if ($key === 'thumbs') {
if (!isset($options['controlNavigation']) || $options['controlNavigation'] !== 'thumbnails') {
unset($options[$key]);
}
}
}
else {
if ($value === $defaults[$key]) {
unset($options[$key]);
}
}
}
}
return $options;
}