You are here

soundmanager2.module in SoundManager2 6

Same filename and directory in other branches
  1. 6.2 soundmanager2.module
  2. 7.2 soundmanager2.module

File

soundmanager2.module
View source
<?php

function soundmanager2_init() {

  // Add module Styles
  drupal_add_css(drupal_get_path('module', 'soundmanager2') . '/page-player.css');

  // Add modules scripts
  if (variable_get('sm2-debug-mode', false)) {
    drupal_add_js(variable_get('sm2-path', 'sites/all/shared/soundmanager2') . '/script/soundmanager2.js');
    drupal_add_js("var sm2_var_debug = true ;", 'inline');
  }
  else {
    drupal_add_js(variable_get('sm2-path', 'sites/all/shared/soundmanager2') . '/script/soundmanager2-nodebug-jsmin.js');
    drupal_add_js("var sm2_var_debug = false ;", 'inline');
  }
  drupal_add_js(drupal_get_path('module', 'soundmanager2') . '/page-player.js');
  drupal_add_js("var sm2_mod_url = '/" . variable_get('sm2-path', 'sites/all/shared/soundmanager2') . '/swf/' . "' ;", 'inline');
  drupal_add_js("var sm2_imageRoot = '/" . drupal_get_path('module', 'soundmanager2') . '/' . "' ;", 'inline');
  drupal_add_js(drupal_get_path('module', 'soundmanager2') . '/soundmanager_config.js');
}
function soundmanager2_perm() {
  return array(
    'administer sm2',
  );
}

// Define a block for debug information of the soundmanager2
function soundmanager2_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == "list") {
    $block = array();
    $block[0]["info"] = t('SoundManager2 Debug');
    return $block;
  }
  else {
    if ($op == "view") {

      //if (variable_get('sm2-debug-mode',false)) {
      cache_clear_all();

      //};
      $block_content = '<div id="soundmanager-debug"><p>Debug block for SoundManager2</p></div>';
      $block['subject'] = t('SoundManager2 Debug');
      $block['content'] = $block_content;
      return $block;
    }
  }
}

// Admin page
function soundmanager2_admin() {
  $form = array();
  $form['sm2-debug-mode'] = array(
    '#type' => 'checkbox',
    '#title' => t('Activate Debug Mode'),
    '#default_value' => variable_get('sm2-debug-mode', false),
    '#description' => t("If checked, the sm2 module will output debug text in the block."),
  );
  $form['sm2-path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path to soundmanager2 files'),
    '#default_value' => variable_get('sm2-path', 'sites/all/shared/soundmanager2'),
    '#description' => t('Path to the soundmanager2 files. No trailing and beggining backslash. Download SoundManager2 from <a href="http://www.schillmania.com/projects/soundmanager2/doc/download/">here</a>.'),
    '#size' => 60,
    '#maxlength' => 128,
    '#required' => TRUE,
  );
  return system_settings_form($form);
}
function soundmanager2_menu() {
  $items = array();
  $items['admin/settings/soundmanager2'] = array(
    'title' => 'SoundManager2 module settings',
    'description' => 'Setup SM2 module (more info about sm2 in <a href="http://schillmania.com/projects/soundmanager2">soundmanager2</a>)',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'soundmanager2_admin',
    ),
    'access arguments' => array(
      'administer sm2',
    ),
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}
function soundmanager2_admin_validate($form, &$form_state) {
  $sm_path = trim($form_state['values']['sm2-path'], '/');
  $form_state['values']['sm2-path'] = $sm_path;
  $sm_path_swf = $sm_path . '/swf';
  $sm_path_script = $sm_path . '/script';
  file_check_directory($sm_path, 0, 'sm2-path');
  file_check_directory($sm_path_swf, 0, 'sm2-path');
  file_check_directory($sm_path_script, 0, 'sm2-path');
}

//==========================================//

// DEFINING A FORMATTER

//==========================================//

/**
 * Implementation of hook_theme().
 */
function soundmanager2_theme() {
  $formatters_filefield = array();
  $formatters_audio = array();
  if (module_exists('audio')) {
    $formatters_audio = array(
      'soundmanager2_formatter_audiosm2' => array(
        'arguments' => array(
          'element' => $element,
        ),
        'template' => 'soundmanager2_audio',
      ),
    );
  }
  if (module_exists('filefield')) {
    $formatters_filefield = array(
      'soundmanager2_formatter_soundmanager2' => array(
        'arguments' => array(
          'element' => $element,
        ),
        'template' => 'soundmanager2',
      ),
    );
  }
  $formatters = array_merge($formatters_filefield, $formatters_audio);
  return $formatters;
}

/**
 * Implementation of hook_field_formatter_info().
 * 
 * All fields should have a 'default' formatter.
 * Any number of other formatters can be defined as well.
 * It's nice for there always to be a 'plain' option
 * for the raw value, but that is not required.
 * 
 */
function soundmanager2_field_formatter_info() {
  $formatterinfo_filefield = array();
  $formatterinfo_audio = array();
  if (module_exists('filefield')) {
    $formatterinfo_filefield = array(
      // The machine name of the formatter.
      'soundmanager2' => array(
        // The human-readable label shown on the Display
        // fields screen.
        'label' => t('SoundManager 2'),
        // An array of the field types this formatter
        // can be used on.
        'field types' => array(
          'filefield',
        ),
        // CONTENT_HANDLE_CORE:   CCK will pass the formatter
        // a single value.
        // CONTENT_HANDLE_MODULE: CCK will pass the formatter
        // an array of all the values. None of CCK's core
        // formatters use multiple values, that is an option
        // available to other modules that want it.

        //'multiple values' => CONTENT_HANDLE_CORE,
        'multiple values' => CONTENT_HANDLE_MODULE,
      ),
    );
  }
  if (module_exists('audio')) {
    $formatterinfo_audio = array(
      'audiosm2' => array(
        'label' => t('Audio integration. Soundmanager2'),
        'field types' => array(
          'nodereference',
        ),
        'multiple values' => CONTENT_HANDLE_MODULE,
      ),
    );
  }
  $formatterinfo = array_merge($formatterinfo_filefield, $formatterinfo_audio);
  return $formatterinfo;
}