You are here

onepixelout.module in SWF Tools 5

Same filename and directory in other branches
  1. 6 onepixelout/onepixelout.module
  2. 6.2 onepixelout/onepixelout.module

File

onepixelout/onepixelout.module
View source
<?php

/**
 * SWF Tools - Jeroen Onepixelout's Flash Players
 *
 * Enables the use of Jeroen Onepixelout's Flash Media and Flash Image
 * Rotator files, branded forms of which ship with SWF Tools module.
 *
 * Author's Site.
 * http://jeroenonepixelout.com
 */
define('ONEPIXELOUT', 'onepixelout');

// 'player', plays a single mp3

/**
 * Implementation of swftools_methods hook
 * Report methods back to SWF Tools
 */
function onepixelout_swftools_methods() {
  $methods = array();
  $media_player = array(
    'name' => ONEPIXELOUT,
    'module' => 'onepixelout',
    'file' => 'soundFile',
    // Define which flashvar to assign a 'file to play' variable.
    'version' => '7',
    'shared_file' => '1pixelout/player.swf',
    'title' => t('1 Pixel Out MP3 Player'),
  );

  // Onepixelout support various actions with the same player and info.
  $methods[SWFTOOLS_MP3_DISPLAY][ONEPIXELOUT] = $media_player;
  return $methods;
}

/**
 * Implementation of hook_menu().
 */
function onepixelout_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'admin/media/swf/onepixelout',
      'title' => t('1 Pixel Out'),
      'callback' => 'drupal_get_form',
      'callback arguments' => 'onepixelout_admin_form',
      'description' => 'Settings for ' . l('1 Pixel Out MP3 Player', 'http://www.1pixelout.net/code/audio-player-wordpress-plugin/') . '.',
    );
  }
  return $items;
}
function onepixelout_admin_form() {
  include_once drupal_get_path('module', 'onepixelout') . '/onepixelout.admin.inc';
  return _onepixelout_admin_form();
}
function onepixelout_admin_form_submit($form_id, &$form_values) {
  include_once drupal_get_path('module', 'onepixelout') . '/onepixelout.admin.inc';
  return _onepixelout_admin_form_submit($form_id, $form_values);
}
function theme_onepixelout_admin_form($form_values) {
  $output = drupal_render($form_values['onepixelout_mediaplayer']['autostart']);
  $output .= drupal_render($form_values['onepixelout_mediaplayer']['loop']);
  $output .= '<img src="http://www.1pixelout.net/wp-content/plugins/audio-player/map.gif" alt="Player Map" />';
  $output .= drupal_render($form_values);
  return $output;
}

/**
 * These are the default settings as they are stored in the database and displayed
 * on the settings page.
 */
function _onepixelout_settings() {
  $saved = variable_get('swftools_' . ONEPIXELOUT, array());
  $defaults = array(
    'autostart' => 'no',
    'loop' => 'no',
    'bg' => '',
    'leftbg' => '',
    'rightbg' => '',
    'rightbghover' => '',
    'lefticon' => '',
    'righticon' => '',
    'righticonhover' => '',
    'text' => '',
    'slider' => '',
    'loader' => '',
    'track' => '',
    'border' => '',
  );
  return array_merge($defaults, $saved);
}

/**
 * Implementation of swftools_flashvars hook.
 * Return an array of flashvars.
 */
function onepixelout_swftools_flashvars($action, &$methods, &$vars) {
  $saved = _onepixelout_flashvars();

  // Combine user and admin defaults, overwriting defaults.
  $saved = array_merge($saved, $vars->flashvars);
  return $saved;
}

/**
 * This function takes the module settings and massages them
 * as required for flashvar output.
 *
 */
function _onepixelout_flashvars() {

  // Cache this.
  static $flashvars = array();
  if (!count($flashvars)) {

    // Get saved settings for this method.
    $saved = _onepixelout_settings();
    foreach ($saved as $key => $setting) {
      if (!$setting || $setting == 'default') {

        // Don't pass out any undefined values.
        unset($saved[$key]);
      }
    }
  }
  return $saved;
}

/**
 * Call swf(), enforcing the one pixel out player, for a single file
 * Parameters are identical to swf()
 */
function onepixelout_swf($filepath, $params = SWFDEFAULT, $flashvars = SWFDEFAULT, $othervars = SWFDEFAULT, $methods = SWFDEFAULT, $debug = FALSE) {
  $methods['player'] = ONEPIXELOUT;
  return swf($filepath, $params, $flashvars, $othervars, $methods);
}

/*
 * Implementation of hook_swftools_variable_mapping.
 *
 */
function onepixelout_swftools_variable_mapping() {
  return array(
    ONEPIXELOUT => array(
      'loop' => 'flashvars',
      'autostart' => 'flashvars',
      'leftbg' => 'flashvars',
      'lefticon' => 'flashvars',
      'rightbg' => 'flashvars',
      'righticon' => 'flashvars',
      'rightbghover' => 'flashvars',
      'righticonhover' => 'flashvars',
    ),
  );
}

Functions

Namesort descending Description
onepixelout_admin_form
onepixelout_admin_form_submit
onepixelout_menu Implementation of hook_menu().
onepixelout_swf Call swf(), enforcing the one pixel out player, for a single file Parameters are identical to swf()
onepixelout_swftools_flashvars Implementation of swftools_flashvars hook. Return an array of flashvars.
onepixelout_swftools_methods Implementation of swftools_methods hook Report methods back to SWF Tools
onepixelout_swftools_variable_mapping
theme_onepixelout_admin_form
_onepixelout_flashvars This function takes the module settings and massages them as required for flashvar output.
_onepixelout_settings These are the default settings as they are stored in the database and displayed on the settings page.

Constants

Namesort descending Description
ONEPIXELOUT SWF Tools - Jeroen Onepixelout's Flash Players