function podPress_stop_statistics($action = 'stop')
{
    $podpress_config = podPress_get_option('podPress_config');
    $do_update = FALSE;
    $result = FALSE;
    if (TRUE === is_Array($podpress_config) and TRUE === isset($podpress_config['enableStats'])) {
        switch ($action) {
            case 'stop':
                $podpress_config['enableStats'] = FALSE;
                $do_update = TRUE;
                break;
            case 'start':
                $podpress_config['enableStats'] = TRUE;
                $do_update = TRUE;
                break;
        }
        if (TRUE === $do_update) {
            $result = podPress_update_option('podPress_config', $podpress_config);
        }
    }
    echo '{ "code": "' . $podpress_config . ' - ' . $result . '" , "result": "' . $action . '" }';
}
 function settings_general_save()
 {
     global $wpdb;
     $blog_charset = get_bloginfo('charset');
     if (function_exists('check_admin_referer')) {
         check_admin_referer('podPress_general_options_nonce');
     }
     if (function_exists('wp_cache_flush')) {
         wp_cache_flush();
     }
     if (isset($_POST['mediaWebPath'])) {
         $mediaWebPath = trim($_POST['mediaWebPath']);
         $mediaWebPath = rtrim($mediaWebPath, '/');
         $this->settings['mediaWebPath'] = clean_url($mediaWebPath, array('http', 'https'), 'db');
     }
     if (isset($_POST['mediaFilePath'])) {
         $mediaFilePath = trim($_POST['mediaFilePath']);
         $mediaFilePath = rtrim($mediaFilePath, '/');
         $mediaFilePath = rtrim($mediaFilePath, '\\');
         $this->settings['mediaFilePath'] = strip_tags($mediaFilePath);
     }
     if (isset($_POST['enableStats'])) {
         $this->settings['enableStats'] = true;
         $this->createstatistictables();
     } else {
         $this->settings['enableStats'] = false;
     }
     if (isset($_POST['disabledashboardwidget'])) {
         $this->settings['disabledashboardwidget'] = TRUE;
     } else {
         $this->settings['disabledashboardwidget'] = FALSE;
     }
     if (isset($_POST['statMethod'])) {
         $this->settings['statMethod'] = $_POST['statMethod'];
     }
     if (isset($_POST['statLogging'])) {
         $this->settings['statLogging'] = $_POST['statLogging'];
     }
     if (isset($_POST['enable3rdPartyStats'])) {
         $this->settings['enable3rdPartyStats'] = $_POST['enable3rdPartyStats'];
     }
     if (isset($_POST['enableBlubrryStats'])) {
         $this->settings['enableBlubrryStats'] = true;
     } else {
         $this->settings['enableBlubrryStats'] = false;
     }
     if (isset($_POST['statBluBrryProgramKeyword'])) {
         $this->settings['statBluBrryProgramKeyword'] = $_POST['statBluBrryProgramKeyword'];
     }
     if (isset($_POST['maxMediaFiles'])) {
         $this->settings['maxMediaFiles'] = intval(preg_replace('/[^0-9]/', '', $_POST['maxMediaFiles']));
     }
     if (TRUE == isset($_POST['activate_podpressmedia_search']) and 'true' == $_POST['activate_podpressmedia_search']) {
         $this->settings['activate_podpressmedia_search'] = TRUE;
     } else {
         $this->settings['activate_podpressmedia_search'] = FALSE;
     }
     if (isset($_POST['enablePodangoIntegration'])) {
         $this->settings['enablePodangoIntegration'] = true;
     } else {
         $this->settings['enablePodangoIntegration'] = false;
     }
     if (isset($_POST['enablePremiumContent'])) {
         $this->settings['enablePremiumContent'] = true;
         if (is_object($GLOBALS['wp_rewrite']) && is_array($GLOBALS['wp_object_cache']) && is_array($GLOBALS['wp_object_cache']['cache']) && is_array($GLOBALS['wp_object_cache']['cache']['options']) && is_array($GLOBALS['wp_object_cache']['cache']['options']['alloptions']) && is_array($GLOBALS['wp_object_cache']['cache']['options']['alloptions']['rewrite_rules']) && !strpos($GLOBALS['wp_object_cache']['cache']['options']['alloptions']['rewrite_rules'], 'playlist.xspf')) {
             $GLOBALS['wp_rewrite']->flush_rules();
         }
     } else {
         $this->settings['enablePremiumContent'] = false;
     }
     // ntm: this is not active because there is no further line of code outside this file which uses this protectedMediaFilePath
     //~ if(isset($_POST['protectedMediaFilePath'])) {
     //~ $this->settings['protectedMediaFilePath'] = $_POST['protectedMediaFilePath'];
     //~ }
     if (isset($_POST['premiumMethod']) && $_POST['premiumMethod'] == 'Basic') {
         $this->settings['premiumMethod'] = 'Basic';
     } else {
         $this->settings['premiumMethod'] = 'Digest';
     }
     if (isset($_POST['premiumContentFakeEnclosure'])) {
         $this->settings['premiumContentFakeEnclosure'] = true;
     } else {
         $this->settings['premiumContentFakeEnclosure'] = false;
     }
     if (isset($_POST['enableTorrentCasting'])) {
         $this->settings['enableTorrentCasting'] = true;
     } else {
         $this->settings['enableTorrentCasting'] = false;
     }
     if (isset($_POST['feedCacheDir'])) {
         $this->settings['feedCacheDir'] = $_POST['feedCacheDir'];
     }
     if (isset($_POST['contentBeforeMore'])) {
         $this->settings['contentBeforeMore'] = $_POST['contentBeforeMore'];
     }
     if (isset($_POST['contentLocation'])) {
         $this->settings['contentLocation'] = $_POST['contentLocation'];
     }
     if (isset($_POST['contentImage'])) {
         $this->settings['contentImage'] = $_POST['contentImage'];
     }
     if (isset($_POST['contentPlayer'])) {
         $this->settings['contentPlayer'] = $_POST['contentPlayer'];
     }
     if (isset($_POST['contentHidePlayerPlayNow'])) {
         $this->settings['contentHidePlayerPlayNow'] = $_POST['contentHidePlayerPlayNow'];
     }
     if (isset($_POST['contentDownload'])) {
         $this->settings['contentDownload'] = $_POST['contentDownload'];
     }
     if (isset($_POST['contentDownloadText'])) {
         $this->settings['contentDownloadText'] = $_POST['contentDownloadText'];
     }
     if (isset($_POST['contentDownloadStats'])) {
         $this->settings['contentDownloadStats'] = $_POST['contentDownloadStats'];
     }
     if (TRUE == isset($_POST['contentDuration'])) {
         $duration_schemes = array('h:m:s', 'm:s', 'h:m:s:ms', 'm:s:ms', 's:ms', 'h', 'm', 's', 'ms');
         if (TRUE == in_array($_POST['contentDuration'], $duration_schemes) or 'disabled' == $_POST['contentDuration']) {
             $this->settings['contentDuration'] = $_POST['contentDuration'];
         } else {
             $this->settings['contentDuration'] = 'h:m:s';
         }
     }
     if (TRUE == isset($_POST['contentDurationdivider'])) {
         $duration_dividers = array('colon', 'hminsms', 'hrminsecmsec', 'hoursminutessecondsmilliseconds');
         if (TRUE == in_array($_POST['contentDurationdivider'], $duration_dividers)) {
             $this->settings['contentDurationdivider'] = $_POST['contentDurationdivider'];
         } else {
             $this->settings['contentDurationdivider'] = 'colon';
         }
     }
     if (TRUE == isset($_POST['contentfilesize']) and ('disabled' === $_POST['contentfilesize'] or 'enabled' === $_POST['contentfilesize'])) {
         $this->settings['contentfilesize'] = $_POST['contentfilesize'];
     }
     if (TRUE == isset($_POST['incontentandexcerpt'])) {
         $incontentandexcerpt_vals = array('in_content_and_excerpt', 'in_content_only', 'in_excerpt_only');
         if (TRUE == in_array($_POST['incontentandexcerpt'], $incontentandexcerpt_vals)) {
             $this->settings['incontentandexcerpt'] = $_POST['incontentandexcerpt'];
         } else {
             $this->settings['incontentandexcerpt'] = 'in_content_and_excerpt';
         }
     }
     if (isset($_POST['do_not_use_the_target_attribute'])) {
         $this->settings['do_not_use_the_target_attribute'] = TRUE;
     } else {
         $this->settings['do_not_use_the_target_attribute'] = FALSE;
     }
     if (TRUE == isset($_POST['metaboxforcustomposttypes']) and TRUE == is_array($_POST['metaboxforcustomposttypes'])) {
         $this->settings['metaboxforcustomposttypes'] = $_POST['metaboxforcustomposttypes'];
     } else {
         $this->settings['metaboxforcustomposttypes'] = array();
         if (FALSE == isset($_POST['metaboxforcustomposttypes'])) {
             unset($this->settings['metaboxforcustomposttypes']);
         }
     }
     if (isset($_POST['enableFooter'])) {
         $this->settings['enableFooter'] = true;
     } else {
         $this->settings['enableFooter'] = false;
     }
     if (isset($_POST['enableVersionInFeeds'])) {
         $this->settings['enableVersionInFeeds'] = true;
     } else {
         $this->settings['enableVersionInFeeds'] = false;
     }
     if (isset($_POST['disableVersionNumber'])) {
         $this->settings['disableVersionNumber'] = true;
     } else {
         $this->settings['disableVersionNumber'] = false;
     }
     if (isset($_POST['cleanupOldMetaKeys'])) {
         $sql = "DELETE FROM " . $wpdb->prefix . "postmeta WHERE meta_key IN('podPress_podcastStandardAudio',\n\t\t\t\t                                                                 'podPress_podcastStandardAudioSize',\n\t\t\t\t                                                                 'podPress_podcastStandardAudioDuration',\n\t\t\t\t                                                                 'podPress_podcastEnhancedAudio',\n\t\t\t\t                                                                 'podPress_podcastEnhancedAudioSize',\n\t\t\t\t                                                                 'podPress_podcastEnhancedAudioDuration',\n\t\t\t\t                                                                 'podPress_podcastVideo',\n\t\t\t\t                                                                 'podPress_podcastVideoSize',\n\t\t\t\t                                                                 'podPress_podcastVideoDuration',\n\t\t\t\t                                                                 'podPress_podcastVideoDimension',\n\t\t\t\t                                                                 'podPress_webVideo',\n\t\t\t\t                                                                 'podPress_webVideoSize',\n\t\t\t\t                                                                 'podPress_webVideoDuration',\n\t\t\t\t                                                                 'podPress_webVideoDimension',\n\t\t\t\t                                                                 'podPress_podcastEbook',\n\t\t\t\t                                                                 'podPress_podcastEbookSize',\n\t\t\t\t                                                                 'itunes:duration',\n\t\t\t\t                                                                 'enclosure',\n\t\t\t\t                                                                 'enclosure_hold')";
         $wpdb->query($sql);
     }
     if (TRUE == isset($_POST['podpress_add_underscore_to_old_meta_keys'])) {
         // rename the post specific settings and the media meta keys.
         $wpdb->query($wpdb->prepare("UPDATE " . $wpdb->prefix . "postmeta SET meta_key = '_podPressPostSpecific' WHERE meta_key = 'podPressPostSpecific'"));
         $wpdb->query($wpdb->prepare("UPDATE " . $wpdb->prefix . "postmeta SET meta_key = '_podPressMedia' WHERE meta_key = 'podPressMedia'"));
         // update the version number in the db
         $current = constant('PODPRESS_VERSION');
         update_option('podPress_version', $current);
     }
     if (TRUE == isset($_POST['podpress_version_set_back_to'])) {
         update_option('podPress_version', strip_tags(trim($_POST['podpress_version_set_back_to'])));
     }
     $result = podPress_update_option('podPress_config', $this->settings);
     if (FALSE !== $result) {
         $location = get_option('siteurl') . '/wp-admin/admin.php?page=podpress/podpress_general.php&updated=true';
     } else {
         $location = get_option('siteurl') . '/wp-admin/admin.php?page=podpress/podpress_general.php&updated=false';
     }
     header('Location: ' . $location);
     exit;
 }
 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;
     }
 }
Esempio n. 4
0
function podPress_admin_footer()
{
    global $podPress;
    if (isset($podPress->settings['compatibilityChecks']['themeTested']) and !$podPress->settings['compatibilityChecks']['themeTested']) {
        $podPress->settings['compatibilityChecks']['themeTested'] = true;
        podPress_update_option('podPress_config', $podPress->settings);
    }
    if (isset($podPress->settings['compatibilityChecks']['wp_footer']) and !$podPress->settings['compatibilityChecks']['wp_footer']) {
        $podPress->settings['compatibilityChecks']['wp_footer'] = true;
        podPress_update_option('podPress_config', $podPress->settings);
    } else {
        $podPress->settings['compatibilityChecks']['wp_footer'] = true;
    }
}
 function insert_content($content = '', $is_the_excerpt = FALSE)
 {
     global $post, $podPressTemplateData, $podPressTemplateUnauthorizedData, $wpdb, $wp_version, $podpress_is_itunessubtitle_or_summary, $podPress;
     if (!empty($post->post_password)) {
         // if there's a password
         //~ printphpnotices_var_dump('post has a password');
         //~ printphpnotices_var_dump($_COOKIE['wp-postpass_'.COOKIEHASH]);
         //~ printphpnotices_var_dump($post->post_password);
         $cookiehash = stripslashes($_COOKIE['wp-postpass_' . COOKIEHASH]);
         //~ printphpnotices_var_dump(wp_check_password($post->post_password, $cookiehash));
         if (TRUE === version_compare($wp_version, '2.5', '>=')) {
             if ($cookiehash != $post->post_password and FALSE === wp_check_password($post->post_password, $cookiehash)) {
                 // and it doesn't match the cookie
                 return $content;
             }
         } else {
             if ($cookiehash != $post->post_password) {
                 // and it doesn't match the cookie
                 return $content;
             }
         }
     }
     //~ printphpnotices_var_dump(wp_check_password($post->ID));
     if ($this->isexcerpt === $is_the_excerpt) {
         unset($this->tempcontentaddedto[$post->ID]);
     }
     $this->isexcerpt = FALSE;
     //~ if ( isset($podpress_is_itunessubtitle_or_summary) ) {
     //~ printphpnotices_var_dump('podpress_is_itunessubtitle_or_summary exists');
     //~ if ( TRUE === $podpress_is_itunessubtitle_or_summary ) {
     //~ printphpnotices_var_dump('podpress_is_itunessubtitle_or_summary : TRUE');
     //~ } else {
     //~ printphpnotices_var_dump('podpress_is_itunessubtitle_or_summary : FALSE');
     //~ }
     //~ } else {
     //~ printphpnotices_var_dump('podpress_is_itunessubtitle_or_summary does not exist');
     //~ }
     if (isset($this->tempcontentaddedto[$post->ID])) {
         if (is_feed()) {
             //~ printphpnotices_var_dump('A:');
             //~ printphpnotices_var_dump($print_podpress_elements_in_contentencoded);
             //~ printphpnotices_var_dump(isset($podpress_is_itunessubtitle_or_summary));
             //~ printphpnotices_var_dump($podpress_is_itunessubtitle_or_summary);
             if (FALSE === isset($podPress->settings['print_podpress_in_contentencoded']) or FALSE === $podPress->settings['print_podpress_in_contentencoded'] or TRUE === isset($podpress_is_itunessubtitle_or_summary) and TRUE === $podpress_is_itunessubtitle_or_summary) {
                 return str_replace($this->podcasttag, '', $content);
             } else {
                 return $content;
             }
         } else {
             return $content;
         }
     } else {
         $this->tempcontentaddedto[$post->ID] = true;
     }
     if (is_feed()) {
         //~ printphpnotices_var_dump('B:');
         //~ printphpnotices_var_dump($print_podpress_elements_in_contentencoded);
         //~ printphpnotices_var_dump(isset($podpress_is_itunessubtitle_or_summary));
         //~ printphpnotices_var_dump($podpress_is_itunessubtitle_or_summary);
         if (FALSE === isset($podPress->settings['print_podpress_in_contentencoded']) or FALSE === $podPress->settings['print_podpress_in_contentencoded'] or TRUE === isset($podpress_is_itunessubtitle_or_summary) and TRUE === $podpress_is_itunessubtitle_or_summary) {
             return str_replace($this->podcasttag, '', $content);
         }
     }
     if (!is_array($post->podPressMedia)) {
         return str_replace($this->podcasttag, '', $content);
     }
     if (FALSE === stristr($content, $this->podcasttag)) {
         if ($this->settings['contentBeforeMore'] == 'no') {
             if (is_home() or is_archive()) {
                 if (FALSE !== strpos($post->post_content, '<!--more-->')) {
                     return $content;
                 }
             }
         }
         if ($this->settings['contentLocation'] == 'start') {
             $content = $this->podcasttag . $content;
         } else {
             $content .= $this->podcasttag;
         }
     }
     $podpressTag_in_the_content = '<p>' . $this->podcasttag . '</p>';
     // add the player and the other elements not if the related setting has been set
     if (TRUE == isset($this->settings['incontentandexcerpt'])) {
         if ($is_the_excerpt === TRUE) {
             switch ($this->settings['incontentandexcerpt']) {
                 default:
                 case 'in_content_and_excerpt':
                 case 'in_excerpt_only':
                     break;
                 case 'in_content_only':
                     if (FALSE !== stripos($content, $podpressTag_in_the_content)) {
                         return str_replace($podpressTag_in_the_content, '', $content);
                     } else {
                         return str_replace($this->podcasttag, '', $content);
                     }
                     break;
             }
         } else {
             switch ($this->settings['incontentandexcerpt']) {
                 default:
                 case 'in_content_and_excerpt':
                 case 'in_content_only':
                     break;
                 case 'in_excerpt_only':
                     if (FALSE !== stripos($content, $podpressTag_in_the_content)) {
                         return str_replace($podpressTag_in_the_content, '', $content);
                     } else {
                         return str_replace($this->podcasttag, '', $content);
                     }
                     break;
             }
         }
     }
     //~ $podPressRSSContent = '';
     $showmp3player = false;
     $showvideopreview = false;
     $showvideoplayer = false;
     $podPressTemplateData = array();
     $podPressTemplateData['showDownloadText'] = $this->settings['contentDownloadText'];
     $podPressTemplateData['showDownloadStats'] = $this->settings['contentDownloadStats'];
     $podPressTemplateData['showDuration'] = $this->settings['contentDuration'];
     $podPressTemplateData['showfilesize'] = $this->settings['contentfilesize'];
     $this->playerCount++;
     $podPressTemplateData['files'] = array();
     $podPressTemplateData['player'] = array();
     reset($post->podPressMedia);
     while (list($key) = each($post->podPressMedia)) {
         if (empty($post->podPressMedia[$key]['previewImage'])) {
             $post->podPressMedia[$key]['previewImage'] = $this->settings['videoPreviewImage'];
         }
         $supportedVideoTypes = array('video_mp4', 'video_m4v', 'video_mov', 'video_qt', 'video_avi', 'video_mpg', 'video_asf', 'video_wmv', 'video_flv', 'video_swf', 'video_ogv');
         if (TRUE == $this->settings['disableVideoPreview'] and TRUE == in_array($post->podPressMedia[$key]['type'], $supportedVideoTypes)) {
             $post->podPressMedia[$key]['disablePreview'] = true;
         }
         if (TRUE == isset($post->podPressMedia[$key]['feedonly']) and 'on' == $post->podPressMedia[$key]['feedonly']) {
             continue;
         }
         $post->podPressMedia[$key]['title'] = htmlentities(stripslashes($post->podPressMedia[$key]['title']), ENT_QUOTES, get_option('blog_charset'));
         $post->podPressMedia[$key]['stats'] = false;
         if ($this->settings['enableStats']) {
             $pos = strrpos($post->podPressMedia[$key]['URI'], '/');
             //$len = strlen($post->podPressMedia[$key]['URI']);
             while (substr($post->podPressMedia[$key]['URI'], $pos, 1) == '/') {
                 $pos++;
             }
             $filename = substr($post->podPressMedia[$key]['URI'], $pos);
             if ($this->settings['statLogging'] == 'Full' || $this->settings['statLogging'] == 'FullPlus') {
                 $where = $this->wherestr_to_exclude_bots('', 'AND');
                 $query_string = "SELECT method, COUNT(DISTINCT id) as downloads FROM " . $wpdb->prefix . "podpress_stats WHERE postID='" . $post->ID . "' AND media='" . rawurlencode($filename) . "' " . $where . "GROUP BY method ORDER BY method ASC";
                 $stats = $wpdb->get_results($query_string);
                 if (0 < count($stats)) {
                     $feed = intval($stats[0]->downloads);
                     $play = intval($stats[1]->downloads);
                     $web = intval($stats[2]->downloads);
                     $post->podPressMedia[$key]['stats'] = array('feed' => $feed, 'web' => $web, 'play' => $play, 'total' => $feed + $play + $web);
                 }
             } else {
                 $sql = "SELECT * FROM " . $wpdb->prefix . "podpress_statcounts WHERE media = '" . rawurlencode($filename) . "'";
                 $stats = $wpdb->get_results($sql);
                 if ($stats) {
                     $post->podPressMedia[$key]['stats'] = array('feed' => intval($stats[0]->feed), 'web' => intval($stats[0]->web), 'play' => intval($stats[0]->play), 'total' => intval($stats[0]->total));
                 }
             }
         }
         $supportedMediaTypes = array('audio_mp3', 'audio_ogg', 'audio_m4a', 'audio_mp4', 'audio_m3u', 'video_mp4', 'video_m4v', 'video_mov', 'video_qt', 'video_avi', 'video_mpg', 'video_asf', 'video_wmv', 'audio_wma', 'video_flv', 'video_swf', 'video_ogv', 'ebook_pdf', 'ebook_epub', 'embed_youtube', 'misc_torrent');
         if (!in_array($post->podPressMedia[$key]['type'], $supportedMediaTypes)) {
             $post->podPressMedia[$key]['type'] = 'misc_other';
         }
         // this loop is for the basics. After this the unauthorized content will stop
         if (empty($post->podPressMedia[$key]['title'])) {
             $post->podPressMedia[$key]['title'] = podPress_defaultTitles($post->podPressMedia[$key]['type']);
         }
         if ('##Global##' == $post->podPressPostSpecific['itunes:author']) {
             global $podPress;
             if (empty($podPress->settings['iTunes']['author'])) {
                 $post->podPressMedia[$key]['artist'] = get_bloginfo('blogname');
             } else {
                 $post->podPressMedia[$key]['artist'] = $podPress->settings['iTunes']['author'];
             }
         } else {
             $post->podPressMedia[$key]['artist'] = $post->podPressPostSpecific['itunes:author'];
         }
         if ($this->settings['contentImage'] != 'none') {
             $post->podPressMedia[$key]['image'] = $post->podPressMedia[$key]['type'] . '_' . $this->settings['contentImage'] . '.png';
         }
         if ($post->podPressMedia[$key]['authorized']) {
             $post->podPressMedia[$key]['URI_orig'] = $post->podPressMedia[$key]['URI'];
             $post->podPressMedia[$key]['URI'] = $this->convertPodcastFileNameToWebPath($post->ID, $key, $post->podPressMedia[$key]['URI'], 'web');
             $post->podPressMedia[$key]['URI_Player'] = $this->convertPodcastFileNameToWebPath($post->ID, $key, $post->podPressMedia[$key]['URI_orig'], 'play');
             if (!empty($post->podPressMedia[$key]['URI_torrent'])) {
                 $post->podPressMedia[$key]['URI_torrent'] = $this->convertPodcastFileNameToWebPath($post->ID, $key, $post->podPressMedia[$key]['URI_torrent'], 'web');
             }
             if ($this->settings['contentDownload'] == 'disabled') {
                 $post->podPressMedia[$key]['enableDownload'] = false;
                 $post->podPressMedia[$key]['enableTorrentDownload'] = false;
             } else {
                 $post->podPressMedia[$key]['enableDownload'] = true;
                 //~ $podPressRSSContent .= '<a href="'.$post->podPressMedia[$key]['URI'].'">'.__('Download', 'podpress').' '.__($post->podPressMedia[$key]['title'], 'podpress').'</a><br/>';
                 if ($this->settings['enableTorrentCasting'] && !empty($post->podPressMedia[$key]['URI_torrent'])) {
                     $post->podPressMedia[$key]['enableTorrentDownload'] = true;
                 }
             }
             switch ($this->settings['contentPlayer']) {
                 case 'disabled':
                     $post->podPressMedia[$key]['enablePlayer'] = false;
                     $post->podPressMedia[$key]['enablePopup'] = false;
                     break;
                 case 'inline':
                     $post->podPressMedia[$key]['enablePlayer'] = true;
                     $post->podPressMedia[$key]['enablePopup'] = false;
                     break;
                 case 'popup':
                     $post->podPressMedia[$key]['enablePlayer'] = false;
                     $post->podPressMedia[$key]['enablePopup'] = true;
                     break;
                 case 'both':
                     $post->podPressMedia[$key]['enablePlayer'] = true;
                     $post->podPressMedia[$key]['enablePopup'] = true;
                 default:
             }
             if ($this->settings['contentHidePlayerPlayNow'] == 'disabled') {
                 $post->podPressMedia[$key]['enablePlaylink'] = FALSE;
             } else {
                 $post->podPressMedia[$key]['enablePlaylink'] = TRUE;
             }
             if ($post->podPressMedia[$key]['enablePlayer']) {
                 // This loop is to put together the player data.
                 switch ($post->podPressMedia[$key]['type']) {
                     case 'audio_mp3':
                         $post->podPressMedia[$key]['dimensionW'] = 290;
                         $post->podPressMedia[$key]['dimensionH'] = 24;
                         //~ $post->podPressMedia[$key]['dimensionW'] = 300;
                         //~ $post->podPressMedia[$key]['dimensionH'] = 30;
                         break;
                     case 'audio_ogg':
                     case 'audio_opus':
                     case 'audio_m4a':
                     case 'audio_mp4':
                     case 'audio_wma':
                     case 'video_ogv':
                     case 'video_m4v':
                     case 'video_mp4':
                     case 'video_mov':
                     case 'video_qt':
                     case 'video_avi':
                     case 'video_mpg':
                     case 'video_asf':
                     case 'video_wmv':
                     case 'video_flv':
                     case 'video_swf':
                         break;
                     case 'embed_youtube':
                         $x = parse_url($post->podPressMedia[$key]['URI_orig']);
                         $x = explode('&', $x['query']);
                         foreach ($x as $v) {
                             if (substr($v, 0, 2) == 'v=') {
                                 if (str_replace('/', '', $post->podPressMedia[$key]['previewImage']) == str_replace('/', '', $this->settings['videoPreviewImage'])) {
                                     $post->podPressMedia[$key]['previewImage'] = 'http://img.youtube.com/vi/' . substr($v, 2) . '/default.jpg';
                                 }
                                 $post->podPressMedia[$key]['URI_Player'] = substr($v, 2) . '.youtube';
                                 break;
                             }
                         }
                         $post->podPressMedia[$key]['URI'] = $post->podPressMedia[$key]['URI_orig'];
                         break;
                     case 'audio_m3u':
                         $post->podPressMedia[$key]['enableDownload'] = true;
                     case 'ebook_pdf':
                     case 'ebook_epub':
                     default:
                         $post->podPressMedia[$key]['enablePlayer'] = false;
                         $post->podPressMedia[$key]['enablePopup'] = false;
                 }
             }
         }
         if (TRUE == isset($post->podPressMedia[$key]['disablePlayer']) and (TRUE === $post->podPressMedia[$key]['disablePlayer'] or 'on' == $post->podPressMedia[$key]['disablePlayer'])) {
             $post->podPressMedia[$key]['enablePlayer'] = false;
             $post->podPressMedia[$key]['enablePopup'] = false;
         }
         $podPressTemplateData['files'][] = $post->podPressMedia[$key];
         $post->podPressMedia[$key]['URI'] = $post->podPressMedia[$key]['URI_orig'];
         unset($post->podPressMedia[$key]['URI_orig']);
     }
     if (!$this->settings['compatibilityChecks']['wp_head']) {
         $podPressContent = '<code>' . __('podPress theme compatibility problem. Please check podPress->General Settings for more information.', 'podpress') . '</code><br/>';
         $this->settings['compatibilityChecks']['wp_head'] = false;
         $this->settings['compatibilityChecks']['wp_footer'] = false;
         podPress_update_option('podPress_config', $this->settings);
     } else {
         /* The theme file needs to populate these */
         $podPressContent = podPress_webContent($podPressTemplateData);
     }
     if (FALSE !== stripos($content, $podpressTag_in_the_content)) {
         return str_replace($podpressTag_in_the_content, $podPressContent, $content);
     } else {
         return str_replace($this->podcasttag, $podPressContent, $content);
     }
 }
 function settings_players_save()
 {
     if (function_exists('check_admin_referer')) {
         check_admin_referer('podPress_player_settings_nonce');
     }
     if (function_exists('wp_cache_flush')) {
         wp_cache_flush();
     }
     if (isset($_POST['contentAutoDisplayPlayer'])) {
         $this->settings['contentAutoDisplayPlayer'] = true;
     } else {
         $this->settings['contentAutoDisplayPlayer'] = false;
     }
     $this->settings['videoPreviewImage'] = clean_url($_POST['videoPreviewImage'], array('http', 'https'), 'db');
     $this->settings['videoDefaultPlayerSize_x'] = intval(preg_replace('/[^0-9]/', '', $_POST['videoDefaultPlayerSize_x']));
     if ($this->settings['videoDefaultPlayerSize_x'] < 0) {
         $this->settings['videoDefaultPlayerSize_x'] = 320;
     }
     $this->settings['videoDefaultPlayerSize_y'] = intval(preg_replace('/[^0-9]/', '', $_POST['videoDefaultPlayerSize_y']));
     if ($this->settings['videoDefaultPlayerSize_y'] < 0) {
         $this->settings['videoDefaultPlayerSize_y'] = 240;
     }
     if (isset($_POST['disableVideoPreview'])) {
         $this->settings['disableVideoPreview'] = true;
     } else {
         $this->settings['disableVideoPreview'] = false;
     }
     if (isset($_POST['mp3Player']) && $_POST['mp3Player'] == '1pixelout') {
         $this->settings['mp3Player'] = '1pixelout';
     } else {
         $this->settings['mp3Player'] = 'podango';
     }
     if (isset($_POST['cortado_version']) and 'cortado_signed' == $_POST['cortado_version']) {
         $this->settings['cortado_version'] = 'cortado_signed';
     } else {
         $this->settings['cortado_version'] = 'cortado_default';
     }
     $this->settings['player'] = $_POST['playerSettings'];
     // ntm: the listenWrapper value is now TRUE or FALSE (bool)
     if (isset($_POST['playerSettings']['listenWrapper'])) {
         $this->settings['player']['listenWrapper'] = true;
     } else {
         $this->settings['player']['listenWrapper'] = false;
     }
     if (isset($_POST['playerSettings']['checkpolicy'])) {
         $this->settings['player']['checkpolicy'] = 'yes';
     } else {
         $this->settings['player']['checkpolicy'] = 'no';
     }
     if (isset($_POST['playerSettings']['overwriteTitleandArtist'])) {
         $this->settings['player']['overwriteTitleandArtist'] = 'yes';
     } else {
         $this->settings['player']['overwriteTitleandArtist'] = 'no';
     }
     if (isset($_POST['playerSettings']['remaining'])) {
         $this->settings['player']['remaining'] = 'yes';
     } else {
         $this->settings['player']['remaining'] = 'no';
     }
     if (isset($_POST['playerSettings']['animation'])) {
         $this->settings['player']['animation'] = 'no';
     } else {
         $this->settings['player']['animation'] = 'yes';
     }
     if (TRUE == isset($_POST['use_html5_media_tags'])) {
         $this->settings['use_html5_media_tags'] = TRUE;
     } else {
         $this->settings['use_html5_media_tags'] = FALSE;
     }
     if (TRUE == isset($_POST['showhtml5playersonpageload'])) {
         $this->settings['showhtml5playersonpageload'] = TRUE;
     } else {
         $this->settings['showhtml5playersonpageload'] = FALSE;
     }
     $result = podPress_update_option('podPress_config', $this->settings);
     if (FALSE !== $result) {
         $location = site_url() . '/wp-admin/admin.php?page=podpress/podpress_players.php&updated=true';
     } else {
         $location = site_url() . '/wp-admin/admin.php?page=podpress/podpress_players.php&updated=false';
     }
     header('Location: ' . $location);
     exit;
 }
 function settings_feed_save()
 {
     global $wp_rewrite;
     if (function_exists('check_admin_referer')) {
         check_admin_referer('podPress_feed_settings_nonce');
     }
     $blog_charset = get_bloginfo('charset');
     if (function_exists('wp_cache_flush')) {
         wp_cache_flush();
     }
     if (isset($_POST['iTunes'])) {
         $iTunesSettings = $_POST['iTunes'];
         $iTunesSettings['summary'] = htmlspecialchars(strip_tags(trim($_POST['iTunes']['summary'])), ENT_QUOTES, $blog_charset);
         $iTunesSettings['image'] = clean_url($_POST['iTunes']['image'], array('http', 'https'), 'db');
         $iTunesSettings['author'] = htmlspecialchars(strip_tags(trim($_POST['iTunes']['author'])), ENT_QUOTES, $blog_charset);
         $iTunesSettings['subtitle'] = htmlspecialchars(strip_tags(trim($_POST['iTunes']['subtitle'])), ENT_QUOTES, $blog_charset);
         $iTunesSettings['keywords'] = $this->cleanup_itunes_keywords($_POST['iTunes']['keywords'], $blog_charset);
         $iTunesSettings['category'] = array();
         if (is_array($_POST['iTunes']['category'])) {
             foreach ($_POST['iTunes']['category'] as $value) {
                 if ('#' != $value and '[ ' . __('nothing', 'podpress') . ' ]' != $value) {
                     $iTunesSettings['category'][] = $value;
                 }
             }
         }
         $this->settings['iTunes'] = $iTunesSettings;
     }
     //~ if(isset($_POST['blogname'])) { podPress_update_option('blogname', htmlspecialchars(strip_tags(trim($_POST['blogname'])), ENT_QUOTES, $blog_charset)); }
     //~ if(isset($_POST['blogdescription'])) { podPress_update_option('blogdescription', htmlspecialchars(strip_tags(trim($_POST['blogdescription'])), ENT_QUOTES, $blog_charset)); }
     //~ if(isset($_POST['admin_email'])) { podPress_update_option('admin_email', htmlspecialchars(strip_tags(trim($_POST['admin_email'])), ENT_QUOTES, $blog_charset)); }
     //~ if(isset($_POST['blog_charset'])) { podPress_update_option('blog_charset', htmlspecialchars(strtoupper(strip_tags(trim($_POST['blog_charset']))), ENT_QUOTES, $blog_charset)); }
     //~ if(isset($_POST['posts_per_rss'])) { podPress_update_option('posts_per_rss', intval(preg_replace('/[^0-9]/', '', $_POST['posts_per_rss']))); }
     if (isset($_POST['rss_language'])) {
         podPress_update_option('rss_language', htmlspecialchars(strip_tags(trim($_POST['rss_language'])), ENT_QUOTES, $blog_charset));
     }
     if (isset($_POST['rss_ttl'])) {
         podPress_update_option('rss_ttl', intval(preg_replace('/[^0-9]/', '', $_POST['rss_ttl'])));
     }
     if (isset($_POST['rss_image'])) {
         podPress_update_option('rss_image', htmlspecialchars(strip_tags(trim($_POST['rss_image'])), ENT_QUOTES, $blog_charset));
     }
     if (isset($_POST['rss_category'])) {
         $this->settings['rss_category'] = htmlspecialchars(strip_tags(trim($_POST['rss_category'])), ENT_QUOTES, $blog_charset);
     }
     if (isset($_POST['rss_copyright'])) {
         $this->settings['rss_copyright'] = htmlspecialchars(strip_tags(trim($_POST['rss_copyright'])), ENT_QUOTES, $blog_charset);
     }
     if (isset($_POST['rss_license_url'])) {
         $this->settings['rss_license_url'] = clean_url($_POST['rss_license_url'], array('http', 'https'), 'db');
     }
     if (isset($_POST['print_podpress_in_contentencoded']) and 'yes' == $_POST['print_podpress_in_contentencoded']) {
         $this->settings['print_podpress_in_contentencoded'] = TRUE;
     }
     //~ if( isset($_POST['protectFeed']) AND 'yes' == strtolower($_POST['protectFeed']) ) {
     //~ $this->settings['protectFeed'] = 'Yes';
     //~ } else {
     //~ $this->settings['protectFeed'] = 'No';
     //~ }
     //~ if(isset($_POST['rss_showlinks'])) {
     //~ $this->settings['rss_showlinks'] = $_POST['rss_showlinks'];
     //~ }
     if (isset($_POST['podcastFeedURL'])) {
         $this->settings['podcastFeedURL'] = clean_url($_POST['podcastFeedURL'], array('http', 'https'), 'db');
     }
     if (isset($_POST['podpress_feeds'])) {
         $i = 0;
         foreach ($_POST['podpress_feeds'] as $feed) {
             $name = htmlspecialchars(strip_tags(trim($feed['name'])), ENT_QUOTES, $blog_charset);
             if (empty($feed['slug'])) {
                 $feed['slug'] = $name;
             }
             $slug = sanitize_title_with_dashes(trim($feed['slug']));
             if (TRUE == defined('PODPRESS_DEACTIVATE_PREMIUM') and TRUE === constant('PODPRESS_DEACTIVATE_PREMIUM') and 'premium' == $slug) {
                 $name = '';
             }
             if (FALSE == empty($name) and FALSE == empty($slug)) {
                 if (isset($feed['use'])) {
                     $this->settings['podpress_feeds'][$i]['use'] = TRUE;
                 } else {
                     $this->settings['podpress_feeds'][$i]['use'] = FALSE;
                 }
                 if (isset($feed['premium'])) {
                     $this->settings['podpress_feeds'][$i]['premium'] = TRUE;
                 } else {
                     $this->settings['podpress_feeds'][$i]['premium'] = FALSE;
                 }
                 if (TRUE == defined('PODPRESS_DEACTIVATE_PREMIUM') and TRUE === constant('PODPRESS_DEACTIVATE_PREMIUM')) {
                     $this->settings['podpress_feeds'][$i]['premium'] = FALSE;
                 }
                 $this->settings['podpress_feeds'][$i]['name'] = $name;
                 if (isset($feed['feedtitle']) and 'blognameastitle' === $feed['feedtitle']) {
                     $this->settings['podpress_feeds'][$i]['feedtitle'] = 'blognameastitle';
                 } elseif (isset($feed['feedtitle']) and 'feednameastitle' === $feed['feedtitle']) {
                     $this->settings['podpress_feeds'][$i]['feedtitle'] = 'feednameastitle';
                 } else {
                     $this->settings['podpress_feeds'][$i]['feedtitle'] = 'append';
                 }
                 $this->settings['podpress_feeds'][$i]['slug'] = $slug;
                 $this->settings['podpress_feeds'][$i]['subtitle'] = htmlspecialchars(strip_tags(trim($feed['subtitle'])), ENT_QUOTES, $blog_charset);
                 if (isset($feed['itunes-newfeedurl']) and 'Enable' === $feed['itunes-newfeedurl']) {
                     $this->settings['podpress_feeds'][$i]['itunes-newfeedurl'] = 'Enable';
                 } else {
                     $this->settings['podpress_feeds'][$i]['itunes-newfeedurl'] = 'Disable';
                 }
                 $this->settings['podpress_feeds'][$i]['newfeedurl'] = clean_url($feed['newfeedurl'], array('http', 'https'), 'db');
                 if (FALSE !== empty($this->settings['podpress_feeds'][$i]['newfeedurl'])) {
                     $this->settings['podpress_feeds'][$i]['itunes-newfeedurl'] = 'Disable';
                 }
                 $this->settings['podpress_feeds'][$i]['descr'] = htmlspecialchars(strip_tags(trim($feed['descr'])), ENT_QUOTES, $blog_charset);
                 $this->settings['podpress_feeds'][$i]['rss_category'] = htmlspecialchars(strip_tags(trim($feed['rss_category'])), ENT_QUOTES, $blog_charset);
                 if (FALSE == is_array($feed['itunes-category'])) {
                     $this->settings['podpress_feeds'][$i]['itunes-category'] = array();
                 } else {
                     $this->settings['podpress_feeds'][$i]['itunes-category'] = $feed['itunes-category'];
                 }
                 $this->settings['podpress_feeds'][$i]['itunes-keywords'] = $this->cleanup_itunes_keywords($feed['itunes-keywords'], $blog_charset);
                 $this->settings['podpress_feeds'][$i]['itunes-author'] = htmlspecialchars(strip_tags(trim($feed['itunes-author'])), ENT_QUOTES, $blog_charset);
                 $this->settings['podpress_feeds'][$i]['email'] = htmlspecialchars(strip_tags(trim($feed['email'])), ENT_QUOTES, $blog_charset);
                 $this->settings['podpress_feeds'][$i]['itunes-image'] = clean_url($feed['itunes-image'], array('http', 'https'), 'db');
                 $this->settings['podpress_feeds'][$i]['rss_image'] = clean_url($feed['rss_image'], array('http', 'https'), 'db');
                 $this->settings['podpress_feeds'][$i]['copyright'] = htmlspecialchars(strip_tags(trim($feed['copyright'])), ENT_QUOTES, $blog_charset);
                 $this->settings['podpress_feeds'][$i]['license_url'] = clean_url($feed['license_url'], array('http', 'https'), 'db');
                 $this->settings['podpress_feeds'][$i]['language'] = htmlspecialchars(strip_tags(trim($feed['language'])), ENT_QUOTES, $blog_charset);
                 $this->settings['podpress_feeds'][$i]['charset'] = htmlspecialchars(strip_tags(trim($feed['charset'])), ENT_QUOTES, $blog_charset);
                 if (FALSE == is_array($feed['PostTypes'])) {
                     $this->settings['podpress_feeds'][$i]['PostTypes'] = array();
                 } else {
                     $this->settings['podpress_feeds'][$i]['PostTypes'] = $feed['PostTypes'];
                 }
                 if (FALSE == is_array($feed['FileTypes'])) {
                     $this->settings['podpress_feeds'][$i]['FileTypes'] = array();
                 } else {
                     $this->settings['podpress_feeds'][$i]['FileTypes'] = $feed['FileTypes'];
                 }
                 if (FALSE == is_array($feed['inclCategories'])) {
                     $this->settings['podpress_feeds'][$i]['inclCategories'] = array();
                 } else {
                     $this->settings['podpress_feeds'][$i]['inclCategories'] = array();
                     foreach ($feed['inclCategories'] as $category) {
                         $this->settings['podpress_feeds'][$i]['inclCategories'][] = intval(preg_replace('/[^0-9]/', '', $category));
                     }
                 }
                 if (isset($feed['itunes-explicit']) and 'Yes' === $feed['itunes-explicit']) {
                     $this->settings['podpress_feeds'][$i]['itunes-explicit'] = 'Yes';
                 } elseif (isset($feed['itunes-explicit']) and 'Clean' === $feed['itunes-explicit']) {
                     $this->settings['podpress_feeds'][$i]['itunes-explicit'] = 'Clean';
                 } else {
                     $this->settings['podpress_feeds'][$i]['itunes-explicit'] = 'No';
                 }
                 if (isset($feed['show_only_podPress_podcasts'])) {
                     $this->settings['podpress_feeds'][$i]['show_only_podPress_podcasts'] = TRUE;
                 } else {
                     $this->settings['podpress_feeds'][$i]['show_only_podPress_podcasts'] = FALSE;
                 }
                 if (isset($feed['bypass_incl_selection'])) {
                     $this->settings['podpress_feeds'][$i]['bypass_incl_selection'] = TRUE;
                 } else {
                     $this->settings['podpress_feeds'][$i]['bypass_incl_selection'] = FALSE;
                 }
                 if (isset($feed['feedtype']) and 'atom' === $feed['feedtype']) {
                     $this->settings['podpress_feeds'][$i]['feedtype'] = 'atom';
                 } else {
                     $this->settings['podpress_feeds'][$i]['feedtype'] = 'rss';
                 }
                 $feed['ttl'] = intval(preg_replace('/[^0-9]/', '', $feed['ttl']));
                 if (1440 > $feed['ttl']) {
                     $feed['ttl'] = 1440;
                 }
                 $this->settings['podpress_feeds'][$i]['ttl'] = $feed['ttl'];
                 $feed['posts_per_feed'] = intval(preg_replace('/[^0-9]/', '', $feed['posts_per_feed']));
                 if (1 >= $feed['posts_per_feed']) {
                     $feed['posts_per_feed'] = 1;
                 }
                 $this->settings['podpress_feeds'][$i]['posts_per_feed'] = $feed['posts_per_feed'];
                 $this->settings['podpress_feeds'][$i]['itunes-feedid'] = htmlspecialchars(strip_tags(trim($feed['itunes-feedid'])), ENT_QUOTES, $blog_charset);
                 if (isset($feed['itunes-block']) and 'Yes' === $feed['itunes-block']) {
                     $this->settings['podpress_feeds'][$i]['itunes-block'] = 'Yes';
                 } else {
                     $this->settings['podpress_feeds'][$i]['itunes-block'] = 'No';
                 }
                 if (isset($feed['use_headerlink'])) {
                     $this->settings['podpress_feeds'][$i]['use_headerlink'] = TRUE;
                 } else {
                     $this->settings['podpress_feeds'][$i]['use_headerlink'] = FALSE;
                 }
                 $i++;
             }
         }
         $report = $i . '_podpress_feeds_send';
         // $i is the number of the submitted podPress Feeds with a proper Feed name. If a Feed name is empty for instance then delete the settings of this Feed.
         for ($j = $i; $j < PODPRESS_FEEDS_MAX_NUMBER; $j++) {
             unset($this->settings['podpress_feeds'][$j]);
         }
     } else {
         $report = 'no_podpress_feeds_send';
     }
     //~ if ( function_exists('add_feed') ) {
     //~ if ( is_array($this->settings['podpress_feeds']) AND FALSE == empty($this->settings['podpress_feeds']) ) {
     //~ foreach ($this->settings['podpress_feeds'] as $feed) {
     //~ if ( TRUE === $feed['use'] AND FALSE == empty($feed['slug']) ) {
     //~ add_feed($feed['slug'], 'podPress_do_dyn_podcast_feed');
     //~ }
     //~ }
     //~ }
     //~ add_feed('playlist.xspf', 'podPress_do_feed_xspf');
     //~ printphpnotices_var_dump('podpress_admin_feed_class.php ---------------');
     //~ add_action('admin_init', function() {
     //~ printphpnotices_var_dump('podPress adding feeds and flush rules');
     //~ $wp_rewrite->flush_rules();}
     //~ );
     //~ }
     $result = podPress_update_option('podPress_config', $this->settings);
     if (FALSE !== $result) {
         $location = site_url() . '/wp-admin/admin.php?page=podpress/podpress_feed.php&updated=true' . '&debugreport=' . $report;
     } else {
         $location = site_url() . '/wp-admin/admin.php?page=podpress/podpress_feed.php&updated=false' . '&debugreport=' . $report;
     }
     header('Location: ' . $location);
     //~ exit;
 }
 function settings_stats_edit()
 {
     global $wpdb, $wp_version;
     podPress_isAuthorized();
     $baseurl = site_url() . '/wp-admin/admin.php?page=podpress/podpress_stats.php&display=';
     echo '<div class="wrap">' . "\n";
     if (TRUE == version_compare($wp_version, '2.7', '>=')) {
         echo '<div id="podpress-icon" class="icon32"><br /></div>';
     }
     if (TRUE == version_compare($wp_version, '2.8', '>=')) {
         echo '	<h2>' . __('Download Statistics', 'podpress') . '</h2>' . "\n";
         // get the plugins version information via the WP plugins version check
         if (TRUE == version_compare($wp_version, '2.9', '>=')) {
             $versioninfo = get_site_transient('update_plugins');
         } else {
             $versioninfo = get_transient('update_plugins');
         }
         // If there is a new version then there is a 'response'. This is the method from the plugins page.
         if (FALSE !== isset($versioninfo->response[plugin_basename(dirname(__FILE__) . '/podpress.php')]->new_version)) {
             echo '<div class="message updated"><p><a href="http://wordpress.org/extend/plugins/podpress/" target="_blank">' . __('a new podPress version is available', 'podpress') . '</a></p></div>';
         }
     } else {
         echo '	<h2>' . __('Download Statistics', 'podpress') . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.mightyseek.com/podpress/#download" target="_new"><img src="http://www.mightyseek.com/podpress_downloads/versioncheck.php?current=' . PODPRESS_VERSION . '" alt="' . __('Checking for updates... Failed.', 'podpress') . '" border="0" /></a></h2>' . "\n";
     }
     if ($this->settings['statLogging'] == 'Full' || $this->settings['statLogging'] == 'FullPlus') {
         // Show all statistics which are based on wp_stats [stat logging: Full and Full+]
         $navi = array('downloads_per_media_file' => __('Downloads Per Media File', 'podpress'), 'downloads_per_post' => __('Downloads Per Post', 'podpress'), 'topips' => __('Downloads Per IP Address', 'podpress'), 'graphbydate' => __('Graph by Date', 'podpress'), 'rawstats' => __('Raw Stats', 'podpress'));
         echo '	<ul id="podPress_navi">' . "\n";
         foreach ($navi as $key => $value) {
             $active = ($_GET['display'] == $key or !$_GET['display'] and $key == 'downloads_per_media_file') ? ' class="current"' : null;
             echo '        	<li class="podpress_stats_sub_menu_item"><a href="' . $baseurl . $key . '"' . $active . '>' . $value . '</a>';
             if ($this->checkGD()) {
                 if ($value == __('Graph by Date', 'podpress')) {
                     echo ' (<a href="' . $baseurl . 'graphbydatealt" title="' . sprintf(__('An alternative view of the %1$s', 'podpress'), __('Graph by Date', 'podpress')) . '">' . __('alt', 'podpress') . '</a>)';
                 }
             }
             echo '</li>' . "\n";
         }
         echo '	</ul>' . "\n";
         // bot management menu (since 8.8.5 beta 3)
         $navi2 = array('botdb_mark_bots' => __('Select / Deselect Bots', 'podpress'), 'botdb_list' => __('List of Bots', 'podpress'));
         echo '	<ul id="podPress_navi">' . "\n";
         foreach ($navi2 as $key => $value) {
             $active = ($_GET['display'] == $key or !$_GET['display'] and $key == 'quickcounts') ? ' class="current"' : null;
             echo '        	<li class="podpress_stats_sub_menu_item"><a href="' . $baseurl . $key . '"' . $active . '>' . $value . '</a></li>' . "\n";
         }
         echo '	</ul>' . "\n";
     } else {
         // Show all statistics which are based on wp_statcounts	[stat logging: Counts Only]
         // old: $_GET['display'] = 'downloads_per_media_file';
         $navi = array('quickcounts' => __('Quick Counts', 'podpress'), 'graphbypost' => __('Graph by Post', 'podpress'));
         echo '	<ul id="podPress_navi">' . "\n";
         foreach ($navi as $key => $value) {
             $active = ($_GET['display'] == $key or !$_GET['display'] and $key == 'quickcounts') ? ' class="current"' : null;
             echo '        	<li class="podpress_stats_sub_menu_item"><a href="' . $baseurl . $key . '"' . $active . '>' . $value . '</a>';
             if ($this->checkGD()) {
                 if ($value == __('Graph by Post', 'podpress')) {
                     echo ' (<a href="' . $baseurl . 'graphbypostalt" title="' . sprintf(__('An alternative view of the %1$s', 'podpress'), __('Graph by Post', 'podpress')) . '">' . __('alt', 'podpress') . '</a>)';
                 }
             }
             echo '</li>' . "\n";
         }
         echo '	</ul>' . "\n";
     }
     // Set Paging-Settings
     $start = isset($_GET['start']) ? $this->podSafeDigit($_GET['start']) : 0;
     //~ ####################
     //~ Limit is limiting the number of rows of the statistic tables
     $limit = 25;
     //~ ####################
     // ntm: since 8.8.5 beta 3 there are two different default statistic tables quickcounts and downloads_per_media_file that is why the default value has to be found before that Switch (and not with this Switch)
     if (FALSE == isset($_GET['display']) or FALSE !== empty($_GET['display'])) {
         if ($this->settings['statLogging'] == 'Full' || $this->settings['statLogging'] == 'FullPlus') {
             $show_this_page = 'downloads_per_media_file';
         } else {
             $show_this_page = 'quickcounts';
         }
     } else {
         $show_this_page = $_GET['display'];
     }
     switch ($show_this_page) {
         case 'botdb_list':
             // ntm: stat logging: Full and Full+
             podPress_isAuthorized();
             $botdb = get_option('podpress_botdb');
             if (isset($_POST['podPress_submitted']) and 'botdb' == $_POST['podPress_submitted']) {
                 if (function_exists('check_admin_referer')) {
                     check_admin_referer('podPress_botdb_nonce');
                 }
                 $IPs = $_POST['podpress_remote_ips'];
                 $fullbotnames = stripslashes_deep($_POST['podpress_user_agents']);
                 if (is_array($botdb)) {
                     $something_removed = FALSE;
                     if (is_array($IPs) and is_array($botdb['IP'])) {
                         $botdb['IP'] = array_diff($botdb['IP'], $IPs);
                         sort($botdb['IP']);
                     }
                     if (is_array($fullbotnames) and is_array($botdb['fullbotnames'])) {
                         $botdb['fullbotnames'] = array_diff($botdb['fullbotnames'], $fullbotnames);
                         sort($botdb['fullbotnames']);
                     }
                 }
                 if (isset($_POST['podpress_maxrowsperpage']) and FALSE == empty($_POST['podpress_maxrowsperpage']) and $limit <= intval($_POST['podpress_maxrowsperpage'])) {
                     $this->settings['maxrowsperpage_' . $show_this_page] = intval($_POST['podpress_maxrowsperpage']);
                 }
                 if (isset($this->settings['maxrowsperpage_' . $show_this_page]) and is_int($this->settings['maxrowsperpage_' . $show_this_page]) and $limit <= $this->settings['maxrowsperpage_' . $show_this_page]) {
                     $limit = $this->settings['maxrowsperpage_' . $show_this_page];
                 }
                 $result = podPress_update_option('podPress_config', $this->settings);
                 $updated = update_option('podpress_botdb', $botdb);
                 if (isset($updated) and TRUE === $updated) {
                     echo '<div id="message" class="updated fade"><p>' . __('Settings Saved', 'podpress') . '</p></div>';
                 }
             }
             echo '	<div class="wrap">' . "\n";
             echo '		<fieldset class="options">' . "\n";
             echo '			<legend>' . __('The list of IP addresses and names of bots', 'podpress') . '</legend>' . "\n";
             echo '			<form method="post">' . "\n";
             if (function_exists('wp_nonce_field')) {
                 // since WP 2.0.4
                 wp_nonce_field('podPress_botdb_nonce');
             }
             echo '			<table class="the-list-x widefat">' . "\n";
             echo '				<thead>' . "\n";
             echo '				<tr><th rowspan="2">' . __('Nr.', 'podpress') . '</th><th rowspan="2">' . __('Bot IP Address', 'podpress') . '</th><th rowspan="2">' . __('Bot User Agent', 'podpress') . '</th><th colspan="2">' . __('Remove this', 'podpress') . '</th></tr><tr><th>' . __('IP', 'podpress') . '</th><th>' . __('Name', 'podpress') . '</th></tr>' . "\n";
             echo '				</thead>' . "\n";
             echo '				<tbody>' . "\n";
             $nobots = FALSE;
             if (is_array($botdb) and (is_array($botdb['fullbotnames']) or is_array($botdb['IP']))) {
                 $botnames_len = count($botdb['fullbotnames']);
                 $IPs_len = count($botdb['IP']);
                 $rows_total = max($botnames_len, $IPs_len);
                 if ($rows_total > $start + $limit) {
                     $high = $start + $limit;
                 } else {
                     $high = $rows_total;
                 }
                 $low = $start + 1;
                 for ($i = $low; $i <= $high; $i++) {
                     $style = $i % 2 ? '' : ' class="alternate"';
                     echo '				<tr' . $style . '>' . "\n";
                     echo '                  			<td>' . ($start + $i) . '.</td>' . "\n";
                     if ($i <= $IPs_len - $start) {
                         $col_ip = '                  			<td>' . stripslashes($botdb['IP'][$i - 1]) . '</td>' . "\n";
                         $col_ip_chb = '                  			<td><input type="checkbox" id="podpress_remote_ip_' . $i . '" name="podpress_remote_ips[]" value="' . $botdb['IP'][$i - 1] . '" ' . $ip_chb_checked . ' /></td>' . "\n";
                     } else {
                         $col_ip = $col_ip_chb = '                  			<td></td>' . "\n";
                     }
                     if ($i <= $botnames_len - $start) {
                         $col_botname = '                  			<td>' . stripslashes($botdb['fullbotnames'][$i - 1]) . '</td>' . "\n";
                         $col_botname_chb = '                  			<td><input type="checkbox" id="podpress_user_agent_' . $i . '" name="podpress_user_agents[]" value="' . attribute_escape($botdb['fullbotnames'][$i - 1]) . '" ' . $name_chb_checked . ' /></td>' . "\n";
                     } else {
                         $col_botname = $col_botname_chb = '                  			<td></td>' . "\n";
                     }
                     echo $col_ip . $col_botname . $col_ip_chb . $col_botname_chb;
                     echo '              			</tr>' . "\n";
                 }
                 if (0 == $botnames_len and 0 == $IPs_len) {
                     $nobots = TRUE;
                 }
             } else {
                 $nobots = TRUE;
             }
             if (TRUE == $nobots) {
                 echo '				<td colspan="5">' . __('Currently are no IP addresses or user agents marked as bots.', 'podpress') . '</td>' . "\n";
             }
             echo '				</tbody>' . "\n";
             echo '				<tfoot>' . "\n";
             echo '				<tr>' . "\n";
             echo '				<th colspan="5">' . "\n";
             // Show paging
             echo $this->paging2($start, $limit, $rows_total, __('names and IPs', 'podpress'));
             echo '				</th>' . "\n";
             echo '              			</tr>' . "\n";
             echo '				</tfoot>' . "\n";
             echo '			</table>' . "\n";
             $this->podpress_print_maxrowsperpage($limit);
             echo '			<p class="submit"> ' . "\n";
             echo '				<input class="button-primary" type="submit" name="Submit" value="' . __('Remove marked elements / Update options', 'podpress') . ' &raquo;" /><br />' . "\n";
             echo '			</p> ' . "\n";
             echo '			<input type="hidden" name="podPress_submitted" value="botdb" />' . "\n";
             echo '			</form>' . "\n";
             echo '		</fieldset>' . "\n";
             echo '	</div>';
             break;
         case 'botdb_mark_bots':
             // ntm: stat logging: Full and Full+
             podPress_isAuthorized();
             $blog_charset = get_bloginfo('charset');
             $botdb = get_option('podpress_botdb');
             if (isset($_POST['podPress_submitted']) and 'botdb' == $_POST['podPress_submitted']) {
                 if (function_exists('check_admin_referer')) {
                     check_admin_referer('podPress_botdb_nonce');
                 }
                 $IPs = $_POST['podpress_remote_ips'];
                 $fullbotnames = stripslashes_deep($_POST['podpress_user_agents']);
                 if (is_array($botdb)) {
                     $current_IP_set = $_POST['podpress_current_IP_set'];
                     $unique_current_data_IPs = array_unique($_POST['podpress_current_IP_set']);
                     //add new bots
                     if (is_array($IPs)) {
                         $unique_IPs = array_unique($IPs);
                         foreach ($unique_IPs as $IP) {
                             if (is_array($botdb['IP'])) {
                                 if (FALSE === array_search($IP, $botdb['IP'])) {
                                     $botdb['IP'][] = $IP;
                                 }
                             } else {
                                 $botdb['IP'][] = $IP;
                             }
                         }
                         // eventually remove bots
                         $unmarked_IPs = array_diff($unique_current_data_IPs, $unique_IPs);
                         $botdb['IP'] = array_diff($botdb['IP'], $unmarked_IPs);
                         sort($botdb['IP']);
                     } else {
                         if (is_array($botdb['IP'])) {
                             $botdb['IP'] = array_diff($botdb['IP'], $unique_current_data_IPs);
                             sort($botdb['IP']);
                         }
                     }
                     $current_user_agent_set = $_POST['podpress_current_user_agent_set'];
                     $unique_current_data_fbnames = array_unique($_POST['podpress_current_user_agent_set']);
                     if (is_array($fullbotnames)) {
                         $unique_fullbotnames = array_unique($fullbotnames);
                         foreach ($unique_fullbotnames as $fullbotname) {
                             if (is_array($botdb['fullbotnames'])) {
                                 if (FALSE === array_search($fullbotname, $botdb['fullbotnames'])) {
                                     $botdb['fullbotnames'][] = $fullbotname;
                                 }
                             } else {
                                 $botdb['fullbotnames'][] = $fullbotname;
                             }
                         }
                         // eventually remove bots
                         $unmarked_fullbotnames = array_diff($unique_current_data_fbnames, $unique_fullbotnames);
                         $botdb['fullbotnames'] = array_diff($botdb['fullbotnames'], $unmarked_fullbotnames);
                         sort($botdb['fullbotnames']);
                     } else {
                         // eventually remove bots
                         if (is_array($botdb['fullbotnames'])) {
                             $botdb['fullbotnames'] = array_diff($botdb['fullbotnames'], $unique_current_data_fbnames);
                             sort($botdb['fullbotnames']);
                         }
                     }
                 } else {
                     //add new bots (first time)
                     if (is_array($IPs)) {
                         $unique_IPs = array_unique($IPs);
                         foreach ($unique_IPs as $IP) {
                             $botdb['IP'][] = $IP;
                         }
                     }
                     if (is_array($fullbotnames)) {
                         $unique_fullbotnames = array_unique($fullbotnames);
                         foreach ($unique_fullbotnames as $fullbotname) {
                             $botdb['fullbotnames'][] = $fullbotname;
                         }
                     }
                 }
                 if (isset($_POST['podpress_maxrowsperpage']) and FALSE == empty($_POST['podpress_maxrowsperpage']) and $limit <= intval($_POST['podpress_maxrowsperpage'])) {
                     $this->settings['maxrowsperpage_' . $show_this_page] = intval($_POST['podpress_maxrowsperpage']);
                 }
                 if (isset($this->settings['maxrowsperpage_' . $show_this_page]) and is_int($this->settings['maxrowsperpage_' . $show_this_page]) and $limit <= $this->settings['maxrowsperpage_' . $show_this_page]) {
                     $limit = $this->settings['maxrowsperpage_' . $show_this_page];
                 }
                 $result = podPress_update_option('podPress_config', $this->settings);
                 $updated = update_option('podpress_botdb', $botdb);
                 if (isset($updated) and TRUE === $updated) {
                     echo '<div id="message" class="updated fade"><p>' . __('Settings Saved', 'podpress') . '</p></div>';
                 }
             }
             $where = '';
             $rows_total = intval($wpdb->get_var('SELECT COUNT(DISTINCT remote_ip, user_agent) AS total FROM ' . $wpdb->prefix . 'podpress_stats ' . $where));
             $query_string = 'SELECT DISTINCT remote_ip, user_agent FROM ' . $wpdb->prefix . 'podpress_stats ' . $where . 'ORDER BY dt DESC LIMIT ' . $start . ', ' . $limit;
             $stats = $wpdb->get_results($query_string);
             echo '	<div class="wrap">' . "\n";
             echo '		<fieldset class="options">' . "\n";
             echo '			<legend>' . __('Which IP address or user agent name is from a web bot?', 'podpress') . '</legend>' . "\n";
             echo '			<p>' . __('Probably not every counted download is a download of a real human listener. Some hits are eventually from so called <a href="http://en.wikipedia.org/wiki/Internet_bot" target="_blank" title="en.Wikipedia: Internet Bot">Internet bots</a>. Every downloader has an <a href="http://en.wikipedia.org/wiki/IP_address" target="_blank" title="en.Wikipedia: IP Address">IP address</a> and a <a href="http://en.wikipedia.org/wiki/User_agent" target="_blank" title="en.Wikipedia: User Agent">user agent</a> name. The user agent name indicates often very good whether it is the name of a browser of a real listener or a name of a bot. Whether a IP address is one of a bot or not is more difficult. But there are some websites which can help to find out more about an IP address. (Some bots are using IP addresses only temporarily.)<br />The list below shows all unique combinations of IP addresses and user agent names. It is possible to select (resp. deselect) only the IP address or the user agent name or both. Downloads of the selected IP addresses or user agents do not appear in the statistics.', 'podpress') . '</p>' . "\n";
             echo '			<form method="post">' . "\n";
             if (function_exists('wp_nonce_field')) {
                 // since WP 2.0.4
                 wp_nonce_field('podPress_botdb_nonce');
             }
             echo "\n" . '			<table class="the-list-x widefat">' . "\n";
             echo '				<thead>' . "\n";
             echo '				<tr><th rowspan="2">' . __('Nr.', 'podpress') . '</th><th rowspan="2">' . __('IP Address', 'podpress') . '</th><th rowspan="2">' . __('User Agent', 'podpress') . '</th><th colspan="2">' . __('Is it a bot?', 'podpress') . '</th></tr><tr><th>' . __('IP', 'podpress') . '</th><th>' . __('Name', 'podpress') . '</th></tr>' . "\n";
             echo '				</thead>' . "\n";
             echo '				<tbody>' . "\n";
             if (0 < count($stats)) {
                 $i = 0;
                 foreach ($stats as $stat) {
                     ++$i;
                     $alternate = $i % 2 ? '' : 'alternate';
                     $bot_style = '';
                     $ip_chb_checked = '';
                     $name_chb_checked = '';
                     if (TRUE == is_array($botdb)) {
                         if (TRUE == is_array($botdb['IP']) and FALSE !== array_search($stat->remote_ip, $botdb['IP'])) {
                             $bot_style = ' podpress_is_bot';
                             $ip_chb_checked = ' checked="checked"';
                         }
                         if (TRUE == is_array($botdb['fullbotnames']) and FALSE !== array_search($stat->user_agent, $botdb['fullbotnames'])) {
                             $bot_style = ' podpress_is_bot';
                             $name_chb_checked = ' checked="checked"';
                         }
                     }
                     echo '				<tr id ="podpress_ip_user_agent_row_' . $i . '" class="' . $alternate . $bot_style . '">' . "\n";
                     echo '                  			<td>' . ($start + $i) . '</td>' . "\n";
                     echo '                  			<td>' . $stat->remote_ip . '<input type="hidden" name="podpress_current_IP_set[]" value="' . $stat->remote_ip . '" /></td>' . "\n";
                     echo '                  			<td>' . podPress_strlimiter2($stat->user_agent, 80, TRUE) . '<input type="hidden" name="podpress_current_user_agent_set[]" value="' . attribute_escape($stat->user_agent) . '" /></td>' . "\n";
                     echo '                  			<td><input type="checkbox" id="podpress_remote_ip_' . $i . '" name="podpress_remote_ips[]" value="' . $stat->remote_ip . '" onclick="podpress_mark_same_all_bots( \'remote_ips\' , ' . $i . ', ' . $start . ' );" ' . $ip_chb_checked . ' /></td>' . "\n";
                     echo '                  			<td><input type="checkbox" id="podpress_user_agent_' . $i . '" name="podpress_user_agents[]" value="' . attribute_escape($stat->user_agent) . '" onclick="podpress_mark_same_all_bots( \'user_agent\' , ' . $i . ', ' . $start . ' );" ' . $name_chb_checked . ' /></td>' . "\n";
                     echo '              			</tr>' . "\n";
                 }
             } else {
                 echo '<td colspan="5">' . __('No downloads yet.', 'podpress') . "</td>\n";
             }
             echo '				</tbody>' . "\n";
             echo '				<tfoot>' . "\n";
             echo '				<tr>' . "\n";
             echo '				<th colspan="5">' . "\n";
             // Show paging
             echo $this->paging2($start, $limit, $rows_total, __('names and IPs', 'podpress'));
             echo '				</th>' . "\n";
             echo '              			</tr>' . "\n";
             echo '				</tfoot>' . "\n";
             echo '			</table>' . "\n";
             $this->podpress_print_maxrowsperpage($limit);
             echo '				<p class="submit"> ' . "\n";
             echo '					<input class="button-primary" type="submit" name="Submit" value="' . __('Update Options', 'podpress') . ' &raquo;" /><br />' . "\n";
             echo '				</p> ' . "\n";
             echo '				<input type="hidden" name="podPress_submitted" value="botdb" />' . "\n";
             echo '			</form>' . "\n";
             echo '		</fieldset>' . "\n";
             echo '	</div>';
             break;
         case 'downloads_per_media_file':
             // ntm: stat logging: Full and Full+
             $where = $this->wherestr_to_exclude_bots('pod');
             $query_string = "SELECT COUNT(DISTINCT pod.media) as total_rows FROM " . $wpdb->prefix . "podpress_stats as pod " . $where;
             $rows_total = intval($wpdb->get_var($query_string));
             if (isset($_POST['podPress_submitted']) and $show_this_page == $_POST['podPress_submitted']) {
                 if (isset($_POST['podpress_maxrowsperpage']) and FALSE == empty($_POST['podpress_maxrowsperpage']) and $limit <= intval($_POST['podpress_maxrowsperpage'])) {
                     $this->settings['maxrowsperpage_' . $show_this_page] = intval($_POST['podpress_maxrowsperpage']);
                 }
                 $result = podPress_update_option('podPress_config', $this->settings);
             }
             if (isset($this->settings['maxrowsperpage_' . $show_this_page]) and is_int($this->settings['maxrowsperpage_' . $show_this_page]) and $limit <= $this->settings['maxrowsperpage_' . $show_this_page]) {
                 $limit = $this->settings['maxrowsperpage_' . $show_this_page];
             }
             $query_string = "SELECT DISTINCT (pod.media) FROM " . $wpdb->prefix . "podpress_stats as pod " . $where . " LIMIT " . $start . ", " . $limit;
             $posts_with_podpressmedia = $wpdb->get_results($query_string);
             $nr_postswpm = count($posts_with_podpressmedia);
             if (0 < $nr_postswpm) {
                 $i = 1;
                 if (FALSE == empty($where)) {
                     $where_posts = "AND pod.media IN (";
                 } else {
                     $where_posts = "WHERE pod.media IN (";
                 }
                 foreach ($posts_with_podpressmedia as $post) {
                     if ($i == $nr_postswpm) {
                         $where_posts .= "'" . $wpdb->escape($post->media) . "'";
                     } else {
                         $where_posts .= "'" . $wpdb->escape($post->media) . "', ";
                     }
                     $i++;
                 }
                 $where_posts .= ") ";
             } else {
                 $where_posts = '';
             }
             $query_string = "SELECT pod.media, pod.method, COUNT(*) as downloads FROM " . $wpdb->prefix . "podpress_stats as pod " . $where . $where_posts . "GROUP BY pod.method, pod.media ORDER BY pod.media DESC";
             $stat_data_sets = $wpdb->get_results($query_string);
             if (FALSE == empty($where)) {
                 $where_or_and = "AND";
             } else {
                 $where_or_and = "WHERE";
             }
             $methods = array('feed', 'web', 'play');
             foreach ($methods as $method) {
                 $query_string = "SELECT COUNT(*) as downloads, pod.media FROM " . $wpdb->prefix . "podpress_stats AS pod " . $where . $where_or_and . " pod.method='" . $method . "' GROUP BY pod.media ORDER BY downloads DESC";
                 $downloads_col = $wpdb->get_col($query_string);
                 switch ($method) {
                     case 'feed':
                         $feed_max = intval($downloads_col[0]);
                         break;
                     case 'web':
                         $web_max = intval($downloads_col[0]);
                         break;
                     case 'play':
                         $play_max = intval($downloads_col[0]);
                         break;
                 }
             }
             $query_string = "SELECT COUNT(*) as downloads, pod.media FROM " . $wpdb->prefix . "podpress_stats AS pod " . $where . " GROUP BY pod.media ORDER BY downloads DESC";
             $downloads_col = $wpdb->get_col($query_string);
             $total_max = intval($downloads_col[0]);
             // prepare the query result for the output:
             // - if a media file was not downloaded  by one or more method then add this method  and a int(0) to the media file
             foreach ($stat_data_sets as $stat_data_set) {
                 $feed = $web = $play = 0;
                 switch ($stat_data_set->method) {
                     case 'feed':
                         $feed = intval($stat_data_set->downloads);
                         break;
                     case 'web':
                         $web = intval($stat_data_set->downloads);
                         break;
                     case 'play':
                         $play = intval($stat_data_set->downloads);
                         break;
                 }
                 $total_sum = $feed + $web + $play;
                 $stats[$stat_data_set->media]['feed'] += $feed;
                 $stats[$stat_data_set->media]['web'] += $web;
                 $stats[$stat_data_set->media]['play'] += $play;
                 $stats[$stat_data_set->media]['total'] += $total_sum;
             }
             // sort the media files by their 'total' value
             if (is_array($stats) and FALSE == empty($stats) and method_exists($this, 'sort_downloads_per_media_desc')) {
                 uasort($stats, array($this, 'sort_downloads_per_media_desc'));
             }
             echo '	<div class="wrap">' . "\n";
             echo '		<fieldset class="options">' . "\n";
             echo '			<legend>' . __('Downloads Per Media File', 'podpress') . '</legend>' . "\n";
             echo '			<table class="the-list-x widefat">' . "\n";
             echo '				<thead>';
             echo "\t\t\t\t<tr>\n";
             echo '                  			<th rowspan="2">' . __('Nr.', 'podpress') . "</th>\n";
             echo '                  			<th rowspan="2">' . __('Media File', 'podpress') . "</th>\n";
             echo '                  			<th class="podpress_stats_nr_head" colspan="2">' . __('Feed', 'podpress') . "</th>\n";
             echo '                  			<th class="podpress_stats_nr_head" colspan="2">' . __('Web', 'podpress') . "</th>\n";
             echo '                  			<th class="podpress_stats_nr_head" colspan="2">' . __('Play', 'podpress') . "</th>\n";
             echo '                  			<th class="podpress_stats_nr_head" rowspan="2">' . __('Total', 'podpress') . "</th>\n";
             echo '              			</tr>' . "\n";
             echo '				<tr>' . "\n";
             echo '                  			<th class="podpress_stats_nr_head">' . __('Files', 'podpress') . "</th>\n";
             echo '                  			<th class="podpress_stats_nr_head">' . __('%', 'podpress') . "</th>\n";
             echo '                  			<th class="podpress_stats_nr_head">' . __('Files', 'podpress') . "</th>\n";
             echo '                  			<th class="podpress_stats_nr_head">' . __('%', 'podpress') . "</th>\n";
             echo '                  			<th class="podpress_stats_nr_head">' . __('Files', 'podpress') . "</th>\n";
             echo '                  			<th class="podpress_stats_nr_head">' . __('%', 'podpress') . "</th>\n";
             echo '              			</tr>' . "\n";
             echo '				</thead>';
             echo '				<tbody>';
             if (0 < count($stat_data_sets)) {
                 $i = 0;
                 foreach ($stats as $media => $downloads_per_method) {
                     $i++;
                     $style = $i % 2 != 0 ? '' : ' class="alternate"';
                     $highest_feed = ($downloads_per_method['feed'] == $feed_max and 0 < $feed_max) ? ' podpress_stats_highest' : '';
                     $highest_web = ($downloads_per_method['web'] == $web_max and 0 < $web_max) ? ' podpress_stats_highest' : '';
                     $highest_play = ($downloads_per_method['play'] == $play_max and 0 < $play_max) ? ' podpress_stats_highest' : '';
                     $highest_total = ($downloads_per_method['total'] == $total_max and 0 < $total_max) ? ' podpress_stats_highest' : '';
                     $perc_feed = number_format($downloads_per_method['feed'] * 100 / $downloads_per_method['total'], 1, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]);
                     $perc_web = number_format($downloads_per_method['web'] * 100 / $downloads_per_method['total'], 1, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]);
                     $perc_play = number_format($downloads_per_method['play'] * 100 / $downloads_per_method['total'], 1, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]);
                     echo '		<tr' . $style . '>' . "\n";
                     echo '                  	<td>' . ($start + $i) . '.</td>' . "\n";
                     echo '                  	<td>' . podPress_strlimiter2(urldecode($media), 50, TRUE) . '</td>' . "\n";
                     echo '                  	<td class="podpress_stats_numbers_abs' . $highest_feed . '">' . number_format($downloads_per_method['feed'], 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]) . "</td>\n";
                     echo '                  	<td class="podpress_stats_numbers_percent' . $highest_feed . '">' . $perc_feed . "</td>\n";
                     echo '                  	<td class="podpress_stats_numbers_abs' . $highest_web . '" >' . number_format($downloads_per_method['web'], 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]) . "</td>\n";
                     echo '                  	<td class="podpress_stats_numbers_percent' . $highest_web . '">' . $perc_web . "</td>\n";
                     echo '                  	<td class="podpress_stats_numbers_abs' . $highest_play . '">' . number_format($downloads_per_method['play'], 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]) . "</td>\n";
                     echo '                  	<td class="podpress_stats_numbers_percent' . $highest_play . '">' . $perc_play . "</td>\n";
                     echo '                  	<td class="podpress_stats_numbers_total' . $highest_total . '">' . number_format($downloads_per_method['total'], 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]) . "</td>\n";
                     echo '		</tr>' . "\n";
                 }
             } else {
                 if (FALSE == empty($where)) {
                     echo '<td colspan="9">' . __('No downloads yet. (Bots have been filtered.)', 'podpress') . "</td>\n";
                 } else {
                     echo '<td colspan="9">' . __('No downloads yet.', 'podpress') . "</td>\n";
                 }
             }
             echo '				</tbody>';
             echo '				<tfoot>' . "\n";
             echo '				<tr>' . "\n";
             echo '				<th colspan="9">' . "\n";
             // Show paging
             echo $this->paging2($start, $limit, $rows_total, __('Ranks', 'podpress'));
             echo '				</th>' . "\n";
             echo '              			</tr>' . "\n";
             echo '				</tfoot>' . "\n";
             echo '			</table>' . "\n";
             echo '			<form method="post">' . "\n";
             $this->podpress_print_maxrowsperpage($limit, TRUE);
             echo '			<input type="hidden" name="podPress_submitted" value="' . $show_this_page . '" />' . "\n";
             echo '			</form>' . "\n";
             echo '		</fieldset>' . "\n";
             echo '	</div>';
             break;
         case 'rawstats':
             // ntm: stat logging: Full and Full+
             $date_format = get_option('date_format');
             $time_format = get_option('time_format');
             $botdb = get_option('podpress_botdb');
             $where = '';
             if (isset($_POST['podPress_submitted']) and $show_this_page == $_POST['podPress_submitted']) {
                 if (isset($_POST['podpress_maxrowsperpage']) and FALSE == empty($_POST['podpress_maxrowsperpage']) and $limit <= intval($_POST['podpress_maxrowsperpage'])) {
                     $this->settings['maxrowsperpage_' . $show_this_page] = intval($_POST['podpress_maxrowsperpage']);
                 }
                 $result = podPress_update_option('podPress_config', $this->settings);
             }
             if (isset($this->settings['maxrowsperpage_' . $show_this_page]) and is_int($this->settings['maxrowsperpage_' . $show_this_page]) and $limit <= $this->settings['maxrowsperpage_' . $show_this_page]) {
                 $limit = $this->settings['maxrowsperpage_' . $show_this_page];
             }
             $rows_total = $wpdb->get_var('SELECT COUNT(*) FROM ' . $wpdb->prefix . 'podpress_stats ' . $where);
             $stats = $wpdb->get_results('SELECT * FROM ' . $wpdb->prefix . 'podpress_stats ' . $where . 'ORDER BY id DESC LIMIT ' . $start . ', ' . $limit);
             echo '	<div class="wrap">' . "\n";
             echo '		<fieldset class="options">' . "\n";
             echo '			<legend>' . __('The raw list', 'podpress') . '</legend>' . "\n";
             echo '			<table class="the-list-x widefat">' . "\n";
             //width="100%" cellpadding="1" cellspacing="1"
             echo '				<thead>';
             echo '				<tr><th>' . __('Hit', 'podpress') . '</th><th>' . __('Media File', 'podpress') . '</th><th>' . __('Method', 'podpress') . '</th><th>' . __('IP', 'podpress') . '</th><th>' . __('User Agent', 'podpress') . '</th><th>' . __('Timestamp', 'podpress') . '</th></tr>' . "\n";
             echo '				</thead>';
             echo '				<tbody>';
             if (0 < count($stats)) {
                 if (TRUE === is_array($botdb['IP']) or TRUE === is_array($botdb['fullbotnames'])) {
                     $i = 0;
                     foreach ($stats as $stat) {
                         ++$i;
                         $style = $i % 2 ? '' : 'alternate';
                         if (FALSE !== empty($botdb['fullbotnames']) or FALSE === array_search($stat->user_agent, $botdb['fullbotnames'])) {
                             if (FALSE !== empty($botdb['IP']) or FALSE === array_search($stat->remote_ip, $botdb['IP'])) {
                                 $bot_style = '';
                             } else {
                                 $bot_style = ' podpress_is_bot';
                             }
                         } else {
                             $bot_style = ' podpress_is_bot';
                         }
                         echo '		<tr class="' . $style . $bot_style . '">' . "\n";
                         echo '                  	<td>' . ($start + $i) . '.</td>' . "\n";
                         echo '                  	<td>' . podPress_strlimiter2(urldecode($stat->media), 20, TRUE) . '</td>' . "\n";
                         echo '                  	<td>' . $stat->method . '</td>' . "\n";
                         // iscifi : mod of stats output to create a link to domaintools.com whois lookup
                         // domaintools seems faster and provides more concise infomation, url can not have trailing /
                         echo '                  	<td><a href="http://whois.domaintools.com/' . $stat->remote_ip . '" target="_blank" title="' . __('Look for more details about this IP at whois.domaintools.com', 'podpress') . '">' . $stat->remote_ip . '</a></td>' . "\n";
                         // OLD code where this .echo '                  <td>'.$stat->remote_ip.'</td>'."\n";
                         echo '                  	<td>' . podPress_strlimiter2($stat->user_agent, 50, TRUE) . '</td>' . "\n";
                         echo '                  	<td>' . date($date_format . ' - ' . $time_format, intval($stat->dt)) . '</td>' . "\n";
                         echo '		</tr>' . "\n";
                     }
                 } else {
                     $i = 0;
                     foreach ($stats as $stat) {
                         ++$i;
                         $style = $i % 2 ? '' : 'alternate';
                         echo '				<tr class="' . $style . '">' . "\n";
                         echo '                  <td>' . ($start + $i) . '.</td>' . "\n";
                         echo '                  <td>' . podPress_strlimiter2(urldecode($stat->media), 20, TRUE) . '</td>' . "\n";
                         echo '                  <td>' . $stat->method . '</td>' . "\n";
                         // iscifi : mod of stats output to create a link to domaintools.com whois lookup
                         // domaintools seems faster and provides more concise infomation, url can not have trailing /
                         echo '                  <td><a href="http://whois.domaintools.com/' . $stat->remote_ip . '" target="_blank">' . $stat->remote_ip . '</a></td>' . "\n";
                         // OLD code where this .echo '                  <td>'.$stat->remote_ip.'</td>'."\n";
                         echo '                  <td>' . podPress_strlimiter2($stat->user_agent, 50, TRUE) . '</td>' . "\n";
                         echo '                  <td>' . date($date_format . ' - ' . $time_format, intval($stat->dt)) . '</td>' . "\n";
                         echo '              </tr>' . "\n";
                     }
                 }
             } else {
                 echo '<td colspan="6">' . __('No downloads yet.', 'podpress') . '</td>' . "\n";
             }
             echo '				</tbody>';
             echo '				<tfoot>' . "\n";
             echo '				<tr>' . "\n";
             echo '				<th colspan="6">' . "\n";
             // Show paging
             echo $this->paging2($start, $limit, $rows_total, __('Hit', 'podpress'));
             echo '				</th>' . "\n";
             echo '              			</tr>' . "\n";
             echo '				</tfoot>' . "\n";
             echo '			</table>' . "\n";
             echo '			<form method="post">' . "\n";
             $this->podpress_print_maxrowsperpage($limit, TRUE);
             echo '			<input type="hidden" name="podPress_submitted" value="' . $show_this_page . '" />' . "\n";
             echo '			</form>' . "\n";
             echo '		</fieldset>' . "\n";
             echo '	</div>';
             break;
         case 'topips':
             // ntm: stat logging: Full and Full+
             $where = $this->wherestr_to_exclude_bots();
             $rows_total = $wpdb->get_var('SELECT COUNT(DISTINCT remote_ip) as uniq FROM ' . $wpdb->prefix . 'podpress_stats ' . $where);
             if (isset($_POST['podPress_submitted']) and $show_this_page == $_POST['podPress_submitted']) {
                 if (isset($_POST['podpress_maxrowsperpage']) and FALSE == empty($_POST['podpress_maxrowsperpage']) and $limit <= intval($_POST['podpress_maxrowsperpage'])) {
                     $this->settings['maxrowsperpage_' . $show_this_page] = intval($_POST['podpress_maxrowsperpage']);
                 }
                 $result = podPress_update_option('podPress_config', $this->settings);
             }
             if (isset($this->settings['maxrowsperpage_' . $show_this_page]) and is_int($this->settings['maxrowsperpage_' . $show_this_page]) and $limit <= $this->settings['maxrowsperpage_' . $show_this_page]) {
                 $limit = $this->settings['maxrowsperpage_' . $show_this_page];
             }
             $sql = 'SELECT remote_ip AS IPAddress, COUNT(DISTINCT remote_ip, media) as uniq, COUNT( * ) AS total FROM ' . $wpdb->prefix . 'podpress_stats ' . $where . 'GROUP BY remote_ip ORDER BY total DESC LIMIT ' . $start . ', ' . $limit;
             $stats = $wpdb->get_results($sql);
             echo '	<div class="wrap">' . "\n";
             echo '		<fieldset class="options">' . "\n";
             echo '			<legend>' . __('Top IP Addresses', 'podpress') . '</legend>' . "\n";
             echo '			<table class="the-list-x widefat">' . "\n";
             echo '				<thead>';
             echo '				<tr><th>' . __('Nr.', 'podpress') . '</th><th>' . __('IP Address', 'podpress') . '</th><th><abbr class="podpress_abbr" title="' . __('Only one download per file from this IP address has been counted. In other words: It is the number of different files which were downloaded from this IP address.', 'podpress') . '">' . __('Unique Files', 'podpress') . '</abbr></th><th>' . __('Total', 'podpress') . '</th></tr>' . "\n";
             echo '				</thead>';
             echo '				<tbody>';
             if (0 < count($stats)) {
                 $i = 0;
                 foreach ($stats as $stat) {
                     ++$i;
                     $style = $i % 2 ? '' : ' class="alternate"';
                     echo '		<tr' . $style . '>' . "\n";
                     echo '                  	<td>' . ($start + $i) . '.</td>' . "\n";
                     echo '                  	<td>' . $stat->IPAddress . '</td>' . "\n";
                     echo '                  	<td>' . $stat->uniq . '</td>' . "\n";
                     echo '                  	<td>' . $stat->total . '</td>' . "\n";
                     echo '             	</tr>' . "\n";
                 }
             } else {
                 if (FALSE == empty($where)) {
                     echo '<td colspan="4">' . __('No downloads yet. (Bots have been filtered.)', 'podpress') . "</td>\n";
                 } else {
                     echo '<td colspan="4">' . __('No downloads yet.', 'podpress') . "</td>\n";
                 }
             }
             echo '				</tbody>';
             echo '				<tfoot>' . "\n";
             echo '				<tr>' . "\n";
             echo '				<th colspan="4">' . "\n";
             // Show paging
             echo $this->paging2($start, $limit, $rows_total, __('IP Address', 'podpress'));
             echo '				</th>' . "\n";
             echo '              			</tr>' . "\n";
             echo '				</tfoot>' . "\n";
             echo '			</table>' . "\n";
             echo '			<form method="post">' . "\n";
             $this->podpress_print_maxrowsperpage($limit, TRUE);
             echo '			<input type="hidden" name="podPress_submitted" value="' . $show_this_page . '" />' . "\n";
             echo '			</form>' . "\n";
             echo '		</fieldset>' . "\n";
             echo '	</div>';
             break;
         case 'graphbydate':
             // ntm: stat logging: Full and Full+
             if ($this->checkGD()) {
                 //&& ($this->settings['statLogging'] == 'Full' || $this->settings['statLogging'] == 'FullPlus')
                 $this->graphByDate();
             } else {
                 $this->graphByDateAlt('With <a href="http://us2.php.net/manual/en/ref.image.php">gdlib-support</a> you\'ll have access to more detailed graphicals stats. Please ask your provider.');
             }
             break;
         case 'graphbydatealt':
             // ntm: stat logging: Full and Full+
             $this->graphByDateAlt();
             break;
         case 'graphbypost':
             // ntm: stat logging: Counts Only
             echo '<p>' . __('<strong>Notice:</strong> This graph is only faultless if your podcast posts contain only one media file per post, each file has a unique name and if you change the media file name on a re-post (deleting a post and publishing the content in a new post)!', 'podpress') . '</p>';
             if ($this->checkGD()) {
                 $this->graphByPost();
             } else {
                 $this->graphByPostAlt('With <a href="http://us2.php.net/manual/en/ref.image.php">gdlib-support</a> you\'ll have access to more detailed graphicals stats. Please ask your provider.');
             }
             break;
         case 'graphbypostalt':
             // ntm: stat logging: Counts Only
             echo '<p>' . __('<strong>Notice:</strong> This graph is only faultless if your podcast posts contain only one media file per post, each file has a unique name and if you change the media file name on a re-post (deleting a post and publishing the content in a new post)!', 'podpress') . '</p>';
             $this->graphByPostAlt();
             break;
         case 'downloads_per_post':
             // ntm: stat logging: Full and Full+
             $where = $this->wherestr_to_exclude_bots('pod');
             // get the number of all post with podPress podcasts
             //~ $query_string = "SELECT COUNT(DISTINCT postID) as posts FROM ".$wpdb->prefix."podpress_stats ".$where;
             // take only posts which are still in the wp_posts table. It is possible that the stats table contains stats of file which were only in posts which are deleted.
             if (TRUE == empty($where)) {
                 $where_ID .= " WHERE p.ID = pod.postID";
             } else {
                 $where_ID .= " AND p.ID = pod.postID";
             }
             // get all post with podPress podcasts
             $query_string = "SELECT DISTINCT(pod.postID), p.post_title FROM " . $wpdb->prefix . "podpress_stats AS pod LEFT JOIN " . $wpdb->prefix . "posts AS p ON pod.postID = p.ID " . $where . $where_ID . " ORDER BY pod.postID DESC";
             $posts_with_podpressmedia = $wpdb->get_results($query_string);
             echo '	<div class="wrap">' . "\n";
             echo '		<fieldset class="options">' . "\n";
             echo '			<legend>' . __('Downloads Per Post', 'podpress') . '</legend>' . "\n";
             echo '			<form method="post">' . "\n";
             if (function_exists('wp_nonce_field')) {
                 // since WP 2.0.4
                 wp_nonce_field('podPress_downloads_per_post_nonce');
             }
             echo '				<label>' . __('Select a post with a media file (attached with podPress):', 'podpress') . '</label><br />' . "\n";
             echo '				<select id="post_with_podpressmedia" name="post_with_podpressmedia" size="5">' . "\n";
             foreach ($posts_with_podpressmedia as $post) {
                 if ($post->postID == $_POST['post_with_podpressmedia']) {
                     $selected = ' selected="selected"';
                 } else {
                     $selected = '';
                 }
                 echo '				<option value="' . $post->postID . '"' . $selected . '>' . $post->post_title . '</option>' . "\n";
                 $post_titles[$post->postID] = $post->post_title;
             }
             echo '				</select>' . "\n";
             echo '				<p class="submit"> ' . "\n";
             echo '					<input type="submit" name="Submit" value="' . __('Show the stats for this post', 'podpress') . ' &raquo;" /><br />' . "\n";
             echo '				</p> ' . "\n";
             echo '				<input type="hidden" name="podPress_submitted" value="downloadsperpost" />' . "\n";
             echo '			</form>' . "\n";
             echo '		</fieldset>' . "\n";
             echo '	</div><!-- .wrap -->' . "\n";
             // show the statistics of the media files of the submitted post
             if ('downloadsperpost' == $_POST['podPress_submitted']) {
                 if (function_exists('check_admin_referer')) {
                     check_admin_referer('podPress_downloads_per_post_nonce');
                 }
                 if (FALSE == empty($where)) {
                     $where_postID = "AND pod.postID = '" . $_POST['post_with_podpressmedia'] . "' ";
                 } else {
                     $where_postID = "WHERE pod.postID = '" . $_POST['post_with_podpressmedia'] . "' ";
                 }
                 $query_string = "SELECT pod.media, pod.method, COUNT(*) as downloads FROM " . $wpdb->prefix . "podpress_stats as pod " . $where . $where_postID . "GROUP BY pod.method, pod.media ORDER BY media DESC";
                 $stat_data_sets = $wpdb->get_results($query_string);
                 // prepare the query result for the output:
                 // - find the maximal downloads value for each download method
                 // - if a media file was not downloaded  by one or more method then add this method  and a int(0) to the media file
                 $feed_max = 0;
                 $web_max = 0;
                 $play_max = 0;
                 $total_max = 0;
                 foreach ($stat_data_sets as $stat_data_set) {
                     $feed = 0;
                     $web = 0;
                     $play = 0;
                     switch ($stat_data_set->method) {
                         case 'feed':
                             $feed = intval($stat_data_set->downloads);
                             $feed_max = max($feed_max, $feed);
                             break;
                         case 'web':
                             $web = intval($stat_data_set->downloads);
                             $web_max = max($web_max, $web);
                             break;
                         case 'play':
                             $play = intval($stat_data_set->downloads);
                             $play_max = max($play_max, $play);
                             break;
                     }
                     $stats[$stat_data_set->media]['feed'] += $feed;
                     $stats[$stat_data_set->media]['web'] += $web;
                     $stats[$stat_data_set->media]['play'] += $play;
                     $stats[$stat_data_set->media]['total'] += $feed + $web + $play;
                     $total_max = max($total_max, $stats[$stat_data_set->media]['total']);
                 }
                 // sort the media files by their 'total' value
                 if (is_array($stats) and FALSE == empty($stats) and method_exists($this, 'sort_downloads_per_media_desc')) {
                     uasort($stats, array($this, 'sort_downloads_per_media_desc'));
                 }
                 echo '	<div class="wrap">' . "\n";
                 echo '		<fieldset class="options">' . "\n";
                 echo '			<legend>' . __('Post:', 'podpress') . " " . $post_titles[$_POST['post_with_podpressmedia']] . " - " . __('Downloads Per Media File', 'podpress') . '</legend>' . "\n";
                 echo '			<table class="the-list-x widefat">' . "\n";
                 echo '				<thead>';
                 echo "\t\t\t\t<tr>\n";
                 echo '                  			<th rowspan="2">' . __('Nr.', 'podpress') . "</th>\n";
                 echo '                  			<th rowspan="2">' . __('Media File', 'podpress') . "</th>\n";
                 echo '                  			<th class="podpress_stats_nr_head" colspan="2">' . __('Feed', 'podpress') . "</th>\n";
                 echo '                  			<th class="podpress_stats_nr_head" colspan="2">' . __('Web', 'podpress') . "</th>\n";
                 echo '                  			<th class="podpress_stats_nr_head" colspan="2">' . __('Play', 'podpress') . "</th>\n";
                 echo '                  			<th class="podpress_stats_nr_head" rowspan="2">' . __('Total', 'podpress') . "</th>\n";
                 echo '              			</tr>' . "\n";
                 echo '				<tr>' . "\n";
                 echo '                  			<th class="podpress_stats_nr_head">' . __('Files', 'podpress') . "</th>\n";
                 echo '                  			<th class="podpress_stats_nr_head">' . __('%', 'podpress') . "</th>\n";
                 echo '                  			<th class="podpress_stats_nr_head">' . __('Files', 'podpress') . "</th>\n";
                 echo '                  			<th class="podpress_stats_nr_head">' . __('%', 'podpress') . "</th>\n";
                 echo '                  			<th class="podpress_stats_nr_head">' . __('Files', 'podpress') . "</th>\n";
                 echo '                  			<th class="podpress_stats_nr_head">' . __('%', 'podpress') . "</th>\n";
                 echo '              			</tr>' . "\n";
                 echo '				</thead>';
                 echo '				<tbody>';
                 $mark_highest = FALSE;
                 $nr_stat_data_sets = count($stat_data_sets);
                 if (0 < $nr_stat_data_sets) {
                     if (1 < $nr_stat_data_sets) {
                         $mark_highest = TRUE;
                     }
                     $i = 0;
                     foreach ($stats as $media => $downloads_per_method) {
                         $i++;
                         $style = $i % 2 != 0 ? '' : ' class="alternate"';
                         if (TRUE === $mark_highest) {
                             $highest_feed = ($downloads_per_method['feed'] == $feed_max and 0 < $feed_max) ? ' podpress_stats_highest' : '';
                             $highest_web = ($downloads_per_method['web'] == $web_max and 0 < $web_max) ? ' podpress_stats_highest' : '';
                             $highest_play = ($downloads_per_method['play'] == $play_max and 0 < $play_max) ? ' podpress_stats_highest' : '';
                             $highest_total = ($downloads_per_method['total'] == $total_max and 0 < $total_max) ? ' podpress_stats_highest' : '';
                         }
                         $perc_feed = number_format($downloads_per_method['feed'] * 100 / $downloads_per_method['total'], 1, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]);
                         $perc_web = number_format($downloads_per_method['web'] * 100 / $downloads_per_method['total'], 1, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]);
                         $perc_play = number_format($downloads_per_method['play'] * 100 / $downloads_per_method['total'], 1, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]);
                         echo '		<tr' . $style . '>' . "\n";
                         echo '                  	<td>' . ($start + $i) . '.</td>' . "\n";
                         echo '                  	<td>' . podPress_strlimiter2(urldecode($media), 50, TRUE) . '</td>' . "\n";
                         echo '                  	<td class="podpress_stats_numbers_abs' . $highest_feed . '">' . number_format($downloads_per_method['feed'], 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]) . "</td>\n";
                         echo '                  	<td class="podpress_stats_numbers_percent' . $highest_feed . '">' . $perc_feed . "</td>\n";
                         echo '                  	<td class="podpress_stats_numbers_abs' . $highest_web . '" >' . number_format($downloads_per_method['web'], 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]) . "</td>\n";
                         echo '                  	<td class="podpress_stats_numbers_percent' . $highest_web . '">' . $perc_web . "</td>\n";
                         echo '                  	<td class="podpress_stats_numbers_abs' . $highest_play . '">' . number_format($downloads_per_method['play'], 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]) . "</td>\n";
                         echo '                  	<td class="podpress_stats_numbers_percent' . $highest_play . '">' . $perc_play . "</td>\n";
                         echo '                  	<td class="podpress_stats_numbers_total' . $highest_total . '">' . number_format($downloads_per_method['total'], 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]) . "</td>\n";
                         echo '		</tr>' . "\n";
                     }
                 } else {
                     if (FALSE == empty($where)) {
                         echo '<td colspan="9">' . __('No downloads yet. (Bots have been filtered.)', 'podpress') . "</td>\n";
                     } else {
                         echo '<td colspan="9">' . __('No downloads yet.', 'podpress') . "</td>\n";
                     }
                 }
                 echo '				</tbody>';
                 echo '				<tfoot>' . "\n";
                 echo '				<tr>' . "\n";
                 echo '				<th colspan="9">' . "\n";
                 echo '				</th>' . "\n";
                 echo '              			</tr>' . "\n";
                 echo '				</tfoot>' . "\n";
                 echo '			</table>' . "\n";
                 echo '		</fieldset>' . "\n";
                 echo '	</div><!-- .wrap -->' . "\n";
             }
             break;
         case 'quickcounts':
             // ntm: stat logging: Counts Only
             // ntm: 'quickcounts' takes the data from the wp_podpress_statcounts table.
             $total = $wpdb->get_var('SELECT COUNT(postID) FROM ' . $wpdb->prefix . 'podpress_statcounts WHERE postID != 0;');
             if ($total > 0) {
                 if (isset($_POST['podPress_submitted']) and $show_this_page == $_POST['podPress_submitted']) {
                     if (isset($_POST['podpress_maxrowsperpage']) and FALSE == empty($_POST['podpress_maxrowsperpage']) and $limit <= intval($_POST['podpress_maxrowsperpage'])) {
                         $this->settings['maxrowsperpage_' . $show_this_page] = intval($_POST['podpress_maxrowsperpage']);
                     }
                     $result = podPress_update_option('podPress_config', $this->settings);
                 }
                 if (isset($this->settings['maxrowsperpage_' . $show_this_page]) and is_int($this->settings['maxrowsperpage_' . $show_this_page]) and $limit <= $this->settings['maxrowsperpage_' . $show_this_page]) {
                     $limit = $this->settings['maxrowsperpage_' . $show_this_page];
                 }
                 // Load highest values
                 $sql = "SELECT 'blah' AS topic, MAX(total) AS total, MAX(feed) AS feed, MAX(web) AS web, MAX(play) AS play FROM " . $wpdb->prefix . 'podpress_statcounts GROUP BY topic';
                 $highest = $wpdb->get_results($sql);
                 $highest = $highest[0];
                 //~ $sql = 'SELECT sc.postID, sc.media, sc.total, sc.feed, sc.web, sc.play, p.post_title, p.post_date, UNIX_TIMESTAMP(p.post_date) AS pdate '
                 //~ 	. 'FROM '.$wpdb->prefix.'podpress_statcounts AS sc, '.$wpdb->prefix.'posts AS p '
                 //~ 	. 'WHERE (sc.postID = p.ID) ORDER BY p.post_date DESC LIMIT '.$start.', '.$limit.'';
                 $sql = 'SELECT sc.media, sc.total, sc.feed, sc.web, sc.play ' . 'FROM ' . $wpdb->prefix . 'podpress_statcounts AS sc ' . 'ORDER BY sc.media DESC LIMIT ' . $start . ', ' . $limit . '';
                 $stats = $wpdb->get_results($sql);
                 $cnt_stats = count($stats);
                 if (isset($_POST['podpress_quickcounts_view_options']) and 'sortquickcountsbypost' == $_POST['podpress_quickcounts_view_options']) {
                     $this->settings['sortquickcountsbypost'] = TRUE;
                 } elseif (isset($_POST['podpress_quickcounts_view_options']) and 'sortquickcountsbymediafilenames' == $_POST['podpress_quickcounts_view_options']) {
                     $this->settings['sortquickcountsbypost'] = FALSE;
                 }
                 //~ printphpnotices_var_dump($_POST['podpress_quickcounts_view_options']);
                 //~ printphpnotices_var_dump($this->settings['sortquickcountsbypost']);
                 if (isset($this->settings['sortquickcountsbypost']) and TRUE === $this->settings['sortquickcountsbypost']) {
                     foreach ($stats as $stat) {
                         $where_instr_ar[] = 'INSTR(pm.meta_value, "' . $stat->media . '")';
                     }
                     if ($cnt_stats > 1) {
                         $where_instr = implode(' OR ', $where_instr_ar);
                     } else {
                         $where_instr = $where_instr_ar[0];
                     }
                     $where = 'pm.meta_key="_podPressMedia" AND (' . $where_instr . ')';
                     $sql = 'SELECT pm.post_id, pm.meta_key, pm.meta_value, p.post_title FROM ' . $wpdb->prefix . 'postmeta AS pm LEFT JOIN ' . $wpdb->prefix . 'posts AS p ON pm.post_id = p.ID WHERE ' . $where . ' ORDER BY pm.post_id DESC';
                     $postmeta_data = $wpdb->get_results($sql);
                     // get the highest post_id of posts which have a certain media file attached with podPress
                     // in other words get the last post which has a certain media file attached
                     foreach ($postmeta_data as $postmeta) {
                         $postmeta->post_id = intval($postmeta->post_id);
                         foreach ($stats as $stat) {
                             if (FALSE !== stristr($postmeta->meta_value, $stat->media)) {
                                 //echo $postmeta->post_id.': '.$stat->media."\n";
                                 $max_post_ids[$stat->media]['ID'] = max($max_post_ids[$stat->media]['ID'], $postmeta->post_id);
                                 if ($max_post_ids[$stat->media]['ID'] == $postmeta->post_id) {
                                     $max_post_ids[$stat->media]['title'] = $postmeta->post_title;
                                 }
                             }
                         }
                     }
                     foreach ($max_post_ids as $media => $last_published_in_post) {
                         foreach ($stats as $stat) {
                             if ($stat->media == $media) {
                                 $stat->postID = $last_published_in_post['ID'];
                                 $stat->post_title = $last_published_in_post['title'];
                                 $stats_new[] = $stat;
                             }
                         }
                     }
                     $stats = $stats_new;
                     unset($stats_new);
                     echo '	<div class="wrap">' . "\n";
                     echo '		<fieldset class="options">' . "\n";
                     echo '			<legend>' . __('Downloads Per Media File', 'podpress') . '</legend>' . "\n";
                     echo '			<p>' . __('sorted by the IDs of the posts in which the media files were last published (descending)', 'podpress') . '</p>';
                     echo '			<table class="the-list-x widefat">' . "\n";
                     echo '				<thead>';
                     echo "\t\t\t\t<tr>\n";
                     echo '                  			<th rowspan="2">' . __('Nr.', 'podpress') . "</th>\n";
                     echo '                  			<th rowspan="2">' . __('Media File', 'podpress') . "</th>\n";
                     echo '                  			<th rowspan="2">' . __('last published in post', 'podpress') . "</th>\n";
                     echo '                  			<th class="podpress_stats_nr_head" colspan="2">' . __('Feed', 'podpress') . "</th>\n";
                     echo '                  			<th class="podpress_stats_nr_head" colspan="2">' . __('Download', 'podpress') . "</th>\n";
                     echo '                  			<th class="podpress_stats_nr_head" colspan="2">' . __('Play', 'podpress') . "</th>\n";
                     echo '                  			<th class="podpress_stats_nr_head" rowspan="2">' . __('Total', 'podpress') . "</th>\n";
                     echo '              			</tr>' . "\n";
                     echo '				<tr>' . "\n";
                     echo '                  			<th class="podpress_stats_nr_head">' . __('Files', 'podpress') . "</th>\n";
                     echo '                  			<th class="podpress_stats_nr_head">' . __('%', 'podpress') . "</th>\n";
                     echo '                  			<th class="podpress_stats_nr_head">' . __('Files', 'podpress') . "</th>\n";
                     echo '                  			<th class="podpress_stats_nr_head">' . __('%', 'podpress') . "</th>\n";
                     echo '                  			<th class="podpress_stats_nr_head">' . __('Files', 'podpress') . "</th>\n";
                     echo '                  			<th class="podpress_stats_nr_head">' . __('%', 'podpress') . "</th>\n";
                     echo '              			</tr>' . "\n";
                     echo '				</thead>';
                     echo '				<tbody>';
                     $date_format = get_option('date_format');
                     $time_format = get_option('time_format');
                     if ($cnt_stats > 0) {
                         $i = 0;
                         foreach ($stats as $stat) {
                             $i++;
                             $style = $i % 2 != 0 ? '' : ' class="alternate"';
                             $highest_feed = ($stat->feed == $highest->feed and 0 < $highest->feed) ? ' podpress_stats_highest' : '';
                             $highest_web = ($stat->web == $highest->web and 0 < $highest->web) ? ' podpress_stats_highest' : '';
                             $highest_play = ($stat->play == $highest->play and 0 < $highest->play) ? ' podpress_stats_highest' : '';
                             $highest_total = $stat->total == $highest->total ? ' podpress_stats_highest' : '';
                             $perc_feed = number_format($stat->feed * 100 / $stat->total, 1, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]);
                             $perc_web = number_format($stat->web * 100 / $stat->total, 1, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]);
                             $perc_play = number_format($stat->play * 100 / $stat->total, 1, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]);
                             echo '		<tr' . $style . '>' . "\n";
                             echo '                  	<td>' . ($start + $i) . '.</td>' . "\n";
                             echo '                  	<td>' . podPress_strlimiter2(urldecode($stat->media), 30, TRUE) . '</td>' . "\n";
                             if (TRUE == version_compare($wp_version, '2.3', '<')) {
                                 echo '                  	<td><a href="' . site_url() . '/wp-admin/post.php?action=edit&amp;post=' . $stat->postID . '" title="' . __('Edit this post', 'podpress') . '">' . podPress_strlimiter2($stat->post_title, 30, TRUE) . '</a></td>' . "\n";
                             } else {
                                 echo '                  	<td><a href="' . get_edit_post_link($stat->postID) . '" title="' . __('Edit this post', 'podpress') . '">' . podPress_strlimiter2($stat->post_title, 30, TRUE) . '</a></td>' . "\n";
                             }
                             echo '                  	<td class="podpress_stats_numbers_abs' . $highest_feed . '">' . number_format($stat->feed, 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]) . "</td>\n";
                             echo '                  	<td class="podpress_stats_numbers_percent' . $highest_feed . '">' . $perc_feed . "</td>\n";
                             echo '                  	<td class="podpress_stats_numbers_abs' . $highest_web . '" >' . number_format($stat->web, 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]) . "</td>\n";
                             echo '                  	<td class="podpress_stats_numbers_percent' . $highest_web . '">' . $perc_web . "</td>\n";
                             echo '                  	<td class="podpress_stats_numbers_abs' . $highest_play . '">' . number_format($stat->play, 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]) . "</td>\n";
                             echo '                  	<td class="podpress_stats_numbers_percent' . $highest_play . '">' . $perc_play . "</td>\n";
                             echo '                  	<td class="podpress_stats_numbers_total' . $highest_total . '">' . number_format($stat->total, 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]) . "</td>\n";
                             echo '              </tr>' . "\n";
                         }
                     }
                     echo '				</tbody>' . "\n";
                     echo '				<tfoot>' . "\n";
                     echo '				<tr>' . "\n";
                     echo '				<th colspan="10">' . "\n";
                 } else {
                     echo '	<div class="wrap">' . "\n";
                     echo '		<fieldset class="options">' . "\n";
                     //echo '			<legend>'.__('The counts', 'podpress').'</legend>'."\n";
                     echo '			<legend>' . __('Downloads Per Media File', 'podpress') . '</legend>' . "\n";
                     echo '			<p>' . __('sorted by the names of the media files (descending)', 'podpress') . '</p>';
                     echo '			<table class="the-list-x widefat">' . "\n";
                     echo '				<thead>';
                     echo "\t\t\t\t<tr>\n";
                     echo '                  			<th rowspan="2">' . __('Nr.', 'podpress') . "</th>\n";
                     //~ echo '                  			<th rowspan="2">'.__('Post', 'podpress')."</th>\n";
                     //~ echo '                  			<th rowspan="2">'.__('Publication Date', 'podpress')."</th>\n";
                     echo '                  			<th rowspan="2">' . __('Media File', 'podpress') . "</th>\n";
                     echo '                  			<th class="podpress_stats_nr_head" colspan="2">' . __('Feed', 'podpress') . "</th>\n";
                     echo '                  			<th class="podpress_stats_nr_head" colspan="2">' . __('Download', 'podpress') . "</th>\n";
                     echo '                  			<th class="podpress_stats_nr_head" colspan="2">' . __('Play', 'podpress') . "</th>\n";
                     echo '                  			<th class="podpress_stats_nr_head" rowspan="2">' . __('Total', 'podpress') . "</th>\n";
                     echo '              			</tr>' . "\n";
                     echo '				<tr>' . "\n";
                     echo '                  			<th class="podpress_stats_nr_head">' . __('Files', 'podpress') . "</th>\n";
                     echo '                  			<th class="podpress_stats_nr_head">' . __('%', 'podpress') . "</th>\n";
                     echo '                  			<th class="podpress_stats_nr_head">' . __('Files', 'podpress') . "</th>\n";
                     echo '                  			<th class="podpress_stats_nr_head">' . __('%', 'podpress') . "</th>\n";
                     echo '                  			<th class="podpress_stats_nr_head">' . __('Files', 'podpress') . "</th>\n";
                     echo '                  			<th class="podpress_stats_nr_head">' . __('%', 'podpress') . "</th>\n";
                     echo '              			</tr>' . "\n";
                     echo '				</thead>';
                     echo '				<tbody>';
                     $date_format = get_option('date_format');
                     $time_format = get_option('time_format');
                     if ($cnt_stats > 0) {
                         $i = 0;
                         foreach ($stats as $stat) {
                             $i++;
                             $style = $i % 2 != 0 ? '' : ' class="alternate"';
                             $highest_feed = ($stat->feed == $highest->feed and 0 < $highest->feed) ? ' podpress_stats_highest' : '';
                             $highest_web = ($stat->web == $highest->web and 0 < $highest->web) ? ' podpress_stats_highest' : '';
                             $highest_play = ($stat->play == $highest->play and 0 < $highest->play) ? ' podpress_stats_highest' : '';
                             $highest_total = $stat->total == $highest->total ? ' podpress_stats_highest' : '';
                             $perc_feed = number_format($stat->feed * 100 / $stat->total, 1, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]);
                             $perc_web = number_format($stat->web * 100 / $stat->total, 1, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]);
                             $perc_play = number_format($stat->play * 100 / $stat->total, 1, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]);
                             echo '		<tr' . $style . '>' . "\n";
                             echo '                  	<td>' . ($start + $i) . '.</td>' . "\n";
                             //~ if ( TRUE == version_compare($wp_version, '2.3', '<') ) {
                             //~ echo '                  	<td><a href="'.site_url().'/wp-admin/post.php?action=edit&amp;post='.$stat->postID.'" title="'.__('Edit this post','podpress').'">'.podPress_strlimiter2($stat->post_title, 30, TRUE).'</a></td>'."\n";
                             //~ } else {
                             //~ echo '                  	<td><a href="'.get_edit_post_link($stat->postID).'" title="'.__('Edit this post','podpress').'">'.podPress_strlimiter2($stat->post_title, 30, TRUE).'</a></td>'."\n";
                             //~ }
                             //~ echo '                  	<td>'.date($date_format.' - '.$time_format, $stat->pdate).'</td>'."\n";
                             echo '                  	<td>' . podPress_strlimiter2(urldecode($stat->media), 30, TRUE) . '</td>' . "\n";
                             echo '                  	<td class="podpress_stats_numbers_abs' . $highest_feed . '">' . number_format($stat->feed, 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]) . "</td>\n";
                             echo '                  	<td class="podpress_stats_numbers_percent' . $highest_feed . '">' . $perc_feed . "</td>\n";
                             echo '                  	<td class="podpress_stats_numbers_abs' . $highest_web . '" >' . number_format($stat->web, 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]) . "</td>\n";
                             echo '                  	<td class="podpress_stats_numbers_percent' . $highest_web . '">' . $perc_web . "</td>\n";
                             echo '                  	<td class="podpress_stats_numbers_abs' . $highest_play . '">' . number_format($stat->play, 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]) . "</td>\n";
                             echo '                  	<td class="podpress_stats_numbers_percent' . $highest_play . '">' . $perc_play . "</td>\n";
                             echo '                  	<td class="podpress_stats_numbers_total' . $highest_total . '">' . number_format($stat->total, 0, $this->local_settings['numbers'][0], $this->local_settings['numbers'][1]) . "</td>\n";
                             echo '              </tr>' . "\n";
                         }
                     }
                     echo '				</tbody>' . "\n";
                     echo '				<tfoot>' . "\n";
                     echo '				<tr>' . "\n";
                     //~ echo '				<th colspan="11">'."\n";
                     echo '				<th colspan="9">' . "\n";
                 }
                 // Show paging
                 if ($_GET['display'] != 'graphbydate' && $_GET['display'] != 'graphbypost') {
                     echo $this->paging2($start, $limit, $total, __('Nr.', 'podpress'));
                 }
                 echo '				</th>' . "\n";
                 echo '              			</tr>' . "\n";
                 echo '				</tfoot>' . "\n";
                 echo '			</table>' . "\n";
                 echo '			<form method="post">' . "\n";
                 echo '			<div> ' . "\n";
                 $this->podpress_print_maxrowsperpage($limit);
                 echo '			<br /> ' . "\n";
                 if (isset($this->settings['sortquickcountsbypost']) and TRUE === $this->settings['sortquickcountsbypost']) {
                     echo '				<input type="radio" name="podpress_quickcounts_view_options" id="sortquickcountsbymediafilenames" value="sortquickcountsbymediafilenames" /> <label for="sortquickcountsbymediafilenames">' . __('sort the media files by their names', 'podpress') . "</label><br />\n";
                     echo '				<input type="radio" name="podpress_quickcounts_view_options" id="sortquickcountsbypost" value="sortquickcountsbypost" checked="checked" /> <label for="sortquickcountsbypost">' . __('sort the media files by the IDs of the posts in which they were last published', 'podpress') . "</label>\n";
                 } else {
                     echo '				<input type="radio" name="podpress_quickcounts_view_options" id="sortquickcountsbymediafilenames" value="sortquickcountsbymediafilenames" checked="checked" /> <label for="sortquickcountsbymediafilenames">' . __('sort the media files by their names', 'podpress') . "</label><br />\n";
                     echo '				<input type="radio" name="podpress_quickcounts_view_options" id="sortquickcountsbypost" value="sortquickcountsbypost" />  <label for="sortquickcountsbypost">' . __('sort the media files by the IDs of the posts in which they were last published', 'podpress') . "</label>\n";
                 }
                 echo '			</div> ' . "\n";
                 echo '			<p class="submit"> ' . "\n";
                 echo '				<input type="submit" class="button-primary"  name="Submit" value="' . __('Update options', 'podpress') . ' &raquo;" /><br />' . "\n";
                 echo '			</p> ' . "\n";
                 echo '			</form>' . "\n";
                 echo '		</fieldset>' . "\n";
                 echo '	</div>';
             } else {
                 echo '<p>' . __('We\'re sorry. At the moment we don\'t have enough data collected to display the graph.', 'podpress') . "</p>\n";
             }
             break;
         default:
             return;
     }
     echo '<div style="clear: both;"></div>' . "\n";
     echo '</div>';
 }