function subscribe($args)
 {
     $ret = $this->validate($args);
     if (is_array($ret)) {
         // Success
         // The remaining params are feed URLs
         foreach ($args as $arg) {
             $finder = new FeedFinder($arg, false, 1);
             $feeds = array_values(array_unique($finder->find()));
             if (count($feeds) > 0) {
                 $link_id = FeedWordPress::syndicate_link(feedwordpress_display_url($feeds[0]), $feeds[0], $feeds[0]);
                 $ret[] = array('added', $feeds[0], $arg);
             } else {
                 $ret[] = array('error', $arg);
             }
         }
     }
     return $ret;
 }
 function accept_multiadd()
 {
     global $fwp_post;
     if (isset($fwp_post['cancel']) and $fwp_post['cancel'] == __(FWP_CANCEL_BUTTON)) {
         return true;
         // Continue ....
     }
     // If this is a POST, validate source and user credentials
     FeedWordPressCompatibility::validate_http_request('feedwordpress_feeds', 'manage_links');
     $in = (isset($fwp_post['multilookup']) ? $fwp_post['multilookup'] : '') . (isset($fwp_post['opml_lookup']) ? $fwp_post['opml_lookup'] : '');
     if (isset($fwp_post['confirm']) and $fwp_post['confirm'] == 'multiadd') {
         $chex = $fwp_post['multilookup'];
         $added = array();
         $errors = array();
         foreach ($chex as $feed) {
             if (isset($feed['add']) and $feed['add'] == 'yes') {
                 // Then, add in the URL.
                 $link_id = FeedWordPress::syndicate_link($feed['title'], $feed['link'], $feed['url']);
                 if ($link_id and !is_wp_error($link_id)) {
                     $added[] = $link_id;
                 } else {
                     $errors[] = array($feed['url'], $link_id);
                 }
             }
         }
         print "<div class='updated'>\n";
         print "<p>Added " . count($added) . " new syndicated sources.</p>";
         if (count($errors) > 0) {
             print "<p>FeedWordPress encountered errors trying to add the following sources:</p>\n\t\t\t\t<ul>\n";
             foreach ($errors as $err) {
                 $url = $err[0];
                 $short = esc_html(feedwordpress_display_url($url));
                 $url = esc_html($url);
                 $wp = $err[1];
                 if (is_wp_error($err[1])) {
                     $error = $err[1];
                     $mesg = " (<code>" . $error->get_error_messages() . "</code>)";
                 } else {
                     $mesg = '';
                 }
                 print "<li><a href='{$url}'>{$short}</a>{$mesg}</li>\n";
             }
             print "</ul>\n";
         }
         print "</div>\n";
     } elseif (is_array($in) or strlen($in) > 0) {
         add_meta_box('feedwordpress_multiadd_box', __('Add Feeds'), array($this, 'multiadd_box'), $this->meta_box_context(), $this->meta_box_context());
     }
     return true;
     // Continue...
 }
function fwp_switchfeed_page()
{
    global $wp_db_version;
    global $fwp_post;
    // If this is a POST, validate source and user credentials
    FeedWordPressCompatibility::validate_http_request('feedwordpress_switchfeed', 'manage_links');
    $changed = false;
    if (!isset($fwp_post['Cancel'])) {
        if (isset($fwp_post['save_link_id']) and $fwp_post['save_link_id'] == '*') {
            $changed = true;
            $link_id = FeedWordPress::syndicate_link($fwp_post['feed_title'], $fwp_post['feed_link'], $fwp_post['feed']);
            if ($link_id) {
                $existingLink = new SyndicatedLink($link_id);
                ?>
<div class="updated"><p><a href="<?php 
                print $fwp_post['feed_link'];
                ?>
"><?php 
                print esc_html($fwp_post['feed_title']);
                ?>
</a>
has been added as a contributing site, using the feed at
&lt;<a href="<?php 
                print $fwp_post['feed'];
                ?>
"><?php 
                print esc_html($fwp_post['feed']);
                ?>
</a>&gt;.
| <a href="admin.php?page=<?php 
                echo FWP_FEEDS_PAGE_SLUG;
                ?>
&amp;link_id=<?php 
                print $link_id;
                ?>
">Configure settings</a>.</p></div>
<?php 
            } else {
                ?>
<div class="updated"><p>There was a problem adding the feed. [SQL: <?php 
                echo esc_html(mysql_error());
                ?>
]</p></div>
<?php 
            }
        } elseif (isset($fwp_post['save_link_id'])) {
            $existingLink = new SyndicatedLink($fwp_post['save_link_id']);
            $changed = $existingLink->set_uri($fwp_post['feed']);
            if ($changed) {
                $home = $existingLink->homepage(false);
                $name = $existingLink->name(false);
                ?>
 
<div class="updated"><p>Feed for <a href="<?php 
                echo esc_html($home);
                ?>
"><?php 
                echo esc_html($name);
                ?>
</a>
updated to &lt;<a href="<?php 
                echo esc_html($fwp_post['feed']);
                ?>
"><?php 
                echo esc_html($fwp_post['feed']);
                ?>
</a>&gt;.</p></div>
				<?php 
            }
        }
    }
    if (isset($existingLink)) {
        do_action('feedwordpress_admin_switchfeed', $fwp_post['feed'], $existingLink);
    }
    if (!$changed) {
        ?>
<div class="updated"><p>Nothing was changed.</p></div>
		<?php 
    }
    return true;
    // Continue
}
function fwp_switchfeed_page()
{
    global $wpdb, $wp_db_version;
    check_admin_referer();
    if (!isset($_REQUEST['Cancel'])) {
        if (!current_user_can('manage_links')) {
            die(__("Cheatin' uh ?"));
        } elseif (isset($_REQUEST['link_id']) and $_REQUEST['link_id'] == 0) {
            $link_id = FeedWordPress::syndicate_link($_REQUEST['feed_title'], $_REQUEST['feed_link'], $_REQUEST['feed']);
            if ($link_id) {
                ?>
<div class="updated"><p><a href="<?php 
                echo $_REQUEST['feed_link'];
                ?>
"><?php 
                echo wp_specialchars($_REQUEST['feed_title'], 'both');
                ?>
</a>
has been added as a contributing site, using the newsfeed at &lt;<a href="<?php 
                echo $_REQUEST['feed'];
                ?>
"><?php 
                echo wp_specialchars($_REQUEST['feed'], 'both');
                ?>
</a>&gt;.</p></div>
<?php 
            } else {
                ?>
<div class="updated"><p>There was a problem adding the newsfeed. [SQL: <?php 
                echo wp_specialchars(mysql_error(), 'both');
                ?>
]</p></div>
<?php 
            }
        } elseif (isset($_REQUEST['link_id'])) {
            // Update link_rss
            $result = $wpdb->query("\n\t\t\tUPDATE {$wpdb->links}\n\t\t\tSET\n\t\t\t\tlink_rss = '" . $wpdb->escape($_REQUEST['feed']) . "'\n\t\t\tWHERE link_id = '" . $wpdb->escape($_REQUEST['link_id']) . "'\n\t\t\t");
            if ($result) {
                $result = $wpdb->get_row("\n\t\t\t\tSELECT link_name, link_url FROM {$wpdb->links}\n\t\t\t\tWHERE link_id = '" . $wpdb->escape($_REQUEST['link_id']) . "'\n\t\t\t\t");
                ?>
 
<div class="updated"><p>Feed for <a href="<?php 
                echo $result->link_url;
                ?>
"><?php 
                echo wp_specialchars($result->link_name, 'both');
                ?>
</a>
updated to &lt;<a href="<?php 
                echo $_REQUEST['feed'];
                ?>
"><?php 
                echo wp_specialchars($_REQUEST['feed'], 'both');
                ?>
</a>&gt;.</p></div>
			<?php 
            } else {
                ?>
<div class="updated"><p>Nothing was changed.</p></div>
			<?php 
            }
        }
    }
    return true;
    // Continue
}
	function accept_multiadd () {
		global $fwp_post;

		if (isset($fwp_post['cancel']) and $fwp_post['cancel']==__(FWP_CANCEL_BUTTON)) :
			return true; // Continue ....
		endif;
		
		// If this is a POST, validate source and user credentials
		FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_feeds', /*capability=*/ 'manage_links');

		$in = (isset($fwp_post['multilookup']) ? $fwp_post['multilookup'] : '')
			.(isset($fwp_post['opml_lookup']) ? $fwp_post['opml_lookup'] : '');
		if (isset($fwp_post['confirm']) and $fwp_post['confirm']=='multiadd') :
			$chex = $fwp_post['multilookup'];
			$added = array(); $errors = array();
			foreach ($chex as $feed) :
				if (isset($feed['add']) and $feed['add']=='yes') :
					// Then, add in the URL.
					$link_id = FeedWordPress::syndicate_link(
						$feed['title'],
						$feed['link'],
						$feed['url']
					);
					if ($link_id and !is_wp_error($link_id)):
						$added[] = $link_id; 
					else :
						$errors[] = array($feed['url'], $link_id);
					endif;
				endif;
			endforeach;
			
			print "<div class='updated'>\n";
			print "<p>Added ".count($added)." new syndicated sources.</p>";
			if (count($errors) > 0) :
				print "<p>FeedWordPress encountered errors trying to add the following sources:</p>
				<ul>\n";
				foreach ($errors as $err) :
					$url = $err[0];
					$short = esc_html(feedwordpress_display_url($url));
					$url = esc_html($url);
					$wp = $err[1];
					if (is_wp_error($err[1])) :
						$error = $err[1];
						$mesg = " (<code>".$error->get_error_messages()."</code>)";
					else :
						$mesg = '';
					endif;
					print "<li><a href='$url'>$short</a>$mesg</li>\n";
				endforeach;
				print "</ul>\n";
			endif;
			print "</div>\n";

		elseif (is_array($in) or strlen($in) > 0) :
			add_meta_box(
				/*id=*/ 'feedwordpress_multiadd_box',
				/*title=*/ __('Add Feeds'),
				/*callback=*/ array($this, 'multiadd_box'),
				/*page=*/ $this->meta_box_context(),
				/*context =*/ $this->meta_box_context()
			);
		endif;
		return true; // Continue...
	}