You are here

swftools_flexpaper.module in SWF Tools 6.3

Enables SWF Tools support for the FlexPaper PDF viewer.

File

flexpaper/swftools_flexpaper.module
View source
<?php

/**
 * @file
 * Enables SWF Tools support for the FlexPaper PDF viewer.
 */

/**
 * Implementation of hook_swftools_methods().
 */
function swftools_flexpaper_swftools_methods() {

  // Define the FlexPaper handler
  $flexpaper = array(
    'module' => 'swftools_flexpaper',
    'title' => t('FlexPaper'),
    'download' => 'http://flexpaper.devaldi.com/',
    'width' => 600,
    'height' => 500,
    'library' => swftools_get_library('flexpaper') . '/FlexPaperViewer.swf',
    'profile' => array(
      'path' => 'flexpaper',
      'settings' => array(
        'swftools_flexpaper',
      ),
      'file' => 'swftools_flexpaper.admin.inc',
      'page argument' => 'swftools_flexpaper_profile_form',
    ),
  );

  // FlexPaper is used as a container for swf files
  $methods['swf']['flexpaper'] = $flexpaper;

  // Return methods that the player supports
  return $methods;
}

/**
 * Implementation of hook_menu().
 */
function swftools_flexpaper_menu() {
  $items['admin/settings/swftools/flexpaper'] = array(
    'title' => 'FlexPaper',
    'description' => 'Settings for ' . l('FlexPaper pdf viewer', 'http://flexpaper.devaldi.com/') . '.',
    'access arguments' => array(
      'administer flash',
    ),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'swftools_flexpaper_admin_form',
    ),
    'file' => 'swftools_flexpaper.admin.inc',
  );
  return $items;
}

/**
 * Implementation of hook_swftools_preprocess_[player]().
 */
function swftools_flexpaper_swftools_preprocess_flexpaper(&$data) {

  // Retrieve default FlexPaper settings
  $saved_settings = _swftools_flexpaper_flashvars($data['othervars']['profile']);

  // Combine user supplied values and defaults, letting user values dominate
  $data['flashvars'] = array_merge($saved_settings, $data['flashvars']);

  // Attach file url of the content to display to flashvars
  $data['flashvars']['SwfFile'] = $data['othervars']['file_url'];
}

/**
 * Returns the player default settings, or customised settings from the configuration page.
 */
function _swftools_flexpaper_settings($profile = '', $mode = SWFTOOLS_MINIMUM_SETTINGS) {

  // Set up defaults
  $defaults = array(
    SWFTOOLS_MINIMUM_SETTINGS => array(
      'height' => 500,
      'width' => 600,
      'Scale' => 0.6,
      'PrintEnabled' => 'true',
      'FullScreenAsMaxWindow' => 'false',
    ),
    SWFTOOLS_FULL_SETTINGS => array(
      'height' => 500,
      'width' => 600,
      'Scale' => 0.6,
      'ZoomTransition' => '',
      'ZoomTime' => '',
      'ZoomInterval' => '',
      'FitPageOnLoad' => 'default',
      'FitWidthOnLoad' => 'default',
      'PrintEnabled' => 'true',
      'localeChain' => 'default',
      'FullScreenAsMaxWindow' => 'true',
    ),
  );

  // Retrieve settings from the database if available
  $settings = swftools_variable_get('swftools_flexpaper', $defaults[SWFTOOLS_MINIMUM_SETTINGS], $profile);

  // If a full set of settings are requested for the admin page then merge with full defaults
  if ($mode == SWFTOOLS_FULL_SETTINGS) {
    $settings = swftools_array_merge($defaults[SWFTOOLS_FULL_SETTINGS], $settings);
  }

  // Return result
  return $settings;
}

/**
 * Retrieves the player default settings and unsets any that are empty.
 *
 * @return array
 *   An array of settings.
 */
function _swftools_flexpaper_flashvars($profile) {

  // Initialise cache to handle repeated calls
  static $cache = array();

  // Store name of profile
  $_profile = $profile;
  if ($profile === '') {
    $_profile = '__default';
  }

  // If no settings stored for this profile then fetch them
  if (!isset($cache[$_profile])) {

    // Get default/saved settings
    $settings = _swftools_flexpaper_settings($profile);

    // Store the result
    $cache[$_profile] = $settings;
  }

  // Return the settings
  return $cache[$_profile];
}

/**
 * Implementation of hook_swftools_variable_mapping().
 */
function swftools_flexpaper_swftools_variable_mapping() {
  return array(
    'flexpaper' => array(
      'height' => 'flashvars',
      'width' => 'flashvars',
      'Scale' => 'flashvars',
      'ZoomTransition' => 'flashvars',
      'ZoomTime' => 'flashvars',
      'ZoomInterval' => 'flashvars',
      'FitPageOnLoad' => 'flashvars',
      'FitWidthOnLoad' => 'flashvars',
      'PrintEnabled' => 'flashvars',
      'localeChain' => 'flashvars',
    ),
  );
}

Functions

Namesort descending Description
swftools_flexpaper_menu Implementation of hook_menu().
swftools_flexpaper_swftools_methods Implementation of hook_swftools_methods().
swftools_flexpaper_swftools_preprocess_flexpaper Implementation of hook_swftools_preprocess_[player]().
swftools_flexpaper_swftools_variable_mapping Implementation of hook_swftools_variable_mapping().
_swftools_flexpaper_flashvars Retrieves the player default settings and unsets any that are empty.
_swftools_flexpaper_settings Returns the player default settings, or customised settings from the configuration page.