/** * Registers the shortcode for WP usage * * * @return <type> */ public static function embedShortcode($atts) { //make sure we have params we need $html = ''; if (isset($atts['podcast']) && !empty($atts['podcast'])) { if (strpos($atts['podcast'], 'libsyn-podcast-') !== false) { //regular my-podcast $atts['show_id'] = str_replace('libsyn-podcast-', '', $atts['podcast']); unset($atts['podcast']); $html .= self::getDataForLibsynPodcast($atts); } elseif ($atts['podcast'] === 'my-podcast') { //my-podcast with no show_id $plugin = new Service(); $api = $plugin->getApis(); $show_id = $api->getShowId(); if (is_numeric($show_id)) { $atts['show_id'] = $show_id; unset($atts['podcast']); } $html .= self::getDataForLibsynPodcast($atts); } else { //handle podcast url if (isset($atts['podcast']) && !empty($atts['podcast'])) { $atts['feed_url'] = $atts['podcast']; unset($atts['podcast']); } $html .= self::getDataForPodcast($atts); } return $html; } }
/** * Outputs the options form on admin * * @param array $instance The widget options */ public function form($instance) { $plugin = new Service(); $api = $plugin->getApis(); $my_podcast_text = isset($api) && $api !== false ? "libsyn-podcast-" . $api->getShowId() : "my-podcast"; $podcast_url = !empty($instance['podcast_url']) ? $instance['podcast_url'] : __('', 'text_domain'); $playlist_type = !empty($instance['playlist_type']) ? $instance['playlist_type'] : __('', 'text_domain'); $playlist_feed_type = !empty($instance['playlist_feed_type']) ? $instance['playlist_feed_type'] : __('', 'text_domain'); $playlist_video_width = !empty($instance['playlist_video_width']) ? $instance['playlist_video_width'] : 240; $playlist_video_height = !empty($instance['playlist_video_height']) ? $instance['playlist_video_height'] : 180; //get the playlist id $typeStr = $this->get_field_id('playlist_type'); $typeArr = explode('-', $typeStr); $id = intval($typeArr[2]); ?> <p> <span style="font-weight:bold;">Playlist Type:</span><br> <input type="radio" name="<?php echo $this->get_field_name('playlist_type'); ?> " value="audio" id="<?php echo $this->get_field_id('playlist_type'); ?> _audio" onclick="hideDimensionsDiv<?php echo $id; ?> ()" <?php echo esc_attr($playlist_type) === 'audio' ? 'checked="checked"' : ''; if (empty($playlist_type)) { echo 'checked="checked"'; } ?> /><label for="<?php _e('playlist_type', 'playlist-widget'); ?> ">Audio</label> <input type="radio" name="<?php echo $this->get_field_name('playlist_type'); ?> " value="video" id="<?php echo $this->get_field_id('playlist_type'); ?> _video" onclick="showDimensionsDiv<?php echo $id; ?> ()" <?php echo esc_attr($playlist_type) === 'video' ? 'checked="checked"' : ''; ?> /><label for="<?php _e('playlist_type', 'playlist-widget'); ?> ">Video</label> <div style="padding:5px;display:none;" id="<?php echo $this->get_field_id('playlist_type'); ?> _playlist-dimensions-div"> <label for="<?php _e('playlist_video_width', 'playlist-widget'); ?> ">Width</label> <input name="<?php echo $this->get_field_name('playlist_video_width'); ?> " id="playlist_video_width-<?php _e($id); ?> " type="text" value="<?php _e($playlist_video_width); ?> "> <br> <label for="<?php _e('playlist_video_height', 'playlist-widget'); ?> ">Height</label> <input name="<?php echo $this->get_field_name('playlist_video_height'); ?> " id="playlist_video_height-<?php _e($id); ?> " type="text" value="<?php _e($playlist_video_height); ?> "> </div> <br><span style="font-weight:bold;">Playlist Source:</span><br> <input type="radio" name="<?php echo $this->get_field_name('playlist_feed_type'); ?> " value="<?php echo $my_podcast_text; ?> " id="my-podcast-<?php _e($id); ?> " onclick="hideOtherUrl<?php echo $id; ?> ()" <?php echo esc_attr($playlist_feed_type) == $my_podcast_text ? 'checked="checked"' : ''; if (empty($playlist_feed_type)) { echo 'checked="checked"'; } ?> /><label for="<?php _e('playlist_feed_type', 'playlist-widget'); ?> ">My Libsyn Podcast</label> <br> <input type="radio" name="<?php echo $this->get_field_name('playlist_feed_type'); ?> " value="other-podcast" id="other-podcast-<?php _e($id); ?> " onclick="showOtherUrl<?php echo $id; ?> ()" <?php echo esc_attr($playlist_feed_type) == 'other-podcast' ? 'checked="checked"' : ''; ?> /><label for="<?php _e('playlist_feed_type', 'playlist-widget'); ?> ">Other Podcast</label> <div id="<?php echo $this->get_field_id('podcast_url'); ?> _div" style="display:none;"> <p> <label for="<?php _e('podcast_url', 'playlist-widget'); ?> "><?php _e('Podcast Url:'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('podcast_url'); ?> " name="<?php echo $this->get_field_name('podcast_url'); ?> " type="text" value="<?php echo esc_attr($podcast_url); ?> " type="url" class="other-url" placeholder="http://www.your-wordpress-site.com/rss"> </p> </div> <input type="hidden" id="<?php echo $this->get_field_id('playlist_widget_id'); ?> " name="<?php echo $this->get_field_name('playlist_widget_id'); ?> " value="<?php _e($id); ?> "> </p> <script type="text/javascript"> var showOtherUrl<?php echo $id; ?> = function(){ jQuery('#<?php echo $this->get_field_id('podcast_url'); ?> _div').fadeIn('normal'); } var hideOtherUrl<?php echo $id; ?> = function(){ jQuery('#<?php echo $this->get_field_id('podcast_url'); ?> _div').hide(); } var showDimensionsDiv<?php echo $id; ?> = function(){ jQuery("#<?php echo $this->get_field_id('playlist_type'); ?> _playlist-dimensions-div").fadeIn("normal"); } var hideDimensionsDiv<?php echo $id; ?> = function(){ jQuery("#<?php echo $this->get_field_id('playlist_type'); ?> _playlist-dimensions-div").hide(); } if (jQuery('#<?php echo $this->get_field_id('playlist_type'); ?> _video:checked').val() == 'video') { showDimensionsDiv<?php echo $id; ?> (); } if (jQuery('#other-podcast-<?php _e($id); ?> :checked').val() == 'other-podcast') { showOtherUrl<?php echo $id; ?> (); } jQuery( document ).on( 'widget-added widget-updated', function() { //console.log(jQuery("[id$='podcast_url_div']")); jQuery("[id$='playlist_type_video']").click(function(){ jQuery("[id$='playlist_type_playlist-dimensions-div']").fadeIn("normal"); }); jQuery("[id$='playlist_type_audio']").click(function(){ jQuery("[id$='playlist_type_playlist-dimensions-div']").hide(); }); jQuery("[id^='other-podcast']").click(function(){ jQuery("[id$='podcast_url_div']").fadeIn('normal'); }); jQuery("input[id^='my-podcast-']").click(function(){ jQuery("[id$='podcast_url_div']").hide(); }); }); </script> <?php }
/** * Handle ajax page for loading post page form data * * * @return <type> */ public static function loadFormData() { if (intval(get_query_var('load_libsyn_media')) == 1 && current_user_can('upload_files') && current_user_can('edit_posts')) { global $wpdb; $error = false; $plugin = new Service(); $api = $plugin->getApis(); $wpdb->delete($wpdb->prefix . 'posts', array('post_mime_type' => 'libsyn/ftp-unreleased')); $wpdb->delete($wpdb->prefix . 'posts', array('post_mime_type' => 'audio/ftp-unreleased')); $wpdb->delete($wpdb->prefix . 'posts', array('post_mime_type' => 'video/ftp-unreleased')); $wpdb->get_results($wpdb->prepare("DELETE FROM " . $wpdb->prefix . "postmeta WHERE meta_value LIKE %s", "/libsyn/ftp-unreleased%")); if ($api instanceof Api && !$api->isRefreshExpired()) { $refreshApi = $api->refreshToken(); if ($refreshApi) { //successfully refreshed /* Remove and add FTP/Unreleased Media */ $ftp_unreleased = $plugin->getFtpUnreleased($api)->{'ftp-unreleased'}; if (!empty($ftp_unreleased)) { foreach ($ftp_unreleased as $media) { // We need to make sure we are working with only audio/video files... if (strpos($media->mime_type, 'audio') !== false || strpos($media->mime_type, 'video') !== false) { //for new versions of wordpress - handle media info in metadata if (strpos($media->mime_type, 'video') !== false) { } elseif (strpos($media->mime_type, 'audio') !== false) { } else { //neither audio or video } $file_name = explode('.', $media->file_name); $mime_type = explode('/', $media->mime_type); $data = array('post_author' => get_current_user_id(), 'post_date' => date("Y-m-d H:i:s"), 'post_date_gmt' => date("Y-m-d H:i:s"), 'post_content' => 'Libsyn FTP/Unreleased Media: ' . $media->file_name, 'post_title' => $file_name[0], 'post_excerpt' => '', 'post_status' => 'inherit', 'comment_status' => 'open', 'ping_status' => 'closed', 'post_password' => '', 'post_name' => 'libsyn-ftp-' . $media->content_id, 'to_ping' => '', 'pinged' => '', 'post_modified' => date("Y-m-d H:i:s"), 'post_modified_gmt' => date("Y-m-d H:i:s"), 'post_content_filtered' => '', 'post_parent' => 0, 'guid' => $media->file_name, 'menu_order' => 0, 'post_type' => 'attachment', 'post_mime_type' => 'libsyn/ftp-unreleased', 'comment_count' => 0); //$wpdb->insert($wpdb->prefix . 'posts', $data); $post_id = wp_insert_post($data, false); //add post meta add_post_meta($post_id, '_wp_attached_file', '/libsyn/ftp-unreleased/' . $media->file_name); } } } /* Get categories and send output on success */ $categories = $plugin->getCategories($api)->{'categories'}; if (!is_array($categories)) { $categories = array($categories); } $json = array(); foreach ($categories as $category) { if (isset($category->item_category_name)) { $json[] = $category->item_category_name; } } //if(empty($json)) $error = true; } else { $error = true; } } else { $error = true; } //set output header('Content-Type: application/json'); if (!$error) { echo json_encode($json); } else { echo json_encode(array()); } exit; } }