Commit 3aa1f60b authored by lechuck's avatar lechuck Committed by lucha
Browse files

Upgrade feedwordpress to 2014.0805

parent 2de0cc2e
......@@ -6,7 +6,7 @@ class FeedWordPressCategoriesPage extends FeedWordPressAdminPage {
if (is_numeric($link) and -1 == $link) :
$link = $this->submitted_link();
endif;
FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpresscategories', $link);
$this->dispatch = 'feedwordpress_admin_page_categories';
$this->pagenames = array(
......@@ -16,7 +16,7 @@ class FeedWordPressCategoriesPage extends FeedWordPressAdminPage {
);
$this->filename = __FILE__;
}
function unfamiliar_category_label ($name) {
if (preg_match('/^create:(.*)$/', $name, $refs)) :
$tax = get_taxonomy($refs[1]);
......@@ -24,11 +24,11 @@ class FeedWordPressCategoriesPage extends FeedWordPressAdminPage {
endif;
return $name;
}
function feed_categories_box ($page, $box = NULL) {
$link = $page->link;
$globalPostType = get_option('feedwordpress_syndicated_post_type', 'post');
if ($this->for_feed_settings()) :
$post_type = $link->setting('syndicated post type', 'syndicated_post_type', 'post');
......@@ -42,7 +42,7 @@ class FeedWordPressCategoriesPage extends FeedWordPressAdminPage {
$tagLikeTaxonomies = array();
foreach ($taxonomies as $tax) :
$taxonomy = get_taxonomy($tax);
if (!$taxonomy->hierarchical) :
$tagLikeTaxonomies[] = $tax;
endif;
......@@ -62,12 +62,12 @@ class FeedWordPressCategoriesPage extends FeedWordPressAdminPage {
);
endforeach;
endforeach;
foreach ($unmatched as $what => $um) :
$unmatched[$what]['null'] = array('label' => __('Don\'t create any matching terms'));
$unmatchedRadio[$what]['null'] = '';
endforeach;
$globalUnmatched = array(
'category' => FeedWordPress::on_unfamiliar('category'),
'post_tag' => FeedWordPress::on_unfamiliar('post_tag'),
......@@ -77,21 +77,21 @@ class FeedWordPressCategoriesPage extends FeedWordPressAdminPage {
if ($value=='tag') : $value = 'create:post_tag'; endif;
$globalUnmatched[$what] = $value;
endforeach;
$globalMatch['cats'] = get_option('feedwordpress_match_cats', $taxonomies);
$globalMatch['tags'] = get_option('feedwordpress_match_tags', $tagLikeTaxonomies);
$globalMatch['filter'] = get_option('feedwordpress_match_filter', array());
$globalMatchLabels = array();
$nothingDoing = array('cats' => "won't try to match", 'tags' => "won't try to match", "filter" => "won't filter");
foreach ($globalMatch as $what => $domain) :
$labels = array(); $domain = array_filter($domain, 'remove_dummy_zero');
foreach ($domain as $tax) :
$tax = get_taxonomy($tax);
$labels[] = $tax->labels->name;
endforeach;
if (count($labels) > 0) :
$globalMatchLabels[$what] = implode(", ", $labels);
else :
......@@ -126,30 +126,30 @@ class FeedWordPressCategoriesPage extends FeedWordPressAdminPage {
$unmatchedDefault[$what] = $opts[0];
$unmatchedColumns[$what] = array();
endif;
$ucKey[$what] = $link->setting("unfamiliar $what", NULL, NULL);
endforeach;
$match['cats'] = $this->link->setting('match/cats', NULL, NULL);
$match['tags'] = $this->link->setting('match/tags', NULL, NULL);
$match['filter'] = $this->link->setting('match/filter', NULL, NULL);
else :
foreach ($unmatched as $what => $um) :
$ucKey[$what] = FeedWordPress::on_unfamiliar($what);
$ucKey[$what] = FeedWordPress::on_unfamiliar($what);
endforeach;
$match = $globalMatch;
endif;
foreach ($ucKey as $what => $uck) :
if ($uck == 'tag') : $uck = 'create:post_tag'; endif;
if ($uck == 'create') : $uck = 'create:category'; endif;
if (!is_string($uck)) :
$uck = $unmatchedDefault[$what];
endif;
$ucKey[$what] = $uck;
if (!array_key_exists($uck, $unmatchedRadio[$what])) :
$obsoleteLi = array(
$uck => array(
......@@ -159,12 +159,12 @@ class FeedWordPressCategoriesPage extends FeedWordPressAdminPage {
$unmatched[$what] = array_merge($obsoleteLi, $unmatched[$what]);
$unmatchedRadio[$what][$uck] = ' disabled="disabled"';
endif;
$unmatchedRadio[$what][$uck] .= ' checked="checked"';
$unmatchedColumns[$what][] = $unmatched[$what];
endforeach;
$defaulted = array();
foreach ($match as $what => $set) :
$defaulted[$what] = false;
......@@ -175,7 +175,7 @@ class FeedWordPressCategoriesPage extends FeedWordPressAdminPage {
$match[$what] = $globalMatch[$what];
endif;
endif;
if (!$defaulted[$what] or $this->for_feed_settings()) :
foreach ($set as $against) :
if (array_key_exists($against, $matchUl[$what])) :
......@@ -350,7 +350,7 @@ least one local <strong><?php $l = $li['labels']; print $l->singular_name; ?></s
<?php if ($page->for_feed_settings()) : ?>
<tr>
<th scope="row">Multiple categories:</th>
<td>
<td>
<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']); endif; ?>" />
<p class="setting-description">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
......@@ -376,9 +376,11 @@ blank.</p></td>
'post_tag' => 'tags',
);
}
function categories_box ($page, $box = NULL) {
$link = $page->link;
$dummy = null;
$syndicatedlink = new SyndicatedLink($dummy);
if ($this->for_feed_settings()) :
$post_type = $link->setting('syndicated post type', 'syndicated_post_type', 'post');
......@@ -417,7 +419,7 @@ blank.</p></td>
$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);
......@@ -430,7 +432,7 @@ blank.</p></td>
else :
$cats = $globalCats;
endif;
if ($page->for_feed_settings()) :
?>
<table class="twofer">
......@@ -439,17 +441,17 @@ blank.</p></td>
<td class="primary">
<?php
endif;
$dogs = SyndicatedPost::category_ids($cats, /*unfamiliar=*/ NULL, /*taxonomies=*/ array($tax));
$dogs = $syndicatedlink->category_ids(/*post=*/ NULL, $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));
$globalDogs = $syndicatedlink->category_ids(/*post=*/ NULL, $globalCats, /*unfamiliar=*/ 'create:'.$tax, /*taxonomies=*/ array($tax));
$siteWideHref = $this->admin_page_href(basename(__FILE__));
if ($page->for_feed_settings()) :
......@@ -472,7 +474,7 @@ blank.</p></td>
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>
......@@ -493,7 +495,7 @@ blank.</p></td>
</table>
<?php
} /* FeedWordPressCategoriesPage::categories_box () */
function save_settings ($post) {
if (isset($post['match_categories'])) :
foreach ($post['match_categories'] as $what => $set) :
......@@ -504,7 +506,7 @@ blank.</p></td>
and $post['match_default'][$what]=='yes') :
$set = NULL; // Defaulted!
endif;
$this->update_setting("match/$what", $set, NULL);
endforeach;
endif;
......@@ -512,9 +514,9 @@ blank.</p></td>
$settingMap = $this->term_setting_map();
$saveTerms = array(); $separateSaveTerms = array('category' => array(), 'post_tag' => array());
if (!isset($post['tax_input'])) : $post['tax_input'] = array(); endif;
// Merge in data from older-notation category check boxes
if (isset($post['post_category'])) :
// Just merging in for processing below.
......@@ -537,7 +539,7 @@ blank.</p></td>
$saveTerms[$tax] = explode(",", $terms);
endif;
$saveTerms[$tax] = array_map('trim', $saveTerms[$tax]);
if (isset($optionMap[$tax])) :
$separateSaveTerms[$tax] = $saveTerms[$tax];
unset($saveTerms[$tax]);
......@@ -546,10 +548,10 @@ blank.</p></td>
if (isset($post['post_category'])) :
foreach ($post['post_category'] as $cat) :
$separateSaveTerms['category'][] = '{category#'.$cat.'}';
$separateSaveTerms['category'][] = '{category#'.$cat.'}';
endforeach;
endif;
// Unmatched categories and tags
foreach (array('category', 'post_tag') as $what) :
if (isset($post["unfamiliar_{$what}"])) :
......@@ -560,7 +562,7 @@ blank.</p></td>
);
endif;
endforeach;
// Categories and Tags
foreach ($separateSaveTerms as $tax => $terms) :
if ($this->for_feed_settings()) :
......@@ -573,7 +575,7 @@ blank.</p></td>
endif;
endif;
endforeach;
// Other terms
$this->update_setting(array('feed'=>'terms', 'global'=>'syndication_terms'), $saveTerms, array());
......@@ -582,7 +584,7 @@ blank.</p></td>
if (isset($post['cat_split'])) :
$this->link->update_setting('cat_split', trim($post['cat_split']), '');
endif;
// Treat global terms (cats, tags, etc.) as additional,
// or as defaults to be overridden and replaced?
if (isset($post['add_global'])) :
......@@ -593,18 +595,18 @@ blank.</p></td>
endif;
parent::save_settings($post);
} /* FeedWordPressCategoriesPage::save_settings() */
function display () {
////////////////////////////////////////////////
// Display settings boxes //////////////////////
////////////////////////////////////////////////
$this->boxes_by_methods = array(
'feed_categories_box' => __('Feed Categories & Tags'),
'categories_box' => array('title' => __('Categories'), 'id' => 'categorydiv'),
);
parent::display();
parent::display();
}
}
......
......@@ -15,9 +15,9 @@ class FeedWordPressCompatibility {
* @return bool TRUE if within the range of versions, FALSE if too low
* or too high.
*/
/*static*/ function test_version ($floor, $ceiling = null) {
static function test_version ($floor, $ceiling = null) {
global $wp_db_version;
$ver = (isset($wp_db_version) ? $wp_db_version : 0);
$good = ($ver >= $floor);
if (!is_null($ceiling)) :
......@@ -26,7 +26,7 @@ class FeedWordPressCompatibility {
return $good;
} /* FeedWordPressCompatibility::test_version() */
/*static*/ function insert_link_category ($name) {
static function insert_link_category ($name) {
global $wpdb;
// WordPress 2.3+ term/taxonomy API
......@@ -45,12 +45,12 @@ class FeedWordPressCompatibility {
else :
$cat_id = $term;
endif;
// Return newly-created category ID
return $cat_id;
} /* FeedWordPressCompatibility::insert_link_category () */
/*static*/ function link_category_id ($value, $key = 'cat_name') {
static function link_category_id ($value, $key = 'cat_name') {
global $wpdb;
$cat_id = NULL;
......@@ -65,11 +65,11 @@ class FeedWordPressCompatibility {
else :
$cat_id = $the_term;
endif;
return $cat_id;
} /* FeedWordPressCompatibility::link_category_id () */
/*static*/ function validate_http_request ($action = -1, $capability = null) {
static function validate_http_request ($action = -1, $capability = null) {
// Only worry about this if we're using a method with significant side-effects
if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') :
// Limit post by user capabilities
......@@ -87,15 +87,15 @@ class FeedWordPressCompatibility {
endif;
endif;
} /* FeedWordPressCompatibility::validate_http_request() */
/*static*/ function stamp_nonce ($action = -1) {
static function stamp_nonce ($action = -1) {
// stamp form with hidden fields for a nonce in WP 2.0.3 & later
if (function_exists('wp_nonce_field')) :
wp_nonce_field($action);
endif;
} /* FeedWordPressCompatibility::stamp_nonce() */
/*static*/ function bottom_script_hook ($filename) {
static function bottom_script_hook ($filename) {
global $fwp_path;
$hook = 'admin_footer-'.$fwp_path.'/'.basename($filename);
......@@ -125,11 +125,11 @@ if (!function_exists('set_post_field')) {
* Included under terms of GPL from WordPress Ticket #10946 <http://core.trac.wordpress.org/attachment/ticket/10946/post.php.diff>
*/
function set_post_field ($field, $value, $post_id) {
global $wpdb;
global $wpdb;
$post_id = absint($post_id);
// sigh ... when FWP is active, I need to avoid avoid_kses_munge
// $value = sanitize_post_field($field, $value, $post_id, 'db');
// $value = sanitize_post_field($field, $value, $post_id, 'db');
return $wpdb->update($wpdb->posts, array($field => $value), array('ID' => $post_id));
} /* function set_post_field () */
......@@ -145,10 +145,10 @@ function fwp_category_checklist ($post_id = 0, $descendents_and_self = 0, $selec
$prefix = (isset($params['prefix']) ? $params['prefix'] : '');
$taxonomy = (isset($params['taxonomy']) ? $params['taxonomy'] : 'category');
endif;
$walker = new FeedWordPress_Walker_Category_Checklist($params);
$walker->set_prefix($prefix);
$walker->set_taxonomy($taxonomy);
$walker->set_taxonomy($taxonomy);
wp_terms_checklist(/*post_id=*/ $post_id, array(
'taxonomy' => $taxonomy,
'descendents_and_self' => $descendents_and_self,
......
......@@ -7,7 +7,7 @@ class FeedWordPressDiagnosticsPage extends FeedWordPressAdminPage {
FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpressdiagnosticspage');
$this->dispatch = 'feedwordpress_diagnostics';
$this->filename = __FILE__;
$this->test_html = array();
add_action('feedwordpress_diagnostics_do_http_test', array($this, 'do_http_test'), 10, 1);
}
......@@ -17,15 +17,15 @@ class FeedWordPressDiagnosticsPage extends FeedWordPressAdminPage {
function display () {
global $wpdb, $wp_db_version, $fwp_path;
global $fwp_post;
if (FeedWordPress::needs_upgrade()) :
fwp_upgrade_page();
return;
endif;
// If this is a POST, validate source and user credentials
FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_diagnostics', /*capability=*/ 'manage_options');
if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') :
$this->accept_POST($fwp_post);
do_action('feedwordpress_admin_page_diagnostics_save', $fwp_post, $this);
......@@ -47,7 +47,7 @@ class FeedWordPressDiagnosticsPage extends FeedWordPressAdminPage {
'updates_box' => __('Updates'),
'tests_box' => __('Diagnostic Tests'),
);
foreach ($boxes_by_methods as $method => $title) :
add_meta_box(
/*id=*/ 'feedwordpress_'.$method,
......@@ -76,13 +76,13 @@ class FeedWordPressDiagnosticsPage extends FeedWordPressAdminPage {
or isset($post['feedwordpress_diagnostics_do'])) :
update_option('feedwordpress_debug', $post['feedwordpress_debug']);
update_option('feedwordpress_secret_key', $post['feedwordpress_secret_key']);
if (!isset($post['diagnostics_output'])
or !is_array($post['diagnostics_output'])) :
$post['diagnostics_output'] = array();
endif;
update_option('feedwordpress_diagnostics_output', $post['diagnostics_output']);
if (!isset($post['diagnostics_show'])
or !is_array($post['diagnostics_show'])) :
$post['diagnostics_show'] = array();
......@@ -95,7 +95,7 @@ class FeedWordPressDiagnosticsPage extends FeedWordPressAdminPage {
else :
delete_option('feedwordpress_diagnostics_persistent_errors_hours');
endif;
if (in_array('email', $post['diagnostics_output'])) :
$ded = $post['diagnostics_email_destination'];
if ('mailto'==$ded) :
......@@ -106,18 +106,18 @@ class FeedWordPressDiagnosticsPage extends FeedWordPressAdminPage {
else :
delete_option('feedwordpress_diagnostics_email_destination');
endif;
if (isset($post['feedwordpress_diagnostics_do'])) :
foreach ($post['feedwordpress_diagnostics_do'] as $do => $value) :
do_action('feedwordpress_diagnostics_do_'.$do, $post);
endforeach;
endif;
$this->updated = true; // Default update message
endif;
} /* FeedWordPressDiagnosticsPage::accept_POST () */
function info_box ($page, $box = NULL) {
static function info_box ($page, $box = NULL) {
global $feedwordpress;
global $wp_version;
$link_category_id = FeedWordPress::link_category_id();
......@@ -147,7 +147,7 @@ class FeedWordPressDiagnosticsPage extends FeedWordPressAdminPage {
</ul>
</td>
</tr>
<tr>
<th scope="row">Link Category:</th>
<td><?php if (!is_wp_error($link_category_id)) :
......@@ -168,13 +168,13 @@ class FeedWordPressDiagnosticsPage extends FeedWordPressAdminPage {
<?php $data = $link_category_id->get_error_data(); if (!empty($data)) : ?>
<tr>
<th scope="row">Auxiliary Data:</th>
<td><pre><?php print esc_html(FeedWordPress::val($link_category_id->get_error_data())); ?></pre></td>
<td><pre><?php print esc_html(MyPHP::val($link_category_id->get_error_data())); ?></pre></td>
</tr>
<?php endif; ?>
</table>
<?php endif; ?></td>
</tr>
<tr>
<th scope="row"><?php _e('Secret Key:'); ?></th>
<td><input type="text" name="feedwordpress_secret_key" value="<?php print esc_attr($feedwordpress->secret_key()); ?>" />
......@@ -186,13 +186,13 @@ class FeedWordPressDiagnosticsPage extends FeedWordPressAdminPage {
<?php
} /* FeedWordPressDiagnosticsPage::info_box () */
function diagnostics_box ($page, $box = NULL) {
static function diagnostics_box ($page, $box = NULL) {
$settings = array();
$settings['debug'] = (get_option('feedwordpress_debug')=='yes');
$diagnostics_output = get_option('feedwordpress_diagnostics_output', array());
$users = fwp_author_list();
$ded = get_option('feedwordpress_diagnostics_email_destination', 'admins');
......@@ -202,7 +202,7 @@ class FeedWordPressDiagnosticsPage extends FeedWordPressAdminPage {
else :
$ded_addy = NULL;
endif;
// Hey ho, let's go...
?>
<table class="edit-form">
......@@ -255,16 +255,16 @@ testing but absolutely inappropriate for a production server.</p>
'mailto',
'inline'
);
} );
} );
</script>
<?php
} /* FeedWordPressDiagnosticsPage::diagnostics_box () */
/*static*/ function updates_box ($page, $box = NULL) {
static function updates_box ($page, $box = NULL) {
$hours = get_option('feedwordpress_diagnostics_persistent_errors_hours', 2);
$fields = apply_filters('feedwordpress_diagnostics', array(
'Update Diagnostics' => array(
'update_schedule:check' => 'whenever a FeedWordPress checks in on the update schedule',
'update_schedule:check' => 'whenever a FeedWordPress checks in on the update schedule',
'updated_feeds' => 'as each feed is checked for updates',
'updated_feeds:errors:persistent' => 'when attempts to update a feed have resulted in errors</label> <label>for at least <input type="number" min="1" max="360" step="1" name="diagnostics_persistent_error_hours" value="'.$hours.'" /> hours',
'updated_feeds:errors' => 'any time FeedWordPress encounters any errors while checking a feed for updates',
......@@ -276,15 +276,17 @@ testing but absolutely inappropriate for a production server.</p>
'Syndicated Post Details' => array(
'feed_items:freshness' => 'as FeedWordPress decides whether to treat an item as a new post, an update, or a duplicate of an existing post',
'feed_items:rejected' => 'when FeedWordPress rejects a post without syndicating it',
'syndicated_posts:categories' => 'as categories, tags, and other terms are added on the post',
'syndicated_posts:meta_data' => 'as syndication meta-data is added on the post',
),
'Advanced Diagnostics' => array(
'feed_items:freshness:reasons' => 'explaining the reason that a post was treated as an update to an existing post',
'feed_items:freshness:sql' => 'when FeedWordPress issues the SQL query it uses to decide whether to treat items as new, updates, or duplicates',
'feed_items:freshness:sql' => 'when FeedWordPress issues the SQL query it uses to decide whether to treat items as new, updates, or duplicates',
'syndicated_posts:categories:test' => 'as FeedWordPress checks for the familiarity of feed categories and tags',
'syndicated_posts:static_meta_data' => 'providing meta-data about syndicated posts in the Edit Posts interface',
),
), $page);
foreach ($fields as $section => $items) :
foreach ($items as $key => $label) :
$checked[$key] = '';
......@@ -317,8 +319,8 @@ testing but absolutely inappropriate for a production server.</p>
</table>
<?php
} /* FeedWordPressDiagnosticsPage::updates_box () */
function tests_box ($page, $box = NULL) {
static function tests_box ($page, $box = NULL) {
?>
<script type="text/javascript">
function clone_http_test_args_keyvalue_prototype () {
......@@ -327,7 +329,7 @@ function clone_http_test_args_keyvalue_prototype () {
newRow.find('.http_test_args_key').attr('name', 'http_test_args_key['+next+']').val('');
newRow.find('.http_test_args_value').attr('name', 'http_test_args_value['+next+']').val('');
newRow.appendTo('#http-test-args');
newRow.appendTo('#http-test-args');
return false;
}
</script>
......@@ -354,7 +356,7 @@ function clone_http_test_args_keyvalue_prototype () {
<td><a href="#http-test-args" onclick="return clone_http_test_args_keyvalue_prototype();">+ Add</a></td>
</tr>
</table>