function display()
    {
        global $wp_db_version;
        global $fwp_post;
        if (FeedWordPress::needs_upgrade()) {
            fwp_upgrade_page();
            return;
        }
        // If this is a POST, validate source and user credentials
        FeedWordPressCompatibility::validate_http_request('feedwordpress_performance', 'manage_options');
        if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
            $this->accept_POST($fwp_post);
            do_action('feedwordpress_admin_page_performance_save', $GLOBALS['fwp_post'], $this);
        }
        ////////////////////////////////////////////////
        // Prepare settings page ///////////////////////
        ////////////////////////////////////////////////
        $this->display_update_notice_if_updated('Performance');
        $this->open_sheet('FeedWordPress Performance');
        ?>
		<div id="post-body">
		<?php 
        $boxes_by_methods = array('performance_box' => __('Performance'));
        foreach ($boxes_by_methods as $method => $title) {
            fwp_add_meta_box('feedwordpress_' . $method, $title, array('FeedWordPressPerformancePage', $method), $this->meta_box_context(), $this->meta_box_context());
        }
        do_action('feedwordpress_admin_page_performance_meta_boxes', $this);
        ?>
			<div class="metabox-holder">
			<?php 
        fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
        ?>
			</div> <!-- class="metabox-holder" -->
		</div> <!-- id="post-body" -->

		<?php 
        $this->close_sheet();
    }
function fwp_posts_page()
{
    global $wp_db_version;
    global $fwp_post;
    if (FeedWordPress::needs_upgrade()) {
        fwp_upgrade_page();
        return;
    }
    // If this is a POST, validate source and user credentials
    FeedWordPressCompatibility::validate_http_request('feedwordpress_posts_settings', 'manage_links');
    $link = FeedWordPressAdminPage::submitted_link();
    $postsPage = new FeedWordPressPostsPage($link);
    $mesg = null;
    ////////////////////////////////////////////////
    // Process POST request, if any ////////////////
    ////////////////////////////////////////////////
    if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
        $postsPage->accept_POST($fwp_post);
        do_action('feedwordpress_admin_page_posts_save', $fwp_post, $postsPage);
    }
    $postsPage->ajax_interface_js();
    if ($postsPage->updated) {
        ?>
<div class="updated"><p>Syndicated posts settings updated.</p></div>
<?php 
    } elseif (!is_null($mesg)) {
        ?>
<div class="updated"><p><?php 
        print esc_html($mesg);
        ?>
</p></div>
<?php 
    }
    ?>

<?php 
    $links = FeedWordPress::syndicated_links();
    $postsPage->open_sheet('Syndicated Posts & Links');
    ?>
<style type="text/css">
	table.edit-form th, table.form-table th { width: 27%; vertical-align: top; }
	table.edit-form td, table.form-table td { width: 73%; vertical-align: top; }
	ul.options { margin: 0; padding: 0; list-style: none; }
</style>
<div id="post-body">
<?php 
    $boxes_by_methods = array('publication_box' => __('Syndicated Posts'), 'links_box' => __('Links'), 'formatting_box' => __('Formatting'), 'comments_and_pings_box' => __('Comments & Pings'), 'custom_post_settings_box' => __('Custom Post Settings (to apply to each syndicated post)'));
    foreach ($boxes_by_methods as $method => $title) {
        fwp_add_meta_box('feedwordpress_' . $method, $title, array('FeedWordPressPostsPage', $method), $postsPage->meta_box_context(), $postsPage->meta_box_context());
    }
    do_action('feedwordpress_admin_page_posts_meta_boxes', $postsPage);
    ?>
	<div class="metabox-holder">
<?php 
    fwp_do_meta_boxes($postsPage->meta_box_context(), $postsPage->meta_box_context(), $postsPage);
    ?>
	</div> <!-- class="metabox-holder" -->
</div> <!-- id="post-body" -->
<?php 
    $postsPage->close_sheet();
}
    function display()
    {
        global $fwp_post;
        global $post_source;
        if (FeedWordPress::needs_upgrade()) {
            fwp_upgrade_page();
            return;
        }
        // Allow overriding of normal source for FeedFinder, which may
        // be called from multiple points.
        if (isset($post_source) and !is_null($post_source)) {
            $source = $post_source;
        } else {
            $source = get_class($this);
        }
        // If this is a POST, validate source and user credentials
        FeedWordPressCompatibility::validate_http_request($source, 'manage_links');
        if (isset($_REQUEST['feedfinder']) or isset($_REQUEST['action']) and $_REQUEST['action'] == 'feedfinder' or isset($_REQUEST['action']) and $_REQUEST['action'] == FWP_SYNDICATE_NEW) {
            return $this->display_feedfinder();
            // re-route to Feed Finder page
        } else {
            if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
                $this->accept_POST($fwp_post);
                do_action('feedwordpress_admin_page_feeds_save', $GLOBALS['fwp_post'], $this);
            }
            ////////////////////////////////////////////////
            // Prepare settings page ///////////////////////
            ////////////////////////////////////////////////
            $this->ajax_interface_js();
            $this->display_update_notice_if_updated('Syndicated feed');
            $this->open_sheet('Feed and Update');
            ?>
			<div id="post-body">
			<?php 
            ////////////////////////////////////////////////
            // Display settings boxes //////////////////////
            ////////////////////////////////////////////////
            $boxes_by_methods = array('feed_information_box' => __('Feed Information'), 'global_feeds_box' => __('Update Scheduling'), 'updated_posts_box' => __('Updated Posts'), 'posts_box' => __('Syndicated Posts, Links, Comments & Pings'), 'authors_box' => __('Syndicated Authors'), 'categories_box' => __('Categories' . FEEDWORDPRESS_AND_TAGS), 'custom_settings_box' => __('Custom Feed Settings (for use in templates)'));
            if ($this->for_default_settings()) {
                unset($boxes_by_methods['custom_settings_box']);
            }
            foreach ($boxes_by_methods as $method => $row) {
                if (is_array($row)) {
                    $id = $row['id'];
                    $title = $row['title'];
                } else {
                    $id = 'feedwordpress_' . $method;
                    $title = $row;
                }
                fwp_add_meta_box($id, $title, array(get_class($this), $method), $this->meta_box_context(), $this->meta_box_context());
            }
            do_action('feedwordpress_admin_page_feeds_meta_boxes', $this);
            ?>
			<div class="metabox-holder">
			<?php 
            fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
            ?>
			</div> <!-- class="metabox-holder" -->
			</div> <!-- id="post-body" -->
			<?php 
            $this->close_sheet();
            ?>

			<script type="text/javascript">
				var els = ['name', 'description', 'url'];
				for (var i = 0; i < els.length; i++) {
					contextual_appearance(
						/*item=*/ 'basics-hardcode-'+els[i],
						/*appear=*/ 'basics-'+els[i]+'-view',
						/*disappear=*/ 'basics-'+els[i]+'-edit',
						/*value=*/ 'no',
						/*visibleStyle=*/ 'block',
						/*checkbox=*/ true
					);
				} /* for */
			</script>
			<?php 
        }
        return false;
        // Don't continue
    }
function fwp_authors_page()
{
    global $wp_db_version;
    if (FeedWordPress::needs_upgrade()) {
        fwp_upgrade_page();
        return;
    }
    FeedWordPressCompatibility::validate_http_request('feedwordpress_author_settings', 'manage_links');
    $link = FeedWordPressAdminPage::submitted_link();
    $authorsPage = new FeedWordPressAuthorsPage($link);
    $mesg = null;
    if (isset($GLOBALS['fwp_post']['fix_mismatch'])) {
        $fix_mismatch_to_id = $GLOBALS['fwp_post']['fix_mismatch_to'];
        $fix_mismatch_from_id = (int) $GLOBALS['fwp_post']['fix_mismatch_from'];
        if (is_numeric($fix_mismatch_from_id)) {
            // Make a list of all the items by this author syndicated from this feed...
            $args = array('posts_per_page' => -1, 'meta_key' => 'syndication_feed_id', 'meta_value' => $link->id, 'post_author' => $fix_mismatch_from_id);
            $query = new WP_Query($args);
            $mesg = '';
            $post_ids = array();
            if ($query->have_posts()) {
                while ($query->have_posts()) {
                    global $post;
                    $query->the_post();
                    if (is_numeric($fix_mismatch_to_id)) {
                        $post->post_author = $fix_mismatch_to_id;
                        $new_post = (array) $post;
                        wp_insert_post($new_post);
                        $mesg_action = 'Re-assigned';
                        $post_ids[] = get_the_ID();
                    } else {
                        if ($fix_mismatch_to_id == 'filter') {
                            wp_delete_post($post->ID);
                            $mesg_action = 'Re-assigned';
                            $post_ids[] = get_the_ID();
                        }
                    }
                }
                $mesg = $mesg_action . ' ' . count($post_ids) . ' post' . (count($post_ids) == 1 ? '' : 's') . '.';
            } else {
                $mesg = "Couldn't find any posts that matched your criteria.";
            }
        }
        $updated_link = false;
    } elseif (isset($GLOBALS['fwp_post']['save'])) {
        if (is_object($link) and $link->found()) {
            $alter = array();
            // Unfamiliar author rule
            if (isset($GLOBALS['fwp_post']["unfamiliar_author"])) {
                if ('site-default' == $GLOBALS['fwp_post']["unfamiliar_author"]) {
                    unset($link->settings["unfamiliar author"]);
                } else {
                    $link->settings["unfamiliar author"] = $GLOBALS['fwp_post']["unfamiliar_author"];
                }
            }
            // Handle author mapping rules
            if (isset($GLOBALS['fwp_post']['author_rules_name']) and isset($GLOBALS['fwp_post']['author_rules_action'])) {
                unset($link->settings['map authors']);
                foreach ($GLOBALS['fwp_post']['author_rules_name'] as $key => $name) {
                    // Normalize for case and whitespace
                    $name = strtolower(trim($name));
                    $author_action = strtolower(trim($GLOBALS['fwp_post']['author_rules_action'][$key]));
                    if (strlen($name) > 0) {
                        $link->settings['map authors']['name'][$name] = $author_action;
                    }
                }
            }
            if (isset($GLOBALS['fwp_post']['add_author_rule_name']) and isset($GLOBALS['fwp_post']['add_author_rule_action'])) {
                $name = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_name']));
                $author_action = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_action']));
                if (strlen($name) > 0) {
                    $link->settings['map authors']['name'][$name] = $author_action;
                }
            }
            // Save settings
            $link->save_settings(true);
            $updated_link = true;
            // Reset, reload
            $link_id = $link->id;
            unset($link);
            $link = new SyndicatedLink($link_id);
        } else {
            update_option('feedwordpress_unfamiliar_author', $GLOBALS['fwp_post']['unfamiliar_author']);
            if (isset($GLOBALS['fwp_post']['match_author_by_email']) and $GLOBALS['fwp_post']['match_author_by_email'] == 'yes') {
                update_option('feedwordpress_do_not_match_author_by_email', 'no');
            } else {
                update_option('feedwordpress_do_not_match_author_by_email', 'yes');
            }
            if (isset($GLOBALS['fwp_post']['null_emails'])) {
                update_option('feedwordpress_null_email_set', $GLOBALS['fwp_post']['null_emails']);
            }
            $updated_link = true;
        }
        do_action('feedwordpress_admin_page_authors_save', $GLOBALS['fwp_post'], $authorsPage);
        $authorsPage->refresh_author_list();
    } else {
        $updated_link = false;
    }
    ////////////////////////////////////////////////
    // Prepare settings page ///////////////////////
    ////////////////////////////////////////////////
    if ($updated_link) {
        ?>
<div class="updated"><p>Syndicated author settings updated.</p></div>
<?php 
    } elseif (!is_null($mesg)) {
        ?>
<div class="updated"><p><?php 
        print esc_html($mesg);
        ?>
</p></div>
<?php 
    }
    if (function_exists('add_meta_box')) {
        add_action(FeedWordPressCompatibility::bottom_script_hook(__FILE__), array($authorsPage, 'fix_toggles'), 10000);
        FeedWordPressSettingsUI::ajax_nonce_fields();
    }
    $authorsPage->open_sheet('Syndicated Author');
    ?>
	<div id="post-body">
	<?php 
    ////////////////////////////////////////////////
    // Display settings boxes //////////////////////
    ////////////////////////////////////////////////
    $boxes_by_methods = array('syndicated_authors_box' => __('Syndicated Authors'), 'fix_authors_box' => __('Reassign Authors'));
    if ($authorsPage->for_default_settings()) {
        unset($boxes_by_methods['fix_authors_box']);
    }
    foreach ($boxes_by_methods as $method => $row) {
        if (is_array($row)) {
            $id = $row['id'];
            $title = $row['title'];
        } else {
            $id = 'feedwordpress_' . $method;
            $title = $row;
        }
        fwp_add_meta_box($id, $title, array('FeedWordPressAuthorsPage', $method), $authorsPage->meta_box_context(), $authorsPage->meta_box_context());
    }
    do_action('feedwordpress_admin_page_authors_meta_boxes', $authorsPage);
    ?>
	<div class="metabox-holder">
<?php 
    fwp_do_meta_boxes($authorsPage->meta_box_context(), $authorsPage->meta_box_context(), $authorsPage);
    ?>
	</div> <!-- class="metabox-holder" -->
</div> <!-- id="post-body" -->
<?php 
    $authorsPage->close_sheet();
    ?>

<script type="text/javascript">
<?php 
    if (!is_object($link) or !$link->found()) {
        ?>
	contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', 'block', /*checkbox=*/ true);
<?php 
    }
    ?>
</script>
<?php 
}
    function display()
    {
        if (FeedWordPress::needs_upgrade()) {
            fwp_upgrade_page();
            return;
        }
        ?>
		<?php 
        $cont = true;
        $dispatcher = array("feedfinder" => 'fwp_feedfinder_page', FWP_SYNDICATE_NEW => 'fwp_feedfinder_page', "switchfeed" => 'fwp_switchfeed_page', FWP_UNSUB_CHECKED => 'fwp_multidelete_page', FWP_DELETE_CHECKED => 'fwp_multidelete_page', 'Unsubscribe' => 'fwp_multidelete_page', FWP_RESUB_CHECKED => 'fwp_multiundelete_page');
        if (isset($_REQUEST['action']) and isset($dispatcher[$_REQUEST['action']])) {
            $method = $dispatcher[$_REQUEST['action']];
            $cont = call_user_func($method);
        }
        if ($cont) {
            ?>
		<style type="text/css">
			.heads-up {
				background-color: #d0d0d0;
				color: black;
				padding: 1.0em;
				margin: 0.5em 4.0em !important;
			}
			.update-form.with-donation {
				margin-right: 50%;
				min-height: 255px;
			}
			.donation-form, .donation-thanks {
				background-color: #ffffcc;
				text-align: left;
				padding: 0.5em 0.5em;
				border-left: thin dashed #777777;
				font-size: 70%;
				position: absolute;
				top: 0; bottom: 0; right: 0; left: auto;
				width: 50%;		
			}
			.donation-thanks {
				background-color: #ccffcc;
			}
			.donation-thanks .signature {
				text-align: right;
				font-style: italic;
			}
			.donation-form h4, .donation-thanks h4 {
				font-size: 10px;
				text-align: center;
				border-bottom: 1px solid #777777;
				margin: 0px;
			}
			.donation-form .donate  {
				text-align: center;
			}
			.donation-form .sod-off {
				padding-top: 0.5em;
				margin-top: 0.5em;
				border-top: thin solid #777777;
			}
			.feed-missing {
				background-color:#FFFFD0;
			}
			.unsubscribed tr {
				background-color: #FFE0E0;
			}
			.unsubscribed tr.alternate {
				background-color: #FFF0F0;
			}
			tr.feed-error {
				background-color: #FFFFD0;
			}
		</style>
		<?php 
            $links = $this->sources('Y');
            $potential_updates = (!$this->show_inactive() and count($this->sources('Y')) > 0);
            $this->open_sheet('Syndicated Sites');
            ?>
			<div id="post-body">
			<?php 
            if ($potential_updates or count($this->updates_requested()) > 0) {
                fwp_add_meta_box('feedwordpress_update_box', __('Update feeds now'), 'fwp_syndication_manage_page_update_box', $this->meta_box_context(), $this->meta_box_context());
            }
            fwp_add_meta_box('feedwordpress_feeds_box', __('Syndicated sources'), 'fwp_syndication_manage_page_links_box', $this->meta_box_context(), $this->meta_box_context());
            if (FeedWordPressCompatibility::test_version(0, FWP_SCHEMA_25)) {
                fwp_add_meta_box('feedwordpress_add_feed_box', 'Add a new syndicated source', 'fwp_syndication_manage_page_add_feed_box', $this->meta_box_context(), $this->meta_box_context());
            }
            do_action('feedwordpress_admin_page_syndication_meta_boxes', $this);
            ?>
			<div class="metabox-holder">		
			<?php 
            fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
            ?>
			</div> <!-- class="metabox-holder" -->
			</div> <!-- id="post-body" -->
		
			<?php 
            $this->close_sheet(NULL);
            ?>
		
			<div style="display: none">
			<div id="tags-input"></div> <!-- avoid JS error from WP 2.5 bug -->
			</div>
		<?php 
        }
    }
function fwp_categories_page()
{
    global $wp_db_version;
    if (FeedWordPress::needs_upgrade()) {
        fwp_upgrade_page();
        return;
    }
    FeedWordPressCompatibility::validate_http_request('feedwordpress_categories_settings', 'manage_links');
    $link = FeedWordPressAdminPage::submitted_link();
    $catsPage = new FeedWordPressCategoriesPage($link);
    $mesg = null;
    ////////////////////////////////////////////////
    // Process POST request, if any /////////////////
    ////////////////////////////////////////////////
    if (isset($GLOBALS['fwp_post']['save']) or isset($GLOBALS['fwp_post']['submit'])) {
        $saveCats = array();
        if (isset($GLOBALS['fwp_post']['post_category'])) {
            foreach ($GLOBALS['fwp_post']['post_category'] as $cat_id) {
                $saveCats[] = '{#' . $cat_id . '}';
            }
        }
        // Different variable names to cope with different WordPress AJAX UIs
        $syndicatedTags = array();
        if (isset($GLOBALS['fwp_post']['tax_input']['post_tag'])) {
            $syndicatedTags = explode(",", $GLOBALS['fwp_post']['tax_input']['post_tag']);
        } elseif (isset($GLOBALS['fwp_post']['tags_input'])) {
            $syndicatedTags = explode(",", $GLOBALS['fwp_post']['tags_input']);
        }
        $syndicatedTags = array_map('trim', $syndicatedTags);
        if (is_object($link) and $link->found()) {
            $alter = array();
            // Categories
            if (!empty($saveCats)) {
                $link->settings['cats'] = $saveCats;
            } else {
                unset($link->settings['cats']);
            }
            // Tags
            $link->settings['tags'] = $syndicatedTags;
            // Unfamiliar categories
            if (isset($GLOBALS['fwp_post']["unfamiliar_category"])) {
                if ('site-default' == $GLOBALS['fwp_post']["unfamiliar_category"]) {
                    unset($link->settings["unfamiliar category"]);
                } else {
                    $link->settings["unfamiliar category"] = $GLOBALS['fwp_post']["unfamiliar_category"];
                }
            }
            // Category spitting regex
            if (isset($GLOBALS['fwp_post']['cat_split'])) {
                if (strlen(trim($GLOBALS['fwp_post']['cat_split'])) > 0) {
                    $link->settings['cat_split'] = trim($GLOBALS['fwp_post']['cat_split']);
                } else {
                    unset($link->settings['cat_split']);
                }
            }
            // Save settings
            $link->save_settings(true);
            $catsPage->updated = true;
            // Reset, reload
            $link_id = $link->id;
            unset($link);
            $link = new SyndicatedLink($link_id);
        } else {
            // Categories
            if (!empty($saveCats)) {
                update_option('feedwordpress_syndication_cats', implode(FEEDWORDPRESS_CAT_SEPARATOR, $saveCats));
            } else {
                delete_option('feedwordpress_syndication_cats');
            }
            // Tags
            if (!empty($syndicatedTags)) {
                update_option('feedwordpress_syndication_tags', implode(FEEDWORDPRESS_CAT_SEPARATOR, $syndicatedTags));
            } else {
                delete_option('feedwordpress_syndication_tags');
            }
            update_option('feedwordpress_unfamiliar_category', $_REQUEST['unfamiliar_category']);
            $catsPage->updated = true;
        }
        do_action('feedwordpress_admin_page_categories_save', $GLOBALS['fwp_post'], $catsPage);
    } else {
        $catsPage->updated = false;
    }
    ////////////////////////////////////////////////
    // Prepare settings page ///////////////////////
    ////////////////////////////////////////////////
    $catsPage->display_update_notice_if_updated('Syndicated categories' . FEEDWORDPRESS_AND_TAGS, $mesg);
    $catsPage->open_sheet('Categories' . FEEDWORDPRESS_AND_TAGS);
    ?>
	<style type="text/css">
		table.edit-form th { width: 27%; vertical-align: top; }
		table.edit-form td { width: 73%; vertical-align: top; }
		table.edit-form td ul.options { margin: 0; padding: 0; list-style: none; }
	</style>

	<div id="post-body">
	<?php 
    ////////////////////////////////////////////////
    // Display settings boxes //////////////////////
    ////////////////////////////////////////////////
    $boxes_by_methods = array('feed_categories_box' => __('Feed Categories' . FEEDWORDPRESS_AND_TAGS), 'categories_box' => array('title' => __('Categories'), 'id' => 'categorydiv'), 'tags_box' => __('Tags'));
    if (!FeedWordPressCompatibility::post_tags()) {
        unset($boxes_by_methods['tags_box']);
    }
    foreach ($boxes_by_methods as $method => $row) {
        if (is_array($row)) {
            $id = $row['id'];
            $title = $row['title'];
        } else {
            $id = 'feedwordpress_' . $method;
            $title = $row;
        }
        fwp_add_meta_box($id, $title, array('FeedWordPressCategoriesPage', $method), $catsPage->meta_box_context(), $catsPage->meta_box_context());
    }
    do_action('feedwordpress_admin_page_categories_meta_boxes', $catsPage);
    ?>
	<div class="metabox-holder">
<?php 
    fwp_do_meta_boxes($catsPage->meta_box_context(), $catsPage->meta_box_context(), $catsPage);
    ?>
	</div> <!-- class="metabox-holder" -->
	</div> <!-- id="post-body" -->
	<?php 
    $catsPage->close_sheet();
}