on_unfamiliar() public static méthode

* FeedWordPress::syndicated_status()
public static on_unfamiliar ( $what = 'author' )
	function feed_categories_box ($page, $box = NULL) {
		$link = $page->link;
		
		$globalPostType = get_option('feedwordpress_syndicated_post_type', 'post');
		if ($this->for_feed_settings()) :
			$post_type = $link->setting('syndicated post type', 'syndicated_post_type', 'post');
		else :
			$post_type = $globalPostType;
		endif;
		$taxonomies = get_object_taxonomies(array('object_type' => $post_type), 'names');

		$unmatched = array('category' => array(), 'post_tag' => array());
		$matchUl = array('cats' => array(), 'tags' => array(), 'filter' => array());
		$tagLikeTaxonomies = array();
		foreach ($taxonomies as $tax) :
			$taxonomy = get_taxonomy($tax);
			
			if (!$taxonomy->hierarchical) :
				$tagLikeTaxonomies[] = $tax;
			endif;

			$name = 'create:'.$tax;
			foreach (array('category', 'post_tag') as $what) :
				$unmatched[$what][$name] = array(
					'label' => $this->unfamiliar_category_label($name),
				);
				$unmatchedRadio[$what][$name] = '';
			endforeach;

			foreach (array('cats', 'tags', 'filter') as $what) :
				$matchUl[$what][$tax] = array(
				'checked' => '',
				'labels' => $taxonomy->labels,
				);
			endforeach;
		endforeach;
		
		foreach ($unmatched as $what => $um) :
			$unmatched[$what]['null'] = array('label' => __('Don\'t create any matching terms'));
			$unmatchedRadio[$what]['null'] = '';
		endforeach;
		
		$globalUnmatched = array(
			'category' => FeedWordPress::on_unfamiliar('category'),
			'post_tag' => FeedWordPress::on_unfamiliar('post_tag'),
		);
		foreach ($globalUnmatched as $what => $value) :
			if ($value=='create') : $value = 'create:category'; endif;
			if ($value=='tag') : $value = 'create:post_tag'; endif;
			$globalUnmatched[$what] = $value;
		endforeach;
		
		$globalMatch['cats'] = get_option('feedwordpress_match_cats', $taxonomies);
		$globalMatch['tags'] = get_option('feedwordpress_match_tags', $tagLikeTaxonomies);
		$globalMatch['filter'] = get_option('feedwordpress_match_filter', array());
		
		$globalMatchLabels = array();
		$nothingDoing = array('cats' => "won't try to match", 'tags' => "won't try to match", "filter" => "won't filter");
		
		foreach ($globalMatch as $what => $domain) :
			$labels = array(); $domain = array_filter($domain, 'remove_dummy_zero');
			foreach ($domain as $tax) :
				$tax = get_taxonomy($tax);
				$labels[] = $tax->labels->name;
			endforeach;
			
			if (count($labels) > 0) :
				$globalMatchLabels[$what] = implode(", ", $labels);
			else :
				$globalMatchLabels[$what] = $nothingDoing[$what];
			endif;
		endforeach;

		if ($this->for_feed_settings()) :
			$href = "admin.php?page={$GLOBALS['fwp_path']}/".basename(__FILE__);

			foreach ($unmatched as $what => $um) :
				// Is the global default setting appropriate to this post type?
				$GUC = $globalUnmatched[$what];
				if (isset($um[$GUC])) :
					// Yup. Let's add a site-default option
					$currently = $um[$GUC]['label'];
					$defaultLi = array(
					'site-default' => array(
						'label' => sprintf(
							__('Use the <a href="%s">site-wide setting</a> <span class="current-setting">Currently: <strong>%s</strong></span>'),
							$href,
							$currently
						),
					), );
					$unmatchedColumns[$what] = array(
						$defaultLi,
					);
					$unmatchedDefault[$what] = 'site-default';
					$unmatchedRadio[$what]['site-default'] = '';
				else :
					$opts = array_keys($unmatched[$what]);
					$unmatchedDefault[$what] = $opts[0];
					$unmatchedColumns[$what] = array();
				endif;
				
				$ucKey[$what] = $link->setting("unfamiliar $what", NULL, NULL);
			endforeach;
			
			$match['cats'] = $this->link->setting('match/cats', NULL, NULL);
			$match['tags'] = $this->link->setting('match/tags', NULL, NULL);
			$match['filter'] = $this->link->setting('match/filter', NULL, NULL);
		else :
			foreach ($unmatched as $what => $um) :
				$ucKey[$what] = FeedWordPress::on_unfamiliar($what); 
			endforeach;

			$match = $globalMatch;
		endif;
		
		foreach ($ucKey as $what => $uck) :
			if ($uck == 'tag') : $uck = 'create:post_tag'; endif;
			if ($uck == 'create') : $uck = 'create:category'; endif;
			
			if (!is_string($uck)) :
				$uck = $unmatchedDefault[$what];
			endif;
			$ucKey[$what] = $uck;
			
			if (!array_key_exists($uck, $unmatchedRadio[$what])) :
				$obsoleteLi = array(
					$uck => array(
					'label' => ' <span style="font-style: italic; color: #777;">'.$this->unfamiliar_category_label($uck).'</span> <span style="background-color: #ffff90; color: black;">(This setting is no longer applicable to the type of post syndicated from this feed!)</span><p>Please change this one of the following settings:</p>',
					),
				);
				$unmatched[$what] = array_merge($obsoleteLi, $unmatched[$what]);
				$unmatchedRadio[$what][$uck] = ' disabled="disabled"';
			endif;
			
			$unmatchedRadio[$what][$uck] .= ' checked="checked"';
			
			$unmatchedColumns[$what][] = $unmatched[$what];
		endforeach;
		
		$defaulted = array();
		foreach ($match as $what => $set) :
			$defaulted[$what] = false;
			if (is_null($set) or (count($set) < 1)) :
				$defaulted[$what] = true;
				if ($this->for_feed_settings()) :
					$set = $globalMatch[$what];
					$match[$what] = $globalMatch[$what];
				endif;
			endif;
			
			if (!$defaulted[$what] or $this->for_feed_settings()) :
				foreach ($set as $against) :
					if (array_key_exists($against, $matchUl[$what])) :
						$matchUl[$what][$against]['checked'] = ' checked="checked"';
					endif;
				endforeach;
			endif;
		endforeach;

		// Hey ho, let's go...
		$offerSiteWideSettings = ($page->for_feed_settings() and ($post_type==$globalPostType));
		?>
<table class="edit-form narrow">
<tr>
<th scope="row">Match feed categories:</th>
<td><input type="hidden" name="match_categories[cats][]" value="0" />
<?php if ($offerSiteWideSettings) : ?>
	<table class="twofer">
	<tbody>
	<tr><td class="equals first <?php if ($defaulted['cats']) : ?>active<?php else: ?>inactive<?php endif; ?>"><p><label><input type="radio" name="match_default[cats]"
value="yes" <?php if ($defaulted['cats']) : ?> checked="checked"<?php endif; ?> />
Use the <a href="<?php print $href; ?>">site-wide setting</a>
<span class="current-setting">Currently: <strong><?php print $globalMatchLabels['cats']; ?></strong></span></label></p></td>
	<td class="equals second <?php if ($defaulted['cats']) : ?>inactive<?php else: ?>active<?php endif; ?>"><p><label><input type="radio" name="match_default[cats]"
value="no" <?php if (!$defaulted['cats']) : ?> checked="checked"<?php endif; ?> />
Do something different with this feed.</label>
<?php else : ?>
	<p>
<?php endif; ?>
When a feed provides categories for a post, try to match those categories
locally with:</p>
<ul class="options compact">
<?php foreach ($matchUl['cats'] as $name => $li) : ?>
	<li><label><input type="checkbox"
	name="match_categories[cats][]" value="<?php print $name; ?>"
	<?php print $li['checked']; ?> /> <?php $l = $li['labels']; print $l->name; ?></label></li>
<?php endforeach; ?>
</ul>
<?php if ($offerSiteWideSettings) : ?>
	</td></tr>
	</tbody>
	</table>
<?php endif; ?>
</td>
</tr>

<tr>
<th scope="row">Unmatched categories:</th>
<td><p>When <?php print $this->these_posts_phrase(); ?> have categories on
the feed that don't have any local matches yet...</p>

<?php	if (count($unmatchedColumns['category']) > 1) : ?>
	<table class="twofer">
<?php	else : ?>
	<table style="width: 100%">
<?php	endif; ?>
	<tbody>
	<tr>
	<?php foreach ($unmatchedColumns['category'] as $index => $column) : ?>
		<td class="equals <?php print (($index == 0) ? 'first' : 'second'); ?> inactive"><ul class="options">
		<?php foreach ($column as $name => $li) : ?>
			<li><label><input type="radio" name="unfamiliar_category" value="<?php print $name; ?>"<?php print $unmatchedRadio['category'][$name]; ?> /> <?php print $li['label']; ?></label></li>
		<?php endforeach; ?>
		</ul></td>
	<?php endforeach; ?>
	</tr>
	</tbody>
	</table>
</td></tr>

<tr>
<th scope="row">Match inline tags:
<p class="setting-description">Applies only to inline tags marked
as links in the text of syndicated posts, using the
<code>&lt;a rel="tag"&gt;...&lt;/a&gt;</code> microformat.
Most feeds with "tags" just treat them as normal feed categories,
like those handled above.</p>
</th>
<td><input type="hidden" name="match_categories[tags][]" value="0" />
<?php if ($offerSiteWideSettings) : ?>
	<table class="twofer">
	<tbody>
	<tr><td class="equals first <?php if ($defaulted['tags']) : ?>active<?php else: ?>inactive<?php endif; ?>"><p><label><input type="radio" name="match_default[tags]"
value="yes" <?php if ($defaulted['tags']) : ?> checked="checked"<?php endif; ?> />
Use the <a href="<?php print $href; ?>">site-wide setting</a>
<span class="current-setting">Currently: <strong><?php print $globalMatchLabels['tags']; ?></strong></span></label></p>
</td>
	<td class="equals second <?php if ($defaulted['tags']) : ?>inactive<?php else: ?>active<?php endif; ?>"><p><label><input type="radio" name="match_default[tags]"
value="no" <?php if (!$defaulted['tags']) : ?> checked="checked"<?php endif; ?> />
Do something different with this feed.</label>
<?php else : ?>
	<p>
<?php endif; ?>
When a feed provides tags inline in a post, try to match those tags
locally with:</p>
<ul class="options compact">
<?php foreach ($matchUl['tags'] as $name => $li) : ?>
	<li><label><input type="checkbox"
	name="match_categories[tags][]" value="<?php print $name; ?>"
	<?php print $li['checked']; ?> /> <?php $l = $li['labels']; print $l->name; ?></label></li>
<?php endforeach; ?>
</ul>
<?php if ($offerSiteWideSettings) : ?>
	</td></tr>
	</tbody>
	</table>
<?php endif; ?>
</td>
</tr>

<tr>
<th scope="row">Unmatched inline tags:</th>
<td><p>When the text of <?php print $this->these_posts_phrase(); ?> contains
inline tags that don't have any local matches yet...</p>

<?php	if (count($unmatchedColumns['post_tag']) > 1) : ?>
	<table class="twofer">
<?php	else : ?>
	<table style="width: 100%">
<?php	endif; ?>
	<tbody>
	<tr>
	<?php foreach ($unmatchedColumns['post_tag'] as $index => $column) : ?>
		<td class="equals <?php print (($index == 0) ? 'first' : 'second'); ?> inactive"><ul class="options">
		<?php foreach ($column as $name => $li) : ?>
			<li><label><input type="radio" name="unfamiliar_post_tag" value="<?php print $name; ?>"<?php print $unmatchedRadio['post_tag'][$name]; ?> /> <?php print $li['label']; ?></label></li>
		<?php endforeach; ?>
		</ul></td>
	<?php endforeach; ?>
	</tr>
	</tbody>
	</table>

</td></tr>

<tr>
<th scope="row">Filter:</th>
<td><input type="hidden" name="match_categories[filter][]" value="0" />
<?php if ($offerSiteWideSettings) : ?>
	<table class="twofer">
	<tbody>
	<tr>
	<td class="equals first <?php if ($defaulted['filter']) : ?>active<?php else: ?>inactive<?php endif; ?>">
	<p><label><input type="radio" name="match_default[filter]"
value="yes" <?php if ($defaulted['filter']) : ?> checked="checked"<?php endif; ?> />
Use the <a href="<?php print $href; ?>">site-wide setting</a>
<span class="current-setting">Currently: <strong><?php print $globalMatchLabels['filter']; ?></strong></span></label></p>
	</td>
	<td class="equals second <?php if ($defaulted['filter']) : ?>inactive<?php else: ?>active<?php endif; ?>">
	<p><label><input type="radio" name="match_default[filter]"
value="no" <?php if (!$defaulted['filter']) : ?> checked="checked"<?php endif; ?> />
Do something different with this feed:</label></p>
<div style="margin-left: 3.0em;">
<?php endif; ?>

<ul class="options">
<?php foreach ($matchUl['filter'] as $tax => $li) : ?>
<li><label><input type="checkbox" name="match_categories[filter][]" value="<?php print $tax; ?>"
<?php print $li['checked']; ?> /> Don't syndicate posts unless they match at
least one local <strong><?php $l = $li['labels']; print $l->singular_name; ?></strong></label></li>
<?php endforeach; ?>
</ul>

<?php if ($offerSiteWideSettings) : ?>
	</div>
	</td></tr>
	</tbody>
	</table>
<?php endif; ?>
</td>
</tr>
<?php if ($page->for_feed_settings()) : ?>
<tr>
<th scope="row">Multiple categories:</th>
<td> 
<input type="text" size="20" id="cat_split" name="cat_split" value="<?php if (isset($link->settings['cat_split'])) : echo htmlspecialchars($link->settings['cat_split']); endif; ?>" />
<p class="setting-description">Enter a <a href="http://us.php.net/manual/en/reference.pcre.pattern.syntax.php">Perl-compatible regular expression</a> here if the feed provides multiple
categories in a single category element. The regular expression should match
the characters used to separate one category from the next. If the feed uses
spaces (like <a href="http://del.icio.us/">del.icio.us</a>), use the pattern "\s".
If the feed does not provide multiple categories in a single element, leave this
blank.</p></td>
</tr>
<?php endif; ?>
</table>
		<?php
	} /* FeedWordPressCategoriesPage::feed_categories_box() */
 function store()
 {
     if ($this->filtered()) {
         // This should never happen.
         FeedWordPress::critical_bug('SyndicatedPost', $this, __LINE__);
     }
     $freshness = $this->freshness();
     if ($freshness > 0) {
         # -- Look up, or create, numeric ID for author
         $this->post['post_author'] = $this->author_id(FeedWordPress::on_unfamiliar('author', $this->post['named']['unfamiliar']['author']));
         if (is_null($this->post['post_author'])) {
             $this->post = NULL;
         }
     }
     if (!$this->filtered() and $freshness > 0) {
         # -- Look up, or create, numeric ID for categories
         list($pcats, $ptags) = $this->category_ids($this->post['named']['category'], FeedWordPress::on_unfamiliar('category', $this->post['named']['unfamiliar']['category']), true);
         $this->post['post_category'] = $pcats;
         $this->post['tags_input'] = array_merge($this->post['tags_input'], $ptags);
         if (is_null($this->post['post_category'])) {
             // filter mode on, no matching categories; drop the post
             $this->post = NULL;
         } else {
             // filter mode off or at least one match; now add on the feed and global presets
             $this->post['post_category'] = array_merge($this->post['post_category'], $this->category_ids($this->post['named']['preset/category'], 'default'));
             if (count($this->post['post_category']) < 1) {
                 $this->post['post_category'][] = 1;
                 // Default to category 1 ("Uncategorized" / "General") if nothing else
             }
         }
     }
     if (!$this->filtered() and $freshness > 0) {
         unset($this->post['named']);
         $this->post = apply_filters('syndicated_post', $this->post, $this);
         // Allow for feed-specific syndicated_post filters.
         $this->post = apply_filters("syndicated_post_" . $this->link->uri(), $this->post, $this);
     }
     // Hook in early to make sure these get inserted if at all possible
     add_action('transition_post_status', array(&$this, 'add_rss_meta'), -10000, 3);
     if (!$this->filtered() and $freshness == 2) {
         // The item has not yet been added. So let's add it.
         FeedWordPress::diagnostic('syndicated_posts', 'Inserting new post "' . $this->post['post_title'] . '"');
         $this->insert_new();
         do_action('post_syndicated_item', $this->wp_id(), $this);
         $ret = 'new';
     } elseif (!$this->filtered() and $freshness == 1) {
         FeedWordPress::diagnostic('syndicated_posts', 'Updating existing post # ' . $this->wp_id() . ', "' . $this->post['post_title'] . '"');
         $this->post['ID'] = $this->wp_id();
         $this->update_existing();
         do_action('update_syndicated_item', $this->wp_id(), $this);
         $ret = 'updated';
     } else {
         $ret = false;
     }
     // Remove add_rss_meta hook
     remove_action('transition_post_status', array(&$this, 'add_rss_meta'), -10000, 3);
     return $ret;
 }
function fwp_syndication_options_page()
{
    global $wpdb, $wp_db_version, $fwp_path;
    if (FeedWordPress::needs_upgrade()) {
        fwp_upgrade_page();
        return;
    }
    if (isset($_POST['create_index'])) {
        check_admin_referer();
        if (!current_user_can('manage_options')) {
            die(__("Cheatin' uh ?"));
        } else {
            FeedWordPress::create_guid_index();
            ?>
<div class="updated">
<p><?php 
            _e('Index created on database table.');
            ?>
</p>
</div>
<?php 
        }
    }
    if (isset($_POST['submit']) or isset($_POST['create_index'])) {
        check_admin_referer();
        if (!current_user_can('manage_options')) {
            die(__("Cheatin' uh ?"));
        } else {
            update_option('feedwordpress_cat_id', $_REQUEST['syndication_category']);
            update_option('feedwordpress_munge_permalink', $_REQUEST['munge_permalink']);
            update_option('feedwordpress_use_aggregator_source_data', $_REQUEST['use_aggregator_source_data']);
            update_option('feedwordpress_formatting_filters', $_REQUEST['formatting_filters']);
            update_option('feedwordpress_update_logging', $_REQUEST['update_logging']);
            if ('newuser' == $_REQUEST['unfamiliar_author']) {
                $newuser_name = trim($_REQUEST['unfamiliar_author_newuser']);
                if (strlen($newuser_name) > 0) {
                    $userdata = array();
                    $userdata['ID'] = NULL;
                    $userdata['user_login'] = sanitize_user($newuser_name);
                    $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
                    $userdata['user_nicename'] = sanitize_title($newuser_name);
                    $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
                    $userdata['display_name'] = $wpdb->escape($newuser_name);
                    $newuser_id = wp_insert_user($userdata);
                    if (is_numeric($newuser_id)) {
                        update_option('feedwordpress_unfamiliar_author', $newuser_id);
                    } else {
                        // TODO: Add some error detection and reporting
                    }
                } else {
                    // TODO: Add some error reporting
                }
            } else {
                update_option('feedwordpress_unfamiliar_author', $_REQUEST['unfamiliar_author']);
            }
            if (isset($_REQUEST['match_author_by_email']) and $_REQUEST['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($_REQUEST['null_emails'])) {
                update_option('feedwordpress_null_email_set', $_REQUEST['null_emails']);
            }
            update_option('feedwordpress_unfamiliar_category', $_REQUEST['unfamiliar_category']);
            update_option('feedwordpress_syndicated_post_status', $_REQUEST['post_status']);
            update_option('feedwordpress_automatic_updates', $_POST['automatic_updates'] == 'yes');
            update_option('feedwordpress_update_time_limit', $_POST['update_time_limit'] == 'yes' ? (int) $_POST['time_limit_seconds'] : 0);
            update_option('feedwordpress_freshness', $_POST['freshness_interval'] * 60);
            // Categories
            $cats = array();
            if (isset($_POST['post_category'])) {
                $cats = array();
                foreach ($_POST['post_category'] as $cat_id) {
                    $cats[] = '{#' . $cat_id . '}';
                }
            }
            if (!empty($cats)) {
                update_option('feedwordpress_syndication_cats', implode(FEEDWORDPRESS_CAT_SEPARATOR, $cats));
            } else {
                delete_option('feedwordpress_syndication_cats');
            }
            // Tags
            if (isset($_REQUEST['tags_input'])) {
                $tags = explode(",", $_REQUEST['tags_input']);
            } else {
                $tags = array();
            }
            if (!empty($tags)) {
                update_option('feedwordpress_syndication_tags', implode(FEEDWORDPRESS_CAT_SEPARATOR, $tags));
            } else {
                delete_option('feedwordpress_syndication_tags');
            }
            if (isset($_REQUEST['comment_status']) and $_REQUEST['comment_status'] == 'open') {
                update_option('feedwordpress_syndicated_comment_status', 'open');
            } else {
                update_option('feedwordpress_syndicated_comment_status', 'closed');
            }
            if (isset($_REQUEST['ping_status']) and $_REQUEST['ping_status'] == 'open') {
                update_option('feedwordpress_syndicated_ping_status', 'open');
            } else {
                update_option('feedwordpress_syndicated_ping_status', 'closed');
            }
            if (isset($_REQUEST['hardcode_name']) and $_REQUEST['hardcode_name'] == 'no') {
                update_option('feedwordpress_hardcode_name', 'no');
            } else {
                update_option('feedwordpress_hardcode_name', 'yes');
            }
            if (isset($_REQUEST['hardcode_description']) and $_REQUEST['hardcode_description'] == 'no') {
                update_option('feedwordpress_hardcode_description', 'no');
            } else {
                update_option('feedwordpress_hardcode_description', 'yes');
            }
            if (isset($_REQUEST['hardcode_url']) and $_REQUEST['hardcode_url'] == 'no') {
                update_option('feedwordpress_hardcode_url', 'no');
            } else {
                update_option('feedwordpress_hardcode_url', 'yes');
            }
            ?>
<div class="updated">
<p><?php 
            _e('Options saved.');
            ?>
</p>
</div>
<?php 
        }
    }
    $cat_id = FeedWordPress::link_category_id();
    $munge_permalink = get_option('feedwordpress_munge_permalink');
    $use_aggregator_source_data = get_option('feedwordpress_use_aggregator_source_data');
    $formatting_filters = get_option('feedwordpress_formatting_filters');
    $update_logging = get_option('feedwordpress_update_logging');
    $update_time_limit = (int) get_option('feedwordpress_update_time_limit');
    $automatic_updates = get_option('feedwordpress_automatic_updates');
    $freshness_interval = get_option('feedwordpress_freshness');
    if (false === $freshness_interval) {
        $freshness_interval = FEEDWORDPRESS_FRESHNESS_INTERVAL;
    }
    $freshness_interval = $freshness_interval / 60;
    // convert to minutes
    $hardcode_name = get_option('feedwordpress_hardcode_name');
    $hardcode_description = get_option('feedwordpress_hardcode_description');
    $hardcode_url = get_option('feedwordpress_hardcode_url');
    $post_status = get_option("feedwordpress_syndicated_post_status");
    // default="publish"
    $comment_status = get_option("feedwordpress_syndicated_comment_status");
    // default="closed"
    $ping_status = get_option("feedwordpress_syndicated_ping_status");
    // default="closed"
    $unfamiliar_author = array('create' => '', 'default' => '', 'filter' => '');
    $ua = FeedWordPress::on_unfamiliar('author');
    if (is_string($ua) and array_key_exists($ua, $unfamiliar_author)) {
        $unfamiliar_author[$ua] = ' checked="checked"';
    }
    $match_author_by_email = !('yes' == get_option("feedwordpress_do_not_match_author_by_email"));
    $null_emails = FeedWordPress::null_email_set();
    $unfamiliar_category = array('create' => '', 'default' => '', 'filter' => '', 'tag' => '');
    $uc = FeedWordPress::on_unfamiliar('category');
    if (is_string($uc) and array_key_exists($uc, $unfamiliar_category)) {
        $unfamiliar_category[$uc] = ' checked="checked"';
    }
    if (isset($wp_db_version) and $wp_db_version >= 4772) {
        $results = get_categories('type=link');
        // Guarantee that the Contributors category will be in the drop-down chooser, even if it is empty.
        $found_link_category_id = false;
        foreach ($results as $row) {
            if ($row->cat_id == $cat_id) {
                $found_link_category_id = true;
            }
        }
        if (!$found_link_category_id) {
            $results[] = get_category($cat_id);
        }
    } else {
        $results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM {$wpdb->linkcategories} ORDER BY cat_id");
    }
    $cats = array_map('trim', preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, get_option('feedwordpress_syndication_cats')));
    $dogs = SyndicatedPost::category_ids($cats, NULL);
    $tags = array_map('trim', preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, get_option('feedwordpress_syndication_tags')));
    if (fwp_test_wp_version(FWP_SCHEMA_27)) {
        $icon = '<div class="icon32"><img src="' . htmlspecialchars(WP_PLUGIN_URL . '/' . $fwp_path . '/feedwordpress.png') . '" alt="" /></div>';
    } else {
        $icon = '';
    }
    if (fwp_test_wp_version(FWP_SCHEMA_26)) {
        $options = __('Settings');
    } else {
        $options = __('Options');
    }
    ?>
<script type="text/javascript">
	function contextual_appearance (item, appear, disappear, value, checkbox) {
		var rollup=document.getElementById(item);
		var newuser=document.getElementById(appear);
		var sitewide=document.getElementById(disappear);
		if (rollup) {
			if ((checkbox && rollup.checked) || (!checkbox && value==rollup.value)) {
				if (newuser) newuser.style.display='block';
				if (sitewide) sitewide.style.display='none';
			} else {
				if (newuser) newuser.style.display='none';
				if (sitewide) sitewide.style.display='block';
			}
		}
	}
</script>

<div class="wrap">
<?php 
    print $icon;
    ?>
<h2>Syndication <?php 
    print $options;
    ?>
</h2>
<div id="poststuff">
<form action="" method="post">
<?php 
    fwp_linkedit_single_submit();
    ?>
<div id="post-body">
<?php 
    fwp_option_box_opener('Syndicated Feeds', 'syndicatedfeedsdiv');
    ?>
<table class="editform" width="100%" cellspacing="2" cellpadding="5">
<tr>
<th width="33%" scope="row">Syndicated Link category:</th>
<td width="67%"><?php 
    echo "\n<select name=\"syndication_category\" size=\"1\">";
    foreach ($results as $row) {
        if (!isset($row->cat_id)) {
            $row->cat_id = $row->cat_ID;
        }
        echo "\n\t<option value=\"{$row->cat_id}\"";
        if ($row->cat_id == $cat_id) {
            echo " selected='selected'";
        }
        echo ">{$row->cat_id}: " . wp_specialchars($row->cat_name);
        if ('Y' == $row->auto_toggle) {
            echo ' (auto toggle)';
        }
        echo "</option>\n";
    }
    echo "\n</select>\n";
    ?>
</td>
</tr>

<tr style="vertical-align: top">
<th width="33%" scope="row">Check for feeds ready to be polled for updates:</th>
<td width="67%"><select name="automatic_updates" size="1" onchange="if (this.value=='yes') { disp = 'inline'; } else { disp = 'none'; }; el=document.getElementById('automatic-update-interval-span'); if (el) el.style.display=disp;">
<option value="yes"<?php 
    echo $automatic_updates ? ' selected="selected"' : '';
    ?>
>automatically</option>
<option value="no"<?php 
    echo !$automatic_updates ? ' selected="selected"' : '';
    ?>
>only when I request</option>
</select>
<span id="automatic-update-interval-span" style="display: <?php 
    echo $automatic_updates ? 'inline' : 'none';
    ?>
"><label for="automatic-update-interval">every</label> <input id="automatic-update-interval" name="freshness_interval" value="<?php 
    echo $freshness_interval;
    ?>
" size="4" /> minutes.</span>
</td>
</tr>

<tr style="vertical-align: top">
<th width="33%" scope="row"><?php 
    print __('Time limit on updates');
    ?>
:</th>
<td width="67%"><select id="time-limit" name="update_time_limit" size="1" onchange="contextual_appearance('time-limit', 'time-limit-box', null, 'yes');">
<option value="no"<?php 
    echo $update_time_limit > 0 ? '' : ' selected="selected"';
    ?>
>no time limit on updates</option>
<option value="yes"<?php 
    echo $update_time_limit > 0 ? ' selected="selected"' : '';
    ?>
>limit updates to no more than...</option>
</select>
<span id="time-limit-box"><label><input type="text" name="time_limit_seconds" value="<?php 
    print $update_time_limit;
    ?>
" size="5" /> seconds</label></span>
</tr>

<script type="text/javascript">
	contextual_appearance('time-limit', 'time-limit-box', null, 'yes');
</script>

<tr><th width="33%" scope="row" style="vertical-align:top">Feed information:</th>
<td width="67%"><ul style="margin:0;padding:0;list-style:none">
<li><input type="checkbox" name="hardcode_name" value="no"<?php 
    echo $hardcode_name == 'yes' ? '' : ' checked="checked"';
    ?>
/> Update the contributor title when the feed title changes</li>
<li><input type="checkbox" name="hardcode_description" value="no"<?php 
    echo $hardcode_description == 'yes' ? '' : ' checked="checked"';
    ?>
/> Update when contributor description if the feed tagline changes</li>
<li><input type="checkbox" name="hardcode_url" value="no"<?php 
    echo $hardcode_url == 'yes' ? '' : ' checked="checked"';
    ?>
/> Update the contributor homepage when the feed link changes</li>
</ul></td></tr>
</table>
<?php 
    fwp_linkedit_periodic_submit();
    fwp_option_box_closer();
    ?>

<?php 
    fwp_option_box_opener(__('Syndicated Posts'), 'syndicatedpostsdiv');
    ?>
<table class="editform" width="75%" cellspacing="2" cellpadding="5">
<tr style="vertical-align: top"><th width="44%" scope="row">Publication:</th>
<td width="56%"><ul style="margin: 0; padding: 0; list-style:none">
<li><label><input type="radio" name="post_status" value="publish"<?php 
    echo (!$post_status or $post_status == 'publish') ? ' checked="checked"' : '';
    ?>
 /> Publish syndicated posts immediately</label></li>
<?php 
    if (SyndicatedPost::use_api('post_status_pending')) {
        ?>
<li><label><input type="radio" name="post_status" value="pending"<?php 
        echo $post_status == 'pending' ? ' checked="checked"' : '';
        ?>
 /> Hold syndicated posts for review; mark as Pending</label></li>
<?php 
    }
    ?>
<li><label><input type="radio" name="post_status" value="draft"<?php 
    echo $post_status == 'draft' ? ' checked="checked"' : '';
    ?>
 /> Save syndicated posts as drafts</label></li>
<li><label><input type="radio" name="post_status" value="private"<?php 
    echo $post_status == 'private' ? ' checked="checked"' : '';
    ?>
 /> Save syndicated posts as private posts</label></li>
</ul></td></tr>

<tr style="vertical-align: top"><th width="44%" scope="row">Permalinks point to:</th>
<td width="56%"><select name="munge_permalink" size="1">
<option value="yes"<?php 
    echo $munge_permalink == 'yes' ? ' selected="selected"' : '';
    ?>
>original website</option>
<option value="no"<?php 
    echo $munge_permalink == 'no' ? ' selected="selected"' : '';
    ?>
>this website</option>
</select></td></tr>

<tr style="vertical-align: top"><th width="44%" scope="row">Posts from aggregator feeds:</th>
<td width="56%"><ul style="margin: 0; padding: 0; list-style: none;">
<li><label><input type="radio" name="use_aggregator_source_data" value="no"<?php 
    echo $use_aggregator_source_data != "yes" ? ' checked="checked"' : '';
    ?>
> Give the aggregator itself as the source of posts from an aggregator feed.</label></li>
<li><label><input type="radio" name="use_aggregator_source_data" value="yes"<?php 
    echo $use_aggregator_source_data == "yes" ? ' checked="checked"' : '';
    ?>
> Give the original source of the post as the source, not the aggregator.</label></li>
</ul>
<p>Some feeds (for example, those produced by FeedWordPress) aggregate content from several different sources, and include information about the original source of the post.
This setting controls what FeedWordPress will give as the source of posts from
such an aggregator feed.</p>
</td></tr>

<tr style="vertical-align:top"><th width="44%" scope="row">Formatting filters:</th>
<td width="56%">
<select name="formatting_filters" size="1">
<option value="no"<?php 
    echo $formatting_filters != 'yes' ? ' selected="selected"' : '';
    ?>
>Protect syndicated posts from formatting filters</option>
<option value="yes"<?php 
    echo $formatting_filters == 'yes' ? ' selected="selected"' : '';
    ?>
>Expose syndicated posts to formatting filters</option>
</select>
<p>If you have trouble getting plugins to work that are supposed to insert
elements after posts (like relevant links or a social networking
<q>Share This</q> button), try changing this option to see if it fixes your
problem.</p>
</td></tr>
</table>
<?php 
    fwp_option_box_closer();
    fwp_linkedit_periodic_submit();
    fwp_option_box_opener(__('Categories for syndicated posts'), 'categorydiv', 'postbox');
    fwp_category_box($dogs, '<em>all syndicated posts</em>');
    ?>
<table class="editform" width="75%" cellspacing="2" cellpadding="5">
<tr style="vertical-align: top"><th width="27%" scope="row" style="vertical-align:top">Unfamiliar categories:</th>
<td><p>When one of the categories on a syndicated post is a category that FeedWordPress has not encountered before ...</p>
<ul style="margin: 0; padding:0; list-style:none">
<li><label><input type="radio" name="unfamiliar_category" value="create"<?php 
    echo $unfamiliar_category['create'];
    ?>
/> create a new category</label></li>
<?php 
    if (fwp_test_wp_version(FWP_SCHEMA_23)) {
        ?>
<li><label><input type="radio" name="unfamiliar_category" value="tag"<?php 
        echo $unfamiliar_category['tag'];
        ?>
/> create a new tag</label></li>
<?php 
    }
    ?>
<li><label><input type="radio" name="unfamiliar_category" value="default"<?php 
    echo $unfamiliar_category['default'];
    ?>
/> don't create new categories<?php 
    if (fwp_test_wp_version(FWP_SCHEMA_23)) {
        ?>
 or tags<?php 
    }
    ?>
</li>
<li><label><input type="radio" name="unfamiliar_category" value="filter"<?php 
    echo $unfamiliar_category['filter'];
    ?>
/> don't create new categories<?php 
    if (fwp_test_wp_version(FWP_SCHEMA_23)) {
        ?>
 or tags<?php 
    }
    ?>
 and don't syndicate posts unless they match at least one familiar category</label></li>
</ul></td></tr>
</table>
<?php 
    fwp_option_box_closer();
    fwp_linkedit_periodic_submit();
    if (isset($wp_db_version) and $wp_db_version >= FWP_SCHEMA_25) {
        fwp_tags_box($tags);
        fwp_linkedit_periodic_submit();
    }
    fwp_option_box_opener(__('Comments & Pings'), 'commentstatus', 'postbox');
    ?>
<table class="editform" width="75%" cellspacing="2" cellpadding="5">
<tr style="vertical-align: top"><th width="44%" scope="row"><?php 
    print __('Comments');
    ?>
:</th>
<td width="56%"><ul style="margin: 0; padding: 0; list-style:none">
<li><label><input type="radio" name="comment_status" value="open"<?php 
    echo $comment_status == 'open' ? ' checked="checked"' : '';
    ?>
 /> Allow comments on syndicated posts</label></li>
<li><label><input type="radio" name="comment_status" value="closed"<?php 
    echo $comment_status != 'open' ? ' checked="checked"' : '';
    ?>
 /> Don't allow comments on syndicated posts</label></li>
</ul></td></tr>

<tr style="vertical-align: top"><th width="44%" scope="row"><?php 
    print __('Pings');
    ?>
:</th>
<td width="56%"><ul style="margin:0; padding: 0; list-style:none">
<li><label><input type="radio" name="ping_status" value="open"<?php 
    echo $ping_status == 'open' ? ' checked="checked"' : '';
    ?>
 /> Accept pings on syndicated posts</label></li>
<li><label><input type="radio" name="ping_status" value="closed"<?php 
    echo $ping_status != 'open' ? ' checked="checked"' : '';
    ?>
 /> Don't accept pings on syndicated posts</label></li>
</ul></td></tr>
</table>
<?php 
    fwp_option_box_closer();
    fwp_linkedit_periodic_submit();
    fwp_option_box_opener('Syndicated Authors', 'authordiv', 'postbox');
    $unfamiliar_author = FeedWordPress::on_unfamiliar('author');
    $authorlist = fwp_author_list();
    ?>
<table>
<tr><th colspan="3" style="text-align: left; padding-top: 1.0em; border-bottom: 1px dotted black;">For posts by authors that haven't been syndicated before:</th></tr>
<tr style="vertical-align: top">
  <th style="text-align: left">Posts by new authors</th>
  <td> 
  <select style="max-width: 16.0em;" id="unfamiliar-author" name="unfamiliar_author" onchange="contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser');">
    <option value="create"<?php 
    if ('create' == $unfamiliar_author) {
        ?>
selected="selected"<?php 
    }
    ?>
>create a new author account</option>
    <?php 
    foreach ($authorlist as $author_id => $author_name) {
        ?>
      <option value="<?php 
        echo $author_id;
        ?>
"<?php 
        if ($author_id == $unfamiliar_author) {
            ?>
selected="selected"<?php 
        }
        ?>
>are assigned to <?php 
        echo $author_name;
        ?>
</option>
    <?php 
    }
    ?>
    <option value="newuser">will be assigned to a user named...</option>
    <option value="filter"<?php 
    if ('filter' == $unfamiliar_author) {
        ?>
selected="selected"<?php 
    }
    ?>
>get filtered out</option>
  </select>
  </td>
  <td>
  <div id="unfamiliar-author-newuser"><input type="text" name="unfamiliar_author_newuser" value="" /></div>
  </td>
</tr>
<tr><td></td>
<td colspan="2">
<p>This is a default setting. You can override it for one or more particular feeds using the Edit link in <a href="admin.php?page=<?php 
    print $GLOBALS['fwp_path'];
    ?>
/syndication.php">Syndicated Sites</a></p>
</td>
</table>

<script type="text/javascript">
	contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser');
</script>

<h4>Matching Authors</h4>
<ul style="list-style: none; margin: 0; padding: 0;">
<li><div><label><input id="match-author-by-email" type="checkbox" name="match_author_by_email" value="yes" <?php 
    if ($match_author_by_email) {
        ?>
checked="checked" <?php 
    }
    ?>
onchange="contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', /*checkbox=*/ true);" /> Treat syndicated authors with the same e-mail address as the same author.</label></div>
<div id="unless-null-email">
<p>Unless the e-mail address is one of the following anonymous e-mail addresses:</p>
<textarea name="null_emails" rows="3" style="width: 100%">
<?php 
    print implode("\n", $null_emails);
    ?>
</textarea>
</div></li>
</ul>

<script type="text/javascript">
contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', /*checkbox=*/ true);
</script>

<?php 
    fwp_option_box_closer();
    fwp_linkedit_periodic_submit();
    fwp_option_box_opener('Back End', 'backenddiv', 'postbox');
    ?>
<table class="editform" width="100%" cellspacing="2" cellpadding="5">
<tr style="vertical-align: top">
<th width="33%" scope="row">Update notices:</th>
<td width="67%"><select name="update_logging" size="1">
<option value="yes"<?php 
    echo $update_logging == 'yes' ? ' selected="selected"' : '';
    ?>
>write to PHP logs</option>
<option value="no"<?php 
    echo $update_logging != 'yes' ? ' selected="selected"' : '';
    ?>
>don't write to PHP logs</option>
</select></td>
</tr>
<tr style="vertical-align: top">
<th width="33%" scope="row">Guid index:</th>
<td width="67%"><input class="button" type="submit" name="create_index" value="Create index on guid column in posts database table" />
<p>Creating this index may significantly improve performance on some large
FeedWordPress installations.</p></td>
</tr>
</table>
<?php 
    fwp_option_box_closer();
    fwp_linkedit_periodic_submit();
    fwp_linkedit_single_submit_closer();
    ?>
</div>
</form>

</div> <!-- id="poststuff" -->
</div> <!-- class="wrap" -->
<?php 
}
    function syndicated_authors_box($page, $box = NULL)
    {
        $link = $page->link;
        $unfamiliar = array('create' => '', 'default' => '', 'filter' => '');
        if ($page->for_feed_settings()) {
            $key = $link->setting('unfamiliar author', NULL, 'site-default');
            $unfamiliar['site-default'] = '';
        } else {
            $key = FeedWordPress::on_unfamiliar('author');
        }
        $unfamiliar[$key] = ' selected="selected"';
        $match_author_by_email = !('yes' == get_option("feedwordpress_do_not_match_author_by_email"));
        $null_emails = FeedWordPress::null_email_set();
        // Hey ho, let's go...
        ?>
<table class="form-table">
<tbody>
<tr>
  <th>New authors</th>
  <td><span>Authors who haven't been syndicated before</span>
  <select style="max-width: 27.0em" id="unfamiliar-author" name="unfamiliar_author">
<?php 
        if ($page->for_feed_settings()) {
            ?>
    <option value="site-default"<?php 
            print $unfamiliar['site-default'];
            ?>
>are handled according to the default for all feeds</option>
<?php 
        }
        ?>
    <?php 
        foreach ($page->authorlist as $author_id => $author_name) {
            ?>
      <option value="<?php 
            echo $author_id;
            ?>
"<?php 
            print isset($unfamiliar[$author_id]) ? $unfamiliar[$author_id] : '';
            ?>
>will have their posts attributed to <?php 
            echo $author_name;
            ?>
</option>
    <?php 
        }
        ?>
    <option value="filter"<?php 
        print $unfamiliar['filter'];
        ?>
>get filtered out</option>
  </select>
  </td>
</tr>

<?php 
        if ($page->for_feed_settings()) {
            ?>
<tr><th>Syndicated authors</th>
<td>For attributing posts by specific authors. Blank out a name to delete the rule. Fill in a new name at the bottom to create a new rule.</p>
<table style="width: 100%">
<?php 
            if (isset($link->settings['map authors'])) {
                $page->rule_count = 0;
                foreach ($link->settings['map authors'] as $author_rules) {
                    foreach ($author_rules as $author_name => $author_action) {
                        $page->rule_count++;
                        ?>
<tr>
<th style="text-align: left; width: 15.0em">Posts by <input type="text" name="author_rules_name[]" value="<?php 
                        echo htmlspecialchars($author_name);
                        ?>
" size="11" /></th>
  <td>
  <select id="author-rules-<?php 
                        echo $page->rule_count;
                        ?>
" name="author_rules_action[]">
    <?php 
                        foreach ($page->authorlist as $local_author_id => $local_author_name) {
                            ?>
    <option value="<?php 
                            echo $local_author_id;
                            ?>
"<?php 
                            if ($local_author_id == $author_action) {
                                echo ' selected="selected"';
                            }
                            ?>
>are assigned to <?php 
                            echo $local_author_name;
                            ?>
</option>
    <?php 
                        }
                        ?>
    <option value="filter"<?php 
                        if ('filter' == $author_action) {
                            echo ' selected="selected"';
                        }
                        ?>
>get filtered out</option>
  </select>
  </td>
</tr>
<?php 
                    }
                }
            }
            ?>

<tr>
<th style="text-align: left; width: 15.0em">Posts by <input type="text" name="add_author_rule_name" size="11" /></th>
  <td>
    <select id="add-author-rule" name="add_author_rule_action">
      <?php 
            foreach ($page->authorlist as $author_id => $author_name) {
                ?>
      <option value="<?php 
                echo $author_id;
                ?>
">are assigned to <?php 
                echo $author_name;
                ?>
</option>
      <?php 
            }
            ?>
      <option value="filter">get filtered out</option>
    </select>
   </td>
</tr>
</table>
</td>
</tr>
<?php 
        }
        ?>

<?php 
        if ($page->for_default_settings()) {
            ?>
<tr>
<th scope="row">Matching Authors</th>
<td><ul style="list-style: none; margin: 0; padding: 0;">
<li><div><label><input id="match-author-by-email" type="checkbox" name="match_author_by_email" value="yes" <?php 
            if ($match_author_by_email) {
                ?>
checked="checked" <?php 
            }
            ?>
onchange="contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', 'block', /*checkbox=*/ true);" /> Treat syndicated authors with the same e-mail address as the same author.</label></div>
<div id="unless-null-email">
<p>Unless the e-mail address is one of the following anonymous e-mail addresses:</p>
<textarea name="null_emails" rows="3" style="width: 100%">
<?php 
            print implode("\n", $null_emails);
            ?>
</textarea>
</div></li>
</ul></td>
</tr>
<?php 
        }
        ?>
</tbody>
</table>
		<?php 
    }
function fwp_linkedit_page()
{
    global $wpdb, $wp_db_version;
    check_admin_referer();
    // Make sure we arrived here from the Dashboard
    $special_settings = array('cats', 'cat_split', 'hardcode name', 'hardcode url', 'hardcode description', 'hardcode categories', 'post status', 'comment status', 'ping status', 'unfamiliar author', 'unfamliar categories', 'unfamiliar category', 'map authors', 'tags', 'update/.*', 'feed/.*', 'link/.*');
    if (!current_user_can('manage_links')) {
        die(__("Cheatin' uh ?"));
    } elseif (isset($_REQUEST['feedfinder'])) {
        return fwp_feedfinder_page();
        // re-route to Feed Finder page
    } else {
        $link_id = (int) $_REQUEST['link_id'];
        $link =& new SyndicatedLink($link_id);
        if ($link->found()) {
            if (isset($GLOBALS['fwp_post']['save'])) {
                $alter = array();
                // custom feed settings first
                foreach ($GLOBALS['fwp_post']['notes'] as $mn) {
                    $mn['key0'] = trim($mn['key0']);
                    $mn['key1'] = trim($mn['key1']);
                    if (preg_match("^((" . implode(')|(', $special_settings) . "))\$i", $mn['key1'])) {
                        $mn['key1'] = 'user/' . $mn['key1'];
                    }
                    if (strlen($mn['key0']) > 0) {
                        unset($link->settings[$mn['key0']]);
                        // out with the old
                    }
                    if ($mn['action'] == 'update' and strlen($mn['key1']) > 0) {
                        $link->settings[$mn['key1']] = $mn['value'];
                        // in with the new
                    }
                }
                // now stuff through the web form
                // hardcoded feed info
                if (isset($GLOBALS['fwp_post']['hardcode_name'])) {
                    $link->settings['hardcode name'] = $GLOBALS['fwp_post']['hardcode_name'];
                    if (FeedWordPress::affirmative($link->settings, 'hardcode name')) {
                        $alter[] = "link_name = '" . $wpdb->escape($GLOBALS['fwp_post']['name']) . "'";
                    }
                }
                if (isset($GLOBALS['fwp_post']['hardcode_description'])) {
                    $link->settings['hardcode description'] = $GLOBALS['fwp_post']['hardcode_description'];
                    if (FeedWordPress::affirmative($link->settings, 'hardcode description')) {
                        $alter[] = "link_description = '" . $wpdb->escape($GLOBALS['fwp_post']['description']) . "'";
                    }
                }
                if (isset($GLOBALS['fwp_post']['hardcode_url'])) {
                    $link->settings['hardcode url'] = $GLOBALS['fwp_post']['hardcode_url'];
                    if (FeedWordPress::affirmative($link->settings, 'hardcode url')) {
                        $alter[] = "link_url = '" . $wpdb->escape($GLOBALS['fwp_post']['linkurl']) . "'";
                    }
                }
                // Update scheduling
                if (isset($GLOBALS['fwp_post']['update_schedule'])) {
                    $link->settings['update/hold'] = $GLOBALS['fwp_post']['update_schedule'];
                }
                // Categories
                if (isset($GLOBALS['fwp_post']['post_category'])) {
                    $link->settings['cats'] = array();
                    foreach ($GLOBALS['fwp_post']['post_category'] as $cat_id) {
                        $link->settings['cats'][] = '{#' . $cat_id . '}';
                    }
                } else {
                    unset($link->settings['cats']);
                }
                // Tags
                if (isset($GLOBALS['fwp_post']['tags_input'])) {
                    $link->settings['tags'] = array();
                    foreach (explode(',', $GLOBALS['fwp_post']['tags_input']) as $tag) {
                        $link->settings['tags'][] = trim($tag);
                    }
                }
                // Post status, comment status, ping status
                foreach (array('post', 'comment', 'ping') as $what) {
                    $sfield = "feed_{$what}_status";
                    if (isset($GLOBALS['fwp_post'][$sfield])) {
                        if ($GLOBALS['fwp_post'][$sfield] == 'site-default') {
                            unset($link->settings["{$what} status"]);
                        } else {
                            $link->settings["{$what} status"] = $GLOBALS['fwp_post'][$sfield];
                        }
                    }
                }
                // Unfamiliar author, unfamiliar categories
                foreach (array("author", "category") as $what) {
                    $sfield = "unfamiliar_{$what}";
                    if (isset($GLOBALS['fwp_post'][$sfield])) {
                        if ('site-default' == $GLOBALS['fwp_post'][$sfield]) {
                            unset($link->settings["unfamiliar {$what}"]);
                        } elseif ('newuser' == $GLOBALS['fwp_post'][$sfield]) {
                            $newuser_name = trim($GLOBALS['fwp_post']["{$sfield}_newuser"]);
                            if (strlen($newuser_name) > 0) {
                                $userdata = array();
                                $userdata['ID'] = NULL;
                                $userdata['user_login'] = sanitize_user($newuser_name);
                                $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
                                $userdata['user_nicename'] = sanitize_title($newuser_name);
                                $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
                                $userdata['display_name'] = $wpdb->escape($newuser_name);
                                $newuser_id = wp_insert_user($userdata);
                                if (is_numeric($newuser_id)) {
                                    $link->settings["unfamiliar {$what}"] = $newuser_id;
                                } else {
                                    // TODO: Add some error detection and reporting
                                }
                            } else {
                                // TODO: Add some error reporting
                            }
                        } else {
                            $link->settings["unfamiliar {$what}"] = $GLOBALS['fwp_post'][$sfield];
                        }
                    }
                }
                // 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) {
                            if ('newuser' == $author_action) {
                                $newuser_name = trim($GLOBALS['fwp_post']['author_rules_newuser'][$key]);
                                if (strlen($newuser_name) > 0) {
                                    $userdata = array();
                                    $userdata['ID'] = NULL;
                                    $userdata['user_login'] = sanitize_user($newuser_name);
                                    $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
                                    $userdata['user_nicename'] = sanitize_title($newuser_name);
                                    $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
                                    $userdata['display_name'] = $wpdb->escape($newuser_name);
                                    $newuser_id = wp_insert_user($userdata);
                                    if (is_numeric($newuser_id)) {
                                        $link->settings['map authors']['name'][$name] = $newuser_id;
                                    } else {
                                        // TODO: Add some error detection and reporting
                                    }
                                } else {
                                    // TODO: Add some error reporting
                                }
                            } else {
                                $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) {
                        if ('newuser' == $author_action) {
                            $newuser_name = trim($GLOBALS['fwp_post']['add_author_rule_newuser']);
                            if (strlen($newuser_name) > 0) {
                                $userdata = array();
                                $userdata['ID'] = NULL;
                                $userdata['user_login'] = sanitize_user($newuser_name);
                                $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
                                $userdata['user_nicename'] = sanitize_title($newuser_name);
                                $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
                                $userdata['display_name'] = $wpdb->escape($newuser_name);
                                $newuser_id = wp_insert_user($userdata);
                                if (is_numeric($newuser_id)) {
                                    $link->settings['map authors']['name'][$name] = $newuser_id;
                                } else {
                                    // TODO: Add some error detection and reporting
                                }
                            } else {
                                // TODO: Add some error reporting
                            }
                        } else {
                            $link->settings['map authors']['name'][$name] = $author_action;
                        }
                    }
                }
                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']);
                    }
                }
                $alter[] = "link_notes = '" . $wpdb->escape($link->settings_to_notes()) . "'";
                $alter_set = implode(", ", $alter);
                // issue update query
                $result = $wpdb->query("\n\t\t\t\tUPDATE {$wpdb->links}\n\t\t\t\tSET {$alter_set}\n\t\t\t\tWHERE link_id='{$link_id}'\n\t\t\t\t");
                $updated_link = true;
                // reload link information from DB
                if (function_exists('clean_bookmark_cache')) {
                    clean_bookmark_cache($link_id);
                }
                $link =& new SyndicatedLink($link_id);
            } else {
                $updated_link = false;
            }
            $db_link = $link->link;
            $link_url = wp_specialchars($db_link->link_url, 1);
            $link_name = wp_specialchars($db_link->link_name, 1);
            $link_description = wp_specialchars($db_link->link_description, 'both');
            $link_rss_uri = wp_specialchars($db_link->link_rss, 'both');
            $post_status_global = get_option('feedwordpress_syndicated_post_status');
            $comment_status_global = get_option('feedwordpress_syndicated_comment_status');
            $ping_status_global = get_option('feedwordpress_syndicated_ping_status');
            $status['post'] = array('publish' => '', 'private' => '', 'draft' => '', 'site-default' => '');
            if (SyndicatedPost::use_api('post_status_pending')) {
                $status['post']['pending'] = '';
            }
            $status['comment'] = array('open' => '', 'closed' => '', 'site-default' => '');
            $status['ping'] = array('open' => '', 'closed' => '', 'site-default' => '');
            foreach (array('post', 'comment', 'ping') as $what) {
                if (isset($link->settings["{$what} status"])) {
                    $status[$what][$link->settings["{$what} status"]] = ' checked="checked"';
                } else {
                    $status[$what]['site-default'] = ' checked="checked"';
                }
            }
            $unfamiliar['author'] = array('create' => '', 'default' => '', 'filter' => '');
            $unfamiliar['category'] = array('create' => '', 'tag' => '', 'default' => '', 'filter' => '');
            foreach (array('author', 'category') as $what) {
                if (is_string($link->settings["unfamiliar {$what}"]) and array_key_exists($link->settings["unfamiliar {$what}"], $unfamiliar[$what])) {
                    $key = $link->settings["unfamiliar {$what}"];
                } else {
                    $key = 'site-default';
                }
                $unfamiliar[$what][$key] = ' checked="checked"';
            }
            if (is_array($link->settings['cats'])) {
                $cats = $link->settings['cats'];
            } else {
                $cats = array();
            }
            $dogs = SyndicatedPost::category_ids($cats, NULL);
        } else {
            die(__('Link not found.'));
        }
        ?>
<script type="text/javascript">
	function flip_hardcode (item) {
		ed=document.getElementById('basics-'+item+'-edit');
		view=document.getElementById('basics-'+item+'-view');
		
		o = document.getElementById('basics-hardcode-'+item);
		if (o.value=='yes') { ed.style.display='inline'; view.style.display='none'; }
		else { ed.style.display='none'; view.style.display='inline'; }
	}
	function flip_newuser (item) {
		rollup=document.getElementById(item);
		newuser=document.getElementById(item+'-newuser');
		sitewide=document.getElementById(item+'-default');
		if (rollup) {
			if ('newuser'==rollup.value) {
				if (newuser) newuser.style.display='block';
				if (sitewide) sitewide.style.display='none';
			} else if ('site-default'==rollup.value) {
				if (newuser) newuser.style.display='none';
				if (sitewide) sitewide.style.display='block';
			} else {
				if (newuser) newuser.style.display='none';
				if (sitewide) sitewide.style.display='none';
			}
		}
	}
</script>

<?php 
        if ($updated_link) {
            ?>
<div class="updated"><p>Syndicated feed settings updated.</p></div>
<?php 
        }
        ?>

<form action="admin.php?page=<?php 
        print $GLOBALS['fwp_path'];
        ?>
/<?php 
        echo basename(__FILE__);
        ?>
" method="post">
<div class="wrap">
<input type="hidden" name="link_id" value="<?php 
        echo $link_id;
        ?>
" />
<input type="hidden" name="action" value="linkedit" />
<input type="hidden" name="save" value="link" />

<h2>Edit a syndicated feed:</h2>
<div id="poststuff">
<?php 
        fwp_linkedit_single_submit($status);
        ?>

<div id="post-body">
<?php 
        fwp_option_box_opener('Feed Information', 'feedinformationdiv');
        ?>
	<table class="editform" width="100%" cellspacing="2" cellpadding="5">
	<tr>
	<th scope="row" width="20%"><?php 
        _e('Feed URI:');
        ?>
</th>
	<td width="60%"><a href="<?php 
        echo wp_specialchars($link_rss_uri, 'both');
        ?>
"><?php 
        echo $link_rss_uri;
        ?>
</a>
	(<a href="<?php 
        echo FEEDVALIDATOR_URI;
        ?>
?url=<?php 
        echo urlencode($link_rss_uri);
        ?>
"
	title="Check feed &lt;<?php 
        echo wp_specialchars($link_rss_uri, 'both');
        ?>
&gt; for validity">validate</a>)
	</td>
	<td width="20%"><input type="submit" name="feedfinder" value="switch &rarr;" style="font-size:smaller" /></td>
	</tr>
	<tr>
	<th scope="row" width="20%"><?php 
        _e('Link Name:');
        ?>
</th>
	<td width="60%"><input type="text" id="basics-name-edit" name="name"
	value="<?php 
        echo $link_name;
        ?>
" style="width: 95%" />
	<span id="basics-name-view"><strong><?php 
        echo $link_name;
        ?>
</strong></span>
	</td>
	<td>
	<select id="basics-hardcode-name" onchange="flip_hardcode('name')" name="hardcode_name">
	<option value="no" <?php 
        echo $link->hardcode('name') ? '' : 'selected="selected"';
        ?>
>update automatically</option>
	<option value="yes" <?php 
        echo $link->hardcode('name') ? 'selected="selected"' : '';
        ?>
>edit manually</option>
	</select>
	</td>
	</tr>
	<tr>
	<th scope="row" width="20%"><?php 
        _e('Short description:');
        ?>
</th>
	<td width="60%">
	<input id="basics-description-edit" type="text" name="description" value="<?php 
        echo $link_description;
        ?>
" style="width: 95%" />
	<span id="basics-description-view"><strong><?php 
        echo $link_description;
        ?>
</strong></span>
	</td>
	<td>
	<select id="basics-hardcode-description" onchange="flip_hardcode('description')"
	name="hardcode_description">
	<option value="no" <?php 
        echo $link->hardcode('description') ? '' : 'selected="selected"';
        ?>
>update automatically</option>
	<option value="yes" <?php 
        echo $link->hardcode('description') ? 'selected="selected"' : '';
        ?>
>edit manually</option>
	</select></td>
	</tr>
	<tr>
	<th width="20%" scope="row"><?php 
        _e('Homepage:');
        ?>
</th>
	<td width="60%">
	<input id="basics-url-edit" type="text" name="linkurl" value="<?php 
        echo $link_url;
        ?>
" style="width: 95%;" />
	<a id="basics-url-view" href="<?php 
        echo $link_url;
        ?>
"><?php 
        echo $link_url;
        ?>
</a></td>
	<td>
	<select id="basics-hardcode-url" onchange="flip_hardcode('url')" name="hardcode_url">
	<option value="no"<?php 
        echo $link->hardcode('url') ? '' : ' selected="selected"';
        ?>
>update automatically</option>
	<option value="yes"<?php 
        echo $link->hardcode('url') ? ' selected="selected"' : '';
        ?>
>edit manually</option>
	</select></td></tr>
	
	<tr>
	<th width="20%"><?php 
        _e('Last update');
        ?>
:</th>
	<td colspan="2"><?php 
        if (isset($link->settings['update/last'])) {
            echo fwp_time_elapsed($link->settings['update/last']) . " ";
        } else {
            echo " none yet";
        }
        ?>
</td></tr>
	<tr><th width="20%">Next update:</th>
	<td colspan="2"><?php 
        $holdem = isset($link->settings['update/hold']) ? $link->settings['update/hold'] : 'scheduled';
        ?>
	<select name="update_schedule">
	<option value="scheduled"<?php 
        echo $holdem == 'scheduled' ? ' selected="selected"' : '';
        ?>
>update on schedule <?php 
        echo " (";
        if (isset($link->settings['update/ttl']) and is_numeric($link->settings['update/ttl'])) {
            if (isset($link->settings['update/timed']) and $link->settings['update/timed'] == 'automatically') {
                echo 'next: ';
                $next = $link->settings['update/last'] + (int) $link->settings['update/ttl'] * 60;
                if (strftime('%x', time()) != strftime('%x', $next)) {
                    echo strftime('%x', $next) . " ";
                }
                echo strftime('%X', $link->settings['update/last'] + (int) $link->settings['update/ttl'] * 60);
            } else {
                echo "every " . $link->settings['update/ttl'] . " minute" . ($link->settings['update/ttl'] != 1 ? "s" : "");
            }
        } else {
            echo "next scheduled update";
        }
        echo ")";
        ?>
</option>
	<option value="next"<?php 
        echo $holdem == 'next' ? ' selected="selected"' : '';
        ?>
>update ASAP</option>
	<option value="ping"<?php 
        echo $holdem == 'ping' ? ' selected="selected"' : '';
        ?>
>update only when pinged</option>
	</select></tr>
	</table>
<?php 
        fwp_option_box_closer();
        ?>

<script type="text/javascript">
flip_hardcode('name');
flip_hardcode('description');
flip_hardcode('url');
</script>

<?php 
        fwp_linkedit_periodic_submit();
        ?>

<?php 
        if (!(isset($wp_db_version) and $wp_db_version >= FWP_SCHEMA_25)) {
            fwp_option_box_opener('Syndicated Posts', 'syndicatedpostsdiv', 'postbox');
            ?>
<table class="editform" width="75%" cellspacing="2" cellpadding="5">
<tr><th width="27%" scope="row" style="vertical-align:top">Publication:</th>
<td width="73%" style="vertical-align:top"><ul style="margin:0; list-style:none">
<li><label><input type="radio" name="feed_post_status" value="site-default"
<?php 
            echo $status['post']['site-default'];
            ?>
 /> Use site-wide setting from <a href="admin.php?page=<?php 
            print $GLOBALS['fwp_path'];
            ?>
/syndication-options.php">Syndication Options</a>
(currently: <strong><?php 
            echo $post_status_global ? $post_status_global : 'publish';
            ?>
</strong>)</label></li>
<li><label><input type="radio" name="feed_post_status" value="publish"
<?php 
            echo $status['post']['publish'];
            ?>
 /> Publish posts from this feed immediately</label></li>

<?php 
            if (SyndicatedPost::use_api('post_status_pending')) {
                ?>
<li><label><input type="radio" name="feed_post_status" value="pending"
<?php 
                echo $status['post']['pending'];
                ?>
/> Hold posts from this feed for review; mark as Pending</label></li>
<?php 
            }
            ?>

<li><label><input type="radio" name="feed_post_status" value="draft"
<?php 
            echo $status['post']['draft'];
            ?>
 /> Save posts from this feed as drafts</label></li>
<li><label><input type="radio" name="feed_post_status" value="private"
<?php 
            echo $status['post']['private'];
            ?>
 /> Save posts from this feed as private posts</label></li>
</ul></td>
</tr>
</table>
<?php 
            fwp_option_box_closer();
            fwp_linkedit_periodic_submit();
        }
        fwp_option_box_opener(__('Categories'), 'categorydiv', 'postbox');
        fwp_category_box($dogs, 'all syndicated posts from this feed');
        ?>
<table>
<tr>
<th width="20%" scope="row" style="vertical-align:top">Unfamiliar categories:</th>
<td width="80%"><p>When one of the categories on a syndicated post is a category that FeedWordPress has not encountered before ...</p>

<ul style="margin: 0; list-style:none">
<li><label><input type="radio" name="unfamiliar_category" value="site-default"<?php 
        echo $unfamiliar['category']['site-default'];
        ?>
 /> use the site-wide setting from <a href="admin.php?page=<?php 
        print $GLOBALS['fwp_path'];
        ?>
/syndication-options.php">Syndication Options</a>
(currently <strong><?php 
        echo FeedWordPress::on_unfamiliar('category');
        ?>
</strong>)</label></li>
<li><label><input type="radio" name="unfamiliar_category" value="create"<?php 
        echo $unfamiliar['category']['create'];
        ?>
 /> create a new category</label></li>
<?php 
        if (fwp_test_wp_version(FWP_SCHEMA_23)) {
            ?>
<li><label><input type="radio" name="unfamiliar_category" value="tag"<?php 
            echo $unfamiliar['category']['tag'];
            ?>
/> create a new tag</label></li>
<?php 
        }
        ?>
<li><label><input type="radio" name="unfamiliar_category" value="default"<?php 
        echo $unfamiliar['category']['default'];
        ?>
 /> don't create new categories<?php 
        if (fwp_test_wp_version(FWP_SCHEMA_23)) {
            ?>
 or tags<?php 
        }
        ?>
</label></li>
<li><label><input type="radio" name="unfamiliar_category" value="filter"<?php 
        echo $unfamiliar['category']['filter'];
        ?>
 /> don't create new categories<?php 
        if (fwp_test_wp_version(FWP_SCHEMA_23)) {
            ?>
 or tags<?php 
        }
        ?>
 and don't syndicate posts unless they match at least one familiar category</label></li>
</ul></td>
</tr>

<tr>
<th width="20%" scope="row" style="vertical-align:top">Multiple categories:</th>
<td width="80%"> 
<input type="text" size="20" id="cat_split" name="cat_split" value="<?php 
        if (isset($link->settings['cat_split'])) {
            echo htmlspecialchars($link->settings['cat_split']);
        }
        ?>
" /><br/>
Enter a <a href="http://us.php.net/manual/en/reference.pcre.pattern.syntax.php">Perl-compatible regular expression</a> here if the feed provides multiple
categories in a single category element. The regular expression should match
the characters used to separate one category from the next. If the feed uses
spaces (like <a href="http://del.icio.us/">del.icio.us</a>), use the pattern "\s".
If the feed does not provide multiple categories in a single element, leave this
blank.</td>
</tr>
</table>
<?php 
        fwp_option_box_closer();
        fwp_linkedit_periodic_submit();
        if (isset($wp_db_version) and $wp_db_version >= FWP_SCHEMA_25) {
            fwp_tags_box($link->settings['tags']);
            fwp_linkedit_periodic_submit();
        }
        ?>

<?php 
        fwp_option_box_opener('Syndicated Authors', 'authordiv', 'postbox');
        $authorlist = fwp_author_list();
        ?>
<table>
<tr><th colspan="3" style="text-align: left; padding-top: 1.0em; border-bottom: 1px dotted black;">For posts by authors that haven't been syndicated before:</th></tr>
<tr>
  <th style="text-align: left">Posts by new authors</th>
  <td> 
  <select id="unfamiliar-author" name="unfamiliar_author" onchange="flip_newuser('unfamiliar-author');">
    <option value="site-default"<?php 
        if (!isset($link->settings['unfamiliar author'])) {
            ?>
selected="selected"<?php 
        }
        ?>
>are handled using site-wide settings</option>
    <option value="create"<?php 
        if ('create' == $link->settings['unfamiliar author']) {
            ?>
selected="selected"<?php 
        }
        ?>
>create a new author account</option>
    <?php 
        foreach ($authorlist as $author_id => $author_name) {
            ?>
      <option value="<?php 
            echo $author_id;
            ?>
"<?php 
            if ($author_id == $link->settings['unfamiliar author']) {
                ?>
selected="selected"<?php 
            }
            ?>
>are assigned to <?php 
            echo $author_name;
            ?>
</option>
    <?php 
        }
        ?>
    <option value="newuser">will be assigned to a new user...</option>
    <option value="filter"<?php 
        if ('filter' == $link->settings['unfamiliar author']) {
            ?>
selected="selected"<?php 
        }
        ?>
>get filtered out</option>
  </select>
  </td>
  <td>
  <div id="unfamiliar-author-default">Site-wide settings can be set in <a href="admin.php?page=<?php 
        print $GLOBALS['fwp_path'];
        ?>
/syndication-options.php">Syndication Options</a></div>
  <div id="unfamiliar-author-newuser">named <input type="text" name="unfamiliar_author_newuser" value="" /></div>
  </td>
</tr>

<tr><th colspan="3" style="text-align: left; padding-top: 1.0em; border-bottom: 1px dotted black;">For posts by specific authors. Blank out a name to delete the rule.</th></tr>

<?php 
        if (isset($link->settings['map authors'])) {
            $i = 0;
            foreach ($link->settings['map authors'] as $author_rules) {
                foreach ($author_rules as $author_name => $author_action) {
                    $i++;
                    ?>
<tr>
  <th style="text-align: left">Posts by <input type="text" name="author_rules_name[]" value="<?php 
                    echo htmlspecialchars($author_name);
                    ?>
" /></th>
  <td>
  <select id="author-rules-<?php 
                    echo $i;
                    ?>
" name="author_rules_action[]" onchange="flip_newuser('author-rules-<?php 
                    echo $i;
                    ?>
');">
    <?php 
                    foreach ($authorlist as $local_author_id => $local_author_name) {
                        ?>
    <option value="<?php 
                        echo $local_author_id;
                        ?>
"<?php 
                        if ($local_author_id == $author_action) {
                            echo ' selected="selected"';
                        }
                        ?>
>are assigned to <?php 
                        echo $local_author_name;
                        ?>
</option>
    <?php 
                    }
                    ?>
    <option value="newuser">will be assigned to a new user...</option>
    <option value="filter"<?php 
                    if ('filter' == $author_action) {
                        echo ' selected="selected"';
                    }
                    ?>
>get filtered out</option>
  </select>
  </td>
  <td><div id="author-rules-<?php 
                    echo $i;
                    ?>
-newuser">named <input type="text" name="author_rules_newuser[]" value="" /></div></td>
</tr>
<?php 
                }
            }
        }
        ?>

<tr><th colspan="3" style="text-align: left; padding-top: 1.0em; border-bottom: 1px dotted black;">Fill in to set up a new rule:</th></tr>

<tr>
  <th style="text-align: left">Posts by <input type="text" name="add_author_rule_name" /></th>
  <td>
    <select id="add-author-rule" name="add_author_rule_action" onchange="flip_newuser('add-author-rule');">
      <?php 
        foreach ($authorlist as $author_id => $author_name) {
            ?>
      <option value="<?php 
            echo $author_id;
            ?>
">are assigned to <?php 
            echo $author_name;
            ?>
</option>
      <?php 
        }
        ?>
      <option value="newuser">will be assigned to a new user...</option>
      <option value="filter">get filtered out</option>
    </select>
  </td>
  <td><div id="add-author-rule-newuser">named <input type="text" name="add_author_rule_newuser" value="" /></div></td>
</tr>

</table>
<?php 
        fwp_option_box_closer();
        ?>

<script>
	flip_newuser('unfamiliar-author');
<?php 
        for ($j = 1; $j <= $i; $j++) {
            ?>
	flip_newuser('author-rules-<?php 
            echo $j;
            ?>
');
<?php 
        }
        ?>
	flip_newuser('add-author-rule');
</script>

<?php 
        fwp_linkedit_periodic_submit();
        fwp_option_box_opener('Comments & Pings', 'commentstatusdiv', 'postbox');
        ?>
<table class="editform" width="75%" cellspacing="2" cellpadding="5">
<tr><th width="27%" scope="row" style="vertical-align:top"><?php 
        print __('Comments');
        ?>
:</th>
<td width="73%"><ul style="margin:0; list-style:none">
<li><label><input type="radio" name="feed_comment_status" value="site-default"
<?php 
        echo $status['comment']['site-default'];
        ?>
 /> Use site-wide setting from <a href="admin.php?page=<?php 
        print $GLOBALS['fwp_path'];
        ?>
/syndication-options.php">Syndication Options</a>
(currently: <strong><?php 
        echo $comment_status_global ? $comment_status_global : 'closed';
        ?>
)</strong></label></li>
<li><label><input type="radio" name="feed_comment_status" value="open"
<?php 
        echo $status['comment']['open'];
        ?>
 /> Allow comments on syndicated posts from this feed</label></li>
<li><label><input type="radio" name="feed_comment_status" value="closed"
<?php 
        echo $status['comment']['closed'];
        ?>
 /> Don't allow comments on syndicated posts from this feed</label></li>
</ul></td></tr>

<tr><th width="27%" scope="row" style="vertical-align:top"><?php 
        print __('Pings');
        ?>
:</th>
<td width="73%"><ul style="margin:0; list-style:none">
<li><label><input type="radio" name="feed_ping_status" value="site-default"
<?php 
        echo $status['ping']['site-default'];
        ?>
 /> Use site-wide setting from <a href="admin.php?page=<?php 
        print $GLOBALS['fwp_path'];
        ?>
/syndication-options.php">Syndication Options</a>
(currently: <strong><?php 
        echo $ping_status_global ? $ping_status_global : 'closed';
        ?>
)</strong></label></li>
<li><label><input type="radio" name="feed_ping_status" value="open"
<?php 
        echo $status['ping']['open'];
        ?>
 /> Accept pings on syndicated posts from this feed</label></li>
<li><label><input type="radio" name="feed_ping_status" value="closed"
<?php 
        echo $status['ping']['closed'];
        ?>
 /> Don't accept pings on syndicated posts from this feed</label></li>
</ul></td></tr>

</table>
<?php 
        fwp_option_box_closer();
        fwp_linkedit_periodic_submit();
        ?>

<?php 
        fwp_option_box_opener('Custom Settings (for use in templates)', 'postcustom', 'postbox');
        ?>
<div id="postcustomstuff">
<table id="meta-list" cellpadding="3">
	<tr>
	<th>Key</th>
	<th>Value</th>
	<th>Action</th>
	</tr>

<?php 
        $i = 0;
        foreach ($link->settings as $key => $value) {
            if (!preg_match("^((" . implode(')|(', $special_settings) . "))\$i", $key)) {
                ?>
			<tr style="vertical-align:top">
			<th width="30%" scope="row"><input type="hidden" name="notes[<?php 
                echo $i;
                ?>
][key0]" value="<?php 
                echo wp_specialchars($key, 'both');
                ?>
" />
			<input id="notes-<?php 
                echo $i;
                ?>
-key" name="notes[<?php 
                echo $i;
                ?>
][key1]" value="<?php 
                echo wp_specialchars($key, 'both');
                ?>
" /></th>
			<td width="60%"><textarea rows="2" cols="40" id="notes-<?php 
                echo $i;
                ?>
-value" name="notes[<?php 
                echo $i;
                ?>
][value]"><?php 
                echo wp_specialchars($value, 'both');
                ?>
</textarea></td>
			<td width="10%"><select name="notes[<?php 
                echo $i;
                ?>
][action]">
			<option value="update">save changes</option>
			<option value="delete">delete this setting</option>
			</select></td>
			</tr>
<?php 
                $i++;
            }
        }
        ?>
	<tr>
	<th scope="row"><input type="text" size="10" name="notes[<?php 
        echo $i;
        ?>
][key1]" value="" /></th>
	<td><textarea name="notes[<?php 
        echo $i;
        ?>
][value]" rows="2" cols="40"></textarea></td>
	<td><em>add new setting...</em><input type="hidden" name="notes[<?php 
        echo $i;
        ?>
][action]" value="update" /></td>
	</tr>
</table>
<?php 
        fwp_option_box_closer();
        ?>

<?php 
        fwp_linkedit_periodic_submit();
        fwp_linkedit_single_submit_closer();
        ?>
</div> <!-- id="post-body" -->
</div> <!-- id="poststuff" -->
</div>
	<?php 
    }
    return false;
    // Don't continue
}
function fwp_authors_page()
{
    global $wpdb, $wp_db_version;
    check_admin_referer();
    // Make sure we arrived here from the Dashboard
    if (isset($GLOBALS['fwp_post']['save']) or isset($GLOBALS['fwp_post']['fix_mismatch'])) {
        $link_id = $_REQUEST['save_link_id'];
    } elseif (isset($_REQUEST['link_id'])) {
        $link_id = $_REQUEST['link_id'];
    } else {
        $link_id = NULL;
    }
    if (is_numeric($link_id) and $link_id) {
        $link =& new SyndicatedLink($link_id);
    } else {
        $link = NULL;
    }
    $mesg = null;
    if (!current_user_can('manage_links')) {
        die(__("Cheatin' uh ?"));
    } else {
        if (isset($GLOBALS['fwp_post']['fix_mismatch'])) {
            if ('newuser' == $GLOBALS['fwp_post']['fix_mismatch_to']) {
                $newuser_name = trim($GLOBALS['fwp_post']['fix_mismatch_to_newuser']);
                if (strlen($newuser_name) > 0) {
                    $userdata = array();
                    $userdata['ID'] = NULL;
                    $userdata['user_login'] = sanitize_user($newuser_name);
                    $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
                    $userdata['user_nicename'] = sanitize_title($newuser_name);
                    $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
                    $userdata['display_name'] = $wpdb->escape($newuser_name);
                    $newuser_id = wp_insert_user($userdata);
                    if (is_numeric($newuser_id)) {
                        $fix_mismatch_to_id = $newuser_id;
                    } else {
                        // TODO: Add some error detection and reporting
                    }
                } else {
                    // TODO: Add some error reporting
                }
            } else {
                $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...
                $post_ids = $wpdb->get_col("\n\t\t\t\tSELECT {$wpdb->posts}.id\n\t\t\t\tFROM {$wpdb->posts}, {$wpdb->postmeta}\n\t\t\t\tWHERE ({$wpdb->posts}.id = {$wpdb->postmeta}.post_id)\n\t\t\t\tAND {$wpdb->postmeta}.meta_key = 'syndication_feed_id'\n\t\t\t\tAND {$wpdb->postmeta}.meta_value = '{$link_id}'\n\t\t\t\tAND {$wpdb->posts}.post_author = '{$fix_mismatch_from_id}'\n\t\t\t\t");
                if (count($post_ids) > 0) {
                    // Re-assign them all to the correct author
                    if (is_numeric($fix_mismatch_to_id)) {
                        // re-assign to a particular user
                        $post_set = "(" . implode(",", $post_ids) . ")";
                        // Getting the revisions too, if there are any
                        if (fwp_test_wp_version(FWP_SCHEMA_26)) {
                            $parent_in_clause = "OR {$wpdb->posts}.post_parent IN {$post_set}";
                        } else {
                            $parent_in_clause = '';
                        }
                        $wpdb->query("\n\t\t\t\t\t\tUPDATE {$wpdb->posts}\n\t\t\t\t\t\tSET post_author='{$fix_mismatch_to_id}'\n\t\t\t\t\t\tWHERE ({$wpdb->posts}.id IN {$post_set}\n\t\t\t\t\t\t{$parent_in_clause})\n\t\t\t\t\t\t");
                        $mesg = "Re-assigned " . count($post_ids) . " post" . (count($post_ids) == 1 ? '' : 's') . ".";
                        // ... and kill them all
                    } elseif ($fix_mismatch_to_id == 'filter') {
                        foreach ($post_ids as $post_id) {
                            wp_delete_post($post_id);
                        }
                        $mesg = "Deleted " . count($post_ids) . " post" . (count($post_ids) == 1 ? '' : 's') . ".";
                    }
                } else {
                    $mesg = "Couldn't find any posts that matched your criteria.";
                }
            }
        } 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"]);
                    } elseif ('newuser' == $GLOBALS['fwp_post']["unfamiliar_author"]) {
                        $newuser_name = trim($GLOBALS['fwp_post']["unfamiliar_author_newuser"]);
                        $link->map_name_to_new_user(NULL, $newuser_name);
                    } 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) {
                            if ('newuser' == $author_action) {
                                $newuser_name = trim($GLOBALS['fwp_post']['author_rules_newuser'][$key]);
                                $link->map_name_to_new_user($name, $newuser_name);
                            } else {
                                $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) {
                        if ('newuser' == $author_action) {
                            $newuser_name = trim($GLOBALS['fwp_post']['add_author_rule_newuser']);
                            $link->map_name_to_new_user($name, $newuser_name);
                        } else {
                            $link->settings['map authors']['name'][$name] = $author_action;
                        }
                    }
                }
                $alter[] = "link_notes = '" . $wpdb->escape($link->settings_to_notes()) . "'";
                $alter_set = implode(", ", $alter);
                // issue update query
                $result = $wpdb->query("\n\t\t\t\tUPDATE {$wpdb->links}\n\t\t\t\tSET {$alter_set}\n\t\t\t\tWHERE link_id='{$link_id}'\n\t\t\t\t");
                $updated_link = true;
                // reload link information from DB
                if (function_exists('clean_bookmark_cache')) {
                    clean_bookmark_cache($link_id);
                }
                $link =& new SyndicatedLink($link_id);
            } else {
                if ('newuser' == $GLOBALS['fwp_post']['unfamiliar_author']) {
                    $newuser_name = trim($GLOBALS['fwp_post']['unfamiliar_author_newuser']);
                    if (strlen($newuser_name) > 0) {
                        $userdata = array();
                        $userdata['ID'] = NULL;
                        $userdata['user_login'] = sanitize_user($newuser_name);
                        $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
                        $userdata['user_nicename'] = sanitize_title($newuser_name);
                        $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
                        $userdata['display_name'] = $wpdb->escape($newuser_name);
                        $newuser_id = wp_insert_user($userdata);
                        if (is_numeric($newuser_id)) {
                            update_option('feedwordpress_unfamiliar_author', $newuser_id);
                        } else {
                            // TODO: Add some error detection and reporting
                        }
                    } else {
                        // TODO: Add some error reporting
                    }
                } 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;
            }
        } else {
            $updated_link = false;
        }
        $unfamiliar = array('create' => '', 'default' => '', 'filter' => '');
        if (is_object($link) and $link->found()) {
            if (is_string($link->settings["unfamiliar author"])) {
                $key = $link->settings["unfamiliar author"];
            } else {
                $key = 'site-default';
            }
        } else {
            $key = FeedWordPress::on_unfamiliar('author');
        }
        $unfamiliar[$key] = ' selected="selected"';
        $match_author_by_email = !('yes' == get_option("feedwordpress_do_not_match_author_by_email"));
        $null_emails = FeedWordPress::null_email_set();
        ?>
<script type="text/javascript">
	function contextual_appearance (item, appear, disappear, value, visibleStyle, checkbox) {
		if (typeof(visibleStyle)=='undefined') visibleStyle = 'block';

		var rollup=document.getElementById(item);
		var newuser=document.getElementById(appear);
		var sitewide=document.getElementById(disappear);
		if (rollup) {
			if ((checkbox && rollup.checked) || (!checkbox && value==rollup.value)) {
				if (newuser) newuser.style.display=visibleStyle;
				if (sitewide) sitewide.style.display='none';
			} else {
				if (newuser) newuser.style.display='none';
				if (sitewide) sitewide.style.display=visibleStyle;
			}
		}
	}
</script>

<?php 
        if ($updated_link) {
            ?>
<div class="updated"><p>Syndicated author settings updated.</p></div>
<?php 
        } elseif (!is_null($mesg)) {
            ?>
<div class="updated"><p><?php 
            print wp_specialchars($mesg, 1);
            ?>
</p></div>
<?php 
        }
        ?>

<div class="wrap">
<form style="position: relative" action="admin.php?page=<?php 
        print $GLOBALS['fwp_path'];
        ?>
/<?php 
        echo basename(__FILE__);
        ?>
" method="post">
<?php 
        if (is_numeric($link_id) and $link_id) {
            ?>
<input type="hidden" name="save_link_id" value="<?php 
            echo $link_id;
            ?>
" />
<?php 
        } else {
            ?>
<input type="hidden" name="save_link_id" value="*" />
<?php 
        }
        ?>

<?php 
        $links = FeedWordPress::syndicated_links();
        if (fwp_test_wp_version(FWP_SCHEMA_27)) {
            ?>
	<div class="icon32"><img src="<?php 
            print htmlspecialchars(WP_PLUGIN_URL . '/' . $GLOBALS['fwp_path'] . '/feedwordpress.png');
            ?>
" alt="" /></div>
<?php 
        }
        ?>
<h2>Syndicated Author Settings<?php 
        if (!is_null($link) and $link->found()) {
            ?>
: <?php 
            echo wp_specialchars($link->link->link_name, 1);
        }
        ?>
</h2>
<?php 
        if (fwp_test_wp_version(FWP_SCHEMA_27)) {
            ?>
	<style type="text/css">
	#post-search {
		float: right;
		margin:11px 12px 0;
		min-width: 130px;
		position:relative;
	}
	.fwpfs {
		color: #dddddd;
		background:#797979 url(<?php 
            bloginfo('home');
            ?>
/wp-admin/images/fav.png) repeat-x scroll left center;
		border-color:#777777 #777777 #666666 !important; -moz-border-radius-bottomleft:12px;
		-moz-border-radius-bottomright:12px;
		-moz-border-radius-topleft:12px;
		-moz-border-radius-topright:12px;
		border-style:solid;
		border-width:1px;
		line-height:15px;
		padding:3px 30px 4px 12px;
	}
	.fwpfs.slide-down {
		border-bottom-color: #626262;
		-moz-border-radius-bottomleft:0;
		-moz-border-radius-bottomright:0;
		-moz-border-radius-topleft:12px;
		-moz-border-radius-topright:12px;
		background-image:url(<?php 
            bloginfo('home');
            ?>
/wp-admin/images/fav-top.png);
		background-position:0 top;
		background-repeat:repeat-x;
		border-bottom-style:solid;
		border-bottom-width:1px;
	}
	</style>
	
	<script type="text/javascript">
		jQuery(document).ready(function($){
			$('.fwpfs').toggle(
				function(){$('.fwpfs').removeClass('slideUp').addClass('slideDown'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideDown') ) { $('.fwpfs').addClass('slide-down'); }}, 10) },
				function(){$('.fwpfs').removeClass('slideDown').addClass('slideUp'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideUp') ) { $('.fwpfs').removeClass('slide-down'); }}, 10) }
			);
			$('.fwpfs').bind(
				'change',
				function () { this.form.submit(); }
			);
			$('#post-search .button').css( 'display', 'none' );
		});
	</script>
<?php 
        }
        /* else : */
        ?>
<p id="post-search">
<select name="link_id" class="fwpfs" style="max-width: 20.0em;">
  <option value="*"<?php 
        if (is_null($link) or !$link->found()) {
            ?>
 selected="selected"<?php 
        }
        ?>
>- defaults for all feeds -</option>
<?php 
        if ($links) {
            foreach ($links as $ddlink) {
                ?>
  <option value="<?php 
                print (int) $ddlink->link_id;
                ?>
"<?php 
                if (!is_null($link) and $link->link->link_id == $ddlink->link_id) {
                    ?>
 selected="selected"<?php 
                }
                ?>
><?php 
                print wp_specialchars($ddlink->link_name, 1);
                ?>
</option>
<?php 
            }
        }
        ?>
</select>
<input class="button" type="submit" name="go" value="<?php 
        _e('Go');
        ?>
 &raquo;" />
</p>
<?php 
        /* endif; */
        ?>

<?php 
        if (!is_null($link) and $link->found()) {
            ?>
	<p>These settings only affect posts syndicated from
	<strong><?php 
            echo wp_specialchars($link->link->link_name, 1);
            ?>
</strong>.</p>
<?php 
        } else {
            ?>
	<p>These settings affect posts syndicated from any feed unless they are overridden
	by settings for that specific feed.</p>
<?php 
        }
        ?>

<?php 
        $authorlist = fwp_author_list();
        ?>
<table class="form-table">
<tbody>
<tr>
  <th>New authors</th>
  <td><span>Authors who haven't been syndicated before</span>
  <select style="max-width: 27.0em" id="unfamiliar-author" name="unfamiliar_author" onchange="contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline');">
<?php 
        if (is_object($link) and $link->found()) {
            ?>
    <option value="site-default"<?php 
            print $unfamiliar['site-default'];
            ?>
>are handled according to the default for all feeds</option>
<?php 
        }
        ?>
    <option value="create"<?php 
        $unfamiliar['create'];
        ?>
>will have a new author account created for them</option>
    <?php 
        foreach ($authorlist as $author_id => $author_name) {
            ?>
      <option value="<?php 
            echo $author_id;
            ?>
"<?php 
            print $unfamiliar[$author_id];
            ?>
>will have their posts attributed to <?php 
            echo $author_name;
            ?>
</option>
    <?php 
        }
        ?>
    <option value="newuser">will have their posts attributed to a new user...</option>
    <option value="filter"<?php 
        print $unfamiliar['filter'];
        ?>
>get filtered out</option>
  </select>

  <span id="unfamiliar-author-newuser">named <input type="text" name="unfamiliar_author_newuser" value="" /></span></p>
  </td>
</tr>

<?php 
        if (is_object($link) and $link->found()) {
            ?>
<tr><th>Syndicated authors</th>
<td>For attributing posts by specific authors. Blank out a name to delete the rule. Fill in a new name at the bottom to create a new rule.</p>
<table style="width: 100%">
<?php 
            if (isset($link->settings['map authors'])) {
                $i = 0;
                foreach ($link->settings['map authors'] as $author_rules) {
                    foreach ($author_rules as $author_name => $author_action) {
                        $i++;
                        ?>
<tr>
<th style="text-align: left; width: 15.0em">Posts by <input type="text" name="author_rules_name[]" value="<?php 
                        echo htmlspecialchars($author_name);
                        ?>
" size="11" /></th>
  <td>
  <select id="author-rules-<?php 
                        echo $i;
                        ?>
" name="author_rules_action[]" onchange="contextual_appearance('author-rules-<?php 
                        echo $i;
                        ?>
', 'author-rules-<?php 
                        echo $i;
                        ?>
-newuser', 'author-rules-<?php 
                        echo $i;
                        ?>
-default', 'newuser', 'inline');">
    <?php 
                        foreach ($authorlist as $local_author_id => $local_author_name) {
                            ?>
    <option value="<?php 
                            echo $local_author_id;
                            ?>
"<?php 
                            if ($local_author_id == $author_action) {
                                echo ' selected="selected"';
                            }
                            ?>
>are assigned to <?php 
                            echo $local_author_name;
                            ?>
</option>
    <?php 
                        }
                        ?>
    <option value="newuser">will be assigned to a new user...</option>
    <option value="filter"<?php 
                        if ('filter' == $author_action) {
                            echo ' selected="selected"';
                        }
                        ?>
>get filtered out</option>
  </select>
  
  <span id="author-rules-<?php 
                        echo $i;
                        ?>
-newuser">named <input type="text" name="author_rules_newuser[]" value="" /></span>
  </td>
</tr>
<?php 
                    }
                }
            }
            ?>

<tr>
<th style="text-align: left; width: 15.0em">Posts by <input type="text" name="add_author_rule_name" size="11" /></th>
  <td>
    <select id="add-author-rule" name="add_author_rule_action" onchange="contextual_appearance('add-author-rule', 'add-author-rule-newuser', 'add-author-rule-default', 'newuser', 'inline');">
      <?php 
            foreach ($authorlist as $author_id => $author_name) {
                ?>
      <option value="<?php 
                echo $author_id;
                ?>
">are assigned to <?php 
                echo $author_name;
                ?>
</option>
      <?php 
            }
            ?>
      <option value="newuser">will be assigned to a new user...</option>
      <option value="filter">get filtered out</option>
    </select>
   
   <span id="add-author-rule-newuser">named <input type="text" name="add_author_rule_newuser" value="" /></span>
   </td>
</tr>
</table>
</td>
</tr>
<?php 
        }
        ?>

<?php 
        if (!(is_object($link) and $link->found())) {
            ?>
<tr>
<th scope="row">Matching Authors</th>
<td><ul style="list-style: none; margin: 0; padding: 0;">
<li><div><label><input id="match-author-by-email" type="checkbox" name="match_author_by_email" value="yes" <?php 
            if ($match_author_by_email) {
                ?>
checked="checked" <?php 
            }
            ?>
onchange="contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', 'block', /*checkbox=*/ true);" /> Treat syndicated authors with the same e-mail address as the same author.</label></div>
<div id="unless-null-email">
<p>Unless the e-mail address is one of the following anonymous e-mail addresses:</p>
<textarea name="null_emails" rows="3" style="width: 100%">
<?php 
            print implode("\n", $null_emails);
            ?>
</textarea>
</div></li>
</ul></td>
</tr>
<?php 
        } else {
            ?>
<th scope="row">Fixing mis-matched authors:</th>
<td><p style="margin: 0.5em 0px">Take all the posts from this feed attributed to
<select name="fix_mismatch_from">
<?php 
            foreach ($authorlist as $author_id => $author_name) {
                ?>
      <option value="<?php 
                echo $author_id;
                ?>
"><?php 
                echo $author_name;
                ?>
</option>
<?php 
            }
            ?>
</select>
and instead
<select id="fix-mismatch-to" name="fix_mismatch_to" onchange="contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline');">
<?php 
            foreach ($authorlist as $author_id => $author_name) {
                ?>
      <option value="<?php 
                echo $author_id;
                ?>
">re-assign them to <?php 
                echo $author_name;
                ?>
</option>
<?php 
            }
            ?>
      <option value="newuser">re-assign them to a new user...</option>
      <option value="filter">delete them</option>
</select>

   <span id="fix-mismatch-to-newuser">named <input type="text" name="fix_mismatch_to_newuser" value="" /></span>
   <input type="submit" class="button" name="fix_mismatch" value="Fix it!" />
   </td>
</td>
<?php 
        }
        ?>
</tbody>
</table>

<p class="submit">
<input class="button-primary" type="submit" name="save" value="Save Changes" />
</p>

<script type="text/javascript">
	contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline');
<?php 
        if (is_object($link) and $link->found()) {
            for ($j = 1; $j <= $i; $j++) {
                ?>
	contextual_appearance('author-rules-<?php 
                echo $j;
                ?>
', 'author-rules-<?php 
                echo $j;
                ?>
-newuser', 'author-rules-<?php 
                echo $j;
                ?>
-default', 'newuser', 'inline');
<?php 
            }
            ?>
	contextual_appearance('add-author-rule', 'add-author-rule-newuser', 'add-author-rule-default', 'newuser', 'inline');
	contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline');
<?php 
        } else {
            ?>
	contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', 'block', /*checkbox=*/ true);
<?php 
        }
        ?>
</script>
</form>
</div> <!-- class="wrap" -->
	<?php 
    }
}
 function store()
 {
     global $wpdb;
     if ($this->filtered()) {
         // This should never happen.
         FeedWordPress::critical_bug('SyndicatedPost', $this, __LINE__);
     }
     $freshness = $this->freshness();
     if ($freshness > 0) {
         # -- Look up, or create, numeric ID for author
         $this->post['post_author'] = $this->author_id(FeedWordPress::on_unfamiliar('author', $this->post['named']['unfamiliar']['author']));
         if (is_null($this->post['post_author'])) {
             $this->post = NULL;
         }
     }
     if (!$this->filtered() and $freshness > 0) {
         # -- Look up, or create, numeric ID for categories
         list($pcats, $ptags) = $this->category_ids($this->post['named']['category'], FeedWordPress::on_unfamiliar('category', $this->post['named']['unfamiliar']['category']), true);
         $this->post['post_category'] = $pcats;
         $this->post['tags_input'] = array_merge($this->post['tags_input'], $ptags);
         if (is_null($this->post['post_category'])) {
             // filter mode on, no matching categories; drop the post
             $this->post = NULL;
         } else {
             // filter mode off or at least one match; now add on the feed and global presets
             $this->post['post_category'] = array_merge($this->post['post_category'], $this->category_ids($this->post['named']['preset/category'], 'default'));
             if (count($this->post['post_category']) < 1) {
                 $this->post['post_category'][] = 1;
                 // Default to category 1 ("Uncategorized" / "General") if nothing else
             }
         }
     }
     if (!$this->filtered() and $freshness > 0) {
         unset($this->post['named']);
         $this->post = apply_filters('syndicated_post', $this->post, $this);
     }
     if (!$this->filtered() and $freshness == 2) {
         // The item has not yet been added. So let's add it.
         $this->insert_new();
         $this->add_rss_meta();
         do_action('post_syndicated_item', $this->wp_id());
         $ret = 'new';
     } elseif (!$this->filtered() and $freshness == 1) {
         $this->post['ID'] = $this->wp_id();
         $this->update_existing();
         $this->add_rss_meta();
         do_action('update_syndicated_item', $this->wp_id());
         $ret = 'updated';
     } else {
         $ret = false;
     }
     return $ret;
 }
    function feed_categories_box($page, $box = NULL)
    {
        $link = $page->link;
        $unfamiliar = array('create' => '', 'tag' => '', 'default' => '', 'filter' => '');
        if ($page->for_feed_settings()) {
            $unfamiliar['site-default'] = '';
            $ucKey = isset($link->settings["unfamiliar category"]) ? $link->settings["unfamiliar category"] : null;
            $ucDefault = 'site-default';
        } else {
            $ucKey = FeedWordPress::on_unfamiliar('category');
            $ucDefault = 'create';
        }
        if (!is_string($ucKey) or !array_key_exists($ucKey, $unfamiliar)) {
            $ucKey = $ucDefault;
        }
        $unfamiliar[$ucKey] = ' checked="checked"';
        // Hey ho, let's go...
        ?>
<table class="edit-form">
<tr>
<th scope="row">Unfamiliar categories:</th>
<td><p>When one of the categories on a syndicated post is a category that FeedWordPress has not encountered before ...</p>

<ul class="options">
<?php 
        if ($page->for_feed_settings()) {
            ?>
<li><label><input type="radio" name="unfamiliar_category" value="site-default"<?php 
            echo $unfamiliar['site-default'];
            ?>
 /> use the <a href="admin.php?page=<?php 
            echo FWP_CATEGORIES_PAGE_SLUG;
            ?>
">site-wide setting</a>
(currently <strong><?php 
            echo FeedWordPress::on_unfamiliar('category');
            ?>
</strong>)</label></li>
<?php 
        }
        ?>

<li><label><input type="radio" name="unfamiliar_category" value="create"<?php 
        echo $unfamiliar['create'];
        ?>
 /> create a new category</label></li>

<?php 
        if (FeedWordPressCompatibility::post_tags()) {
            ?>
<li><label><input type="radio" name="unfamiliar_category" value="tag"<?php 
            echo $unfamiliar['tag'];
            ?>
/> create a new tag</label></li>
<?php 
        }
        ?>

<li><label><input type="radio" name="unfamiliar_category" value="default"<?php 
        echo $unfamiliar['default'];
        ?>
 /> don't create new categories<?php 
        if (fwp_test_wp_version(FWP_SCHEMA_23)) {
            ?>
 or tags<?php 
        }
        ?>
</label></li>
<li><label><input type="radio" name="unfamiliar_category" value="filter"<?php 
        echo $unfamiliar['filter'];
        ?>
 /> don't create new categories<?php 
        if (fwp_test_wp_version(FWP_SCHEMA_23)) {
            ?>
 or tags<?php 
        }
        ?>
 and don't syndicate posts unless they match at least one familiar category</label></li>
</ul></td>
</tr>

<?php 
        if ($page->for_feed_settings()) {
            ?>
<tr>
<th scope="row">Multiple categories:</th>
<td> 
<input type="text" size="20" id="cat_split" name="cat_split" value="<?php 
            if (isset($link->settings['cat_split'])) {
                echo htmlspecialchars($link->settings['cat_split']);
            }
            ?>
" />
<p class="setting-description">Enter a <a href="http://us.php.net/manual/en/reference.pcre.pattern.syntax.php">Perl-compatible regular expression</a> here if the feed provides multiple
categories in a single category element. The regular expression should match
the characters used to separate one category from the next. If the feed uses
spaces (like <a href="http://del.icio.us/">del.icio.us</a>), use the pattern "\s".
If the feed does not provide multiple categories in a single element, leave this
blank.</p></td>
</tr>
<?php 
        }
        ?>
</table>
		<?php 
    }