swftools_simpleviewer.module in SWF Tools 6.3
Enables SWF Tools support for SimpleViewer.
File
simpleviewer/swftools_simpleviewer.moduleView source
<?php
/**
* @file
* Enables SWF Tools support for SimpleViewer.
*/
/**
* Implementation of hook_swftools_methods().
*/
function swftools_simpleviewer_swftools_methods() {
$simpleviewer = array(
'module' => 'swftools_simpleviewer',
'title' => t('SimpleViewer'),
'download' => 'http://www.simpleviewer.net/simpleviewer',
'width' => 700,
'height' => 600,
'library' => swftools_get_library('simpleviewer') . '/simpleviewer.swf',
'profile' => array(
'path' => 'simpleviewer',
'settings' => array(
'swftools_simpleviewer',
),
'file' => 'swftools_simpleviewer.admin.inc',
'page argument' => 'swftools_simpleviewer_profile_form',
),
);
$methods['image_list']['simpleviewer'] = $simpleviewer;
return $methods;
}
/**
* Implementation of hook_menu().
*/
function swftools_simpleviewer_menu() {
$items['admin/settings/swftools/simpleviewer'] = array(
'title' => 'SimpleViewer',
'description' => 'Settings for ' . l('SimpleViewer', 'http://www.simpleviewer.net/simpleviewer') . '.',
'weight' => 1,
'access arguments' => array(
'administer flash',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'swftools_simpleviewer_admin_form',
),
'file' => 'swftools_simpleviewer.admin.inc',
);
return $items;
}
/**
* Implementation of hook_swftools_preprocess_[player]().
*/
function swftools_simpleviewer_swftools_preprocess_simpleviewer(&$data) {
// Get array of simpleviewer settings
$saved_settings = _swftools_simpleviewer_vars($data['othervars']['profile']);
// Combine user supplied values and defaults, letting user values dominate
$data['flashvars'] = array_merge($saved_settings['swf'], $data['flashvars']);
// Attach file url of the content to display to flashvars
$data['flashvars']['galleryURL'] = $data['othervars']['file_url'];
}
/**
* Implementation of hook_swftools_playlist().
*/
function swftools_simpleviewer_swftools_playlist_simpleviewer(&$data) {
// Get array of simpleviewer settings
$saved_settings = _swftools_simpleviewer_vars($data['othervars']['profile']);
// Extract any relevant xml settings from the $data['othervars'] array
$user_xml = array_intersect_key($data['othervars'], $saved_settings['xml']);
// Merge user defined xml parameters with default parameters
$xml_vars = array_merge($saved_settings['xml'], $user_xml);
// Extract any relevant flickr settings from the $data['othervars'] array
$user_flickr = array_intersect_key($data['othervars'], $saved_settings['flickr']);
// Merge user defined flickr parameters with default parameters
$flickr_vars = array_merge($saved_settings['flickr'], $user_flickr);
// If useFlickr is true then add the flickr settings to the array of xml parameters
if ($flickr_vars['useFlickr'] == 'true' || $flickr_vars['useFlickr'] == 1) {
// Set useFlickr 'true'
$xml_vars['useFlickr'] = 'true';
// If a username was specified include this as flickrUserName
if ($flickr_vars['flickrUserName']) {
$xml_vars['flickrUserName'] = $flickr_vars['flickrUserName'];
}
// If flickrTags is not set, but tags is, then use tags
if (!$flickr_vars['flickrTags'] && isset($data['othervars']['tags']) && $data['othervars']['tags']) {
$flickr_vars['flickrTags'] = $data['othervars']['tags'];
}
// TODO: Could we convert user_id to flickrUserName?
// If tags were specified include them as flickrTags
if ($flickr_vars['flickrTags']) {
$xml_vars['flickrTags'] = $flickr_vars['flickrTags'];
}
}
// Put xml_vars and base in to the header array so the xml themer can access them
$data['othervars']['playlist_data']['header']['xml_vars'] = $xml_vars;
$data['othervars']['playlist_data']['header']['base'] = $data['params']['base'];
// Initialise a string to contain the elements
$xml = '';
// Iterate over the playlist to build elements xml
if ($data['othervars']['playlist_data']['playlist']) {
foreach ($data['othervars']['playlist_data']['playlist'] as $track => $details) {
$xml .= theme('swftools_simpleviewer_playlist_element', $details, $saved_settings['imagecache']['imagecache'] == SWFTOOLS_UNDEFINED ? '' : $saved_settings['imagecache']['imagecache']);
}
}
// Add xml wrapper around the elements
$xml = theme('swftools_simpleviewer_playlist_wrapper', $data['othervars']['playlist_data']['header'], $xml);
// Return the resulting xml
return $xml;
}
/**
* Implementation of hook_theme().
*/
function swftools_simpleviewer_theme() {
return array(
'swftools_simpleviewer_playlist_element' => array(
'template' => 'swftools-simpleviewer-playlist-element',
'arguments' => array(
'element' => NULL,
'imagecache' => NULL,
),
),
'swftools_simpleviewer_playlist_wrapper' => array(
'template' => 'swftools-simpleviewer-playlist-wrapper',
'arguments' => array(
'header' => NULL,
'xml' => NULL,
),
),
);
}
/**
* Return an array of default settings for the admin page and player configuration
*/
function _swftools_simpleviewer_settings($profile) {
$defaults['appearance'] = array(
'width' => 700,
'height' => 600,
'maxImageWidth' => 480,
'maxImageHeight' => 480,
'frameWidth' => 20,
'thumbPosition' => 'LEFT',
'thumbColumns' => 3,
'thumbRows' => 4,
'showOpenButton' => 'true',
'showFullScreenButton' => 'true',
'galleryStyle' => 'MODERN',
'textColor' => '#FFFFFF',
'frameColor' => '#FFFFFF',
);
$defaults['flickr'] = array(
'useFlickr' => 0,
'flickrUserName' => '',
'flickrTags' => '',
);
$defaults['imagecache'] = array(
'imagecache' => SWFTOOLS_UNDEFINED,
);
// Retrieve settings from database, if available
$settings = swftools_variable_get('swftools_simpleviewer', $defaults, $profile);
// Return resulting defaults
return $settings;
}
/**
* Remap values from the settings form to the format needed to build player output.
*/
function _swftools_simpleviewer_vars($profile) {
// Cache this
static $cache = array();
// If profile is not set then we need a name to cache it
$_profile = $profile ? $profile : SWFTOOLS_UNDEFINED;
// If values not already populated then get them
if (!isset($cache[$_profile])) {
// Get current defaults
$settings = _swftools_simpleviewer_settings($profile);
// Attach height and width
$cache[$_profile]['swf'] = array(
'width' => $settings['appearance']['width'],
'height' => $settings['appearance']['height'],
);
// Don't attach swf appearance settings to xml
unset($settings['appearance']['swf']);
// Attach remaining appearance variables to xml
$cache[$_profile]['xml'] = $settings['appearance'];
// Attach imagecache settings
$cache[$_profile]['imagecache'] = $settings['imagecache'];
// Attach flickr settings
$cache[$_profile]['flickr'] = $settings['flickr'];
}
// Return remapped variables
return $cache[$_profile];
}
Functions
Name | Description |
---|---|
swftools_simpleviewer_menu | Implementation of hook_menu(). |
swftools_simpleviewer_swftools_methods | Implementation of hook_swftools_methods(). |
swftools_simpleviewer_swftools_playlist_simpleviewer | Implementation of hook_swftools_playlist(). |
swftools_simpleviewer_swftools_preprocess_simpleviewer | Implementation of hook_swftools_preprocess_[player](). |
swftools_simpleviewer_theme | Implementation of hook_theme(). |
_swftools_simpleviewer_settings | Return an array of default settings for the admin page and player configuration |
_swftools_simpleviewer_vars | Remap values from the settings form to the format needed to build player output. |