Exemplo n.º 1
0
 /**
  * Main Post script which handles Libsyn API posting. Used for post scheduled/immediate post.
  * 
  * @param <WP_Post> $post 
  * @param <int> $post_id 
  * @param <bool> $schedule 
  * @param <bool> $draft 
  * 
  * @return <Libsyn_Item|mixed>
  */
 public static function postEpisode($post, $isSchedule = false, $isDraft = false)
 {
     /* Back out quickly if the post to libsyn is not checked */
     if (get_post_meta($post->ID, 'libsyn-post-episode', true) !== 'isLibsynPost') {
         return;
     }
     $plugin = new Service();
     $api = $plugin->getApis();
     //testing
     //get post player settings
     $playerSettings = array();
     $playerSettings['player_use_thumbnail'] = get_option('libsyn-podcasting-player_use_thumbnail');
     $playerSettings['player_use_theme'] = get_option('libsyn-podcasting-player_use_theme');
     $playerSettings['player_height'] = get_option('libsyn-podcasting-player_height');
     $playerSettings['player_width'] = get_option('libsyn-podcasting-player_width');
     $playerSettings['player_placement'] = get_option('libsyn-podcasting-player_placement');
     //Create item API array
     $item = array();
     $item['show_id'] = $api->getShowId();
     $item['item_title'] = $post->post_title;
     $item['item_subtitle'] = get_post_meta($post->ID, 'libsyn-post-episode-subtitle', true);
     $item['thumbnail_url'] = get_post_meta($post->ID, 'libsyn-new-media-image', true);
     $item['item_body'] = $content = wp_kses_post(self::stripShortcode('podcast', self::stripShortcode('podcast', $post->post_content)));
     $item['item_category'] = get_post_meta($post->ID, 'libsyn-post-episode-category-selection', true);
     $item['itunes_explicit'] = get_post_meta($post->ID, 'libsyn-post-episode-itunes', true);
     if ($item['itunes_explicit'] === 'explicit') {
         $item['itunes_explicit'] = 'yes';
     }
     $item['tv_rating'] = get_post_meta($post->ID, 'libsyn-post-episode-tvrating', true);
     if ($item['tv_rating'] === 'no') {
         $item['tv_rating'] = '';
     }
     //$item['tv_subrating'] = get_post_meta($post->ID, 'libsyn-post-episode-tvrating-contains', true);
     $item['item_keywords'] = get_post_meta($post->ID, 'libsyn-post-episode-keywords', true);
     //player settings //post params are height(int),theme(standard,mini),width(int)
     $item['height'] = get_post_meta($post->ID, 'libsyn-post-episode-player_height', true);
     $item['width'] = get_post_meta($post->ID, 'libsyn-post-episode-player_width', true);
     $item['theme'] = get_post_meta($post->ID, 'libsyn-post-episode-player_use_theme', true);
     //handle primary content
     $url = get_post_meta($post->ID, 'libsyn-new-media-media', true);
     if (strpos($url, 'libsyn-ftp-') !== false) {
         $content_id = str_replace('http:', '', str_replace('https:', '', str_replace('/', '', str_replace('libsyn-ftp-', '', $url))));
     }
     if (strpos($url, 'libsyn-upload-') !== false) {
         $content_id = str_replace('http:', '', str_replace('https:', '', str_replace('/', '', str_replace('libsyn-upload-', '', $url))));
     }
     if (isset($content_id) && is_numeric($content_id)) {
         //then is ftp/unreleased
         $item['primary_content_id'] = intval($content_id);
     } elseif (!empty($url)) {
         //is regular
         $sanitize = new \Libsyn\Service\Sanitize();
         $item['primary_content_url'] = $sanitize->url_raw($url);
     } else {
         //throw new Exception('Primary media error, please check your Libsyn settings.');
     }
     //get destinations
     $destinations = $plugin->getDestinations($api);
     //TODO: commenting out all Exceptions put in place a logging system.
     //if(!$destinations) throw new Exception('Error using the Libsyn API, please try again later.');
     //TODO: Handle validation error on bad api call for destinations.
     if ($isSchedule) {
         $releaseDate = $post->post_date_gmt;
     } else {
         $releaseDate = 'now';
     }
     if ($isDraft) {
         $item['is_draft'] = 'true';
     } else {
         $item['is_draft'] = 'false';
     }
     $item['releases'] = array();
     foreach ($destinations->destinations as $destination) {
         if ($destination->destination_type !== 'WordPress') {
             $item['releases'][] = array('destination_id' => $destination->destination_id, 'release_date' => $releaseDate);
         }
     }
     //is this post an update or new?
     $wp_libsyn_item_id = get_post_meta($post->ID, 'libsyn-item-id', true);
     $isUpdatePost = empty($wp_libsyn_item_id) ? false : true;
     if ($isUpdatePost) {
         $item['item_id'] = $wp_libsyn_item_id;
     }
     //run post
     $libsyn_post = $plugin->postPost($api, $item);
     if ($libsyn_post !== false) {
         self::updatePost($post, $libsyn_post, $isUpdatePost);
     } else {
         add_post_meta($post->ID, 'libsyn-post-error', 'true', true);
     }
 }
Exemplo n.º 2
0
         $clientId = $api->getClientId();
     }
     if (!isset($clientSecret)) {
         $clientSecret = $api->getClientSecret();
     }
 } else {
     $client = get_option('client');
     if (!isset($clientId)) {
         $clientId = $sanitize->clientId($client['id']);
     }
     if (!isset($clientSecret)) {
         $clientSecret = $sanitize->clientSecret($client['secret']);
     }
 }
 /* Auth login */
 $json = $plugin->requestBearer($sanitize->clientId($clientId), $sanitize->clientSecret($clientSecret), $sanitize->text($code), $sanitize->url_raw(urldecode($redirectUri)));
 $check = $plugin->checkResponse($json);
 $response = (array) json_decode($json->body);
 if (!$check) {
     echo "<div class\"updated\"><span style=\"font-weight:bold;\">" . implode(" ", $json->response) . "<br>" . $response['detail'] . "<span></div>";
 } elseif ($check) {
     $response = $response + array('client_id' => $sanitize->clientId($clientId), 'client_secret' => $sanitize->clientSecret($clientSecret));
     if ($api instanceof Libsyn\Api && $api->isRefreshExpired()) {
         $api = $api->update($response);
     } else {
         $libsyn_api = $plugin->createLibsynApi($response);
         $libsyn_api->refreshToken();
         $api = $libsyn_api->retrieveApiById($libsyn_api->getPluginApiId());
         $url = get_site_url() . '/wp-admin/?page=' . LIBSYN_DIR . '/admin/settings.php';
         echo "<script type=\"text/javascript\">\r\n\t\t\t\t\t\t\tif (typeof window.top.location.href == 'string') window.top.location.href = \"" . $url . "\";\r\n\t\t\t\t\t\t\t\telse if(typeof document.location.href == 'string') document.location.href = \"" . $url . "\";\r\n\t\t\t\t\t\t\t\t\telse alert('Unknown javascript error 1022.  Please report this error to support@libsyn.com and help us improve this plugin!');\r\n\t\t\t\t\t\t </script>";
     }