diff -urp mp3player/mp3player.install mp3player_new/mp3player.install --- mp3player/mp3player.install 2009-07-19 11:24:04.000000000 -0500 +++ mp3player_new/mp3player.install 2009-08-07 10:21:05.000000000 -0500 @@ -21,6 +21,9 @@ function mp3player_install() { */ function mp3player_uninstall() { drupal_uninstall_schema('mp3player'); + // Delete the variables we created. + variable_del('mp3player_page_list'); + variable_del('mp3player_page_init_action'); } function mp3player_schema() { @@ -216,4 +219,4 @@ function mp3player_update_1() { $ret = array(); db_add_field($ret, 'mp3player_players', 'checkpolicy', array('type' => 'varchar', 'length' => 3, 'not null' => TRUE, 'default' => 'no')); return $ret; -} \ No newline at end of file +} diff -urp mp3player/mp3player.module mp3player_new/mp3player.module --- mp3player/mp3player.module 2009-07-19 11:24:04.000000000 -0500 +++ mp3player_new/mp3player.module 2009-08-07 10:26:34.000000000 -0500 @@ -164,7 +164,24 @@ function mp3player_settings() { '#description' => t('Either use default description field or ID3 template file.'), ); } - + $page_options = array( + 'page_enable' => t('Load only on the listed pages.'), + 'page_disable' => t('Load on every page except the listed pages.'), + ); + $form['mp3player_page_init']['mp3player_page_init_action'] = array( + '#type' => 'radios', + '#options' => $page_options, + '#title' => t('Enable mp3player on specific pages'), + '#default_value' => variable_get('mp3player_page_init_action', 'page_disable'), + ); + // Add text input for list of pages to take specific action on. + $form['mp3player_page_init']['mp3player_page_list'] = array( + '#type' => 'textarea', + '#title' => t('Pages'), + '#description' => t('List one page per line as Drupal paths. The * character is a wildcard. Example paths are "node/add/page" and "node/add/*". Use <front> to match the front page.'), + '#default_value' => variable_get('mp3player_page_list', ''), + ); + return system_settings_form($form); } } @@ -867,20 +884,22 @@ function mp3player_player_delete_submit( * Implementation of hook_init(). */ function mp3player_init() { - if(!file_exists(drupal_get_path('module', 'mp3player').'/mp3player/audio-player.js') || !file_exists(drupal_get_path('module', 'mp3player').'/mp3player/player.swf')) { - drupal_set_message(t('%file1 or %file2 were not found in %directory, download the standalone WordPress Audio Player.', array('%file1' => 'audio-player.js', '%file2' => 'player.swf', '%directory' => '/'.drupal_get_path('module', 'mp3player').'/mp3player/')), 'error'); - } + if (mp3player_exclude_these_paths() != 1) { + if(!file_exists(drupal_get_path('module', 'mp3player').'/mp3player/audio-player.js') || !file_exists(drupal_get_path('module', 'mp3player').'/mp3player/player.swf')) { + drupal_set_message(t('%file1 or %file2 were not found in %directory, download the standalone WordPress Audio Player.', array('%file1' => 'audio-player.js', '%file2' => 'player.swf', '%directory' => '/'.drupal_get_path('module', 'mp3player').'/mp3player/')), 'error'); + } + + drupal_add_js(drupal_get_path('module', 'mp3player').'/mp3player/audio-player.js'); - drupal_add_js(drupal_get_path('module', 'mp3player').'/mp3player/audio-player.js'); - - //If cache isn't set, set it. - if(cache_get('mp3player_default') == '') { - mp3player_rebuild_cache(); + //If cache isn't set, set it. + if(cache_get('mp3player_default') == '') { + mp3player_rebuild_cache(); + } + + $js_audio_settings = cache_get('mp3player_default'); + + drupal_add_js($js_audio_settings->data, 'inline'); } - - $js_audio_settings = cache_get('mp3player_default'); - - drupal_add_js($js_audio_settings->data, 'inline'); } /** @@ -1199,4 +1218,25 @@ function mp3player_simplecdnapi($op) { ); break; } -} \ No newline at end of file +} + +/** + * Return TRUE if current path is disabled for mp3player according to + * mp3player_page_list and mp3player_page_init_action. + */ +function mp3player_exclude_these_paths() { + $action = variable_get('mp3player_page_init_action', 'page_disable'); + $page_list = variable_get('mp3player_page_list', ''); + + if (!empty($page_list)) { + // Retrieve Drupal alias for the current path (if exists). + $alias = drupal_get_path_alias($_GET['q']); + + if (drupal_match_path($_GET['q'], $page_list) || drupal_match_path($alias, $page_list)) { + return ($action == 'page_disable' ? 1 : 0); + } + } + + return ($action == 'page_disable' ? 0 : 1); +} +