function posts_request($sql, &$query)
 {
     if ($query->get('fields') == '_synfresh') {
         FeedWordPress::diagnostic('feed_items:freshness:sql', "SQL: " . $sql);
     }
     return $sql;
 }
 function poll($crash_ts = NULL)
 {
     // Do nothing but update copy of feed
     $this->simplepie = FeedWordPress::fetch($this->url);
     $this->magpie = new MagpieFromSimplePie($this->simplepie);
     $this->link = $this->magpie;
 }
 function accept_POST($post)
 {
     if (isset($post['clear_cache'])) {
         $N = FeedWordPress::clear_cache();
         $feeds = $N == 1 ? __("feed") : __("feeds");
         $this->updated = sprintf(__("Cleared %d cached %s from WordPress database."), $N, $feeds);
     }
 }
 public function meta($what, $params = array())
 {
     // -=-=-= 1. INITIAL SETUP. =-=-=-
     $params = wp_parse_args($params, array("single" => true, "default" => NULL, "global" => NULL, "unproxied setting" => NULL, "unproxy" => false));
     // This is a little weird, just bear with me here.
     $results = array();
     // Has this been left up to the admin setting?
     if (is_null($params['unproxy'])) {
         $params['unproxy'] = FeedWordPress::use_aggregator_source_data();
     }
     // -=-=-= 2. GET DATA FROM THE PROXIMATE OR THE ULTIMATE SOURCE. =-=-=-
     // Now if we are supposed to look for ultimate source data (e.g. from
     // <atom:source> ... </atom:source> elements), do so here.
     if ($params['unproxy']) {
         if (!is_string($params['unproxied setting'])) {
             // Default pattern for unproxied settings: {$name}_original
             $params['unproxied setting'] = $what . '_original';
         }
         // Now see if there's anything in postmeta from our ultimate source.
         // If so, then we can cut out the middle man here.
         $results = get_post_meta($this->post->ID, $params['unproxied setting'], false);
     }
     // If we weren't looking for ultimate source data, or if there wasn't
     // any recorded, then grab this from the data for the proximate source.
     if (empty($results)) {
         $results = get_post_meta($this->post->ID, $what, false);
     }
     // -=-=-= 3. DEAL WITH THE RESULTS, IF ANY, OR FALLBACK VALUES. =-=-=-
     // If we have results now, cool. Just pass them back.
     if (!empty($results)) {
         $ret = $params['single'] ? $results[0] : $results;
         // If we got no results but we have a fallback global setting, cool. Use
         // that. Jam it into a singleton array for queries expecting an array of
         // results instead of a scalar result.
     } elseif (is_string($params['global']) and strlen($params['global']) > 0) {
         $opt = get_option($params['global'], $params['default']);
         $ret = $params['single'] ? $opt : array($opt);
         // If we got no results and we have no fallback global setting, pass
         // back a default value for single-result queries, or an empty array for
         // multiple-result queries.
     } else {
         $ret = $params['single'] ? $params['default'] : array();
     }
     return $ret;
 }
 function unsubscribe($method, $args)
 {
     $ret = $this->validate($args);
     if (is_array($ret)) {
         // Success
         // The remaining params are feed URLs
         foreach ($args as $arg) {
             $link_id = FeedWordPress::find_link($arg);
             if (!$link_id) {
                 $link_id = FeedWordPress::find_link($arg, 'link_url');
             }
             if ($link_id) {
                 $link = new SyndicatedLink($link_id);
                 $link->{$method}();
                 $ret[] = array('deactivated', $arg);
             } else {
                 $ret[] = array('error', $arg);
             }
         }
     }
     return $ret;
 }
    function display()
    {
        global $wp_db_version;
        global $fwp_post;
        if (FeedWordPress::needs_upgrade()) {
            fwp_upgrade_page();
            return;
        }
        // If this is a POST, validate source and user credentials
        FeedWordPressCompatibility::validate_http_request('feedwordpress_diagnostics', 'manage_options');
        if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
            $this->accept_POST($fwp_post);
            do_action('feedwordpress_admin_page_diagnostics_save', $GLOBALS['fwp_post'], $this);
        }
        ////////////////////////////////////////////////
        // Prepare settings page ///////////////////////
        ////////////////////////////////////////////////
        $this->display_update_notice_if_updated('Diagnostics');
        $this->open_sheet('FeedWordPress Diagnostics');
        ?>
		<div id="post-body">
		<?php 
        $boxes_by_methods = array('diagnostics_box' => __('Diagnostics'), 'updates_box' => __('Updates'));
        foreach ($boxes_by_methods as $method => $title) {
            fwp_add_meta_box('feedwordpress_' . $method, $title, array('FeedWordPressDiagnosticsPage', $method), $this->meta_box_context(), $this->meta_box_context());
        }
        do_action('feedwordpress_admin_page_diagnostics_meta_boxes', $this);
        ?>
			<div class="metabox-holder">
			<?php 
        fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
        ?>
			</div> <!-- class="metabox-holder" -->
		</div> <!-- id="post-body" -->

		<?php 
        $this->close_sheet();
    }
	function get_settings_from_notes () {
		// Read off feed settings from link_notes
		$notes = explode("\n", $this->link->link_notes);
		foreach ($notes as $note):
			$pair = explode(": ", $note, 2);
			$key = (isset($pair[0]) ? $pair[0] : null);
			$value = (isset($pair[1]) ? $pair[1] : null);
			if (!is_null($key) and !is_null($value)) :
				// Unescape and trim() off the whitespace.
				// Thanks to Ray Lischner for pointing out the
				// need to trim off whitespace.
				$this->settings[$key] = stripcslashes (trim($value));
			endif;
		endforeach;

		// "Magic" feed settings
		$this->settings['link/uri'] = $this->link->link_rss;
		$this->settings['link/name'] = $this->link->link_name;
		$this->settings['link/id'] = $this->link->link_id;
		
		// `hardcode categories` and `unfamiliar categories` are
		// deprecated in favor of `unfamiliar category`
		if (
			isset($this->settings['unfamiliar categories'])
			and !isset($this->settings['unfamiliar category'])
		) :
			$this->settings['unfamiliar category'] = $this->settings['unfamiliar categories'];
		endif;
		if (
			FeedWordPress::affirmative($this->settings, 'hardcode categories')
			and !isset($this->settings['unfamiliar category'])
		) :
			$this->settings['unfamiliar category'] = 'default';
		endif;

		// Set this up automagically for del.icio.us
		$bits = parse_url($this->link->link_rss);
		$tagspacers = array('del.icio.us', 'feeds.delicious.com');
		if (!isset($this->settings['cat_split']) and in_array($bits['host'], $tagspacers)) : 
			$this->settings['cat_split'] = '\s'; // Whitespace separates multiple tags in del.icio.us RSS feeds
		endif;

		// Simple lists
		foreach ($this->imploded_settings() as $what) :
			if (isset($this->settings[$what])):
				$this->settings[$what] = explode(
					FEEDWORDPRESS_CAT_SEPARATOR,
					$this->settings[$what]
				);
			endif;
		endforeach;

		if (isset($this->settings['terms'])) :
			// Look for new format
			$this->settings['terms'] = maybe_unserialize($this->settings['terms']);
			
			if (!is_array($this->settings['terms'])) :
				// Deal with old format instead. Ugh.

				// Split on two *or more* consecutive breaks
				// because in the old format, a taxonomy
				// without any associated terms would
				// produce tax_name#1\n\n\ntax_name#2\nterm,
				// and the naive split on the first \n\n
				// would screw up the tax_name#2 list.
				//
				// Props to David Morris for pointing this
				// out.

				$this->settings['terms'] = preg_split(
					"/".FEEDWORDPRESS_CAT_SEPARATOR."{2,}/",
					$this->settings['terms']
				);
				$terms = array();
				foreach ($this->settings['terms'] as $line) :
					$line = explode(FEEDWORDPRESS_CAT_SEPARATOR, $line);
					$tax = array_shift($line);
					$terms[$tax] = $line;
				endforeach;
				$this->settings['terms'] = $terms;
			endif;
		endif;

		if (isset($this->settings['map authors'])) :
			$author_rules = explode("\n\n", $this->settings['map authors']);
			$ma = array();
			foreach ($author_rules as $rule) :
				list($rule_type, $author_name, $author_action) = explode("\n", $rule);
				
				// Normalize for case and whitespace
				$rule_type = strtolower(trim($rule_type));
				$author_name = strtolower(trim($author_name));
				$author_action = strtolower(trim($author_action));
				
				$ma[$rule_type][$author_name] = $author_action;
			endforeach;
			$this->settings['map authors'] = $ma;
		endif;

	} /* SyndicatedLink::get_settings_from_notes () */
 function post($key, $default = NULL)
 {
     return FeedWordPress::param($key, 'POST');
 }
 function save_settings($post)
 {
     if ($this->for_feed_settings()) {
         if (isset($post['link_rss_params_key'])) {
             $qp = array();
             foreach ($post['link_rss_params_key'] as $index => $key) {
                 if (strlen($key) > 0) {
                     if (isset($post['link_rss_params_value'][$index]) and strlen($post['link_rss_params_value'][$index])) {
                         $value = $post['link_rss_params_value'][$index];
                         $qp[] = array($key, $value);
                     }
                 }
             }
             $this->update_setting('query parameters', serialize($qp));
         }
         // custom feed settings first
         foreach ($post['notes'] as $mn) {
             $mn['key0'] = isset($mn['key0']) ? trim($mn['key0']) : NULL;
             $mn['key1'] = trim($mn['key1']);
             if (preg_match("^((" . implode(')|(', $this->special_settings) . "))\$i", $mn['key1'])) {
                 $mn['key1'] = 'user/' . $mn['key1'];
             }
             if (strlen($mn['key0']) > 0) {
                 unset($this->link->settings[$mn['key0']]);
                 // out with the old
             }
             if ($mn['action'] == 'update' and strlen($mn['key1']) > 0) {
                 $this->link->settings[$mn['key1']] = $mn['value'];
                 // in with the new
             }
         }
         // now stuff through the web form
         // hardcoded feed info
         foreach (array('name', 'description', 'url') as $what) {
             // We have a checkbox for "No," so if it's unchecked, mark as "Yes."
             $this->link->settings["hardcode {$what}"] = isset($post["hardcode_{$what}"]) ? $post["hardcode_{$what}"] : 'yes';
             if (FeedWordPress::affirmative($this->link->settings, "hardcode {$what}")) {
                 $this->link->link->{'link_' . $what} = $post['link' . $what];
             }
         }
         // Update scheduling
         if (isset($post['update_schedule'])) {
             $this->link->settings['update/hold'] = $post['update_schedule'];
         }
         if (isset($post['use_default_update_window']) and strtolower($post['use_default_update_window']) == 'yes') {
             unset($this->link->settings['update/window']);
         } elseif (isset($post['update_window'])) {
             if ((int) $post['update_window'] > 0) {
                 $this->link->settings['update/window'] = (int) $post['update_window'];
             }
         }
     } else {
         // Global
         update_option('feedwordpress_cat_id', $post['syndication_category']);
         if (!isset($post['automatic_updates']) or !in_array($post['automatic_updates'], array('init', 'shutdown'))) {
             $automatic_updates = NULL;
         } else {
             $automatic_updates = $post['automatic_updates'];
         }
         update_option('feedwordpress_automatic_updates', $automatic_updates);
         if (isset($post['update_window'])) {
             if ((int) $post['update_window'] > 0) {
                 update_option('feedwordpress_update_window', (int) $post['update_window']);
             }
         }
         update_option('feedwordpress_update_time_limit', $post['update_time_limit'] == 'yes' ? (int) $post['time_limit_seconds'] : 0);
         foreach (array('name', 'description', 'url') as $what) {
             // We have a checkbox for "No," so if it's unchecked, mark as "Yes."
             $hardcode = isset($post["hardcode_{$what}"]) ? $post["hardcode_{$what}"] : 'yes';
             update_option("feedwordpress_hardcode_{$what}", $hardcode);
         }
     }
     if (isset($post['fetch_timeout'])) {
         if (isset($post['fetch_timeout_default']) and $post['fetch_timeout_default'] == 'yes') {
             $timeout = NULL;
         } else {
             $timeout = $post['fetch_timeout'];
         }
         if (is_int($timeout)) {
             $timeout = intval($timeout);
         }
         $this->update_setting('fetch timeout', $timeout);
     }
     if (isset($post['update_minimum'])) {
         $this->update_setting('update/minimum', $post['update_minimum']);
     }
     if (isset($post['link_rss_auth_method']) and $post['link_rss_auth_method'] and '-' != $post['link_rss_auth_method']) {
         $this->update_setting('http auth method', $post['link_rss_auth_method']);
     } else {
         $this->update_setting('http auth method', NULL);
     }
     if (isset($post['link_rss_username']) and strlen($post['link_rss_username']) > 0 and '-' != $post['link_rss_auth_method']) {
         $this->update_setting('http username', $post['link_rss_username']);
     } else {
         $this->update_setting('http username', NULL);
     }
     if (isset($post['link_rss_password']) and strlen($post['link_rss_password']) > 0 and '-' != $post['link_rss_auth_method']) {
         $this->update_setting('http password', $post['link_rss_password']);
     } else {
         $this->update_setting('http password', NULL);
     }
     $this->updatedPosts->accept_POST($post);
     parent::save_settings($post);
 }
 /**
  * category_ids: look up (and create) category ids from a list of
  * categories
  *
  * @param array $cats
  * @param string $unfamiliar_category
  * @param array|null $taxonomies
  * @return array
  */
 function category_ids($post, $cats, $unfamiliar_category = 'create', $taxonomies = NULL, $params = array())
 {
     $singleton = isset($params['singleton']) ? $params['singleton'] : true;
     $allowFilters = isset($params['filters']) ? $params['filters'] : false;
     $catTax = 'category';
     if (is_null($taxonomies)) {
         $taxonomies = array('category');
     }
     // We need to normalize whitespace because (1) trailing
     // whitespace can cause PHP and MySQL not to see eye to eye on
     // VARCHAR comparisons for some versions of MySQL (cf.
     // <http://dev.mysql.com/doc/mysql/en/char.html>), and (2)
     // because I doubt most people want to make a semantic
     // distinction between 'Computers' and 'Computers  '
     $cats = array_map('trim', $cats);
     $terms = array();
     foreach ($taxonomies as $tax) {
         $terms[$tax] = array();
     }
     foreach ($cats as $cat_name) {
         if (strlen(trim($cat_name)) < 1) {
             continue;
         }
         $oTerm = new SyndicatedPostTerm($cat_name, $taxonomies, $post);
         if ($oTerm->is_familiar()) {
             $tax = $oTerm->taxonomy();
             if (!isset($terms[$tax])) {
                 $terms[$tax] = array();
             }
             $terms[$tax][] = $oTerm->id();
         } else {
             if ('tag' == $unfamiliar_category) {
                 $unfamiliar_category = 'create:post_tag';
             }
             if (preg_match('/^create(:(.*))?$/i', $unfamiliar_category, $ref)) {
                 $tax = $catTax;
                 // Default
                 if (isset($ref[2]) and strlen($ref[2]) > 2) {
                     $tax = $ref[2];
                 }
                 $inserted = $oTerm->insert($tax);
                 if (!is_null($inserted)) {
                     if (!isset($terms[$tax])) {
                         $terms[$tax] = array();
                     }
                     $terms[$tax][] = $inserted;
                 } else {
                 }
                 // !is_null($inserted)
             }
             // preg_match(...)
         }
         /* ($oTerm->is_familiar()) */
     }
     $filtersOn = $allowFilters;
     if ($allowFilters) {
         $filters = array_filter($this->setting('match/filter', 'match_filter', array()), 'remove_dummy_zero');
         $filtersOn = ($filtersOn and is_array($filters) and count($filters) > 0);
     }
     // Check for filter conditions
     foreach ($terms as $tax => $term_ids) {
         if ($filtersOn and count($term_ids) == 0 and in_array($tax, $filters)) {
             $terms = NULL;
             // Drop the post
             break;
         } else {
             $terms[$tax] = array_unique($term_ids);
         }
     }
     if ($singleton and count($terms) == 1) {
         // If we only searched one, just return the term IDs
         $terms = end($terms);
     }
     FeedWordPress::diagnostic('syndicated_posts:categories', 'Category: MAPPED term names ' . json_encode($cats) . ' to IDs: ' . json_encode($terms));
     return $terms;
 }
    function performance_box($page, $box = NULL)
    {
        $optimize_in = get_option('feedwordpress_optimize_in_clauses', false);
        // Hey ho, let's go...
        ?>
<table class="editform" width="100%" cellspacing="2" cellpadding="5">
<tr style="vertical-align: top">
<th width="33%" scope="row">Feed cache:</th>
<td width="67%"><input class="button" type="submit" name="clear_cache" value="Clear all cached feeds from WordPress database" />
<p>This will clear all cached copies of feed data from the WordPress database
and force FeedWordPress to make a fresh scan for updates on syndicated feeds.</p></td></tr>

<tr style="vertical-align: top">
<th width="33%" scope="row">Guid index:</th>
<td width="67%"><?php 
        if (!FeedWordPress::has_guid_index()) {
            ?>
<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>
<?php 
        } else {
            ?>

<p>You have already created an index on the guid column in the WordPress posts
table. If you'd like to remove the index for any reason, you can do so here.</p>

<input class="button" type="submit" name="remove_index" value="Remove index on guid column in posts database table" />

<?php 
        }
        ?>

<tr style="vertical-align: top">
<th width="33%" scope="row">Optimize IN clauses:</th>
<td width="67%"><?php 
        if (!$optimize_in) {
            ?>
<input class="button" type="submit" name="optimize_in" value="Optimize inefficient IN clauses in SQL queries" />

<p><strong>Advanced setting.</strong> As of releases up to 3.3.2, WordPress
still generates many SQL queries with an extremely inefficient use of the IN
operator (for example, <code>SELECT user_id, meta_key, meta_value FROM
wp_usermeta WHERE user_id IN (1)</code>). When there is only one item in the
set, the IN operator is unnecessary; and inefficient, because it prevents SQL
from making use of indexes on the table being queried. Activating this setting
will cause these queries to get rewritten to use a simple equality operator when
there is only one item in the set (for example, the example query above would be
rewritten as <code>SELECT user_id, meta_key, meta_value FROM wp_usermeta WHERE
user_id = 1</code>).</p>

<p><strong>Note.</strong> This is an advanced setting, which affects WordPress's
database queries at a very low level. The change should be harmless, but
proceed with caution, and only if you are confident in your ability to restore
your WordPress installation from backups if something important should stop
working.</p>

<?php 
        } else {
            ?>
<input class="button" type="submit" name="optimize_out" value="Disable optimizing inefficient IN clauses" />
<p>You can use this setting to disable any attempts by FeedWordPress to optimize
or rewrite WordPress's SQL queries.</p>
<?php 
        }
        ?>
</td>
</tr>

</td>
</tr>
</table>
		<?php 
    }
	function __construct ($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) {
		global $feedwordpress;
		global $wp_version;

		$source = NULL;
		if ($feedwordpress->subscribed($url)) :
			$source = $feedwordpress->subscription($url);
		endif;
		
		$this->url = $url;
		$this->timeout = $timeout;
		$this->redirects = $redirects;
		$this->headers = $headers;
		$this->useragent = $useragent;

		$this->method = SIMPLEPIE_FILE_SOURCE_REMOTE;
		
		global $wpdb;
		global $fwp_credentials;
		
		if ( preg_match('/^http(s)?:\/\//i', $url) ) {
			$args = array( 'timeout' => $this->timeout, 'redirection' => $this->redirects);
	
			if ( !empty($this->headers) )
				$args['headers'] = $this->headers;

			// Use default FWP user agent unless custom has been specified
			if ( SIMPLEPIE_USERAGENT != $this->useragent ) :
				$args['user-agent'] = $this->useragent;
			else :
				$args['user-agent'] = apply_filters('feedwordpress_user_agent',
					'FeedWordPress/'.FEEDWORDPRESS_VERSION
					.' (aggregator:feedwordpress; WordPress/'.$wp_version
					.' + '.SIMPLEPIE_NAME.'/'.SIMPLEPIE_VERSION
					.'; Allow like Gecko; +http://feedwordpress.radgeek.com/) at '
					. feedwordpress_display_url(get_bloginfo('url')),
					$this
				);
			endif;

			// This is ugly as hell, but communicating up and down the chain
			// in any other way is difficult.

			if (!is_null($fwp_credentials)) :

				$args['authentication'] = $fwp_credentials['authentication'];
				$args['username'] = $fwp_credentials['username'];
				$args['password'] = $fwp_credentials['password'];

			elseif ($source InstanceOf SyndicatedLink) :

				$args['authentication'] = $source->authentication_method();
				$args['username'] = $source->username();
				$args['password'] = $source->password();
			
			endif;

			FeedWordPress::diagnostic('updated_feeds:http', "HTTP [$url] &#8668; ".esc_html(FeedWordPress::val($args)));
			$res = wp_remote_request($url, $args);
			FeedWordPress::diagnostic('updated_feeds:http', "HTTP [$url] &#8669; ".esc_html(FeedWordPress::val($res)));

			if ( is_wp_error($res) ) {
				$this->error = 'WP HTTP Error: ' . $res->get_error_message();
				$this->success = false;
			} else {
				$this->headers = wp_remote_retrieve_headers( $res );
				$this->body = wp_remote_retrieve_body( $res );
				$this->status_code = wp_remote_retrieve_response_code( $res );
			}
			
			if ($source InstanceOf SyndicatedLink) :
				$source->update_setting('link/filesize', strlen($this->body));
				$source->update_setting('link/http status', $this->status_code);
				$source->save_settings(/*reload=*/ true);
			endif;
			
		} else {
			if ( ! $this->body = file_get_contents($url) ) {
				$this->error = 'file_get_contents could not read the file';
				$this->success = false;
			}
		}

		// SimplePie makes a strongly typed check against integers with
		// this, but WordPress puts a string in. Which causes caching
		// to break and fall on its ass when SimplePie is getting a 304,
		// but doesn't realize it because this member is "304" instead.
		$this->status_code = (int) $this->status_code;
	}
    function bleg_box($page, $box = NULL)
    {
        ?>
<script type="text/javascript">
/* <![CDATA[ */
    (function() {
        var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];
        s.type = 'text/javascript';
        s.async = true;
        s.src = 'https://api.flattr.com/js/0.6/load.js?mode=auto';
        t.parentNode.insertBefore(s, t);
    })();
/* ]]> */</script>

<div class="donation-form">
<h4>Consider a Donation to FeedWordPress</h4>
<form action="https://www.paypal.com/cgi-bin/webscr" accept-charset="UTF-8" method="post"><div>
<p><a href="http://feedwordpress.radgeek.com/">FeedWordPress</a> makes syndication
simple and empowers you to stream content from all over the web into your
WordPress hub. If you&#8217;re finding FWP useful,
<a href="http://feedwordpress.radgeek.com/donate/">a modest gift</a>
is the best way to support steady progress on development, enhancements,
support, and documentation.</p>

<div class="donate" style="vertical-align: middle">

<div id="flattr-paypal">

<div style="display: inline-block; vertical-align: middle; ">
<a class="FlattrButton" style="display:none;"   href="http://feedwordpress.radgeek.com/"></a>
<noscript>
<a href="https://flattr.com/thing/1380856/FeedWordPress" target="_blank"><img src="https://api.flattr.com/button/flattr-badge-large.png" alt="Flattr this" title="Flattr this" border="0" /></a>
</noscript>
<div>via Flattr</div>

</div> <!-- style="display: inline-block" -->

<div class="hovered-component" style="display: inline-block; vertical-align: bottom">
<a href="bitcoin:<?php 
        print esc_attr(FEEDWORDPRESS_BLEG_BTC);
        ?>
"><img src="<?php 
        print esc_url(plugins_url('/' . FeedWordPress::path('btc-qr-64px.png')));
        ?>
" alt="Donate" /></a>
<div><a href="bitcoin:<?php 
        print esc_attr(FEEDWORDPRESS_BLEG_BTC);
        ?>
">via bitcoin<span class="hover-on pop-over" style="background-color: #ddffdd; padding: 5px; color: black; border-radius: 5px;">bitcoin:<?php 
        print esc_html(FEEDWORDPRESS_BLEG_BTC);
        ?>
</span></a></div>
</div>

<div style="display: inline-block; vertical-align: bottom">
<input type="image" name="submit" src="<?php 
        print esc_url(plugins_url('/' . FeedWordPress::path('paypal-donation-64px.png')));
        ?>
" alt="Donate through PayPal" />
<input type="hidden" name="business" value="*****@*****.**"  />
<input type="hidden" name="cmd" value="_xclick"  />
<input type="hidden" name="item_name" value="FeedWordPress donation"  />
<input type="hidden" name="no_shipping" value="1"  />
<input type="hidden" name="return" value="<?php 
        print esc_attr($this->admin_page_href(basename($this->filename), array('paid' => 'yes')));
        ?>
"  />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="notify_url" value="http://feedwordpress.radgeek.com/ipn/donation"  />
<input type="hidden" name="custom" value="1"  />
<div>via PayPal</div>
</div> <!-- style="display: inline-block" -->

</div> <!-- id="flattr-paypal" -->
</div> <!-- class="donate" -->

</div> <!-- class="donation-form" -->
</form>

<p>You can make a gift online (or
<a href="http://feedwordpress.radgeek.com/donation">set up an automatic
regular donation</a>) using an existing PayPal account or any major credit card.</p>

<div class="sod-off">
<form style="text-align: center" action="<?php 
        print $this->form_action();
        ?>
" method="POST"><div>
<input class="button" type="submit" name="maybe_later" value="Maybe Later" />
<input class="button" type="submit" name="go_away" value="Dismiss" />
</div></form>
</div>
</div> <!-- class="donation-form" -->
		<?php 
    }
    function comments_and_pings_box($page, $box = NULL)
    {
        $setting = array();
        $selector = array();
        $whatsits = array('comment' => array('label' => __('Comments'), 'accept' => 'Allow comments'), 'ping' => array('label' => __('Pings'), 'accept' => 'Accept pings'));
        $onThesePosts = 'on ' . $page->these_posts_phrase();
        $selected = array('munge_comments_feed_links' => array('yes' => '', 'no' => ''));
        $globalMungeCommentsFeedLinks = get_option('feedwordpress_munge_comments_feed_links', 'yes');
        if ($page->for_feed_settings()) {
            $selected['munge_comments_feed_links']['default'] = '';
            $sel = $page->link->setting('munge comments feed links', NULL, 'default');
        } else {
            $sel = $globalMungeCommentsFeedLinks;
        }
        $selected['munge_comments_feed_links'][$sel] = ' checked="checked"';
        if ($globalMungeCommentsFeedLinks != 'no') {
            $siteWide = __('comment feeds from the original website');
        } else {
            $siteWide = __('local comment feeds on this website');
        }
        foreach ($whatsits as $what => $how) {
            $whatsits[$what]['default'] = FeedWordPress::syndicated_status($what, 'closed');
            // Set up array for selector
            $setting = array('open' => array('label' => "{$how['accept']} %s", 'checked' => ''), 'closed' => array('label' => "Don't " . strtolower($how['accept']) . " %s", 'checked' => ''));
            if ($page->for_feed_settings()) {
                $href = FWP_POSTS_PAGE_SLUG;
                $currently = trim(str_replace('%s', '', strtolower(strtok($setting[$whatsits[$what]['default']]['label'], ';'))));
                $setting['site-default'] = array('label' => "Use <a href=\"admin.php?page={$href}\">site-wide setting</a>", 'checked' => '');
                $setting['site-default']['label'] .= " (currently: <strong>{$currently}</strong>)";
                $checked = $page->link->syndicated_status($what, 'site-default', false);
            } else {
                $checked = $whatsits[$what]['default'];
            }
            // Re-order appropriately
            $selector[$what] = array();
            $order = array('site-default', 'open', 'closed');
            foreach ($order as $line) {
                if (isset($setting[$line])) {
                    $selector[$what][$line] = $setting[$line];
                }
            }
            $selector[$what][$checked]['checked'] = ' checked="checked"';
        }
        // Hey ho, let's go...
        ?>
		<table class="form-table" cellspacing="2" cellpadding="5">
		<?php 
        foreach ($whatsits as $what => $how) {
            ?>
		  <tr><th scope="row"><?php 
            print $how['label'];
            ?>
:</th>
		  <td><ul class="options">
		  <?php 
            foreach ($selector[$what] as $code => $li) {
                ?>
		    <li><label><input type="radio" name="feed_<?php 
                print $what;
                ?>
_status"
		    value="<?php 
                print $code;
                ?>
"<?php 
                print $li['checked'];
                ?>
 />
		    <?php 
                print trim(str_replace('%s', $onThesePosts, $li['label']));
                ?>
</label></li>
		  <?php 
            }
            ?>
		  </ul></td></tr>
		<?php 
        }
        ?>
		  <tr><th scope="row"><?php 
        _e('Comment feeds');
        ?>
</th>
		  <td><p>When WordPress feeds and templates link to comments
		  feeds for <?php 
        print $page->these_posts_phrase();
        ?>
, the
		  URLs for the feeds should...</p>
		  <ul class="options">
		  <?php 
        if ($page->for_feed_settings()) {
            ?>
		  <li><label><input type="radio" name="munge_comments_feed_links" value="default"<?php 
            print $selected['munge_comments_feed_links']['default'];
            ?>
 /> Use <a href="admin.php?page=<?php 
            print $href;
            ?>
">site-wide setting</a> (currently: <strong><?php 
            _e($siteWide);
            ?>
</strong>)</label></li>
		  <?php 
        }
        ?>
		  <li><label><input type="radio" name="munge_comments_feed_links" value="yes"<?php 
        print $selected['munge_comments_feed_links']['yes'];
        ?>
 /> <?php 
        _e('Point to comment feeds from the original website (when provided by the syndicated feed)');
        ?>
</label></li>
		  <li><label><input type="radio" name="munge_comments_feed_links" value="no"<?php 
        print $selected['munge_comments_feed_links']['no'];
        ?>
 /> <?php 
        _e('Point to local comment feeds on this website');
        ?>
</label></li>
		  </ul></td></tr>
		</table>

		<?php 
    }
Exemple #15
0
function fwp_upgrade_page()
{
    if (MyPHP::post('action') == 'Upgrade') {
        $ver = get_option('feedwordpress_version');
        if (get_option('feedwordpress_version') != FEEDWORDPRESS_VERSION) {
            echo "<div class=\"wrap\">\n";
            echo "<h2>Upgrading FeedWordPress...</h2>";
            $feedwordpress = new FeedWordPress();
            $feedwordpress->upgrade_database($ver);
            echo "<p><strong>Done!</strong> Upgraded database to version " . FEEDWORDPRESS_VERSION . ".</p>\n";
            echo "<form action=\"\" method=\"get\">\n";
            echo "<div class=\"submit\"><input type=\"hidden\" name=\"page\" value=\"syndication.php\" />";
            echo "<input type=\"submit\" value=\"Continue &raquo;\" /></form></div>\n";
            echo "</div>\n";
            return;
        } else {
            echo "<div class=\"updated\"><p>Already at version " . FEEDWORDPRESS_VERSION . "!</p></div>";
        }
    }
    ?>
<div class="wrap">
<h2>Upgrade FeedWordPress</h2>

<p>It appears that you have installed FeedWordPress
<?php 
    echo FEEDWORDPRESS_VERSION;
    ?>
 as an upgrade to an existing installation of
FeedWordPress. That's no problem, but you will need to take a minute out first
to upgrade your database: some necessary changes in how the software keeps
track of posts and feeds will cause problems such as duplicate posts and broken
templates if we were to continue without the upgrade.</p>

<p>Note that most of FeedWordPress's functionality is temporarily disabled
until we have successfully completed the upgrade. Everything should begin
working as normal again once the upgrade is complete. There's extraordinarily
little chance of any damage as the result of the upgrade, but if you're paranoid
like me you may want to back up your database before you proceed.</p>

<p>This may take several minutes for a large installation.</p>

<form action="" method="post">
<?php 
    FeedWordPressCompatibility::stamp_nonce('feedwordpress_upgrade');
    ?>
<div class="submit"><input type="submit" name="action" value="Upgrade" /></div>
</form>
</div>
<?php 
}
Exemple #16
0
    function display()
    {
        global $fwp_post;
        if (FeedWordPress::needs_upgrade()) {
            fwp_upgrade_page();
            return;
        }
        FeedWordPressCompatibility::validate_http_request($this->dispatch, 'manage_links');
        ////////////////////////////////////////////////
        // Process POST request, if any ////////////////
        ////////////////////////////////////////////////
        if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
            $this->accept_POST($fwp_post);
        } else {
            $this->updated = false;
        }
        ////////////////////////////////////////////////
        // Prepare settings page ///////////////////////
        ////////////////////////////////////////////////
        $this->display_update_notice_if_updated($this->pagename('settings-update'), $this->update_message());
        $this->open_sheet($this->pagename('open-sheet'));
        ?>
		<div id="post-body">
		<?php 
        foreach ($this->boxes_by_methods as $method => $row) {
            if (is_array($row)) {
                $id = $row['id'];
                $title = $row['title'];
            } else {
                $id = 'feedwordpress_' . $method;
                $title = $row;
            }
            add_meta_box($id, $title, array($this, $method), $this->meta_box_context(), $this->meta_box_context());
        }
        do_action($this->dispatch . '_meta_boxes', $this);
        ?>
		<div class="metabox-holder">
		<?php 
        fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
        ?>
		</div> <!-- class="metabox-holder" -->
		</div> <!-- id="post-body" -->
		<?php 
        $this->close_sheet();
        ?>
	<?php 
    }
    static function info_box($page, $box = NULL)
    {
        global $feedwordpress;
        global $wp_version;
        $link_category_id = FeedWordPress::link_category_id();
        ?>
		<table class="edit-form narrow">
		<thead style="display: none">
		<th scope="col">Topic</th>
		<th scope="col">Information</th>
		</thead>

		<tbody>
		<tr>
		<th scope="row">Version:</th>
		<td>You are using FeedWordPress version <strong><?php 
        print FEEDWORDPRESS_VERSION;
        ?>
</strong>.</td>
		</tr>

		<tr>
		<th scope="row">Hosting Environment:</th>
		<td><ul style="margin-top: 0; padding-top: 0;">
		<li><em>WordPress:</em> version <?php 
        print $wp_version;
        ?>
</li>
		<?php 
        if (function_exists('phpversion')) {
            ?>
		<li><em>PHP:</em> version <?php 
            print phpversion();
            ?>
</li>
		<?php 
        }
        ?>
		<?php 
        if (function_exists('apache_get_version')) {
            ?>
		<li><sem>Web Server:</em> <?php 
            print apache_get_version();
            ?>
</li>
		<?php 
        }
        ?>
		</ul>
		</td>
		</tr>

		<tr>
		<th scope="row">Link Category:</th>
		<td><?php 
        if (!is_wp_error($link_category_id)) {
            $term = get_term($link_category_id, 'link_category');
            ?>
<p>Syndicated feeds are
		kept in link category #<?php 
            print $term->term_id;
            ?>
, <strong><?php 
            print $term->name;
            ?>
</strong>.</p>
		<?php 
        } else {
            ?>
		<p><strong>FeedWordPress has been unable to set up a valid Link Category
		for syndicated feeds.</strong> Attempting to set one up returned an
		<code><?php 
            $link_category_id->get_error_code();
            ?>
</code> error with this
		additional data:</p>
		<table>
		<tbody>
		<tr>
		<th scope="row">Message:</th>
		<td><?php 
            print $link_category_id->get_error_message();
            ?>
</td>
		</tr>
		<?php 
            $data = $link_category_id->get_error_data();
            if (!empty($data)) {
                ?>
		<tr>
		<th scope="row">Auxiliary Data:</th>
		<td><pre><?php 
                print esc_html(MyPHP::val($link_category_id->get_error_data()));
                ?>
</pre></td>
		</tr>
		<?php 
            }
            ?>
		</table>
		<?php 
        }
        ?>
</td>
		</tr>

		<tr>
		<th scope="row"><?php 
        _e('Secret Key:');
        ?>
</th>
		<td><input type="text" name="feedwordpress_secret_key" value="<?php 
        print esc_attr($feedwordpress->secret_key());
        ?>
" />
		<p class="setting-description">This is used to control access to some diagnostic testing functions. You can change it to any string you want,
		but only tell it to people you trust to help you troubleshoot your
		FeedWordPress installation. Keep it secret&#8212;keep it safe.</p></td>
		</tr>
		</table>

		<?php 
    }
Exemple #18
0
 function diagnostic($level, $out, $persist = NULL, $since = NULL, $mostRecent = NULL)
 {
     global $feedwordpress_admin_footer;
     $output = get_option('feedwordpress_diagnostics_output', array());
     $dlog = get_option('feedwordpress_diagnostics_log', array());
     $diagnostic_nesting = count(explode(":", $level));
     if (FeedWordPress::diagnostic_on($level)) {
         foreach ($output as $method) {
             switch ($method) {
                 case 'echo':
                     if (!FeedWordPress::update_requested()) {
                         echo "<div><pre><strong>Diag" . str_repeat('====', $diagnostic_nesting - 1) . '|</strong> ' . $out . "</pre></div>";
                     }
                     break;
                 case 'echo_in_cronjob':
                     if (FeedWordPress::update_requested()) {
                         echo FeedWordPress::log_prefix() . " " . $out . "\n";
                     }
                     break;
                 case 'admin_footer':
                     $feedwordpress_admin_footer[] = $out;
                     break;
                 case 'error_log':
                     error_log(FeedWordPress::log_prefix() . ' ' . $out);
                     break;
                 case 'email':
                     if (is_null($persist)) {
                         $sect = 'occurrent';
                         $hook = isset($dlog['mesg'][$sect]) ? count($dlog['mesg'][$sect]) : 0;
                         $line = array("Time" => time(), "Message" => $out);
                     } else {
                         $sect = 'persistent';
                         $hook = md5($level . "\n" . $persist);
                         $line = array("Since" => $since, "Message" => $out, "Most Recent" => $mostRecent);
                     }
                     if (!isset($dlog['mesg'])) {
                         $dlog['mesg'] = array();
                     }
                     if (!isset($dlog['mesg'][$sect])) {
                         $dlog['mesg'][$sect] = array();
                     }
                     $dlog['mesg'][$sect][$hook] = $line;
             }
         }
     }
     update_option('feedwordpress_diagnostics_log', $dlog);
 }
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 
}
 public function insert($tax = NULL)
 {
     $ret = NULL;
     if (is_null($tax)) {
         if (count($this->tax) > 0) {
             $tax = $this->tax[0];
         }
     }
     if (!$this->is_forbidden_in($tax)) {
         $aTerm = wp_insert_term($this->term, $tax);
         if (is_wp_error($aTerm)) {
             // If debug mode is ON, this will halt us here.
             FeedWordPress::noncritical_bug('term insertion problem', array('term' => $this->term, 'result' => $aTerm, 'post' => $post, 'this' => $this), __LINE__, __FILE__);
             // Otherwise, we'll continue & return NULL...
         } else {
             $this->exists = $aTerm;
             $this->exists_in = $tax;
             $ret = $this->id();
         }
         FeedWordPress::diagnostic('syndicated_posts:categories', 'CREATED unfamiliar ' . $tax . ': ' . json_encode($this->term) . ' with result: ' . json_encode($aTerm));
     } else {
         FeedWordPress::diagnostic('syndicated_posts:categories', 'Category: DID NOT CREATE unfamiliar ' . $tax . ': ' . json_encode($this->term) . ':' . ' that ' . $tax . ' name is filtered out.');
     }
     return $ret;
 }
Exemple #21
0
 public function attach_image($url, $to, $args = array())
 {
     $attach_id = NULL;
     $p = wp_parse_args($args, array("crop" => NULL, "resize" => NULL));
     # Fetch the URI
     $headers['Connection'] = 'close';
     $headers['Referer'] = get_permalink($to);
     if (is_callable(array('FeedWordPress', 'fetch_timeout'))) {
         $timeout = FeedWordPress::fetch_timeout();
     } elseif (defined('FEEDWORDPRESS_FETCH_TIME_OUT')) {
         $timeout = FEEDWORDPRESS_FETCH_TIME_OUT;
     } elseif (defined('FEEDWORDPRESS_FETCH_TIMEOUT_DEFAULT')) {
         $timeout = FEEDWORDPRESS_FETCH_TIMEOUT_DEFAULT;
     } else {
         $timeout = 60;
     }
     FeedWordPress::diagnostic('sicem:capture:http', "HTTP &raquo;&raquo; GET [{$url}]");
     $params = apply_filters('sicem_remote_request_params', array('headers' => $headers, 'timeout' => $timeout), $url);
     $http = apply_filters('sicem_remote_request', NULL, $url, $params);
     if (is_null($http)) {
         $http = wp_remote_request($url, $params);
     }
     $imgBits = new SicWebImage($url, $params, $http);
     if ($imgBits->is_ok() and $imgBits->is_image()) {
         // Check whether our size filters or MIME constraints filter it out
         $imagesize = $imgBits->size();
         if (!is_null($imagesize)) {
             $minWidth = isset($args['min width']) ? $args['min width'] : 0;
             $minHeight = isset($args['min height']) ? $args['min height'] : 0;
             if ($imagesize[0] < $minWidth or $imagesize[1] < $minHeight or !$this->allowedtype($imagesize['mime'], $args)) {
                 FeedWordPress::diagnostic('sicem:capture:reject', "Image [{$url}] rejected. " . ($imagesize[0] < $minWidth ? 'width: ' . $imagesize[0] . ' &lt; ' . $minWidth . '. ' : '') . ($imagesize[1] < $minHeight ? 'height: ' . $imagesize[1] . ' &lt; ' . $minHeight . '. ' : '') . (!$this->allowedtype($imagesize['mime'], $args) ? 'type [' . $imagesize['mime'] . ']: whitelist [' . implode('|', $args['whitelist']) . '] blacklist [' . implode('|', $args['blacklist']) . '].' : ''));
                 $imgBits->set_image(NULL, NULL);
             }
         }
         // Apply (if applicable) crop and resize settings
         $imgBits->constrain($p['crop'], $p['resize']);
         if ($imgBits->is_image()) {
             $attach_id = $imgBits->upload($to);
         } else {
             $attach_id = -1;
             // Filtered
         }
     } else {
         // Got a WP_Error object back instead of a HTTP GET reply
         if (is_wp_error($http)) {
             $error_message = preg_replace('/\\s+/', " ", "WP_Error: " . implode(" / ", $http->get_error_messages()));
             // Got a HTTP GET reply other than 200 OK.
         } elseif (is_array($http) and isset($http['response'])) {
             $code = $http['response']['code'];
             $mesg = $http['response']['message'];
             $pcode = preg_replace('/\\s+/', '\\s+', preg_quote($code));
             $pmesg = preg_replace('/\\s+/', '\\s+', preg_quote($mesg));
             $pattern = ":<([^>]+)> \\s* ({$pcode}\\s*)? {$pmesg} \\s*</\\1>:ix";
             $stripped_body = strip_tags(preg_replace($pattern, '', $http['body']));
             $len = 66;
             $error_message = preg_replace('/\\s+/', " ", "{$code} {$mesg}: " . substr($stripped_body, 0, $len) . (strlen($stripped_body) > $len ? "&hellip;" : ''));
             // Well, who knows what the hell is going on, really?
         } else {
             $error_message = preg_replace('/\\s+/', " ", FeedWordPress::val($http));
         }
         // Send it to the diagnostix module.
         FeedWordPress::diagnostic('sicem:capture:error', "Failed GET [{$url}] &laquo;&laquo; " . $error_message);
     }
     return $attach_id;
 }
 function author_id($unfamiliar_author = 'create')
 {
     $a = $this->author();
     $author = $a['name'];
     $email = isset($a['email']) ? $a['email'] : NULL;
     $authorUrl = isset($a['uri']) ? $a['uri'] : NULL;
     $match_author_by_email = !('yes' == get_option("feedwordpress_do_not_match_author_by_email"));
     if ($match_author_by_email and !FeedWordPress::is_null_email($email)) {
         $test_email = $email;
     } else {
         $test_email = NULL;
     }
     // Never can be too careful...
     $login = sanitize_user($author, true);
     $login = apply_filters('pre_user_login', $login);
     $nice_author = sanitize_title($author);
     $nice_author = apply_filters('pre_user_nicename', $nice_author);
     // Do our escape just how $wpdb does it for a string
     $author = addslashes($author);
     // Check for an existing author rule....
     if (isset($this->link->settings['map authors']['name'][strtolower(trim($author))])) {
         $author_rule = $this->link->settings['map authors']['name'][strtolower(trim($author))];
     } else {
         $author_rule = NULL;
     }
     // User name is mapped to a particular author. If that author ID exists, use it.
     if (is_numeric($author_rule) and get_userdata((int) $author_rule)) {
         $id = (int) $author_rule;
         // User name is filtered out
     } elseif ('filter' == $author_rule) {
         $id = NULL;
     } else {
         // Check the database for an existing author record that might fit
         $id = NULL;
         // First try the user core data table.
         if ($user = get_user_by('login', trim(strtolower($login)))) {
             $id = $user->ID;
         } else {
             if ($user = get_user_by('email', trim(strtolower($test_email)))) {
                 $id = $user->ID;
             } else {
                 if ($user = get_user_by('slug', trim(strtolower($nice_author)))) {
                     $id = $user->ID;
                 }
             }
         }
         /* CF: No WP functionality to accomplish this, we're not going 
         			to try the description field right now */
         // If that fails, look for aliases in the user meta data table
         // if (empty($id)) :
         // 	$reg_author = $wpdb->escape(preg_quote($author));
         // 	$id = $wpdb->get_var(
         // 	"SELECT user_id FROM $wpdb->usermeta
         // 	WHERE
         // 		(meta_key = 'description' AND TRIM(LCASE(meta_value)) = TRIM(LCASE('$author')))
         // 		OR (
         // 			meta_key = 'description'
         // 			AND TRIM(LCASE(meta_value))
         // 			RLIKE CONCAT(
         // 				'(^|\\n)a\\.?k\\.?a\\.?( |\\t)*:?( |\\t)*',
         // 				TRIM(LCASE('$reg_author')),
         // 				'( |\\t|\\r)*(\\n|\$)'
         // 			)
         // 		)
         // 	");
         // endif;
         // ... if you don't find one, then do what you need to do
         if (is_null($id)) {
             if (is_numeric($unfamiliar_author) and get_userdata((int) $unfamiliar_author)) {
                 $id = (int) $unfamiliar_author;
                 // Do the default, assign to admin
             } else {
                 $id = 1;
             }
         }
     }
     if ($id) {
         $this->link->settings['map authors']['name'][strtolower(trim($author))] = $id;
     }
     return $id;
 }
	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 comments_and_pings_box($page, $box = NULL)
    {
        $whatsits = array('comment' => array('label' => __('Comments'), 'accept' => 'Allow comments'), 'ping' => array('label' => __('Pings'), 'accept' => 'Accept pings'));
        $onThesePosts = 'on ' . $page->these_posts_phrase();
        $mcflSettings = array("yes" => __('Point to comment feeds from the original website (when provided by the syndicated feed)'), "no" => __('Point to local comment feeds on this website'));
        $mcflParams = array('setting-default' => 'default', 'global-setting-default' => 'yes', 'labels' => array('yes' => __('comment feeds from the original website'), 'no' => __('local comment feeds on this website')), 'default-input-value' => 'default');
        $settings = array();
        $params = array();
        foreach ($whatsits as $what => $how) {
            $whatsits[$what]['default'] = FeedWordPress::syndicated_status($what, 'closed');
            // Set up array for selector
            $settings[$what] = array('open' => sprintf(__("{$how['accept']} %s"), __($onThesePosts)), 'closed' => sprintf(__("Don't " . strtolower($how['accept']) . " %s"), __($onThesePosts)));
            $params[$what] = array('input-name' => "feed_{$what}_status", 'setting-default' => NULL, 'global-setting-default' => FeedWordPress::syndicated_status($what, 'closed'), 'labels' => array('open' => strtolower(__($how['accept'])), 'closed' => strtolower(__("Don't " . $how['accept']))));
        }
        // Hey ho, let's go...
        ?>
		<table class="edit-form narrow">
		<?php 
        foreach ($whatsits as $what => $how) {
            ?>
		  
		  <tr><th scope="row"><?php 
            print $how['label'];
            ?>
:</th>
		  <td><?php 
            $this->setting_radio_control("{$what} status", "syndicated_{$what}_status", $settings[$what], $params[$what]);
            ?>
</td></tr>
		  
		<?php 
        }
        ?>
		
		  <tr><th scope="row"><?php 
        _e('Comment feeds');
        ?>
</th>
		  <td><p>When WordPress feeds and templates link to comments
		  feeds for <?php 
        print $page->these_posts_phrase();
        ?>
, the
		  URLs for the feeds should...</p>
		  <?php 
        $this->setting_radio_control("munge comments feed links", "munge_comments_feed_links", $mcflSettings, $mcflParams);
        ?>
</td></tr>
		</table>

		<?php 
    }
 function _get($uri = NULL)
 {
     if ($uri) {
         $this->uri = $uri;
     }
     // Is the result not yet cached?
     if ($this->uri != 'tag:localhost' and $this->_cache_uri !== $this->uri) {
         $headers['Connection'] = 'close';
         $headers['Accept'] = 'application/atom+xml application/rdf+xml application/rss+xml application/xml text/html */*';
         $headers['User-Agent'] = 'feedfinder/1.2 (compatible; PHP FeedFinder) +http://projects.radgeek.com/feedwordpress';
         // Use WordPress API function
         $client = wp_remote_request($this->uri, array_merge($this->credentials, array('headers' => $headers, 'timeout' => FeedWordPress::fetch_timeout())));
         $this->_response = $client;
         if (is_wp_error($client)) {
             $this->_data = NULL;
             $this->_error = $client->get_error_messages();
         } else {
             $this->_data = $client['body'];
             $this->_error = NULL;
         }
         // Kilroy was here
         $this->_cache_uri = $this->uri;
     }
 }
 /**
  * category_ids: look up (and create) category ids from a list of categories
  *
  * @param array $cats
  * @param string $unfamiliar_category
  * @param array|null $taxonomies
  * @return array
  */
 function category_ids($cats, $unfamiliar_category = 'create', $taxonomies = NULL, $params = array())
 {
     $singleton = isset($params['singleton']) ? $params['singleton'] : true;
     $allowFilters = isset($params['filters']) ? $params['filters'] : false;
     $catTax = 'category';
     if (is_null($taxonomies)) {
         $taxonomies = array('category');
     }
     // We need to normalize whitespace because (1) trailing
     // whitespace can cause PHP and MySQL not to see eye to eye on
     // VARCHAR comparisons for some versions of MySQL (cf.
     // <http://dev.mysql.com/doc/mysql/en/char.html>), and (2)
     // because I doubt most people want to make a semantic
     // distinction between 'Computers' and 'Computers  '
     $cats = array_map('trim', $cats);
     $terms = array();
     foreach ($taxonomies as $tax) {
         $terms[$tax] = array();
     }
     foreach ($cats as $cat_name) {
         if (preg_match('/^{([^#}]*)#([0-9]+)}$/', $cat_name, $backref)) {
             $cat_id = (int) $backref[2];
             $tax = $backref[1];
             if (strlen($tax) < 1) {
                 $tax = $catTax;
             }
             $term = term_exists($cat_id, $tax);
             if (!is_wp_error($term) and !!$term) {
                 if (!isset($terms[$tax])) {
                     $terms[$tax] = array();
                 }
                 $terms[$tax][] = $cat_id;
             }
         } elseif (strlen($cat_name) > 0) {
             $familiar = false;
             foreach ($taxonomies as $tax) {
                 if ($tax != 'category' or strtolower($cat_name) != 'uncategorized') {
                     $term = term_exists($cat_name, $tax);
                     if (!is_wp_error($term) and !!$term) {
                         $familiar = true;
                         if (is_array($term)) {
                             $term_id = (int) $term['term_id'];
                         } else {
                             $term_id = (int) $term;
                         }
                         if (!isset($terms[$tax])) {
                             $terms[$tax] = array();
                         }
                         $terms[$tax][] = $term_id;
                         break;
                         // We're done here.
                     }
                 }
             }
             if (!$familiar) {
                 if ('tag' == $unfamiliar_category) {
                     $unfamiliar_category = 'create:post_tag';
                 }
                 if (preg_match('/^create(:(.*))?$/i', $unfamiliar_category, $ref)) {
                     $tax = $catTax;
                     // Default
                     if (isset($ref[2]) and strlen($ref[2]) > 2) {
                         $tax = $ref[2];
                     }
                     $term = wp_insert_term($cat_name, $tax);
                     if (is_wp_error($term)) {
                         FeedWordPress::noncritical_bug('term insertion problem', array('cat_name' => $cat_name, 'term' => $term, 'this' => $this), __LINE__, __FILE__);
                     } else {
                         if (!isset($terms[$tax])) {
                             $terms[$tax] = array();
                         }
                         $terms[$tax][] = (int) $term['term_id'];
                     }
                 }
             }
         }
     }
     $filtersOn = $allowFilters;
     if ($allowFilters) {
         $filters = array_filter($this->link->setting('match/filter', 'match_filter', array()), 'remove_dummy_zero');
         $filtersOn = ($filtersOn and is_array($filters) and count($filters) > 0);
     }
     // Check for filter conditions
     foreach ($terms as $tax => $term_ids) {
         if ($filtersOn and count($term_ids) == 0 and in_array($tax, $filters)) {
             $terms = NULL;
             // Drop the post
             break;
         } else {
             $terms[$tax] = array_unique($term_ids);
         }
     }
     if ($singleton and count($terms) == 1) {
         // If we only searched one, just return the term IDs
         $terms = end($terms);
     }
     return $terms;
 }
 public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
 {
     global $feedwordpress;
     global $wp_version;
     $source = NULL;
     if ($feedwordpress->subscribed($url)) {
         $source = $feedwordpress->subscription($url);
     }
     $this->url = $url;
     $this->timeout = $timeout;
     $this->redirects = $redirects;
     $this->headers = $headers;
     $this->useragent = $useragent;
     $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE;
     global $wpdb;
     global $fwp_credentials;
     if (preg_match('/^http(s)?:\\/\\//i', $url)) {
         $args = array('timeout' => $this->timeout, 'redirection' => $this->redirects);
         if (!empty($this->headers)) {
             $args['headers'] = $this->headers;
         }
         // Use default FWP user agent unless custom has been specified
         if (SIMPLEPIE_USERAGENT != $this->useragent) {
             $args['user-agent'] = $this->useragent;
         } else {
             $args['user-agent'] = apply_filters('feedwordpress_user_agent', 'FeedWordPress/' . FEEDWORDPRESS_VERSION . ' (aggregator:feedwordpress; WordPress/' . $wp_version . ' + ' . SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . '; Allow like Gecko; +http://feedwordpress.radgeek.com/) at ' . feedwordpress_display_url(get_bloginfo('url')), $this);
         }
         // This is ugly as hell, but communicating up and down the chain
         // in any other way is difficult.
         if (!is_null($fwp_credentials)) {
             $args['authentication'] = $fwp_credentials['authentication'];
             $args['username'] = $fwp_credentials['username'];
             $args['password'] = $fwp_credentials['password'];
         } elseif ($source instanceof SyndicatedLink) {
             $args['authentication'] = $source->authentication_method();
             $args['username'] = $source->username();
             $args['password'] = $source->password();
         }
         FeedWordPress::diagnostic('updated_feeds:http', "HTTP [{$url}] &#8668; " . esc_html(MyPHP::val($args)));
         $res = wp_remote_request($url, $args);
         FeedWordPress::diagnostic('updated_feeds:http', "HTTP [{$url}] &#8669; " . esc_html(MyPHP::val($res)));
         if (is_wp_error($res)) {
             $this->error = 'WP HTTP Error: ' . $res->get_error_message();
             $this->success = false;
         } else {
             $this->headers = wp_remote_retrieve_headers($res);
             $this->body = wp_remote_retrieve_body($res);
             $this->status_code = wp_remote_retrieve_response_code($res);
         }
         if ($source instanceof SyndicatedLink) {
             $source->update_setting('link/filesize', strlen($this->body));
             $source->update_setting('link/http status', $this->status_code);
             $source->save_settings(true);
         }
         // Do not allow schemes other than http(s)? for the time being.
         // They are unlikely to be used; and unrestricted use of schemes
         // allows for user to use an unrestricted file:/// scheme, which
         // may result in exploits by WordPress users against the web
         // hosting environment.
     } else {
         $this->error = 'FeedWordPress only allows http or https URLs';
         $this->success = false;
     }
     // SimplePie makes a strongly typed check against integers with
     // this, but WordPress puts a string in. Which causes caching
     // to break and fall on its ass when SimplePie is getting a 304,
     // but doesn't realize it because this member is "304" instead.
     $this->status_code = (int) $this->status_code;
 }
    static function performance_box($page, $box = NULL)
    {
        // Hey ho, let's go...
        ?>
<table class="editform" width="100%" cellspacing="2" cellpadding="5">
<tr style="vertical-align: top">
<th width="33%" scope="row">Feed cache:</th>
<td width="67%"><input class="button" type="submit" name="clear_cache" value="Clear all cached feeds from WordPress database" />
<p>This will clear all cached copies of feed data from the WordPress database
and force FeedWordPress to make a fresh scan for updates on syndicated feeds.</p></td></tr>

<tr style="vertical-align: top">
<th width="33%" scope="row">Guid index:</th>
<td width="67%"><?php 
        if (!FeedWordPress::has_guid_index()) {
            ?>
<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>
<?php 
        } else {
            ?>

<p>You have already created an index on the guid column in the WordPress posts
table. If you'd like to remove the index for any reason, you can do so here.</p>

<input class="button" type="submit" name="remove_index" value="Remove index on guid column in posts database table" />

<?php 
        }
        ?>

</tr>

</td>
</tr>
</table>
		<?php 
    }
 /**
  * SyndicatedPost::author_id (): get the ID for an author name from
  * the feed. Create the author if necessary.
  *
  * @param string $unfamiliar_author
  *
  * @return NULL|int The numeric ID of the author to attribute the post to
  *	NULL if the post should be filtered out.
  */
 function author_id($unfamiliar_author = 'create')
 {
     global $wpdb;
     $a = $this->named['author'];
     $source = $this->source();
     $forbidden = apply_filters('feedwordpress_forbidden_author_names', array('admin', 'administrator', 'www', 'root'));
     // Prepare the list of candidates to try for author name: name from
     // feed, original source title (if any), immediate source title live
     // from feed, subscription title, prettied version of feed homepage URL,
     // prettied version of feed URL, or, failing all, use "unknown author"
     // as last resort
     $candidates = array();
     $candidates[] = $a['name'];
     if (!is_null($source)) {
         $candidates[] = $source['title'];
     }
     $candidates[] = $this->link->name(true);
     $candidates[] = $this->link->name(false);
     if (strlen($this->link->homepage()) > 0) {
         $candidates[] = feedwordpress_display_url($this->link->homepage());
     }
     $candidates[] = feedwordpress_display_url($this->link->uri());
     $candidates[] = 'unknown author';
     // Pick the first one that works from the list, screening against empty
     // or forbidden names.
     $author = NULL;
     while (is_null($author) and $candidate = each($candidates)) {
         if (!is_null($candidate['value']) and strlen(trim($candidate['value'])) > 0 and !in_array(strtolower(trim($candidate['value'])), $forbidden)) {
             $author = $candidate['value'];
         }
     }
     $email = isset($a['email']) ? $a['email'] : NULL;
     $authorUrl = isset($a['uri']) ? $a['uri'] : NULL;
     $hostUrl = $this->link->homepage();
     if (is_null($hostUrl) or strlen($hostUrl) < 0) {
         $hostUrl = $this->link->uri();
     }
     $match_author_by_email = !('yes' == get_option("feedwordpress_do_not_match_author_by_email"));
     if ($match_author_by_email and !FeedWordPress::is_null_email($email)) {
         $test_email = $email;
     } else {
         $test_email = NULL;
     }
     // Never can be too careful...
     $login = sanitize_user($author, true);
     // Possible for, e.g., foreign script author names
     if (strlen($login) < 1) {
         // No usable characters in author name for a login.
         // (Sometimes results from, e.g., foreign scripts.)
         //
         // We just need *something* in Western alphanumerics,
         // so let's try the domain name.
         //
         // Uniqueness will be guaranteed below if necessary.
         $url = parse_url($hostUrl);
         $login = sanitize_user($url['host'], true);
         if (strlen($login) < 1) {
             // This isn't working. Frak it.
             $login = '******';
         }
     }
     $login = apply_filters('pre_user_login', $login);
     $nice_author = sanitize_title($author);
     $nice_author = apply_filters('pre_user_nicename', $nice_author);
     $reg_author = esc_sql(preg_quote($author));
     $author = esc_sql($author);
     $email = esc_sql($email);
     $test_email = esc_sql($test_email);
     $authorUrl = esc_sql($authorUrl);
     // Check for an existing author rule....
     if (isset($this->link->settings['map authors']['name']['*'])) {
         $author_rule = $this->link->settings['map authors']['name']['*'];
     } elseif (isset($this->link->settings['map authors']['name'][strtolower(trim($author))])) {
         $author_rule = $this->link->settings['map authors']['name'][strtolower(trim($author))];
     } else {
         $author_rule = NULL;
     }
     // User name is mapped to a particular author. If that author ID exists, use it.
     if (is_numeric($author_rule) and get_userdata((int) $author_rule)) {
         $id = (int) $author_rule;
         // User name is filtered out
     } elseif ('filter' == $author_rule) {
         $id = NULL;
     } else {
         // Check the database for an existing author record that might fit
         // First try the user core data table.
         $id = $wpdb->get_var("SELECT ID FROM {$wpdb->users}\n\t\t\tWHERE TRIM(LCASE(display_name)) = TRIM(LCASE('{$author}'))\n\t\t\tOR TRIM(LCASE(user_login)) = TRIM(LCASE('{$author}'))\n\t\t\tOR (\n\t\t\t\tLENGTH(TRIM(LCASE(user_email))) > 0\n\t\t\t\tAND TRIM(LCASE(user_email)) = TRIM(LCASE('{$test_email}'))\n\t\t\t)");
         // If that fails, look for aliases in the user meta data table
         if (is_null($id)) {
             $id = $wpdb->get_var("SELECT user_id FROM {$wpdb->usermeta}\n\t\t\t\tWHERE\n\t\t\t\t\t(meta_key = 'description' AND TRIM(LCASE(meta_value)) = TRIM(LCASE('{$author}')))\n\t\t\t\t\tOR (\n\t\t\t\t\t\tmeta_key = 'description'\n\t\t\t\t\t\tAND TRIM(LCASE(meta_value))\n\t\t\t\t\t\tRLIKE CONCAT(\n\t\t\t\t\t\t\t'(^|\\n)a\\.?k\\.?a\\.?( |\\t)*:?( |\\t)*',\n\t\t\t\t\t\t\tTRIM(LCASE('{$reg_author}')),\n\t\t\t\t\t\t\t'( |\\t|\\r)*(\\n|\$)'\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t");
         }
         // ... if you don't find one, then do what you need to do
         if (is_null($id)) {
             if ($unfamiliar_author === 'create') {
                 $userdata = array();
                 // WordPress 3 is going to pitch a fit if we attempt to register
                 // more than one user account with an empty e-mail address, so we
                 // need *something* here. Ugh.
                 if (strlen($email) == 0 or FeedWordPress::is_null_email($email)) {
                     $url = parse_url($hostUrl);
                     $email = $nice_author . '@' . $url['host'];
                 }
                 #-- user table data
                 $userdata['ID'] = NULL;
                 // new user
                 $userdata['user_login'] = $login;
                 $userdata['user_nicename'] = $nice_author;
                 $userdata['user_pass'] = substr(md5(uniqid(microtime())), 0, 6);
                 // just something random to lock it up
                 $userdata['user_email'] = $email;
                 $userdata['user_url'] = $authorUrl;
                 $userdata['nickname'] = $author;
                 $parts = preg_split('/\\s+/', trim($author), 2);
                 if (isset($parts[0])) {
                     $userdata['first_name'] = $parts[0];
                 }
                 if (isset($parts[1])) {
                     $userdata['last_name'] = $parts[1];
                 }
                 $userdata['display_name'] = $author;
                 $userdata['role'] = 'contributor';
                 do {
                     // Keep trying until you get it right. Or until PHP crashes, I guess.
                     $id = wp_insert_user($userdata);
                     if (is_wp_error($id)) {
                         $codes = $id->get_error_code();
                         switch ($codes) {
                             case 'empty_user_login':
                             case 'existing_user_login':
                                 // Add a random disambiguator
                                 $userdata['user_login'] .= substr(md5(uniqid(microtime())), 0, 6);
                                 break;
                             case 'existing_user_email':
                                 // No disassemble!
                                 $parts = explode('@', $userdata['user_email'], 2);
                                 // Add a random disambiguator as a gmail-style username extension
                                 $parts[0] .= '+' . substr(md5(uniqid(microtime())), 0, 6);
                                 // Reassemble
                                 $userdata['user_email'] = $parts[0] . '@' . $parts[1];
                                 break;
                         }
                     }
                 } while (is_wp_error($id));
             } elseif (is_numeric($unfamiliar_author) and get_userdata((int) $unfamiliar_author)) {
                 $id = (int) $unfamiliar_author;
             } elseif ($unfamiliar_author === 'default') {
                 $id = 1;
             }
         }
     }
     if ($id) {
         $this->link->settings['map authors']['name'][strtolower(trim($author))] = $id;
         // Multisite: Check whether the author has been recorded
         // on *this* blog before. If not, put her down as a
         // Contributor for *this* blog.
         $user = new WP_User((int) $id);
         if (empty($user->roles)) {
             $user->add_role('contributor');
         }
     }
     return $id;
 }
 function diagnostic($level, $out)
 {
     global $feedwordpress_admin_footer;
     $output = get_option('feedwordpress_diagnostics_output', array());
     $diagnostic_nesting = count(explode(":", $level));
     if (FeedWordPress::diagnostic_on($level)) {
         foreach ($output as $method) {
             switch ($method) {
                 case 'echo':
                     echo "<div><pre><strong>Diag" . str_repeat('====', $diagnostic_nesting - 1) . '|</strong> ' . esc_html($out) . "</pre></div>";
                     break;
                 case 'admin_footer':
                     $feedwordpress_admin_footer[] = $out;
                     break;
                 case 'error_log':
                     //	error_log('[feedwordpress]' . $out);
                     break;
             }
         }
     }
 }