Add a new subscription to, or update an existing subscription in,
FWP's list of subscribed feeds.
Postcondition: If $rss is the URL of a feed not yet on FWP's list of
subscribed feeds, then a new subscription will be added, using $name
as its initial title and $uri as its initial homepage URL (normally
these will be updated with new values taken from the feed, the first
time the new feed is checked for syndicated content, unless feed
settings prevent this). If $rss is the URL of a feed that is already
on FWP's list of subscribed feeds, then that feed will be updated to
use the title provided in $name and the homepage URL in $uri
public static syndicate_link ( string $name, string $uri, string $rss ) : mixed | ||
$name | string | The human-readable title of the feed (for example, "Rad Geek People's Daily") |
$uri | string | The URI for the human-readable homepage associated with the feed (for example, |
$rss | string | The URI for the feed itself (for example, |
Результат | mixed | Returns an int with the numeric ID of the new subscription's wp_links record if successful or a WP_Error object if wp_insert_link() failed. |
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 <<a href="<?php print $fwp_post['feed']; ?> "><?php print esc_html($fwp_post['feed']); ?> </a>>. | <a href="admin.php?page=<?php echo FWP_FEEDS_PAGE_SLUG; ?> &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 <<a href="<?php echo esc_html($fwp_post['feed']); ?> "><?php echo esc_html($fwp_post['feed']); ?> </a>>.</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 <<a href="<?php echo $_REQUEST['feed']; ?> "><?php echo wp_specialchars($_REQUEST['feed'], 'both'); ?> </a>>.</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 <<a href="<?php echo $_REQUEST['feed']; ?> "><?php echo wp_specialchars($_REQUEST['feed'], 'both'); ?> </a>>.</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... }