Esempio n. 1
0
function powerpress_admin_players_init()
{
    wp_enqueue_style('wp-mediaelement');
    wp_enqueue_script('wp-mediaelement');
    $Settings = false;
    // Important, never remove this
    $Step = 1;
    $action = isset($_GET['action']) ? $_GET['action'] : (isset($_POST['action']) ? $_POST['action'] : false);
    //$type = (isset($_GET['type'])?$_GET['type']: (isset($_POST['type'])?$_POST['type']:'audio') );
    if (!$action) {
        return;
    }
    switch ($action) {
        case 'powerpress-select-player':
            $SaveSettings = array();
            //$SaveSettings = $_POST['Player'];
            if (isset($_POST['Player'])) {
                $SaveSettings = $_POST['Player'];
            }
            if (isset($_POST['VideoPlayer'])) {
                $SaveSettings += $_POST['VideoPlayer'];
            }
            powerpress_save_settings($SaveSettings, 'powerpress_general');
            powerpress_page_message_add_notice(__('Player activated successfully.', 'powerpress'));
            break;
        case 'powerpress-audio-player':
            $SaveSettings = $_POST['Player'];
            powerpress_save_settings($SaveSettings, 'powerpress_audio-player');
            powerpress_page_message_add_notice(__('Audio Player settings saved successfully.', 'powerpress'));
            break;
    }
}
function powerpress_admin_players_init()
{
    //wp_enqueue_script('jquery');
    //echo "powerpres player init";
    wp_enqueue_style('mediaelement');
    wp_enqueue_style('wp-mediaelement');
    wp_enqueue_script('mediaelement');
    // wp_enqueue_script( 'wp-mediaelement' );
    wp_enqueue_script('powerpress-mejs', powerpress_get_root_url() . 'powerpress-mejs.js');
    $Settings = false;
    // Important, never remove this
    $Step = 1;
    $action = isset($_GET['action']) ? $_GET['action'] : (isset($_POST['action']) ? $_POST['action'] : false);
    //$type = (isset($_GET['type'])?$_GET['type']: (isset($_POST['type'])?$_POST['type']:'audio') );
    if (!$action) {
        return;
    }
    switch ($action) {
        case 'powerpress-select-player':
            $SaveSettings = array();
            //$SaveSettings = $_POST['Player'];
            if (isset($_POST['Player'])) {
                $SaveSettings = $_POST['Player'];
            }
            if (isset($_POST['VideoPlayer'])) {
                $SaveSettings += $_POST['VideoPlayer'];
            }
            powerpress_save_settings($SaveSettings, 'powerpress_general');
            powerpress_page_message_add_notice(__('Player activated successfully.', 'powerpress'));
            break;
        case 'powerpress-audio-player':
            $SaveSettings = $_POST['Player'];
            powerpress_save_settings($SaveSettings, 'powerpress_audio-player');
            powerpress_page_message_add_notice(__('Audio Player settings saved successfully.', 'powerpress'));
            break;
        case 'powerpress-flashmp3-maxi':
            $SaveSettings = $_POST['Player'];
            powerpress_save_settings($SaveSettings, 'powerpress_flashmp3-maxi');
            powerpress_page_message_add_notice(__('Flash Mp3 Maxi settings saved successfully.', 'powerpress'));
            break;
        case 'powerpress-audioplay':
            $SaveSettings = $_POST['Player'];
            powerpress_save_settings($SaveSettings, 'powerpress_audioplay');
            powerpress_page_message_add_notice(__('AudioPlay settings saved successfully.', 'powerpress'));
            break;
            //TODO: PowerPress 5.0
            //case 'powerpress-mediaelement':
            //{
            //	$SaveSettings = $_POST['Player'];
            //	powerpress_save_settings($SaveSettings, 'powerpress_mediaelement');
            //	powerpress_page_message_add_notice( __('MediaElement.js settings saved successfully.', 'powerpress') );
            //}; break;
    }
}
function powerpressadmin_ping_sites_process()
{
    $PingSites = false;
    if (isset($_POST['PingSite'])) {
        $PingSites = $_POST['PingSite'];
    }
    if ($PingSites && count($PingSites) > 0) {
        $ping_site_data = get_option('ping_sites');
        while (list($null, $url) = each($PingSites)) {
            $ping_site_data = trim($ping_site_data) . "\r\n{$url}";
        }
        update_option('ping_sites', $ping_site_data);
        powerpress_page_message_add_notice(__('Update services added successfully.', 'powerpress'));
    } else {
        powerpress_page_message_add_notice(__('No update services selected to add.', 'powerpress'));
    }
}
function powerpress_admin_jquery_init()
{
    $Settings = false;
    // Important, never remove this
    $Settings = get_option('powerpress_general');
    $Error = false;
    $Programs = false;
    $Step = 1;
    $action = isset($_GET['action']) ? $_GET['action'] : (isset($_POST['action']) ? $_POST['action'] : false);
    if (!$action) {
        return;
    }
    $DeleteFile = false;
    switch ($action) {
        case 'powerpress-jquery-stats':
            // Make sure users have permission to access this
            if (!empty($Settings['use_caps']) && !current_user_can('view_podcast_stats')) {
                powerpress_admin_jquery_header(__('Blubrry Media Statistics', 'powerpress'));
                ?>
<h2><?php 
                echo __('Blubrry Media Statistics', 'powerpress');
                ?>
</h2>
<p><?php 
                echo __('You do not have sufficient permission to manage options.', 'powerpress');
                ?>
</p>
<p style="text-align: center;"><a href="#" onclick="self.parent.tb_remove();"><?php 
                echo __('Close', 'powerpress');
                ?>
</a></p>
<?php 
                powerpress_admin_jquery_footer();
                exit;
            } else {
                if (!current_user_can('edit_posts')) {
                    powerpress_admin_jquery_header(__('Blubrry Media Statistics', 'powerpress'));
                    powerpress_page_message_add_notice(__('You do not have sufficient permission to view media statistics.', 'powerpress'));
                    powerpress_page_message_print();
                    powerpress_admin_jquery_footer();
                    exit;
                }
            }
            $StatsCached = get_option('powerpress_stats');
            powerpress_admin_jquery_header(__('Blubrry Media Statistics', 'powerpress'));
            ?>
<h2><?php 
            echo __('Blubrry Media Statistics', 'powerpress');
            ?>
</h2>
<?php 
            echo $StatsCached['content'];
            powerpress_admin_jquery_footer();
            exit;
            break;
        case 'powerpress-jquery-media-disable':
            if (!current_user_can('edit_posts')) {
                powerpress_admin_jquery_header('Uploader');
                powerpress_page_message_add_notice(__('You do not have sufficient permission to disable this option.', 'powerpress'));
                powerpress_page_message_print();
                powerpress_admin_jquery_footer();
                exit;
            }
            check_admin_referer('powerpress-jquery-media-disable');
            $DisableSetting = array();
            $DisableSetting['no_media_url_folder'] = 1;
            powerpress_save_settings($DisableSetting);
            powerpress_admin_jquery_header(__('Select Media', 'powerpress'));
            ?>
<h2><?php 
            echo __('Select Media', 'powerpress');
            ?>
</h2>
<p><?php 
            echo __('Blubrry Media Hosting icon will no longer be displayed when editing posts and pages.', 'powerpress');
            ?>
</p>
<p style="text-align: center;"><a href="#" onclick="self.parent.tb_remove();"><?php 
            echo __('Close', 'powerpress');
            ?>
</a></p>
<?php 
            powerpress_admin_jquery_footer();
            exit;
            // No break here, let this fall thru..
        // No break here, let this fall thru..
        case 'powerpress-jquery-media-delete':
            if (!current_user_can('edit_posts')) {
                powerpress_admin_jquery_header('Uploader');
                powerpress_page_message_add_notice(__('You do not have sufficient permission to upload media.', 'powerpress'));
                powerpress_page_message_print();
                powerpress_admin_jquery_footer();
                exit;
            }
            check_admin_referer('powerpress-jquery-media-delete');
            $DeleteFile = $_GET['delete'];
            // No break here, let this fall thru..
        // No break here, let this fall thru..
        case 'powerpress-jquery-media':
            if (!current_user_can('edit_posts')) {
                powerpress_admin_jquery_header(__('Select Media', 'powerpress'));
                ?>
<h2><?php 
                echo __('Select Media', 'powerpress');
                ?>
</h2>
<p><?php 
                echo __('You do not have sufficient permission to manage options.', 'powerpress');
                ?>
</p>
<p style="text-align: center;"><a href="#" onclick="self.parent.tb_remove();"><?php 
                echo __('Close', 'powerpress');
                ?>
</a></p>
<?php 
                powerpress_admin_jquery_footer();
                exit;
            }
            if (empty($Settings['blubrry_auth']) || empty($Settings['blubrry_hosting']) || $Settings['blubrry_hosting'] === 'false') {
                powerpress_admin_jquery_header(__('Select Media', 'powerpress'));
                ?>
<h2><?php 
                echo __('Select Media', 'powerpress');
                ?>
</h2>
<p><?php 
                echo __('Wait a sec! This feature is only available to Blubrry Media Podcast Hosting customers.', 'powerpress');
                if (!isset($Settings['blubrry_auth'])) {
                    echo ' ' . sprintf(__('Join our community to get free podcast statistics and access to other valuable %s.', 'powerpress'), '<a href="http://create.blubrry.com/resources/" target="_blank">' . __('services', 'powerpress') . '</a>');
                }
                ?>
</p>
<p><?php 
                echo sprintf(__('Our %s integrated with PowerPress making podcast publishing simple. Check out the %s on our exciting three-step publishing system!', 'powerpress'), '<a href="http://create.blubrry.com/resources/podcast-media-hosting/" target="_blank">' . __('Podcast Media Hosting', 'powerpress') . '</a>', '<a href="http://create.blubrry.com/resources/podcast-media-hosting/blubrry-on-site-podcast-hosting-demo/" target="_blank">' . __('video', 'powerpress') . '</a>');
                ?>
   </p>
	 <p><a href="<?php 
                echo wp_nonce_url("admin.php?action=powerpress-jquery-media-disable", 'powerpress-jquery-media-disable');
                ?>
&amp;KeepThis=true&amp;TB_iframe=true&amp;modal=true" onclick="return confirm('<?php 
                echo __('Remove the Blubrry Media Hosting icon from the Media URL field?', 'powerpress');
                ?>
');"><?php 
                echo __('Do not show this icon next to the Media URL field', 'powerpress');
                ?>
</a></p>
<p style="text-align: center;"><a href="#" onclick="self.parent.tb_remove();"><?php 
                echo __('Close', 'powerpress');
                ?>
</a></p>
<?php 
                powerpress_admin_jquery_footer();
                exit;
            }
            $Msg = false;
            if ($DeleteFile) {
                $json_data = false;
                $api_url_array = powerpress_get_api_array();
                while (list($index, $api_url) = each($api_url_array)) {
                    $req_url = sprintf('%s/media/%s/%s?format=json', rtrim($api_url, '/'), $Settings['blubrry_program_keyword'], $DeleteFile);
                    $req_url .= defined('POWERPRESS_BLUBRRY_API_QSA') ? '&' . POWERPRESS_BLUBRRY_API_QSA : '';
                    $json_data = powerpress_remote_fopen($req_url, $Settings['blubrry_auth'], array(), 10, 'DELETE');
                    if ($json_data != false) {
                        break;
                    }
                }
                $results = powerpress_json_decode($json_data);
                if (isset($results['text'])) {
                    $Msg = $results['text'];
                } else {
                    if (isset($results['error'])) {
                        $Msg = $results['error'];
                    } else {
                        $Msg = __('An unknown error occurred deleting media file.', 'powerpress');
                    }
                }
            }
            $json_data = false;
            $api_url_array = powerpress_get_api_array();
            while (list($index, $api_url) = each($api_url_array)) {
                $req_url = sprintf('%s/media/%s/index.json?quota=true&published=true', rtrim($api_url, '/'), $Settings['blubrry_program_keyword']);
                $req_url .= defined('POWERPRESS_BLUBRRY_API_QSA') ? '&' . POWERPRESS_BLUBRRY_API_QSA : '';
                $json_data = powerpress_remote_fopen($req_url, $Settings['blubrry_auth']);
                if ($json_data != false) {
                    break;
                }
            }
            $results = powerpress_json_decode($json_data);
            $FeedSlug = $_GET['podcast-feed'];
            powerpress_admin_jquery_header(__('Select Media', 'powerpress'), true);
            ?>
<script language="JavaScript" type="text/javascript"><!--

function SelectMedia(File)
{
	self.parent.document.getElementById('powerpress_url_<?php 
            echo $FeedSlug;
            ?>
').value=File;
	self.parent.document.getElementById('powerpress_hosting_<?php 
            echo $FeedSlug;
            ?>
').value='1';
	self.parent.document.getElementById('powerpress_url_<?php 
            echo $FeedSlug;
            ?>
').readOnly=true;
	self.parent.document.getElementById('powerpress_hosting_note_<?php 
            echo $FeedSlug;
            ?>
').style.display='block';
	if( self.parent.powerpress_update_for_video )
		self.parent.powerpress_update_for_video(File, '<?php 
            echo $FeedSlug;
            ?>
');
	self.parent.tb_remove();
}
function SelectURL(url)
{
	self.parent.document.getElementById('powerpress_url_<?php 
            echo $FeedSlug;
            ?>
').value=url;
	self.parent.document.getElementById('powerpress_hosting_<?php 
            echo $FeedSlug;
            ?>
').value='0';
	self.parent.document.getElementById('powerpress_url_<?php 
            echo $FeedSlug;
            ?>
').readOnly=false;
	self.parent.document.getElementById('powerpress_hosting_note_<?php 
            echo $FeedSlug;
            ?>
').style.display='none';
	if( self.parent.powerpress_update_for_video )
		self.parent.powerpress_update_for_video(url, '<?php 
            echo $FeedSlug;
            ?>
');
	self.parent.tb_remove();
}
function DeleteMedia(File)
{
	return confirm('<?php 
            echo __('Delete', 'powerpress');
            ?>
: '+File+'\n\n<?php 
            echo __('Are you sure you want to delete this media file?', 'powerpress');
            ?>
');
}
//-->
</script>
		<div id="media-header">
			<h2><?php 
            echo __('Select Media', 'powerpress');
            ?>
</h2>
			<?php 
            if (!empty($results['quota']['expires'])) {
                $message = '';
                if (!empty($results['quota']['expires']['expired'])) {
                    $message = '<p>' . sprintf(__('Media hosting service expired on %s.', 'powerpress'), $results['quota']['expires']['readable_date']) . '</p>';
                } else {
                    $message = '<p>' . sprintf(__('Media hosting service will expire on %s.', 'powerpress'), $results['quota']['expires']['readable_date']) . '</p>';
                }
                $message .= '<p style="text-align: center;"><strong><a href="' . $results['quota']['expires']['renew_link'] . '" target="_blank" style="text-decoration: underline;">' . __('Renew Media Hosting Service', 'powerpress') . '</a></strong></p>';
                powerpress_page_message_add_notice($message);
                powerpress_page_message_print();
            } else {
                if (empty($results)) {
                    // Handle the error here.
                    $message = '<h3>' . __('Error', 'powerpress') . '</h3>';
                    global $g_powerpress_remote_error, $g_powerpress_remote_errorno;
                    if (!empty($g_powerpress_remote_errorno) && $g_powerpress_remote_errorno == 401) {
                        $message .= '<p>' . __('Incorrect sign-in email address or password.', 'powerpress') . '</p><p>' . __('Verify your account entered under Services and Statistics settings then try again.', 'powerpress') . '</p>';
                    } else {
                        if (!empty($g_powerpress_remote_error)) {
                            $message .= '<p>' . $g_powerpress_remote_error . '</p>';
                        } else {
                            $message .= '<p>' . __('Unable to connect to service.', 'powerpress') . '</p>';
                        }
                    }
                    // Print an erro here
                    powerpress_page_message_add_notice($message);
                    powerpress_page_message_print();
                }
            }
            if ($Msg) {
                echo '<p>' . $Msg . '</p>';
            }
            ?>
			<div class="media-upload-link"><a href="<?php 
            echo admin_url() . wp_nonce_url("admin.php?action=powerpress-jquery-upload", 'powerpress-jquery-upload');
            ?>
&podcast-feed=<?php 
            echo $FeedSlug;
            ?>
&keepThis=true&TB_iframe=true&height=350&width=530&modal=true" class="thickbox"><?php 
            echo __('Upload Media File', 'powerpress');
            ?>
</a></div>
			<p><?php 
            echo __('Select from media files uploaded to blubrry.com', 'powerpress');
            ?>
:</p>
		</div>
	<div id="media-items-container">
		<div id="media-items">
<?php 
            $QuotaData = false;
            if (isset($results['error'])) {
                echo $results['error'];
            } else {
                if (is_array($results)) {
                    $PublishedList = false;
                    while (list($index, $data) = each($results)) {
                        if ($index === 'quota') {
                            $QuotaData = $data;
                            continue;
                        }
                        if ($PublishedList == false && !empty($data['published'])) {
                            ?>
<div id="media-published-title">
	<?php 
                            echo __('Media Published within the past 30 days', 'powerpress');
                            ?>
:
</div>
<?php 
                            $PublishedList = true;
                        }
                        ?>
<div class="media-item <?php 
                        echo empty($data['published']) ? 'media-unpublished' : 'media-published';
                        ?>
">
	<strong class="media-name"><?php 
                        echo htmlspecialchars($data['name']);
                        ?>
</strong>
	<cite><?php 
                        echo powerpress_byte_size($data['length']);
                        ?>
</cite>
	<?php 
                        if (!empty($data['published'])) {
                            ?>
	<div class="media-published-date">&middot; <?php 
                            echo __('Published on', 'powerpress');
                            ?>
 <?php 
                            echo date(get_option('date_format'), $data['last_modified']);
                            ?>
</div>
	<?php 
                        }
                        ?>
	<div class="media-item-links">
		<?php 
                        if (!empty($data['published']) && !empty($data['url'])) {
                            ?>
			<a href="#" onclick="SelectURL('<?php 
                            echo $data['url'];
                            ?>
'); return false;"><?php 
                            echo __('Select', 'powerpress');
                            ?>
</a>
		<?php 
                        } else {
                            ?>
			<?php 
                            if (function_exists('curl_init')) {
                                ?>
				<a href="<?php 
                                echo admin_url() . wp_nonce_url("admin.php?action=powerpress-jquery-media-delete", 'powerpress-jquery-media-delete');
                                ?>
&amp;podcast-feed=<?php 
                                echo $FeedSlug;
                                ?>
&amp;delete=<?php 
                                echo urlencode($data['name']);
                                ?>
" onclick="return DeleteMedia('<?php 
                                echo $data['name'];
                                ?>
');"><?php 
                                echo __('Delete', 'powerpress');
                                ?>
</a> | 
			<?php 
                            }
                            ?>
			<a href="#" onclick="SelectMedia('<?php 
                            echo $data['name'];
                            ?>
'); return false;"><?php 
                            echo __('Select', 'powerpress');
                            ?>
</a>
		<?php 
                        }
                        ?>
	</div> 
</div>
<?php 
                    }
                }
            }
            ?>
		</div>
	</div>
	<div id="media-footer">
		<div class="media-upload-link"><a href="<?php 
            echo admin_url() . wp_nonce_url("admin.php?action=powerpress-jquery-upload", 'powerpress-jquery-upload');
            ?>
&podcast-feed=<?php 
            echo $FeedSlug;
            ?>
&keepThis=true&TB_iframe=true&height=350&width=530&modal=true" class="thickbox"><?php 
            echo __('Upload Media File', 'powerpress');
            ?>
</a></div>
		<?php 
            if ($QuotaData) {
                $NextDate = strtotime($QuotaData['published']['next_date']);
                ?>
			<?php 
                if ($QuotaData['unpublished']['available'] != $QuotaData['unpublished']['total']) {
                    //echo '<p>';
                    //echo sprintf( __('You have uploaded %s (%s available) of your %s upload limit.', 'powerpress'),
                    //	'<em>'. powerpress_byte_size($QuotaData['unpublished']['used']) .'</em>',
                    //	'<em>'. powerpress_byte_size($QuotaData['unpublished']['available']) .'</em>',
                    //	'<em>'. powerpress_byte_size($QuotaData['unpublished']['total']) .'</em>' );
                    //echo '</p>';
                }
                if ($QuotaData['published']['status'] == 'OK') {
                    ?>
			<p><?php 
                    if ($QuotaData['published']['available'] > 0) {
                        echo sprintf(__('Publishing space available: %s of (%s %%) of %s/month quota.', 'powerpress'), '<em>' . powerpress_byte_size($QuotaData['published']['available']) . '</em>', '<em>' . round($QuotaData['published']['available'] / $QuotaData['published']['total'] * 100) . '</em>', '<em>' . str_replace('.0', '', powerpress_byte_size($QuotaData['published']['total'])) . '</em>');
                        //echo sprintf( __('You have %s available (%s published in the last 30 days) of your %s publish limit.', 'powerpress'),
                        //	'<em>'. powerpress_byte_size($QuotaData['published']['available']) .'</em>',
                        //	'<em>'. powerpress_byte_size($QuotaData['published']['total']-$QuotaData['published']['available']) .'</em>',
                        //	'<em>'. powerpress_byte_size($QuotaData['published']['total']) .'</em>' );
                    } else {
                        if ($QuotaData['published']['available'] == 0) {
                        } else {
                            echo sprintf(__('You have %s publish space available.', 'powerpress'), '<em>' . powerpress_byte_size($QuotaData['published']['total']) . '</em>');
                        }
                    }
                    ?>
			</p>
			<p>
			<?php 
                    echo sprintf(__('No-Fault Hosting: You may upload a media file up to %s in size and be within the No-Fault maximum (25%% more than your %s quota).', 'powerpress'), powerpress_byte_size($QuotaData['published']['no_fault_maximum']), str_replace('.0', '', powerpress_byte_size($QuotaData['published']['total'])));
                    echo ' ';
                    echo '<a href="http://create.blubrry.com/resources/podcast-media-hosting/no-fault/" target="_blank">' . __('Learn More', 'powerpress') . '</a>';
                    ?>
			</p>
			<p><?php 
                    if ($QuotaData['published']['available'] != $QuotaData['published']['total']) {
                        echo sprintf(__('Your quota will reset on %s.', 'powerpress'), date('m/d/Y', $NextDate));
                    }
                    ?>
			</p>
			<?php 
                } else {
                    if ($QuotaData['published']['status'] == 'UNLIMITED') {
                        echo '<p>';
                        echo __('Publishing Space Available: Unlimited (Professional Hosting)', 'powerpress');
                        echo '<p>';
                    } else {
                        echo '<p>';
                        echo __('Publishing Space Available: Account has expired', 'powerpress');
                        echo '<p>';
                    }
                }
                ?>
		<?php 
            }
            ?>
		<p style="text-align: center;"><a href="#" onclick="self.parent.tb_remove();"><?php 
            echo __('Close', 'powerpress');
            ?>
</a></p>
	</div>
	
<?php 
            powerpress_admin_jquery_footer(true);
            exit;
            break;
        case 'powerpress-jquery-account-save':
            if (!current_user_can(POWERPRESS_CAPABILITY_MANAGE_OPTIONS)) {
                powerpress_admin_jquery_header('Blubrry Services Integration', 'powerpress');
                powerpress_page_message_add_notice(__('You do not have sufficient permission to manage options.', 'powerpress'));
                powerpress_page_message_print();
                powerpress_admin_jquery_footer();
                exit;
            }
            check_admin_referer('powerpress-jquery-account');
            $Password = $_POST['Password'];
            $SaveSettings = $_POST['Settings'];
            $Password = powerpress_stripslashes($Password);
            $SaveSettings = powerpress_stripslashes($SaveSettings);
            $Save = false;
            $Close = false;
            if (!empty($_POST['Remove'])) {
                $SaveSettings['blubrry_username'] = '';
                $SaveSettings['blubrry_auth'] = '';
                $SaveSettings['blubrry_program_keyword'] = '';
                $SaveSettings['blubrry_hosting'] = false;
                $Close = true;
                $Save = true;
            } else {
                $Programs = array();
                $ProgramHosting = array();
                // Anytime we change the password we need to test it...
                $auth = base64_encode($SaveSettings['blubrry_username'] . ':' . $Password);
                $json_data = false;
                $api_url_array = powerpress_get_api_array();
                while (list($index, $api_url) = each($api_url_array)) {
                    $req_url = sprintf('%s/service/index.json', rtrim($api_url, '/'));
                    $req_url .= defined('POWERPRESS_BLUBRRY_API_QSA') ? '?' . POWERPRESS_BLUBRRY_API_QSA : '';
                    $json_data = powerpress_remote_fopen($req_url, $auth);
                    if ($json_data != false) {
                        break;
                    }
                }
                if ($json_data) {
                    $results = powerpress_json_decode($json_data);
                    if (isset($results['error'])) {
                        $Error = $results['error'];
                        if (strstr($Error, __('currently not available', 'powerpress'))) {
                            $Error = __('Unable to find podcasts for this account.', 'powerpress');
                            $Error .= '<br /><span style="font-weight: normal; font-size: 12px;">';
                            $Error .= 'Verify that the email address you enter here matches the email address you used when you listed your podcast on blubrry.com.</span>';
                        } else {
                            if (preg_match('/No programs found.*media hosting/i', $results['error'])) {
                                $Error .= '<br/><span style="font-weight: normal; font-size: 12px;">';
                                $Error .= 'Service may take a few minutes to activate.</span>';
                            }
                        }
                    } else {
                        if (!is_array($results)) {
                            $Error = $json_data;
                        } else {
                            // Get all the programs for this user...
                            while (list($null, $row) = each($results)) {
                                $Programs[$row['program_keyword']] = $row['program_title'];
                                if ($row['hosting'] === true || $row['hosting'] == 'true') {
                                    $ProgramHosting[$row['program_keyword']] = true;
                                } else {
                                    $ProgramHosting[$row['program_keyword']] = false;
                                }
                            }
                            if (count($Programs) > 0) {
                                $SaveSettings['blubrry_auth'] = $auth;
                                if (!empty($SaveSettings['blubrry_program_keyword'])) {
                                    powerpress_add_blubrry_redirect($SaveSettings['blubrry_program_keyword']);
                                    $SaveSettings['blubrry_hosting'] = $ProgramHosting[$SaveSettings['blubrry_program_keyword']];
                                    if (!is_bool($SaveSettings['blubrry_hosting'])) {
                                        if ($SaveSettings['blubrry_hosting'] === 'false' || empty($SaveSettings['blubrry_hosting'])) {
                                            $SaveSettings['blubrry_hosting'] = false;
                                        }
                                    }
                                    $Save = true;
                                    $Close = true;
                                } else {
                                    if (isset($SaveSettings['blubrry_program_keyword'])) {
                                        $Error = __('You must select a program to continue.', 'powerpress');
                                    } else {
                                        if (count($Programs) == 1) {
                                            list($keyword, $title) = each($Programs);
                                            $SaveSettings['blubrry_program_keyword'] = $keyword;
                                            $SaveSettings['blubrry_hosting'] = $ProgramHosting[$keyword];
                                            if (!is_bool($SaveSettings['blubrry_hosting'])) {
                                                if ($SaveSettings['blubrry_hosting'] === 'false' || empty($SaveSettings['blubrry_hosting'])) {
                                                    $SaveSettings['blubrry_hosting'] = false;
                                                }
                                            }
                                            powerpress_add_blubrry_redirect($keyword);
                                            $Close = true;
                                            $Save = true;
                                        } else {
                                            $Error = __('Please select your podcast program to continue.', 'powerpress');
                                            $Step = 2;
                                            $Settings['blubrry_username'] = $SaveSettings['blubrry_username'];
                                        }
                                    }
                                }
                            } else {
                                $Error = __('No podcasts for this account are listed on blubrry.com.', 'powerpress');
                            }
                        }
                    }
                } else {
                    global $g_powerpress_remote_error, $g_powerpress_remote_errorno;
                    //$Error = '<h3>'. __('Error', 'powerpress') .'</h3>';
                    if (!empty($g_powerpress_remote_errorno) && $g_powerpress_remote_errorno == 401) {
                        $Error .= '<p>' . __('Incorrect sign-in email address or password.', 'powerpress') . '</p><p>' . __('Verify your account settings then try again.', 'powerpress') . '</p>';
                    } else {
                        if (!empty($g_powerpress_remote_error)) {
                            $Error .= '<p>' . $g_powerpress_remote_error . '</p>';
                        } else {
                            $Error .= '<p>' . __('Authentication failed.', 'powerpress') . '</p>';
                        }
                    }
                }
                if ($Error) {
                    $Error .= '<p style="text-align: center;"><a href="http://create.blubrry.com/resources/powerpress/powerpress-settings/services-stats/" target="_blank">' . __('Click Here For Help', 'powerpress') . '</a></p>';
                }
            }
            if ($Save) {
                powerpress_save_settings($SaveSettings);
            }
            // Clear cached statistics
            delete_option('powerpress_stats');
            if ($Error) {
                powerpress_page_message_add_notice($Error);
            }
            if ($Close) {
                powerpress_admin_jquery_header(__('Blubrry Services Integration', 'powerpress'));
                powerpress_page_message_print();
                ?>
<p style="text-align: right; position: absolute; top: 5px; right: 5px; margin: 0; padding:0;"><a href="#" onclick="self.parent.tb_remove(); return false;" title="<?php 
                echo __('Close', 'powerpress');
                ?>
"><img src="<?php 
                echo admin_url();
                ?>
/images/no.png" alt="<?php 
                echo __('Close', 'powerpress');
                ?>
" /></a></p>
<h2><?php 
                echo __('Blubrry Services Integration', 'powerpress');
                ?>
</h2>
<p style="text-align: center;"><strong><?php 
                echo __('Settings Saved Successfully!', 'powerpress');
                ?>
</strong></p>
<p style="text-align: center;">
	<a href="<?php 
                echo admin_url("admin.php?page=powerpress/powerpressadmin_basic.php");
                ?>
" onclick="self.parent.tb_remove(); return false;" target="_top"><?php 
                echo __('Close', 'powerpress');
                ?>
</a>
</p>
<script type="text/javascript"><!--

jQuery(document).ready(function($) {
	// Upload loading, check the parent window for #blubrry_stats_settings div
	if( jQuery('#blubrry_stats_settings',parent.document).length )
	{
		jQuery('#blubrry_stats_settings',parent.document).html('');
	}
});

// --></script>
<?php 
                powerpress_admin_jquery_footer();
                exit;
            }
            // no break here, let the next case catch it...
        // no break here, let the next case catch it...
        case 'powerpress-jquery-account':
            if (!current_user_can(POWERPRESS_CAPABILITY_MANAGE_OPTIONS)) {
                powerpress_admin_jquery_header(__('Blubrry Services Integration', 'powerpress'));
                powerpress_page_message_add_notice(__('You do not have sufficient permission to manage options.', 'powerpress'));
                powerpress_page_message_print();
                powerpress_admin_jquery_footer();
                exit;
            }
            if (!ini_get('allow_url_fopen') && !function_exists('curl_init')) {
                powerpress_admin_jquery_header(__('Blubrry Services Integration', 'powerpress'));
                powerpress_page_message_add_notice(__('Your server must either have the php.ini setting \'allow_url_fopen\' enabled or have the PHP cURL library installed in order to continue.', 'powerpress'));
                powerpress_page_message_print();
                powerpress_admin_jquery_footer();
                exit;
            }
            check_admin_referer('powerpress-jquery-account');
            if (!$Settings) {
                $Settings = get_option('powerpress_general');
            }
            if (empty($Settings['blubrry_username'])) {
                $Settings['blubrry_username'] = '';
            }
            if (empty($Settings['blubrry_hosting']) || $Settings['blubrry_hosting'] === 'false') {
                $Settings['blubrry_hosting'] = false;
            }
            if (empty($Settings['blubrry_program_keyword'])) {
                $Settings['blubrry_program_keyword'] = '';
            }
            if ($Programs == false) {
                $Programs = array();
            }
            powerpress_admin_jquery_header(__('Blubrry Services Integration', 'powerpress'));
            powerpress_page_message_print();
            ?>
<form action="<?php 
            echo admin_url('admin.php');
            ?>
" enctype="multipart/form-data" method="post">
<?php 
            wp_nonce_field('powerpress-jquery-account');
            ?>
<input type="hidden" name="action" value="powerpress-jquery-account-save" />
<div id="accountinfo">
	<h2><?php 
            echo __('Blubrry Services Integration', 'powerpress');
            ?>
</h2>
<?php 
            if ($Step == 1) {
                ?>
	<p>
		<label for="blubrry_username"><?php 
                echo __('Blubrry User Name (Email)', 'powerpress');
                ?>
</label>
		<input type="text" id="blubrry_username" name="Settings[blubrry_username]" value="<?php 
                echo $Settings['blubrry_username'];
                ?>
" />
	</p>
	<p id="password_row">
		<label for="password_password"><?php 
                echo __('Blubrry Password', 'powerpress');
                ?>
</label>
		<input type="password" id="password_password" name="Password" value="" />
	</p>
<?php 
            } else {
                ?>
	<input type="hidden" name="Settings[blubrry_username]" value="<?php 
                echo htmlspecialchars($Settings['blubrry_username']);
                ?>
" />
	<input type="hidden" name="Password" value="<?php 
                echo htmlspecialchars($Password);
                ?>
" />
	<!-- <input type="hidden" name="Settings[blubrry_hosting]" value="<?php 
                echo $Settings['blubrry_hosting'];
                ?>
" /> -->
	<p>
		<label for="blubrry_program_keyword"><?php 
                echo __('Select Blubrry Program', 'powerpress');
                ?>
</label>
<select id="blubrry_program_keyword" name="Settings[blubrry_program_keyword]">
<option value=""><?php 
                echo __('Select Program', 'powerpress');
                ?>
</option>
<?php 
                while (list($value, $desc) = each($Programs)) {
                    echo "\t<option value=\"{$value}\"" . ($Settings['blubrry_program_keyword'] == $value ? ' selected' : '') . ">{$desc}</option>\n";
                }
                ?>
</select>
	</p>
<?php 
            }
            ?>
	<p>
		<input type="submit" name="Save" value="<?php 
            echo __('Save', 'powerpress');
            ?>
" />
		<input type="button" name="Cancel" value="<?php 
            echo __('Cancel', 'powerpress');
            ?>
" onclick="self.parent.tb_remove();" />
		<input type="submit" name="Remove" value="Remove" style="float: right;" onclick="return confirm('<?php 
            echo __('Remove Blubrry Services Integration, are you sure?', 'powerpress');
            ?>
');" />
	</p>
</div>
</form>
<?php 
            powerpress_admin_jquery_footer();
            exit;
            break;
        case 'powerpress-jquery-upload':
            if (!current_user_can('edit_posts')) {
                powerpress_admin_jquery_header(__('Uploader', 'powerpress'));
                powerpress_page_message_add_notice(__('You do not have sufficient permission to upload media.', 'powerpress'));
                powerpress_page_message_print();
                powerpress_admin_jquery_footer();
                exit;
            }
            check_admin_referer('powerpress-jquery-upload');
            $RedirectURL = false;
            $Error = false;
            if (!$Settings) {
                $Settings = get_option('powerpress_general');
            }
            if (empty($Settings['blubrry_hosting']) || $Settings['blubrry_hosting'] === 'false') {
                $Settings['blubrry_hosting'] = false;
            }
            if (empty($Settings['blubrry_program_keyword'])) {
                $Settings['blubrry_program_keyword'] = '';
            }
            if (empty($Settings['blubrry_auth'])) {
                $Settings['blubrry_auth'] = '';
            }
            if (empty($Settings['blubrry_hosting'])) {
                $Error = __('This feature is available to Blubrry Hosting users only.', 'powerpress');
            }
            if ($Error == false) {
                $json_data = false;
                $api_url_array = powerpress_get_api_array();
                while (list($index, $api_url) = each($api_url_array)) {
                    $req_url = sprintf('%s/media/%s/upload_session.json', rtrim($api_url, '/'), $Settings['blubrry_program_keyword']);
                    $req_url .= defined('POWERPRESS_BLUBRRY_API_QSA') ? '?' . POWERPRESS_BLUBRRY_API_QSA : '';
                    $json_data = powerpress_remote_fopen($req_url, $Settings['blubrry_auth']);
                    if ($json_data != false) {
                        break;
                    }
                }
                $results = powerpress_json_decode($json_data);
                // We need to obtain an upload session for this user...
                if (isset($results['error']) && strlen($results['error']) > 1) {
                    $Error = $results['error'];
                    if (strstr($Error, 'currently not available')) {
                        $Error = __('Unable to find podcasts for this account.', 'powerpress');
                    }
                } else {
                    if ($results === $json_data) {
                        $Error = $json_data;
                    } else {
                        if (!is_array($results) || $results == false) {
                            $Error = $json_data;
                        } else {
                            if (isset($results['url']) && !empty($results['url'])) {
                                $RedirectURL = $results['url'];
                            }
                        }
                    }
                }
            }
            if ($Error == false && $RedirectURL) {
                $RedirectURL .= '&ReturnURL=';
                $RedirectURL .= urlencode(admin_url("admin.php?action=powerpress-jquery-upload-complete"));
                header("Location: {$RedirectURL}");
                exit;
            } else {
                if ($Error == false) {
                    global $g_powerpress_remote_error, $g_powerpress_remote_errorno;
                    if (!empty($g_powerpress_remote_errorno) && $g_powerpress_remote_errorno == 401) {
                        $Error = '<p>' . __('Incorrect sign-in email address or password.', 'powerpress') . '</p><p>' . __('Verify your account entered under Services and Statistics settings then try again.', 'powerpress') . '</p>';
                    } else {
                        if (!empty($g_powerpress_remote_error)) {
                            $Error = '<p>' . $g_powerpress_remote_error . '</p>';
                        } else {
                            $Error = '<p>' . __('Unable to obtain upload session.', 'powerpress') . '</p>';
                        }
                    }
                }
            }
            powerpress_admin_jquery_header(__('Uploader', 'powerpress'));
            echo '<h2>' . __('Uploader', 'powerpress') . '</h2>';
            echo '<p>';
            echo $Error;
            echo '</p>';
            ?>
			<p style="text-align: center;"><a href="#" onclick="self.parent.tb_remove();"><?php 
            echo __('Close', 'powerpress');
            ?>
</a></p>
			<?php 
            powerpress_admin_jquery_footer();
            exit;
            break;
        case 'powerpress-jquery-upload-complete':
            if (!current_user_can('edit_posts')) {
                powerpress_admin_jquery_header('Uploader');
                powerpress_page_message_add_notice(__('You do not have sufficient permission to upload media.', 'powerpress'));
                powerpress_page_message_print();
                powerpress_admin_jquery_footer();
                exit;
            }
            $File = isset($_GET['File']) ? $_GET['File'] : false;
            $Message = isset($_GET['Message']) ? $_GET['Message'] : false;
            powerpress_admin_jquery_header(__('Upload Complete', 'powerpress'));
            echo '<h2>' . __('Uploader', 'powerpress') . '</h2>';
            echo '<p>';
            if ($File) {
                echo __('File', 'powerpress') . ': ';
                echo $File;
                echo ' - ';
            }
            echo $Message;
            echo '</p>';
            ?>
			<p style="text-align: center;"><a href="#" onclick="self.parent.tb_remove();"><?php 
            echo __('Close', 'powerpress');
            ?>
</a></p>
			<?php 
            if ($Message == '') {
                ?>
<script language="JavaScript" type="text/javascript"><!--
<?php 
                if ($File != '') {
                    ?>
self.parent.SelectMedia('<?php 
                    echo $File;
                    ?>
'); <?php 
                }
                ?>
self.parent.tb_remove();
//-->
</script>
<?php 
            }
            powerpress_admin_jquery_footer();
            exit;
            break;
    }
}
function powerpressadmin_diagnostics_process()
{
    global $powerpress_diags;
    $powerpress_diags = array();
    // First, see if the user has cURL and/or allow_url_fopen enabled...
    $powerpress_diags['detecting_media'] = array();
    $powerpress_diags['detecting_media']['success'] = true;
    $powerpress_diags['detecting_media']['warning'] = false;
    $powerpress_diags['detecting_media']['allow_url_fopen'] = ini_get('allow_url_fopen') != false;
    // fopen
    $powerpress_diags['detecting_media']['curl'] = function_exists('curl_init');
    // cURL
    $powerpress_diags['detecting_media']['message2'] = '';
    // if ( !ini_get('safe_mode') && !ini_get('open_basedir') )
    // Testing:
    //$powerpress_diags['detecting_media']['allow_url_fopen'] = false;
    //$powerpress_diags['detecting_media']['curl'] = false;
    if ($powerpress_diags['detecting_media']['curl']) {
        $powerpress_diags['detecting_media']['message'] = __('Your web server supports the PHP cURL library.', 'powerpress');
        if ($powerpress_diags['detecting_media']['allow_url_fopen']) {
            $powerpress_diags['detecting_media']['message'] .= ' ' . __('Your web server is also configured with the php.ini setting \'allow_url_fopen\' enabled, but the cURL library takes precedence.', 'powerpress');
        }
        if (ini_get('safe_mode') && ini_get('open_basedir')) {
            $powerpress_diags['detecting_media']['warning'] = true;
            $powerpress_diags['detecting_media']['message2'] = __('Warning: Both php.ini settings \'safe_mode\' and \'open_basedir\' will prevent the cURL library from following redirects in URLs.', 'powerpress');
        } else {
            if (ini_get('safe_mode')) {
                $powerpress_diags['detecting_media']['warning'] = true;
                $powerpress_diags['detecting_media']['message2'] = __('Warning: The php.ini setting \'safe_mode\' will prevent the cURL library from following redirects in URLs.', 'powerpress');
            } else {
                if (ini_get('open_basedir')) {
                    $powerpress_diags['detecting_media']['warning'] = true;
                    $powerpress_diags['detecting_media']['message2'] = __('Warning: The php.ini setting \'open_basedir\' will prevent the cURL library from following redirects in URLs.', 'powerpress');
                }
            }
        }
    } else {
        if ($powerpress_diags['detecting_media']['allow_url_fopen']) {
            $powerpress_diags['detecting_media']['message'] = __('Your web server is configured with the php.ini setting \'allow_url_fopen\' enabled.', 'powerpress');
        } else {
            $powerpress_diags['detecting_media']['success'] = false;
            $powerpress_diags['detecting_media']['message'] = __('Your server must either have the php.ini setting \'allow_url_fopen\' enabled or have the PHP cURL library installed in order to detect media information.', 'powerpress');
        }
    }
    // Second, see if we can ping itunes, OpenSSL is required
    $powerpress_diags['pinging_itunes'] = array();
    $powerpress_diags['pinging_itunes']['success'] = true;
    $powerpress_diags['pinging_itunes']['openssl'] = extension_loaded('openssl');
    $powerpress_diags['pinging_itunes']['curl_ssl'] = false;
    if (function_exists('curl_version')) {
        $curl_info = curl_version();
        $powerpress_diags['pinging_itunes']['curl_ssl'] = $curl_info['features'] & CURL_VERSION_SSL;
    }
    // testing:
    //$powerpress_diags['pinging_itunes']['openssl'] = false;
    //$powerpress_diags['pinging_itunes']['curl_ssl'] = false;
    if ($powerpress_diags['detecting_media']['success'] == false) {
        $powerpress_diags['pinging_itunes']['success'] = false;
        $powerpress_diags['pinging_itunes']['message'] = __('The problem with \'Detecting Media Information\' above needs to be resolved for this test to continue.', 'powerpress');
    } else {
        if ($powerpress_diags['detecting_media']['curl'] && $powerpress_diags['pinging_itunes']['curl_ssl']) {
            $powerpress_diags['pinging_itunes']['message'] = __('Your web server supports secure HTTPS connections.', 'powerpress');
        } else {
            if ($powerpress_diags['detecting_media']['curl']) {
                $powerpress_diags['pinging_itunes']['success'] = false;
                $powerpress_diags['pinging_itunes']['message'] = __('Your web server\'s cURL library does not support secure HTTPS connections.', 'powerpress');
            } else {
                if ($powerpress_diags['pinging_itunes']['openssl'] && $powerpress_diags['detecting_media']['allow_url_fopen']) {
                    $powerpress_diags['pinging_itunes']['message'] = __('Your web server supports secure HTTPS connections.', 'powerpress');
                } else {
                    $powerpress_diags['pinging_itunes']['success'] = false;
                    $powerpress_diags['pinging_itunes']['message'] = __('Pinging iTunes requires the PHP OpenSSL library to be installed.', 'powerpress');
                }
            }
        }
    }
    // Third, see if the uploads/powerpress folder is writable
    $UploadArray = wp_upload_dir();
    $powerpress_diags['uploading_artwork'] = array();
    $powerpress_diags['uploading_artwork']['success'] = false;
    $powerpress_diags['uploading_artwork']['file_uploads'] = ini_get('file_uploads');
    $powerpress_diags['uploading_artwork']['writable'] = false;
    $powerpress_diags['uploading_artwork']['upload_path'] = '';
    $powerpress_diags['uploading_artwork']['message'] = '';
    // Testing:
    //$UploadArray['error'] = 'WordPres broke';
    //$powerpress_diags['uploading_artwork']['file_uploads'] = false;
    //$UploadArray['error'] = true;
    if ($powerpress_diags['uploading_artwork']['file_uploads'] == false) {
        $powerpress_diags['uploading_artwork']['message'] = __('Your server requires the php.ini setting \'file_uploads\' enabled in order to upload podcast artwork.', 'powerpress');
    } else {
        if ($UploadArray['error'] === false) {
            $powerpress_diags['uploading_artwork']['upload_path'] = $UploadArray['basedir'] . '/powerpress/';
            if (!is_dir($powerpress_diags['uploading_artwork']['upload_path']) && !wp_mkdir_p(rtrim($powerpress_diags['uploading_artwork']['upload_path'], '/'))) {
                $powerpress_diags['uploading_artwork']['message'] = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?', 'powerpress'), rtrim($powerpress_diags['uploading_artwork']['upload_path'], '/'));
            } else {
                $powerpress_diags['uploading_artwork']['writable'] = powerpressadmin_diagnostics_is_writable($powerpress_diags['uploading_artwork']['upload_path']);
                if ($powerpress_diags['uploading_artwork']['writable'] == false) {
                    $powerpress_diags['uploading_artwork']['message'] = sprintf(__('PowerPress is unable to write to the %s directory.', 'powerpress'), $powerpress_diags['uploading_artwork']['upload_path']);
                } else {
                    $powerpress_diags['uploading_artwork']['success'] = true;
                    $powerpress_diags['uploading_artwork']['message'] = __('You are able to upload and save artwork images for your podcasts.', 'powerpress');
                }
            }
        } else {
            if (strlen($UploadArray['error']) > 2) {
                $powerpress_diags['uploading_artwork']['message'] = $UploadArray['error'];
            } else {
                $powerpress_diags['uploading_artwork']['message'] = __('An error occurred obtaining the uploads directory from WordPress.', 'powerpress');
            }
        }
    }
    // Fourth, see if we have enough memory and we're running an appropriate version of PHP
    $powerpress_diags['system_info'] = array();
    $powerpress_diags['system_info']['warning'] = false;
    $powerpress_diags['system_info']['success'] = true;
    $powerpress_diags['system_info']['php_version'] = phpversion();
    $powerpress_diags['system_info']['php_cgi'] = function_exists('php_sapi_name') && preg_match('/cgi/i', php_sapi_name()) ? true : false;
    $powerpress_diags['system_info']['memory_limit'] = (int) ini_get('memory_limit');
    $powerpress_diags['system_info']['temp_directory'] = get_temp_dir();
    // Function available since WP2.5+
    // testing:
    //$powerpress_diags['system_info']['memory_limit'] = -1;
    //$powerpress_diags['system_info']['memory_limit'] = 0;
    //$powerpress_diags['system_info']['memory_limit'] = 16;
    if ($powerpress_diags['system_info']['memory_limit'] == 0) {
        if (version_compare($powerpress_diags['system_info']['php_version'], '5.2') > 0) {
            $powerpress_diags['system_info']['memory_limit'] = 128;
        } else {
            if (version_compare($powerpress_diags['system_info']['php_version'], '5.2') == 0) {
                $powerpress_diags['system_info']['memory_limit'] = 16;
            } else {
                $powerpress_diags['system_info']['memory_limit'] = 8;
            }
        }
    }
    $powerpress_diags['system_info']['memory_used'] = 0;
    if (version_compare($powerpress_diags['system_info']['php_version'], '5.4') > -1) {
        $powerpress_diags['system_info']['message'] = sprintf(__('Your version of PHP (%s) is OK!', 'powerpress'), $powerpress_diags['system_info']['php_version']);
    } else {
        if (version_compare($powerpress_diags['system_info']['php_version'], '5.3') > -1) {
            $powerpress_diags['system_info']['message'] = sprintf(__('Your version of PHP (%s) is OK, though PHP 5.4 or newer is recommended.', 'powerpress'), $powerpress_diags['system_info']['php_version']);
        } else {
            $powerpress_diags['system_info']['message'] = sprintf(__('Your version of PHP (%s) will work, but PHP 5.4 or newer is recommended.', 'powerpress'), $powerpress_diags['system_info']['php_version']);
        }
    }
    $used = 0;
    $total = $powerpress_diags['system_info']['memory_limit'];
    if ($total == -1) {
        $powerpress_diags['system_info']['message2'] = __('Your scripts have no limit to the amount of memory they can use.', 'powerpress');
        $used = function_exists('memory_get_peak_usage') ? memory_get_peak_usage() : (function_exists('memory_get_usage') ? memory_get_usage() : 0);
        if ($used) {
            $powerpress_diags['system_info']['memory_used'] = round($used / 1024 / 1024, 2);
        }
    } else {
        if (function_exists('memory_get_peak_usage')) {
            $used = round(memory_get_peak_usage() / 1024 / 1024, 2);
            $powerpress_diags['system_info']['memory_used'] = $used;
            $percent = $used / $total * 100;
            $powerpress_diags['system_info']['message2'] = sprintf(__('You are using %d%% (%.01fM of %.01dM) of available memory.', 'powerpress'), $percent, $used, $total);
        } else {
            if (function_exists('memory_get_usage')) {
                $used = round(memory_get_usage() / 1024 / 1024, 2);
                $powerpress_diags['system_info']['memory_used'] = $used;
                $percent = $used / $total * 100;
                $powerpress_diags['system_info']['message2'] = sprintf(__('You are using %d%% (%.01fM of %dM) of available memory. Versions of PHP 5.2 or newer will give you a more accurate total of memory usage.', 'powerpress'), $percent, $used, $total);
            } else {
                $powerpress_diags['system_info']['message2'] = sprintf(__('Your scripts have a total of %dM.', 'powerpress'), $total);
            }
        }
    }
    if ($total > 0 && $used + 4 > $total) {
        $powerpress_diags['system_info']['warning'] = true;
        $powerpress_diags['system_info']['message2'] = __('Warning:', 'powerpress') . ' ' . $powerpress_diags['system_info']['message2'];
        $powerpress_diags['system_info']['message2'] .= ' ';
        $powerpress_diags['system_info']['message2'] .= sprintf(__('We recommend that you have at least %dM (4M more that what is currently used) or more memory to accomodate all of your installed plugins.', 'powerpress'), ceil($used) + 4);
    }
    if (empty($powerpress_diags['system_info']['temp_directory'])) {
        $powerpress_diags['system_info']['success'] = false;
        $powerpress_diags['system_info']['message3'] = __('Error:', 'powerpress') . ' ' . __('No temporary directory available.', 'powerpress');
    } else {
        if (is_dir($powerpress_diags['system_info']['temp_directory']) && is_writable($powerpress_diags['system_info']['temp_directory'])) {
            $powerpress_diags['system_info']['message3'] = sprintf(__('Temporary directory %s is writable.', 'powerpress'), $powerpress_diags['system_info']['temp_directory']);
        } else {
            $powerpress_diags['system_info']['success'] = false;
            $powerpress_diags['system_info']['message3'] = __('Error:', 'powerpress') . ' ' . sprintf(__('Temporary directory %s is not writable.', 'powerpress'), $powerpress_diags['system_info']['temp_directory']);
        }
    }
    if (empty($powerpress_diags['system_info']['php_cgi'])) {
        $powerpress_diags['system_info']['message4'] = '';
    } else {
        $powerpress_diags['system_info']['message4'] = __('Warning:', 'powerpress') . ' ' . __('PHP running in CGI mode.', 'powerpress');
    }
    if (isset($_GET['Email']) && strlen($_GET['Email']) > 4) {
        check_admin_referer('powerpress-diagnostics');
        $email = $_GET['Email'];
        powerpressadmin_diagnostics_email($email);
        powerpress_page_message_add_notice(sprintf(__('Diagnostic results sent to %s.', 'powerpress'), $email));
    }
}
Esempio n. 6
0
    public function _admin_ajax_configure_services($blog_id, $Step = 1, $Settings = false, $Programs = false, $Password = '')
    {
        if (!current_user_can(POWERPRESS_CAPABILITY_MANAGE_OPTIONS)) {
            powerpress_page_message_add_notice(__('You do not have sufficient permission to manage options.', 'powerpress-multisite'));
            powerpress_page_message_print();
            return;
        }
        if (!ini_get('allow_url_fopen') && !function_exists('curl_init')) {
            powerpress_page_message_add_notice(__('Your server must either have the php.ini setting \'allow_url_fopen\' enabled or have the PHP cURL library installed in order to continue.', 'powerpress-multisite'));
            powerpress_page_message_print();
            return;
        }
        if (empty($blog_id)) {
            powerpress_page_message_add_notice(__('No site specified.', 'powerpress-multisite'));
            powerpress_page_message_print();
            return;
        }
        if (!$Settings) {
            $Settings = get_blog_option($blog_id, 'powerpress_general');
        }
        if (empty($Settings['blubrry_username'])) {
            $Settings['blubrry_username'] = '';
        }
        if (empty($Settings['blubrry_hosting']) || $Settings['blubrry_hosting'] === 'false') {
            $Settings['blubrry_hosting'] = false;
        }
        if (empty($Settings['blubrry_program_keyword'])) {
            $Settings['blubrry_program_keyword'] = '';
        }
        if (empty($Programs)) {
            $Programs = array();
        }
        powerpress_page_message_print();
        ?>
<form action="<?php 
        echo network_admin_url('sites.php?action=powerpress-multisite');
        ?>
" enctype="multipart/form-data" method="post">
<?php 
        wp_nonce_field('powerpress-multisite-ajax-account');
        ?>
<input type="hidden" name="action" value="powerpress-jquery-account-save" />
<input type="hidden" name="ajax" value="1" />
<input type="hidden" name="blog_id" value="<?php 
        echo $blog_id;
        ?>
" />
<div id="accountinfo">
	<h2><?php 
        echo __('Blubrry Services Integration', 'powerpress');
        ?>
</h2>
<?php 
        if ($Step == 1) {
            ?>
	<p>
		<label for="blubrry_username"><?php 
            echo __('Blubrry User Name (Email)', 'powerpress');
            ?>
</label>
		<input type="text" id="blubrry_username" name="Settings[blubrry_username]" value="<?php 
            echo $Settings['blubrry_username'];
            ?>
" />
	</p>
	<p id="password_row">
		<label for="password_password"><?php 
            echo __('Blubrry Password', 'powerpress');
            ?>
</label>
		<input type="password" id="password_password" name="Password" value="" />
	</p>
<?php 
        } else {
            if ($Step == 3) {
                ?>
<p style="text-align: center;"><strong><?php 
                echo __('Settings Saved Successfully!', 'powerpress');
                ?>
</strong></p>
<p style="text-align: center;">
	<a href="<?php 
                echo network_admin_url("sites.php?page=powerpress-multisite&amp;={$blog_idW}");
                ?>
" onclick="self.parent.tb_remove(); return false;" target="_top"><?php 
                echo __('Close', 'powerpress');
                ?>
</a>
</p>
<script type="text/javascript"><!--

jQuery(document).ready(function($) {
	// Upload loading, check the parent window for #blubrry_stats_settings div
	if( jQuery('#blubrry_stats_settings',parent.document).length )
	{
		jQuery('#blubrry_stats_settings',parent.document).html('');
	}
});

// --></script>
<?php 
            } else {
                ?>
	<input type="hidden" name="Settings[blubrry_username]" value="<?php 
                echo htmlspecialchars($Settings['blubrry_username']);
                ?>
" />
	<input type="hidden" name="Password" value="<?php 
                echo htmlspecialchars($Password);
                ?>
" />
	<!-- <input type="hidden" name="Settings[blubrry_hosting]" value="<?php 
                echo $Settings['blubrry_hosting'];
                ?>
" /> -->
	<p>
		<label for="blubrry_program_keyword"><?php 
                echo __('Select Blubrry Program', 'powerpress');
                ?>
</label>
<select id="blubrry_program_keyword" name="Settings[blubrry_program_keyword]">
<option value=""><?php 
                echo __('Select Program', 'powerpress');
                ?>
</option>
<?php 
                while (list($value, $desc) = each($Programs)) {
                    echo "\t<option value=\"{$value}\"" . ($Settings['blubrry_program_keyword'] == $value ? ' selected' : '') . ">{$desc}</option>\n";
                }
                ?>
</select>
	</p>
<?php 
            }
        }
        if ($Step != 3) {
            ?>
	<p>
		<input type="submit" name="Save" value="<?php 
            echo __('Save', 'powerpress');
            ?>
" />
		<input type="button" name="Cancel" value="<?php 
            echo __('Cancel', 'powerpress');
            ?>
" onclick="self.parent.tb_remove();" />
		<input type="submit" name="Remove" value="Remove" style="float: right;" onclick="return confirm('<?php 
            echo __('Remove Blubrry Services Integration, are you sure?', 'powerpress');
            ?>
');" />
	</p>
<?php 
        }
        ?>
</div>
</form>
<?php 
    }
function powerpress_admin_queue_files($extensions = array())
{
    $add_urls = '';
    $extensions_preg_match = '';
    while (list($extension, $null) = each($extensions)) {
        if ($extension == '*') {
            $extensions_preg_match = '.*';
            break;
            // Lets just match everything
        }
        if (!empty($extensions_preg_match)) {
            $extensions_preg_match .= '|';
        }
        $extensions_preg_match .= $extension;
    }
    if (empty($extensions_preg_match)) {
        // No files specified, no error message needed
        return;
    }
    $files = powerpress_admin_migrate_get_files(true, true);
    // Keep the URLs clean, excude blubrry media URLs
    $QueuedFiles = array();
    $Update = false;
    $update_option = true;
    $PastResults = get_option('powerpress_migrate_queued');
    if ($PastResults == false) {
        $update_option = false;
    }
    if (is_array($PastResults)) {
        $QueuedFiles = $PastResults;
    }
    $AddedCount = 0;
    $AlreadyAddedCount = 0;
    while (list($meta_id, $row) = each($files)) {
        $parts = pathinfo($row['src_url']);
        if (preg_match('/(' . $extensions_preg_match . ')/i', $parts['extension'])) {
            if (!empty($QueuedFiles[$meta_id]) && $QueuedFiles[$meta_id] == $row['src_url']) {
                $AlreadyAddedCount++;
                continue;
                // Already queued
            }
            $QueuedFiles[$meta_id] = $row['src_url'];
            if (!empty($add_urls)) {
                $add_urls .= "\n";
            }
            $add_urls .= $row['src_url'];
            $Update = true;
            $AddedCount++;
        }
    }
    if ($Update) {
        // Make API CALL to add files to queue here!
        $UpdateResults = powepress_admin_migrate_add_urls($add_urls);
        if (empty($UpdateResults)) {
            $Update = false;
        }
    }
    if ($Update) {
        // IF the API call was successful, lets save the list locally
        if ($update_option) {
            update_option('powerpress_migrate_queued', $QueuedFiles);
        } else {
            add_option('powerpress_migrate_queued', $QueuedFiles, '', 'no');
        }
        powerpress_page_message_add_notice(sprintf(__('%d media files added to migration queue.', 'powerpress'), $AddedCount));
    }
    if ($AlreadyAddedCount > 0) {
        powerpress_page_message_add_notice(sprintf(__('%d media files were already added to migration queue.', 'powerpress'), $AlreadyAddedCount));
    }
}
function powerpressadmin_find_replace_process()
{
    $wp_remote_options = array();
    $wp_remote_options['user-agent'] = 'Blubrry PowerPress/' . POWERPRESS_VERSION;
    $wp_remote_options['httpversion'] = '1.1';
    global $g_FindReplaceResults;
    if (isset($_POST['FindReplace'])) {
        $FindReplace = $_POST['FindReplace'];
        $FindReplace['step'] = intval($FindReplace['step']);
        if ($FindReplace['step'] == 2 || $FindReplace['step'] == 3) {
            $success_count = 0;
            $failed_count = 0;
            $FoundArray = powerpressadmin_find_replace_get_enclosures($FindReplace['find_string']);
            while (list($meta_id, $row) = each($FoundArray)) {
                // powerpress_get_post_meta
                $meta_value = get_post_meta($row['post_id'], $row['meta_key'], true);
                $parts = explode("\n", $meta_value, 2);
                $other_meta_data = false;
                if (count($parts) == 2) {
                    list($old_url, $other_meta_data) = $parts;
                } else {
                    $old_url = trim($meta_value);
                }
                $old_url = trim($old_url);
                //echo  $old_url;
                $g_FindReplaceResults[$meta_id] = $row;
                $g_FindReplaceResults[$meta_id]['old_url'] = $old_url;
                $g_FindReplaceResults[$meta_id]['find_readable'] = str_replace($FindReplace['find_string'], sprintf('<span class="find_string strong">%s</span>', esc_attr($FindReplace['find_string'])), esc_attr($old_url));
                $g_FindReplaceResults[$meta_id]['replace_readable'] = str_replace($FindReplace['find_string'], sprintf('<span class="replace_string strong">%s</span>', esc_attr($FindReplace['replace_string'])), esc_attr($old_url));
                $new_url = str_replace($FindReplace['find_string'], $FindReplace['replace_string'], $old_url);
                $g_FindReplaceResults[$meta_id]['new_url'] = $new_url;
                if ($FindReplace['step'] == 3 && $FindReplace['find_string'] != '') {
                    $good = true;
                    if (!empty($FindReplace['verify'])) {
                        $response = wp_remote_head($new_url, $wp_remote_options);
                        // Redirect 1
                        if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) {
                            $headers = wp_remote_retrieve_headers($response);
                            $response = wp_remote_head($headers['location'], $wp_remote_options);
                        }
                        // Redirect 2
                        if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) {
                            $headers = wp_remote_retrieve_headers($response);
                            $response = wp_remote_head($headers['location'], $wp_remote_options);
                        }
                        // Redirect 3
                        if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) {
                            $headers = wp_remote_retrieve_headers($response);
                            $response = wp_remote_head($headers['location'], $wp_remote_options);
                        }
                        // Redirect 4
                        if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) {
                            $headers = wp_remote_retrieve_headers($response);
                            $response = wp_remote_head($headers['location'], $wp_remote_options);
                        }
                        //$headers = wp_remote_retrieve_headers( $response );
                        //$response = @wp_remote_head( $new_url, $wp_remote_options );
                        if (is_wp_error($response)) {
                            $g_FindReplaceResults[$meta_id]['error'] = $response->get_error_message();
                            $good = false;
                        }
                        if ($good && isset($response['response']['code']) && ($response['response']['code'] < 200 || $response['response']['code'] > 203)) {
                            $g_FindReplaceResults[$meta_id]['error'] = 'Error, HTTP ' . $response['response']['code'];
                            $good = false;
                        }
                    }
                    if ($good) {
                        $DataUpdated = $new_url;
                        if ($other_meta_data) {
                            $DataUpdated .= "\n" . $other_meta_data;
                        }
                        if (update_post_meta($row['post_id'], $row['meta_key'], $DataUpdated)) {
                            $success_count++;
                        } else {
                            $good = false;
                        }
                    }
                    if (!$good) {
                        $failed_count++;
                    }
                    $g_FindReplaceResults[$meta_id]['success'] = $good;
                }
            }
            if ($FindReplace['step'] == 3) {
                if ($success_count > 0) {
                    powerpress_page_message_add_notice(sprintf(__('%d URLs updated successfully.', 'powerpress'), $success_count));
                }
                if ($failed_count > 0) {
                    powerpress_page_message_add_error(sprintf(__('%d URLs were not updated.', 'powerpress'), $failed_count));
                } else {
                    if ($FindReplace['find_string'] == '') {
                        powerpress_page_message_add_notice(__('Nothing specified to find.', 'powerpress'));
                    }
                }
            }
        }
    }
    powerpress_page_message_add_notice(__('WARNING: Please backup your database before proceeding. Blubrry PowerPress is not responsible for any lost or damaged data resulting from this Find and Replace tool.', 'powerpress'));
}
Esempio n. 9
0
function powerpress_admin_init()
{
    global $wp_rewrite;
    add_thickbox();
    // we use the thckbox for some settings
    wp_enqueue_script('jquery');
    wp_enqueue_script('jquery-ui-core');
    // Now including the library at Google
    wp_enqueue_script('jquery-ui-tabs');
    // Powerpress page
    if (isset($_GET['page']) && strstr($_GET['page'], 'powerpress') !== false) {
        //wp_enqueue_script('jquery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js');
        if (preg_match('/powerpressadmin_(mobile|audio|video)player/', $_GET['page'])) {
            wp_enqueue_style('wp-color-picker');
        }
        if (preg_match('/powerpressadmin_migrate/', $_GET['page'])) {
            wp_enqueue_script('media-upload');
            // For the readjustment of the thickbox only
        }
    }
    if (function_exists('powerpress_admin_jquery_init')) {
        powerpress_admin_jquery_init();
    }
    if (!current_user_can(POWERPRESS_CAPABILITY_MANAGE_OPTIONS)) {
        powerpress_page_message_add_error(__('You do not have sufficient permission to manage options.', 'powerpress'));
        return;
    }
    // Check for other podcasting plugin
    if (defined('PODPRESS_VERSION') || isset($GLOBALS['podcasting_player_id']) || isset($GLOBALS['podcast_channel_active']) || defined('PODCASTING_VERSION')) {
        powerpress_page_message_add_error(__('Another podcasting plugin has been detected, PowerPress is currently disabled.', 'powerpress'));
    }
    global $wp_version;
    $VersionDiff = version_compare($wp_version, 3.6);
    if ($VersionDiff < 0) {
        powerpress_page_message_add_error(__('Blubrry PowerPress requires Wordpress version 3.6 or greater.', 'powerpress'));
    }
    // Check for incompatible plugins:
    if (isset($GLOBALS['objWPOSFLV']) && is_object($GLOBALS['objWPOSFLV'])) {
        powerpress_page_message_add_error(__('The WP OS FLV plugin is not compatible with Blubrry PowerPress.', 'powerpress'));
    }
    // Security step, we must be in a powerpress/* page...
    if (isset($_GET['page']) && strstr($_GET['page'], 'powerpress/') !== false) {
        // Save settings here
        if (isset($_POST['Feed']) || isset($_POST['General'])) {
            check_admin_referer('powerpress-edit');
            $upload_path = false;
            $upload_url = false;
            $UploadArray = wp_upload_dir();
            if (false === $UploadArray['error']) {
                $upload_path = $UploadArray['basedir'] . '/powerpress/';
                $upload_url = $UploadArray['baseurl'] . '/powerpress/';
            }
            // Save the posted value in the database
            $Feed = isset($_POST['Feed']) ? $_POST['Feed'] : false;
            $General = isset($_POST['General']) ? $_POST['General'] : false;
            $FeedSlug = isset($_POST['feed_slug']) ? esc_attr($_POST['feed_slug']) : false;
            $Category = isset($_POST['cat']) ? intval($_POST['cat']) : false;
            $term_taxonomy_id = isset($_POST['ttid']) ? intval($_POST['ttid']) : false;
            $podcast_post_type = isset($_POST['podcast_post_type']) ? esc_attr($_POST['podcast_post_type']) : false;
            // New iTunes image
            if (!empty($_POST['itunes_image_checkbox'])) {
                $filename = str_replace(" ", "_", basename($_FILES['itunes_image_file']['name']));
                $temp = $_FILES['itunes_image_file']['tmp_name'];
                if (file_exists($upload_path . $filename)) {
                    $filenameParts = pathinfo($filename);
                    if (!empty($filenameParts['extension'])) {
                        do {
                            $filename_no_ext = substr($filenameParts['basename'], 0, (strlen($filenameParts['extension']) + 1) * -1);
                            $filename = sprintf('%s-%03d.%s', $filename_no_ext, rand(0, 999), $filenameParts['extension']);
                        } while (file_exists($upload_path . $filename));
                    }
                }
                // Check the image...
                if (file_exists($temp)) {
                    $ImageData = @getimagesize($temp);
                    $rgb = true;
                    // We assume it is RGB
                    if (defined('POWERPRESS_IMAGICK') && POWERPRESS_IMAGICK) {
                        if ($ImageData[2] == IMAGETYPE_PNG && extension_loaded('imagick')) {
                            $image = new Imagick($temp);
                            if ($image->getImageColorspace() != imagick::COLORSPACE_RGB) {
                                $rgb = false;
                            }
                        }
                    }
                    if (empty($ImageData['channels'])) {
                        $ImageData['channels'] = 3;
                    }
                    // Assume it's ok if we cannot detect it.
                    if ($ImageData) {
                        if ($rgb && ($ImageData[2] == IMAGETYPE_JPEG || $ImageData[2] == IMAGETYPE_PNG) && $ImageData[0] == $ImageData[1] && $ImageData[0] >= 1400 && $ImageData[0] <= 3000 && $ImageData['channels'] == 3) {
                            if (!move_uploaded_file($temp, $upload_path . $filename)) {
                                powerpress_page_message_add_error(__('Error saving iTunes image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('An error occurred saving the iTunes image on the server.', 'powerprss') . ' ' . sprintf(__('Local folder: %s; File name: %s', 'powerpress'), $upload_path, $filename));
                            } else {
                                $Feed['itunes_image'] = $upload_url . $filename;
                                if (!empty($_POST['itunes_image_checkbox_as_rss'])) {
                                    $Feed['rss2_image'] = $upload_url . $filename;
                                }
                                //if( $ImageData[0] < 1400 || $ImageData[1] < 1400 )
                                //{
                                //	powerpress_page_message_add_error( __('iTunes image warning', 'powerpress')  .':	'. htmlspecialchars($_FILES['itunes_image_file']['name']) . __(' is', 'powerpress') .' '. $ImageData[0] .' x '.$ImageData[0]   .' - '. __('Image must be square 1400 x 1400 pixels or larger.', 'powerprss') );
                                //}
                            }
                        } else {
                            if ($ImageData['channels'] != 3 || $rgb == false) {
                                powerpress_page_message_add_error(__('Invalid iTunes image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('Image must be in RGB color space (CMYK is not supported).', 'powerprss'));
                            } else {
                                if ($ImageData[0] != $ImageData[1]) {
                                    powerpress_page_message_add_error(__('Invalid iTunes image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('Image must be square, 1400 x 1400 is the required minimum size.', 'powerprss'));
                                } else {
                                    if ($ImageData[0] != $ImageData[1] || $ImageData[0] < 1400) {
                                        powerpress_page_message_add_error(__('Invalid iTunes image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('Image is too small, 1400 x 1400 is the required minimum size.', 'powerprss'));
                                    } else {
                                        if ($ImageData[0] != $ImageData[1] || $ImageData[0] > 3000) {
                                            powerpress_page_message_add_error(__('Invalid iTunes image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('Image is too large, 3000 x 3000 is the maximum size allowed.', 'powerprss'));
                                        } else {
                                            powerpress_page_message_add_error(__('Invalid iTunes image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']));
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        powerpress_page_message_add_error(__('Invalid iTunes image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']));
                    }
                }
            }
            // New RSS2 image
            if (!empty($_POST['rss2_image_checkbox'])) {
                $filename = str_replace(" ", "_", basename($_FILES['rss2_image_file']['name']));
                $temp = $_FILES['rss2_image_file']['tmp_name'];
                if (file_exists($upload_path . $filename)) {
                    $filenameParts = pathinfo($filename);
                    if (!empty($filenameParts['basename']) && !empty($filenameParts['extension'])) {
                        do {
                            $filename_no_ext = substr($filenameParts['basename'], 0, (strlen($filenameParts['extension']) + 1) * -1);
                            $filename = sprintf('%s-%03d.%s', $filename_no_ext, rand(0, 999), $filenameParts['extension']);
                        } while (file_exists($upload_path . $filename));
                    }
                }
                if (@getimagesize($temp)) {
                    if (!move_uploaded_file($temp, $upload_path . $filename)) {
                        powerpress_page_message_add_error(__('Error saving RSS image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('An error occurred saving the RSS image on the server.', 'powerprss') . ' ' . sprintf(__('Local folder: %s; File name: %s', 'powerpress'), $upload_path, $filename));
                    } else {
                        $Feed['rss2_image'] = $upload_url . $filename;
                    }
                } else {
                    powerpress_page_message_add_error(__('Invalid RSS image', 'powerpress') . ': ' . htmlspecialchars($_FILES['rss2_image_file']['name']));
                }
            }
            // New mp3 coverart image
            if (!empty($_POST['coverart_image_checkbox'])) {
                $filename = str_replace(" ", "_", basename($_FILES['coverart_image_file']['name']));
                $temp = $_FILES['coverart_image_file']['tmp_name'];
                if (file_exists($upload_path . $filename)) {
                    $filenameParts = pathinfo($filename);
                    do {
                        $filename_no_ext = substr($filenameParts['basename'], 0, (strlen($filenameParts['extension']) + 1) * -1);
                        $filename = sprintf('%s-%03d.%s', $filename_no_ext, rand(0, 999), $filenameParts['extension']);
                    } while (file_exists($upload_path . $filename));
                }
                if (@getimagesize($temp)) {
                    if (!move_uploaded_file($temp, $upload_path . $filename)) {
                        powerpress_page_message_add_error(__('Error saving Coverart image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('An error occurred saving the coverart image on the server.', 'powerprss') . ' ' . sprintf(__('Local folder: %s; File name: %s', 'powerpress'), $upload_path, $filename));
                    } else {
                        $_POST['TagValues']['tag_coverart'] = $upload_url . $filename;
                        $General['tag_coverart'] = $upload_url . $filename;
                    }
                } else {
                    powerpress_page_message_add_error(__('Invalid Coverat image', 'powerpress') . ': ' . htmlspecialchars($_FILES['coverart_image_file']['name']));
                }
            }
            // New poster image
            if (!empty($_POST['poster_image_checkbox'])) {
                $filename = str_replace(" ", "_", basename($_FILES['poster_image_file']['name']));
                $temp = $_FILES['poster_image_file']['tmp_name'];
                if (file_exists($upload_path . $filename)) {
                    $filenameParts = pathinfo($filename);
                    do {
                        $filename_no_ext = substr($filenameParts['basename'], 0, (strlen($filenameParts['extension']) + 1) * -1);
                        $filename = sprintf('%s-%03d.%s', $filename_no_ext, rand(0, 999), $filenameParts['extension']);
                    } while (file_exists($upload_path . $filename));
                }
                if (@getimagesize($temp)) {
                    if (!move_uploaded_file($temp, $upload_path . $filename)) {
                        powerpress_page_message_add_error(__('Error saving Poster image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('An error occurred saving the poster image on the server.', 'powerprss') . ' ' . sprintf(__('Local folder: %s; File name: %s', 'powerpress'), $upload_path, $filename));
                    } else {
                        $General['poster_image'] = $upload_url . $filename;
                    }
                } else {
                    powerpress_page_message_add_error(__('Invalid poster image', 'powerpress') . ': ' . htmlspecialchars($_FILES['poster_image_file']['name']));
                }
            }
            // New audio play icon image
            if (!empty($_POST['audio_custom_play_button_checkbox'])) {
                $filename = str_replace(" ", "_", basename($_FILES['audio_custom_play_button_file']['name']));
                $temp = $_FILES['audio_custom_play_button_file']['tmp_name'];
                if (file_exists($upload_path . $filename)) {
                    $filenameParts = pathinfo($filename);
                    do {
                        $filename_no_ext = substr($filenameParts['basename'], 0, (strlen($filenameParts['extension']) + 1) * -1);
                        $filename = sprintf('%s-%03d.%s', $filename_no_ext, rand(0, 999), $filenameParts['extension']);
                    } while (file_exists($upload_path . $filename));
                }
                if (@getimagesize($temp)) {
                    if (!move_uploaded_file($temp, $upload_path . $filename)) {
                        powerpress_page_message_add_error(__('Error saving Play image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('An error occurred saving the play image on the server.', 'powerprss') . ' ' . sprintf(__('Local folder: %s; File name: %s', 'powerpress'), $upload_path, $filename));
                    } else {
                        $General['audio_custom_play_button'] = $upload_url . $filename;
                    }
                } else {
                    powerpress_page_message_add_error(__('Invalid play icon image', 'powerpress') . ': ' . htmlspecialchars($_FILES['audio_custom_play_button_file']['name']));
                }
            }
            // New video play icon image
            if (!empty($_POST['video_custom_play_button_checkbox'])) {
                $filename = str_replace(" ", "_", basename($_FILES['video_custom_play_button_file']['name']));
                $temp = $_FILES['video_custom_play_button_file']['tmp_name'];
                if (file_exists($upload_path . $filename)) {
                    $filenameParts = pathinfo($filename);
                    do {
                        $filename_no_ext = substr($filenameParts['basename'], 0, (strlen($filenameParts['extension']) + 1) * -1);
                        $filename = sprintf('%s-%03d.%s', $filename_no_ext, rand(0, 999), $filenameParts['extension']);
                    } while (file_exists($upload_path . $filename));
                }
                $imageInfo = @getimagesize($temp);
                if ($imageInfo && $imageInfo[0] == $imageInfo[1] && $imageInfo[0] == 60) {
                    if (!move_uploaded_file($temp, $upload_path . $filename)) {
                        powerpress_page_message_add_error(__('Error saving Video Play icon image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('An error occurred saving the Video Play icon image on the server.', 'powerprss') . ' ' . sprintf(__('Local folder: %s; File name: %s', 'powerpress'), $upload_path, $filename));
                    } else {
                        $General['video_custom_play_button'] = $upload_url . $filename;
                    }
                } else {
                    if ($imageInfo) {
                        powerpress_page_message_add_error(__('Invalid play icon image size', 'powerpress') . ': ' . htmlspecialchars($_FILES['video_custom_play_button_file']['name']));
                    } else {
                        powerpress_page_message_add_error(__('Invalid play icon image', 'powerpress') . ': ' . htmlspecialchars($_FILES['video_custom_play_button_file']['name']));
                    }
                }
            }
            if (isset($_POST['UpdateDisablePlayer'])) {
                $player_feed_slug = $_POST['UpdateDisablePlayer'];
                $General['disable_player'] = array();
                $GeneralPrev = get_option('powerpress_general');
                if (isset($GeneralPrev['disable_player'])) {
                    $General['disable_player'] = $GeneralPrev['disable_player'];
                }
                if (isset($_POST['DisablePlayerFor'])) {
                    $General['disable_player'][$player_feed_slug] = 1;
                } else {
                    unset($General['disable_player'][$player_feed_slug]);
                }
            }
            // Check to see if we need to update the feed title
            if ($FeedSlug && !$podcast_post_type) {
                $GeneralSettingsTemp = powerpress_get_settings('powerpress_general', false);
                if (!isset($GeneralSettingsTemp['custom_feeds'][$FeedSlug]) || $GeneralSettingsTemp['custom_feeds'][$FeedSlug] != $Feed['title']) {
                    if (!$General) {
                        $General = array();
                    }
                    if (!empty($GeneralSettingsTemp['custom_feeds'])) {
                        $General['custom_feeds'] = $GeneralSettingsTemp['custom_feeds'];
                    } else {
                        $General['custom_feeds'] = array();
                    }
                    $General['custom_feeds'][$FeedSlug] = $Feed['title'];
                }
            }
            // Update the settings in the database:
            if ($General) {
                if (!empty($_POST['action']) && $_POST['action'] == 'powerpress-save-settings') {
                    if (!isset($General['display_player_excerpt'])) {
                        // If we are modifying appearance settings but this option was not checked...
                        $General['display_player_excerpt'] = 0;
                    }
                    // Set it to zero.
                    //if( !isset($General['display_player_disable_mobile']) )
                    //	$General['display_player_disable_mobile'] = 0;
                    $General['disable_dashboard_stats'] = 0;
                    if (!empty($_POST['DisableStatsInDashboard'])) {
                        $General['disable_dashboard_stats'] = 1;
                    }
                    if (!isset($General['disable_dashboard_news'])) {
                        $General['disable_dashboard_news'] = 0;
                    }
                    if (!isset($General['episode_box_mode'])) {
                        // Default not set, 1 = no duration/file size, 2 = yes duration/file size (default if not set)
                        $General['episode_box_mode'] = 1;
                    }
                    // 1 = no duration/file size (unchecked)
                    if (!isset($General['episode_box_embed'])) {
                        $General['episode_box_embed'] = 0;
                    }
                    if (!isset($General['embed_replace_player'])) {
                        $General['embed_replace_player'] = 0;
                    }
                    if (!isset($General['episode_box_no_player'])) {
                        $General['episode_box_no_player'] = 0;
                    }
                    if (!isset($General['episode_box_no_links'])) {
                        $General['episode_box_no_links'] = 0;
                    }
                    if (!isset($General['episode_box_no_player_and_links'])) {
                        $General['episode_box_no_player_and_links'] = 0;
                    }
                    if (!isset($General['episode_box_cover_image'])) {
                        $General['episode_box_cover_image'] = 0;
                    }
                    if (!isset($General['episode_box_player_size'])) {
                        $General['episode_box_player_size'] = 0;
                    }
                    if (!isset($General['episode_box_subtitle'])) {
                        $General['episode_box_subtitle'] = 0;
                    }
                    if (!isset($General['episode_box_summary'])) {
                        $General['episode_box_summary'] = 0;
                    }
                    if (!isset($General['episode_box_author'])) {
                        $General['episode_box_author'] = 0;
                    }
                    if (!isset($General['episode_box_explicit'])) {
                        $General['episode_box_explicit'] = 0;
                    }
                    if (!isset($General['episode_box_closed_captioned'])) {
                        $General['episode_box_closed_captioned'] = 0;
                    }
                    if (!isset($General['episode_box_itunes_image'])) {
                        $General['episode_box_itunes_image'] = 0;
                    }
                    if (!isset($General['episode_box_order'])) {
                        $General['episode_box_order'] = 0;
                    }
                    if (!isset($General['episode_box_feature_in_itunes'])) {
                        $General['episode_box_feature_in_itunes'] = 0;
                    } else {
                        $General['episode_box_order'] = 0;
                    }
                    if (!isset($General['allow_feed_comments'])) {
                        $General['allow_feed_comments'] = 0;
                    }
                    if (!isset($General['feed_links'])) {
                        $General['feed_links'] = 0;
                    }
                    // Advanced Features
                    if (!isset($General['player_options'])) {
                        $General['player_options'] = 0;
                    }
                    if (!isset($General['cat_casting'])) {
                        $General['cat_casting'] = 0;
                    }
                    if (!isset($General['channels'])) {
                        $General['channels'] = 0;
                    }
                    if (!isset($General['taxonomy_podcasting'])) {
                        $General['taxonomy_podcasting'] = 0;
                    }
                    if (!isset($General['posttype_podcasting'])) {
                        $General['posttype_podcasting'] = 0;
                    }
                    if (!isset($General['playlist_player'])) {
                        $General['playlist_player'] = 0;
                    }
                    if (!isset($General['metamarks'])) {
                        $General['metamarks'] = 0;
                    }
                    // Media Presentation Settings
                    $PlayerSettings = array();
                    if (!empty($_POST['PlayerSettings'])) {
                        $PlayerSettings = $_POST['PlayerSettings'];
                    }
                    if (empty($PlayerSettings['display_pinw'])) {
                        $PlayerSettings['display_pinw'] = 0;
                    }
                    if (empty($PlayerSettings['display_media_player'])) {
                        $PlayerSettings['display_media_player'] = 0;
                    }
                    if (empty($PlayerSettings['display_pinw'])) {
                        $PlayerSettings['display_pinw'] = 0;
                    }
                    if (empty($PlayerSettings['display_media_player'])) {
                        $PlayerSettings['display_media_player'] = 0;
                    }
                    $General['player_function'] = abs($PlayerSettings['display_pinw'] - $PlayerSettings['display_media_player']);
                    $General['podcast_link'] = 0;
                    if (!empty($PlayerSettings['display_download'])) {
                        $General['podcast_link'] = 1;
                        if (!empty($PlayerSettings['display_download_size'])) {
                            $General['podcast_link'] = 2;
                            if (!empty($PlayerSettings['display_download_duration'])) {
                                $General['podcast_link'] = 3;
                            }
                        }
                    }
                    if (!isset($General['podcast_embed'])) {
                        $General['podcast_embed'] = 0;
                    }
                    if (!isset($General['podcast_embed_in_feed'])) {
                        $General['podcast_embed_in_feed'] = 0;
                    }
                    if (!isset($General['m4a'])) {
                        $General['m4a'] = '';
                    }
                    if (!isset($General['new_window_nofactor'])) {
                        $General['new_window_nofactor'] = '';
                    }
                    if (!isset($General['subscribe_links'])) {
                        $General['subscribe_links'] = false;
                    }
                    if (!isset($General['subscribe_feature_email'])) {
                        $General['subscribe_feature_email'] = false;
                    }
                } else {
                    if (!empty($_POST['action']) && $_POST['action'] == 'powerpress-save-defaults') {
                        if (!isset($General['display_player_excerpt'])) {
                            // If we are modifying appearance settings but this option was not checked...
                            $General['display_player_excerpt'] = 0;
                        }
                        // Set it to zero.
                        $General['disable_dashboard_stats'] = 0;
                        if (!empty($_POST['DisableStatsInDashboard'])) {
                            $General['disable_dashboard_stats'] = 1;
                        }
                        // Advanced Mode options
                        if (!isset($General['cat_casting'])) {
                            $General['cat_casting'] = 0;
                        }
                        if (!isset($General['channels'])) {
                            $General['channels'] = 0;
                        }
                        if (!isset($General['taxonomy_podcasting'])) {
                            $General['taxonomy_podcasting'] = 0;
                        }
                        if (!isset($General['posttype_podcasting'])) {
                            $General['posttype_podcasting'] = 0;
                        }
                        if (!isset($General['metamarks'])) {
                            $General['metamarks'] = 0;
                        }
                    }
                }
                if (!empty($_POST['action']) && $_POST['action'] == 'powerpress-save-search') {
                    //$PowerPressSearch = $_POST['PowerPressSearch'];
                    $PowerPressSearchToggle = $_POST['PowerPressSearchToggle'];
                    if (empty($PowerPressSearchToggle['seo_feed_title'])) {
                        $General['seo_feed_title'] = 0;
                    }
                }
                if (!empty($_POST['action']) && $_POST['action'] == 'powerpress-save-tags') {
                    if (!isset($General['write_tags'])) {
                        // If we are modifying appearance settings but this option was not checked...
                        $General['write_tags'] = 0;
                    }
                    // Set it to zero.
                    $TagValues = $_POST['TagValues'];
                    $GeneralPosted = $_POST['General'];
                    if (!empty($_POST['PowerPressTrackNumber'])) {
                        update_option('powerpress_track_number', $_POST['PowerPressTrackNumber']);
                    }
                    // Set all the tag values...
                    while (list($key, $value) = each($GeneralPosted)) {
                        if (substr($key, 0, 4) == 'tag_') {
                            // Special case, we are uploading new coverart image
                            if (!empty($_POST['coverart_image_checkbox']) && $key == 'tag_coverart') {
                                continue;
                            }
                            // Specail case, the track is saved in a separate column in the database.
                            if ($key == 'tag_track') {
                                continue;
                            }
                            if (!empty($value)) {
                                $General[$key] = $TagValues[$key];
                            } else {
                                $General[$key] = '';
                            }
                        }
                    }
                    if (!empty($General['tag_coverart'])) {
                        $GeneralSettingsTemp = powerpress_get_settings('powerpress_general', false);
                        if (!empty($GeneralSettingsTemp['blubrry_hosting']) && $GeneralSettingsTemp['blubrry_hosting'] !== 'false') {
                            $json_data = false;
                            $api_url_array = powerpress_get_api_array();
                            while (list($index, $api_url) = each($api_url_array)) {
                                $req_url = sprintf('%s/media/%s/coverart.json?url=%s', rtrim($api_url, '/'), $GeneralSettingsTemp['blubrry_program_keyword'], urlencode($TagValues['tag_coverart']));
                                $req_url .= defined('POWERPRESS_BLUBRRY_API_QSA') ? '&' . POWERPRESS_BLUBRRY_API_QSA : '';
                                $json_data = powerpress_remote_fopen($req_url, $GeneralSettingsTemp['blubrry_auth']);
                                if ($json_data != false) {
                                    break;
                                }
                            }
                            // Lets try to cache the image onto Blubrry's Server...
                            $results = powerpress_json_decode($json_data);
                            if (is_array($results) && !isset($results['error'])) {
                                // Good!
                                powerpress_page_message_add_notice(__('Coverart image updated successfully.', 'powerpress'));
                            } else {
                                if (isset($results['error'])) {
                                    $error = __('Blubrry Hosting Error (updating coverart)', 'powerpress') . ': ' . $results['error'];
                                    powerpress_page_message_add_error($error);
                                } else {
                                    $error = __('An error occurred updating the coverart with your Blubrry Services Account.', 'powerpress');
                                    powerpress_page_message_add_error($error);
                                }
                            }
                        } else {
                            powerpress_page_message_add_error(__('Coverart Image was not uploaded to your Blubrry Services Account. It will NOT be added to your mp3s.', 'powerpress'));
                        }
                    }
                }
                if (!empty($_POST['action']) && $_POST['action'] == 'powerpress-save-videocommon') {
                    if (!isset($General['poster_play_image'])) {
                        $General['poster_play_image'] = 0;
                    }
                    if (!isset($General['poster_image_audio'])) {
                        $General['poster_image_audio'] = 0;
                    }
                }
                // Wordpress adds slashes to everything, but since we're storing everything serialized, lets remove them...
                $General = powerpress_stripslashes($General);
                powerpress_save_settings($General);
            }
            if ($Feed) {
                if (!isset($_POST['ProtectContent']) && isset($Feed['premium'])) {
                    $Feed['premium'] = false;
                }
                if (!isset($Feed['enhance_itunes_summary'])) {
                    $Feed['enhance_itunes_summary'] = false;
                }
                if (!isset($Feed['itunes_author_post'])) {
                    $Feed['itunes_author_post'] = false;
                }
                if (!isset($Feed['itunes_block'])) {
                    $Feed['itunes_block'] = false;
                }
                if (!isset($Feed['itunes_complete'])) {
                    $Feed['itunes_complete'] = false;
                }
                if (!isset($Feed['maximize_feed'])) {
                    $Feed['maximize_feed'] = false;
                }
                if (!isset($Feed['episode_itunes_image'])) {
                    $Feed['episode_itunes_image'] = false;
                }
                $Feed = powerpress_stripslashes($Feed);
                if ($Category) {
                    powerpress_save_settings($Feed, 'powerpress_cat_feed_' . $Category);
                } else {
                    if ($term_taxonomy_id) {
                        powerpress_save_settings($Feed, 'powerpress_taxonomy_' . $term_taxonomy_id);
                    } else {
                        if ($podcast_post_type) {
                            $PostTypeSettings = array();
                            $PostTypeSettings[$FeedSlug] = $Feed;
                            powerpress_save_settings($PostTypeSettings, 'powerpress_posttype_' . $podcast_post_type);
                            powerpress_rebuild_posttype_podcasting();
                        } else {
                            if ($FeedSlug == false && get_option('powerpress_feed_podcast')) {
                                // If the settings were moved to the podcast channels feature...
                                powerpress_save_settings($Feed, 'powerpress_feed_podcast');
                            }
                            // save a copy here if that is the case.
                            powerpress_save_settings($Feed, 'powerpress_feed' . ($FeedSlug ? '_' . $FeedSlug : ''));
                        }
                    }
                }
            }
            if (isset($_POST['EpisodeBoxBGColor'])) {
                $GeneralSettingsTemp = get_option('powerpress_general');
                $SaveEpisdoeBoxBGColor['episode_box_background_color'] = array();
                if (isset($GeneralSettingsTemp['episode_box_background_color'])) {
                    $SaveEpisdoeBoxBGColor['episode_box_background_color'] = $GeneralSettingsTemp['episode_box_background_color'];
                }
                //  copy previous settings
                list($feed_slug_temp, $background_color) = each($_POST['EpisodeBoxBGColor']);
                $SaveEpisdoeBoxBGColor['episode_box_background_color'][$feed_slug_temp] = $background_color;
                powerpress_save_settings($SaveEpisdoeBoxBGColor);
            }
            // Anytime settings are saved lets flush the rewrite rules
            $wp_rewrite->flush_rules();
            // Settings saved successfully
            if (!empty($_POST['action'])) {
                switch ($_POST['action']) {
                    case 'powerpress-save-settings':
                    case 'powerpress-save-defaults':
                        powerpress_page_message_add_notice(__('Blubrry PowerPress settings saved.', 'powerpress'));
                        break;
                    case 'powerpress-save-channel':
                        powerpress_page_message_add_notice(__('Blubrry PowerPress Channel settings saved.', 'powerpress'));
                        break;
                    case 'powerpress-save-category':
                        powerpress_page_message_add_notice(__('Blubrry PowerPress Category Podcasting  settings saved.', 'powerpress'));
                        break;
                    case 'powerpress-save-ttid':
                        powerpress_page_message_add_notice(__('Blubrry PowerPress Taxonomy Podcasting settings saved.', 'powerpress'));
                        break;
                    case 'powerpress-save-post_type':
                        powerpress_page_message_add_notice(__('Blubrry PowerPress Post Type Podcasting settings saved.', 'powerpress'));
                        break;
                    case 'powerpress-save-tags':
                        $General = get_option('powerpress_general');
                        if (empty($General['blubrry_hosting']) || $General['blubrry_hosting'] === 'false') {
                            powerpress_page_message_add_notice(__('ATTENTION: You must configure your Blubrry Services in the Blubrry PowerPress &gt; Basic Settings page in order to utilize this feature.', 'powerpress'));
                        } else {
                            powerpress_page_message_add_notice(__('Blubrry PowerPress MP3 Tag settings saved.', 'powerpress'));
                        }
                        break;
                    default:
                        powerpress_page_message_add_notice(__('Blubrry PowerPress settings saved.', 'powerpress'));
                        break;
                }
            }
        }
        // Handle POST actions...
        if (isset($_POST['action'])) {
            switch ($_POST['action']) {
                case 'powerpress-addfeed':
                    check_admin_referer('powerpress-add-feed');
                    $Settings = get_option('powerpress_general');
                    $key = sanitize_title($_POST['feed_slug']);
                    $value = $_POST['feed_name'];
                    $value = powerpress_stripslashes($value);
                    /*
                    					if( isset($Settings['custom_feeds'][ $key ]) && empty($_POST['overwrite']) )
                    					{
                    						powerpress_page_message_add_error( sprintf(__('Feed slug "%s" already exists.'), $key) );
                    					} else */
                    if ($key == '') {
                        powerpress_page_message_add_error(sprintf(__('Feed slug "%s" is not valid.', 'powerpress'), esc_html($_POST['feed_slug'])));
                    } else {
                        if (in_array($key, $wp_rewrite->feeds) && !isset($Settings['custom_feeds'][$key])) {
                            powerpress_page_message_add_error(sprintf(__('Feed slug "%s" is not available.', 'powerpress'), esc_html($key)));
                        } else {
                            $Settings['custom_feeds'][$key] = $value;
                            powerpress_save_settings($Settings);
                            add_feed($key, 'powerpress_do_podcast_feed');
                            // Before we flush the rewrite rules we need to add the new custom feed...
                            $wp_rewrite->flush_rules();
                            powerpress_page_message_add_notice(sprintf(__('Podcast Feed "%s" added, please configure your new feed now.', 'powerpress'), esc_html($value)));
                            $_GET['action'] = 'powerpress-editfeed';
                            $_GET['feed_slug'] = $key;
                        }
                    }
                    break;
                case 'powerpress-addtaxonomyfeed':
                    if (!empty($_POST['cancel'])) {
                        unset($_POST['taxonomy']);
                    }
                    if (empty($_POST['add_podcasting'])) {
                        break;
                    }
                    // We do not handle this situation
                case 'powerpress-addcategoryfeed':
                    check_admin_referer('powerpress-add-taxonomy-feed');
                    $taxonomy_type = isset($_POST['taxonomy']) ? $_POST['taxonomy'] : $_GET['taxonomy'];
                    $term_ID = intval(isset($_POST['term']) ? $_POST['term'] : $_GET['term']);
                    $term_object = get_term($term_ID, $taxonomy_type, OBJECT, 'edit');
                    if (empty($term_ID)) {
                        if ($taxonomy_type == 'category') {
                            powerpress_page_message_add_error(__('You must select a category to continue.', 'powerpress'));
                        } else {
                            powerpress_page_message_add_error(__('You must select a term to continue.', 'powerpress'));
                        }
                    } else {
                        if ($term_object == false) {
                            powerpress_page_message_add_error(__('Error obtaining term information.', 'powerpress'));
                        } else {
                            if ($taxonomy_type == 'category') {
                                $Settings = get_option('powerpress_general');
                                if (empty($Settings['custom_cat_feeds'])) {
                                    $Settings['custom_cat_feeds'] = array();
                                }
                                if (!in_array($term_ID, $Settings['custom_cat_feeds'])) {
                                    $Settings['custom_cat_feeds'][] = $term_ID;
                                    powerpress_save_settings($Settings);
                                }
                                powerpress_page_message_add_notice(__('Please configure your category podcast feed now.', 'powerpress'));
                                $_GET['action'] = 'powerpress-editcategoryfeed';
                                $_GET['cat'] = $term_ID;
                            } else {
                                //$term_info = term_exists($term_ID, $taxonomy_type);
                                $tt_id = $term_object->term_taxonomy_id;
                                if (!$tt_id) {
                                } else {
                                    $Settings = get_option('powerpress_taxonomy_podcasting');
                                    if (!isset($Settings[$tt_id])) {
                                        $Settings[$tt_id] = true;
                                        powerpress_save_settings($Settings, 'powerpress_taxonomy_podcasting');
                                        // add the feed to the taxonomy podcasting list
                                    }
                                    powerpress_page_message_add_notice(__('Please configure your taxonomy podcast now.', 'powerpress'));
                                    $_GET['action'] = 'powerpress-edittaxonomyfeed';
                                    $_GET['term'] = $term_ID;
                                    $_GET['ttid'] = $tt_id;
                                }
                            }
                        }
                    }
                    break;
                case 'powerpress-addposttypefeed':
                    check_admin_referer('powerpress-add-posttype-feed');
                    //die('ok 2');
                    $Settings = get_option('powerpress_general');
                    $feed_slug = sanitize_title($_POST['feed_slug']);
                    $post_type = $_POST['podcast_post_type'];
                    $post_type = powerpress_stripslashes($post_type);
                    $feed_title = $_POST['feed_title'];
                    $feed_title = powerpress_stripslashes($feed_title);
                    /*
                    					if( isset($Settings['custom_feeds'][ $key ]) && empty($_POST['overwrite']) )
                    					{
                    						powerpress_page_message_add_error( sprintf(__('Feed slug "%s" already exists.'), $key) );
                    					} else */
                    if (empty($feed_slug)) {
                        powerpress_page_message_add_error(sprintf(__('Feed slug "%s" is not valid.', 'powerpress'), esc_html($_POST['feed_slug'])));
                    } else {
                        if (empty($post_type)) {
                            powerpress_page_message_add_error(__('Post Type is invalid.', 'powerpress'));
                        } else {
                            $ExistingSettings = powerpress_get_settings('powerpress_posttype_' . $post_type);
                            if (!empty($ExistingSettings[$feed_slug])) {
                                powerpress_page_message_add_error(sprintf(__('Feed slug "%s" already exists.', 'powerpress'), $_POST['feed_slug']));
                            } else {
                                $NewSettings = array();
                                $NewSettings[$feed_slug]['title'] = $feed_title;
                                powerpress_save_settings($NewSettings, 'powerpress_posttype_' . $post_type);
                                add_feed($feed_slug, 'powerpress_do_podcast_feed');
                                // Before we flush the rewrite rules we need to add the new custom feed...
                                $wp_rewrite->flush_rules();
                                powerpress_page_message_add_notice(sprintf(__('Podcast "%s" added, please configure your new podcast.', 'powerpress'), $feed_title));
                                $_GET['action'] = 'powerpress-editposttypefeed';
                                $_GET['feed_slug'] = $feed_slug;
                                $_GET['podcast_post_type'] = $post_type;
                            }
                        }
                    }
                    break;
                case 'powerpress-ping-sites':
                    check_admin_referer('powerpress-ping-sites');
                    require_once POWERPRESS_ABSPATH . '/powerpressadmin-ping-sites.php';
                    powerpressadmin_ping_sites_process();
                    $_GET['action'] = 'powerpress-ping-sites';
                    break;
                case 'powerpress-find-replace':
                    check_admin_referer('powerpress-find-replace');
                    require_once POWERPRESS_ABSPATH . '/powerpressadmin-find-replace.php';
                    powerpressadmin_find_replace_process();
                    $_GET['action'] = 'powerpress-find-replace';
                    break;
                case 'powerpress-importpodpress':
                    check_admin_referer('powerpress-import-podpress');
                    require_once POWERPRESS_ABSPATH . '/powerpressadmin-podpress.php';
                    powerpressadmin_podpress_do_import();
                    $_GET['action'] = 'powerpress-podpress-epiosdes';
                    break;
                case 'powerpress-importmt':
                    check_admin_referer('powerpress-import-mt');
                    require_once POWERPRESS_ABSPATH . '/powerpressadmin-mt.php';
                    powerpressadmin_mt_do_import();
                    $_GET['action'] = 'powerpress-mt-epiosdes';
                    break;
                case 'deletepodpressdata':
                    check_admin_referer('powerpress-delete-podpress-data');
                    require_once POWERPRESS_ABSPATH . '/powerpressadmin-podpress.php';
                    powerpressadmin_podpress_delete_data();
                    break;
                case 'powerpress-save-mode':
                    //if( !isset($_POST['General']['advanced_mode']) )
                    //	powerpress_page_message_add_notice( __('You must select a Mode to continue.', 'powerpress') );
                    break;
            }
        }
        // Handle GET actions...
        if (isset($_GET['action'])) {
            switch ($_GET['action']) {
                case 'powerpress-enable-categorypodcasting':
                    check_admin_referer('powerpress-enable-categorypodcasting');
                    $Settings = get_option('powerpress_general');
                    $Settings['cat_casting'] = 1;
                    powerpress_save_settings($Settings);
                    wp_redirect('edit-tags.php?taxonomy=category&message=3');
                    exit;
                    break;
                case 'powerpress-addcategoryfeed':
                    check_admin_referer('powerpress-add-taxonomy-feed');
                    $cat_ID = intval($_GET['cat']);
                    $Settings = get_option('powerpress_general');
                    $category = get_category($cat_ID);
                    if ($category == false) {
                        powerpress_page_message_add_error(__('Error obtaining category information.', 'powerpress'));
                    } else {
                        if (empty($Settings['custom_cat_feeds']) || !is_array($Settings['custom_cat_feeds'])) {
                            $Settings['custom_cat_feeds'] = array();
                        }
                        if (!in_array($cat_ID, $Settings['custom_cat_feeds'])) {
                            $Settings['custom_cat_feeds'][] = $cat_ID;
                            powerpress_save_settings($Settings);
                        }
                        powerpress_page_message_add_notice(__('Please configure your category podcast feed now.', 'powerpress'));
                        $_GET['action'] = 'powerpress-editcategoryfeed';
                        $_GET['cat'] = $cat_ID;
                    }
                    break;
                case 'powerpress-delete-feed':
                    $delete_slug = $_GET['feed_slug'];
                    $force_deletion = !empty($_GET['force']);
                    check_admin_referer('powerpress-delete-feed-' . $delete_slug);
                    $Episodes = powerpress_admin_episodes_per_feed($delete_slug);
                    if (false && $delete_slug == 'podcast' && $force_deletion == false) {
                        powerpress_page_message_add_error(__('Cannot delete default podcast feed.', 'powerpress'));
                    } else {
                        if ($delete_slug != 'podcast' && $Episodes > 0 && $force_deletion == false) {
                            powerpress_page_message_add_error(sprintf(__('Cannot delete feed. Feed contains %d episode(s).', 'powerpress'), $Episodes));
                        } else {
                            $Settings = get_option('powerpress_general');
                            unset($Settings['custom_feeds'][$delete_slug]);
                            powerpress_save_settings($Settings);
                            // Delete the feed from the general settings
                            delete_option('powerpress_feed_' . $delete_slug);
                            // Delete the actual feed settings
                            // Now we need to update the rewrite cso the cached rules are up to date
                            if (in_array($delete_slug, $wp_rewrite->feeds)) {
                                $index = array_search($delete_slug, $wp_rewrite->feeds);
                                if ($index !== false) {
                                    unset($wp_rewrite->feeds[$index]);
                                }
                                // Remove the old feed
                            }
                            // Remove feed function hook
                            $hook = 'do_feed_' . $delete_slug;
                            remove_action($hook, $hook, 10, 1);
                            // This may not be necessary
                            $wp_rewrite->flush_rules();
                            // This is definitely necessary
                            powerpress_page_message_add_notice(__('Feed deleted successfully.', 'powerpress'));
                        }
                    }
                    break;
                case 'powerpress-delete-category-feed':
                    $cat_ID = intval($_GET['cat']);
                    check_admin_referer('powerpress-delete-category-feed-' . $cat_ID);
                    $Settings = get_option('powerpress_general');
                    $key = array_search($cat_ID, $Settings['custom_cat_feeds']);
                    if ($key !== false) {
                        unset($Settings['custom_cat_feeds'][$key]);
                        powerpress_save_settings($Settings);
                        // Delete the feed from the general settings
                    }
                    delete_option('powerpress_cat_feed_' . $cat_ID);
                    // Delete the actual feed settings
                    powerpress_page_message_add_notice(__('Removed podcast settings for category feed successfully.', 'powerpress'));
                    break;
                case 'powerpress-delete-taxonomy-feed':
                    $tt_ID = intval($_GET['ttid']);
                    check_admin_referer('powerpress-delete-taxonomy-feed-' . $tt_ID);
                    $Settings = get_option('powerpress_taxonomy_podcasting');
                    if (!empty($Settings[$tt_ID])) {
                        unset($Settings[$tt_ID]);
                        powerpress_save_settings($Settings, 'powerpress_taxonomy_podcasting');
                        // Delete the feed from the general settings
                    }
                    delete_option('powerpress_taxonomy_' . $tt_ID);
                    // Delete the actual feed settings
                    powerpress_page_message_add_notice(__('Removed podcast settings for term successfully.', 'powerpress'));
                    break;
                case 'powerpress-delete-posttype-feed':
                    // check admin referer prevents xss
                    $feed_slug = esc_attr($_GET['feed_slug']);
                    $post_type = esc_attr($_GET['podcast_post_type']);
                    check_admin_referer('powerpress-delete-posttype-feed-' . $post_type . '_' . $feed_slug);
                    $Settings = get_option('powerpress_posttype_' . $post_type);
                    if (!empty($Settings[$feed_slug])) {
                        unset($Settings[$feed_slug]);
                        update_option('powerpress_posttype_' . $post_type, $Settings);
                        //powerpress_save_settings($Settings, 'powerpress_posttype_'.$post_type); // Delete the feed from the general settings
                    }
                    powerpress_page_message_add_notice(__('Removed podcast settings for post type successfully.', 'powerpress'));
                    break;
                case 'powerpress-podpress-settings':
                    check_admin_referer('powerpress-podpress-settings');
                    // Import settings here..
                    if (powerpress_admin_import_podpress_settings()) {
                        powerpress_page_message_add_notice(__('Podpress settings imported successfully.', 'powerpress'));
                    } else {
                        powerpress_page_message_add_error(__('No Podpress settings found.', 'powerpress'));
                    }
                    break;
                case 'powerpress-podcasting-settings':
                    check_admin_referer('powerpress-podcasting-settings');
                    // Import settings here..
                    if (powerpress_admin_import_podcasting_settings()) {
                        powerpress_page_message_add_notice(__('Settings imported from the plugin "Podcasting" successfully.', 'powerpress'));
                    } else {
                        powerpress_page_message_add_error(__('No settings found for the plugin "Podcasting".', 'powerpress'));
                    }
                    break;
                case 'powerpress-add-caps':
                    check_admin_referer('powerpress-add-caps');
                    $users = array('administrator', 'editor', 'author');
                    // , 'contributor', 'subscriber');
                    while (list($null, $user) = each($users)) {
                        $role = get_role($user);
                        if (!empty($role)) {
                            if (!$role->has_cap('edit_podcast')) {
                                $role->add_cap('edit_podcast');
                            }
                            if ($user == 'administrator' && !$role->has_cap('view_podcast_stats')) {
                                $role->add_cap('view_podcast_stats');
                            }
                        }
                    }
                    $General = array('use_caps' => true);
                    powerpress_save_settings($General);
                    powerpress_page_message_add_notice(__('PowerPress Roles and Capabilities added to WordPress Blog.', 'powerpress'));
                    break;
                case 'powerpress-remove-caps':
                    check_admin_referer('powerpress-remove-caps');
                    $users = array('administrator', 'editor', 'author', 'contributor', 'subscriber');
                    while (list($null, $user) = each($users)) {
                        $role = get_role($user);
                        if (!empty($role)) {
                            if ($role->has_cap('edit_podcast')) {
                                $role->remove_cap('edit_podcast');
                            }
                            if ($role->has_cap('view_podcast_stats')) {
                                $role->remove_cap('view_podcast_stats');
                            }
                        }
                    }
                    $General = array('use_caps' => false);
                    powerpress_save_settings($General);
                    powerpress_page_message_add_notice(__('PowerPress Roles and Capabilities removed from WordPress Blog', 'powerpress'));
                    break;
                case 'powerpress-add-feed-caps':
                    check_admin_referer('powerpress-add-feed-caps');
                    $ps_role = get_role('premium_subscriber');
                    if (empty($ps_role)) {
                        add_role('premium_subscriber', __('Premium Subscriber', 'powerpress'));
                        $ps_role = get_role('premium_subscriber');
                        $ps_role->add_cap('read');
                        $ps_role->add_cap('premium_content');
                    }
                    $users = array('administrator', 'editor', 'author');
                    // , 'contributor', 'subscriber');
                    while (list($null, $user) = each($users)) {
                        $role = get_role($user);
                        if (!empty($role)) {
                            if (!$role->has_cap('premium_content')) {
                                $role->add_cap('premium_content');
                            }
                        }
                    }
                    $General = array('premium_caps' => true);
                    powerpress_save_settings($General);
                    powerpress_page_message_add_notice(__('Podcast Password Protection Capabilities for Custom Channel Feeds added successfully.', 'powerpress'));
                    break;
                case 'powerpress-remove-feed-caps':
                    check_admin_referer('powerpress-remove-feed-caps');
                    $users = array('administrator', 'editor', 'author', 'contributor', 'subscriber', 'premium_subscriber', 'powerpress');
                    while (list($null, $user) = each($users)) {
                        $role = get_role($user);
                        if (!empty($role)) {
                            if ($role->has_cap('premium_content')) {
                                $role->remove_cap('premium_content');
                            }
                        }
                    }
                    remove_role('premium_subscriber');
                    $General = array('premium_caps' => false);
                    powerpress_save_settings($General);
                    powerpress_page_message_add_notice(__('Podcast Password Protection Capabilities for Custom Channel Feeds removed successfully.', 'powerpress'));
                    break;
                case 'powerpress-clear-update_plugins':
                    check_admin_referer('powerpress-clear-update_plugins');
                    delete_option('update_plugins');
                    // OLD method
                    delete_option('_site_transient_update_plugins');
                    // New method
                    powerpress_page_message_add_notice(sprintf(__('Plugins Update Cache cleared successfully. You may now to go the %s page to see the latest plugin versions.', 'powerpress'), '<a href="' . admin_url() . 'plugins.php" title="' . __('Manage Plugins', 'powerpress') . '">' . __('Manage Plugins', 'powerpress') . '</a>'));
                    break;
            }
        }
        if (isset($_REQUEST['action'])) {
            switch ($_REQUEST['action']) {
                case 'powerpress-migrate-media':
                    require_once POWERPRESS_ABSPATH . '/powerpressadmin-migrate.php';
                    powerpress_admin_migrate_request();
                    break;
            }
        }
    }
    // Handle edit from category page
    if (isset($_POST['from_categories'])) {
        wp_redirect('edit-tags.php?taxonomy=category&message=3');
        exit;
    }
    // Hnadle player settings
    require_once POWERPRESS_ABSPATH . '/powerpressadmin-player.php';
    powerpress_admin_players_init();
}
Esempio n. 10
0
function powerpressadmin_podpress_delete_data()
{
    global $wpdb;
    // Delete podpress data from database...
    $query = "DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE 'podPress%'";
    $deleted_count = $wpdb->query($query);
    powerpress_page_message_add_notice(sprintf(__('PodPress data deleted from database successfully. (%d database records removed)', 'powerpress'), $deleted_count));
}