| 1 |
<?php |
| 2 |
################################################################################ |
| 3 |
## LEGACY API: Replicate or mock up functions for legacy support purposes ###### |
| 4 |
################################################################################ |
| 5 |
|
| 6 |
class FeedWordPressCompatibility { |
| 7 |
|
| 8 |
/** |
| 9 |
* FeedWordPressCompatibility::test_version: test version of WordPress |
| 10 |
* based on the database schema version. |
| 11 |
* |
| 12 |
* @param int $floor The minimum version necessary |
| 13 |
* @param mixed $ceiling The first version that is too high. If omitted |
| 14 |
* or NULL, no version is too high. |
| 15 |
* @return bool TRUE if within the range of versions, FALSE if too low |
| 16 |
* or too high. |
| 17 |
*/ |
| 18 |
static function test_version ($floor, $ceiling = null) { |
| 19 |
global $wp_db_version; |
| 20 |
|
| 21 |
$ver = (isset($wp_db_version) ? $wp_db_version : 0); |
| 22 |
$good = ($ver >= $floor); |
| 23 |
if (!is_null($ceiling)) : |
| 24 |
$good = ($good and ($ver < $ceiling)); |
| 25 |
endif; |
| 26 |
return $good; |
| 27 |
} /* FeedWordPressCompatibility::test_version() */ |
| 28 |
|
| 29 |
static function insert_link_category ($name) { |
| 30 |
global $wpdb; |
| 31 |
|
| 32 |
// WordPress 2.3+ term/taxonomy API |
| 33 |
$term = wp_insert_term($name, 'link_category'); |
| 34 |
|
| 35 |
// OK: returned array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id) |
| 36 |
if (!is_wp_error($term)) : |
| 37 |
$cat_id = $term['term_id']; |
| 38 |
|
| 39 |
// Error: term with this name already exists. Well, let's use that then. |
| 40 |
elseif ($term->get_error_code() == 'term_exists') : |
| 41 |
// Already-existing term ID is returned in data field |
| 42 |
$cat_id = $term->get_error_data('term_exists'); |
| 43 |
|
| 44 |
// Error: another kind of error, harder to recover from. Return WP_Error. |
| 45 |
else : |
| 46 |
$cat_id = $term; |
| 47 |
endif; |
| 48 |
|
| 49 |
// Return newly-created category ID |
| 50 |
return $cat_id; |
| 51 |
} /* FeedWordPressCompatibility::insert_link_category () */ |
| 52 |
|
| 53 |
static function link_category_id ($value, $key = 'cat_name') { |
| 54 |
global $wpdb; |
| 55 |
|
| 56 |
$cat_id = NULL; |
| 57 |
|
| 58 |
$the_term = term_exists($value, 'link_category'); |
| 59 |
|
| 60 |
// Sometimes, in some versions, we get a row |
| 61 |
if (is_array($the_term)) : |
| 62 |
$cat_id = $the_term['term_id']; |
| 63 |
|
| 64 |
// other times we get an integer result |
| 65 |
else : |
| 66 |
$cat_id = $the_term; |
| 67 |
endif; |
| 68 |
|
| 69 |
return $cat_id; |
| 70 |
} /* FeedWordPressCompatibility::link_category_id () */ |
| 71 |
|
| 72 |
static function validate_http_request ($action = -1, $capability = null) { |
| 73 |
// Only worry about this if we're using a method with significant side-effects |
| 74 |
if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') : |
| 75 |
// Limit post by user capabilities |
| 76 |
if (!is_null($capability) and !current_user_can($capability)) : |
| 77 |
wp_die(__('Cheatin’ uh?')); |
| 78 |
endif; |
| 79 |
|
| 80 |
// If check_admin_referer() checks a nonce. |
| 81 |
if (function_exists('wp_verify_nonce')) : |
| 82 |
check_admin_referer($action); |
| 83 |
|
| 84 |
// No nonces means no checking nonces. |
| 85 |
else : |
| 86 |
check_admin_referer(); |
| 87 |
endif; |
| 88 |
endif; |
| 89 |
} /* FeedWordPressCompatibility::validate_http_request() */ |
| 90 |
|
| 91 |
static function stamp_nonce ($action = -1) { |
| 92 |
// stamp form with hidden fields for a nonce in WP 2.0.3 & later |
| 93 |
if (function_exists('wp_nonce_field')) : |
| 94 |
wp_nonce_field($action); |
| 95 |
endif; |
| 96 |
} /* FeedWordPressCompatibility::stamp_nonce() */ |
| 97 |
|
| 98 |
static function bottom_script_hook ($filename) { |
| 99 |
global $fwp_path; |
| 100 |
|
| 101 |
$hook = 'admin_footer-'.$fwp_path.'/'.basename($filename); |
| 102 |
return $hook; |
| 103 |
} /* FeedWordPressCompatibility::bottom_script_hook() */ |
| 104 |
} /* class FeedWordPressCompatibility */ |
| 105 |
|
| 106 |
// Compat |
| 107 |
|
| 108 |
if (!function_exists('set_post_field')) { |
| 109 |
|
| 110 |
/** |
| 111 |
* Update data from a post field based on Post ID |
| 112 |
* |
| 113 |
* Examples of the post field will be, 'post_type', 'post_status', 'post_content', etc. |
| 114 |
* |
| 115 |
* The context values are based off of the taxonomy filter functions and |
| 116 |
* supported values are found within those functions. |
| 117 |
* |
| 118 |
* @uses sanitize_post_field() |
| 119 |
* |
| 120 |
* @param string $field Post field name |
| 121 |
* @param mixed $value New value for post field |
| 122 |
* @param id $post Post ID |
| 123 |
* @return bool Result of UPDATE query |
| 124 |
* |
| 125 |
* Included under terms of GPL from WordPress Ticket #10946 <http://core.trac.wordpress.org/attachment/ticket/10946/post.php.diff> |
| 126 |
*/ |
| 127 |
function set_post_field ($field, $value, $post_id) { |
| 128 |
global $wpdb; |
| 129 |
|
| 130 |
$post_id = absint($post_id); |
| 131 |
// sigh ... when FWP is active, I need to avoid avoid_kses_munge |
| 132 |
// $value = sanitize_post_field($field, $value, $post_id, 'db'); |
| 133 |
return $wpdb->update($wpdb->posts, array($field => $value), array('ID' => $post_id)); |
| 134 |
} /* function set_post_field () */ |
| 135 |
|
| 136 |
} /* if */ |
| 137 |
|
| 138 |
if (!function_exists('is_countable')) { |
| 139 |
|
| 140 |
// Copied from WordPress 5.3.2 wp-includes/compat.php pursuant to terms |
| 141 |
// of GPL. Provide support for is_countable() for versions of PHP < 7.3 |
| 142 |
// and for versions of WordPress < 4.9.6. -C.J. 2020/01/24 |
| 143 |
|
| 144 |
/** |
| 145 |
* Polyfill for is_countable() function added in PHP 7.3. |
| 146 |
* |
| 147 |
* Verify that the content of a variable is an array or an object |
| 148 |
* implementing the Countable interface. |
| 149 |
* |
| 150 |
* @since 4.9.6 |
| 151 |
* |
| 152 |
* @param mixed $var The value to check. |
| 153 |
* |
| 154 |
* @return bool True if `$var` is countable, false otherwise. |
| 155 |
*/ |
| 156 |
function is_countable( $var ) { |
| 157 |
return ( is_array( $var ) |
| 158 |
|| $var instanceof Countable |
| 159 |
|| $var instanceof SimpleXMLElement |
| 160 |
|| $var instanceof ResourceBundle |
| 161 |
); |
| 162 |
} |
| 163 |
|
| 164 |
} /* if */ |
| 165 |
|
| 166 |
require_once(dirname(__FILE__).'/feedwordpress-walker-category-checklist.class.php'); |
| 167 |
|
| 168 |
function fwp_category_checklist ($post_id = 0, $descendents_and_self = 0, $selected_cats = false, $params = array()) { |
| 169 |
if (is_string($params)) : |
| 170 |
$prefix = $params; |
| 171 |
$taxonomy = 'category'; |
| 172 |
elseif (is_array($params)) : |
| 173 |
$prefix = (isset($params['prefix']) ? $params['prefix'] : ''); |
| 174 |
$taxonomy = (isset($params['taxonomy']) ? $params['taxonomy'] : 'category'); |
| 175 |
endif; |
| 176 |
|
| 177 |
$walker = new FeedWordPress_Walker_Category_Checklist($params); |
| 178 |
$walker->set_prefix($prefix); |
| 179 |
$walker->set_taxonomy($taxonomy); |
| 180 |
wp_terms_checklist(/*post_id=*/ $post_id, array( |
| 181 |
'taxonomy' => $taxonomy, |
| 182 |
'descendents_and_self' => $descendents_and_self, |
| 183 |
'selected_cats' => $selected_cats, |
| 184 |
'popular_cats' => false, |
| 185 |
'walker' => $walker, |
| 186 |
'checked_ontop' => true, |
| 187 |
)); |
| 188 |
} |
| 189 |
|
| 190 |
function fwp_time_elapsed ($ts) { |
| 191 |
if (function_exists('human_time_diff')) : |
| 192 |
if ($ts >= time()) : |
| 193 |
$ret = __(human_time_diff($ts)." from now"); |
| 194 |
else : |
| 195 |
$ret = __(human_time_diff($ts)." ago"); |
| 196 |
endif; |
| 197 |
else : |
| 198 |
$ret = strftime('%x %X', $ts); |
| 199 |
endif; |
| 200 |
return $ret; |
| 201 |
} |
| 202 |
|
| 203 |
################################################################################ |
| 204 |
## UPGRADE INTERFACE: Have users upgrade DB from older versions of FWP ######### |
| 205 |
################################################################################ |
| 206 |
|
| 207 |
function fwp_upgrade_page () { |
| 208 |
if (MyPHP::post('action')=='Upgrade') : |
| 209 |
$ver = get_option('feedwordpress_version'); |
| 210 |
if (get_option('feedwordpress_version') != FEEDWORDPRESS_VERSION) : |
| 211 |
echo "<div class=\"wrap\">\n"; |
| 212 |
echo "<h2>Upgrading FeedWordPress...</h2>"; |
| 213 |
|
| 214 |
$feedwordpress = new FeedWordPress; |
| 215 |
$feedwordpress->upgrade_database($ver); |
| 216 |
echo "<p><strong>Done!</strong> Upgraded database to version ".FEEDWORDPRESS_VERSION.".</p>\n"; |
| 217 |
echo "<form action=\"\" method=\"get\">\n"; |
| 218 |
echo "<div class=\"submit\"><input type=\"hidden\" name=\"page\" value=\"syndication.php\" />"; |
| 219 |
echo "<input type=\"submit\" value=\"Continue »\" /></form></div>\n"; |
| 220 |
echo "</div>\n"; |
| 221 |
return; |
| 222 |
else : |
| 223 |
echo "<div class=\"updated\"><p>Already at version ".FEEDWORDPRESS_VERSION."!</p></div>"; |
| 224 |
endif; |
| 225 |
endif; |
| 226 |
?> |
| 227 |
<div class="wrap"> |
| 228 |
<h2>Upgrade FeedWordPress</h2> |
| 229 |
|
| 230 |
<p>It appears that you have installed FeedWordPress |
| 231 |
<?php echo FEEDWORDPRESS_VERSION; ?> as an upgrade to an existing installation of |
| 232 |
FeedWordPress. That's no problem, but you will need to take a minute out first |
| 233 |
to upgrade your database: some necessary changes in how the software keeps |
| 234 |
track of posts and feeds will cause problems such as duplicate posts and broken |
| 235 |
templates if we were to continue without the upgrade.</p> |
| 236 |
|
| 237 |
<p>Note that most of FeedWordPress's functionality is temporarily disabled |
| 238 |
until we have successfully completed the upgrade. Everything should begin |
| 239 |
working as normal again once the upgrade is complete. There's extraordinarily |
| 240 |
little chance of any damage as the result of the upgrade, but if you're paranoid |
| 241 |
like me you may want to back up your database before you proceed.</p> |
| 242 |
|
| 243 |
<p>This may take several minutes for a large installation.</p> |
| 244 |
|
| 245 |
<form action="" method="post"> |
| 246 |
<?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_upgrade'); ?> |
| 247 |
<div class="submit"><input type="submit" name="action" value="Upgrade" /></div> |
| 248 |
</form> |
| 249 |
</div> |
| 250 |
<?php |
| 251 |
} // function fwp_upgrade_page () |
| 252 |
|
| 253 |
function remove_dummy_zero ($var) { |
| 254 |
return !(is_numeric($var) and ((int) $var == 0)); |
| 255 |
} |
| 256 |
|
| 257 |
|