예제 #1
0
 /**
  * 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;
 }
예제 #3
0
 static function val($v, $no_newlines = false)
 {
     return MyPHP::val($v, $no_newlines);
 }
예제 #4
0
 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));
     }
 }
예제 #5
0
    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 
                print $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 &lt;<?php 
                echo esc_html($f);
                ?>
&gt; 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="&laquo; 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>" . MyPHP::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
    }