Same filename and directory in other branches
  1. 5.0.x views_slideshow.module
  2. 8.x-3.x views_slideshow.module
  3. 8.x-4.x views_slideshow.module

Provides Slideshow style options for Views.

Fichier

./views_slideshow.module

View source
<?php


/**
 * @file
 * Provides Slideshow style options for Views.
 */

/**
 * Implements hook_theme().
 */
function views_slideshow_theme($existing, $type, $theme, $path) {
    return array(
        'views_slideshow_main_section' => array(
            'variables' => array(
                'vss_id' => NULL,
                'slides' => NULL,
                'plugin' => NULL,
            ),
            'file' => 'theme/views_slideshow.theme.inc',
            'pattern' => 'views_slideshow_main_section__',
        ),
        'views_slideshow_pager_widget_render' => array(
            'variables' => array(
                'vss_id' => NULL,
                'view' => NULL,
                'settings' => array(),
                'location' => NULL,
                'rows' => array(),
            ),
            'file' => 'theme/views_slideshow.theme.inc',
            'pattern' => 'views_slideshow_pager_widget_render__',
        ),
        'views_slideshow_pager_fields' => array(
            'variables' => array(
                'vss_id' => NULL,
                'view' => NULL,
                'settings' => array(),
                'location' => NULL,
                'attributes' => array(),
            ),
            'template' => 'theme/views-slideshow-pager-fields',
            'file' => 'theme/views_slideshow.theme.inc',
            'pattern' => 'views_slideshow_pager_fields__',
        ),
        'views_slideshow_pager_field_field' => array(
            'variables' => array(
                'view' => NULL,
                'field' => NULL,
                'count' => NULL,
            ),
            'template' => 'theme/views-slideshow-pager-field-field',
            'file' => 'theme/views_slideshow.theme.inc',
            'pattern' => 'views_slideshow_pager_field_field__',
        ),
        'views_slideshow_pager_field_item' => array(
            'variables' => array(
                'vss_id' => NULL,
                'item' => NULL,
                'count' => NULL,
                'location' => NULL,
                'length' => NULL,
            ),
            'template' => 'theme/views-slideshow-pager-field-item',
            'file' => 'theme/views_slideshow.theme.inc',
            'pattern' => 'views_slideshow_pager_field_item__',
        ),
        'views_slideshow_controls_widget_render' => array(
            'variables' => array(
                'vss_id' => NULL,
                'view' => NULL,
                'settings' => array(),
                'location' => NULL,
                'rows' => array(),
            ),
            'file' => 'theme/views_slideshow.theme.inc',
            'pattern' => 'views_slideshow_controls_widget_render__',
        ),
        'views_slideshow_controls_text' => array(
            'variables' => array(
                'vss_id' => NULL,
                'view' => NULL,
                'settings' => array(),
                'location' => NULL,
                'rows' => array(),
            ),
            'template' => 'theme/views-slideshow-controls-text',
            'file' => 'theme/views_slideshow.theme.inc',
            'pattern' => 'views_slideshow_controls_text__',
        ),
        'views_slideshow_controls_text_previous' => array(
            'variables' => array(
                'vss_id' => NULL,
                'view' => NULL,
                'settings' => array(),
            ),
            'template' => 'theme/views-slideshow-controls-text-previous',
            'file' => 'theme/views_slideshow.theme.inc',
            'pattern' => 'views_slideshow_controls_text_previous__',
        ),
        'views_slideshow_controls_text_pause' => array(
            'variables' => array(
                'vss_id' => NULL,
                'view' => NULL,
                'settings' => array(),
            ),
            'template' => 'theme/views-slideshow-controls-text-pause',
            'file' => 'theme/views_slideshow.theme.inc',
            'pattern' => 'views_slideshow_controls_text_pause__',
        ),
        'views_slideshow_controls_text_next' => array(
            'variables' => array(
                'vss_id' => NULL,
                'view' => NULL,
                'settings' => array(),
            ),
            'template' => 'theme/views-slideshow-controls-text-next',
            'file' => 'theme/views_slideshow.theme.inc',
            'pattern' => 'views_slideshow_controls_text_next__',
        ),
        'views_slideshow_slide_counter_widget_render' => array(
            'variables' => array(
                'vss_id' => NULL,
                'view' => NULL,
                'settings' => array(),
                'location' => NULL,
                'rows' => array(),
            ),
            'file' => 'theme/views_slideshow.theme.inc',
            'pattern' => 'views_slideshow_counter_widget_render__',
        ),
        'views_slideshow_slide_counter' => array(
            'variables' => array(
                'vss_id' => NULL,
                'view' => NULL,
                'settings' => array(),
                'location' => NULL,
                'rows' => array(),
            ),
            'template' => 'theme/views-slideshow-slide-counter',
            'file' => 'theme/views_slideshow.theme.inc',
            'pattern' => 'views_slideshow_slide_counter__',
        ),
    );
}

/**
 * Implements hook_views_api().
 */
function views_slideshow_views_api() {
    return array(
        'api' => '3',
    );
}

/**
 * Implements hook_help().
 */
function views_slideshow_help($path, $arg) {
    switch ($path) {
        case 'admin/help#views_slideshow':
            return '<p>Check the Views Slideshow project page documentation for tutorials and videos on how to use this module.</p>';
    }
}

/**
 * Implements hook_library().
 */
function views_slideshow_library() {
    $libraries = array();
    $libraries['views_slideshow'] = array(
        'title' => 'Views slideshow',
        'version' => '1.0',
        'js' => array(
            drupal_get_path('module', 'views_slideshow') . '/js/views_slideshow.js' => array(),
        ),
        'css' => array(
            drupal_get_path('module', 'views_slideshow') . '/views_slideshow.css' => array(),
        ),
    );
    return $libraries;
}

/**
 * Implements hook_views_slideshow_skin_info().
 */
function views_slideshow_views_slideshow_skin_info() {
    return array(
        'default' => array(
            'name' => t('Default'),
        ),
    );
}

/**
 * Implements hook_views_slideshow_widget_info().
 */
function views_slideshow_views_slideshow_widget_info() {
    return array(
        'views_slideshow_pager' => array(
            'name' => t('Pager'),
            'accepts' => array(
                'transitionBegin' => array(
                    'required' => TRUE,
                ),
                'goToSlide' => array(),
                'previousSlide' => array(),
                'nextSlide' => array(),
            ),
            'calls' => array(
                'goToSlide',
                'pause',
                'play',
            ),
        ),
        'views_slideshow_controls' => array(
            'name' => t('Controls'),
            'accepts' => array(
                'pause' => array(
                    'required' => TRUE,
                ),
                'play' => array(
                    'required' => TRUE,
                ),
            ),
            'calls' => array(
                'nextSlide',
                'pause',
                'play',
                'previousSlide',
            ),
        ),
        'views_slideshow_slide_counter' => array(
            'name' => t('Slide Counter'),
            'accepts' => array(
                'transitionBegin' => array(
                    'required' => TRUE,
                ),
                'goToSlide' => array(),
                'previousSlide' => array(),
                'nextSlide' => array(),
            ),
            'calls' => array(),
        ),
    );
}

/**
 * Implements [widget]_views_slideshow_widget_form_options().
 */
function views_slideshow_pager_views_slideshow_widget_form_options(&$form, &$form_state, &$view, $defaults, $dependency) {
    // Get all the pager info from other modules.
    $pagers = module_invoke_all('views_slideshow_widget_pager_info', $view);
    if (!empty($pagers)) {
        $pager_options = array();
        foreach ($pagers as $pager_id => $pager_info) {
            $pager_options[$pager_id] = $pager_info['name'];
        }
        asort($pager_options);
        // Need to wrap this so it indents correctly.
        $form['views_slideshow_pager_wrapper'] = array(
            '#markup' => '<div class="vs-dependent">',
        );
        // Option for master_pager to control all slideshows in this location.
        $form['master_pager'] = array(
            '#type' => 'checkbox',
            '#title' => t('Master Pager'),
            '#default_value' => $defaults['master_pager'],
            '#description' => t('Should this pager control all slideshows in this location.'),
            '#states' => array(
                'visible' => array(
                    ':input[name="' . $dependency . '[enable]"]' => array(
                        'checked' => TRUE,
                    ),
                ),
            ),
        );
        // Add field to see if they would like to hide pager if there is only one
        // slide.
        $form['hide_on_single_slide'] = array(
            '#type' => 'checkbox',
            '#title' => t('Hide pager if there is only one slide'),
            '#default_value' => $defaults['hide_on_single_slide'],
            '#description' => t('Should the pager be hidden if there is only one slide.'),
            '#states' => array(
                'visible' => array(
                    ':input[name="' . $dependency . '[enable]"]' => array(
                        'checked' => TRUE,
                    ),
                ),
            ),
        );
        // Create the widget type field.
        $form['type'] = array(
            '#type' => 'select',
            '#title' => t('Pager Type'),
            '#description' => t('Style of the pager'),
            '#default_value' => $defaults['type'],
            '#options' => $pager_options,
            '#states' => array(
                'visible' => array(
                    ':input[name="' . $dependency . '[enable]"]' => array(
                        'checked' => TRUE,
                    ),
                ),
            ),
        );
        // Add any additional form elements
        // Build our arguments to pass to
        // [pager-type]_views_slideshow_widget_pager_form_options.
        $arguments = array(
            &$form,
            &$form_state,
            &$view,
            $defaults,
            $dependency,
        );
        foreach ($pagers as $pager_key => $pager_info) {
            $function = $pager_key . '_views_slideshow_widget_pager_form_options';
            if (function_exists($function)) {
                call_user_func_array($function, $arguments);
            }
        }
        $form['views_slideshow_pager_wrapper_close'] = array(
            '#markup' => '</div>',
        );
    }
    else {
        $form['enable_pager'] = array(
            '#markup' => 'There are no pagers available.',
        );
    }
}

/**
 * Callback for preg_replace_callback.
 *
 * @see views_slideshow_format_addons_name()
 */
function _views_slideshow_get_preg_strtoupper_callback($matches) {
    if (isset($matches[1])) {
        return strtoupper($matches[1]);
    }
}

/**
 * PHP5.x preg_replace_callback() method.
 */
function views_slideshow_format_addons_name($subject) {
    return preg_replace_callback('/_(.?)/', '_views_slideshow_get_preg_strtoupper_callback', $subject);
}

/**
 * Implements hook_views_slideshow_widget_pager_info().
 */
function views_slideshow_views_slideshow_widget_pager_info($view) {
    $settings = array();
    // Settings for fields pager.
    // First verfiy that the view is using fields.
    if ($view->row_plugin
        ->uses_fields()) {
        $settings = array(
            'views_slideshow_pager_fields' => array(
                'name' => t('Fields'),
            ),
        );
    }
    return $settings;
}

/**
 * Implements [widget-type]_views_slideshow_pager_form_options().
 */
function views_slideshow_pager_fields_views_slideshow_widget_pager_form_options(&$form, &$form_state, &$view, $defaults, $dependency) {
    // Settings for fields pager.
    $options = array();
    // Get each field and it's name.
    foreach ($view->display->handler
        ->get_handlers('field') as $field => $handler) {
        $options[$field] = $handler->ui_name();
    }
    // Need to wrap this so it indents correctly.
    $form['views_slideshow_pager_fields_wrapper'] = array(
        '#markup' => '<div class="vs-dependent">',
    );
    // Add ability to choose which fields to show in the pager.
    $form['views_slideshow_pager_fields_fields'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Pager fields'),
        '#options' => $options,
        '#default_value' => $defaults['views_slideshow_pager_fields_fields'],
        '#description' => t("Choose the fields that will appear in the pager."),
        '#process' => array(
            'form_process_checkboxes',
        ),
        '#states' => array(
            'visible' => array(
                ':input[name="' . $dependency . '[enable]"]' => array(
                    'checked' => TRUE,
                ),
                ':input[name="' . $dependency . '[type]"]' => array(
                    'value' => 'views_slideshow_pager_fields',
                ),
            ),
        ),
    );
    // Add field to see if they would like to activate slide and pause on pager
    // hover.
    $form['views_slideshow_pager_fields_hover'] = array(
        '#type' => 'checkbox',
        '#title' => t('Activate Slide and Pause on Pager Hover'),
        '#default_value' => $defaults['views_slideshow_pager_fields_hover'],
        '#description' => t('Should the slide be activated and paused when hovering over a pager item.'),
        '#states' => array(
            'visible' => array(
                ':input[name="' . $dependency . '[enable]"]' => array(
                    'checked' => TRUE,
                ),
                ':input[name="' . $dependency . '[type]"]' => array(
                    'value' => 'views_slideshow_pager_fields',
                ),
            ),
        ),
    );
    $form['views_slideshow_pager_fields_wrapper_close'] = array(
        '#markup' => '</div>',
    );
}

/**
 * Implements [widget]_views_slideshow_widget_form_options().
 */
function views_slideshow_controls_views_slideshow_widget_form_options(&$form, &$form_state, &$view, $defaults, $dependency) {
    // Get all the control info from other modules.
    $controls = module_invoke_all('views_slideshow_widget_controls_info', $view);
    if (!empty($controls)) {
        $control_type_options = array();
        foreach ($controls as $control_id => $control_info) {
            $control_type_options[$control_id] = $control_info['name'];
        }
        asort($control_type_options);
        // Need to wrap this so it indents correctly.
        $form['views_slideshow_controls_wrapper'] = array(
            '#markup' => '<div class="vs-dependent">',
        );
        // Add field to see if they would like to hide controls if there is only one
        // slide.
        $form['hide_on_single_slide'] = array(
            '#type' => 'checkbox',
            '#title' => t('Hide controls if there is only one slide'),
            '#default_value' => $defaults['hide_on_single_slide'],
            '#description' => t('Should the controls be hidden if there is only one slide.'),
            '#states' => array(
                'visible' => array(
                    ':input[name="' . $dependency . '[enable]"]' => array(
                        'checked' => TRUE,
                    ),
                ),
            ),
        );
        // Create the widget type field.
        $form['type'] = array(
            '#type' => 'select',
            '#title' => t('Controls Type'),
            '#description' => t('Style of the controls'),
            '#default_value' => $defaults['type'],
            '#options' => $control_type_options,
            '#states' => array(
                'visible' => array(
                    ':input[name="' . $dependency . '[enable]"]' => array(
                        'checked' => TRUE,
                    ),
                ),
            ),
        );
        // Add any additional form elements
        // Build our arguments to pass to
        // [pager-type]_views_slideshow_widget_pager_form_options.
        $arguments = array(
            &$form,
            &$form_state,
            &$view,
            $defaults,
            $dependency,
        );
        foreach ($controls as $control_key => $control_info) {
            $function = $control_key . '_views_slideshow_widget_controls_form_options';
            if (function_exists($function)) {
                call_user_func_array($function, $arguments);
            }
        }
        $form['controls_wrapper_close'] = array(
            '#markup' => '</div>',
        );
    }
    else {
        $form['enable_controls'] = array(
            '#markup' => 'There are no controls available.',
        );
    }
}

/**
 * Implements hook_views_slideshow_controls_info().
 */
function views_slideshow_views_slideshow_widget_controls_info($view) {
    return array(
        'views_slideshow_controls_text' => array(
            'name' => t('Text'),
        ),
    );
}

/**
 * Implements hook_views_slideshow_option_definition().
 */
function views_slideshow_views_slideshow_option_definition() {
    // Default slideshow type and skins.
    $options['slideshow_type'] = array(
        'default' => '',
    );
    $options['slideshow_skin'] = array(
        'default' => '',
    );
    $options['skin_info'] = array(
        'default' => array(
            'class' => 'default',
            'name' => t('Untitled skin'),
            'module' => 'views_slideshow',
            'path' => '',
            'stylesheets' => array(),
        ),
    );
    // Set default widgets and weight values.
    $widgets = module_invoke_all('views_slideshow_widget_info');
    if ($widgets) {
        $locations = array(
            'top',
            'bottom',
        );
        foreach ($locations as $location) {
            foreach ($widgets as $widget_id => $widget_name) {
                $options['widgets']['contains'][$location]['contains'][$widget_id]['contains']['enable'] = array(
                    'default' => 0,
                );
                $options['widgets']['contains'][$location]['contains'][$widget_id]['contains']['weight'] = array(
                    'default' => 1,
                );
            }
        }
    }
    // Defaults for the pager widget.
    foreach ($locations as $location) {
        $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['master_pager'] = array(
            'default' => 0,
        );
        $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['hide_on_single_slide'] = array(
            'default' => 0,
        );
        $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['type'] = array(
            'default' => 0,
        );
        $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_numbered_hover'] = array(
            'default' => 0,
        );
        $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_numbered_click_to_page'] = array(
            'default' => 0,
        );
        $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_thumbnails_hover'] = array(
            'default' => 0,
        );
        $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_thumbnails_click_to_page'] = array(
            'default' => 0,
        );
        $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_fields_fields'] = array(
            'default' => array(),
        );
        $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_fields_hover'] = array(
            'default' => 0,
        );
        $options['widgets']['contains'][$location]['contains']['views_slideshow_controls']['contains']['hide_on_single_slide'] = array(
            'default' => 0,
        );
        $options['widgets']['contains'][$location]['contains']['views_slideshow_controls']['contains']['type'] = array(
            'default' => 0,
        );
    }
    return $options;
}

Functions

Titre Deprecated Résumé
views_slideshow_controls_views_slideshow_widget_form_options Implements [widget]_views_slideshow_widget_form_options().
views_slideshow_format_addons_name PHP5.x preg_replace_callback() method.
views_slideshow_help Implements hook_help().
views_slideshow_library Implements hook_library().
views_slideshow_pager_fields_views_slideshow_widget_pager_form_options Implements [widget-type]_views_slideshow_pager_form_options().
views_slideshow_pager_views_slideshow_widget_form_options Implements [widget]_views_slideshow_widget_form_options().
views_slideshow_theme Implements hook_theme().
views_slideshow_views_api Implements hook_views_api().
views_slideshow_views_slideshow_option_definition Implements hook_views_slideshow_option_definition().
views_slideshow_views_slideshow_skin_info Implements hook_views_slideshow_skin_info().
views_slideshow_views_slideshow_widget_controls_info Implements hook_views_slideshow_controls_info().
views_slideshow_views_slideshow_widget_info Implements hook_views_slideshow_widget_info().
views_slideshow_views_slideshow_widget_pager_info Implements hook_views_slideshow_widget_pager_info().
_views_slideshow_get_preg_strtoupper_callback Callback for preg_replace_callback.