val() static public method

* FeedWordPress::noncritical_bug ()
static public val ( $v, $no_newlines = false )
 function insert_post($update = false, $freshness = 2)
 {
     global $wpdb;
     $dbpost = $this->normalize_post(true);
     if (!is_null($dbpost)) {
         $dbpost['post_pingback'] = false;
         // Tell WP 2.1 and 2.2 not to process for pingbacks
         // This is a ridiculous f*****g kludge necessitated by WordPress 2.6 munging authorship meta-data
         add_action('_wp_put_post_revision', array($this, 'fix_revision_meta'));
         // Kludge to prevent kses filters from stripping the
         // content of posts when updating without a logged in
         // user who has `unfiltered_html` capability.
         $mungers = array('wp_filter_kses', 'wp_filter_post_kses');
         $removed = array();
         foreach ($mungers as $munger) {
             if (has_filter('content_save_pre', $munger)) {
                 remove_filter('content_save_pre', $munger);
                 $removed[] = $munger;
             }
         }
         if ($update and function_exists('get_post_field')) {
             // Don't munge status fields that the user may
             // have reset manually
             $doNotMunge = array('post_status', 'comment_status', 'ping_status');
             foreach ($doNotMunge as $field) {
                 $dbpost[$field] = get_post_field($field, $this->wp_id());
             }
         }
         // WP3's wp_insert_post scans current_user_can() for the
         // tax_input, with no apparent way to override. Ugh.
         add_action('transition_post_status', array($this, 'add_terms'), -10001, 3);
         // WP3 appears to override whatever you give it for
         // post_modified. Ugh.
         add_action('transition_post_status', array($this, 'fix_post_modified_ts'), -10000, 3);
         if ($update) {
             $this->post['ID'] = $this->wp_id();
             $dbpost['ID'] = $this->post['ID'];
         }
         // O.K., is this a new post? If so, we need to create
         // the basic post record before we do anything else.
         if ($this->this_revision_needs_original_post()) {
             // *sigh*, for handling inconsistent slash expectations < 3.6
             $sdbpost = $this->db_sanitize_post($dbpost);
             // Go ahead and insert the first post record to
             // anchor the revision history.
             $this->_wp_id = wp_insert_post($sdbpost, true);
             $dbpost['ID'] = $this->_wp_id;
         }
         // Now that we've made sure the original exists, insert
         // this version here as a revision.
         $revision_id = _wp_put_post_revision($dbpost, false);
         if (!$this->this_revision_needs_original_post()) {
             if ($this->this_revision_is_current()) {
                 wp_restore_post_revision($revision_id);
             } else {
                 // If we do not activate this revision, then the
                 // add_rss_meta will not be called, which is
                 // more or less as it should be, but that means
                 // we have to actively record this revision's
                 // update hash from here.
                 $postId = $this->post['ID'];
                 $key = 'syndication_item_hash';
                 $hash = $this->update_hash();
                 FeedWordPress::diagnostic('syndicated_posts:meta_data', "Adding post meta-datum to post [{$postId}]: [{$key}] = " . FeedWordPress::val($hash, true));
                 add_post_meta($postId, $key, $hash, false);
             }
         }
         remove_action('transition_post_status', array($this, 'add_terms'), -10001, 3);
         remove_action('transition_post_status', array($this, 'fix_post_modified_ts'), -10000, 3);
         // Turn off ridiculous f*****g kludges #1 and #2
         remove_action('_wp_put_post_revision', array($this, 'fix_revision_meta'));
         foreach ($removed as $filter) {
             add_filter('content_save_pre', $filter);
         }
         $this->validate_post_id($dbpost, $update, array(__CLASS__, __FUNCTION__));
     }
 }
Esempio n. 2
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 __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;
	}
 /**
  * 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 = $wpdb->escape($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}] = " . FeedWordPress::val($value, true));
                     add_post_meta($postId, $key, $value, false);
                 }
             }
         }
     }
 }
    function display_feedfinder()
    {
        global $wpdb;
        $lookup = isset($_REQUEST['lookup']) ? $_REQUEST['lookup'] : NULL;
        $auth = FeedWordPress::param('link_rss_auth_method');
        $username = FeedWordPress::param('link_rss_username');
        $password = FeedWordPress::param('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);
        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);
                $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="admin.php?page=<?php 
                print $GLOBALS['fwp_path'];
                ?>
/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>" . 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
    }
 function add_rss_meta($new_status, $old_status, $post)
 {
     FeedWordPress::diagnostic('syndicated_posts:meta_data', 'Adding post meta-data: {' . implode(", ", array_keys($this->post['meta'])) . '}');
     // not saving the post we're processing; bail.
     if ($post->ID != $this->wp_id()) {
         return;
     }
     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 = delete_post_meta($postId, '_pingme');
         foreach ($this->post['meta'] as $key => $values) {
             // If this is an update, clear out the old
             // values to avoid duplication.
             $result = delete_post_meta($postId, $key);
             // 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}] = " . FeedWordPress::val($value, true));
                 add_post_meta($postId, $key, $value, false);
             }
         }
     }
 }
    function info_box($page, $box = NULL)
    {
        global $feedwordpress;
        $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">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(FeedWordPress::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 
    }
	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];
						endif;
						
						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;
								endif;
							endif;
						endif;
						
						$args[$name] = $value;
					endif;
				endforeach;
			endif;
			
			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;
			endswitch;
			
			$this->test_html['http_test'] = esc_html(FeedWordPress::val($out));
		endif;
	} /* FeedWordPressDiagnosticsPage::do_http_test () */
 /**
  * SICWebImage::upload ()
  *
  * @return int The numeric ID of the attachment created in the WordPress
  * media gallery as a result of uploading this image. -1 if upload failed
  */
 function upload($attach_to)
 {
     $attach_id = NULL;
     # Now send the image to the upload directory
     $up = wp_upload_bits($this->local_filename(), $this->mimetype(), $this->data());
     if ($up and !$up['error']) {
         # Now do the attachment
         $attach = array('post_mime_type' => $this->mimetype(), 'post_title' => $this->post_title(), 'post_content' => '', 'post_status' => 'inherit', 'guid' => self::guid($this->url()));
         $attach_id = wp_insert_attachment($attach, $up['file'], $attach_to);
         require_once ABSPATH . 'wp-admin' . '/includes/image.php';
         $attach_data = wp_generate_attachment_metadata($attach_id, $up['file']);
         wp_update_attachment_metadata($attach_id, $attach_data);
     } else {
         if (is_array($up) and isset($up['error'])) {
             $error_message = $up['error'];
         } else {
             $error_message = preg_replace('/\\s+/', " ", FeedWordPress::val($up));
         }
         FeedWordPress::diagnostic('sicem:capture:error', "Failed image storage [{$url}]: {$error_message}");
     }
     return $attach_id;
 }
Esempio n. 10
0
 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['http_test'] = esc_html(FeedWordPress::val($out));
     }
 }