function powerpressadmin_edit_itunes_feed($FeedSettings, $General, $FeedAttribs = array())
{
    $feed_slug = $FeedAttribs['feed_slug'];
    $cat_ID = $FeedAttribs['category_id'];
    $SupportUploads = powerpressadmin_support_uploads();
    if (!isset($FeedSettings['itunes_subtitle'])) {
        $FeedSettings['itunes_subtitle'] = '';
    }
    if (!isset($FeedSettings['itunes_summary'])) {
        $FeedSettings['itunes_summary'] = '';
    }
    if (!isset($FeedSettings['itunes_keywords'])) {
        $FeedSettings['itunes_keywords'] = '';
    }
    if (!isset($FeedSettings['itunes_cat_1'])) {
        $FeedSettings['itunes_cat_1'] = '';
    }
    if (!isset($FeedSettings['itunes_cat_2'])) {
        $FeedSettings['itunes_cat_2'] = '';
    }
    if (!isset($FeedSettings['itunes_cat_3'])) {
        $FeedSettings['itunes_cat_3'] = '';
    }
    if (!isset($FeedSettings['itunes_explicit'])) {
        $FeedSettings['itunes_explicit'] = 0;
    }
    if (!isset($FeedSettings['itunes_talent_name'])) {
        $FeedSettings['itunes_talent_name'] = '';
    }
    if (!isset($FeedSettings['email'])) {
        $FeedSettings['email'] = '';
    }
    if (!isset($FeedSettings['itunes_new_feed_url_podcast'])) {
        $FeedSettings['itunes_new_feed_url_podcast'] = '';
    }
    if (!isset($FeedSettings['itunes_new_feed_url'])) {
        $FeedSettings['itunes_new_feed_url'] = '';
    }
    $AdvancediTunesSettings = !empty($FeedSettings['itunes_summary']);
    if (!empty($FeedSettings['itunes_subtitle'])) {
        $AdvancediTunesSettings = true;
    }
    ?>

<h3><?php 
    echo __('iTunes Settings', 'powerpress');
    ?>
</h3>
<table class="form-table">
<tr valign="top">
<th scope="row">
<?php 
    echo __('iTunes Program Subtitle', 'powerpress');
    ?>
 <br />
</th>
<td>
<input type="text" name="Feed[itunes_subtitle]" style="width: 60%;"  value="<?php 
    echo esc_attr($FeedSettings['itunes_subtitle']);
    ?>
" maxlength="250" />
</td>
</tr>

<tr valign="top">
<th scope="row">

<?php 
    echo __('iTunes Program Summary', 'powerpress');
    ?>
</th>
<td>
<p style="margin-top: 5px;"><?php 
    echo __('Your summary may not contain HTML and cannot exceed 4,000 characters in length.', 'powerpress');
    ?>
</p>

<textarea name="Feed[itunes_summary]" rows="5" style="width:80%;" ><?php 
    echo $FeedSettings['itunes_summary'];
    ?>
</textarea>
</td>
</tr>

<?php 
    if (!empty($General['advanced_mode_2'])) {
        ?>
<tr valign="top">
<th scope="row">

<?php 
        echo __('iTunes Episode Summary', 'powerpress');
        ?>
</th>
<td>
<div><input type="checkbox" name="Feed[enhance_itunes_summary]" value="1" <?php 
        echo !empty($FeedSettings['enhance_itunes_summary']) ? 'checked ' : '';
        ?>
/> <?php 
        echo __('Optimize iTunes Summary from Blog Posts', 'powerpress');
        ?>
</div>
<p>
	<?php 
        echo __('Creates a friendlier view of your post/episode content by converting web links and images to clickable links in the iTunes application.', 'powerpress');
        ?>
</p>
</td>
</tr>
</table>


<table class="form-table">
<?php 
        if (!empty($FeedSettings['itunes_keywords'])) {
            ?>
<tr valign="top">
<th scope="row">
<?php 
            echo __('iTunes Program Keywords', 'powerpress');
            ?>
 <br />
</th>
<td>
<input type="text" name="Feed[itunes_keywords]" style="width: 60%;"  value="<?php 
            echo esc_attr($FeedSettings['itunes_keywords']);
            ?>
" maxlength="250" />
<p><?php 
            echo __('Feature Deprecated by Apple. Keywords above are for your reference only.', 'powerpress');
            ?>
</p>
</td>
</tr>
<?php 
        }
        // End iTunes keywords
    }
    // end advanced mode
    ?>

<tr valign="top">
<th scope="row">
<?php 
    echo __('iTunes Category', 'powerpress');
    ?>
 
<span class="powerpress-required"><?php 
    echo __('Required', 'powerpress');
    ?>
</span>
</th>
<td>
<select name="Feed[itunes_cat_1]" class="bpp_input_med">
<?php 
    $MoreCategories = false;
    if (!empty($FeedSettings['itunes_cat_2'])) {
        $MoreCategories = true;
    } else {
        if (!empty($FeedSettings['itunes_cat_3'])) {
            $MoreCategories = true;
        }
    }
    $Categories = powerpress_itunes_categories(true);
    echo '<option value="">' . __('Select Category', 'powerpress') . '</option>';
    $UseCategories = powerpress_categories_strict($Categories, $FeedSettings['itunes_cat_1']);
    while (list($value, $desc) = each($UseCategories)) {
        echo "\t<option value=\"{$value}\"" . ($FeedSettings['itunes_cat_1'] == $value ? ' selected' : '') . ">" . htmlspecialchars($desc) . "</option>\n";
    }
    reset($Categories);
    ?>
</select>
<?php 
    if (!$MoreCategories && empty($General['seo_itunes'])) {
        ?>
	<a href="#" onclick="document.getElementById('more_itunes_cats').style.display='block';return false;"><?php 
        echo __('more', 'powerpress');
        ?>
</a>
<?php 
    }
    ?>
	<p>
		<?php 
    echo __('The category above is where you will appear when browsing iTunes.', 'powerpress');
    ?>
	</p>
</td>
</tr>
</table>


<!-- start advanced features -->
<div id="more_itunes_cats" style="display: <?php 
    echo $MoreCategories || !empty($General['seo_itunes']) ? 'block' : 'none';
    ?>
;">
<table class="form-table">
<tr valign="top">
<th scope="row">
<?php 
    echo __('iTunes Category 2', 'powerpress');
    ?>
 
</th>
<td>
<select name="Feed[itunes_cat_2]" class="bpp_input_med">
<?php 
    echo '<option value="">' . __('Select Category', 'powerpress') . '</option>';
    $UseCategories = powerpress_categories_strict($Categories, $FeedSettings['itunes_cat_2']);
    while (list($value, $desc) = each($UseCategories)) {
        echo "\t<option value=\"{$value}\"" . ($FeedSettings['itunes_cat_2'] == $value ? ' selected' : '') . ">" . htmlspecialchars($desc) . "</option>\n";
    }
    reset($Categories);
    ?>
</select>
<?php 
    if (!empty($General['seo_itunes'])) {
        ?>
			<p>
				<em><?php 
        echo __('SEO Suggestion: Select a second category.', 'powerpress');
        ?>
</em>
			</p>
<?php 
    }
    ?>

</td>
</tr>

<tr valign="top">
<th scope="row">
<?php 
    echo __('iTunes Category 3', 'powerpress');
    ?>
 
</th>
<td>
<select name="Feed[itunes_cat_3]" class="bpp_input_med">
<?php 
    echo '<option value="">' . __('Select Category', 'powerpress') . '</option>';
    $UseCategories = powerpress_categories_strict($Categories, $FeedSettings['itunes_cat_3']);
    while (list($value, $desc) = each($UseCategories)) {
        echo "\t<option value=\"{$value}\"" . ($FeedSettings['itunes_cat_3'] == $value ? ' selected' : '') . ">" . htmlspecialchars($desc) . "</option>\n";
    }
    reset($Categories);
    ?>
</select>
<?php 
    if (!empty($General['seo_itunes'])) {
        ?>
			<p>
				<em><?php 
        echo __('SEO Suggestion: Select a third category.', 'powerpress');
        ?>
</em>
			</p>
<?php 
    }
    ?>
</td>
</tr>
</table>
</div>
<!-- end advanced features -->


<table class="form-table">
<tr valign="top">
<th scope="row">
<?php 
    echo __('iTunes Explicit', 'powerpress');
    ?>
 
</th>
<td>
<select name="Feed[itunes_explicit]" class="bpp_input_med">
<?php 
    $explicit = array(0 => __('No - display nothing', 'powerpress'), 1 => __('Yes - explicit content', 'powerpress'), 2 => __('Clean - no explicit content', 'powerpress'));
    while (list($value, $desc) = each($explicit)) {
        echo "\t<option value=\"{$value}\"" . ($FeedSettings['itunes_explicit'] == $value ? ' selected' : '') . ">{$desc}</option>\n";
    }
    ?>
</select>
</td>
</tr>
<?php 
    if (!empty($General['advanced_mode_2'])) {
        ?>
<!-- start advanced features -->
<tr valign="top">
<th scope="row">
<?php 
        echo __('iTunes Author Name', 'powerpress');
        ?>
 
</th>
<td>
<input type="text" name="Feed[itunes_talent_name]" class="bpp_input_med" value="<?php 
        echo esc_attr($FeedSettings['itunes_talent_name']);
        ?>
" maxlength="250" /><br />
<div><input type="checkbox" name="Feed[itunes_author_post]" value="1" <?php 
        echo !empty($FeedSettings['itunes_author_post']) ? 'checked ' : '';
        ?>
/> <?php 
        echo __('Use blog post author\'s name for individual episodes.', 'powerpress');
        ?>
</div>

<?php 
        if (!empty($General['seo_itunes'])) {
            ?>
			<p>
				<em><?php 
            echo __('SEO Suggestion: Include talent names and slogans not mentioned in the show title.', 'powerpress');
            ?>
</em>
			</p>
<?php 
        }
        ?>
</td>
</tr>
<!-- end advanced features -->
<?php 
    }
    ?>

<tr valign="top">
<th scope="row">
<?php 
    echo __('iTunes Email', 'powerpress');
    ?>
 
<span class="powerpress-required"><?php 
    echo __('Required', 'powerpress');
    ?>
</span>
</th>
<td>
<input type="text" name="Feed[email]" class="bpp_input_med" value="<?php 
    echo esc_attr($FeedSettings['email']);
    ?>
" maxlength="250" />
<div>(<?php 
    echo __('iTunes will email this address when your podcast is accepted into the iTunes Directory.', 'powerpress');
    ?>
)</div>
</td>
</tr>
</table>

<?php 
    if (!empty($General['advanced_mode_2'])) {
        ?>
<!-- start advanced features -->
<table class="form-table">
	<tr valign="top">
	<th scope="row" >

<?php 
        echo __('iTunes New Feed URL', 'powerpress');
        ?>
</th> 
	<td>
		<div id="new_feed_url_step_1" style="display: <?php 
        echo !empty($FeedSettings['itunes_new_feed_url']) || !empty($FeedSettings['itunes_new_feed_url_podcast']) ? 'none' : 'block';
        ?>
;">
			 <p style="margin-top: 5px;"><strong><a href="#" onclick="return powerpress_new_feed_url_prompt();"><?php 
        echo __('Set iTunes New Feed URL', 'powerpress');
        ?>
</a></strong></p>
			 <p><strong>
			 <?php 
        echo __('The iTunes New Feed URL option works primarily for Apple\'s iTunes application only, and should only be used if you are unable to implement a HTTP 301 redirect.', 'powerpress');
        ?>
			 <?php 
        echo __('A 301 redirect will route <u>all podcast clients including iTunes</u> to your new feed address.', 'powerpress');
        ?>
			 </strong> 
			 </p>
			 <p>
			 <?php 
        echo __('Learn more:', 'powerpress');
        ?>
 <a href="http://create.blubrry.com/manual/syndicating-your-podcast-rss-feeds/changing-your-podcast-rss-feed-address-url/" target="_blank"><?php 
        echo __('Changing Your Podcast RSS Feed Address (URL)', 'powerpress');
        ?>
</a>
			</p>
		</div>
		<div id="new_feed_url_step_2" style="display: <?php 
        echo !empty($FeedSettings['itunes_new_feed_url']) || !empty($FeedSettings['itunes_new_feed_url_podcast']) ? 'block' : 'none';
        ?>
;">
			<p style="margin-top: 5px;"><strong><?php 
        echo __('WARNING: Changes made here are permanent. If the New Feed URL entered is incorrect, you will lose subscribers and will no longer be able to update your listing in the iTunes Store.', 'powerpress');
        ?>
</strong></p>
			<p><strong><?php 
        echo __('DO NOT MODIFY THIS SETTING UNLESS YOU ABSOLUTELY KNOW WHAT YOU ARE DOING.', 'powerpress');
        ?>
</strong></p>
			<p>
				<?php 
        echo htmlspecialchars(sprintf(__('Apple recommends you maintain the %s tag in your feed for at least two weeks to ensure that most subscribers will receive the new New Feed URL.', 'powerpress'), '<itunes:new-feed-url>'));
        ?>
			</p>
			<p>
			<?php 
        $FeedName = __('Main RSS2 feed', 'powerpress');
        $FeedURL = get_feed_link('rss2');
        if ($cat_ID) {
            $category = get_category_to_edit($cat_ID);
            $FeedName = sprintf(__('%s category feed', 'powerpress'), htmlspecialchars($category->name));
            $FeedURL = get_category_feed_link($cat_ID);
        } else {
            if ($feed_slug) {
                if (!empty($General['custom_feeds'][$feed_slug])) {
                    $FeedName = $General['custom_feeds'][$feed_slug];
                } else {
                    $FeedName = __('Podcast', 'powerpress');
                }
                $FeedName = trim($FeedName) . ' ' . __('feed', 'powerpress');
                $FeedURL = get_feed_link($feed_slug);
            } else {
                if ($FeedAttribs['type'] == 'ttid') {
                    $term_object = get_term_to_edit($FeedAttribs['term_id'], $FeedAttribs['taxonomy_type']);
                    $FeedName = sprintf(__('%s taxonomy term feed', 'powerpress'), htmlspecialchars($term_object->name));
                    $FeedURL = get_term_feed_link($FeedAttribs['term_id'], $FeedAttribs['taxonomy_type'], 'rss2');
                }
            }
        }
        echo sprintf(__('The New Feed URL value below will be applied to the %s (%s).', 'powerpress'), $FeedName, $FeedURL);
        ?>
			</p>
			<p style="margin-bottom: 0;">
				<label style="width: 25%; float:left; display:block; font-weight: bold;"><?php 
        echo __('New Feed URL', 'powerpress');
        ?>
</label>
				<input type="text" name="Feed[itunes_new_feed_url]" style="width: 55%;"  value="<?php 
        echo esc_attr($FeedSettings['itunes_new_feed_url']);
        ?>
" maxlength="250" />
			</p>
			<p style="margin-left: 25%;margin-top: 0;font-size: 90%;">(<?php 
        echo __('Leave blank for no New Feed URL', 'powerpress');
        ?>
)</p>
			
			<p><a href="http://www.apple.com/itunes/whatson/podcasts/specs.html#changing" target="_blank"><?php 
        echo __('More information regarding the iTunes New Feed URL is available here.', 'powerpress');
        ?>
</a></p>
			<p>
<?php 
        if (!$cat_ID && !$feed_slug) {
            if (empty($General['channels'])) {
                echo sprintf(__('Please activate the \'Custom Podcast Channels\' Advanced Option to set the new-feed-url for your podcast only feed (%s)', 'powerpress'), get_feed_link('podcast'));
            } else {
                echo sprintf(__('Please navigate to the \'Custom Podcast Channels\' section to set the new-feed-url for your podcast only feed (%s)', 'powerpress'), get_feed_link('podcast'));
            }
        }
        ?>
			</p>
		</div>
	</td>
	</tr>
</table>
<?php 
        if (defined('POWERPRESS_NOT_SUPPORTED')) {
            // start powerpress not supported features
            ?>
<fieldset style="border: 1px dashed #333333;">
<legend style="margin: 0 20px; padding: 0 5px; font-weight: bold;"><?php 
            echo __('Features Not Supported by PowerPress', 'powerpress');
            ?>
</legend>

	<div style="margin-left: 230px; margin-bottom: 10px;">
		<p>
			<strong style="color: #CC0000; font-weight: bold;"><?php 
            echo __('USE THE FOLLOWING SETTINGS AT YOUR OWN RISK.', 'powerpress');
            ?>
</strong>
		</p>
		<p style="margin-bottom: 0;">
			<?php 
            echo __('Feeds affected', 'powerpress');
            ?>
: 
		</p>
		<div style="margin-left: 20px;">
			<?php 
            // $General, $feed_slug=false, $cat_ID=false
            if ($feed_slug) {
                echo '<a href="';
                echo get_feed_link($feed_slug);
                echo '" target="_blank">';
                echo get_feed_link($feed_slug);
                echo '</a>';
            } else {
                if ($cat_ID) {
                    echo '<a href="';
                    echo get_category_feed_link($cat_ID);
                    echo '" target="_blank">';
                    echo get_category_feed_link($cat_ID);
                    echo '</a>';
                } else {
                    echo '<a href="';
                    echo get_feed_link('feed');
                    echo '" target="_blank">';
                    echo get_feed_link('feed');
                    echo '</a>';
                    if (empty($General['custom_feeds']['podcast'])) {
                        echo '<br /><a href="';
                        echo get_feed_link('podcast');
                        echo '" target="_blank">';
                        echo get_feed_link('podcast');
                        echo '</a>';
                    }
                }
            }
            ?>
		</div>
		
	</div>
<div id="permanent_itunes_settings">
<table class="form-table">
	
	<tr valign="top">
	<th scope="row" >

<?php 
            echo __('iTunes Block', 'powerpress');
            ?>
</th> 
	<td>
		<input type="checkbox" name="Feed[itunes_block]" value="1" <?php 
            if (!empty($FeedSettings['itunes_block'])) {
                echo 'checked';
            }
            ?>
 />
		<?php 
            echo __('Prevent the entire podcast from appearing in the iTunes Podcast directory.', 'powerpress');
            ?>
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row" >

<?php 
            echo __('iTunes Complete', 'powerpress');
            ?>
</th> 
	<td>
		<input type="checkbox" name="Feed[itunes_complete]" value="1" <?php 
            if (!empty($FeedSettings['itunes_complete'])) {
                echo 'checked';
            }
            ?>
 />
		<?php 
            echo __('Indicate the completion of a podcast. iTunes will no longer update your listing in the iTunes Podcast directory.', 'powerpress');
            ?>
	</td>
	</tr>
</table>
</div>
</fieldset>
<?php 
        }
        // End PowerPress not supported features
        ?>
<!-- end advanced features -->
<?php 
    }
    // end other advanced options
}
Example #2
0
function powerpress_rss2_head()
{
    global $powerpress_feed;
    if (!powerpress_is_podcast_feed()) {
        return;
    }
    // Not a feed we manage
    $feed_slug = get_query_var('feed');
    $cat_ID = get_query_var('cat');
    $Feed = get_option('powerpress_feed');
    // Get the main feed settings
    if (!empty($powerpress_feed['category'])) {
        $CustomFeed = get_option('powerpress_cat_feed_' . $powerpress_feed['category']);
        // Get the custom podcast feed settings saved in the database
        if ($CustomFeed) {
            $Feed = powerpress_merge_empty_feed_settings($CustomFeed, $Feed);
        }
    } else {
        if (!empty($powerpress_feed['term_taxonomy_id'])) {
            $CustomFeed = get_option('powerpress_taxonomy_' . $powerpress_feed['term_taxonomy_id']);
            // Get the taxonomy podcast settings saved in the database
            if ($CustomFeed) {
                $Feed = powerpress_merge_empty_feed_settings($CustomFeed, $Feed);
            }
        } else {
            if (powerpress_is_custom_podcast_feed()) {
                $CustomFeed = get_option('powerpress_feed_' . $feed_slug);
                // Get the custom podcast feed settings saved in the database
                $Feed = powerpress_merge_empty_feed_settings($CustomFeed, $Feed, $feed_slug == 'podcast');
            }
        }
    }
    if (!isset($Feed['url']) || trim($Feed['url']) == '') {
        if (is_category()) {
            $Feed['url'] = get_category_link($cat_ID);
        } else {
            $Feed['url'] = get_bloginfo('url');
        }
    }
    $General = get_option('powerpress_general');
    // We made it this far, lets write stuff to the feed!
    echo '<!-- podcast_generator="Blubrry PowerPress/' . POWERPRESS_VERSION . '" ';
    if (isset($General['advanced_mode_2']) && empty($General['advanced_mode_2'])) {
        echo 'mode="simple" ';
    } else {
        echo 'mode="advanced" ';
    }
    if (defined('POWERPRESS_DEBUG')) {
        if (!empty($powerpress_feed['category'])) {
            echo 'category="' . $powerpress_feed['category'] . '" ';
        }
        if (!empty($powerpress_feed['term_taxonomy_id'])) {
            echo 'ttid="' . $powerpress_feed['term_taxonomy_id'] . '" ';
        }
        if (!empty($powerpress_feed['post_type'])) {
            echo 'posttype="' . $powerpress_feed['post_type'] . '" ';
        }
        if (!empty($powerpress_feed['feed-slug'])) {
            echo 'feedslug="' . $powerpress_feed['feed-slug'] . '" ';
        }
    }
    echo '-->' . PHP_EOL;
    // add the itunes:new-feed-url tag to feed
    if (powerpress_is_custom_podcast_feed()) {
        if (!empty($Feed['itunes_new_feed_url'])) {
            $Feed['itunes_new_feed_url'] = str_replace('&amp;', '&', $Feed['itunes_new_feed_url']);
            echo "\t<itunes:new-feed-url>" . htmlspecialchars(trim($Feed['itunes_new_feed_url'])) . '</itunes:new-feed-url>' . PHP_EOL;
        }
    } else {
        if (!empty($Feed['itunes_new_feed_url']) && ($feed_slug == 'feed' || $feed_slug == 'rss2')) {
            $Feed['itunes_new_feed_url'] = str_replace('&amp;', '&', $Feed['itunes_new_feed_url']);
            echo "\t<itunes:new-feed-url>" . htmlspecialchars(trim($Feed['itunes_new_feed_url'])) . '</itunes:new-feed-url>' . PHP_EOL;
        }
    }
    if (!empty($Feed['itunes_summary'])) {
        echo "\t" . '<itunes:summary>' . powerpress_format_itunes_value($Feed['itunes_summary'], 'summary') . '</itunes:summary>' . PHP_EOL;
    } else {
        echo "\t" . '<itunes:summary>' . powerpress_format_itunes_value(get_bloginfo('description'), 'summary') . '</itunes:summary>' . PHP_EOL;
    }
    if (!empty($powerpress_feed['itunes_talent_name'])) {
        echo "\t<itunes:author>" . esc_html($powerpress_feed['itunes_talent_name']) . '</itunes:author>' . PHP_EOL;
    }
    if (!empty($powerpress_feed['explicit'])) {
        echo "\t" . '<itunes:explicit>' . $powerpress_feed['explicit'] . '</itunes:explicit>' . PHP_EOL;
    }
    if (!empty($Feed['itunes_block'])) {
        echo "\t<itunes:block>yes</itunes:block>" . PHP_EOL;
    }
    if (!empty($Feed['itunes_complete'])) {
        echo "\t<itunes:complete>yes</itunes:complete>" . PHP_EOL;
    }
    if (!empty($Feed['itunes_image'])) {
        echo "\t" . '<itunes:image href="' . esc_html(str_replace(' ', '+', $Feed['itunes_image']), 'double') . '" />' . PHP_EOL;
    } else {
        echo "\t" . '<itunes:image href="' . powerpress_get_root_url() . 'itunes_default.jpg" />' . PHP_EOL;
    }
    if (!empty($Feed['email'])) {
        echo "\t" . '<itunes:owner>' . PHP_EOL;
        echo "\t\t" . '<itunes:name>' . esc_html($powerpress_feed['itunes_talent_name']) . '</itunes:name>' . PHP_EOL;
        echo "\t\t" . '<itunes:email>' . esc_html($Feed['email']) . '</itunes:email>' . PHP_EOL;
        echo "\t" . '</itunes:owner>' . PHP_EOL;
        echo "\t" . '<managingEditor>' . esc_html($Feed['email'] . ' (' . $powerpress_feed['itunes_talent_name'] . ')') . '</managingEditor>' . PHP_EOL;
    }
    if (!empty($Feed['copyright'])) {
        // In case the user entered the copyright html version or the copyright UTF-8 or ASCII symbol or just (c)
        $Feed['copyright'] = str_replace(array('&copy;', '(c)', '(C)', chr(194) . chr(169), chr(169)), '&#xA9;', $Feed['copyright']);
        echo "\t" . '<copyright>' . esc_html($Feed['copyright']) . '</copyright>' . PHP_EOL;
    }
    if (!empty($Feed['itunes_subtitle'])) {
        echo "\t" . '<itunes:subtitle>' . powerpress_format_itunes_value($Feed['itunes_subtitle'], 'subtitle') . '</itunes:subtitle>' . PHP_EOL;
    } else {
        echo "\t" . '<itunes:subtitle>' . powerpress_format_itunes_value(get_bloginfo('description'), 'subtitle') . '</itunes:subtitle>' . PHP_EOL;
    }
    if (!empty($Feed['rss2_image']) || !empty($Feed['itunes_image'])) {
        if (!empty($Feed['rss2_image'])) {
            // If the RSS image is set, use it, otherwise use the iTunes image...
            $rss_image = $Feed['rss2_image'];
        } else {
            $rss_image = $Feed['itunes_image'];
        }
        echo "\t" . '<image>' . PHP_EOL;
        if (is_category() && !empty($Feed['title'])) {
            echo "\t\t" . '<title>' . esc_html(get_bloginfo_rss('name')) . '</title>' . PHP_EOL;
        } else {
            echo "\t\t" . '<title>' . esc_html(get_bloginfo_rss('name') . get_wp_title_rss()) . '</title>' . PHP_EOL;
        }
        echo "\t\t" . '<url>' . esc_html(str_replace(' ', '+', $rss_image)) . '</url>' . PHP_EOL;
        echo "\t\t" . '<link>' . $Feed['url'] . '</link>' . PHP_EOL;
        echo "\t" . '</image>' . PHP_EOL;
    } else {
        echo "\t" . '<image>' . PHP_EOL;
        if ((is_category() || is_tax() || is_tag()) && !empty($Feed['title'])) {
            echo "\t\t" . '<title>' . esc_html(get_bloginfo_rss('name')) . '</title>' . PHP_EOL;
        } else {
            echo "\t\t" . '<title>' . esc_html(get_bloginfo_rss('name') . get_wp_title_rss()) . '</title>' . PHP_EOL;
        }
        echo "\t\t" . '<url>' . powerpress_get_root_url() . 'rss_default.jpg</url>' . PHP_EOL;
        echo "\t\t" . '<link>' . $Feed['url'] . '</link>' . PHP_EOL;
        echo "\t" . '</image>' . PHP_EOL;
    }
    // Handle iTunes categories
    $Categories = powerpress_itunes_categories();
    $Cat1 = false;
    $Cat2 = false;
    $Cat3 = false;
    if (!empty($Feed['itunes_cat_1'])) {
        list($Cat1, $SubCat1) = explode('-', $Feed['itunes_cat_1']);
    }
    if (!empty($Feed['itunes_cat_2'])) {
        list($Cat2, $SubCat2) = explode('-', $Feed['itunes_cat_2']);
    }
    if (!empty($Feed['itunes_cat_3'])) {
        list($Cat3, $SubCat3) = explode('-', $Feed['itunes_cat_3']);
    }
    if ($Cat1) {
        $CatDesc = $Categories[$Cat1 . '-00'];
        $SubCatDesc = $Categories[$Cat1 . '-' . $SubCat1];
        if ($Cat1 != $Cat2 && $SubCat1 == '00') {
            echo "\t" . '<itunes:category text="' . esc_html($CatDesc) . '" />' . PHP_EOL;
        } else {
            echo "\t" . '<itunes:category text="' . esc_html($CatDesc) . '">' . PHP_EOL;
            if ($SubCat1 != '00') {
                echo "\t\t" . '<itunes:category text="' . esc_html($SubCatDesc) . '" />' . PHP_EOL;
            }
            // End this category set
            if ($Cat1 != $Cat2) {
                echo "\t" . '</itunes:category>' . PHP_EOL;
            }
        }
    }
    if ($Cat2) {
        $CatDesc = $Categories[$Cat2 . '-00'];
        $SubCatDesc = $Categories[$Cat2 . '-' . $SubCat2];
        // It's a continuation of the last category...
        if ($Cat1 == $Cat2) {
            if ($SubCat2 != '00') {
                echo "\t\t" . '<itunes:category text="' . esc_html($SubCatDesc) . '" />' . PHP_EOL;
            }
            // End this category set
            if ($Cat2 != $Cat3) {
                echo "\t" . '</itunes:category>' . PHP_EOL;
            }
        } else {
            if ($Cat2 != $Cat3 && $SubCat2 == '00') {
                echo "\t" . '<itunes:category text="' . esc_html($CatDesc) . '" />' . PHP_EOL;
            } else {
                if ($Cat1 != $Cat2) {
                    // Start a new category set
                    echo "\t" . '<itunes:category text="' . esc_html($CatDesc) . '">' . PHP_EOL;
                }
                if ($SubCat2 != '00') {
                    echo "\t\t" . '<itunes:category text="' . esc_html($SubCatDesc) . '" />' . PHP_EOL;
                }
                if ($Cat2 != $Cat3) {
                    // End this category set
                    echo "\t" . '</itunes:category>' . PHP_EOL;
                }
            }
        }
    }
    if ($Cat3) {
        $CatDesc = $Categories[$Cat3 . '-00'];
        $SubCatDesc = $Categories[$Cat3 . '-' . $SubCat3];
        // It's a continuation of the last category...
        if ($Cat2 == $Cat3) {
            if ($SubCat3 != '00') {
                echo "\t\t" . '<itunes:category text="' . esc_html($SubCatDesc) . '" />' . PHP_EOL;
            }
            // End this category set
            echo "\t" . '</itunes:category>' . PHP_EOL;
        } else {
            if ($Cat2 != $Cat3 && $SubCat3 == '00') {
                echo "\t" . '<itunes:category text="' . esc_html($CatDesc) . '" />' . PHP_EOL;
            } else {
                if ($Cat2 != $Cat3) {
                    // Start a new category set
                    echo "\t" . '<itunes:category text="' . esc_html($CatDesc) . '">' . PHP_EOL;
                }
                if ($SubCat3 != '00') {
                    echo "\t\t" . '<itunes:category text="' . esc_html($SubCatDesc) . '" />' . PHP_EOL;
                }
                // End this category set
                echo "\t" . '</itunes:category>' . PHP_EOL;
            }
        }
    }
    // End Handle iTunes categories
    // RawVoice RSS Tags
    if (!defined('POWERPRESS_RAWVOICE_RSS') || POWERPRESS_RAWVOICE_RSS != false) {
        if (!empty($Feed['parental_rating'])) {
            echo "\t\t<rawvoice:rating>" . $Feed['parental_rating'] . "</rawvoice:rating>" . PHP_EOL;
        }
        if (!empty($Feed['location'])) {
            echo "\t\t<rawvoice:location>" . htmlspecialchars($Feed['location']) . "</rawvoice:location>" . PHP_EOL;
        }
        if (!empty($Feed['frequency'])) {
            echo "\t\t<rawvoice:frequency>" . htmlspecialchars($Feed['frequency']) . "</rawvoice:frequency>" . PHP_EOL;
        }
    }
}
function powerpress_admin_import_podcasting_settings()
{
    $Changes = false;
    $General = get_option('powerpress_general');
    if (!$General) {
        $General = array();
        $Changes = true;
        $General['process_podpress'] = 0;
        $General['display_player'] = 1;
        $General['player_function'] = 1;
        $General['podcast_link'] = 1;
    }
    $pod_player_location = get_option('pod_player_location');
    if ($pod_player_location == 'top') {
        $General['display_player'] = 2;
        // display above posts
        $Changes = true;
    }
    $pod_audio_width = get_option('pod_audio_width');
    if (is_int((int) $pod_audio_width) && $pod_audio_width > 100) {
        $General['player_width_audio'] = $pod_audio_width;
        $Changes = true;
    }
    $pod_player_width = get_option('pod_player_width');
    if (is_int((int) $pod_player_width) && $pod_player_width > 100) {
        $General['player_width'] = $pod_player_width;
        $Changes = true;
    }
    $pod_player_height = get_option('pod_player_height');
    if (is_int((int) $pod_player_height) && $pod_player_height > 100) {
        $General['player_height'] = $pod_player_height;
        $Changes = true;
    }
    if ($Changes == true) {
        // save these imported general settings
        powerpress_save_settings($General, 'powerpress_general');
    }
    $FeedChanges = false;
    // Feed settings:
    $FeedSettings = get_option('powerpress_feed');
    if (!$FeedSettings) {
        $FeedSettings = array();
        $FeedChanges = true;
    }
    $pod_itunes_summary = get_option('pod_itunes_summary');
    if ($pod_itunes_summary) {
        $FeedSettings['itunes_summary'] = stripslashes($pod_itunes_summary);
        $FeedChanges = true;
    }
    $pod_itunes_image = get_option('pod_itunes_image');
    if ($pod_itunes_image) {
        $FeedSettings['itunes_image'] = $pod_itunes_image;
        $FeedChanges = true;
    }
    $iTunesCategories = powerpress_itunes_categories(true);
    for ($x = 1; $x <= 3; $x++) {
        $pod_itunes_cat = get_option('pod_itunes_cat' . $x);
        $find = str_replace('&amp;', '&', $pod_itunes_cat);
        $CatDesc = str_replace('||', ' > ', $find);
        $CatKey = array_search($CatDesc, $iTunesCategories);
        if ($CatKey) {
            $FeedSettings['itunes_cat_' . $x] = $CatKey;
            $FeedChanges = true;
        }
    }
    $pod_itunes_ownername = get_option('pod_itunes_ownername');
    if ($pod_itunes_ownername) {
        $FeedSettings['itunes_talent_name'] = stripslashes($pod_itunes_ownername);
        $FeedChanges = true;
    }
    $pod_itunes_owneremail = get_option('pod_itunes_owneremail');
    if ($pod_itunes_owneremail) {
        $FeedSettings['email'] = $pod_itunes_owneremail;
        $FeedChanges = true;
    }
    $rss_language = get_option('rss_language');
    if ($rss_language) {
        $FeedSettings['rss_language'] = $rss_language;
        $FeedChanges = true;
    }
    $pod_tagline = get_option('pod_tagline');
    if ($pod_tagline) {
        $FeedSettings['itunes_subtitle'] = stripslashes($pod_tagline);
        $FeedChanges = true;
    }
    $pod_itunes_explicit = get_option('pod_itunes_explicit');
    if ($pod_itunes_explicit == 'yes') {
        $FeedSettings['itunes_explicit'] = 1;
        $FeedChanges = true;
    } else {
        if ($pod_itunes_explicit == 'clean') {
            $FeedSettings['itunes_explicit'] = 2;
            $FeedChanges = true;
        }
    }
    if ($FeedChanges) {
        // save these imported feed settings
        powerpress_save_settings($FeedSettings, 'powerpress_feed');
    }
    return $Changes || $FeedChanges;
}
 function import_program_info($channel, $overwrite = false, $download_itunes_image = false)
 {
     $Feed = get_option('powerpress_feed_podcast');
     if (empty($Feed)) {
         $Feed = get_option('powerpress_feed');
     }
     $NewSettings = array();
     $matches = array();
     $program_title = false;
     if (preg_match('|<title>(.*?)</title>|is', $channel, $matches)) {
         $program_title = $this->_sanatize_tag_value($matches[1]);
         if ($overwrite || empty($Feed['title'])) {
             $NewSettings['title'] = $program_title;
         }
     }
     // language
     $language = false;
     if (preg_match('|<language>(.*?)</language>|is', $channel, $matches)) {
         $language = $this->_sanatize_tag_value($matches[1]);
         if ($overwrite || empty($Feed['rss_language'])) {
             $NewSettings['rss_language'] = $language;
         }
     }
     // copyright
     $copyright = false;
     if (preg_match('|<copyright>(.*?)</copyright>|is', $channel, $matches)) {
         $copyright = $this->_sanatize_tag_value($matches[1]);
         if ($overwrite || empty($Feed['copyright'])) {
             $NewSettings['copyright'] = $copyright;
         }
     }
     // description
     $description = false;
     if (preg_match('|<description>(.*?)</description>|is', $channel, $matches)) {
         $description = $this->_sanatize_tag_value($matches[1]);
         if ($overwrite || empty($Feed['description'])) {
             $NewSettings['description'] = $description;
         }
     }
     // itunes:subtitle
     $itunes_subtitle = false;
     if (preg_match('|<itunes:subtitle>(.*?)</itunes:subtitle>|is', $channel, $matches)) {
         $itunes_subtitle = $this->_sanatize_tag_value($matches[1]);
         if ($overwrite || empty($Feed['itunes_subtitle'])) {
             $NewSettings['itunes_subtitle'] = $itunes_subtitle;
         }
     }
     // itunes:summary
     $itunes_summary = false;
     if (preg_match('|<itunes:summary>(.*?)</itunes:summary>|is', $channel, $matches)) {
         $itunes_summary = $this->_sanatize_tag_value($matches[1]);
         if ($overwrite || empty($Feed['itunes_summary'])) {
             $NewSettings['itunes_summary'] = $itunes_summary;
         }
     }
     // itunes:email
     $itunes_email = false;
     if (preg_match('|<itunes:email>(.*?)</itunes:email>|is', $channel, $matches)) {
         $itunes_email = $this->_sanatize_tag_value($matches[1]);
         if ($overwrite || empty($Feed['email'])) {
             $NewSettings['email'] = $itunes_email;
         }
     }
     // itunes:author
     $itunes_talent_name = false;
     if (preg_match('|<itunes:author>(.*?)</itunes:author>|is', $channel, $matches)) {
         $itunes_talent_name = $this->_sanatize_tag_value($matches[1]);
         if ($overwrite || empty($Feed['itunes_talent_name'])) {
             $NewSettings['itunes_talent_name'] = $itunes_talent_name;
         }
     }
     // itunes:explicit
     if (preg_match('|<itunes:explicit>(.*?)</itunes:explicit>|is', $channel, $explicit)) {
         $explicit_array = array('yes' => 1, 'clean' => 2);
         // No need to save 'no'
         $value = strtolower(trim($explicit[1]));
         if (!empty($explicit_array[$value])) {
             if ($overwrite || empty($Feed['itunes_explicit'])) {
                 $NewSettings['itunes_explicit'] = $explicit_array[$value];
             }
         }
     }
     // itunes:image
     $itunes_image = '';
     if (preg_match('/<itunes:image.*href="(.*?)".*(\\/>|>.*<\\/itunes:image>)/is', $channel, $image)) {
         $itunes_image = html_entity_decode(trim($image[1]));
         // Now we need to download and save the image locally...
         // download the image then save it locally...
         if ($download_itunes_image) {
             $upload_path = false;
             $upload_url = false;
             $UploadArray = wp_upload_dir();
             if (false === $UploadArray['error']) {
                 $upload_path = $UploadArray['basedir'] . '/powerpress/';
                 $upload_url = $UploadArray['baseurl'] . '/powerpress/';
                 $filename = str_replace(" ", "_", basename($itunes_image));
                 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));
                     }
                 }
                 $image_data = wp_remote_fopen($itunes_image);
                 if (!empty($image_data)) {
                     file_put_contents($upload_path . $filename, $image_data);
                     $NewSettings['itunes_image'] = $upload_url . $filename;
                     $NewSettings['rss2_image'] = $itunes_image;
                 }
             }
         } else {
             if ($overwrite || empty($Feed['itunes_image'])) {
                 $NewSettings['itunes_image'] = $itunes_image;
                 $NewSettings['rss2_image'] = $itunes_image;
             }
         }
     }
     if (preg_match('|<itunes:author>(.*?)</itunes:author>|is', $channel, $matches)) {
         $itunes_talent_name = $this->_sanatize_tag_value($matches[1]);
         if ($overwrite || empty($Feed['itunes_talent_name'])) {
             $NewSettings['itunes_talent_name'] = $itunes_talent_name;
         }
     }
     // itunes:category (up to 3)
     $itunes_categories = false;
     if (preg_match_all('|<itunes:category.*text="(.*?)"|is', $channel, $matches)) {
         $pos = 1;
         $itunes_categories = $matches[1];
         $Categories = powerpress_itunes_categories();
         $Categories = array_map('strtolower', $Categories);
         $cats_by_title = array_flip($Categories);
         $FoundCategories = array();
         while (list($index, $category) = each($itunes_categories)) {
             $category = str_replace('&amp;', '&', $category);
             $category = strtolower($category);
             if (!empty($cats_by_title[$category])) {
                 $FoundCategories[] = $cats_by_title[$category];
             }
         }
         // Now walk trouigh found categories and stack them correctly...
         // this logic rebuilds the categorires in the correct order no matter what method the service stacked them
         $FinalCats = array(1 => '', 2 => '', 3 => '');
         $last_category_index = 1;
         while (list($index, $cat_id) = each($FoundCategories)) {
             if (!empty($FinalCats[$last_category_index])) {
                 if (intval(substr($FinalCats[$last_category_index], 3)) > 0) {
                     $last_category_index++;
                 } else {
                     if (intval(substr($FinalCats[$last_category_index], 0, 2)) != intval(substr($cat_id, 0, 2))) {
                         $last_category_index++;
                     }
                 }
                 // else we can overwrite this category with subcategory
             }
             if ($last_category_index > 3) {
                 break;
             }
             // We are at the max cats available...
             $FinalCats[$last_category_index] = $cat_id;
         }
         while (list($field_no, $cat_id) = each($FinalCats)) {
             if (empty($cat_id)) {
                 continue;
             }
             $field = sprintf('itunes_cat_%d', $field_no);
             if ($overwrite || empty($Feed[$field])) {
                 $NewSettings[$field] = $cat_id;
             }
         }
     }
     if (!empty($NewSettings)) {
         // Save here..
         if (get_option('powerpress_feed_podcast')) {
             // If the settings were moved to the podcast channels feature...
             powerpress_save_settings($NewSettings, 'powerpress_feed_podcast');
             // save a copy here if that is the case.
         } else {
             powerpress_save_settings($NewSettings, 'powerpress_feed');
         }
         echo '<hr />';
         echo '<p><strong>' . __('Program information imported', 'powerpress') . '</strong></p>';
         echo '<ul class="ul-disc">';
         while (list($field, $value) = each($NewSettings)) {
             if ($field == 'rss2_image') {
                 continue;
             }
             echo '<li>';
             switch ($field) {
                 case 'title':
                     echo __('Feed Title (Show Title)', 'powerpress');
                     break;
                 case 'rss_language':
                     echo __(' Feed Language', 'powerpress');
                     break;
                 case 'description':
                     echo __('Feed Description', 'powerpress');
                     break;
                 case 'copyright':
                     echo __('Copyright', 'powerpress');
                     break;
                 case 'itunes_talent_name':
                     echo __('iTunes Author Name', 'powerpress');
                     break;
                 case 'itunes_summary':
                     echo __('iTunes Program Summary', 'powerpress');
                     break;
                 case 'itunes_subtitle':
                     echo __('iTunes Program Subtitle', 'powerpress');
                     break;
                 case 'itunes_image':
                     echo __('iTunes Image', 'powerpress');
                     break;
                 case 'itunes_explicit':
                     echo __('iTunes Explicit', 'powerpress');
                     break;
                 case 'email':
                     echo __('iTunes Email', 'powerpress');
                     break;
                 case 'itunes_cat_1':
                     echo __('iTunes Category', 'powerpress');
                     break;
                 case 'itunes_cat_2':
                     echo __('iTunes Category 2', 'powerpress');
                     break;
                 case 'itunes_cat_3':
                     echo __('iTunes Category 3', 'powerpress');
                     break;
                 default:
                     echo $field . ': ' . htmlspecialchars($value);
                     break;
             }
             echo '</li>';
         }
         echo '</ul>';
     }
 }