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 »\" /></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 }
/** * SyndicatedPost::add_rss_meta: adds interesting meta-data to each entry * using the space for custom keys. The set of keys and values to add is * specified by the keys and values of $post['meta']. This is used to * store anything that the WordPress user might want to access from a * template concerning the post's original source that isn't provided * for by standard WP meta-data (i.e., any interesting data about the * syndicated post other than author, title, timestamp, categories, and * guid). It's also used to hook into WordPress's support for * enclosures. * * @param string $new_status Unused action parameter. * @param string $old_status Unused action parameter. * @param object $post The database record for the post just inserted. */ function add_rss_meta($new_status, $old_status, $post) { global $wpdb; if ($new_status != 'inherit') { // Bail if we are creating a revision. FeedWordPress::diagnostic('syndicated_posts:meta_data', 'Adding post meta-data: {' . implode(", ", array_keys($this->post['meta'])) . '}'); if (is_array($this->post) and isset($this->post['meta']) and is_array($this->post['meta'])) { $postId = $post->ID; // Aggregated posts should NOT send out pingbacks. // WordPress 2.1-2.2 claim you can tell them not to // using $post_pingback, but they don't listen, so we // make sure here. $result = $wpdb->query("\n\t\t\t\tDELETE FROM {$wpdb->postmeta}\n\t\t\t\tWHERE post_id='{$postId}' AND meta_key='_pingme'\n\t\t\t\t"); foreach ($this->post['meta'] as $key => $values) { $eKey = esc_sql($key); // If this is an update, clear out the old // values to avoid duplication. $result = $wpdb->query("\n\t\t\t\t\tDELETE FROM {$wpdb->postmeta}\n\t\t\t\t\tWHERE post_id='{$postId}' AND meta_key='{$eKey}'\n\t\t\t\t\t"); // Allow for either a single value or an array if (!is_array($values)) { $values = array($values); } foreach ($values as $value) { FeedWordPress::diagnostic('syndicated_posts:meta_data', "Adding post meta-datum to post [{$postId}]: [{$key}] = " . MyPHP::val($value, true)); add_post_meta($postId, $key, $value, false); } } } } }
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}] ⇜ " . esc_html(MyPHP::val($args))); $res = wp_remote_request($url, $args); FeedWordPress::diagnostic('updated_feeds:http', "HTTP [{$url}] ⇝ " . 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; }
function multiundelete_page() { global $wpdb; // If this is a POST, validate source and user credentials FeedWordPressCompatibility::validate_http_request('feedwordpress_feeds', 'manage_links'); // Get single link ID or multiple link IDs from REQUEST parameters // if available. Sanitize values for MySQL. $link_list = $this->requested_link_ids_sql(); if (MyPHP::post('confirm') == 'Undelete') { if (is_array(MyPHP::post('link_action'))) { $actions = MyPHP::post('link_action'); } else { $actions = array(); } $do_it = array('unhide' => array()); foreach ($actions as $link_id => $what) { $do_it[$what][] = $link_id; } $alter = array(); if (count($do_it['unhide']) > 0) { $unhiddem = "(" . implode(', ', $do_it['unhide']) . ")"; $alter[] = "\n\t\t\t\tUPDATE {$wpdb->links}\n\t\t\t\tSET link_visible = 'Y'\n\t\t\t\tWHERE link_id IN {$unhiddem}\n\t\t\t\t"; } $errs = array(); $success = array(); foreach ($alter as $sql) { $result = $wpdb->query($sql); if (!$result) { $errs[] = mysql_error(); } } if (count($alter) > 0) { echo "<div class=\"updated\">\n"; if (count($errs) > 0) { echo "There were some problems processing your "; echo "re-subscribe request. [SQL: " . implode('; ', $errs) . "]"; } else { echo "Your re-subscribe request(s) have been processed."; } echo "</div>\n"; } return true; // Continue on to Syndicated Sites listing } else { // $link_list has previously been sanitized for html by self::requested_link_ids_sql $targets = $wpdb->get_results("\n\t\t\t\tSELECT * FROM {$wpdb->links}\n\t\t\t\tWHERE link_id IN {$link_list}\n\t\t\t\t"); ?> <form action="<?php print $this->form_action(); ?> " method="post"> <div class="wrap"> <?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?> <input type="hidden" name="action" value="<?php print FWP_RESUB_CHECKED; ?> " /> <input type="hidden" name="confirm" value="Undelete" /> <h2>Re-subscribe to Syndicated Links:</h2> <?php foreach ($targets as $link) { $subscribed = 'Y' == strtoupper($link->link_visible); $link_url = esc_html($link->link_url); $link_name = esc_html($link->link_name); $link_description = esc_html($link->link_description); $link_rss = esc_html($link->link_rss); if (!$subscribed) { ?> <fieldset> <legend><?php echo $link_name; ?> </legend> <table class="editform" width="100%" cellspacing="2" cellpadding="5"> <tr><th scope="row" width="20%"><?php _e('Feed URI:'); ?> </th> <td width="80%"><a href="<?php echo $link_rss; ?> "><?php echo $link_rss; ?> </a></td></tr> <tr><th scope="row" width="20%"><?php _e('Short description:'); ?> </th> <td width="80%"><?php echo $link_description; ?> </span></td></tr> <tr><th width="20%" scope="row"><?php _e('Homepage:'); ?> </th> <td width="80%"><a href="<?php echo $link_url; ?> "><?php echo $link_url; ?> </a></td></tr> <tr style="vertical-align:top"><th width="20%" scope="row">Subscription <?php _e('Options'); ?> :</th> <td width="80%"><ul style="margin:0; padding: 0; list-style: none"> <li><input type="radio" id="unhide-<?php echo $link->link_id; ?> " name="link_action[<?php echo $link->link_id; ?> ]" value="unhide" checked="checked" /> <label for="unhide-<?php echo $link->link_id; ?> ">Turn back on the subscription for this syndication source.</label></li> <li><input type="radio" id="nothing-<?php echo $link->link_id; ?> " name="link_action[<?php echo $link->link_id; ?> ]" value="nothing" /> <label for="nothing-<?php echo $link->link_id; ?> ">Leave this feed as it is. I changed my mind.</label></li> </ul> </table> </fieldset> <?php } } ?> <div class="submit"> <input class="button-primary delete" type="submit" name="submit" value="<?php _e('Re-subscribe to selected feeds »'); ?> " /> </div> </div> <?php return false; // Don't continue on to Syndicated Sites listing } }
public function do_http_test($post) { if (isset($post['http_test_url']) and isset($post['http_test_method'])) { $url = $post['http_test_url']; $args = array(); if (isset($post['http_test_args_key'])) { foreach ($post['http_test_args_key'] as $idx => $name) { $name = trim($name); if (strlen($name) > 0) { $value = NULL; if (isset($post['http_test_args_value']) and isset($post['http_test_args_value'][$idx])) { $value = $post['http_test_args_value'][$idx]; } if (preg_match('/^javascript:(.*)$/i', $value, $refs)) { if (function_exists('json_decode')) { $json_value = json_decode($refs[1]); if (!is_null($json_value)) { $value = $json_value; } } } $args[$name] = $value; } } } switch ($post['http_test_method']) { case 'wp_remote_request': $out = wp_remote_request($url, $args); break; case 'FeedWordPress_File': $out = new FeedWordPress_File($url); break; } $this->test_html['url'] = $url; $this->test_html['http_test'] = esc_html(MyPHP::val($out)); } }
function display_feed_settings_page_links($params = array()) { global $fwp_path; $params = wp_parse_args($params, array('before' => '', 'between' => ' | ', 'after' => '', 'long' => false, 'subscription' => $this->link)); $sub = $params['subscription']; $links = array("Feed" => array('page' => 'feeds-page.php', 'long' => 'Feeds & Updates'), "Posts" => array('page' => 'posts-page.php', 'long' => 'Posts & Links'), "Authors" => array('page' => 'authors-page.php', 'long' => 'Authors'), 'Categories' => array('page' => 'categories-page.php', 'long' => 'Categories & Tags')); $link_id = NULL; if (is_object($sub)) { if (method_exists($sub, 'found')) { if ($sub->found()) { $link_id = $sub->link->link_id; } } else { $link_id = $sub->link_id; } } print $params['before']; $first = true; foreach ($links as $label => $link) { if (!$first) { print $params['between']; } if (isset($link['url'])) { MyPHP::url($link['url'], array("link_id" => $link_id)); } else { $url = $this->admin_page_href($link['page'], array(), $sub); } $url = esc_html($url); if ($link['page'] == basename($this->filename)) { print "<strong>"; } else { print "<a href=\"{$url}\">"; } if ($params['long']) { print esc_html(__($link['long'])); } else { print esc_html(__($label)); } if ($link['page'] == basename($this->filename)) { print "</strong>"; } else { print "</a>"; } $first = false; } print $params['after']; }
function post($key, $default = NULL) { return MyPHP::post($key, $default); }
public function get_categories() { $terms = wp_get_object_terms($this->post->ID, get_taxonomies(array('public' => true), 'names'), 'all'); $rootUrl = get_bloginfo('url'); $cats = array(); foreach ($terms as $term) { $taxUrl = MyPHP::url($rootUrl, array("taxonomy" => $term->taxonomy)); //array("taxonomy" => $term->taxonomy )); $cats[] = new SimplePie_Category($term->slug, $taxUrl, $term->name); } return $cats; }
function display_feedfinder() { global $wpdb; $lookup = isset($_REQUEST['lookup']) ? $_REQUEST['lookup'] : NULL; $auth = MyPHP::request('link_rss_auth_method'); $username = MyPHP::request('link_rss_username'); $password = MyPHP::request('link_rss_password'); $credentials = array("authentication" => $auth, "username" => $username, "password" => $password); $feeds = array(); $feedSwitch = false; $current = null; if ($this->for_feed_settings()) { // Existing feed? $feedSwitch = true; if (is_null($lookup)) { // Switch Feed without a specific feed yet suggested // Go to the human-readable homepage to look for // auto-detection links $lookup = $this->link->link->link_url; $auth = $this->link->setting('http auth method'); $username = $this->link->setting('http username'); $password = $this->link->setting('http password'); // Guarantee that you at least have the option to // stick with what works. $current = $this->link->link->link_rss; $feeds[] = $current; } $name = esc_html($this->link->link->link_name); } else { // Or a new subscription to add? $name = "Subscribe to <code>" . esc_html(feedwordpress_display_url($lookup)) . "</code>"; } ?> <div class="wrap" id="feed-finder"> <h2>Feed Finder: <?php echo $name; ?> </h2> <?php if ($feedSwitch) { $this->display_alt_feed_box($lookup); } $finder = array(); if (!is_null($current)) { $finder[$current] = new FeedFinder($current); } $finder[$lookup] = new FeedFinder($lookup); foreach ($finder as $url => $ff) { $feeds = array_merge($feeds, $ff->find(NULL, $credentials)); } $feeds = array_values($feeds); // Allow for some simple FeedFinder results filtering $feeds = apply_filters('feedwordpress_feedfinder_results', $feeds, array("url" => $lookup, "auth" => $auth, "username" => $username, "password" => $password, "finder" => $finder), $this); if (count($feeds) > 0) { if ($feedSwitch) { ?> <h3>Feeds Found</h3> <?php } if (count($feeds) > 1) { $option_template = 'Option %d: '; $form_class = ' class="multi"'; ?> <p><strong>This web page provides at least <?php print count($feeds); ?> different feeds.</strong> These feeds may provide the same information in different formats, or may track different items. (You can check the Feed Information and the Sample Item for each feed to get an idea of what the feed provides.) Please select the feed that you'd like to subscribe to.</p> <?php } else { $option_template = ''; $form_class = ''; } global $fwp_credentials; foreach ($feeds as $key => $f) { $ofc = $fwp_credentials; $fwp_credentials = $credentials; // Set $pie = FeedWordPress::fetch($f, array("cache" => false)); $fwp_credentials = $ofc; // Re-Set $rss = is_wp_error($pie) ? $pie : new MagpieFromSimplePie($pie); if ($this->url_for_401($pie)) { $this->display_alt_feed_box($lookup, array("err" => $pie, "auth" => $auth, "username" => $username, "password" => $password)); continue; } if ($rss and !is_wp_error($rss)) { $feed_link = isset($rss->channel['link']) ? $rss->channel['link'] : ''; $feed_title = isset($rss->channel['title']) ? $rss->channel['title'] : $feed_link; $feed_type = $rss->feed_type ? $rss->feed_type : 'Unknown'; $feed_version_template = '%.1f'; $feed_version = $rss->feed_version; } else { // Give us some sucky defaults $feed_title = feedwordpress_display_url($lookup); $feed_link = $lookup; $feed_type = 'Unknown'; $feed_version_template = ''; $feed_version = ''; } ?> <form<?php print $form_class; ?> action="<?php $this->form_action('syndication.php'); ?> " method="post"> <div class="inside"><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_switchfeed'); ?> <?php $classes = array('feed-found'); $currentFeed = ''; if (!is_null($current) and $current == $f) { $classes[] = 'current'; $currentFeed = ' (currently subscribed)'; } if ($key % 2) { $classes[] = 'alt'; } ?> <fieldset class="<?php print implode(" ", $classes); ?> "> <legend><?php printf($option_template, $key + 1); print $feed_type . " "; printf($feed_version_template, $feed_version); ?> feed<?php print $currentFeed; ?> </legend> <?php $this->stamp_link_id(); // No feed specified = add new feed; we // need to pass along a starting title // and homepage URL for the new Link. if (!$this->for_feed_settings()) { ?> <input type="hidden" name="feed_title" value="<?php echo esc_html($feed_title); ?> " /> <input type="hidden" name="feed_link" value="<?php echo esc_html($feed_link); ?> " /> <?php } ?> <input type="hidden" name="feed" value="<?php echo esc_html($f); ?> " /> <input type="hidden" name="action" value="switchfeed" /> <div> <div class="feed-sample"> <?php $link = NULL; $post = NULL; if (!is_wp_error($rss) and count($rss->items) > 0) { // Prepare to display Sample Item $link = new MagpieMockLink(array('simplepie' => $pie, 'magpie' => $rss), $f); $post = new SyndicatedPost(array('simplepie' => $rss->originals[0], 'magpie' => $rss->items[0]), $link); ?> <h3>Sample Item</h3> <ul> <li><strong>Title:</strong> <a href="<?php echo $post->post['meta']['syndication_permalink']; ?> "><?php echo $post->post['post_title']; ?> </a></li> <li><strong>Date:</strong> <?php print date('d-M-y g:i:s a', $post->published()); ?> </li> </ul> <div class="entry"> <?php print $post->post['post_content']; ?> </div> <?php do_action('feedwordpress_feed_finder_sample_item', $f, $post, $link); } else { if (is_wp_error($rss)) { print '<div class="feed-problem">'; print "<h3>Problem:</h3>\n"; print "<p>FeedWordPress encountered the following error\n\t\t\t\t\t\t\twhen trying to retrieve this feed:</p>"; print '<p style="margin: 1.0em 3.0em"><code>' . $rss->get_error_message() . '</code></p>'; print "<p>If you think this is a temporary problem, you can still force FeedWordPress to add the subscription. FeedWordPress will not be able to find any syndicated posts until this problem is resolved.</p>"; print "</div>"; } ?> <h3>No Items</h3> <p>FeedWordPress found no posts on this feed.</p> <?php } ?> </div> <div> <h3>Feed Information</h3> <ul> <li><strong>Homepage:</strong> <a href="<?php echo $feed_link; ?> "><?php echo is_null($feed_title) ? '<em>Unknown</em>' : $feed_title; ?> </a></li> <li><strong>Feed URL:</strong> <a title="<?php echo esc_html($f); ?> " href="<?php echo esc_html($f); ?> "><?php echo esc_html(feedwordpress_display_url($f, 40, 10)); ?> </a> (<a title="Check feed <<?php echo esc_html($f); ?> > for validity" href="http://feedvalidator.org/check.cgi?url=<?php echo urlencode($f); ?> ">validate</a>)</li> <li><strong>Encoding:</strong> <?php echo isset($rss->encoding) ? esc_html($rss->encoding) : "<em>Unknown</em>"; ?> </li> <li><strong>Description:</strong> <?php echo isset($rss->channel['description']) ? esc_html($rss->channel['description']) : "<em>Unknown</em>"; ?> </li> </ul> <?php $this->display_authentication_credentials_box(array('username' => $username, 'password' => $password, 'method' => $auth)); ?> <?php do_action('feedwordpress_feedfinder_form', $f, $post, $link, $this->for_feed_settings()); ?> <div class="submit"><input type="submit" class="button-primary" name="Use" value="« Use this feed" /> <input type="submit" class="button" name="Cancel" value="× Cancel" /></div> </div> </div> </fieldset> </div> <!-- class="inside" --> </form> <?php unset($link); unset($post); } } else { foreach ($finder as $url => $ff) { $url = esc_html($url); print "<h3>Searched for feeds at {$url}</h3>\n"; print "<p><strong>" . __('Error') . ":</strong> " . __("FeedWordPress couldn't find any feeds at") . ' <code><a href="' . htmlspecialchars($lookup) . '">' . htmlspecialchars($lookup) . '</a></code>'; print ". " . __('Try another URL') . ".</p>"; // Diagnostics print "<div class=\"updated\" style=\"margin-left: 3.0em; margin-right: 3.0em;\">\n"; print "<h3>" . __('Diagnostic information') . "</h3>\n"; if (!is_null($ff->error()) and strlen($ff->error()) > 0) { print "<h4>" . __('HTTP request failure') . "</h4>\n"; print "<p>" . $ff->error() . "</p>\n"; } else { print "<h4>" . __('HTTP request completed') . "</h4>\n"; print "<p><strong>Status " . $ff->status() . ":</strong> " . $this->HTTPStatusMessages[(int) $ff->status()] . "</p>\n"; } // Do some more diagnostics if the API for it is available. if (function_exists('_wp_http_get_object')) { $httpObject = _wp_http_get_object(); if (is_callable(array($httpObject, '_getTransport'))) { $transports = $httpObject->_getTransport(); print "<h4>" . __('HTTP Transports available') . ":</h4>\n"; print "<ol>\n"; print "<li>" . implode("</li>\n<li>", array_map('get_class', $transports)) . "</li>\n"; print "</ol>\n"; } elseif (is_callable(array($httpObject, '_get_first_available_transport'))) { $transport = $httpObject->_get_first_available_transport(array(), $url); print "<h4>" . __("HTTP Transport") . ":</h4>\n"; print "<ol>\n"; print "<li>" . FeedWordPress::val($transport) . "</li>\n"; print "</ol>\n"; } print "</div>\n"; } } } if (!$feedSwitch) { $this->display_alt_feed_box($lookup, true); } ?> </div> <!-- class="wrap" --> <?php return false; // Don't continue }