From e0e81f553fa6252709a6853771f08ce2f5964e28 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 29 Nov 2009 12:37:19 -0500 Subject: [PATCH] initial commit --- .gitignore | 3 ++ quick-audio-embed.php | 113 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 .gitignore create mode 100644 quick-audio-embed.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..33711c3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.settings/ +.buildpath +.project diff --git a/quick-audio-embed.php b/quick-audio-embed.php new file mode 100644 index 0000000..f8ce67f --- /dev/null +++ b/quick-audio-embed.php @@ -0,0 +1,113 @@ +load(); + add_filter('the_content', array(&$qae, 'the_content')); + add_action('admin_menu', array(&$qae, 'admin_menu')); + + if (isset($_REQUEST['qae'])) { + if (is_array($_REQUEST['qae'])) { + if (isset($_REQUEST['qae']['_nonce'])) { + if (wp_verify_nonce($_REQUEST['qae']['_nonce'], 'quick-audio-embed')) { + $qae->save($_REQUEST['qae']); + } + } + } + } + } + + function load() { + $this->settings = array( + 'dimensions' => '300x50' + ); + + $options = get_option('quick-audio-embed-settings'); + if (is_array($options)) { + $this->settings = array_merge($this->settings, $options); + } + } + + function save($info) { + foreach ($info as $key => $value) { + switch ($key) { + case 'dimensions': + if (count($result = explode('x', $value)) !== 2) { + unset($info[$key]); + } else { + $result = array_map('intval', $result); + $info[$key] = implode('x', $result); + } + break; + } + } + + $this->settings = $info; + update_option('quick-audio-embed-settings', $info); + } + + function admin_menu() { + add_settings_section('quick-audio-embed', __('Quick Audio Embed', 'quick-audio-embed'), array(&$this, 'media_settings'), 'media'); + + add_settings_field('qae-dimensions', __('Dimensions', 'quick-audio-embed'), array(&$this, 'qae_dimensions'), 'media', 'quick-audio-embed'); + } + + function the_content($content = '') { + return preg_replace_callback('#]+href="(?P[^\"]+\.mp3)"[^\>]*>.*#mis', array(&$this, '_the_content_callback'), $content); + } + + function media_settings() { ?> +

Quick Audio Embed takes any linked-to MP3 file and wraps it in Google Reader's Audio Player.

+ + + +

+ The dimensions of the player as widthxheight: 300x50 +

+ settings['dimensions']); + + return sprintf(' + + ', esc_url($matches['url']), esc_attr($dimensions[0]), esc_attr($dimensions[1])); + } +} + +add_action('init', array('QuickAudioEmbed', 'init'));