function sources($visibility = 'Y') { if (is_null($this->_sources)) { $links = FeedWordPress::syndicated_links(array("hide_invisible" => false)); $this->_sources = array("Y" => array(), "N" => array()); foreach ($links as $link) { $this->_sources[$link->link_visible][] = $link; } } $ret = array_key_exists($visibility, $this->_sources) ? $this->_sources[$visibility] : $this->_sources; return $ret; }
function syndicated_sources_box($page, $box = NULL) { global $fwp_path; $links = FeedWordPress::syndicated_links(array("hide_invisible" => false)); $sources = $this->sources('*'); $visibility = $this->visibility_toggle(); $showInactive = $this->show_inactive(); $hrefPrefix = $this->form_action(); ?> <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?> </div> <div class="tablenav"> <div id="add-multiple-uri" class="hide-if-js"> <form action="<?php print $hrefPrefix; ?> &visibility=<?php print $visibility; ?> " method="post"> <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?> </div> <h4>Add Multiple Sources</h4> <div>Enter one feed or website URL per line. If a URL links to a website which provides multiple feeds, FeedWordPress will use the first one listed.</div> <div><textarea name="multilookup" rows="8" cols="60" style="vertical-align: top"></textarea></div> <div style="border-top: 1px dotted black; padding-top: 10px"> <div class="alignright"><input type="submit" class="button-primary" name="multiadd" value="<?php print FWP_SYNDICATE_NEW; ?> " /></div> <div class="alignleft"><input type="button" class="button-secondary" name="action" value="<?php print FWP_CANCEL_BUTTON; ?> " id="turn-off-multiple-sources" /></div> </div> </form> </div> <!-- id="add-multiple-uri" --> <div id="upload-opml" style="float: right" class="hide-if-js"> <h4>Import source list</h4> <p>You can import a list of sources in OPML format, either by providing a URL for the OPML document, or by uploading a copy from your computer.</p> <form enctype="multipart/form-data" action="<?php print $hrefPrefix; ?> &visibility=<?php print $visibility; ?> " method="post"> <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /></div> <div style="clear: both"><label for="opml-lookup" style="float: left; width: 8.0em; margin-top: 5px;">From URL:</label> <input type="text" id="opml-lookup" name="opml_lookup" value="OPML document" /></div> <div style="clear: both"><label for="opml-upload" style="float: left; width: 8.0em; margin-top: 5px;">From file:</label> <input type="file" id="opml-upload" name="opml_upload" /></div> <div style="border-top: 1px dotted black; padding-top: 10px"> <div class="alignright"><input type="submit" class="button-primary" name="action" value="<?php print FWP_SYNDICATE_NEW; ?> " /></div> <div class="alignleft"><input type="button" class="button-secondary" name="action" value="<?php print FWP_CANCEL_BUTTON; ?> " id="turn-off-opml-upload" /></div> </div> </form> </div> <!-- id="upload-opml" --> <div id="add-single-uri" class="alignright"> <form id="syndicated-links" action="<?php print $hrefPrefix; ?> &visibility=<?php print $visibility; ?> " method="post"> <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?> </div> <ul class="subsubsub"> <li><label for="add-uri">New source:</label> <input type="text" name="lookup" id="add-uri" value="Website or feed URI" /> <?php FeedWordPressSettingsUI::magic_input_tip_js('add-uri'); FeedWordPressSettingsUI::magic_input_tip_js('opml-lookup'); ?> <input type="hidden" name="action" value="feedfinder" /> <input type="submit" class="button-secondary" name="action" value="<?php print FWP_SYNDICATE_NEW; ?> " /> <div style="text-align: right; margin-right: 2.0em"><a id="turn-on-multiple-sources" href="#add-multiple-uri"><img style="vertical-align: middle" src="<?php print plugins_url('/' . $fwp_path . '/down.png'); ?> " alt="" /> add multiple</a> <span class="screen-reader-text"> or </span> <a id="turn-on-opml-upload" href="#upload-opml"><img src="<?php print plugins_url('/' . $fwp_path . '/plus.png'); ?> " alt="" style="vertical-align: middle" /> import source list</a></div> </li> </ul> </form> </div> <!-- class="alignright" --> <div class="alignleft"> <?php if (count($sources[$visibility]) > 0) { $this->manage_page_links_subsubsub($sources, $showInactive); } ?> </div> <!-- class="alignleft" --> </div> <!-- class="tablenav" --> <form id="syndicated-links" action="<?php print $hrefPrefix; ?> &visibility=<?php print $visibility; ?> " method="post"> <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?> </div> <?php if ($showInactive) { ?> <div style="clear: right" class="alignright"> <p style="font-size: smaller; font-style: italic">FeedWordPress used to syndicate posts from these sources, but you have unsubscribed from them.</p> </div> <?php } ?> <?php if (count($sources[$visibility]) > 0) { $this->display_button_bar($showInactive); } else { $this->manage_page_links_subsubsub($sources, $showInactive); } fwp_syndication_manage_page_links_table_rows($sources[$visibility], $this, $visibility); $this->display_button_bar($showInactive); ?> </form> <?php }
function needs_upgrade() { global $wpdb; $fwp_db_version = get_option('feedwordpress_version'); $ret = false; // innocent until proven guilty if (!$fwp_db_version or $fwp_db_version < FEEDWORDPRESS_VERSION) { // This is an older version or a fresh install. Does it // require a database upgrade or database initialization? if ($fwp_db_version <= 0.96) { // Yes. Check to see whether this is a fresh install or an upgrade. $syn = $wpdb->get_col("\n\t\t\t\tSELECT post_id\n\t\t\t\tFROM {$wpdb->postmeta}\n\t\t\t\tWHERE meta_key = 'syndication_feed'\n\t\t\t\t"); if (count($syn) > 0) { // contains at least one syndicated post $ret = true; } else { // fresh install; brand it as ours update_option('feedwordpress_version', FEEDWORDPRESS_VERSION); } } elseif ($fwp_db_version < 2009.0707) { // We need to clear out any busted AJAX crap $wpdb->query("\n\t\t\t\tDELETE FROM {$wpdb->usermeta}\n\t\t\t\tWHERE LOCATE('feedwordpress', meta_key)\n\t\t\t\tAND LOCATE('box', meta_key);\n\t\t\t\t"); update_option('feedwordpress_version', FEEDWORDPRESS_VERSION); } elseif ($fwp_db_version < 2010.0814) { // Change in terminology. if (get_option('feedwordpress_unfamiliar_category', 'create') == 'default') { update_option('feedwordpress_unfamiliar_category', 'null'); } foreach (FeedWordPress::syndicated_links() as $link) { $sub = new SyndicatedLink($link); $remap_uf = array('default' => 'null', 'filter' => 'null', 'create' => 'create:category', 'tag' => 'create:post_tag'); if (isset($sub->settings['unfamiliar category'])) { if ($sub->settings['unfamiliar category'] == 'filter') { $sub->settings['match/filter'] = array('category'); } foreach ($remap_uf as $from => $to) { if ($sub->settings['unfamiliar category'] == $from) { $sub->settings['unfamiliar category'] = $to; } } } if (isset($sub->settings['add global categories'])) { $sub->settings['add/category'] = $sub->settings['add global categories']; unset($sub->settings['add global categories']); } $sub->save_settings(true); } update_option('feedwordpress_version', FEEDWORDPRESS_VERSION); } else { // No. Just brand it with the new version. update_option('feedwordpress_version', FEEDWORDPRESS_VERSION); } } return $ret; }
/** * Remove all the feed transients attached to our links. Originally * this removed "MagpieRSS" and "SimplePie" feed options/transients by * direct sql. This had to be changed for VIP compatibility. * * It looks like the SimplePie RSS is the only currently used method for * feed retrieval (on current systems, ie. local environment and most likely * VIP platform), so we are looping through the links that are part of FWP's * syndication, and clears their transient. * * It looks like Magpie's options are stored simply too, so we added * support to remove its options/caches as well for any of our links. */ function clear_cache() { // Set our counters $simplepies = $magpies = 0; // Grab all our links $links = FeedWordPress::syndicated_links(); if (!empty($links) && is_array($links)) { foreach ($links as $link) { $link_hash = md5($link->link_rss); $magpie_option = 'rss_' . $link_hash; if (get_option($magpie_option)) { // It's a MagpieRSS feed, clear the options delete_option($magpie_option); delete_option($magpie_option . '_ts'); // clear timestamp as well $magpies++; } else { // It's a SimplePie object, use its methods $trans = new WP_Feed_Cache_Transient('', $link_hash, ''); $trans->unlink(); $simplepies++; } } } return $magpies + $simplepies; }
function display_feed_select_dropdown() { $links = FeedWordPress::syndicated_links(); ?> <div id="fwpfs-container"><ul class="subsubsub"> <li><select name="link_id" class="fwpfs" style="max-width: 20.0em;"> <option value="*"<?php if ($this->for_default_settings()) { ?> selected="selected"<?php } ?> >- defaults for all feeds -</option> <?php if ($links) { foreach ($links as $ddlink) { ?> <option value="<?php print (int) $ddlink->link_id; ?> "<?php if (!is_null($this->link) and $this->link->id == $ddlink->link_id) { ?> selected="selected"<?php } ?> ><?php print esc_html($ddlink->link_name); ?> </option> <?php } } ?> </select> <input id="fwpfs-button" class="button" type="submit" name="go" value="<?php _e('Go'); ?> »" /></li> <?php $this->display_feed_settings_page_links(array('before' => '<li>', 'between' => "</li>\n<li>", 'after' => '</li>', 'subscription' => $this->link)); if ($this->for_feed_settings()) { ?> <li><input class="button" type="submit" name="update" value="Update Now" /></li> <?php } ?> </ul> </div> <?php }
function fwp_posts_page() { global $wp_db_version; global $fwp_post; if (FeedWordPress::needs_upgrade()) { fwp_upgrade_page(); return; } // If this is a POST, validate source and user credentials FeedWordPressCompatibility::validate_http_request('feedwordpress_posts_settings', 'manage_links'); $link = FeedWordPressAdminPage::submitted_link(); $postsPage = new FeedWordPressPostsPage($link); $mesg = null; //////////////////////////////////////////////// // Process POST request, if any //////////////// //////////////////////////////////////////////// if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') { $postsPage->accept_POST($fwp_post); do_action('feedwordpress_admin_page_posts_save', $fwp_post, $postsPage); } $postsPage->ajax_interface_js(); if ($postsPage->updated) { ?> <div class="updated"><p>Syndicated posts settings updated.</p></div> <?php } elseif (!is_null($mesg)) { ?> <div class="updated"><p><?php print esc_html($mesg); ?> </p></div> <?php } ?> <?php $links = FeedWordPress::syndicated_links(); $postsPage->open_sheet('Syndicated Posts & Links'); ?> <style type="text/css"> table.edit-form th, table.form-table th { width: 27%; vertical-align: top; } table.edit-form td, table.form-table td { width: 73%; vertical-align: top; } ul.options { margin: 0; padding: 0; list-style: none; } </style> <div id="post-body"> <?php $boxes_by_methods = array('publication_box' => __('Syndicated Posts'), 'links_box' => __('Links'), 'formatting_box' => __('Formatting'), 'comments_and_pings_box' => __('Comments & Pings'), 'custom_post_settings_box' => __('Custom Post Settings (to apply to each syndicated post)')); foreach ($boxes_by_methods as $method => $title) { fwp_add_meta_box('feedwordpress_' . $method, $title, array('FeedWordPressPostsPage', $method), $postsPage->meta_box_context(), $postsPage->meta_box_context()); } do_action('feedwordpress_admin_page_posts_meta_boxes', $postsPage); ?> <div class="metabox-holder"> <?php fwp_do_meta_boxes($postsPage->meta_box_context(), $postsPage->meta_box_context(), $postsPage); ?> </div> <!-- class="metabox-holder" --> </div> <!-- id="post-body" --> <?php $postsPage->close_sheet(); }
static function needs_upgrade() { global $wpdb; $fwp_db_version = get_option('feedwordpress_version', NULL); $ret = false; // innocent until proven guilty if (is_null($fwp_db_version) or $fwp_db_version < FEEDWORDPRESS_VERSION) { // This is an older version or a fresh install. Does it require a database // upgrade or database initialization? if (is_null($fwp_db_version)) { // Fresh install; brand it as ours. Or possibly a version of FWP // from before 0.96. But I'm no longer supporting upgrade paths // for versions from the previous decade. Sorry. update_option('feedwordpress_version', FEEDWORDPRESS_VERSION); } elseif ($fwp_db_version < 2010.0814) { // Change in terminology. if (get_option('feedwordpress_unfamiliar_category', 'create') == 'default') { update_option('feedwordpress_unfamiliar_category', 'null'); } foreach (FeedWordPress::syndicated_links() as $link) { $sub = new SyndicatedLink($link); $remap_uf = array('default' => 'null', 'filter' => 'null', 'create' => 'create:category', 'tag' => 'create:post_tag'); if (isset($sub->settings['unfamiliar category'])) { if ($sub->settings['unfamiliar category'] == 'filter') { $sub->settings['match/filter'] = array('category'); } foreach ($remap_uf as $from => $to) { if ($sub->settings['unfamiliar category'] == $from) { $sub->settings['unfamiliar category'] = $to; } } } if (isset($sub->settings['add global categories'])) { $sub->settings['add/category'] = $sub->settings['add global categories']; unset($sub->settings['add global categories']); } $sub->save_settings(true); } update_option('feedwordpress_version', FEEDWORDPRESS_VERSION); } else { // No upgrade needed. Just brand it with the new version. update_option('feedwordpress_version', FEEDWORDPRESS_VERSION); } } return $ret; }
function fwp_syndication_manage_page_links_box($object = NULL, $box = NULL) { $links = FeedWordPress::syndicated_links(); ?> <?php if (!fwp_test_wp_version(FWP_SCHEMA_27)) { ?> <div class="wrap"> <h2>Syndicated Sites</h2> <?php } ?> <form id="syndicated-links" action="admin.php?page=<?php print $GLOBALS['fwp_path']; ?> /<?php echo basename(__FILE__); ?> " method="post"> <?php $alt_row = true; ?> <?php if (fwp_test_wp_version(FWP_SCHEMA_25)) { ?> <div class="tablenav"> <div class="alignright"> <label for="add-uri">Add new source:</label> <input type="text" name="lookup" id="add-uri" value="Website or feed URI" /> <script type="text/javascript"> jQuery(document).ready( function () { var addUri = jQuery("#add-uri"); var box = addUri.get(0); if (box.value==box.defaultValue) { addUri.addClass('form-input-tip'); } addUri.focus(function() { if ( this.value == this.defaultValue ) jQuery(this).val( '' ).removeClass( 'form-input-tip' ); }); addUri.blur(function() { if ( this.value == '' ) jQuery(this).val( this.defaultValue ).addClass( 'form-input-tip' ); }); } ); </script> <input type="hidden" name="action" value="feedfinder" /> <input type="submit" class="button-secondary" name="action" value="<?php print FWP_SYNDICATE_NEW; ?> " /></div> <?php if (count($links) > 0) { ?> <div class="alignleft"> <input class="button-secondary" type="submit" name="action" value="<?php print FWP_UPDATE_CHECKED; ?> " /> <input class="button-secondary delete" type="submit" class="delete" name="action" value="<?php print FWP_UNSUB_CHECKED; ?> " /> </div> <?php } ?> <br class="clear" /> </div> <br class="clear" /> <table class="widefat"> <?php } else { ?> <table width="100%" cellpadding="3" cellspacing="3"> <?php } ?> <thead> <tr> <th class="check-column" scope="col"><?php if (fwp_test_wp_version(FWP_SCHEMA_25)) { ?> <input type="checkbox" <?php if (fwp_test_wp_version(FWP_SCHEMA_25, FWP_SCHEMA_26)) { ?> onclick="checkAll(document.getElementById('syndicated-links'));"<?php } ?> /> <?php } ?> </th> <th scope="col"><?php _e('Name'); ?> </th> <th scope="col"><?php _e('Feed'); ?> </th> <th scope="col"><?php _e('Updated'); ?> </th> </tr> </thead> <tbody> <?php if (count($links) > 0) { foreach ($links as $link) { $alt_row = !$alt_row; ?> <tr<?php echo $alt_row ? ' class="alternate"' : ''; ?> > <th class="check-column" scope="row"><input type="checkbox" name="link_ids[]" value="<?php echo $link->link_id; ?> " /></th> <?php if (strlen($link->link_rss) > 0) { $caption = __('Switch Feed'); } else { $caption = __('Find Feed'); } ?> <td> <strong><a href="admin.php?page=<?php print $GLOBALS['fwp_path']; ?> /<?php echo basename(__FILE__); ?> &link_id=<?php echo $link->link_id; ?> &action=linkedit"><?php echo wp_specialchars($link->link_name, 'both'); ?> </a></strong> <div class="row-actions"><a href="admin.php?page=<?php print $GLOBALS['fwp_path']; ?> /<?php echo basename(__FILE__); ?> &link_id=<?php echo $link->link_id; ?> &action=linkedit"><?php _e('Edit'); ?> </a> | <a href="admin.php?page=<?php print $GLOBALS['fwp_path']; ?> /<?php echo basename(__FILE__); ?> &link_id=<?php echo $link->link_id; ?> &action=feedfinder"><?php echo $caption; ?> </a> | <a href="admin.php?page=<?php print $GLOBALS['fwp_path']; ?> /<?php echo basename(__FILE__); ?> &link_id=<?php echo $link->link_id; ?> &action=Unsubscribe"><?php _e('Unsubscribe'); ?> </a> | <a href="<?php echo wp_specialchars($link->link_url, 'both'); ?> "><?php _e('View'); ?> </a> </div> </td> <?php if (strlen($link->link_rss) > 0) { $uri_bits = parse_url($link->link_rss); $uri_bits['host'] = preg_replace('/^www\\./i', '', $uri_bits['host']); $display_uri = (isset($uri_bits['user']) ? $uri_bits['user'] . '@' : '') . (isset($uri_bits['host']) ? $uri_bits['host'] : '') . (isset($uri_bits['port']) ? ':' . $uri_bits['port'] : '') . (isset($uri_bits['path']) ? $uri_bits['path'] : '') . (isset($uri_bits['query']) ? '?' . $uri_bits['query'] : ''); if (strlen($display_uri) > 32) { $display_uri = substr($display_uri, 0, 32) . '…'; } ?> <td><a href="<?php echo wp_specialchars($link->link_rss, 'both'); ?> "><?php echo wp_specialchars($display_uri, 'both'); ?> </a></td> <?php } else { ?> <td style="background-color:#FFFFD0"><p><strong>no feed assigned</strong></p></td> <?php } ?> <td><?php $sLink =& new SyndicatedLink($link->link_id); if (isset($sLink->settings['update/last'])) { print fwp_time_elapsed($sLink->settings['update/last']); } else { _e('None yet'); } print "<div style='font-style:italic;size:0.9em'>Ready for next update "; if (isset($sLink->settings['update/ttl']) and is_numeric($sLink->settings['update/ttl'])) { if (isset($sLink->settings['update/timed']) and $sLink->settings['update/timed'] == 'automatically') { $next = $sLink->settings['update/last'] + (int) $sLink->settings['update/ttl'] * 60; print fwp_time_elapsed($next); } else { echo "every " . $sLink->settings['update/ttl'] . " minute" . ($sLink->settings['update/ttl'] != 1 ? "s" : ""); } } else { echo "as soon as possible"; } print "</div>"; ?> </td> </tr> <?php } } else { ?> <tr><td colspan="<?php print $span + 2; ?> "><p>There are no websites currently listed for syndication.</p></td></tr> <?php } ?> </tbody> </table> <?php if (count($links) > 0 and fwp_test_wp_version(0, FWP_SCHEMA_25)) { ?> <br/><hr/> <div class="submit"><input type="submit" class="delete" name="action" value="<?php print FWP_UNSUB_CHECKED; ?> " /> <input type="submit" name="action" value="<?php print FWP_UPDATE_CHECKED; ?> " /></div> <?php } ?> </form> <?php }
function fwp_authors_page() { global $wpdb, $wp_db_version; check_admin_referer(); // Make sure we arrived here from the Dashboard if (isset($GLOBALS['fwp_post']['save']) or isset($GLOBALS['fwp_post']['fix_mismatch'])) { $link_id = $_REQUEST['save_link_id']; } elseif (isset($_REQUEST['link_id'])) { $link_id = $_REQUEST['link_id']; } else { $link_id = NULL; } if (is_numeric($link_id) and $link_id) { $link =& new SyndicatedLink($link_id); } else { $link = NULL; } $mesg = null; if (!current_user_can('manage_links')) { die(__("Cheatin' uh ?")); } else { if (isset($GLOBALS['fwp_post']['fix_mismatch'])) { if ('newuser' == $GLOBALS['fwp_post']['fix_mismatch_to']) { $newuser_name = trim($GLOBALS['fwp_post']['fix_mismatch_to_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)) { $fix_mismatch_to_id = $newuser_id; } else { // TODO: Add some error detection and reporting } } else { // TODO: Add some error reporting } } else { $fix_mismatch_to_id = $GLOBALS['fwp_post']['fix_mismatch_to']; } $fix_mismatch_from_id = (int) $GLOBALS['fwp_post']['fix_mismatch_from']; if (is_numeric($fix_mismatch_from_id)) { // Make a list of all the items by this author syndicated from this feed... $post_ids = $wpdb->get_col("\n\t\t\t\tSELECT {$wpdb->posts}.id\n\t\t\t\tFROM {$wpdb->posts}, {$wpdb->postmeta}\n\t\t\t\tWHERE ({$wpdb->posts}.id = {$wpdb->postmeta}.post_id)\n\t\t\t\tAND {$wpdb->postmeta}.meta_key = 'syndication_feed_id'\n\t\t\t\tAND {$wpdb->postmeta}.meta_value = '{$link_id}'\n\t\t\t\tAND {$wpdb->posts}.post_author = '{$fix_mismatch_from_id}'\n\t\t\t\t"); if (count($post_ids) > 0) { // Re-assign them all to the correct author if (is_numeric($fix_mismatch_to_id)) { // re-assign to a particular user $post_set = "(" . implode(",", $post_ids) . ")"; // Getting the revisions too, if there are any if (fwp_test_wp_version(FWP_SCHEMA_26)) { $parent_in_clause = "OR {$wpdb->posts}.post_parent IN {$post_set}"; } else { $parent_in_clause = ''; } $wpdb->query("\n\t\t\t\t\t\tUPDATE {$wpdb->posts}\n\t\t\t\t\t\tSET post_author='{$fix_mismatch_to_id}'\n\t\t\t\t\t\tWHERE ({$wpdb->posts}.id IN {$post_set}\n\t\t\t\t\t\t{$parent_in_clause})\n\t\t\t\t\t\t"); $mesg = "Re-assigned " . count($post_ids) . " post" . (count($post_ids) == 1 ? '' : 's') . "."; // ... and kill them all } elseif ($fix_mismatch_to_id == 'filter') { foreach ($post_ids as $post_id) { wp_delete_post($post_id); } $mesg = "Deleted " . count($post_ids) . " post" . (count($post_ids) == 1 ? '' : 's') . "."; } } else { $mesg = "Couldn't find any posts that matched your criteria."; } } } elseif (isset($GLOBALS['fwp_post']['save'])) { if (is_object($link) and $link->found()) { $alter = array(); // Unfamiliar author rule if (isset($GLOBALS['fwp_post']["unfamiliar_author"])) { if ('site-default' == $GLOBALS['fwp_post']["unfamiliar_author"]) { unset($link->settings["unfamiliar author"]); } elseif ('newuser' == $GLOBALS['fwp_post']["unfamiliar_author"]) { $newuser_name = trim($GLOBALS['fwp_post']["unfamiliar_author_newuser"]); $link->map_name_to_new_user(NULL, $newuser_name); } else { $link->settings["unfamiliar author"] = $GLOBALS['fwp_post']["unfamiliar_author"]; } } // 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]); $link->map_name_to_new_user($name, $newuser_name); } 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']); $link->map_name_to_new_user($name, $newuser_name); } else { $link->settings['map authors']['name'][$name] = $author_action; } } } $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 { if ('newuser' == $GLOBALS['fwp_post']['unfamiliar_author']) { $newuser_name = trim($GLOBALS['fwp_post']['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', $GLOBALS['fwp_post']['unfamiliar_author']); } if (isset($GLOBALS['fwp_post']['match_author_by_email']) and $GLOBALS['fwp_post']['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($GLOBALS['fwp_post']['null_emails'])) { update_option('feedwordpress_null_email_set', $GLOBALS['fwp_post']['null_emails']); } $updated_link = true; } } else { $updated_link = false; } $unfamiliar = array('create' => '', 'default' => '', 'filter' => ''); if (is_object($link) and $link->found()) { if (is_string($link->settings["unfamiliar author"])) { $key = $link->settings["unfamiliar author"]; } else { $key = 'site-default'; } } else { $key = FeedWordPress::on_unfamiliar('author'); } $unfamiliar[$key] = ' selected="selected"'; $match_author_by_email = !('yes' == get_option("feedwordpress_do_not_match_author_by_email")); $null_emails = FeedWordPress::null_email_set(); ?> <script type="text/javascript"> function contextual_appearance (item, appear, disappear, value, visibleStyle, checkbox) { if (typeof(visibleStyle)=='undefined') visibleStyle = 'block'; 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=visibleStyle; if (sitewide) sitewide.style.display='none'; } else { if (newuser) newuser.style.display='none'; if (sitewide) sitewide.style.display=visibleStyle; } } } </script> <?php if ($updated_link) { ?> <div class="updated"><p>Syndicated author settings updated.</p></div> <?php } elseif (!is_null($mesg)) { ?> <div class="updated"><p><?php print wp_specialchars($mesg, 1); ?> </p></div> <?php } ?> <div class="wrap"> <form style="position: relative" action="admin.php?page=<?php print $GLOBALS['fwp_path']; ?> /<?php echo basename(__FILE__); ?> " method="post"> <?php if (is_numeric($link_id) and $link_id) { ?> <input type="hidden" name="save_link_id" value="<?php echo $link_id; ?> " /> <?php } else { ?> <input type="hidden" name="save_link_id" value="*" /> <?php } ?> <?php $links = FeedWordPress::syndicated_links(); if (fwp_test_wp_version(FWP_SCHEMA_27)) { ?> <div class="icon32"><img src="<?php print htmlspecialchars(WP_PLUGIN_URL . '/' . $GLOBALS['fwp_path'] . '/feedwordpress.png'); ?> " alt="" /></div> <?php } ?> <h2>Syndicated Author Settings<?php if (!is_null($link) and $link->found()) { ?> : <?php echo wp_specialchars($link->link->link_name, 1); } ?> </h2> <?php if (fwp_test_wp_version(FWP_SCHEMA_27)) { ?> <style type="text/css"> #post-search { float: right; margin:11px 12px 0; min-width: 130px; position:relative; } .fwpfs { color: #dddddd; background:#797979 url(<?php bloginfo('home'); ?> /wp-admin/images/fav.png) repeat-x scroll left center; border-color:#777777 #777777 #666666 !important; -moz-border-radius-bottomleft:12px; -moz-border-radius-bottomright:12px; -moz-border-radius-topleft:12px; -moz-border-radius-topright:12px; border-style:solid; border-width:1px; line-height:15px; padding:3px 30px 4px 12px; } .fwpfs.slide-down { border-bottom-color: #626262; -moz-border-radius-bottomleft:0; -moz-border-radius-bottomright:0; -moz-border-radius-topleft:12px; -moz-border-radius-topright:12px; background-image:url(<?php bloginfo('home'); ?> /wp-admin/images/fav-top.png); background-position:0 top; background-repeat:repeat-x; border-bottom-style:solid; border-bottom-width:1px; } </style> <script type="text/javascript"> jQuery(document).ready(function($){ $('.fwpfs').toggle( function(){$('.fwpfs').removeClass('slideUp').addClass('slideDown'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideDown') ) { $('.fwpfs').addClass('slide-down'); }}, 10) }, function(){$('.fwpfs').removeClass('slideDown').addClass('slideUp'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideUp') ) { $('.fwpfs').removeClass('slide-down'); }}, 10) } ); $('.fwpfs').bind( 'change', function () { this.form.submit(); } ); $('#post-search .button').css( 'display', 'none' ); }); </script> <?php } /* else : */ ?> <p id="post-search"> <select name="link_id" class="fwpfs" style="max-width: 20.0em;"> <option value="*"<?php if (is_null($link) or !$link->found()) { ?> selected="selected"<?php } ?> >- defaults for all feeds -</option> <?php if ($links) { foreach ($links as $ddlink) { ?> <option value="<?php print (int) $ddlink->link_id; ?> "<?php if (!is_null($link) and $link->link->link_id == $ddlink->link_id) { ?> selected="selected"<?php } ?> ><?php print wp_specialchars($ddlink->link_name, 1); ?> </option> <?php } } ?> </select> <input class="button" type="submit" name="go" value="<?php _e('Go'); ?> »" /> </p> <?php /* endif; */ ?> <?php if (!is_null($link) and $link->found()) { ?> <p>These settings only affect posts syndicated from <strong><?php echo wp_specialchars($link->link->link_name, 1); ?> </strong>.</p> <?php } else { ?> <p>These settings affect posts syndicated from any feed unless they are overridden by settings for that specific feed.</p> <?php } ?> <?php $authorlist = fwp_author_list(); ?> <table class="form-table"> <tbody> <tr> <th>New authors</th> <td><span>Authors who haven't been syndicated before</span> <select style="max-width: 27.0em" id="unfamiliar-author" name="unfamiliar_author" onchange="contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline');"> <?php if (is_object($link) and $link->found()) { ?> <option value="site-default"<?php print $unfamiliar['site-default']; ?> >are handled according to the default for all feeds</option> <?php } ?> <option value="create"<?php $unfamiliar['create']; ?> >will have a new author account created for them</option> <?php foreach ($authorlist as $author_id => $author_name) { ?> <option value="<?php echo $author_id; ?> "<?php print $unfamiliar[$author_id]; ?> >will have their posts attributed to <?php echo $author_name; ?> </option> <?php } ?> <option value="newuser">will have their posts attributed to a new user...</option> <option value="filter"<?php print $unfamiliar['filter']; ?> >get filtered out</option> </select> <span id="unfamiliar-author-newuser">named <input type="text" name="unfamiliar_author_newuser" value="" /></span></p> </td> </tr> <?php if (is_object($link) and $link->found()) { ?> <tr><th>Syndicated authors</th> <td>For attributing posts by specific authors. Blank out a name to delete the rule. Fill in a new name at the bottom to create a new rule.</p> <table style="width: 100%"> <?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; width: 15.0em">Posts by <input type="text" name="author_rules_name[]" value="<?php echo htmlspecialchars($author_name); ?> " size="11" /></th> <td> <select id="author-rules-<?php echo $i; ?> " name="author_rules_action[]" onchange="contextual_appearance('author-rules-<?php echo $i; ?> ', 'author-rules-<?php echo $i; ?> -newuser', 'author-rules-<?php echo $i; ?> -default', 'newuser', 'inline');"> <?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> <span id="author-rules-<?php echo $i; ?> -newuser">named <input type="text" name="author_rules_newuser[]" value="" /></span> </td> </tr> <?php } } } ?> <tr> <th style="text-align: left; width: 15.0em">Posts by <input type="text" name="add_author_rule_name" size="11" /></th> <td> <select id="add-author-rule" name="add_author_rule_action" onchange="contextual_appearance('add-author-rule', 'add-author-rule-newuser', 'add-author-rule-default', 'newuser', 'inline');"> <?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> <span id="add-author-rule-newuser">named <input type="text" name="add_author_rule_newuser" value="" /></span> </td> </tr> </table> </td> </tr> <?php } ?> <?php if (!(is_object($link) and $link->found())) { ?> <tr> <th scope="row">Matching Authors</th> <td><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', 'block', /*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></td> </tr> <?php } else { ?> <th scope="row">Fixing mis-matched authors:</th> <td><p style="margin: 0.5em 0px">Take all the posts from this feed attributed to <select name="fix_mismatch_from"> <?php foreach ($authorlist as $author_id => $author_name) { ?> <option value="<?php echo $author_id; ?> "><?php echo $author_name; ?> </option> <?php } ?> </select> and instead <select id="fix-mismatch-to" name="fix_mismatch_to" onchange="contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline');"> <?php foreach ($authorlist as $author_id => $author_name) { ?> <option value="<?php echo $author_id; ?> ">re-assign them to <?php echo $author_name; ?> </option> <?php } ?> <option value="newuser">re-assign them to a new user...</option> <option value="filter">delete them</option> </select> <span id="fix-mismatch-to-newuser">named <input type="text" name="fix_mismatch_to_newuser" value="" /></span> <input type="submit" class="button" name="fix_mismatch" value="Fix it!" /> </td> </td> <?php } ?> </tbody> </table> <p class="submit"> <input class="button-primary" type="submit" name="save" value="Save Changes" /> </p> <script type="text/javascript"> contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline'); <?php if (is_object($link) and $link->found()) { for ($j = 1; $j <= $i; $j++) { ?> contextual_appearance('author-rules-<?php echo $j; ?> ', 'author-rules-<?php echo $j; ?> -newuser', 'author-rules-<?php echo $j; ?> -default', 'newuser', 'inline'); <?php } ?> contextual_appearance('add-author-rule', 'add-author-rule-newuser', 'add-author-rule-default', 'newuser', 'inline'); contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline'); <?php } else { ?> contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', 'block', /*checkbox=*/ true); <?php } ?> </script> </form> </div> <!-- class="wrap" --> <?php } }
function FeedWordPress() { $this->feeds = array(); $links = FeedWordPress::syndicated_links(); if ($links) { foreach ($links as $link) { $this->feeds[] =& new SyndicatedLink($link); } } }
function display_feed_select_dropdown() { $links = FeedWordPress::syndicated_links(); ?> <p id="post-search"> <select name="link_id" class="fwpfs" style="max-width: 20.0em;"> <option value="*"<?php if ($this->for_default_settings()) { ?> selected="selected"<?php } ?> >- defaults for all feeds -</option> <?php if ($links) { foreach ($links as $ddlink) { ?> <option value="<?php print (int) $ddlink->link_id; ?> "<?php if (!is_null($this->link) and $this->link->id == $ddlink->link_id) { ?> selected="selected"<?php } ?> ><?php print esc_html($ddlink->link_name); ?> </option> <?php } } ?> </select> <input class="button" type="submit" name="go" value="<?php _e('Go'); ?> »" /> </p> <?php }