swftools_wpaudio.module

Tracking 6.x-3.x branch
  1. drupal
    1. 6 contributions/swftools/wpaudio/swftools_wpaudio.module

Enables SWF Tools support for the WordPress Audio player.

Functions & methods

NameDescription
swftools_wpaudio_add_jsAdds WordPress audio JavaScript to the page.
swftools_wpaudio_initImplementation of hook_init().
swftools_wpaudio_menuImplementation of hook_menu().
swftools_wpaudio_swftools_methodsImplementation of hook_swftools_methods().
swftools_wpaudio_swftools_playlist_wpaudioImplementation of hook_swftools_playlist_[player]().
swftools_wpaudio_swftools_preprocess_wpaudioImplementation of hook_swftools_preprocess_[player]().
swftools_wpaudio_swftools_variable_mapping
swftools_wpaudio_themeImplementation of hook_theme().
theme_swftools_wpaudio_accessibleReturns markup to enable accessible controls for the WordPress audio player.
_swftools_wpaudio_flashvarsRetrieves the audio player default settings and unsets any that are empty.
_swftools_wpaudio_settingsReturns the audio player default settings, or customised settings from the configuration page.

File

View source
  1. <?php
  2. /**
  3. * @file
  4. * Enables SWF Tools support for the WordPress Audio player.
  5. */
  6. /**
  7. * Implementation of hook_swftools_methods().
  8. */
  9. function swftools_wpaudio_swftools_methods() {
  10. // Define the media player
  11. $wpaudio = array(
  12. 'module' => 'swftools_wpaudio',
  13. 'title' => t('WordPress Audio'),
  14. 'download' => 'http://wpaudioplayer.com/',
  15. 'width' => 290,
  16. 'height' => 24,
  17. 'library' => swftools_get_library('audio-player') . '/player.swf',
  18. 'profile' => array(
  19. 'path' => 'wpaudio',
  20. 'settings' => array('swftools_wpaudio'),
  21. 'file' => 'swftools_wpaudio.admin.inc',
  22. 'page argument' => 'swftools_wpaudio_profile_form',
  23. ),
  24. );
  25. // WordPress audio player supports single audio files and playlists
  26. $methods['audio']['wpaudio'] = $wpaudio;
  27. $methods['audio_list']['wpaudio'] = $wpaudio;
  28. // Return methods that the player supports
  29. return $methods;
  30. }
  31. /**
  32. * Implementation of hook_menu().
  33. */
  34. function swftools_wpaudio_menu() {
  35. $items['admin/settings/swftools/wpaudio'] = array(
  36. 'title' => 'WordPress Audio Player',
  37. 'description' => 'Settings for '. l('WordPress audio player', 'http://wpaudioplayer.com/') .'.',
  38. 'access arguments' => array('administer flash'),
  39. 'page callback' => 'drupal_get_form',
  40. 'page arguments' => array('swftools_wpaudio_admin_form'),
  41. 'file' => 'swftools_wpaudio.admin.inc',
  42. );
  43. return $items;
  44. }
  45. /**
  46. * Implementation of hook_swftools_preprocess_[player]().
  47. */
  48. function swftools_wpaudio_swftools_preprocess_wpaudio(&$data) {
  49. // If the passed variables includes 'playlist_data' we have a playlist to use
  50. if ($data['othervars']['playlist_data']) {
  51. // Overwrite the file_url with the playlist string
  52. $data['othervars']['file_url'] = $data['othervars']['wpaudio']['soundFile'];
  53. }
  54. else {
  55. // Was a title set on this single element from CCK?
  56. if (isset($data['othervars']['title']) && $data['othervars']['title']) {
  57. $data['flashvars']['titles'] = $data['othervars']['title'];
  58. }
  59. }
  60. // Set the playerID the same as the container id
  61. $data['flashvars']['playerID'] = $data['othervars']['id'];
  62. // Retrieve default audio player settings
  63. $saved_settings = _swftools_wpaudio_flashvars($data['othervars']['profile']);
  64. // Combine user supplied values and defaults, letting user values dominate
  65. $data['flashvars'] = array_merge($saved_settings, $data['flashvars']);
  66. // Add accessible controls?
  67. if ($data['flashvars']['accessible']) {
  68. // Add the accessible markup to #suffix so it will be output after the player
  69. $data['othervars']['#suffix'] = theme('swftools_wpaudio_accessible', $data['othervars']['id'], $data['flashvars']['accessible']);
  70. // Unset the accessible parameters from flashvars so they are not output
  71. unset($data['flashvars']['accessible']);
  72. }
  73. // Attach file url of the content to display to flashvars
  74. $data['flashvars']['soundFile'] = $data['othervars']['file_url'];
  75. // Add JavaScript to enable auto-close behavior and accessibility
  76. swftools_wpaudio_add_js();
  77. }
  78. /**
  79. * Returns the audio player default settings, or customised settings from the configuration page.
  80. */
  81. function _swftools_wpaudio_settings($profile) {
  82. // Set up defaults
  83. // TODO: Put these in an array so we can organise the admin form by categories, like other players
  84. $defaults = array(
  85. 'player' => array(
  86. 'height' => 24,
  87. 'width' => 290,
  88. 'autostart' => 'no',
  89. 'loop' => 'no',
  90. 'animation' => 'yes',
  91. 'remaining' => 'no',
  92. 'noinfo' => 'no',
  93. 'initialvolume' => 60,
  94. 'buffer' => 5,
  95. 'encode' => 'no',
  96. 'checkpolicy' => 'no',
  97. 'rtl' => 'no',
  98. 'transparentpagebg' => 'no',
  99. ),
  100. 'colors' => array(
  101. 'bg' => 'E5E5E5',
  102. 'leftbg' => 'CCCCCC',
  103. 'lefticon' => '333333',
  104. 'voltrack' => 'F2F2F2',
  105. 'volslider' => '666666',
  106. 'rightbg' => 'B4B4B4',
  107. 'rightbghover' => '999999',
  108. 'righticon' => '333333',
  109. 'righticonhover' => 'FFFFFF',
  110. 'loader' => '009900',
  111. 'track' => 'FFFFFF',
  112. 'tracker' => 'DDDDDD',
  113. 'border' => 'CCCCCC',
  114. 'skip' => '666666',
  115. 'text' => '333333',
  116. 'pagebg' => '',
  117. ),
  118. 'accessibility' => array(
  119. 'accessible' => SWFTOOLS_ACCESSIBLE_DISABLED,
  120. ),
  121. );
  122. // Retrieve settings from the database if available
  123. $settings = swftools_variable_get('swftools_wpaudio', $defaults, $profile);
  124. // Return result
  125. return $settings;
  126. }
  127. /**
  128. * Retrieves the audio player default settings and unsets any that are empty.
  129. *
  130. * @return
  131. * An array of settings.
  132. */
  133. function _swftools_wpaudio_flashvars($profile) {
  134. // Initialise cache to handle repeated calls
  135. static $cache = array();
  136. // Store name of profile
  137. $_profile = $profile;
  138. if ($profile === '') {
  139. $_profile = '__default';
  140. }
  141. // If no settings stored for this profile then fetch them
  142. if (!isset($cache[$_profile])) {
  143. // Get default/saved settings
  144. $settings = _swftools_wpaudio_settings($profile);
  145. // Flatten
  146. swftools_array_flatten($settings);
  147. // Filter out unassigned or default entries
  148. $settings = array_diff($settings, array('', 'default'));
  149. // Store the result
  150. $cache[$_profile] = $settings;
  151. }
  152. // Return the settings
  153. return $cache[$_profile];
  154. }
  155. /*
  156. * Implementation of hook_swftools_variable_mapping.
  157. *
  158. * This tells SWF Tools where to map parameters passed through the input filter.
  159. *
  160. */
  161. function swftools_wpaudio_swftools_variable_mapping() {
  162. return array(
  163. 'wpaudio' => array(
  164. 'height' => 'flashvars',
  165. 'width' => 'flashvars',
  166. 'autostart' => 'flashvars',
  167. 'loop' => 'flashvars',
  168. 'animation' => 'flashvars',
  169. 'remaining' => 'flashvars',
  170. 'noinfo' => 'flashvars',
  171. 'initialvolume' => 'flashvars',
  172. 'buffer' => 'flashvars',
  173. 'encode' => 'flashvars',
  174. 'checkpolicy' => 'flashvars',
  175. 'rtl' => 'flashvars',
  176. 'transparentpagebg' => 'flashvars',
  177. 'pagebg' => 'flashvars',
  178. 'bg' => 'flashvars',
  179. 'leftbg' => 'flashvars',
  180. 'lefticon' => 'flashvars',
  181. 'voltrack' => 'flashvars',
  182. 'volslider' => 'flashvars',
  183. 'rightbg' => 'flashvars',
  184. 'rightbghover' => 'flashvars',
  185. 'righticon' => 'flashvars',
  186. 'righticonhover' => 'flashvars',
  187. 'loader' => 'flashvars',
  188. 'track' => 'flashvars',
  189. 'tracker' => 'flashvars',
  190. 'border' => 'flashvars',
  191. 'skip' => 'flashvars',
  192. 'text' => 'flashvars',
  193. ),
  194. );
  195. }
  196. /**
  197. * Implementation of hook_init().
  198. *
  199. * Push the script to stop other players on to the page.
  200. */
  201. function swftools_wpaudio_init() {
  202. // Add JavaScript to enable auto-close behavior and accessibility
  203. if (variable_get('swftools_always_add_js', SWFTOOLS_ALWAYS_ADD_JS)) {
  204. swftools_wpaudio_add_js();
  205. }
  206. };
  207. /**
  208. * Returns markup to enable accessible controls for the WordPress audio player.
  209. *
  210. * @param string $id
  211. * id of the player to be made accessible.
  212. * @param int $visible
  213. * Whether the controls should be visible. Options are one the following constants:
  214. * - SWFTOOLS_ACCESSIBLE_DISABLED
  215. * - SWFTOOLS_ACCESSIBLE_HIDDEN
  216. * - SWFTOOLS_ACCESSIBLE_VISIBLE
  217. *
  218. * @return string
  219. * Mark up to place accessible controls on the page.
  220. *
  221. * @ingroup themeable
  222. * @ingroup swftools
  223. */
  224. function theme_swftools_wpaudio_accessible($id, $visible) {
  225. $actions = array(
  226. 'open' => t('Play'),
  227. 'close' => t('Stop'),
  228. );
  229. return theme('swftools_accessible_controls', 'wpaudio', $id, $actions, $visible);
  230. }
  231. /**
  232. * Implementation of hook_theme().
  233. */
  234. function swftools_wpaudio_theme() {
  235. return array(
  236. 'swftools_wpaudio_accessible' => array(
  237. 'arguments' => array('id' => NULL, 'visible' => NULL),
  238. ),
  239. );
  240. }
  241. /**
  242. * Adds WordPress audio JavaScript to the page.
  243. */
  244. function swftools_wpaudio_add_js() {
  245. // Add JavaScript to enable auto-close behavior and accessibility
  246. drupal_add_js(drupal_get_path('module', 'swftools_wpaudio') . '/swftools_wpaudio.js');
  247. }
  248. /**
  249. * Implementation of hook_swftools_playlist_[player]().
  250. */
  251. function swftools_wpaudio_swftools_playlist_wpaudio(&$data) {
  252. // Set flag to show if we found a description
  253. $found_titles = FALSE;
  254. // Initialise arrays
  255. $playlist = array();
  256. $titles = array();
  257. // Get file paths out of the playlist_data array and add to the playlist
  258. foreach ($data['othervars']['playlist_data']['playlist'] as $key => $play) {
  259. // Add this element to the playlist
  260. $playlist[] = $play['fileurl'];
  261. // Add title to titles array
  262. $titles[]= $play['title'];
  263. // Set flag if this title actually contained something
  264. if ($play['title']) {
  265. $found_titles = TRUE;
  266. }
  267. }
  268. // Convert playlist array to a string
  269. $playlist = implode(',', $playlist);
  270. // Convert titles array to a string
  271. $titles = implode(',', $titles);
  272. // Overwrite $data['othervars']['file_url'] with playlist string
  273. $data['othervars']['wpaudio']['soundFile'] = $playlist;
  274. // If we found some actual titles add these to the flashvars array
  275. if ($found_titles) {
  276. $data['flashvars']['titles'] = $titles;
  277. }
  278. // Show we are not offering xml
  279. return SWFTOOLS_NON_XML_PLAYLIST;
  280. }