<?php
/**
 * @author Bruno Massa http://drupal.org/user/67164
 * @file
 * Create slideshows using any image on the internet with many other features.
 *
 * @note only hooks are here. For other function see slideshow_creator.inc
 */


/**
 * Implements hook_init().
 */
function slideshow_creator_init() {
  // Add the CSS file
  drupal_add_css(
    drupal_get_path('module', 'slideshow_creator') . '/slideshow_creator.css'
  );

  // Add the main JavaScript, that does all the magic
  drupal_add_js(
    drupal_get_path('module', 'slideshow_creator') . '/slideshow_creator.js',
    array(
      'type' => 'file',
      'scope' => 'header',
    )
  );
  drupal_add_library('jquery_plugin', 'cycle');
}

/**
 * Implements hook_element_info().
 *
 * Any FAPI callbacks needed for individual widgets can be declared here,
 * and the element will be passed to those callbacks for processing.
 *
 * Drupal will automatically theme the element using a theme with
 * the same name as the hook_element_info key.
 *
 * Autocomplete_path is not used by text_widget but other widgets can use it
 * (see nodereference and userreference).
 */
function slideshow_creator_element_info() {
  return array(
    'slideshow_creator' => array(
      '#input'              => TRUE,
      '#columns'            => array('value'),
      '#delta'              => 0,
      '#process'            => array('slideshow_creator_process'),
      ),
    'slideshow_creator_form' => array(
      '#input'              => TRUE,
      '#columns'            => array('ssc'),
      '#delta'              => 0,
      '#element_validate'   => array('_slideshow_creator_form_validate'),
      '#process'            => array('_slideshow_creator_form_process'),
      ),
  );
}

/**
 * Callback to connect to the main user hook to display a slideshow.
 */
function _slideshow_creator_filter_insert_slideshow(
  $text, $filter, $format, $langcode, $cache, $cache_id
) {
  include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'slideshow_creator') .
      '/slideshow_creator.inc';
  return _slideshow_creator_process_text($text);
}

/**
 * Implements hook_filter_tips().
 */
function _slideshow_creator_filter_tips($delta, $format, $long = FALSE) {
  return t('Slideshows can be added to this post.');
}

/**
 * Implements hook_filter_info().
 */
function slideshow_creator_filter_info() {
  $filters['slideshow'] = array(
    'title' => t('Slideshow Creator'),
    'cache' => TRUE,
    'description' => t('Create slideshows using any image on the internet with many other features.'),
    'process callback' => '_slideshow_creator_filter_insert_slideshow',
    'tips callback' => '_slideshow_creator_filter_tips',
  );
  return $filters;
}

/**
 * Implements hook_menu().
 */
function slideshow_creator_menu() {
  $items = array();

  $items['admin/config/content/slideshow_creator'] = array(
    'title'             => 'Slideshow Creator',
    'description'       => 'Set defaults for Slideshow Creator slideshows.',
    'page callback'     => 'drupal_get_form',
    'page arguments'    => array('_slideshow_creator_admin'),
    'access arguments'  => array('administer filters'),
    'file'              => 'slideshow_creator.admin.inc',
    'type'              => MENU_NORMAL_ITEM,
  );

  return $items;
}

/**
 * Implements hook_theme().
 */
function slideshow_creator_theme() {
  return array(
    'slideshow_creator' => array(
      'variables' => array('ss' => NULL),
      'file'      => 'slideshow_creator.inc'
    ),
  );
}
