AudioBoo website. Version: 1.0.0 Author: BestBefore Author URI: http://bestbefore.tv/ */ //define('MAGPIE_CACHE_AGE', 120); define('MAGPIE_CACHE_ON', 0); //2.7 Cache Bug define('MAGPIE_INPUT_ENCODING', 'UTF-8'); define('MAGPIE_OUTPUT_ENCODING', 'UTF-8'); $audioboo_options['widget_fields']['widgettitle'] = array('label'=>'Widget title:', 'type'=>'text', 'default'=>''); $audioboo_options['widget_fields']['username'] = array('label'=>'Username:', 'type'=>'user', 'default'=>''); $audioboo_options['widget_fields']['num'] = array('label'=>'Number of audioboos:', 'type'=>'text', 'default'=>'5'); $audioboo_options['widget_fields']['title'] = array('label'=>'Show title:', 'type'=>'checkbox', 'default'=>true); $audioboo_options['widget_fields']['createDate'] = array('label'=>'Show create date:', 'type'=>'checkbox', 'default'=>true); $audioboo_options['widget_fields']['link'] = array('label'=>'Show link:', 'type'=>'checkbox', 'default'=>false); $audioboo_options['prefix'] = 'audioboo'; $audioboo_LOCALTEST = false; // should read user profile (download boosURL) $audiobooReadUserProfile = false; // audioboo widget stuff function widget_audioboo_init() { if ( !function_exists('register_sidebar_widget') ) return; $check_options = get_option('widget_audioboo'); if ($check_options['number']=='') { $check_options['number'] = 1; update_option('widget_audioboo', $check_options); } /* BLOG PAGE */ function widget_audioboo($args, $number = 1) { global $audioboo_options; // $args is an array of strings that help widgets to conform to // the active theme: before_widget, before_title, after_widget, // and after_title are the array keys. Default tags: li and h2. extract($args); // Each widget can store its own options. We keep strings here. //include_once(ABSPATH . WPINC . '/rss.php'); $options = get_option('widget_audioboo'); // fill options with default values if value is not set $item = $options[$number]; foreach($audioboo_options['widget_fields'] as $key => $field) { if (! isset($item[$key])) { $item[$key] = $field['default']; } } // These lines generate our output. // Display audioboo messages echo $before_widget . $before_title . $item['widgettitle'] . $after_title; syslog (LOG_ALERT,$before_widget); echo '
'; echo '
'; echo '
'; echo $after_widget; } /* ADMIN */ // This is the function that outputs the form to let the users edit // the widget's title. It's an optional feature that users cry for. function widget_audioboo_control($number) { global $audioboo_options, $audiobooGetUserIdURL, $audiobooReadUserProfile; // Get our options and see if we're handling a form submission. $options = get_option('widget_audioboo'); $username = $options[1]['username']; $audioBoosURL = ''; if ( isset($_POST['audioboo-submit']) ) { // form submited (POST) $postUsername = $_POST['audioboo_username']; // if we submited audoboo's admin form if ($postUsername == $username) { $audioBoosURL = $_POST["audioboo-boosURL"]; if ( isset($_POST['audioboo-boosURL']) ) { if ($audioBoosURL) { if ($options['audioboo-boosURL']!=$audioBoosURL) { $options['audioboo-boosURL'] = $audioBoosURL; update_option('widget_audioboo', $options); } } else { // delete option???? check it } } } else { unset($options['audioboo-boosURL']); update_option('widget_audioboo', $options); } foreach($audioboo_options['widget_fields'] as $key => $field) { $options[$number][$key] = $field['default']; $field_name = sprintf('%s_%s', $audioboo_options['prefix'], $key); if ($field['type'] == 'text' || $field['type'] == 'user') { $options[$number][$key] = strip_tags(stripslashes($_POST[$field_name])); } elseif ($field['type'] == 'checkbox') { $options[$number][$key] = isset($_POST[$field_name]); } } update_option('widget_audioboo', $options); } else { // probably GET $audioBoosURL = $options['audioboo-boosURL'];; if ($audioBoosURL == '') { $audiobooReadUserProfile = true; } } foreach($audioboo_options['widget_fields'] as $key => $field) { $field_name = sprintf('%s_%s', $audioboo_options['prefix'], $key); $field_checked = ''; if ($field['type'] == 'user') { $field_value = htmlspecialchars($options[$number][$key], ENT_QUOTES); printf('

user added
'); else printf('
Sorry - we couldn\'t find that user
'); printf('

'); continue; } elseif ($field['type'] == 'text') { $field_value = htmlspecialchars($options[$number][$key], ENT_QUOTES); } elseif ($field['type'] == 'checkbox') { $field_value = 1; if (! empty($options[$number][$key])) { $field_checked = 'checked="checked"'; } } printf('

', $field_name, __($field['label']), $field_name, $field_name, $field['type'], $field_value, $field['type'], $field_checked); } echo ''; echo ''; } /* ADMIN */ function widget_audioboo_setup() { $options = $newoptions = get_option('widget_audioboo'); if ( isset($_POST['audioboo-number-submit']) ) { $number = (int) $_POST['audioboo-number']; $newoptions['number'] = $number; } if ( $options != $newoptions ) { update_option('widget_audioboo', $newoptions); widget_audioboo_register(); } } function widget_audioboo_register() { $options = get_option('widget_audioboo'); $dims = array('width' => 300, 'height' => 300); $class = array('classname' => 'widget_audioboo'); for ($i = 1; $i <= 9; $i++) { $name = sprintf(__('audioboo #%d'), $i); $id = "audioboo-$i"; // Never never never translate an id wp_register_sidebar_widget($id, $name, $i <= $options['number'] ? 'widget_audioboo' : /* unregister */ '', $class, $i); wp_register_widget_control($id, $name, $i <= $options['number'] ? 'widget_audioboo_control' : /* unregister */ '', $dims, $i); } add_action('sidebar_admin_setup', 'widget_audioboo_setup'); } widget_audioboo_register(); } // Run our code later in case this loads prior to any required plugins. add_action('widgets_init', 'widget_audioboo_init'); // add CSS /* * register with hook 'wp_print_styles' */ add_action('wp_print_styles', 'audioboo_css'); /* * Enqueue style-file, if it exists. */ function audioboo_css() { // global $audioboo_LOCALTEST; $myStyleFile = ''; // if ($audioboo_LOCALTEST) $myStyleFile = WP_PLUGIN_URL.'/audioboo-wp/audioboo.css'; // else // $myStyleFile = 'http://audioboo.fm/wordpressres/audioboo.css'; wp_register_style('audiobooStyleSheets', $myStyleFile); wp_enqueue_style( 'audiobooStyleSheets'); } // add JavaScript - near end of document function audioboo_js() { global $audioboo_LOCALTEST; $audioboojs_url = ''; if ($audioboo_LOCALTEST) $audioboojs_url = get_bloginfo('wpurl') . '/wp-content/plugins/audioboo-wp/res/audioboo.js'; else $audioboojs_url = 'http://audioboo.fm/wordpressres/audioboo.js'; // add JavaScript - (set global variables) $options = get_option('widget_audioboo'); $item = $options[1]; echo ''; echo ''; $boosURL = $options['audioboo-boosURL']; $limit = $options[1]['num']; if ($limit =='') $limit=1; $audioboo_callback = ''; if ($boosURL) { $audioboo_callback = $boosURL . "?fmt=jsonp&callback=audiobooJson&find%5Blimit%5D=" . $limit; } if ( $audioboo_callback) echo ""; } function audiobooAdmin_js() { global $audiobooReadUserProfile, $audioboo_LOCALTEST; if (!$audiobooReadUserProfile) return; $audiobooAdminjs_url = ''; if ($audioboo_LOCALTEST) $audiobooAdminjs_url = get_bloginfo('wpurl') . '/wp-content/plugins/audioboo-wp/res/audiobooAdmin.js'; else $audiobooAdminjs_url = 'http://audioboo.fm/wordpressres/audiobooAdmin.js'; echo ''; $audiobooGetUserID_callback = ''; $options = get_option('widget_audioboo'); $username = $options[1]['username']; if ($username) { $audiobooGetUserID_callback = "http://audioboo.fm/profile/". $username . "?fmt=jsonp&callback=audiobooUserProfile"; echo ''; } } add_action('wp_footer', 'audioboo_js'); add_action('admin_footer', 'audiobooAdmin_js'); ?>