[^<]+<\/a>/i", "ap_replace", $content ); // Replace [audio syntax] if( in_array( "default", $ap_behaviour ) ) $content = preg_replace_callback( "/\[audio:(([^]]+))]/i", "ap_replace", $content ); // Enclosure integration if( in_array( "enclosure", $ap_behaviour ) ) { $enclosure = get_enclosed($post_id); // Insert prefix and postfix clips if set $prefixAudio = get_option( "audio_player_prefixaudio" ); if( $prefixAudio != "" ) $prefixAudio .= ","; $postfixAudio = get_option( "audio_player_postfixaudio" ); if( $postfixAudio != "" ) $postfixAudio = "," . $postfixAudio; if( count($enclosure) > 0 ) { for($i = 0;$i < count($enclosure);$i++) { // Make sure the enclosure is an mp3 file and it hasn't been inserted into the post yet if( preg_match( "/.*\.mp3$/", $enclosure[$i] ) == 1 && !in_array( $enclosure[$i], $ap_instances ) ) { $content .= "\n\n" . ap_getplayer( $prefixAudio . $enclosure[$i] . $postfixAudio ); } } } } return $content; } // Callback function for preg_replace_callback function ap_replace($matches) { global $ap_audioURL, $ap_instances; // Split options $data = preg_split("/[\|]/", $matches[2]); $files = array(); if(!is_feed()) { // Insert prefix clip if set $prefixAudio = get_option( "audio_player_prefixaudio" ); if( $prefixAudio != "" ) array_push( $files, $prefixAudio ); } // If file doesn't start with http://, assume it is in the default audio folder foreach( explode( ",", $data[0] ) as $afile ) { if(strpos($afile, "http://") !== 0) $afile = $ap_audioURL . "/" . $afile; array_push( $files, $afile ); // Add source file to instances already added to the post array_push( $ap_instances, $afile ); } if(!is_feed()) { // Insert postfix clip if set $postfixAudio = get_option( "audio_player_postfixaudio" ); if( $postfixAudio != "" ) array_push( $files, $postfixAudio ); } $file = implode( ",", $files ); // Build runtime options array $options = array(); for($i=1;$i $value) $flashVars .= '&' . $key . '=' . rawurlencode($value); if(is_feed()) { // We are in a feed so use RSS alternate content option switch( get_option( "audio_player_rssalternate" ) ) { case "download": // Get filenames from path and output a link for each file in the sequence $files = explode(",", $source); $links = ""; for($i=0;$iDownload audio file (' . $fileName . ')
'; } return $links; break; case "nothing": return ""; break; case "custom": return get_option( "audio_player_rsscustomalternate" ); break; } } // Not in a feed so return formatted object tag else { if( get_option("audio_player_transparentpagebg") ) $bgparam = ''; else $bgparam = ''; return '' . $bgparam . ''; } } // Add filter hook add_filter('the_content', 'ap_insert_player_widgets'); // Helper function for displaying a system message function ap_showMessage( $message ) { echo '

' . $message . '

'; } // Option panel functionality function ap_options_subpanel() { global $ap_colorkeys, $ap_options, $ap_version, $ap_updateURL, $ap_docURL; if( $_POST['ap_updateCheck'] ) { // Update check. Gets the file at the update URL , reads and compares it with the current version $ap_contents = ""; if( function_exists( "curl_init" ) ) { $source = curl_init(); curl_setopt( $source, CURLOPT_URL, $ap_updateURL ); curl_setopt( $source, CURLOPT_CONNECTTIMEOUT, 10 ); curl_setopt( $source, CURLOPT_FAILONERROR, 1 ); curl_setopt( $source, CURLOPT_RETURNTRANSFER, 1 ); $ap_contents = curl_exec( $source ); if( curl_errno( $source ) > 0 ) { $ap_contents = "error"; } else curl_close( $source ); } else if( ini_get( "allow_url_fopen" ) ) { if( $source = @fopen( $ap_updateURL, "r" ) ) { while( !feof( $source ) ) { $ap_contents .= fread( $source, 8192 ); } fclose($source); } else $ap_contents = "error"; } // Errors if( $ap_contents == "error" ) { ap_showMessage( 'Failed to contact update server. Please visit 1 Pixel Out to check for updates.' ); } else if( $ap_contents == "" ) { ap_showMessage( 'Some PHP functionality used by the Upgrade wizard are disabled on your server. Please visit 1 Pixel Out to check for updates.' ); } else if( $ap_contents != $ap_version ) { // A new version is available so announce this with a message // Check that the zip extension is loaded and the PHP engine is 4.2.0 at least (otherwise the upgrade wizard won't work) if( version_compare( phpversion(), "4.2.0" ) == 1 && in_array( "zip", get_loaded_extensions() ) ) { ap_showMessage( 'Version ' . $ap_contents . ' of the Audio Player plugin is now available! Upgrade now.' ); } else { ap_showMessage( 'Version ' . $ap_contents . ' of the Audio Player plugin is now available! Download it here.' ); } } else { // Plugin is up-to-date ap_showMessage( "Your copy of Audio Player plugin is up-to-date." ); } } else if( $_POST['Submit'] ) { // Update plugin options // Set audio web path if( substr( $_POST['ap_audiowebpath'], -1 ) == "/" ) $_POST['ap_audiowebpath'] = substr( $_POST['ap_audiowebpath'], 0, strlen( $_POST['ap_audiowebpath'] ) - 1 ); update_option('audio_player_web_path', $_POST['ap_audiowebpath']); // Update behaviour and rss alternate content options update_option('audio_player_behaviour', implode(",", $_POST['ap_behaviour'])); update_option('audio_player_rssalternate', $_POST['ap_rssalternate']); update_option('audio_player_rsscustomalternate', $_POST['ap_rsscustomalternate']); update_option('audio_player_prefixaudio', $_POST['ap_audioprefixwebpath']); update_option('audio_player_postfixaudio', $_POST['ap_audiopostfixwebpath']); // Update colour options foreach( $ap_colorkeys as $colorkey ) { // Ignore missing or invalid color values if( isset( $_POST["ap_" . $colorkey . "color"] ) && preg_match( "/#[0-9A-Fa-f]{6}/", $_POST["ap_" . $colorkey . "color"] ) == 1 ) { update_option( "audio_player_" . $colorkey . "color", str_replace( "#", "0x", $_POST["ap_" . $colorkey . "color"] ) ); } } if(isset( $_POST["ap_pagebgcolor"] )) update_option('audio_player_pagebgcolor', $_POST['ap_pagebgcolor']); update_option('audio_player_transparentpagebg', isset( $_POST["ap_transparentpagebg"] )); // Need to do this again for the player preview on the options panel ap_set_options(); // Print confirmation message ap_showMessage( "Options updated." ); } $ap_behaviour = explode(",", get_option("audio_player_behaviour")); $ap_rssalternate = get_option('audio_player_rssalternate'); // Preview player options $ap_demo_options = array(); $ap_demo_options["autostart"] = "yes"; $ap_demo_options["loop"] = "yes"; // Include options panel include( "audio-player/options-panel.php" ); } // Add options page to admin menu function ap_post_add_options() { add_options_page('Audio player options', 'Audio player', 8, basename(__FILE__), 'ap_options_subpanel'); } add_action('admin_menu', 'ap_post_add_options'); // Output script tag in WP front-end head function ap_wp_head() { global $ap_playerID; echo ''; echo "\n"; } add_action('wp_head', 'ap_wp_head'); // Output script tag in WP admin head function ap_wp_admin_head() { global $ap_playerID; echo ''; echo "\n"; echo ''; echo "\n"; } add_action('admin_head', 'ap_wp_admin_head'); ?>