function podPress_processDownloadRedirect($postID, $mediaNum, $filename, $method = '')
{
    global $podPress, $wpdb;
    $allowedMethods = array('feed', 'play', 'web');
    $realURL = false;
    $realSysPath = false;
    $statID = false;
    if (substr($filename, -20, 20) == 'podPressStatTest.txt') {
        status_header('200');
        echo 'Worked';
        // Don't translate this!
        exit;
    }
    if (in_array($method, $allowedMethods) && is_numeric($postID) && is_numeric($mediaNum)) {
        $mediaFiles = podPress_get_post_meta($postID, '_podPressMedia', true);
        if (isset($mediaFiles[$mediaNum])) {
            if ($mediaFiles[$mediaNum]['URI'] == urldecode($filename)) {
                $realURL = $filename;
            } elseif (podPress_getFileName($mediaFiles[$mediaNum]['URI']) == urldecode($filename)) {
                $realURL = $mediaFiles[$mediaNum]['URI'];
            } elseif (podPress_getFileName($mediaFiles[$mediaNum]['URI_torrent']) == urldecode($filename)) {
                $realURL = $mediaFiles[$mediaNum]['URI_torrent'];
            }
        }
    }
    if (!$realURL) {
        header('X-PodPress-Location: ' . get_option('siteurl'));
        header('Location: ' . get_option('siteurl'));
        exit;
    }
    $badextensions = array('.smi', '.jpg', '.png', '.gif');
    if ($filename && !in_array(strtolower(substr($filename, -4)), $badextensions)) {
        podPress_StatCounter($postID, $filename, $method);
        if ($podPress->settings['statLogging'] == 'Full' || $podPress->settings['statLogging'] == 'FullPlus') {
            $statID = podPress_StatCollector($postID, $filename, $method);
        }
    }
    $realSysPath = $podPress->convertPodcastFileNameToSystemPath(str_replace('%20', ' ', $realURL));
    if (FALSE === $realSysPath) {
        $realSysPath = $podPress->TryToFindAbsFileName(str_replace('%20', ' ', $realURL));
    }
    $realURL = $podPress->convertPodcastFileNameToValidWebPath($realURL);
    if ($podPress->settings['enable3rdPartyStats'] == 'PodTrac') {
        $realURL = str_replace(array('ftp://', 'http://', 'https://'), '', $realURL);
        $realURL = $podPress->podtrac_url . $realURL;
    } elseif (strtolower($podPress->settings['enable3rdPartyStats']) == 'blubrry' && !empty($podPress->settings['statBluBrryProgramKeyword'])) {
        $realURL = str_replace('http://', '', $realURL);
        $realURL = $podPress->blubrry_url . $podPress->settings['statBluBrryProgramKeyword'] . '/' . $realURL;
    } elseif ($podPress->settings['statLogging'] == 'FullPlus' && $realSysPath !== false) {
        status_header('200');
        $content_type = podPress_mimetypes(podPress_getFileExt($realSysPath));
        if ($method == 'web') {
            header("Pragma: ");
            header("Cache-Control: ");
            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
            header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
            header("Cache-Control: no-store, no-cache, must-revalidate");
            // HTTP/1.1
            header("Cache-Control: post-check=0, pre-check=0", false);
            header('Content-Disposition: attachment; filename="' . $filename . '"');
            header("Content-Description: " . trim(htmlentities($filename)));
            header("Connection: close");
            if (substr($content_type, 0, 4) != 'text') {
                header("Content-Transfer-Encoding: binary");
            }
        } else {
            header("Connection: Keep-Alive");
        }
        header("X-ForcedBy: podPress");
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        header('Content-type: ' . $content_type);
        header('Content-Length: ' . filesize($realSysPath));
        set_time_limit(0);
        $chunksize = 1 * (1024 * 1024);
        // how many bytes per chunk
        if ($handle = fopen($realSysPath, 'rb')) {
            while (!feof($handle) && connection_status() == 0) {
                echo fread($handle, $chunksize);
                ob_flush();
                flush();
            }
            fclose($handle);
        }
        if ($statID !== false && connection_status() == 0 && !connection_aborted()) {
            $sqlU = "UPDATE " . $wpdb->prefix . "podpress_stats SET completed=1 WHERE id=" . $statID;
            $wpdb->hide_errors();
            $result = $wpdb->query($sqlI);
            if (!$result) {
                $wpdb->query($sqlU);
            }
        }
        exit;
    }
    $realURL = str_replace(' ', '%20', $realURL);
    status_header('302');
    header('X-PodPress-Location: ' . $realURL, true, 302);
    header('Location: ' . $realURL, true, 302);
    header('Content-Length: 0');
    exit;
}
 function convertPodcastFileNameToWebPath($postID, $mediaNum, $filename = '', $method = false)
 {
     global $wp_version;
     $url = $this->convertPodcastFileNameToValidWebPath($filename);
     if ($method != false) {
         if ($this->settings['enableStats']) {
             $filename_part = podPress_getFileName($url);
             if ($this->settings['statMethod'] == 'download.mp3') {
                 $url = podPress_url() . 'download.mp3?' . $method . '=' . $postID . '/' . $mediaNum . '/' . $filename_part;
             } else {
                 if (TRUE === version_compare($wp_version, '3.0', '<')) {
                     $url = get_bloginfo('home') . '/podpress_trac/' . $method . '/' . $postID . '/' . $mediaNum . '/' . $filename_part;
                 } else {
                     $url = home_url() . '/podpress_trac/' . $method . '/' . $postID . '/' . $mediaNum . '/' . $filename_part;
                 }
             }
         } elseif ($this->settings['enable3rdPartyStats'] == 'Podtrac') {
             $url = str_replace(array('ftp://', 'http://', 'https://'), '', $url);
             $url = $this->podtrac_url . $url;
         } elseif ($this->settings['enable3rdPartyStats'] == 'BluBrry' && !empty($this->settings['statBluBrryProgramKeyword'])) {
             $url = $this->blubrry_url . $this->settings['statBluBrryProgramKeyword'] . '/' . $url;
         }
     }
     $url = str_replace(' ', '%20', $url);
     return $url;
 }
 function do_legacy_upgrades($current)
 {
     global $wpdb;
     while (TRUE == version_compare(PODPRESS_VERSION, $current, '>=') and TRUE == version_compare('8.8', $current, '>=')) {
         settype($current, 'string');
         switch ($current) {
             case '0':
                 $current = PODPRESS_VERSION;
                 break;
             case '1.4':
                 $posts_that_need_upgrades = array();
                 $posts = $wpdb->get_results("SELECT ID, post_content FROM " . $wpdb->posts);
                 if ($posts) {
                     foreach ($posts as $post) {
                         if (preg_match($this->podcasttag_regexp, $post->post_content, $matches)) {
                             $podcastTagFileName = $matches[1];
                         } else {
                             $podcastTagFileName = false;
                         }
                         if ($podcastTagFileName) {
                             $posts_that_need_upgrades[$post->ID] = $post->post_content;
                         }
                     }
                     reset($posts_that_need_upgrades);
                     foreach ($posts_that_need_upgrades as $key => $value) {
                         $wpdb->query("UPDATE " . $wpdb->posts . " SET post_content = '" . preg_replace($this->podcasttag_regexp, '', $value) . "' WHERE ID=" . $key);
                         if (preg_match($this->podcasttag_regexp, $content, $matches)) {
                             $podcastTagFileName = $matches[1];
                         } else {
                             $podcastTagFileName = false;
                         }
                         delete_post_meta($key, 'podPress_podcastStandardAudio');
                         add_post_meta($key, 'podPress_podcastStandardAudio', $podcastTagFileName, true);
                     }
                 }
                 break;
             case '3.8':
                 $this->settings['audioWebPath'] = get_option('podPress_audioWebPath');
                 $this->settings['audioFilePath'] = get_option('podPress_audioFilePath');
                 if ($this->settings['audioWebPath'] == '') {
                     add_option('podPress_mediaWebPath', $this->settings['audioWebPath'], "Web path to Podcast media files", true);
                     $this->settings['audioWebPath'] = $this->settings['audioWebPath'];
                     delete_option('podPress_audioWebPath');
                 }
                 if ($this->settings['audioFilePath'] == '') {
                     add_option('podPress_mediaFilePath', $this->settings['audioFilePath'], "File path to Podcast media files", true);
                     $this->settings['mediaFilePath'] = $this->settings['audioFilePath'];
                     delete_option('podPress_audioFilePath');
                 }
                 $posts = $wpdb->get_results("SELECT ID FROM " . $wpdb->prefix . "posts");
                 if ($posts) {
                     foreach ($posts as $post) {
                         $sql = "SELECT meta_key, meta_value\n\t\t\t\t\t\t\t\t        FROM " . $wpdb->prefix . "postmeta \n\t\t\t\t\t\t\t\t\tWHERE meta_key  IN(\n\t\t\t\t\t\t\t\t\t\t'podPress_podcastStandardAudio', \n\t\t\t\t\t\t\t\t\t\t'podPress_podcastStandardAudioSize',\n\t\t\t\t\t\t\t\t\t\t'podPress_podcastStandardAudioDuration',\n\t\t\t\t\t\t\t\t\t\t'podPress_podcastEnhancedAudio',\n\t\t\t\t\t\t\t\t\t\t'podPress_podcastEnhancedAudioSize',\n\t\t\t\t\t\t\t\t\t\t'podPress_podcastEnhancedAudioDuration',\n\t\t\t\t\t\t\t\t\t\t'podPress_podcastVideo',\n\t\t\t\t\t\t\t\t\t\t'podPress_podcastVideoSize',\n\t\t\t\t\t\t\t\t\t\t'podPress_podcastVideoDuration',\n\t\t\t\t\t\t\t\t\t\t'podPress_podcastVideoDimension',\n\t\t\t\t\t\t\t\t\t\t'podPress_webVideo',\n\t\t\t\t\t\t\t\t\t\t'podPress_webVideoSize',\n\t\t\t\t\t\t\t\t\t\t'podPress_webVideoDuration',\n\t\t\t\t\t\t\t\t\t\t'podPress_webVideoDimension',\n\t\t\t\t\t\t\t\t\t\t'podPress_podcastEbook',\n\t\t\t\t\t\t\t\t\t\t'podPress_podcastEbookSize',\n\t\t\t\t\t\t\t\t\t\t'itunes:duration',\n\t\t\t\t\t\t\t\t\t\t'enclosure'\n\t\t\t\t\t\t\t\t\t) AND post_id = " . $post->ID;
                         $metadata = $wpdb->get_results($sql);
                         if ($metadata) {
                             $posts2convert = array();
                             foreach ($metadata as $stat) {
                                 $posts2convert[$post->ID][$stat->meta_key] = $stat->meta_value;
                             }
                             $rssaddedyet = false;
                             $podPressMedia = array();
                             foreach ($posts2convert as $key => $val) {
                                 if (isset($val['enclosure'])) {
                                     $encParts = split("\n", $val['enclosure']);
                                     $data = $this->upgrade_convert39to40mediaFile(trim(htmlspecialchars($encParts[0])), trim(htmlspecialchars($encParts[1])));
                                     if (!$rssaddedyet) {
                                         $rssaddedyet = true;
                                         $data['rss'] = 'on';
                                     }
                                     $podPressMedia[] = $data;
                                 }
                                 if (isset($val['podPress_podcastStandardAudio'])) {
                                     $data = $this->upgrade_convert39to40mediaFile($val['podPress_podcastStandardAudio'], $val['podPress_podcastStandardAudioSize'], $val['podPress_podcastStandardAudioDuration']);
                                     if (!$rssaddedyet) {
                                         $rssaddedyet = true;
                                         $data['rss'] = 'on';
                                     }
                                     $podPressMedia[] = $data;
                                 }
                                 if (isset($val['podPress_podcastEnhancedAudio'])) {
                                     $data = $this->upgrade_convert39to40mediaFile($val['podPress_podcastEnhancedAudio'], $val['podPress_podcastEnhancedAudioSize'], $val['podPress_podcastEnhancedAudioDuration']);
                                     if (!$rssaddedyet) {
                                         $rssaddedyet = true;
                                         $data['rss'] = 'on';
                                     }
                                     $podPressMedia[] = $data;
                                 }
                                 if (isset($val['podPress_podcastVideo'])) {
                                     $data = $this->upgrade_convert39to40mediaFile($val['podPress_podcastVideo'], $val['podPress_podcastVideoSize'], $val['podPress_podcastVideoDuration'], $val['podPress_podcastVideoDimension']);
                                     if (!$rssaddedyet) {
                                         $rssaddedyet = true;
                                         $data['rss'] = 'on';
                                     }
                                     $podPressMedia[] = $data;
                                 }
                                 if (isset($val['podPress_webVideo'])) {
                                     $data = $this->upgrade_convert39to40mediaFile($val['podPress_webVideo'], $val['podPress_webVideoSize'], $val['podPress_webVideoDuration'], $val['podPress_webVideoDimension']);
                                     $podPressMedia[] = $data;
                                 }
                                 if (isset($val['podPress_podcastEbook'])) {
                                     $data = $this->upgrade_convert39to40mediaFile($val['podPress_podcastEbook'], $val['podPress_podcastEbookSize']);
                                     if (!$rssaddedyet) {
                                         $rssaddedyet = true;
                                         $data['rss'] = 'on';
                                     }
                                     $podPressMedia[] = $data;
                                 }
                             }
                             if (is_array($podPressMedia)) {
                                 delete_post_meta($post->ID, 'podPressMedia');
                                 podPress_add_post_meta($post->ID, 'podPressMedia', $podPressMedia, true);
                             }
                         }
                     }
                 }
                 $sql = "UPDATE " . $wpdb->prefix . "postmeta SET meta_key='enclosure_hold' WHERE meta_key='enclosure'";
                 $wpdb->query($sql);
                 break;
             case '4.2':
                 $playerOptions['bg'] = str_replace('0x', '#', get_option('podPress_player_bgcolor'));
                 delete_option('podPress_player_bgcolor');
                 $playerOptions['text'] = str_replace('0x', '#', get_option('podPress_player_textcolor'));
                 delete_option('podPress_player_textcolor');
                 $playerOptions['leftbg'] = str_replace('0x', '#', get_option('podPress_player_leftbgcolor'));
                 delete_option('podPress_player_leftbgcolor');
                 $playerOptions['lefticon'] = str_replace('0x', '#', get_option('podPress_player_lefticoncolor'));
                 delete_option('podPress_player_lefticoncolor');
                 $playerOptions['rightbg'] = str_replace('0x', '#', get_option('podPress_player_rightbgcolor'));
                 delete_option('podPress_player_rightbgcolor');
                 $playerOptions['rightbghover'] = str_replace('0x', '#', get_option('podPress_player_rightbghovercolor'));
                 delete_option('podPress_player_rightbghovercolor');
                 $playerOptions['righticon'] = str_replace('0x', '#', get_option('podPress_player_righticoncolor'));
                 delete_option('podPress_player_righticoncolor');
                 $playerOptions['righticonhover'] = str_replace('0x', '#', get_option('podPress_player_righticonhovercolor'));
                 delete_option('podPress_player_righticonhovercolor');
                 $playerOptions['slider'] = str_replace('0x', '#', get_option('podPress_player_slidercolor'));
                 delete_option('podPress_player_slidercolor');
                 $playerOptions['track'] = str_replace('0x', '#', get_option('podPress_player_trackcolor'));
                 delete_option('podPress_player_trackcolor');
                 $playerOptions['loader'] = str_replace('0x', '#', get_option('podPress_player_loadercolor'));
                 delete_option('podPress_player_loadercolor');
                 $playerOptions['border'] = str_replace('0x', '#', get_option('podPress_player_bordercolor'));
                 delete_option('podPress_player_bordercolor');
                 podPress_update_option('podPress_playerOptions', $playerOptions);
                 break;
             case '4.4':
                 if (!is_array($this->settings['iTunes'])) {
                     $this->settings['iTunes'] = array();
                 }
                 $x = stripslashes(get_option('itunesAdminName'));
                 delete_option('itunesAdminName');
                 if (!empty($x)) {
                     $this->settings['iTunes']['author'] = $x;
                 }
                 $this->settings['iTunes']['block'] = 'No';
                 $this->settings['iTunes']['category'] = array();
                 $cat1 = get_option('itunesCategory1');
                 $cat2 = get_option('itunesCategory2');
                 $cat3 = get_option('itunesCategory3');
                 if (!empty($cat1)) {
                     $this->settings['iTunes']['category'][] = $cat1;
                 }
                 if (!empty($cat2)) {
                     $this->settings['iTunes']['category'][] = $cat2;
                 }
                 if (!empty($cat3)) {
                     $this->settings['iTunes']['category'][] = $cat3;
                 }
                 $x = stripslashes(get_option('itunesImageBig'));
                 delete_option('itunesImageBig');
                 if (!empty($x)) {
                     $this->settings['iTunes']['image'] = $x;
                 }
                 $x = stripslashes(get_option('itunesDefaultExplicit'));
                 delete_option('itunesDefaultExplicit');
                 if (!empty($x)) {
                     $this->settings['iTunes']['explicit'] = $x;
                 }
                 $x = stripslashes(get_option('itunesFeedKeywords'));
                 delete_option('itunesFeedKeywords');
                 if (!empty($x)) {
                     $this->settings['iTunes']['keywords'] = $x;
                 }
                 $x = stripslashes(get_option('podcastdescription'));
                 delete_option('podcastdescription');
                 if (!empty($x)) {
                     $this->settings['iTunes']['summary'] = $x;
                 }
                 $x = stripslashes(get_option('itunesFeedID'));
                 delete_option('itunesFeedID');
                 if (!empty($x)) {
                     $this->settings['iTunes']['FeedID'] = $x;
                 }
                 delete_option('itunesUseKeyword');
                 delete_option('itunesFeedURL');
                 $x = stripslashes(get_option('itunesImageSmall'));
                 delete_option('itunesImageSmall');
                 if (!empty($x)) {
                     add_option('rss_image', $x);
                 }
                 $x = stripslashes(get_option('itunesTTL'));
                 delete_option('itunesTTL');
                 if (!empty($x)) {
                     add_option('rss_ttl', $x);
                 }
                 $x = stripslashes(get_option('downloadLinksInRSS'));
                 delete_option('downloadLinksInRSS');
                 if (!empty($x)) {
                     add_option('podPress_rss_showlinks', $x);
                 }
                 $x = stripslashes(get_option('channelCat'));
                 delete_option('channelCat');
                 if (!empty($x)) {
                     add_option('podPress_rss_category', $x);
                 }
                 delete_option('podPress_iTunes');
                 podPress_add_option('podPress_iTunes', $this->settings['iTunes']);
                 $x = podPress_get_option('podPress_playerOptions');
                 delete_option('podPress_playerOptions');
                 if (!empty($x)) {
                     podPress_add_option('podPress_playerSettings', $x);
                 }
                 $x = stripslashes(get_option('podPress_BeforeMore'));
                 delete_option('podPress_BeforeMore');
                 if (!empty($x)) {
                     add_option('podPress_contentBeforeMore', $x);
                 }
                 $sql = "SELECT media, \n\t\t\t\t\t\t               method, \n\t\t\t\t\t\t               COUNT(media) as cnt_total, \n\t\t\t\t\t\t               COUNT(CASE WHEN method = 'feed' THEN 1 END) as cnt_feed ,\n\t\t\t\t\t\t               COUNT(CASE WHEN method = 'web' THEN 1 END) as cnt_web ,\n\t\t\t\t\t\t               COUNT(CASE WHEN method = 'play' THEN 1 END) as cnt_play \n\t\t\t\t\t\t        FROM " . $wpdb->prefix . "podpress_stats \n\t\t\t\t\t\t        GROUP BY media \n\t\t\t\t\t\t        ORDER BY cnt_total DESC";
                 $stats = $wpdb->get_results($sql);
                 if ($stats) {
                     $i = 0;
                     foreach ($stats as $stat) {
                         ++$i;
                         $sqlI = "INSERT INTO " . $wpdb->prefix . "podpress_statcounts (media, total, feed, web, play) VALUES ('" . $stat->media . "', " . $stat->cnt_total . ", " . $stat->cnt_feed . ", " . $stat->cnt_web . ", " . $stat->cnt_play . ")";
                         $wpdb->query($sqlI);
                     }
                 }
                 break;
             case '4.5':
                 $x = stripslashes(get_option('channelCat'));
                 delete_option('channelCat');
                 if (!empty($x)) {
                     add_option('podPress_rss_category', $x);
                 }
                 break;
             case '5.3':
                 $posts = $wpdb->get_results("SELECT ID FROM " . $wpdb->prefix . "posts");
                 if ($posts) {
                     foreach ($posts as $post) {
                         $x['itunes:subtitle'] = get_post_meta($post->ID, 'itunes:subtitle', true);
                         delete_post_meta($post->ID, 'itunes:subtitle');
                         if (!isset($x['itunes:subtitle'])) {
                             unset($x['itunes:subtitle']);
                         }
                         $x['itunes:summary'] = get_post_meta($post->ID, 'itunes:summary', true);
                         delete_post_meta($post->ID, 'itunes:summary');
                         if (!isset($x['itunes:summary'])) {
                             unset($x['itunes:summary']);
                         }
                         $x['itunes:keywords'] = get_post_meta($post->ID, 'itunes:keywords', true);
                         delete_post_meta($post->ID, 'itunes:keywords');
                         if (!isset($x['itunes:keywords'])) {
                             unset($x['itunes:keywords']);
                         }
                         $x['itunes:author'] = get_post_meta($post->ID, 'itunes:author', true);
                         delete_post_meta($post->ID, 'itunes:author');
                         if (!isset($x['itunes:author'])) {
                             unset($x['itunes:author']);
                         }
                         $x['itunes:explicit'] = get_post_meta($post->ID, 'itunes:explicit', true);
                         delete_post_meta($post->ID, 'itunes:explicit');
                         if (!isset($x['itunes:explicit'])) {
                             unset($x['itunes:explicit']);
                         }
                         $x['itunes:block'] = get_post_meta($post->ID, 'itunes:block', true);
                         delete_post_meta($post->ID, 'itunes:block');
                         if (!isset($x['itunes:block'])) {
                             unset($x['itunes:block']);
                         }
                         if (!empty($x)) {
                             podPress_add_post_meta($post->ID, 'podPressPostSpecific', $x, true);
                         }
                     }
                 }
                 break;
             case '5.6':
                 $x = podPress_get_option('podPress_config');
                 $y = true;
                 if ($y) {
                     $newSettings = array();
                     $newSettings['enableStats'] = get_option('podPress_enableStats');
                     $newSettings['statMethod'] = get_option('podPress_statMethod');
                     $newSettings['statLogging'] = get_option('podPress_statLogging');
                     $newSettings['enablePodTracStats'] = get_option('podPress_enablePodTracStats');
                     $newSettings['enablePremiumContent'] = get_option('podPress_enablePremiumContent');
                     $newSettings['enableTorrentCasting'] = get_option('podPress_enableTorrentCasting');
                     $newSettings['mediaWebPath'] = get_option('podPress_mediaWebPath');
                     $newSettings['mediaFilePath'] = get_option('podPress_mediaFilePath');
                     $newSettings['contentBeforeMore'] = get_option('podPress_contentBeforeMore');
                     $newSettings['contentLocation'] = get_option('podPress_contentLocation');
                     $newSettings['contentImage'] = get_option('podPress_contentImage');
                     $newSettings['contentPlayer'] = get_option('podPress_contentPlayer');
                     $newSettings['contentDownload'] = get_option('podPress_contentDownload');
                     $newSettings['contentDownloadText'] = get_option('podPress_contentDownloadText');
                     $newSettings['contentDownloadStats'] = get_option('podPress_contentDownloadStats');
                     $newSettings['contentDuration'] = get_option('podPress_contentDuration');
                     $newSettings['rss_showlinks'] = get_option('podPress_rss_showlinks');
                     $newSettings['rss_category'] = get_option('podPress_rss_category');
                     $newSettings['enableFooter'] = get_option('podPress_enableFooter');
                     $newSettings['player'] = podPress_get_option('podPress_playerSettings');
                     $newSettings['iTunes'] = podPress_get_option('podPress_iTunes');
                     delete_option('podPress_config');
                     add_option('podPress_config', $newSettings, "podPress Configuration", true);
                 }
                 break;
             case '5.7':
                 // in the next release I will clean up old crap data that is still laying around
                 delete_option('podPress_enableStats');
                 delete_option('podPress_statMethod');
                 delete_option('podPress_statLogging');
                 delete_option('podPress_enablePodTracStats');
                 delete_option('podPress_enablePremiumContent');
                 delete_option('podPress_enableTorrentCasting');
                 delete_option('podPress_mediaWebPath');
                 delete_option('podPress_mediaFilePath');
                 delete_option('podPress_contentBeforeMore');
                 delete_option('podPress_contentLocation');
                 delete_option('podPress_contentImage');
                 delete_option('podPress_contentPlayer');
                 delete_option('podPress_contentDownload');
                 delete_option('podPress_contentDownloadText');
                 delete_option('podPress_contentDownloadStats');
                 delete_option('podPress_contentDuration');
                 delete_option('podPress_rss_showlinks');
                 delete_option('podPress_rss_category');
                 delete_option('podPress_enableFooter');
                 delete_option('podPress_iTunes');
                 delete_option('podPress_playerSettings');
                 delete_option('podPress_enableLogging');
                 delete_option('podPress_downloadLinksInRSS');
                 delete_option('podPress_categoryCasting');
                 delete_option('podPress_beforeMore');
                 $sql = "DELETE FROM " . $wpdb->prefix . "postmeta WHERE meta_key='podPressiTunesPostSpecific'";
                 $wpdb->query($sql);
                 break;
             case '6.3':
                 $x = podPress_get_option('podPress_config');
                 $x['iTunes']['category'][0] = podPress_upgradeCategory($x['iTunes']['category'][0]);
                 if (isset($x['iTunes']['category'][1])) {
                     $x['iTunes']['category'][1] = podPress_upgradeCategory($x['iTunes']['category'][1]);
                 }
                 if (isset($x['iTunes']['category'][2])) {
                     $x['iTunes']['category'][2] = podPress_upgradeCategory($x['iTunes']['category'][2]);
                 }
                 podPress_update_option('podPress_config', $x);
                 break;
             case '6.7':
                 $create_table = "ALTER TABLE " . $wpdb->prefix . "podpress_statcounts ADD COLUMN postID  int(11) NOT NULL DEFAULT 0 FIRST;";
                 podPress_maybe_add_column($wpdb->prefix . 'podpress_statcounts', 'postID', $create_table);
                 $sql = 'ALTER TABLE ' . $wpdb->prefix . 'podpress_statcounts ADD PRIMARY KEY (media(255),postID), DROP PRIMARY KEY;';
                 $wpdb->get_results($sql);
                 $create_table = "ALTER TABLE " . $wpdb->prefix . "podpress_stats ADD COLUMN postID  int(11) NOT NULL DEFAULT 0 AFTER id;";
                 podPress_maybe_add_column($wpdb->prefix . 'podpress_stats', 'postID', $create_table);
                 $mappings = array();
                 $sql = "SELECT * FROM " . $wpdb->prefix . "postmeta WHERE meta_key = 'podPressMedia' ORDER BY meta_id;";
                 $posts = $wpdb->get_results($sql);
                 if ($posts) {
                     foreach ($posts as $post) {
                         $mediaFiles = unserialize($post->meta_value);
                         if (is_array($mediaFiles)) {
                             foreach ($mediaFiles as $mediaFile) {
                                 if (!isset($mappings[$mediaFile['URI']])) {
                                     $filename = podPress_getFileName($mediaFile['URI']);
                                     $mappings[$filename] = $post->post_id;
                                 }
                             }
                         }
                     }
                     reset($mappings);
                     foreach ($mappings as $key => $val) {
                         $wpdb->query('UPDATE ' . $wpdb->prefix . "podpress_statcounts SET postID = '" . $val . "' WHERE media='" . $key . "'");
                         $wpdb->query('UPDATE ' . $wpdb->prefix . "podpress_stats SET postID = '" . $val . "' WHERE media='" . $key . "'");
                     }
                 }
             case '7.9':
                 $create_table = "ALTER TABLE " . $wpdb->prefix . "podpress_stats ADD COLUMN completed TINYINT(1) UNSIGNED DEFAULT 0;";
                 podPress_maybe_add_column($wpdb->prefix . 'podpress_stats', 'completed', $create_table);
                 break;
             case '8.3':
                 if ($this->settings['enablePodTracStats']) {
                     $this->settings['enable3rdPartyStats'] = 'PodTrac';
                 }
                 break;
             default:
                 // do nothing
                 break;
         }
         if (function_exists('wp_cache_flush')) {
             wp_cache_flush();
         }
         if (version_compare(PODPRESS_VERSION, $current, '>=')) {
             update_option('podPress_version', $current);
         }
         $current = $current + 0.1;
     }
 }
/** podPress_get_real_url - demasks an URL which is masked with the podPress stats scheme
 * @package podPress
 * @since 8.8.10.3 beta 5
 * @param mixed $url - the masked url
 * @param mixed $print - print (TRUE) or return the result (FALSE)
 * @return string - the real URL
 */
function podPress_get_real_url($url, $count = TRUE, $print = TRUE)
{
    $requested = parse_url($url);
    $requested = $requested['path'];
    $realURL = 'false';
    $pos = 0;
    if ($pos = strpos($requested, 'podpress_trac')) {
        if ($pos == 0) {
            $pos = strpos($requested, 'podpress_trac');
        }
        $pos = $pos + 14;
        if (substr($requested, $pos, 1) == '/') {
            $pos = $pos + 1;
        }
        $requested = substr($requested, $pos);
        $parts = explode('/', $requested);
        if (count($parts) == 4) {
            $postID = $parts[1];
            $mediaNum = $parts[2];
            $filename = rawurlencode($parts[3]);
            $method = $parts[0];
            $allowedMethods = array('feed', 'play', 'web');
            $realSysPath = false;
            $statID = false;
            if (in_array($method, $allowedMethods) && is_numeric($postID) && is_numeric($mediaNum)) {
                $mediaFiles = podPress_get_post_meta($postID, '_podPressMedia', true);
                if (isset($mediaFiles[$mediaNum])) {
                    if ($mediaFiles[$mediaNum]['URI'] == urldecode($filename)) {
                        $realURL = $filename;
                    } elseif (podPress_getFileName($mediaFiles[$mediaNum]['URI']) == urldecode($filename)) {
                        $realURL = $mediaFiles[$mediaNum]['URI'];
                    } elseif (podPress_getFileName($mediaFiles[$mediaNum]['URI_torrent']) == urldecode($filename)) {
                        $realURL = $mediaFiles[$mediaNum]['URI_torrent'];
                    }
                }
            }
            if (TRUE === $count) {
                $badextensions = array('.smi', '.jpg', '.png', '.gif');
                if ($filename && !in_array(strtolower(substr($filename, -4)), $badextensions)) {
                    global $podPress;
                    podPress_StatCounter($postID, $filename, $method);
                    if ($podPress->settings['statLogging'] == 'Full' || $podPress->settings['statLogging'] == 'FullPlus') {
                        $statID = podPress_StatCollector($postID, $filename, $method);
                    }
                }
            }
            //~ $realSysPath = $podPress->convertPodcastFileNameToSystemPath(str_replace('%20', ' ', $realURL));
            //~ if (FALSE === $realSysPath) {
            //~ $realSysPath = $podPress->TryToFindAbsFileName(str_replace('%20', ' ', $realURL));
            //~ }
            //~ $realURL = $podPress->convertPodcastFileNameToValidWebPath($realURL);
            //~ if ($podPress->settings['enable3rdPartyStats'] == 'PodTrac') {
            //~ $realURL = str_replace(array('ftp://', 'http://', 'https://'), '', $realURL);
            //~ $realURL = $podPress->podtrac_url.$realURL;
            //~ } elseif( strtolower($podPress->settings['enable3rdPartyStats']) == 'blubrry' && !empty($podPress->settings['statBluBrryProgramKeyword'])) {
            //~ $realURL = str_replace('http://', '', $realURL);
            //~ $realURL = $podPress->blubrry_url.$podPress->settings['statBluBrryProgramKeyword'].'/'.$realURL;
            //~ }
        }
    }
    if (TRUE === $print) {
        echo $realURL;
    } else {
        return $realURL;
    }
}