swftools_tiltviewer.module in SWF Tools 6.3
Enables SWF Tools support for TiltViewer.
File
tiltviewer/swftools_tiltviewer.moduleView source
<?php
/**
* @file
* Enables SWF Tools support for TiltViewer.
*/
/**
* Implementation of hook_swftools_methods().
*/
function swftools_tiltviewer_swftools_methods() {
$tiltviewer = array(
'module' => 'swftools_tiltviewer',
'title' => t('TiltViewer'),
'download' => 'http://www.simpleviewer.net/tiltviewer',
'width' => 700,
'height' => 600,
'library' => swftools_get_library('tiltviewer') . '/TiltViewer.swf',
'profile' => array(
'path' => 'tiltviewer',
'settings' => array(
'swftools_tiltviewer',
),
'file' => 'swftools_tiltviewer.admin.inc',
'page argument' => 'swftools_tiltviewer_profile_form',
),
);
$methods['image_list']['tiltviewer'] = $tiltviewer;
return $methods;
}
/**
* Implementation of hook_menu().
*/
function swftools_tiltviewer_menu() {
$items['admin/settings/swftools/tiltviewer'] = array(
'title' => 'TiltViewer',
'description' => 'Settings for ' . l('TiltViewer', 'http://www.simpleviewer.net/tiltviewer') . '.',
'weight' => 1,
'access arguments' => array(
'administer flash',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'swftools_tiltviewer_admin_form',
),
'file' => 'swftools_tiltviewer.admin.inc',
);
return $items;
}
/**
* Implementation of hook_swftools_preprocess_[player]().
*/
function swftools_tiltviewer_swftools_preprocess_tiltviewer(&$data) {
// Retrieve settings
$saved_settings = _swftools_tiltviewer_vars($data['othervars']['profile']);
// Extract any relevant config vars from the $data['othervars'] array
$user_vars = array_intersect_key($data['othervars'], $saved_settings['basic']);
// Merge any incoming values with basic settings
$saved_settings['basic'] = array_merge($saved_settings['basic'], $user_vars);
// Extract any relevant Flickr config vars from the $data['othervars'] array
$user_vars = array_intersect_key($data['othervars'], $saved_settings['flickr']);
// Merge any incoming values with flickr settings
$saved_settings['flickr'] = array_merge($saved_settings['flickr'], $user_vars);
// Always set the useFlickr option on the main settings
$saved_settings['basic']['useFlickr'] = $saved_settings['flickr']['useFlickr'];
// If tags is not set, but flickrTags is, then use flickrTags
if (!$saved_settings['flickr']['tags'] && isset($data['othervars']['flickrTags']) && $data['othervars']['flickrTags']) {
$saved_settings['flickr']['tags'] = $data['othervars']['flickrTags'];
}
// TODO: Could we convert flickrUserName to a user_id?
// Adjust flash vars depending on whether we're integrating to Flickr or not, filtering out empty keys
if ($saved_settings['flickr']['useFlickr'] == 'true') {
$data['flashvars'] += array_filter($saved_settings['flickr']);
}
else {
$data['flashvars']['xmlURL'] = $data['othervars']['file_url'];
}
// Combine user supplied values and defaults, letting user values dominate
$data['flashvars'] = array_merge($saved_settings['basic'], $data['flashvars']);
}
/**
* Implementation of hook_swftools_playlist().
*/
function swftools_tiltviewer_swftools_playlist_tiltviewer(&$data) {
// Get array of TiltViewer settings
$saved_settings = _swftools_tiltviewer_vars($data['othervars']['profile']);
// 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) {
// If no description was passed then set to an empty string
$details += array(
'description' => '',
);
// Format a single xml element
$xml .= theme('swftools_tiltviewer_playlist_element', $details, $saved_settings['imagecache']['imagecache'] == SWFTOOLS_UNDEFINED ? '' : $saved_settings['imagecache']['imagecache']);
}
}
// Add xml wrapper around the elements
$xml = theme('swftools_tiltviewer_playlist_wrapper', $data['othervars']['playlist_data']['header'], $xml);
// Return the resulting xml
return $xml;
}
/**
* Implementation of hook_theme().
*/
function swftools_tiltviewer_theme() {
return array(
'swftools_tiltviewer_playlist_element' => array(
'template' => 'swftools-tiltviewer-playlist-element',
'arguments' => array(
'element' => NULL,
'imagecache' => NULL,
),
),
'swftools_tiltviewer_playlist_wrapper' => array(
'template' => 'swftools-tiltviewer-playlist-wrapper',
'arguments' => array(
'header' => NULL,
'xml' => NULL,
),
),
);
}
/**
* Return an array of default settings for the admin page and player configuration
*/
function _swftools_tiltviewer_settings($profile) {
$defaults['basic'] = array(
'width' => 700,
'height' => 600,
'useReloadButton' => 'true',
'showFlipButton' => 'true',
'showLinkButton' => 'true',
'columns' => 5,
'rows' => 5,
'linkLabel' => t('go to Flickr Page'),
'frameColor' => '0xFFFFFF',
'backColor' => '0xFFFF00',
'bkgndInnerColor' => '0x333333',
'bkgndOuterColor' => '0x000000',
'langGoFull' => t('Go Fullscreen'),
'langExitFull' => t('Exit Fullscreen'),
'langAbout' => t('About'),
'maxJPGSize' => 1024,
);
$defaults['flickr'] = array(
'useFlickr' => 'false',
'user_id' => '',
'tags' => '',
'tag_mode' => 'any',
'showTakenByText' => 'true',
);
$defaults['imagecache'] = array(
'imagecache' => SWFTOOLS_UNDEFINED,
);
// Retrieve settings from database, if available
$settings = swftools_variable_get('swftools_tiltviewer', $defaults, $profile);
// Return resulting defaults
return $settings;
}
/**
* Retrieves TiltViewer settings for the selected profile
*/
function _swftools_tiltviewer_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_tiltviewer_settings($profile);
// Attach settings to the cache
$cache[$_profile] = $settings;
}
// Return settings for this profile
return $cache[$_profile];
}
Functions
Name | Description |
---|---|
swftools_tiltviewer_menu | Implementation of hook_menu(). |
swftools_tiltviewer_swftools_methods | Implementation of hook_swftools_methods(). |
swftools_tiltviewer_swftools_playlist_tiltviewer | Implementation of hook_swftools_playlist(). |
swftools_tiltviewer_swftools_preprocess_tiltviewer | Implementation of hook_swftools_preprocess_[player](). |
swftools_tiltviewer_theme | Implementation of hook_theme(). |
_swftools_tiltviewer_settings | Return an array of default settings for the admin page and player configuration |
_swftools_tiltviewer_vars | Retrieves TiltViewer settings for the selected profile |