예제 #1
0
function powerpressadmin_mt_do_import()
{
    $wp_remote_options = array();
    $wp_remote_options['user-agent'] = 'Blubrry PowerPress/' . POWERPRESS_VERSION;
    $wp_remote_options['httpversion'] = '1.1';
    $Import = isset($_POST['Import']) ? $_POST['Import'] : array();
    $Media = isset($_POST['Media']) ? $_POST['Media'] : array();
    $Titles = isset($_POST['Titles']) ? $_POST['Titles'] : array();
    set_time_limit(60 + 10 * count($Import));
    $DetectDuration = !empty($_POST['DetectDuration']) ? $_POST['DetectDuration'] : 0;
    if ($DetectDuration) {
        require_once POWERPRESS_ABSPATH . '/mp3info.class.php';
        $Mp3Info = new Mp3Info();
        if (defined('POWERPRESS_DOWNLOAD_BYTE_LIMIT')) {
            $Mp3Info->SetDownloadBytesLimit(POWERPRESS_DOWNLOAD_BYTE_LIMIT);
        }
    }
    while (list($post_id, $episode_feeds) = each($Import)) {
        while (list($media_index, $feed_slug) = each($episode_feeds)) {
            if ($feed_slug == '') {
                continue;
            }
            // User decoded not to import this one..
            $url = $Media[$post_id][$media_index];
            //$headers = wp_remote_head($url, array('httpversion' => 1.1));
            //$response = wp_remote_request($url, $options);
            $response = wp_remote_head($url, array('httpversion' => 1.1));
            // Redirect 1
            if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) {
                $headers = wp_remote_retrieve_headers($response);
                $response = wp_remote_head($headers['location'], $wp_remote_options);
            }
            // Redirect 2
            if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) {
                $headers = wp_remote_retrieve_headers($response);
                $response = wp_remote_head($headers['location'], $wp_remote_options);
            }
            // Redirect 3
            if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) {
                $headers = wp_remote_retrieve_headers($response);
                $response = wp_remote_head($headers['location'], $wp_remote_options);
            }
            // Redirect 4
            if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) {
                $headers = wp_remote_retrieve_headers($response);
                $response = wp_remote_head($headers['location'], $wp_remote_options);
            }
            $headers = wp_remote_retrieve_headers($response);
            if (is_wp_error($response)) {
                powerpressadmin_mt_import_log($Titles[$post_id], $url, $feed_slug, 'A system error occurred.');
            } else {
                if ($headers && $response['response']['code'] >= 200 && $response['response']['code'] < 300) {
                    $EpisodeData = array();
                    $EpisodeData['url'] = $url;
                    if ($headers['content-length']) {
                        $EpisodeData['size'] = (int) $headers['content-length'];
                    } else {
                        $EpisodeData['size'] = 0;
                    }
                    $EpisodeData['type'] = powerpress_get_contenttype($EpisodeData['url']);
                    $EpisodeData['duration'] = false;
                    if ($EpisodeData['type'] == 'audio/mpeg' && $DetectDuration) {
                        $Mp3Data = $Mp3Info->GetMp3Info($EpisodeData['url']);
                        if ($Mp3Data) {
                            $Duration = $Mp3Data['playtime_string'];
                            $EpisodeData['duration'] = powerpress_readable_duration($Duration, true);
                            // Fix so it looks better when viewed for editing
                        }
                    }
                    $EnclosureData = $EpisodeData['url'] . "\n" . $EpisodeData['size'] . "\n" . $EpisodeData['type'];
                    if ($EpisodeData['duration']) {
                        $EnclosureData .= "\n" . serialize(array('duration' => $EpisodeData['duration']));
                    }
                    // Save it here...
                    if ($feed_slug == 'podcast') {
                        add_post_meta($post_id, 'enclosure', $EnclosureData, true);
                    } else {
                        add_post_meta($post_id, '_' . $feed_slug . ':enclosure', $EnclosureData, true);
                    }
                    powerpressadmin_mt_import_log($Titles[$post_id], $EpisodeData['url'], $feed_slug);
                } else {
                    powerpressadmin_mt_import_log($Titles[$post_id], $url, $feed_slug, __('HTTP return code', 'powerpress') . ' ' . $response['response']['code'] . '.');
                }
            }
        }
    }
}
예제 #2
0
function powerpress_get_media_info_local($media_file, $content_type = '', $file_size = 0, $duration = '', $return_warnings = false)
{
    $error_msg = '';
    $warning_msg = '';
    if ($content_type == '') {
        $content_type = powerpress_get_contenttype($media_file);
    }
    if (isset($GLOBALS['objWPOSFLV']) && is_object($GLOBALS['objWPOSFLV'])) {
        return array('error' => __('The WP OS FLV plugin is not compatible with Blubrry PowerPress.', 'powerpress'));
    }
    $get_duration_info = ($content_type == 'audio/mpeg' || $content_type == 'audio/x-m4a' || $content_type == 'video/x-m4v' || $content_type == 'video/mp4' || $content_type == 'audio/ogg') && $duration === '';
    // Lets use the mp3info class:
    require_once POWERPRESS_ABSPATH . '/mp3info.class.php';
    $Mp3Info = new Mp3Info();
    if ($get_duration_info) {
        if (preg_match('/video/i', $content_type)) {
            if (defined('POWERPRESS_DOWNLOAD_BYTE_LIMIT_VIDEO')) {
                $Mp3Info->SetDownloadBytesLimit(POWERPRESS_DOWNLOAD_BYTE_LIMIT_VIDEO);
            }
        } else {
            if (defined('POWERPRESS_DOWNLOAD_BYTE_LIMIT')) {
                $Mp3Info->SetDownloadBytesLimit(POWERPRESS_DOWNLOAD_BYTE_LIMIT);
            }
        }
    }
    $Mp3Data = $Mp3Info->GetMp3Info($media_file, !$get_duration_info);
    if ($Mp3Data) {
        if ($Mp3Info->GetRedirectCount() > 5) {
            // Add a warning that the redirect count exceeded 5, which may prevent some podcatchers from downloading the media.
            $warning = sprintf(__('Warning, the Media URL %s contains %d redirects.', 'powerpress'), $media_file, $Mp3Info->GetRedirectCount());
            $warning .= ' [<a href="http://create.blubrry.com/resources/powerpress/using-powerpress/warning-messages-explained/" title="' . __('PowerPress Warnings Explained', 'powerpress') . '" target="_blank">' . __('PowerPress Warnings Explained') . '</a>]';
            if ($return_warnings) {
                $warning_msg .= $warning;
            } else {
                powerpress_add_error($warning);
            }
        }
        if ($file_size == 0) {
            $file_size = $Mp3Info->GetContentLength();
        }
        if ($get_duration_info) {
            $playtime_string = !empty($Mp3Data['playtime_string']) ? $Mp3Data['playtime_string'] : '';
            $duration = powerpress_readable_duration($playtime_string, true);
            // Fix so it looks better when viewed for editing
        }
        $GeneralSettings = get_option('powerpress_general');
        if (empty($GeneralSettings['hide_warnings']) && count($Mp3Info->GetWarnings()) > 0) {
            $Warnings = $Mp3Info->GetWarnings();
            while (list($null, $warning) = each($Warnings)) {
                $warning = sprintf(__('Warning, Media URL %s', 'powerpress'), $media_file) . ': ' . $warning . ' [<a href="http://create.blubrry.com/resources/powerpress/using-powerpress/warning-messages-explained/" target="_blank">' . __('PowerPress Warnings Explained', 'powerpress') . '</a>]';
                if ($return_warnings) {
                    $warning_msg .= $warning;
                } else {
                    powerpress_add_error($warning);
                }
            }
        }
    } else {
        if ($Mp3Info->GetError() != '') {
            return array('error' => $Mp3Info->GetError());
        } else {
            return array('error' => __('Error occurred obtaining media information.', 'powerpress'));
        }
    }
    if ($file_size == 0) {
        return array('error' => __('Error occurred obtaining media file size.', 'powerpress'));
    }
    if ($return_warnings && $warning_msg != '') {
        return array('content-type' => $content_type, 'length' => $file_size, 'duration' => $duration, 'warnings' => $warning_msg);
    }
    return array('content-type' => $content_type, 'length' => $file_size, 'duration' => $duration);
    // OLD CODE FOLLOWS:
    if ($content_type == 'audio/mpeg' && $duration === '') {
        // Lets use the mp3info class:
        require_once POWERPRESS_ABSPATH . '/mp3info.class.php';
        $Mp3Info = new Mp3Info();
        if (defined('POWERPRESS_DOWNLOAD_BYTE_LIMIT')) {
            $Mp3Info->SetDownloadBytesLimit(POWERPRESS_DOWNLOAD_BYTE_LIMIT);
        }
        $Mp3Data = $Mp3Info->GetMp3Info($media_file);
        if ($Mp3Data) {
            if ($Mp3Info->GetRedirectCount() > 5) {
                // Add a warning that the redirect count exceeded 5, which may prevent some podcatchers from downloading the media.
                powerpress_add_error(sprintf(__('Warning, the Media URL %s contains %d redirects.', 'powerpress'), $media_file, $Mp3Info->GetRedirectCount()) . ' [<a href="http://create.blubrry.com/resources/powerpress/using-powerpress/warning-messages-explained/" target="_blank">' . __('PowerPress Warnings Explained', 'powerpress') . '</a>]');
            }
            if ($file_size == 0) {
                $file_size = $Mp3Info->GetContentLength();
            }
            $playtime_string = !empty($Mp3Data['playtime_string']) ? $Mp3Data['playtime_string'] : '';
            $duration = powerpress_readable_duration($playtime_string, true);
            // Fix so it looks better when viewed for editing
            if (count($Mp3Info->GetWarnings()) > 0) {
                $Warnings = $Mp3Info->GetWarnings();
                while (list($null, $warning) = each($Warnings)) {
                    powerpress_add_error(sprintf(__('Warning, Media URL %s', 'powerpress'), $media_file) . ': ' . $warning . ' [<a href="http://create.blubrry.com/resources/powerpress/using-powerpress/warning-messages-explained/" target="_blank">' . __('PowerPress Warnings Explained', 'powerpress') . '</a>]');
                }
            }
        } else {
            if ($Mp3Info->GetError()) {
                return array('error' => $Mp3Info->GetError());
            } else {
                return array('error' => __('Error occurred obtaining media information.', 'powerpress'));
            }
        }
    }
    $wp_remote_options = array();
    $wp_remote_options['user-agent'] = 'Blubrry PowerPress/' . POWERPRESS_VERSION;
    $wp_remote_options['httpversion'] = '1.1';
    if ($content_type != '' && $file_size == 0) {
        $response = wp_remote_head($media_file, array('httpversion' => 1.1));
        // Redirect 1
        if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) {
            $headers = wp_remote_retrieve_headers($response);
            $response = wp_remote_head($headers['location'], $wp_remote_options);
        }
        // Redirect 2
        if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) {
            $headers = wp_remote_retrieve_headers($response);
            $response = wp_remote_head($headers['location'], $wp_remote_options);
        }
        // Redirect 3
        if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) {
            $headers = wp_remote_retrieve_headers($response);
            $response = wp_remote_head($headers['location'], $wp_remote_options);
        }
        // Redirect 4
        if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) {
            $headers = wp_remote_retrieve_headers($response);
            $response = wp_remote_head($headers['location'], $wp_remote_options);
        }
        if (is_wp_error($response)) {
            return array('error' => $response->get_error_message());
        }
        if (isset($response['response']['code']) && $response['response']['code'] < 200 || $response['response']['code'] > 290) {
            return array('error' => __('Error, HTTP', 'powerpress') . ' ' . $response['response']['code']);
        }
        $headers = wp_remote_retrieve_headers($response);
        if ($headers && $headers['content-length']) {
            $file_size = (int) $headers['content-length'];
        } else {
            return array('error' => __('Unable to obtain file size of media file.', 'powerpress'));
        }
    }
    if ($file_size == 0) {
        return array('error' => __('Error occurred obtaining media file size.', 'powerpress'));
    }
    return array('content-type' => $content_type, 'length' => $file_size, 'duration' => $duration);
}