asset_bonus.module

Tracking 5.x-2.x branch
  1. drupal
    1. 5 contributions/asset/contrib/asset_bonus/asset_bonus.module
    2. 6 contributions/asset/asset_bonus/asset_bonus.module
    3. 6 contributions/asset/contrib/asset_bonus/asset_bonus.module

Functions & methods

NameDescription
asset_bonus_admin_mp3player
asset_bonus_admin_overview
asset_bonus_asset_formatter
asset_bonus_help
asset_bonus_menu
asset_bonus_mp3player_colors
asset_bonus_mp3player_form
asset_bonus_mp3player_img
asset_bonus_mp3player_preview
asset_bonus_swfobject_details
asset_bonus_swfobject_form
asset_bonus_swfobject_img
asset_bonus_swfobject_preview
theme_asset_bonus_mp3player
theme_asset_bonus_swfobject

Constants

NameDescription
ASSET_PRIVATE
ASSET_PUBLIC

File

View source
  1. <?php
  2. define('ASSET_PRIVATE', 0);
  3. define('ASSET_PUBLIC', 1);
  4. function asset_bonus_help($section) {
  5. switch ($section) {
  6. case 'admin/help#asset_bonus':
  7. case 'admin/settings/asset/asset_bonus':
  8. return t('<p>The Asset Bonus Pack adds additional functionality to the
  9. Asset module for handling audio files and Flash objects.</p>
  10. <p>The Assets Bonus Pack consists of two parts. The first part is
  11. included with the Asset module. Due to licensing guidelines on
  12. Drupal.org (only software licensed under the GPL may be included
  13. in CVS) the second part must be downloaded separately from
  14. !link. Though the additional files are open-source, they are not
  15. GPL licensed.</p>
  16. <p>The zip file includes three folders. Unzip these folders into
  17. the <em>modules/asset/asset_bonus</em> folder and check below to
  18. make sure that they were found.</p>
  19. ', array('!link' => l('digett.com', 'http://digett.com/sites/digett.com/files/asset_bonus.zip')));
  20. }
  21. }
  22. function asset_bonus_menu($may_cache) {
  23. if (!$may_cache) {
  24. $items[] = array(
  25. 'path' => 'admin/settings/asset/asset_bonus',
  26. 'title' => t('Asset Bonus'),
  27. 'access' => user_access('administer assets'),
  28. 'callback' => 'asset_bonus_admin_overview',
  29. 'type' => MENU_LOCAL_TASK,
  30. 'weight' => 1,
  31. );
  32. $items[] = array(
  33. 'path' => 'admin/settings/asset/asset_bonus/overview',
  34. 'type' => MENU_DEFAULT_LOCAL_TASK,
  35. 'title' => t('Overview'),
  36. 'weight' => -10,
  37. 'access' => user_access('administer assets'),
  38. 'callback' => 'asset_bonus_admin_overview',
  39. );
  40. $items[] = array(
  41. 'path' => 'admin/settings/asset/asset_bonus/mp3player',
  42. 'type' => MENU_LOCAL_TASK,
  43. 'title' => t('mp3 Player'),
  44. 'access' => user_access('administer assets'),
  45. 'callback' => 'drupal_get_form',
  46. 'callback arguments' => array('asset_bonus_admin_mp3player'),
  47. );
  48. }
  49. return $items;
  50. }
  51. function asset_bonus_admin_overview() {
  52. $files = array(
  53. 'audioplayer/audio-player.js',
  54. 'audioplayer/player.swf',
  55. 'swfheader/swfheader.class.php',
  56. 'swfobject/swfobject.js',
  57. );
  58. foreach ($files as $file) {
  59. $found = file_exists(drupal_get_path('module', 'asset_bonus') .'/'. $file);
  60. $output .= '<tr class="'. ($found ? 'ok' : 'error') .'"><th>'. $file .'</th>'
  61. .'<td>'. ($found ? 'Found' : 'Not found') .'</td></tr>';
  62. }
  63. return '<table class="system-status-report">'. $output .'</table>';
  64. }
  65. function asset_bonus_mp3player_colors() {
  66. return array(
  67. 'bg' => array(
  68. 'title' => t('Background'),
  69. 'default' => '#f8f8f8',
  70. ),
  71. 'leftbg' => array(
  72. 'title' => t('Left Background'),
  73. 'default' => '#eeeeee',
  74. ),
  75. 'lefticon' => array(
  76. 'title' => t('Left Icon'),
  77. 'default' => '#666666',
  78. ),
  79. 'rightbg' => array(
  80. 'title' => t('Right Background'),
  81. 'default' => '#cccccc',
  82. ),
  83. 'rightbghover' => array(
  84. 'title' => t('Right Background Hover'),
  85. 'default' => '#999999',
  86. ),
  87. 'righticon' => array(
  88. 'title' => t('Right Icon'),
  89. 'default' => '#666666',
  90. ),
  91. 'righticonhover' => array(
  92. 'title' => t('Right Icon Hover'),
  93. 'default' => '#ffffff',
  94. ),
  95. 'text' => array(
  96. 'title' => t('Text'),
  97. 'default' => '#666666',
  98. ),
  99. 'slider' => array(
  100. 'title' => t('Slider'),
  101. 'default' => '#666666',
  102. ),
  103. 'track' => array(
  104. 'title' => t('Track'),
  105. 'default' => '#ffffff',
  106. ),
  107. 'border' => array(
  108. 'title' => t('Border'),
  109. 'default' => '#666666',
  110. ),
  111. 'loader' => array(
  112. 'title' => t('Loader'),
  113. 'default' => '#9fffb8',
  114. ),
  115. );
  116. }
  117. function asset_bonus_admin_mp3player() {
  118. drupal_add_css('misc/farbtastic/farbtastic.css', 'module', 'all', FALSE);
  119. drupal_add_js('misc/farbtastic/farbtastic.js');
  120. drupal_add_css(drupal_get_path('module', 'asset_bonus') .'/asset_bonus.css');
  121. drupal_add_js(drupal_get_path('module', 'asset_bonus') .'/asset_bonus.js');
  122. $settings = array(
  123. 'asset_bonus_swf' => '/'. drupal_get_path('module', 'asset_bonus') .'/audioplayer/player.swf',
  124. 'asset_bonus_test_mp3' => '/'. drupal_get_path('module', 'asset_bonus') .'/audioplayer/test.mp3',
  125. );
  126. drupal_add_js($settings, 'setting');
  127. $colors = asset_bonus_mp3player_colors();
  128. $form['palette'] = array(
  129. '#type' => 'fieldset',
  130. '#title' => t('Color Palette'),
  131. '#attributes' => array('id' => 'palette'),
  132. );
  133. foreach ($colors as $key => $color) {
  134. $form['palette']['asset_bonus_mp3player_'. $key] = array(
  135. '#type' => 'textfield',
  136. '#title' => $color['title'],
  137. '#default_value' => variable_get('asset_bonus_mp3player_'. $key, $color['default']),
  138. '#size' => 8,
  139. );
  140. }
  141. $form[] = array(
  142. '#value' => '<div id="color-map">'. theme('image', drupal_get_path('module', 'asset_bonus') .'/audioplayer/map.gif') .'</div>',
  143. );
  144. $form[] = array(
  145. '#value' => '<div>Audio Player by:<br/>'. l(theme('image', drupal_get_path('module', 'asset_bonus') .'/audioplayer/logo.gif'), 'http://www.1pixelout.net/code/audio-player-wordpress-plugin/', array(), NULL, NULL, FALSE, TRUE) .'</div>',
  146. );
  147. return system_settings_form($form);
  148. }
  149. function asset_bonus_swfobject_img($asset) {
  150. return drupal_get_path('module', 'asset_bonus') .'/swfobject.jpg';
  151. }
  152. function asset_bonus_asset_formatter($op='list', $asset=NULL, $attr=array()) {
  153. switch ($op) {
  154. case 'info':
  155. $formats['mp3player'] = array(
  156. 'name' => 'mp3 Player',
  157. 'types' => array('local' => array('mp3')),
  158. 'description' => t('Embed the mp3 file using the !1pixelout audio player',
  159. array('!1pixelout' => l('1pixelout', 'http://www.1pixelout.net/code/audio-player-wordpress-plugin/'))),
  160. 'module' => 'asset_bonus',
  161. );
  162. $formats['swfobject'] = array(
  163. 'name' => 'swfobject',
  164. 'types' => array('local' => array('swf', 'flv')),
  165. 'description' => t('Embed the flash movie using the !swfobject javascript library',
  166. array('!swfobject' => l('swfobject', 'http://blog.deconcept.com/swfobject/'))),
  167. 'module' => 'asset_bonus',
  168. );
  169. return $formats;
  170. case 'load':
  171. if ($asset->type=='file' && $asset->file['filemime'] == 'audio/mpeg') {
  172. return array('mp3player');
  173. }
  174. elseif ($asset->type=='file' && $asset->file['filemime'] == 'application/x-shockwave-flash') {
  175. return array('swfobject');
  176. }
  177. case 'img':
  178. case 'form':
  179. $function = 'asset_bonus_'. $attr['format'] .'_'. $op;
  180. if (function_exists($function)) {
  181. return call_user_func($function, $asset);
  182. }
  183. break;
  184. case 'render':
  185. $function = 'asset_bonus_'. $attr['format'];
  186. return theme($function, $asset, $attr);
  187. }
  188. }
  189. function asset_bonus_swfobject_form($asset) {
  190. require_once(drupal_get_path('module', 'asset_bonus') .'/swfheader/swfheader.class.php');
  191. $swf = new swfheader();
  192. $swf->getDimensions($asset->filepath);
  193. $form['width'] = array(
  194. '#type' => 'textfield',
  195. '#title' => t('Width'),
  196. '#description' => t('Width in pixels'),
  197. '#default_value' => !isset($_GET['width']) ? $swf->width : filter_xss($_GET['width']),
  198. '#size' => 5,
  199. '#required' => true,
  200. );
  201. $form['height'] = array(
  202. '#type' => 'textfield',
  203. '#title' => t('Height'),
  204. '#description' => t('Height in pixels'),
  205. '#default_value' => !isset($_GET['height']) ? $swf->height : filter_xss($_GET['height']),
  206. '#size' => 5,
  207. '#required' => true,
  208. );
  209. $form['version'] = array(
  210. '#type' => 'textfield',
  211. '#title' => t('Minimum Version'),
  212. '#default_value' => $swf->version,
  213. '#size' => 5,
  214. '#required' => true,
  215. );
  216. $form['bgcolor'] = array(
  217. '#type' => 'textfield',
  218. '#title' => t('Background Color'),
  219. '#description' => t('Hex formatted background color like #FFFFFF. Make sure to include the #.'),
  220. '#default_value' => '#FFFFFF',
  221. '#size' => 7,
  222. '#required' => true,
  223. );
  224. return $form;
  225. }
  226. function asset_bonus_swfobject_preview($asset) {
  227. require_once(drupal_get_path('module', 'asset_bonus') .'/swfheader/swfheader.class.php');
  228. $swf = new swfheader();
  229. list($w, $h) = explode('|', $swf->getDimensions($asset->filepath));
  230. if (!$w) {
  231. $w = "240";
  232. $h = "180";
  233. }
  234. $r = ($w > $h) ? ($w / 150) : ($h / 150);
  235. $attr = array('height' => ($h/$r), 'width' => ($w/$r), 'version' => $swf->version, 'bgcolor' => '#FFFFFF');
  236. $output = theme('asset_bonus_swfobject', $asset, $attr);
  237. return $output;
  238. }
  239. function asset_bonus_swfobject_details($asset) {
  240. require_once(drupal_get_path('module', 'asset_bonus') .'/swfheader/swfheader.class.php');
  241. $swf = new swfheader();
  242. $swf->getDimensions($asset->filepath);
  243. $details = array(
  244. t('Width') => $swf->width .'px',
  245. t('Height') => $swf->height .'px',
  246. t('Flash Version') => $swf->version,
  247. t('Compressed') => ($swf->compressed ? t('Yes') : t('No')),
  248. t('FPS') => $swf->fps[1],
  249. t('Frames') => $swf->frames,
  250. );
  251. return $details;
  252. }
  253. function theme_asset_bonus_swfobject($asset, $options=array()) {
  254. $embed_id = 'embed-'. preg_replace('/[^A-Za-z_-]/', '-', substr($asset->filename, 0, strlen($asset->filename)-4));
  255. $div_id = 'swfobject-'. preg_replace('/[^A-Za-z_-]/', '-', substr($asset->filename, 0, strlen($asset->filename)-4));
  256. $embed_id = 'swfobject-object-'. $asset->aid;
  257. $div_id = 'swfobject-'. $asset->aid;
  258. $add_variable = '';
  259. $add_param = '';
  260. // build a list of addVariable statements for each flashVar
  261. foreach ((array)$options['vars'] as $k => $v) {
  262. $add_variable .= "oSwf.addVariable('$k','$v');\n";
  263. }
  264. if ($asset->extension=="flv") {
  265. $add_variable .= "oSwf.addVariable('file','". $asset->url ."');";
  266. $add_param .= "oSwf.addParam('allowfullscreen','true');\n";
  267. $asset->url = '/'. drupal_get_path('module', 'asset_bonus') .'/swfobject/flvplayer.swf';
  268. // if (arg(2)!="edit" && (arg(0)!="node" || $options['width']==0)) {
  269. if (arg(2)!="edit" && ($options['height']=="112.5" || $options['height']=="100")) {
  270. // Set a default width/height if none is available or when we're looking at an asset gallery (panels)
  271. $options['width'] = 204;
  272. $options['height'] = 145;
  273. }
  274. elseif (arg(2)=="edit") {
  275. // Set a static width/height to keep the asset cck gui clean
  276. $options['width'] = 120;
  277. $options['height'] = 80;
  278. }
  279. }
  280. elseif (substr($asset->url, 0, 4) != "http") {
  281. $asset->url = '/'. $asset->url;
  282. }
  283. // build a list of addParam statements for known params
  284. if ($options['transparent']) {
  285. $add_param .= "oSwf.addParam('wmode','transparent');\n";
  286. }
  287. if (empty($options['version'])) $options['version'] = "0";
  288. // We're not using drupal_add_js(drupal_get_path('module','asset_bonus').'/swfobject/swfobject.js') because of caching issues
  289. $swfobject = base_path() . drupal_get_path('module', 'asset_bonus') .'/swfobject/swfobject.js';
  290. $url = file_create_url($asset->file['filepath']);
  291. $output = <<<OUT
  292. <script type="text/javascript" src="{$swfobject}"></script>
  293. <div id="$div_id" class="asset-swfobject">Video placeholder</div>
  294. <script type="text/javascript">
  295. var oSwf = new SWFObject("{$url}","$embed_id","{$options['width']}","{$options['height']}","{$options['version']}","{$options['bgcolor']}");
  296. $add_variable
  297. $add_param
  298. oSwf.write("$div_id");
  299. oSwf = null;
  300. </script>
  301. OUT;
  302. return $output;
  303. }
  304. function asset_bonus_mp3player_form($asset) {
  305. $form['width'] = array('#type' => 'hidden', '#value' => '290');
  306. $form['height'] = array('#type' => 'hidden', '#value' => '24');
  307. return $form;
  308. }
  309. function asset_bonus_mp3player_preview($asset) {
  310. return theme('asset_bonus_mp3player', $asset, $attr);
  311. }
  312. function asset_bonus_mp3player_img($asset) {
  313. return drupal_get_path('module', 'asset_bonus') .'/audioplayer.png';
  314. }
  315. function theme_asset_bonus_mp3player($asset, $options=array()) {
  316. drupal_add_js(drupal_get_path('module', 'asset_bonus') .'/swfobject/swfobject.js');
  317. drupal_add_js(drupal_get_path('module', 'asset_bonus') .'/audioplayer/audio-player.js');
  318. $swffile = base_path() . drupal_get_path('module', 'asset_bonus') .'/audioplayer/player.swf';
  319. $colors = asset_bonus_mp3player_colors();
  320. foreach ($colors as $key => $color_data) {
  321. $color = variable_get('asset_bonus_mp3player_'. $key, $color_data['default']);
  322. if ($color) {
  323. $color = str_replace('#', '0x', $color);
  324. $colorvars .= "oSwf.addVariable('$key','$color');";
  325. }
  326. }
  327. $file_url = file_create_url($asset->file['filepath']);
  328. $output = <<<OUT
  329. <div id="mp3player-{$asset->aid}" class="asset-swfobject">Audio placeholder</div>
  330. <script type="text/javascript">
  331. var oSwf = new SWFObject("$swffile","mp3player-object-{$asset->aid}","190","24","7","#FFFFFF");
  332. oSwf.addVariable('playerID','{$asset->aid}');
  333. oSwf.addVariable('soundFile','{$file_url}');
  334. $colorvars
  335. oSwf.addParam('wmode','transparent');
  336. oSwf.addParam('menu','false');
  337. oSwf.write("mp3player-{$asset->aid}");
  338. oSwf = null;
  339. </script>
  340. OUT;
  341. return $output;
  342. }