function posts_search($search, &$query) { global $wpdb; if ($guid = $query->get('guid')) { if (strlen(trim($guid)) > 0) { $seek = array($guid); // MD5 hashes if (preg_match('/^[0-9a-f]{32}$/i', $guid)) { $seek[] = SyndicatedPost::normalize_guid_prefix() . $guid; } // Invalid URIs, URIs that WordPress just doesn't like, and URIs // that WordPress decides to munge. $nGuid = SyndicatedPost::normalize_guid($guid); if ($guid != $nGuid) { $seek[] = $nGuid; } // Escape to prevent frak-ups, injections, etc. $seek = array_map('esc_sql', $seek); // Assemble $guidMatch = "(guid = '" . implode("') OR (guid = '", $seek) . "')"; $search .= " AND ({$guidMatch})"; } } if ($query->get('fields') == '_synfresh') { // Ugly hack to ensure we ONLY check by guid in syndicated freshness // checks -- for reasons of both performance and correctness. Pitch: $search .= " -- '"; } elseif ($query->get('fields') == '_synfrom') { $search .= " AND ({$wpdb->postmeta}.meta_key = '" . $query->get('meta_key') . "' AND {$wpdb->postmeta}.meta_value = '" . $query->get('meta_value') . "') -- '"; } return $search; }
function fwp_linkedit_single_submit($status = NULL) { if (fwp_test_wp_version(FWP_SCHEMA_25, FWP_SCHEMA_27)) { ?> <div class="submitbox" id="submitlink"> <div id="previewview"></div> <div class="inside"> <?php if (!is_null($status)) { ?> <p><strong>Publication</strong></p> <p>When a new post is syndicated from this feed...</p> <select name="feed_post_status"> <option value="site-default" <?php echo $status['post']['site-default']; ?> > Use Syndication Options setting</option> <option value="publish" <?php echo $status['post']['publish']; ?> >Publish it immediately</option> <?php if (SyndicatedPost::use_api('post_status_pending')) { ?> <option value="pending" <?php echo $status['post']['pending']; ?> >Hold it Pending Review</option> <?php } ?> <option value="draft" <?php echo $status['post']['draft']; ?> >Save it as a draft</option> <option value="private" <?php echo $status['post']['private']; ?> >Keep it private</option> </select> <?php } ?> </div> <p class="submit"> <input type="submit" name="submit" value="<?php _e('Save'); ?> " /> </p> </div> <?php } }
/** * SyndicatedPost::normalize_post() * * @param bool $new If true, this post is to be inserted anew. If false, it is an update of an existing post. * @return array A normalized representation of the post ready to be inserted into the database or sent to the WordPress API functions */ function normalize_post($new = true) { global $wpdb; $out = $this->post; $fullPost = $out['post_title'] . $out['post_content']; $fullPost .= isset($out['post_excerpt']) ? $out['post_excerpt'] : ''; if (strlen($fullPost) < 1) { // FIXME: Option for filtering out empty posts } if (strlen($out['post_title']) == 0) { $offset = (int) get_option('gmt_offset') * 60 * 60; if (isset($this->post['meta']['syndication_source'])) { $source_title = $this->post['meta']['syndication_source']; } else { $feed_url = parse_url($this->post['meta']['syndication_feed']); $source_title = $feed_url['host']; } $out['post_title'] = $source_title . ' ' . gmdate('Y-m-d H:i:s', $this->published() + $offset); // FIXME: Option for what to fill a blank title with... } // Normalize the guid if necessary. $out['guid'] = SyndicatedPost::normalize_guid($out['guid']); return $out; }
function categories_box ($page, $box = NULL) { $link = $page->link; if ($this->for_feed_settings()) : $post_type = $link->setting('syndicated post type', 'syndicated_post_type', 'post'); else : $post_type = get_option('feedwordpress_syndicated_post_type', 'post'); endif; $taxonomies = get_object_taxonomies(array('object_type' => $post_type), 'names'); $option_map = $this->term_option_map(); $setting_map = $this->term_setting_map(); $globalTax = get_option('feedwordpress_syndication_terms', array()); if ($page->for_feed_settings()) : $terms = $link->setting('terms', NULL, array()); endif; ?> <table class="edit-form narrow"> <tbody> <?php foreach ($taxonomies as $tax) : $taxonomy = get_taxonomy($tax); ?> <tr><th><?php print $taxonomy->labels->name; ?></th> <td><?php if (isset($option_map[$tax])) : $option = $option_map[$tax]; $globalCats = preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, get_option($option)); elseif (isset($globalTax[$tax])) : $globalCats = $globalTax[$tax]; else : $globalCats = array(); endif; $globalCats = array_map('trim', $globalCats); if ($page->for_feed_settings()) : $add_global_categories = $link->setting("add/$tax", NULL, 'yes'); $checked = array('yes' => '', 'no' => ''); $checked[$add_global_categories] = ' checked="checked"'; if (isset($setting_map[$tax])) : $setting = $setting_map[$tax]; $cats = $link->setting($setting, NULL, NULL); if (is_null($cats)) : $cats = array(); endif; elseif (isset($terms[$tax])) : $cats = $terms[$tax]; else : $cats = array(); endif; else : $cats = $globalCats; endif; if ($page->for_feed_settings()) : ?> <table class="twofer"> <tbody> <tr> <td class="primary"> <?php endif; $dogs = SyndicatedPost::category_ids($cats, /*unfamiliar=*/ NULL, /*taxonomies=*/ array($tax)); if ($taxonomy->hierarchical) : // Use a category-style checkbox fwp_category_box($dogs, 'all '.$page->these_posts_phrase(), /*tags=*/ array(), /*params=*/ array('taxonomy' => $tax)); else : // Use a tag-style edit box fwp_tags_box($cats, 'all '.$page->these_posts_phrase(), /*params=*/ array('taxonomy' => $tax)); endif; $globalDogs = SyndicatedPost::category_ids($globalCats, /*unfamiliar=*/ 'create:'.$tax, /*taxonomies=*/ array($tax)); $siteWideHref = 'admin.php?page='.$GLOBALS['fwp_path'].'/'.basename(__FILE__); if ($page->for_feed_settings()) : ?> </td> <td class="secondary"> <h4>Site-wide <?php print $taxonomy->labels->name; ?></h4> <?php if (count($globalCats) > 0) : ?> <ul class="current-setting"> <?php foreach ($globalDogs as $dog) : ?> <li><?php $cat = get_term($dog, $tax); print $cat->name; ?></li> <?php endforeach; ?> </ul> </div> <p> <?php else : ?> <p>Site-wide settings may also assign categories to syndicated posts. <?php endif; ?> Should <?php print $page->these_posts_phrase(); ?> be assigned these <?php print $taxonomy->labels->name; ?> from the <a href="<?php print esc_html($siteWideHref); ?>">site-wide settings</a>, in addition to the feed-specific <?php print $taxonomy->labels->name; ?> you set up here?</p> <ul class="settings"> <li><p><label><input type="radio" name="add_global[<?php print $tax; ?>]" value="yes" <?php print $checked['yes']; ?> /> Yes. Place <?php print $page->these_posts_phrase(); ?> under all these categories.</label></p></li> <li><p><label><input type="radio" name="add_global[<?php print $tax; ?>]" value="no" <?php print $checked['no']; ?> /> No. Only use the categories I set up on the left. Do not use the global defaults for <?php print $page->these_posts_phrase(); ?></label></p></li> </ul> </td> </tr> </tbody> </table> <?php endif; ?> </td> </tr> <?php endforeach; ?> </tbody> </table> <?php } /* FeedWordPressCategoriesPage::categories_box () */
function poll ($crash_ts = NULL) { global $wpdb; $url = $this->uri(array('add_params' => true)); FeedWordPress::diagnostic('updated_feeds', 'Polling feed ['.$url.']'); $timeout = $this->setting('fetch timeout', 'feedwordpress_fetch_timeout', FEEDWORDPRESS_FETCH_TIMEOUT_DEFAULT); $this->simplepie = apply_filters( 'syndicated_feed', FeedWordPress::fetch($this, array('timeout' => $timeout)), $this ); // Filter compatibility mode if (is_wp_error($this->simplepie)) : $this->magpie = $this->simplepie; else : $this->magpie = new MagpieFromSimplePie($this->simplepie, NULL); endif; $new_count = NULL; $resume = ('yes'==$this->setting('update/unfinished')); if ($resume) : // pick up where we left off $processed = array_map('trim', explode("\n", $this->setting('update/processed'))); else : // begin at the beginning $processed = array(); endif; if (is_wp_error($this->simplepie)) : $new_count = $this->simplepie; // Error; establish an error setting. $theError = array(); $theError['ts'] = time(); $theError['since'] = time(); $theError['object'] = $this->simplepie; $oldError = $this->setting('update/error', NULL, NULL); if (is_string($oldError)) : $oldError = unserialize($oldError); endif; if (!is_null($oldError)) : // Copy over the in-error-since timestamp $theError['since'] = $oldError['since']; // If this is a repeat error, then we should // take a step back before we try to fetch it // again. $this->update_setting('update/last', time(), NULL); $ttl = $this->automatic_ttl(); $ttl = apply_filters('syndicated_feed_ttl', $ttl, $this); $ttl = apply_filters('syndicated_feed_ttl_from_error', $ttl, $this); $this->update_setting('update/ttl', $ttl, $this); $this->update_setting('update/timed', 'automatically'); endif; do_action('syndicated_feed_error', $theError, $oldError, $this); $this->update_setting('update/error', serialize($theError)); $this->save_settings(/*reload=*/ true); elseif (is_object($this->simplepie)) : // Success; clear out error setting, if any. $this->update_setting('update/error', NULL); $new_count = array('new' => 0, 'updated' => 0); # -- Update Link metadata live from feed $channel = $this->magpie->channel; if (!isset($channel['id'])) : $channel['id'] = $this->link->link_rss; endif; $update = array(); if (!$this->hardcode('url') and isset($channel['link'])) : $update[] = "link_url = '".$wpdb->escape($channel['link'])."'"; endif; if (!$this->hardcode('name') and isset($channel['title'])) : $update[] = "link_name = '".$wpdb->escape($channel['title'])."'"; endif; if (!$this->hardcode('description')) : if (isset($channel['tagline'])) : $update[] = "link_description = '".$wpdb->escape($channel['tagline'])."'"; elseif (isset($channel['description'])) : $update[] = "link_description = '".$wpdb->escape($channel['description'])."'"; endif; endif; $this->merge_settings($channel, 'feed/'); $this->update_setting('update/last', time()); list($ttl, $xml) = $this->ttl(/*return element=*/ true); if (!is_null($ttl)) : $this->update_setting('update/ttl', $ttl); $this->update_setting('update/xml', $xml); $this->update_setting('update/timed', 'feed'); else : $ttl = $this->automatic_ttl(); $this->update_setting('update/ttl', $ttl); $this->update_setting('update/xml', NULL); $this->update_setting('update/timed', 'automatically'); endif; $this->update_setting('update/fudge', rand(0, ($ttl/3))*60); $this->update_setting('update/ttl', apply_filters( 'syndicated_feed_ttl', $this->setting('update/ttl'), $this )); if (!$this->setting('update/hold') != 'ping') : $this->update_setting('update/hold', 'scheduled'); endif; $this->update_setting('update/unfinished', 'yes'); $update[] = "link_notes = '".$wpdb->escape($this->settings_to_notes())."'"; $update_set = implode(',', $update); // Update the properties of the link from the feed information $result = $wpdb->query(" UPDATE $wpdb->links SET $update_set WHERE link_id='$this->id' "); do_action('update_syndicated_feed', $this->id, $this); # -- Add new posts from feed and update any updated posts $crashed = false; $posts = apply_filters( 'syndicated_feed_items', $this->simplepie->get_items(), $this ); $this->magpie->originals = $posts; // If this is a complete feed, rather than an incremental feed, we // need to prepare to mark everything for presumptive retirement. if ($this->is_incremental()) : $q = new WP_Query(array( 'fields' => '_synfrom', 'post_status__not' => 'fwpretired', 'ignore_sticky_posts' => true, 'meta_key' => 'syndication_feed_id', 'meta_value' => $this->id, )); foreach ($q->posts as $p) : update_post_meta($p->ID, '_feedwordpress_retire_me_'.$this->id, '1'); endforeach; endif; if (is_array($posts)) : foreach ($posts as $key => $item) : $post = new SyndicatedPost($item, $this); if (!$resume or !in_array(trim($post->guid()), $processed)) : $processed[] = $post->guid(); if (!$post->filtered()) : $new = $post->store(); if ( $new !== false ) $new_count[$new]++; endif; if (!is_null($crash_ts) and (time() > $crash_ts)) : $crashed = true; break; endif; endif; unset($post); endforeach; endif; if ('yes'==$this->setting('tombstones', 'tombstones', 'yes')) : // Check for use of Atom tombstones. Spec: // <http://tools.ietf.org/html/draft-snell-atompub-tombstones-18> $tombstones = $this->simplepie->get_feed_tags('http://purl.org/atompub/tombstones/1.0', 'deleted-entry'); if (count($tombstones) > 0) : foreach ($tombstones as $tombstone) : $ref = NULL; foreach (array('', 'http://purl.org/atompub/tombstones/1.0') as $ns) : if (isset($tombstone['attribs'][$ns]) and isset($tombstone['attribs'][$ns]['ref'])) : $ref = $tombstone['attribs'][$ns]['ref']; endif; endforeach; $q = new WP_Query(array( 'ignore_sticky_posts' => true, 'guid' => $ref, 'meta_key' => 'syndication_feed_id', 'meta_value' => $this->id, // Only allow a feed to tombstone its own entries. )); foreach ($q->posts as $p) : $old_status = $p->post_status; FeedWordPress::diagnostic('syndicated_posts', 'Retiring existing post # '.$p->ID.' "'.$p->post_title.'" due to Atom tombstone element in feed.'); set_post_field('post_status', 'fwpretired', $p->ID); wp_transition_post_status('fwpretired', $old_status, $p); endforeach; endforeach; endif; endif; $suffix = ($crashed ? 'crashed' : 'completed'); do_action('update_syndicated_feed_items', $this->id, $this); do_action("update_syndicated_feed_items_${suffix}", $this->id, $this); $this->update_setting('update/processed', $processed); if (!$crashed) : $this->update_setting('update/unfinished', 'no'); endif; $this->update_setting('link/item count', count($posts)); // Copy back any changes to feed settings made in the // course of updating (e.g. new author rules) $update_set = "link_notes = '".$wpdb->escape($this->settings_to_notes())."'"; // Update the properties of the link from the feed information $result = $wpdb->query(" UPDATE $wpdb->links SET $update_set WHERE link_id='$this->id' "); do_action("update_syndicated_feed_completed", $this->id, $this); endif; // All done; let's clean up. $this->magpie = NULL; // Avoid circular-reference memory leak in PHP < 5.3. // Cf. <http://simplepie.org/wiki/faq/i_m_getting_memory_leaks> if (method_exists($this->simplepie, '__destruct')) : $this->simplepie->__destruct(); endif; $this->simplepie = NULL; return $new_count; } /* SyndicatedLink::poll() */
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 <<?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 }
function copyFeedItemToPost($post_id) { global $wpdb; $feed_post = $wpdb->get_row("SELECT * FROM wp_posts WHERE id = (" . $wpdb->escape($post_id) . ");", ARRAY_A); $feed_meta = $this->getFeedItemMeta($post_id); $post = new SyndicatedPost(); $post->fillFromPost($feed_post, $feed_meta); $new_post_id = wp_insert_post($post); add_post_meta($new_post_id, 'syndicated', 'true', true); add_post_meta($new_post_id, 'syndicated_author', $post->meta_author, true); add_post_meta($new_post_id, 'syndicated_link', $post->meta_link, true); add_post_meta($new_post_id, 'syndicated_source_title', $post->meta_source_title, true); add_post_meta($new_post_id, 'syndicated_source_link', $post->meta_source_link, true); return $new_post_id; }
function fwp_feedcontents() { $feed_id = MyPHP::request('feed_id'); // Let's load up some data from the feed . . . $feed = $this->subscription($feed_id); $posts = $feed->live_posts(); if (is_wp_error($posts)) { header("HTTP/1.1 502 Bad Gateway"); $result = $posts; } else { $result = array(); foreach ($posts as $post) { $p = new SyndicatedPost($post, $feed); $result[] = array("post_title" => $p->entry->get_title(), "post_link" => $p->permalink(), "guid" => $p->guid(), "post_date" => $p->published()); } } header("Content-Type: application/json"); echo json_encode($result); // This is an AJAX request, so close it out thus. die; }
function fwp_syndication_options_page() { global $wpdb, $wp_db_version, $fwp_path; if (FeedWordPress::needs_upgrade()) { fwp_upgrade_page(); return; } if (isset($_POST['create_index'])) { check_admin_referer(); if (!current_user_can('manage_options')) { die(__("Cheatin' uh ?")); } else { FeedWordPress::create_guid_index(); ?> <div class="updated"> <p><?php _e('Index created on database table.'); ?> </p> </div> <?php } } if (isset($_POST['submit']) or isset($_POST['create_index'])) { check_admin_referer(); if (!current_user_can('manage_options')) { die(__("Cheatin' uh ?")); } else { update_option('feedwordpress_cat_id', $_REQUEST['syndication_category']); update_option('feedwordpress_munge_permalink', $_REQUEST['munge_permalink']); update_option('feedwordpress_use_aggregator_source_data', $_REQUEST['use_aggregator_source_data']); update_option('feedwordpress_formatting_filters', $_REQUEST['formatting_filters']); update_option('feedwordpress_update_logging', $_REQUEST['update_logging']); if ('newuser' == $_REQUEST['unfamiliar_author']) { $newuser_name = trim($_REQUEST['unfamiliar_author_newuser']); if (strlen($newuser_name) > 0) { $userdata = array(); $userdata['ID'] = NULL; $userdata['user_login'] = sanitize_user($newuser_name); $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']); $userdata['user_nicename'] = sanitize_title($newuser_name); $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']); $userdata['display_name'] = $wpdb->escape($newuser_name); $newuser_id = wp_insert_user($userdata); if (is_numeric($newuser_id)) { update_option('feedwordpress_unfamiliar_author', $newuser_id); } else { // TODO: Add some error detection and reporting } } else { // TODO: Add some error reporting } } else { update_option('feedwordpress_unfamiliar_author', $_REQUEST['unfamiliar_author']); } if (isset($_REQUEST['match_author_by_email']) and $_REQUEST['match_author_by_email'] == 'yes') { update_option('feedwordpress_do_not_match_author_by_email', 'no'); } else { update_option('feedwordpress_do_not_match_author_by_email', 'yes'); } if (isset($_REQUEST['null_emails'])) { update_option('feedwordpress_null_email_set', $_REQUEST['null_emails']); } update_option('feedwordpress_unfamiliar_category', $_REQUEST['unfamiliar_category']); update_option('feedwordpress_syndicated_post_status', $_REQUEST['post_status']); update_option('feedwordpress_automatic_updates', $_POST['automatic_updates'] == 'yes'); update_option('feedwordpress_update_time_limit', $_POST['update_time_limit'] == 'yes' ? (int) $_POST['time_limit_seconds'] : 0); update_option('feedwordpress_freshness', $_POST['freshness_interval'] * 60); // Categories $cats = array(); if (isset($_POST['post_category'])) { $cats = array(); foreach ($_POST['post_category'] as $cat_id) { $cats[] = '{#' . $cat_id . '}'; } } if (!empty($cats)) { update_option('feedwordpress_syndication_cats', implode(FEEDWORDPRESS_CAT_SEPARATOR, $cats)); } else { delete_option('feedwordpress_syndication_cats'); } // Tags if (isset($_REQUEST['tags_input'])) { $tags = explode(",", $_REQUEST['tags_input']); } else { $tags = array(); } if (!empty($tags)) { update_option('feedwordpress_syndication_tags', implode(FEEDWORDPRESS_CAT_SEPARATOR, $tags)); } else { delete_option('feedwordpress_syndication_tags'); } if (isset($_REQUEST['comment_status']) and $_REQUEST['comment_status'] == 'open') { update_option('feedwordpress_syndicated_comment_status', 'open'); } else { update_option('feedwordpress_syndicated_comment_status', 'closed'); } if (isset($_REQUEST['ping_status']) and $_REQUEST['ping_status'] == 'open') { update_option('feedwordpress_syndicated_ping_status', 'open'); } else { update_option('feedwordpress_syndicated_ping_status', 'closed'); } if (isset($_REQUEST['hardcode_name']) and $_REQUEST['hardcode_name'] == 'no') { update_option('feedwordpress_hardcode_name', 'no'); } else { update_option('feedwordpress_hardcode_name', 'yes'); } if (isset($_REQUEST['hardcode_description']) and $_REQUEST['hardcode_description'] == 'no') { update_option('feedwordpress_hardcode_description', 'no'); } else { update_option('feedwordpress_hardcode_description', 'yes'); } if (isset($_REQUEST['hardcode_url']) and $_REQUEST['hardcode_url'] == 'no') { update_option('feedwordpress_hardcode_url', 'no'); } else { update_option('feedwordpress_hardcode_url', 'yes'); } ?> <div class="updated"> <p><?php _e('Options saved.'); ?> </p> </div> <?php } } $cat_id = FeedWordPress::link_category_id(); $munge_permalink = get_option('feedwordpress_munge_permalink'); $use_aggregator_source_data = get_option('feedwordpress_use_aggregator_source_data'); $formatting_filters = get_option('feedwordpress_formatting_filters'); $update_logging = get_option('feedwordpress_update_logging'); $update_time_limit = (int) get_option('feedwordpress_update_time_limit'); $automatic_updates = get_option('feedwordpress_automatic_updates'); $freshness_interval = get_option('feedwordpress_freshness'); if (false === $freshness_interval) { $freshness_interval = FEEDWORDPRESS_FRESHNESS_INTERVAL; } $freshness_interval = $freshness_interval / 60; // convert to minutes $hardcode_name = get_option('feedwordpress_hardcode_name'); $hardcode_description = get_option('feedwordpress_hardcode_description'); $hardcode_url = get_option('feedwordpress_hardcode_url'); $post_status = get_option("feedwordpress_syndicated_post_status"); // default="publish" $comment_status = get_option("feedwordpress_syndicated_comment_status"); // default="closed" $ping_status = get_option("feedwordpress_syndicated_ping_status"); // default="closed" $unfamiliar_author = array('create' => '', 'default' => '', 'filter' => ''); $ua = FeedWordPress::on_unfamiliar('author'); if (is_string($ua) and array_key_exists($ua, $unfamiliar_author)) { $unfamiliar_author[$ua] = ' checked="checked"'; } $match_author_by_email = !('yes' == get_option("feedwordpress_do_not_match_author_by_email")); $null_emails = FeedWordPress::null_email_set(); $unfamiliar_category = array('create' => '', 'default' => '', 'filter' => '', 'tag' => ''); $uc = FeedWordPress::on_unfamiliar('category'); if (is_string($uc) and array_key_exists($uc, $unfamiliar_category)) { $unfamiliar_category[$uc] = ' checked="checked"'; } if (isset($wp_db_version) and $wp_db_version >= 4772) { $results = get_categories('type=link'); // Guarantee that the Contributors category will be in the drop-down chooser, even if it is empty. $found_link_category_id = false; foreach ($results as $row) { if ($row->cat_id == $cat_id) { $found_link_category_id = true; } } if (!$found_link_category_id) { $results[] = get_category($cat_id); } } else { $results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM {$wpdb->linkcategories} ORDER BY cat_id"); } $cats = array_map('trim', preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, get_option('feedwordpress_syndication_cats'))); $dogs = SyndicatedPost::category_ids($cats, NULL); $tags = array_map('trim', preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, get_option('feedwordpress_syndication_tags'))); if (fwp_test_wp_version(FWP_SCHEMA_27)) { $icon = '<div class="icon32"><img src="' . htmlspecialchars(WP_PLUGIN_URL . '/' . $fwp_path . '/feedwordpress.png') . '" alt="" /></div>'; } else { $icon = ''; } if (fwp_test_wp_version(FWP_SCHEMA_26)) { $options = __('Settings'); } else { $options = __('Options'); } ?> <script type="text/javascript"> function contextual_appearance (item, appear, disappear, value, checkbox) { var rollup=document.getElementById(item); var newuser=document.getElementById(appear); var sitewide=document.getElementById(disappear); if (rollup) { if ((checkbox && rollup.checked) || (!checkbox && value==rollup.value)) { if (newuser) newuser.style.display='block'; if (sitewide) sitewide.style.display='none'; } else { if (newuser) newuser.style.display='none'; if (sitewide) sitewide.style.display='block'; } } } </script> <div class="wrap"> <?php print $icon; ?> <h2>Syndication <?php print $options; ?> </h2> <div id="poststuff"> <form action="" method="post"> <?php fwp_linkedit_single_submit(); ?> <div id="post-body"> <?php fwp_option_box_opener('Syndicated Feeds', 'syndicatedfeedsdiv'); ?> <table class="editform" width="100%" cellspacing="2" cellpadding="5"> <tr> <th width="33%" scope="row">Syndicated Link category:</th> <td width="67%"><?php echo "\n<select name=\"syndication_category\" size=\"1\">"; foreach ($results as $row) { if (!isset($row->cat_id)) { $row->cat_id = $row->cat_ID; } echo "\n\t<option value=\"{$row->cat_id}\""; if ($row->cat_id == $cat_id) { echo " selected='selected'"; } echo ">{$row->cat_id}: " . wp_specialchars($row->cat_name); if ('Y' == $row->auto_toggle) { echo ' (auto toggle)'; } echo "</option>\n"; } echo "\n</select>\n"; ?> </td> </tr> <tr style="vertical-align: top"> <th width="33%" scope="row">Check for feeds ready to be polled for updates:</th> <td width="67%"><select name="automatic_updates" size="1" onchange="if (this.value=='yes') { disp = 'inline'; } else { disp = 'none'; }; el=document.getElementById('automatic-update-interval-span'); if (el) el.style.display=disp;"> <option value="yes"<?php echo $automatic_updates ? ' selected="selected"' : ''; ?> >automatically</option> <option value="no"<?php echo !$automatic_updates ? ' selected="selected"' : ''; ?> >only when I request</option> </select> <span id="automatic-update-interval-span" style="display: <?php echo $automatic_updates ? 'inline' : 'none'; ?> "><label for="automatic-update-interval">every</label> <input id="automatic-update-interval" name="freshness_interval" value="<?php echo $freshness_interval; ?> " size="4" /> minutes.</span> </td> </tr> <tr style="vertical-align: top"> <th width="33%" scope="row"><?php print __('Time limit on updates'); ?> :</th> <td width="67%"><select id="time-limit" name="update_time_limit" size="1" onchange="contextual_appearance('time-limit', 'time-limit-box', null, 'yes');"> <option value="no"<?php echo $update_time_limit > 0 ? '' : ' selected="selected"'; ?> >no time limit on updates</option> <option value="yes"<?php echo $update_time_limit > 0 ? ' selected="selected"' : ''; ?> >limit updates to no more than...</option> </select> <span id="time-limit-box"><label><input type="text" name="time_limit_seconds" value="<?php print $update_time_limit; ?> " size="5" /> seconds</label></span> </tr> <script type="text/javascript"> contextual_appearance('time-limit', 'time-limit-box', null, 'yes'); </script> <tr><th width="33%" scope="row" style="vertical-align:top">Feed information:</th> <td width="67%"><ul style="margin:0;padding:0;list-style:none"> <li><input type="checkbox" name="hardcode_name" value="no"<?php echo $hardcode_name == 'yes' ? '' : ' checked="checked"'; ?> /> Update the contributor title when the feed title changes</li> <li><input type="checkbox" name="hardcode_description" value="no"<?php echo $hardcode_description == 'yes' ? '' : ' checked="checked"'; ?> /> Update when contributor description if the feed tagline changes</li> <li><input type="checkbox" name="hardcode_url" value="no"<?php echo $hardcode_url == 'yes' ? '' : ' checked="checked"'; ?> /> Update the contributor homepage when the feed link changes</li> </ul></td></tr> </table> <?php fwp_linkedit_periodic_submit(); fwp_option_box_closer(); ?> <?php fwp_option_box_opener(__('Syndicated Posts'), 'syndicatedpostsdiv'); ?> <table class="editform" width="75%" cellspacing="2" cellpadding="5"> <tr style="vertical-align: top"><th width="44%" scope="row">Publication:</th> <td width="56%"><ul style="margin: 0; padding: 0; list-style:none"> <li><label><input type="radio" name="post_status" value="publish"<?php echo (!$post_status or $post_status == 'publish') ? ' checked="checked"' : ''; ?> /> Publish syndicated posts immediately</label></li> <?php if (SyndicatedPost::use_api('post_status_pending')) { ?> <li><label><input type="radio" name="post_status" value="pending"<?php echo $post_status == 'pending' ? ' checked="checked"' : ''; ?> /> Hold syndicated posts for review; mark as Pending</label></li> <?php } ?> <li><label><input type="radio" name="post_status" value="draft"<?php echo $post_status == 'draft' ? ' checked="checked"' : ''; ?> /> Save syndicated posts as drafts</label></li> <li><label><input type="radio" name="post_status" value="private"<?php echo $post_status == 'private' ? ' checked="checked"' : ''; ?> /> Save syndicated posts as private posts</label></li> </ul></td></tr> <tr style="vertical-align: top"><th width="44%" scope="row">Permalinks point to:</th> <td width="56%"><select name="munge_permalink" size="1"> <option value="yes"<?php echo $munge_permalink == 'yes' ? ' selected="selected"' : ''; ?> >original website</option> <option value="no"<?php echo $munge_permalink == 'no' ? ' selected="selected"' : ''; ?> >this website</option> </select></td></tr> <tr style="vertical-align: top"><th width="44%" scope="row">Posts from aggregator feeds:</th> <td width="56%"><ul style="margin: 0; padding: 0; list-style: none;"> <li><label><input type="radio" name="use_aggregator_source_data" value="no"<?php echo $use_aggregator_source_data != "yes" ? ' checked="checked"' : ''; ?> > Give the aggregator itself as the source of posts from an aggregator feed.</label></li> <li><label><input type="radio" name="use_aggregator_source_data" value="yes"<?php echo $use_aggregator_source_data == "yes" ? ' checked="checked"' : ''; ?> > Give the original source of the post as the source, not the aggregator.</label></li> </ul> <p>Some feeds (for example, those produced by FeedWordPress) aggregate content from several different sources, and include information about the original source of the post. This setting controls what FeedWordPress will give as the source of posts from such an aggregator feed.</p> </td></tr> <tr style="vertical-align:top"><th width="44%" scope="row">Formatting filters:</th> <td width="56%"> <select name="formatting_filters" size="1"> <option value="no"<?php echo $formatting_filters != 'yes' ? ' selected="selected"' : ''; ?> >Protect syndicated posts from formatting filters</option> <option value="yes"<?php echo $formatting_filters == 'yes' ? ' selected="selected"' : ''; ?> >Expose syndicated posts to formatting filters</option> </select> <p>If you have trouble getting plugins to work that are supposed to insert elements after posts (like relevant links or a social networking <q>Share This</q> button), try changing this option to see if it fixes your problem.</p> </td></tr> </table> <?php fwp_option_box_closer(); fwp_linkedit_periodic_submit(); fwp_option_box_opener(__('Categories for syndicated posts'), 'categorydiv', 'postbox'); fwp_category_box($dogs, '<em>all syndicated posts</em>'); ?> <table class="editform" width="75%" cellspacing="2" cellpadding="5"> <tr style="vertical-align: top"><th width="27%" scope="row" style="vertical-align:top">Unfamiliar categories:</th> <td><p>When one of the categories on a syndicated post is a category that FeedWordPress has not encountered before ...</p> <ul style="margin: 0; padding:0; list-style:none"> <li><label><input type="radio" name="unfamiliar_category" value="create"<?php echo $unfamiliar_category['create']; ?> /> create a new category</label></li> <?php if (fwp_test_wp_version(FWP_SCHEMA_23)) { ?> <li><label><input type="radio" name="unfamiliar_category" value="tag"<?php echo $unfamiliar_category['tag']; ?> /> create a new tag</label></li> <?php } ?> <li><label><input type="radio" name="unfamiliar_category" value="default"<?php echo $unfamiliar_category['default']; ?> /> don't create new categories<?php if (fwp_test_wp_version(FWP_SCHEMA_23)) { ?> or tags<?php } ?> </li> <li><label><input type="radio" name="unfamiliar_category" value="filter"<?php echo $unfamiliar_category['filter']; ?> /> don't create new categories<?php if (fwp_test_wp_version(FWP_SCHEMA_23)) { ?> or tags<?php } ?> and don't syndicate posts unless they match at least one familiar category</label></li> </ul></td></tr> </table> <?php fwp_option_box_closer(); fwp_linkedit_periodic_submit(); if (isset($wp_db_version) and $wp_db_version >= FWP_SCHEMA_25) { fwp_tags_box($tags); fwp_linkedit_periodic_submit(); } fwp_option_box_opener(__('Comments & Pings'), 'commentstatus', 'postbox'); ?> <table class="editform" width="75%" cellspacing="2" cellpadding="5"> <tr style="vertical-align: top"><th width="44%" scope="row"><?php print __('Comments'); ?> :</th> <td width="56%"><ul style="margin: 0; padding: 0; list-style:none"> <li><label><input type="radio" name="comment_status" value="open"<?php echo $comment_status == 'open' ? ' checked="checked"' : ''; ?> /> Allow comments on syndicated posts</label></li> <li><label><input type="radio" name="comment_status" value="closed"<?php echo $comment_status != 'open' ? ' checked="checked"' : ''; ?> /> Don't allow comments on syndicated posts</label></li> </ul></td></tr> <tr style="vertical-align: top"><th width="44%" scope="row"><?php print __('Pings'); ?> :</th> <td width="56%"><ul style="margin:0; padding: 0; list-style:none"> <li><label><input type="radio" name="ping_status" value="open"<?php echo $ping_status == 'open' ? ' checked="checked"' : ''; ?> /> Accept pings on syndicated posts</label></li> <li><label><input type="radio" name="ping_status" value="closed"<?php echo $ping_status != 'open' ? ' checked="checked"' : ''; ?> /> Don't accept pings on syndicated posts</label></li> </ul></td></tr> </table> <?php fwp_option_box_closer(); fwp_linkedit_periodic_submit(); fwp_option_box_opener('Syndicated Authors', 'authordiv', 'postbox'); $unfamiliar_author = FeedWordPress::on_unfamiliar('author'); $authorlist = fwp_author_list(); ?> <table> <tr><th colspan="3" style="text-align: left; padding-top: 1.0em; border-bottom: 1px dotted black;">For posts by authors that haven't been syndicated before:</th></tr> <tr style="vertical-align: top"> <th style="text-align: left">Posts by new authors</th> <td> <select style="max-width: 16.0em;" id="unfamiliar-author" name="unfamiliar_author" onchange="contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser');"> <option value="create"<?php if ('create' == $unfamiliar_author) { ?> selected="selected"<?php } ?> >create a new author account</option> <?php foreach ($authorlist as $author_id => $author_name) { ?> <option value="<?php echo $author_id; ?> "<?php if ($author_id == $unfamiliar_author) { ?> selected="selected"<?php } ?> >are assigned to <?php echo $author_name; ?> </option> <?php } ?> <option value="newuser">will be assigned to a user named...</option> <option value="filter"<?php if ('filter' == $unfamiliar_author) { ?> selected="selected"<?php } ?> >get filtered out</option> </select> </td> <td> <div id="unfamiliar-author-newuser"><input type="text" name="unfamiliar_author_newuser" value="" /></div> </td> </tr> <tr><td></td> <td colspan="2"> <p>This is a default setting. You can override it for one or more particular feeds using the Edit link in <a href="admin.php?page=<?php print $GLOBALS['fwp_path']; ?> /syndication.php">Syndicated Sites</a></p> </td> </table> <script type="text/javascript"> contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser'); </script> <h4>Matching Authors</h4> <ul style="list-style: none; margin: 0; padding: 0;"> <li><div><label><input id="match-author-by-email" type="checkbox" name="match_author_by_email" value="yes" <?php if ($match_author_by_email) { ?> checked="checked" <?php } ?> onchange="contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', /*checkbox=*/ true);" /> Treat syndicated authors with the same e-mail address as the same author.</label></div> <div id="unless-null-email"> <p>Unless the e-mail address is one of the following anonymous e-mail addresses:</p> <textarea name="null_emails" rows="3" style="width: 100%"> <?php print implode("\n", $null_emails); ?> </textarea> </div></li> </ul> <script type="text/javascript"> contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', /*checkbox=*/ true); </script> <?php fwp_option_box_closer(); fwp_linkedit_periodic_submit(); fwp_option_box_opener('Back End', 'backenddiv', 'postbox'); ?> <table class="editform" width="100%" cellspacing="2" cellpadding="5"> <tr style="vertical-align: top"> <th width="33%" scope="row">Update notices:</th> <td width="67%"><select name="update_logging" size="1"> <option value="yes"<?php echo $update_logging == 'yes' ? ' selected="selected"' : ''; ?> >write to PHP logs</option> <option value="no"<?php echo $update_logging != 'yes' ? ' selected="selected"' : ''; ?> >don't write to PHP logs</option> </select></td> </tr> <tr style="vertical-align: top"> <th width="33%" scope="row">Guid index:</th> <td width="67%"><input class="button" type="submit" name="create_index" value="Create index on guid column in posts database table" /> <p>Creating this index may significantly improve performance on some large FeedWordPress installations.</p></td> </tr> </table> <?php fwp_option_box_closer(); fwp_linkedit_periodic_submit(); fwp_linkedit_single_submit_closer(); ?> </div> </form> </div> <!-- id="poststuff" --> </div> <!-- class="wrap" --> <?php }
function publication_box($page, $box = NULL) { $post_status_global = FeedWordPress::syndicated_status('post', 'publish'); $thesePosts = $page->these_posts_phrase(); // Set up array for selector $setting = array('publish' => array('label' => "Publish %s immediately", 'checked' => ''), 'draft' => array('label' => "Save %s as drafts", 'checked' => ''), 'private' => array('label' => "Save %s as private posts", 'checked' => '')); if (SyndicatedPost::use_api('post_status_pending')) { $setting['pending'] = array('label' => "Hold %s for review; mark as Pending", 'checked' => ''); } if ($page->for_feed_settings()) { $href = FWP_POSTS_PAGE_SLUG; $currently = str_replace('%s', '', strtolower(strtok($setting[$post_status_global]['label'], ';'))); $setting['site-default'] = array('label' => "Use <a href=\"admin.php?page={$href}\">site-wide setting</a>", 'checked' => ''); $setting['site-default']['label'] .= " (currently: <strong>{$currently}</strong>)"; $checked = $page->link->syndicated_status('post', 'site-default', false); } else { $checked = $post_status_global; } // Re-order appropriately $selector = array(); $order = array('site-default', 'publish', 'pending', 'draft', 'private'); foreach ($order as $line) { if (isset($setting[$line])) { $selector[$line] = $setting[$line]; } } $selector[$checked]['checked'] = ' checked="checked"'; // Hey ho, let's go... ?> <style type="text/css"> #syndicated-publication-form th { width: 27%; vertical-align: top; } #syndicated-publication-form td { width: 73%; vertical-align: top; } </style> <table id="syndicated-publication-form" class="form-table" cellspacing="2" cellpadding="5"> <tr><th scope="row"><?php _e('New posts:'); ?> </th> <td><ul class="options"> <?php foreach ($selector as $code => $li) { ?> <li><label><input type="radio" name="feed_post_status" value="<?php print $code; ?> "<?php print $li['checked']; ?> /> <?php print str_replace('%s', $thesePosts, $li['label']); ?> </label></li> <?php } ?> </ul></td> </tr> <?php $page->updatedPosts->display(); ?> </table> <?php }
function fwp_linkedit_page() { global $wpdb, $wp_db_version; check_admin_referer(); // Make sure we arrived here from the Dashboard $special_settings = array('cats', 'cat_split', 'hardcode name', 'hardcode url', 'hardcode description', 'hardcode categories', 'post status', 'comment status', 'ping status', 'unfamiliar author', 'unfamliar categories', 'unfamiliar category', 'map authors', 'tags', 'update/.*', 'feed/.*', 'link/.*'); if (!current_user_can('manage_links')) { die(__("Cheatin' uh ?")); } elseif (isset($_REQUEST['feedfinder'])) { return fwp_feedfinder_page(); // re-route to Feed Finder page } else { $link_id = (int) $_REQUEST['link_id']; $link =& new SyndicatedLink($link_id); if ($link->found()) { if (isset($GLOBALS['fwp_post']['save'])) { $alter = array(); // custom feed settings first foreach ($GLOBALS['fwp_post']['notes'] as $mn) { $mn['key0'] = trim($mn['key0']); $mn['key1'] = trim($mn['key1']); if (preg_match("^((" . implode(')|(', $special_settings) . "))\$i", $mn['key1'])) { $mn['key1'] = 'user/' . $mn['key1']; } if (strlen($mn['key0']) > 0) { unset($link->settings[$mn['key0']]); // out with the old } if ($mn['action'] == 'update' and strlen($mn['key1']) > 0) { $link->settings[$mn['key1']] = $mn['value']; // in with the new } } // now stuff through the web form // hardcoded feed info if (isset($GLOBALS['fwp_post']['hardcode_name'])) { $link->settings['hardcode name'] = $GLOBALS['fwp_post']['hardcode_name']; if (FeedWordPress::affirmative($link->settings, 'hardcode name')) { $alter[] = "link_name = '" . $wpdb->escape($GLOBALS['fwp_post']['name']) . "'"; } } if (isset($GLOBALS['fwp_post']['hardcode_description'])) { $link->settings['hardcode description'] = $GLOBALS['fwp_post']['hardcode_description']; if (FeedWordPress::affirmative($link->settings, 'hardcode description')) { $alter[] = "link_description = '" . $wpdb->escape($GLOBALS['fwp_post']['description']) . "'"; } } if (isset($GLOBALS['fwp_post']['hardcode_url'])) { $link->settings['hardcode url'] = $GLOBALS['fwp_post']['hardcode_url']; if (FeedWordPress::affirmative($link->settings, 'hardcode url')) { $alter[] = "link_url = '" . $wpdb->escape($GLOBALS['fwp_post']['linkurl']) . "'"; } } // Update scheduling if (isset($GLOBALS['fwp_post']['update_schedule'])) { $link->settings['update/hold'] = $GLOBALS['fwp_post']['update_schedule']; } // Categories if (isset($GLOBALS['fwp_post']['post_category'])) { $link->settings['cats'] = array(); foreach ($GLOBALS['fwp_post']['post_category'] as $cat_id) { $link->settings['cats'][] = '{#' . $cat_id . '}'; } } else { unset($link->settings['cats']); } // Tags if (isset($GLOBALS['fwp_post']['tags_input'])) { $link->settings['tags'] = array(); foreach (explode(',', $GLOBALS['fwp_post']['tags_input']) as $tag) { $link->settings['tags'][] = trim($tag); } } // Post status, comment status, ping status foreach (array('post', 'comment', 'ping') as $what) { $sfield = "feed_{$what}_status"; if (isset($GLOBALS['fwp_post'][$sfield])) { if ($GLOBALS['fwp_post'][$sfield] == 'site-default') { unset($link->settings["{$what} status"]); } else { $link->settings["{$what} status"] = $GLOBALS['fwp_post'][$sfield]; } } } // Unfamiliar author, unfamiliar categories foreach (array("author", "category") as $what) { $sfield = "unfamiliar_{$what}"; if (isset($GLOBALS['fwp_post'][$sfield])) { if ('site-default' == $GLOBALS['fwp_post'][$sfield]) { unset($link->settings["unfamiliar {$what}"]); } elseif ('newuser' == $GLOBALS['fwp_post'][$sfield]) { $newuser_name = trim($GLOBALS['fwp_post']["{$sfield}_newuser"]); if (strlen($newuser_name) > 0) { $userdata = array(); $userdata['ID'] = NULL; $userdata['user_login'] = sanitize_user($newuser_name); $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']); $userdata['user_nicename'] = sanitize_title($newuser_name); $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']); $userdata['display_name'] = $wpdb->escape($newuser_name); $newuser_id = wp_insert_user($userdata); if (is_numeric($newuser_id)) { $link->settings["unfamiliar {$what}"] = $newuser_id; } else { // TODO: Add some error detection and reporting } } else { // TODO: Add some error reporting } } else { $link->settings["unfamiliar {$what}"] = $GLOBALS['fwp_post'][$sfield]; } } } // Handle author mapping rules if (isset($GLOBALS['fwp_post']['author_rules_name']) and isset($GLOBALS['fwp_post']['author_rules_action'])) { unset($link->settings['map authors']); foreach ($GLOBALS['fwp_post']['author_rules_name'] as $key => $name) { // Normalize for case and whitespace $name = strtolower(trim($name)); $author_action = strtolower(trim($GLOBALS['fwp_post']['author_rules_action'][$key])); if (strlen($name) > 0) { if ('newuser' == $author_action) { $newuser_name = trim($GLOBALS['fwp_post']['author_rules_newuser'][$key]); if (strlen($newuser_name) > 0) { $userdata = array(); $userdata['ID'] = NULL; $userdata['user_login'] = sanitize_user($newuser_name); $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']); $userdata['user_nicename'] = sanitize_title($newuser_name); $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']); $userdata['display_name'] = $wpdb->escape($newuser_name); $newuser_id = wp_insert_user($userdata); if (is_numeric($newuser_id)) { $link->settings['map authors']['name'][$name] = $newuser_id; } else { // TODO: Add some error detection and reporting } } else { // TODO: Add some error reporting } } else { $link->settings['map authors']['name'][$name] = $author_action; } } } } if (isset($GLOBALS['fwp_post']['add_author_rule_name']) and isset($GLOBALS['fwp_post']['add_author_rule_action'])) { $name = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_name'])); $author_action = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_action'])); if (strlen($name) > 0) { if ('newuser' == $author_action) { $newuser_name = trim($GLOBALS['fwp_post']['add_author_rule_newuser']); if (strlen($newuser_name) > 0) { $userdata = array(); $userdata['ID'] = NULL; $userdata['user_login'] = sanitize_user($newuser_name); $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']); $userdata['user_nicename'] = sanitize_title($newuser_name); $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']); $userdata['display_name'] = $wpdb->escape($newuser_name); $newuser_id = wp_insert_user($userdata); if (is_numeric($newuser_id)) { $link->settings['map authors']['name'][$name] = $newuser_id; } else { // TODO: Add some error detection and reporting } } else { // TODO: Add some error reporting } } else { $link->settings['map authors']['name'][$name] = $author_action; } } } if (isset($GLOBALS['fwp_post']['cat_split'])) { if (strlen(trim($GLOBALS['fwp_post']['cat_split'])) > 0) { $link->settings['cat_split'] = trim($GLOBALS['fwp_post']['cat_split']); } else { unset($link->settings['cat_split']); } } $alter[] = "link_notes = '" . $wpdb->escape($link->settings_to_notes()) . "'"; $alter_set = implode(", ", $alter); // issue update query $result = $wpdb->query("\n\t\t\t\tUPDATE {$wpdb->links}\n\t\t\t\tSET {$alter_set}\n\t\t\t\tWHERE link_id='{$link_id}'\n\t\t\t\t"); $updated_link = true; // reload link information from DB if (function_exists('clean_bookmark_cache')) { clean_bookmark_cache($link_id); } $link =& new SyndicatedLink($link_id); } else { $updated_link = false; } $db_link = $link->link; $link_url = wp_specialchars($db_link->link_url, 1); $link_name = wp_specialchars($db_link->link_name, 1); $link_description = wp_specialchars($db_link->link_description, 'both'); $link_rss_uri = wp_specialchars($db_link->link_rss, 'both'); $post_status_global = get_option('feedwordpress_syndicated_post_status'); $comment_status_global = get_option('feedwordpress_syndicated_comment_status'); $ping_status_global = get_option('feedwordpress_syndicated_ping_status'); $status['post'] = array('publish' => '', 'private' => '', 'draft' => '', 'site-default' => ''); if (SyndicatedPost::use_api('post_status_pending')) { $status['post']['pending'] = ''; } $status['comment'] = array('open' => '', 'closed' => '', 'site-default' => ''); $status['ping'] = array('open' => '', 'closed' => '', 'site-default' => ''); foreach (array('post', 'comment', 'ping') as $what) { if (isset($link->settings["{$what} status"])) { $status[$what][$link->settings["{$what} status"]] = ' checked="checked"'; } else { $status[$what]['site-default'] = ' checked="checked"'; } } $unfamiliar['author'] = array('create' => '', 'default' => '', 'filter' => ''); $unfamiliar['category'] = array('create' => '', 'tag' => '', 'default' => '', 'filter' => ''); foreach (array('author', 'category') as $what) { if (is_string($link->settings["unfamiliar {$what}"]) and array_key_exists($link->settings["unfamiliar {$what}"], $unfamiliar[$what])) { $key = $link->settings["unfamiliar {$what}"]; } else { $key = 'site-default'; } $unfamiliar[$what][$key] = ' checked="checked"'; } if (is_array($link->settings['cats'])) { $cats = $link->settings['cats']; } else { $cats = array(); } $dogs = SyndicatedPost::category_ids($cats, NULL); } else { die(__('Link not found.')); } ?> <script type="text/javascript"> function flip_hardcode (item) { ed=document.getElementById('basics-'+item+'-edit'); view=document.getElementById('basics-'+item+'-view'); o = document.getElementById('basics-hardcode-'+item); if (o.value=='yes') { ed.style.display='inline'; view.style.display='none'; } else { ed.style.display='none'; view.style.display='inline'; } } function flip_newuser (item) { rollup=document.getElementById(item); newuser=document.getElementById(item+'-newuser'); sitewide=document.getElementById(item+'-default'); if (rollup) { if ('newuser'==rollup.value) { if (newuser) newuser.style.display='block'; if (sitewide) sitewide.style.display='none'; } else if ('site-default'==rollup.value) { if (newuser) newuser.style.display='none'; if (sitewide) sitewide.style.display='block'; } else { if (newuser) newuser.style.display='none'; if (sitewide) sitewide.style.display='none'; } } } </script> <?php if ($updated_link) { ?> <div class="updated"><p>Syndicated feed settings updated.</p></div> <?php } ?> <form action="admin.php?page=<?php print $GLOBALS['fwp_path']; ?> /<?php echo basename(__FILE__); ?> " method="post"> <div class="wrap"> <input type="hidden" name="link_id" value="<?php echo $link_id; ?> " /> <input type="hidden" name="action" value="linkedit" /> <input type="hidden" name="save" value="link" /> <h2>Edit a syndicated feed:</h2> <div id="poststuff"> <?php fwp_linkedit_single_submit($status); ?> <div id="post-body"> <?php fwp_option_box_opener('Feed Information', 'feedinformationdiv'); ?> <table class="editform" width="100%" cellspacing="2" cellpadding="5"> <tr> <th scope="row" width="20%"><?php _e('Feed URI:'); ?> </th> <td width="60%"><a href="<?php echo wp_specialchars($link_rss_uri, 'both'); ?> "><?php echo $link_rss_uri; ?> </a> (<a href="<?php echo FEEDVALIDATOR_URI; ?> ?url=<?php echo urlencode($link_rss_uri); ?> " title="Check feed <<?php echo wp_specialchars($link_rss_uri, 'both'); ?> > for validity">validate</a>) </td> <td width="20%"><input type="submit" name="feedfinder" value="switch →" style="font-size:smaller" /></td> </tr> <tr> <th scope="row" width="20%"><?php _e('Link Name:'); ?> </th> <td width="60%"><input type="text" id="basics-name-edit" name="name" value="<?php echo $link_name; ?> " style="width: 95%" /> <span id="basics-name-view"><strong><?php echo $link_name; ?> </strong></span> </td> <td> <select id="basics-hardcode-name" onchange="flip_hardcode('name')" name="hardcode_name"> <option value="no" <?php echo $link->hardcode('name') ? '' : 'selected="selected"'; ?> >update automatically</option> <option value="yes" <?php echo $link->hardcode('name') ? 'selected="selected"' : ''; ?> >edit manually</option> </select> </td> </tr> <tr> <th scope="row" width="20%"><?php _e('Short description:'); ?> </th> <td width="60%"> <input id="basics-description-edit" type="text" name="description" value="<?php echo $link_description; ?> " style="width: 95%" /> <span id="basics-description-view"><strong><?php echo $link_description; ?> </strong></span> </td> <td> <select id="basics-hardcode-description" onchange="flip_hardcode('description')" name="hardcode_description"> <option value="no" <?php echo $link->hardcode('description') ? '' : 'selected="selected"'; ?> >update automatically</option> <option value="yes" <?php echo $link->hardcode('description') ? 'selected="selected"' : ''; ?> >edit manually</option> </select></td> </tr> <tr> <th width="20%" scope="row"><?php _e('Homepage:'); ?> </th> <td width="60%"> <input id="basics-url-edit" type="text" name="linkurl" value="<?php echo $link_url; ?> " style="width: 95%;" /> <a id="basics-url-view" href="<?php echo $link_url; ?> "><?php echo $link_url; ?> </a></td> <td> <select id="basics-hardcode-url" onchange="flip_hardcode('url')" name="hardcode_url"> <option value="no"<?php echo $link->hardcode('url') ? '' : ' selected="selected"'; ?> >update automatically</option> <option value="yes"<?php echo $link->hardcode('url') ? ' selected="selected"' : ''; ?> >edit manually</option> </select></td></tr> <tr> <th width="20%"><?php _e('Last update'); ?> :</th> <td colspan="2"><?php if (isset($link->settings['update/last'])) { echo fwp_time_elapsed($link->settings['update/last']) . " "; } else { echo " none yet"; } ?> </td></tr> <tr><th width="20%">Next update:</th> <td colspan="2"><?php $holdem = isset($link->settings['update/hold']) ? $link->settings['update/hold'] : 'scheduled'; ?> <select name="update_schedule"> <option value="scheduled"<?php echo $holdem == 'scheduled' ? ' selected="selected"' : ''; ?> >update on schedule <?php echo " ("; if (isset($link->settings['update/ttl']) and is_numeric($link->settings['update/ttl'])) { if (isset($link->settings['update/timed']) and $link->settings['update/timed'] == 'automatically') { echo 'next: '; $next = $link->settings['update/last'] + (int) $link->settings['update/ttl'] * 60; if (strftime('%x', time()) != strftime('%x', $next)) { echo strftime('%x', $next) . " "; } echo strftime('%X', $link->settings['update/last'] + (int) $link->settings['update/ttl'] * 60); } else { echo "every " . $link->settings['update/ttl'] . " minute" . ($link->settings['update/ttl'] != 1 ? "s" : ""); } } else { echo "next scheduled update"; } echo ")"; ?> </option> <option value="next"<?php echo $holdem == 'next' ? ' selected="selected"' : ''; ?> >update ASAP</option> <option value="ping"<?php echo $holdem == 'ping' ? ' selected="selected"' : ''; ?> >update only when pinged</option> </select></tr> </table> <?php fwp_option_box_closer(); ?> <script type="text/javascript"> flip_hardcode('name'); flip_hardcode('description'); flip_hardcode('url'); </script> <?php fwp_linkedit_periodic_submit(); ?> <?php if (!(isset($wp_db_version) and $wp_db_version >= FWP_SCHEMA_25)) { fwp_option_box_opener('Syndicated Posts', 'syndicatedpostsdiv', 'postbox'); ?> <table class="editform" width="75%" cellspacing="2" cellpadding="5"> <tr><th width="27%" scope="row" style="vertical-align:top">Publication:</th> <td width="73%" style="vertical-align:top"><ul style="margin:0; list-style:none"> <li><label><input type="radio" name="feed_post_status" value="site-default" <?php echo $status['post']['site-default']; ?> /> Use site-wide setting from <a href="admin.php?page=<?php print $GLOBALS['fwp_path']; ?> /syndication-options.php">Syndication Options</a> (currently: <strong><?php echo $post_status_global ? $post_status_global : 'publish'; ?> </strong>)</label></li> <li><label><input type="radio" name="feed_post_status" value="publish" <?php echo $status['post']['publish']; ?> /> Publish posts from this feed immediately</label></li> <?php if (SyndicatedPost::use_api('post_status_pending')) { ?> <li><label><input type="radio" name="feed_post_status" value="pending" <?php echo $status['post']['pending']; ?> /> Hold posts from this feed for review; mark as Pending</label></li> <?php } ?> <li><label><input type="radio" name="feed_post_status" value="draft" <?php echo $status['post']['draft']; ?> /> Save posts from this feed as drafts</label></li> <li><label><input type="radio" name="feed_post_status" value="private" <?php echo $status['post']['private']; ?> /> Save posts from this feed as private posts</label></li> </ul></td> </tr> </table> <?php fwp_option_box_closer(); fwp_linkedit_periodic_submit(); } fwp_option_box_opener(__('Categories'), 'categorydiv', 'postbox'); fwp_category_box($dogs, 'all syndicated posts from this feed'); ?> <table> <tr> <th width="20%" scope="row" style="vertical-align:top">Unfamiliar categories:</th> <td width="80%"><p>When one of the categories on a syndicated post is a category that FeedWordPress has not encountered before ...</p> <ul style="margin: 0; list-style:none"> <li><label><input type="radio" name="unfamiliar_category" value="site-default"<?php echo $unfamiliar['category']['site-default']; ?> /> use the site-wide setting from <a href="admin.php?page=<?php print $GLOBALS['fwp_path']; ?> /syndication-options.php">Syndication Options</a> (currently <strong><?php echo FeedWordPress::on_unfamiliar('category'); ?> </strong>)</label></li> <li><label><input type="radio" name="unfamiliar_category" value="create"<?php echo $unfamiliar['category']['create']; ?> /> create a new category</label></li> <?php if (fwp_test_wp_version(FWP_SCHEMA_23)) { ?> <li><label><input type="radio" name="unfamiliar_category" value="tag"<?php echo $unfamiliar['category']['tag']; ?> /> create a new tag</label></li> <?php } ?> <li><label><input type="radio" name="unfamiliar_category" value="default"<?php echo $unfamiliar['category']['default']; ?> /> don't create new categories<?php if (fwp_test_wp_version(FWP_SCHEMA_23)) { ?> or tags<?php } ?> </label></li> <li><label><input type="radio" name="unfamiliar_category" value="filter"<?php echo $unfamiliar['category']['filter']; ?> /> don't create new categories<?php if (fwp_test_wp_version(FWP_SCHEMA_23)) { ?> or tags<?php } ?> and don't syndicate posts unless they match at least one familiar category</label></li> </ul></td> </tr> <tr> <th width="20%" scope="row" style="vertical-align:top">Multiple categories:</th> <td width="80%"> <input type="text" size="20" id="cat_split" name="cat_split" value="<?php if (isset($link->settings['cat_split'])) { echo htmlspecialchars($link->settings['cat_split']); } ?> " /><br/> Enter a <a href="http://us.php.net/manual/en/reference.pcre.pattern.syntax.php">Perl-compatible regular expression</a> here if the feed provides multiple categories in a single category element. The regular expression should match the characters used to separate one category from the next. If the feed uses spaces (like <a href="http://del.icio.us/">del.icio.us</a>), use the pattern "\s". If the feed does not provide multiple categories in a single element, leave this blank.</td> </tr> </table> <?php fwp_option_box_closer(); fwp_linkedit_periodic_submit(); if (isset($wp_db_version) and $wp_db_version >= FWP_SCHEMA_25) { fwp_tags_box($link->settings['tags']); fwp_linkedit_periodic_submit(); } ?> <?php fwp_option_box_opener('Syndicated Authors', 'authordiv', 'postbox'); $authorlist = fwp_author_list(); ?> <table> <tr><th colspan="3" style="text-align: left; padding-top: 1.0em; border-bottom: 1px dotted black;">For posts by authors that haven't been syndicated before:</th></tr> <tr> <th style="text-align: left">Posts by new authors</th> <td> <select id="unfamiliar-author" name="unfamiliar_author" onchange="flip_newuser('unfamiliar-author');"> <option value="site-default"<?php if (!isset($link->settings['unfamiliar author'])) { ?> selected="selected"<?php } ?> >are handled using site-wide settings</option> <option value="create"<?php if ('create' == $link->settings['unfamiliar author']) { ?> selected="selected"<?php } ?> >create a new author account</option> <?php foreach ($authorlist as $author_id => $author_name) { ?> <option value="<?php echo $author_id; ?> "<?php if ($author_id == $link->settings['unfamiliar author']) { ?> selected="selected"<?php } ?> >are assigned to <?php echo $author_name; ?> </option> <?php } ?> <option value="newuser">will be assigned to a new user...</option> <option value="filter"<?php if ('filter' == $link->settings['unfamiliar author']) { ?> selected="selected"<?php } ?> >get filtered out</option> </select> </td> <td> <div id="unfamiliar-author-default">Site-wide settings can be set in <a href="admin.php?page=<?php print $GLOBALS['fwp_path']; ?> /syndication-options.php">Syndication Options</a></div> <div id="unfamiliar-author-newuser">named <input type="text" name="unfamiliar_author_newuser" value="" /></div> </td> </tr> <tr><th colspan="3" style="text-align: left; padding-top: 1.0em; border-bottom: 1px dotted black;">For posts by specific authors. Blank out a name to delete the rule.</th></tr> <?php if (isset($link->settings['map authors'])) { $i = 0; foreach ($link->settings['map authors'] as $author_rules) { foreach ($author_rules as $author_name => $author_action) { $i++; ?> <tr> <th style="text-align: left">Posts by <input type="text" name="author_rules_name[]" value="<?php echo htmlspecialchars($author_name); ?> " /></th> <td> <select id="author-rules-<?php echo $i; ?> " name="author_rules_action[]" onchange="flip_newuser('author-rules-<?php echo $i; ?> ');"> <?php foreach ($authorlist as $local_author_id => $local_author_name) { ?> <option value="<?php echo $local_author_id; ?> "<?php if ($local_author_id == $author_action) { echo ' selected="selected"'; } ?> >are assigned to <?php echo $local_author_name; ?> </option> <?php } ?> <option value="newuser">will be assigned to a new user...</option> <option value="filter"<?php if ('filter' == $author_action) { echo ' selected="selected"'; } ?> >get filtered out</option> </select> </td> <td><div id="author-rules-<?php echo $i; ?> -newuser">named <input type="text" name="author_rules_newuser[]" value="" /></div></td> </tr> <?php } } } ?> <tr><th colspan="3" style="text-align: left; padding-top: 1.0em; border-bottom: 1px dotted black;">Fill in to set up a new rule:</th></tr> <tr> <th style="text-align: left">Posts by <input type="text" name="add_author_rule_name" /></th> <td> <select id="add-author-rule" name="add_author_rule_action" onchange="flip_newuser('add-author-rule');"> <?php foreach ($authorlist as $author_id => $author_name) { ?> <option value="<?php echo $author_id; ?> ">are assigned to <?php echo $author_name; ?> </option> <?php } ?> <option value="newuser">will be assigned to a new user...</option> <option value="filter">get filtered out</option> </select> </td> <td><div id="add-author-rule-newuser">named <input type="text" name="add_author_rule_newuser" value="" /></div></td> </tr> </table> <?php fwp_option_box_closer(); ?> <script> flip_newuser('unfamiliar-author'); <?php for ($j = 1; $j <= $i; $j++) { ?> flip_newuser('author-rules-<?php echo $j; ?> '); <?php } ?> flip_newuser('add-author-rule'); </script> <?php fwp_linkedit_periodic_submit(); fwp_option_box_opener('Comments & Pings', 'commentstatusdiv', 'postbox'); ?> <table class="editform" width="75%" cellspacing="2" cellpadding="5"> <tr><th width="27%" scope="row" style="vertical-align:top"><?php print __('Comments'); ?> :</th> <td width="73%"><ul style="margin:0; list-style:none"> <li><label><input type="radio" name="feed_comment_status" value="site-default" <?php echo $status['comment']['site-default']; ?> /> Use site-wide setting from <a href="admin.php?page=<?php print $GLOBALS['fwp_path']; ?> /syndication-options.php">Syndication Options</a> (currently: <strong><?php echo $comment_status_global ? $comment_status_global : 'closed'; ?> )</strong></label></li> <li><label><input type="radio" name="feed_comment_status" value="open" <?php echo $status['comment']['open']; ?> /> Allow comments on syndicated posts from this feed</label></li> <li><label><input type="radio" name="feed_comment_status" value="closed" <?php echo $status['comment']['closed']; ?> /> Don't allow comments on syndicated posts from this feed</label></li> </ul></td></tr> <tr><th width="27%" scope="row" style="vertical-align:top"><?php print __('Pings'); ?> :</th> <td width="73%"><ul style="margin:0; list-style:none"> <li><label><input type="radio" name="feed_ping_status" value="site-default" <?php echo $status['ping']['site-default']; ?> /> Use site-wide setting from <a href="admin.php?page=<?php print $GLOBALS['fwp_path']; ?> /syndication-options.php">Syndication Options</a> (currently: <strong><?php echo $ping_status_global ? $ping_status_global : 'closed'; ?> )</strong></label></li> <li><label><input type="radio" name="feed_ping_status" value="open" <?php echo $status['ping']['open']; ?> /> Accept pings on syndicated posts from this feed</label></li> <li><label><input type="radio" name="feed_ping_status" value="closed" <?php echo $status['ping']['closed']; ?> /> Don't accept pings on syndicated posts from this feed</label></li> </ul></td></tr> </table> <?php fwp_option_box_closer(); fwp_linkedit_periodic_submit(); ?> <?php fwp_option_box_opener('Custom Settings (for use in templates)', 'postcustom', 'postbox'); ?> <div id="postcustomstuff"> <table id="meta-list" cellpadding="3"> <tr> <th>Key</th> <th>Value</th> <th>Action</th> </tr> <?php $i = 0; foreach ($link->settings as $key => $value) { if (!preg_match("^((" . implode(')|(', $special_settings) . "))\$i", $key)) { ?> <tr style="vertical-align:top"> <th width="30%" scope="row"><input type="hidden" name="notes[<?php echo $i; ?> ][key0]" value="<?php echo wp_specialchars($key, 'both'); ?> " /> <input id="notes-<?php echo $i; ?> -key" name="notes[<?php echo $i; ?> ][key1]" value="<?php echo wp_specialchars($key, 'both'); ?> " /></th> <td width="60%"><textarea rows="2" cols="40" id="notes-<?php echo $i; ?> -value" name="notes[<?php echo $i; ?> ][value]"><?php echo wp_specialchars($value, 'both'); ?> </textarea></td> <td width="10%"><select name="notes[<?php echo $i; ?> ][action]"> <option value="update">save changes</option> <option value="delete">delete this setting</option> </select></td> </tr> <?php $i++; } } ?> <tr> <th scope="row"><input type="text" size="10" name="notes[<?php echo $i; ?> ][key1]" value="" /></th> <td><textarea name="notes[<?php echo $i; ?> ][value]" rows="2" cols="40"></textarea></td> <td><em>add new setting...</em><input type="hidden" name="notes[<?php echo $i; ?> ][action]" value="update" /></td> </tr> </table> <?php fwp_option_box_closer(); ?> <?php fwp_linkedit_periodic_submit(); fwp_linkedit_single_submit_closer(); ?> </div> <!-- id="post-body" --> </div> <!-- id="poststuff" --> </div> <?php } return false; // Don't continue }
function poll($crash_ts = NULL) { global $wpdb; $url = $this->uri(array('add_params' => true)); FeedWordPress::diagnostic('updated_feeds', 'Polling feed [' . $url . ']'); $timeout = $this->setting('fetch timeout', 'feedwordpress_fetch_timeout', FEEDWORDPRESS_FETCH_TIMEOUT_DEFAULT); $this->simplepie = apply_filters('syndicated_feed', FeedWordPress::fetch($url, array('timeout' => $timeout)), $this); // Filter compatibility mode if (is_wp_error($this->simplepie)) { $this->magpie = $this->simplepie; } else { $this->magpie = new MagpieFromSimplePie($this->simplepie, NULL); } $new_count = NULL; $resume = FeedWordPress::affirmative($this->settings, 'update/unfinished'); if ($resume) { // pick up where we left off $processed = array_map('trim', explode("\n", $this->settings['update/processed'])); } else { // begin at the beginning $processed = array(); } if (is_wp_error($this->simplepie)) { $new_count = $this->simplepie; // Error; establish an error setting. $theError = array(); $theError['ts'] = time(); $theError['since'] = time(); $theError['object'] = $this->simplepie; $oldError = $this->setting('update/error', NULL, NULL); if (is_string($oldError)) { $oldError = unserialize($oldError); } if (!is_null($oldError)) { // Copy over the in-error-since timestamp $theError['since'] = $oldError['since']; // If this is a repeat error, then we should take // a step back before we try to fetch it again. $this->settings['update/last'] = time(); $this->settings['update/ttl'] = $this->automatic_ttl(); $this->settings['update/ttl'] = apply_filters('syndicated_feed_ttl', $this->settings['update/ttl'], $this); $this->settings['update/ttl'] = apply_filters('syndicated_feed_ttl_from_error', $this->settings['update/ttl'], $this); $this->settings['update/timed'] = 'automatically'; } do_action('syndicated_feed_error', $theError, $oldError, $this); $this->settings['update/error'] = serialize($theError); $this->save_settings(true); } elseif (is_object($this->simplepie)) { // Success; clear out error setting, if any. if (isset($this->settings['update/error'])) { unset($this->settings['update/error']); } $new_count = array('new' => 0, 'updated' => 0); # -- Update Link metadata live from feed $channel = $this->magpie->channel; if (!isset($channel['id'])) { $channel['id'] = $this->link->link_rss; } $update = array(); if (!$this->hardcode('url') and isset($channel['link'])) { $update[] = "link_url = '" . $wpdb->escape($channel['link']) . "'"; } if (!$this->hardcode('name') and isset($channel['title'])) { $update[] = "link_name = '" . $wpdb->escape($channel['title']) . "'"; } if (!$this->hardcode('description')) { if (isset($channel['tagline'])) { $update[] = "link_description = '" . $wpdb->escape($channel['tagline']) . "'"; } elseif (isset($channel['description'])) { $update[] = "link_description = '" . $wpdb->escape($channel['description']) . "'"; } } $this->settings = array_merge($this->settings, $this->flatten_array($channel)); $this->settings['update/last'] = time(); list($ttl, $xml) = $this->ttl(true); if (!is_null($ttl)) { $this->settings['update/ttl'] = $ttl; $this->settings['update/xml'] = $xml; $this->settings['update/timed'] = 'feed'; } else { $ttl = $this->automatic_ttl(); $this->settings['update/ttl'] = $ttl; $this->settings['update/xml'] = NULL; $this->settings['update/timed'] = 'automatically'; } $this->settings['update/fudge'] = rand(0, $ttl / 3) * 60; $this->settings['update/ttl'] = apply_filters('syndicated_feed_ttl', $this->setting('update/ttl'), $this); if (!$this->setting('update/hold') != 'ping') { $this->settings['update/hold'] = 'scheduled'; } $this->settings['update/unfinished'] = 'yes'; $update[] = "link_notes = '" . $wpdb->escape($this->settings_to_notes()) . "'"; $update_set = implode(',', $update); // Update the properties of the link from the feed information $result = $wpdb->query("\n\t\t\t\tUPDATE {$wpdb->links}\n\t\t\t\tSET {$update_set}\n\t\t\t\tWHERE link_id='{$this->id}'\n\t\t\t"); do_action('update_syndicated_feed', $this->id, $this); # -- Add new posts from feed and update any updated posts $crashed = false; $posts = apply_filters('syndicated_feed_items', $this->simplepie->get_items(), &$this); $this->magpie->originals = $posts; if (is_array($posts)) { foreach ($posts as $key => $item) { $post = new SyndicatedPost($item, $this); if (!$resume or !in_array(trim($post->guid()), $processed)) { $processed[] = $post->guid(); if (!$post->filtered()) { $new = $post->store(); if ($new !== false) { $new_count[$new]++; } } if (!is_null($crash_ts) and time() > $crash_ts) { $crashed = true; break; } } unset($post); } } $suffix = $crashed ? 'crashed' : 'completed'; do_action('update_syndicated_feed_items', $this->id, $this); do_action("update_syndicated_feed_items_{$suffix}", $this->id, $this); // Copy back any changes to feed settings made in the course of updating (e.g. new author rules) $to_notes = $this->settings; $this->settings['update/processed'] = $processed; if (!$crashed) { $this->settings['update/unfinished'] = 'no'; } $update_set = "link_notes = '" . $wpdb->escape($this->settings_to_notes()) . "'"; // Update the properties of the link from the feed information $result = $wpdb->query("\n\t\t\tUPDATE {$wpdb->links}\n\t\t\tSET {$update_set}\n\t\t\tWHERE link_id='{$this->id}'\n\t\t\t"); do_action("update_syndicated_feed_completed", $this->id, $this); } // All done; let's clean up. $this->magpie = NULL; // Avoid circular-reference memory leak in PHP < 5.3. // Cf. <http://simplepie.org/wiki/faq/i_m_getting_memory_leaks> if (method_exists($this->simplepie, '__destruct')) { $this->simplepie->__destruct(); } $this->simplepie = NULL; return $new_count; }
function poll($crash_ts = NULL) { FeedWordPress::diagnostic('updated_feeds', 'Polling feed <' . $this->link->link_rss . '>'); $this->simplepie = apply_filters('syndicated_feed', FeedWordPress::fetch($this->link->link_rss), $this); // Filter compatibility mode if (is_wp_error($this->simplepie)) { $this->magpie = $this->simplepie; } else { $this->magpie = new MagpieFromSimplePie($this->simplepie); } $new_count = NULL; $resume = FeedWordPress::affirmative($this->settings, 'update/unfinished'); if ($resume) { // pick up where we left off $processed = array_map('trim', explode("\n", $this->settings['update/processed'])); } else { // begin at the beginning $processed = array(); } if (is_wp_error($this->simplepie)) { $new_count = $this->simplepie; // Error; establish an error setting. $theError = array(); $theError['ts'] = time(); $theError['since'] = time(); $theError['object'] = $this->simplepie; $oldError = $this->setting('update/error', NULL, NULL); if (is_string($oldError)) { $oldError = unserialize($oldError); } if (!is_null($oldError)) { // Copy over the in-error-since timestamp $theError['since'] = $oldError['since']; // If this is a repeat error, then we should take // a step back before we try to fetch it again. $this->settings['update/last'] = time(); $this->settings['update/ttl'] = $this->automatic_ttl(); $this->settings['update/ttl'] = apply_filters('syndicated_feed_ttl', $this->settings['update/ttl'], $this); $this->settings['update/ttl'] = apply_filters('syndicated_feed_ttl_from_error', $this->settings['update/ttl'], $this); $this->settings['update/timed'] = 'automatically'; } $this->settings['update/error'] = serialize($theError); $this->save_settings(true); } elseif (is_object($this->simplepie)) { // Grab our bookmark we're going to be updating $link = get_bookmark($this->id, ARRAY_A); if (is_array($link) && !empty($link)) { // Success; clear out error setting, if any. if (isset($this->settings['update/error'])) { unset($this->settings['update/error']); } $new_count = array('new' => 0, 'updated' => 0); # -- Update Link metadata live from feed $channel = $this->magpie->channel; if (!isset($channel['id'])) { $channel['id'] = $this->link->link_rss; } if (!$this->hardcode('url') and isset($channel['link'])) { $link['link_url'] = $channel['link']; } if (!$this->hardcode('name') and isset($channel['title'])) { $link['link_name'] = $channel['title']; } if (!$this->hardcode('description')) { if (isset($channel['tagline'])) { $link['link_description'] = $channel['tagline']; } elseif (isset($channel['description'])) { $link['link_description'] = $channel['description']; } } $this->settings = array_merge($this->settings, $this->flatten_array($channel)); $this->settings['update/last'] = time(); $ttl = $this->ttl(); if (!is_null($ttl)) { $this->settings['update/ttl'] = $ttl; $this->settings['update/timed'] = 'feed'; } else { $this->settings['update/ttl'] = $this->automatic_ttl(); $this->settings['update/timed'] = 'automatically'; } $this->settings['update/ttl'] = apply_filters('syndicated_feed_ttl', $this->settings['update/ttl'], $this); if (!isset($this->settings['update/hold']) or $this->settings['update/hold'] != 'ping') { $this->settings['update/hold'] = 'scheduled'; } $this->settings['update/unfinished'] = 'yes'; $link['link_notes'] = $this->settings_to_notes(); // Update the properties of the link from the feed information $result = wp_update_link($link); do_action('update_syndicated_feed', $this->id, $this); # -- Add new posts from feed and update any updated posts $crashed = false; $posts = apply_filters('syndicated_feed_items', $this->magpie->originals, $this); if (is_array($posts)) { foreach ($posts as $key => $original) { $item = $this->magpie->items[$key]; $post = new SyndicatedPost(array('simplepie' => $original, 'magpie' => $item), $this); if (!$resume or !in_array(trim($post->guid()), $processed)) { $processed[] = $post->guid(); if (!$post->filtered()) { $new = $post->store(); if ($new !== false) { $new_count[$new]++; } } if (!is_null($crash_ts) and time() > $crash_ts) { $crashed = true; break; } } unset($post); } } $suffix = $crashed ? 'crashed' : 'completed'; do_action('update_syndicated_feed_items', $this->id, $this); do_action("update_syndicated_feed_items_{$suffix}", $this->id, $this); // Copy back any changes to feed settings made in the course of updating (e.g. new author rules) $to_notes = $this->settings; $this->settings['update/processed'] = $processed; if (!$crashed) { $this->settings['update/unfinished'] = 'no'; } $link['link_notes'] = $this->settings_to_notes(); // Update the properties of the link from the feed information $result = wp_update_link($link); do_action("update_syndicated_feed_completed", $this->id, $this); } } return $new_count; }
function categories_box($page, $box = NULL) { $link = $page->link; if ($page->for_feed_settings()) { $cats = isset($link->settings['cats']) && is_array($link->settings['cats']) ? $link->settings['cats'] : array(); } else { $cats = array_map('trim', preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, get_option('feedwordpress_syndication_cats'))); } $dogs = SyndicatedPost::category_ids($cats, NULL); fwp_category_box($dogs, 'all ' . $page->these_posts_phrase()); }