PluginProbe
FeedWordPress / 2025.1211
FeedWordPress v2025.1211
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
← All changes | compatability.php +251 -215 2009.11112025.1211 View file →
@@ -1,112 +1,118 @@
1 1 <?php
2 -################################################################################
3 -## LEGACY API: Replicate or mock up functions for legacy support purposes ######
4 -################################################################################
2 +/**
3 + * LEGACY API: Replicate or mock up functions for legacy support purposes.
4 + *
5 + * @author radgeek
6 + */
5 7
6 -// version testing
7 -function fwp_test_wp_version ($floor, $ceiling = NULL) {
8 - global $wp_db_version;
9 -
10 - $ver = (isset($wp_db_version) ? $wp_db_version : 0);
11 - $good = ($ver >= $floor);
12 - if (!is_null($ceiling)) :
13 - $good = ($good and ($ver < $ceiling));
14 - endif;
15 - return $good;
16 -} /* function fwp_test_wp_version () */
17 -
8 +/**
9 + * Implements legacy functionality no longer present in the current WordPress
10 + * versions
11 + */
18 12 class FeedWordPressCompatibility {
19 - /*static*/ function test_version ($floor, $ceiling = null) {
20 - return fwp_test_wp_version($floor, $ceiling);
21 - } /* FeedWordPressCompatibility::test_version() */
22 13
23 - /*static*/ function insert_link_category ($name) {
24 - global $wpdb;
14 + /**
15 + * FeedWordPressCompatibility::test_version: test version of WordPress
16 + * based on the database schema version.
17 + *
18 + * @param int $floor The minimum version necessary.
19 + * @param mixed $ceiling The first version that is too high. If omitted
20 + * or NULL, no version is too high.
21 + * @return bool TRUE if within the range of versions, FALSE if too low
22 + * or too high.
23 + */
24 + static function test_version( $floor, $ceiling = null ) {
25 + global $wp_db_version;
25 26
26 - $name = $wpdb->escape($name);
27 + $ver = ( isset( $wp_db_version ) ? $wp_db_version : 0 );
28 + $good = ( $ver >= $floor );
29 + if ( ! is_null( $ceiling ) ) :
30 + $good = ( $good and ( $ver < $ceiling ) );
31 + endif;
32 + return $good;
33 + } /* FeedWordPressCompatibility::test_version() */
27 34
35 + /**
36 + * Creates a new category for the Links.
37 + *
38 + * WP dropped support for "Links".
39 + *
40 + * @param string $name New link category name.
41 + *
42 + * @return mixed Most of the time should return an array with `term_id`
43 + * and `term_taxonomy_id`, unless there was an error.
44 + */
45 + static function insert_link_category( $name ) {
28 46 // WordPress 2.3+ term/taxonomy API
29 - if (function_exists('wp_insert_term')) :
30 - $term = wp_insert_term($name, 'link_category');
47 + $term = wp_insert_term( $name, 'link_category' );
48 +
49 + // OK: returned array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id)
50 + if ( ! is_wp_error( $term ) ) :
31 51 $cat_id = $term['term_id'];
32 - // WordPress 2.1, 2.2 category API. By the way, why the fuck is this API function only available in a wp-admin module?
33 - elseif (function_exists('wp_insert_category') and !fwp_test_wp_version(FWP_SCHEMA_20, FWP_SCHEMA_21)) :
34 - $cat_id = wp_insert_category(array('cat_name' => $name));
35 - // WordPress 1.5 and 2.0.x
36 - elseif (fwp_test_wp_version(0, FWP_SCHEMA_21)) :
37 - $result = $wpdb->query("
38 - INSERT INTO $wpdb->linkcategories
39 - SET
40 - cat_id = 0,
41 - cat_name='$name',
42 - show_images='N',
43 - show_description='N',
44 - show_rating='N',
45 - show_updated='N',
46 - sort_order='name'
47 - ");
48 - $cat_id = $wpdb->insert_id;
49 - // This should never happen.
52 +
53 + // Error: term with this name already exists. Well, let's use that then.
54 + elseif ( 'term_exists' == $term->get_error_code() ) :
55 + // Already-existing term ID is returned in data field
56 + $cat_id = $term->get_error_data( 'term_exists' );
57 +
58 + // Error: another kind of error, harder to recover from. Return WP_Error.
50 59 else :
51 - FeedWordPress::critical_bug('FeedWordPress::link_category_id::wp_db_version', $wp_db_version, __LINE__);
60 + $cat_id = $term;
52 61 endif;
53 -
62 +
54 63 // Return newly-created category ID
55 64 return $cat_id;
56 65 } /* FeedWordPressCompatibility::insert_link_category () */
57 66
58 - /*static*/ function link_category_id ($value, $key = 'cat_name') {
59 - global $wpdb;
60 -
67 + /**
68 + * Returns category id for a Links category.
69 + *
70 + * "Links" became optional in WP.
71 + *
72 + * For the explanation of the values, see @see term_exists()
73 + *
74 + * @param int|string $value @see term_exists()
75 + * @param string $key Unused.
76 + * @return mixed @see term_exists()
77 + */
78 + static function link_category_id( $value, $key = 'cat_name' ) {
61 79 $cat_id = NULL;
62 80
63 - // WordPress 2.3 introduces a new taxonomy/term API
64 - if (function_exists('is_term')) :
65 - $the_term = is_term($value, 'link_category');
81 + $the_term = term_exists( $value, 'link_category' );
66 82
67 - // Sometimes, in some versions, we get a row
68 - if (is_array($the_term)) :
69 - $cat_id = $the_term['term_id'];
83 + // Sometimes, in some versions, we get a row
84 + if ( is_array( $the_term ) ) :
85 + $cat_id = $the_term['term_id'];
70 86
71 - // other times we get an integer result
72 - else :
73 - $cat_id = $the_term;
74 - endif;
75 -
76 - // WordPress 2.1 and 2.2 use a common table for both link and post categories
77 - elseif (fwp_test_wp_version(FWP_SCHEMA_21, FWP_SCHEMA_23)) :
78 - $value = $wpdb->escape($value);
79 - $cat_id = $wpdb->get_var("SELECT cat_id FROM {$wpdb->categories} WHERE {$key}='$value'");
80 -
81 - // WordPress 1.5 and 2.0.x have a separate table for link categories
82 - elseif (fwp_test_wp_version(0, FWP_SCHEMA_21)):
83 - $value = $wpdb->escape($value);
84 - $cat_id = $wpdb->get_var("SELECT cat_id FROM {$wpdb->linkcategories} WHERE {$key}='$value'");
85 -
86 - // This should never happen.
87 + // other times we get an integer result
87 88 else :
88 - FeedWordPress::critical_bug(__CLASS__.'::'.__METHOD__.'::wp_db_version', $wp_db_version, __LINE__);
89 + $cat_id = $the_term;
89 90 endif;
90 -
91 +
91 92 return $cat_id;
92 93 } /* FeedWordPressCompatibility::link_category_id () */
93 94
94 - /*static*/ function post_tags () {
95 - return FeedWordPressCompatibility::test_version(FWP_SCHEMA_23);
96 - } /* FeedWordPressCompatibility::post_tags () */
97 -
98 - /*static*/ function validate_http_request ($action = -1, $capability = null) {
95 + /**
96 + * Validate if the user has the right capability for doing this request.
97 + *
98 + * @see check_admin_referer()
99 + * @see current_user_can()
100 + *
101 + * @param int|string $action The nonce action.
102 + * @param string|null $capability Capability name.
103 + */
104 + static function validate_http_request( $action = -1, $capability = null ) {
99 105 // Only worry about this if we're using a method with significant side-effects
100 - if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') :
106 + if ( 'POST' == strtoupper( $_SERVER['REQUEST_METHOD'] ) ) :
101 107 // Limit post by user capabilities
102 - if (!is_null($capability) and !current_user_can($capability)) :
103 - wp_die(__('Cheatin&#8217; uh?'));
108 + if ( ! is_null( $capability ) and ! current_user_can( $capability ) ) :
109 + wp_die( esc_html__( 'Cheatin&rsquo; uh?' ) );
104 110 endif;
105 111
106 112 // If check_admin_referer() checks a nonce.
107 - if (function_exists('wp_verify_nonce')) :
108 - check_admin_referer($action);
113 + if ( function_exists( 'wp_verify_nonce' ) ) :
114 + check_admin_referer( $action );
109 115
110 116 // No nonces means no checking nonces.
111 117 else :
112 118 check_admin_referer();
@@ -112,157 +118,175 @@
112 118 check_admin_referer();
113 119 endif;
114 120 endif;
115 121 } /* FeedWordPressCompatibility::validate_http_request() */
116 -
117 - /*static*/ function stamp_nonce ($action = -1) {
118 - // stamp form with hidden fields for a nonce in WP 2.0.3 & later
119 - if (function_exists('wp_nonce_field')) :
120 - wp_nonce_field($action);
122 +
123 + /**
124 + * Stamps form with hidden fields for a nonce in WP 2.0.3 & later.
125 + *
126 + * Basically just checks if the function wp_nonce_field() exists, and, if so,
127 + * uses it; on earlier WP versions, just skips it.
128 + *
129 + * @todo What about the HTML which might get returned by wp_nonce_field()?
130 + * (gwyneth 20230917)
131 + *
132 + * @see wp_nonce_field()
133 + *
134 + * @param int|string $action Optional action name, defaults to -1.
135 + *
136 + */
137 + static function stamp_nonce( $action = -1 ) {
138 + if ( function_exists( 'wp_nonce_field' ) ) :
139 + wp_nonce_field( $action );
121 140 endif;
122 141 } /* FeedWordPressCompatibility::stamp_nonce() */
123 -
124 - /*static*/ function bottom_script_hook ($filename) {
142 +
143 + static function bottom_script_hook ($filename) {
125 144 global $fwp_path;
126 145
127 - $hook = 'admin_footer';
128 - if (FeedWordPressCompatibility::test_version(FWP_SCHEMA_28)) : // WordPress 2.8+
129 - $hook = $hook . '-' . $fwp_path . '/' . basename($filename);
130 - endif;
146 + $hook = 'admin_footer-'.$fwp_path.'/'.basename($filename);
131 147 return $hook;
132 148 } /* FeedWordPressCompatibility::bottom_script_hook() */
133 149 } /* class FeedWordPressCompatibility */
134 150
135 -define('FEEDWORDPRESS_AND_TAGS', (FeedWordPressCompatibility::post_tags() ? ' & Tags' : ''));
151 +// Compat
136 152
137 -if (!function_exists('stripslashes_deep')) {
138 - function stripslashes_deep($value) {
139 - $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
140 - return $value;
141 - }
142 -}
153 +if ( ! function_exists( 'set_post_field' ) ) {
154 + /**
155 + * Update data from a post field based on Post ID.
156 + *
157 + * Examples of the post field will be, 'post_type', 'post_status', 'post_content', etc.
158 + *
159 + * The context values are based off of the taxonomy filter functions and
160 + * supported values are found within those functions.
161 + *
162 + * @uses sanitize_post_field()
163 + *
164 + * @param string $field Post field name.
165 + * @param mixed $value New value for post field.
166 + * @param id $post Post ID.
167 + * @return bool Result of UPDATE query.
168 + *
169 + * Included under terms of GPL from WordPress Ticket #10946 <http://core.trac.wordpress.org/attachment/ticket/10946/post.php.diff>
170 + */
171 + function set_post_field ($field, $value, $post_id) {
172 + global $wpdb;
143 173
144 -if (!function_exists('get_option')) {
145 - function get_option ($option) {
146 - return get_settings($option);
147 - }
148 -}
149 -if (!function_exists('current_user_can')) {
150 - $fwp_capability['manage_options'] = 6;
151 - $fwp_capability['manage_links'] = 5;
152 - function current_user_can ($task) {
153 - global $user_level;
174 + $post_id = absint($post_id);
175 + // sigh ... when FWP is active, I need to avoid avoid_kses_munge
176 + // $value = sanitize_post_field($field, $value, $post_id, 'db');
177 + return $wpdb->update($wpdb->posts, array($field => $value), array('ID' => $post_id));
178 + } /* function set_post_field () */
154 179
155 - $can = false;
180 +} /* if */
156 181
157 - // This is **not** a full replacement for current_user_can. It
158 - // is only for checking the capabilities we care about via the
159 - // WordPress 1.5 user levels.
160 - switch ($task) :
161 - case 'manage_options':
162 - $can = ($user_level >= 6);
163 - break;
164 - case 'manage_links':
165 - $can = ($user_level >= 5);
166 - break;
167 - case 'edit_files':
168 - $can = ($user_level >= 9);
169 - break;
170 - endswitch;
171 - return $can;
182 +if ( ! function_exists( 'is_countable' ) ) {
183 + /* Copied from WordPress 5.3.2 wp-includes/compat.php pursuant to terms
184 + * of GPL. Provide support for is_countable() for versions of PHP < 7.3
185 + * and for versions of WordPress < 4.9.6. -C.J. 2020/01/24
186 + */
187 +
188 + /**
189 + * Polyfill for is_countable() function added in PHP 7.3.
190 + *
191 + * Verify that the content of a variable is an array or an object
192 + * implementing the Countable interface.
193 + *
194 + * @since 4.9.6
195 + *
196 + * @param mixed $var The value to check.
197 + *
198 + * @return bool True if `$var` is countable, false otherwise.
199 + */
200 + function is_countable( $var ) {
201 + return ( is_array( $var )
202 + || $var instanceof Countable
203 + || $var instanceof SimpleXMLElement
204 + || $var instanceof ResourceBundle
205 + );
172 206 }
173 -} else {
174 - $fwp_capability['manage_options'] = 'manage_options';
175 - $fwp_capability['manage_links'] = 'manage_links';
176 -}
177 -if (!function_exists('sanitize_user')) {
178 - function sanitize_user ($text, $strict = false) {
179 - return $text; // Don't munge it if it wasn't munged going in...
180 - }
181 -}
182 -if (!function_exists('wp_insert_user')) {
183 - function wp_insert_user ($userdata) {
184 - global $wpdb;
207 +} /* if */
185 208
186 - #-- Help WordPress 1.5.x quack like a duck
187 - $login = $userdata['user_login'];
188 - $author = $userdata['display_name'];
189 - $nice_author = $userdata['user_nicename'];
190 - $email = $userdata['user_email'];
191 - $url = $userdata['user_url'];
209 +require_once dirname(__FILE__) . '/feedwordpress-walker-category-checklist.class.php';
192 210
193 - $wpdb->query (
194 - "INSERT INTO $wpdb->users
195 - SET
196 - ID='0',
197 - user_login='$login',
198 - user_firstname='$author',
199 - user_nickname='$author',
200 - user_nicename='$nice_author',
201 - user_description='$author',
202 - user_email='$email',
203 - user_url='$url'");
204 - $id = $wpdb->insert_id;
205 -
206 - return $id;
207 - }
208 -} /* if (!function_exists('wp_insert_user')) */
211 +/**
212 + * Checks if we have all the categories we need.
213 + *
214 + * @see wp_terms_checklist()
215 + *
216 + * @param int $post_id Optional, defaults to zero.
217 + * @param int $descendents_and_self @see wp_terms_checklist()
218 + * @param bool $selected_cats @see wp_terms_checklist()
219 + * @param string|array $params @see wp_terms_checklist()
220 + *
221 + * @uses wp_terms_checklist()
222 + * @uses FeedWordPress_Walker_Category_Checklist()
223 + */
224 +function fwp_category_checklist( $post_id = 0, $descendents_and_self = 0, $selected_cats = false, $params = array() ) {
225 + if ( is_string( $params ) ) :
226 + $prefix = $params;
227 + $taxonomy = 'category';
228 + elseif ( is_array( $params ) ) :
229 + $prefix = ( isset( $params['prefix'] ) ? $params['prefix'] : '' );
230 + $taxonomy = ( isset( $params['taxonomy'] ) ? $params['taxonomy'] : 'category' );
231 + endif;
209 232
210 -if (!function_exists('wp_die')) {
211 - function wp_die ( $message, $title = '', $args = array() ) {
212 - die($message);
213 - } /* wp_die() */
214 -} /* if */
233 + $walker = new FeedWordPress_Walker_Category_Checklist( $params );
234 + $walker->set_prefix( $prefix );
235 + $walker->set_taxonomy( $taxonomy );
236 + wp_terms_checklist( /*post_id=*/ $post_id, array(
237 + 'taxonomy' => $taxonomy,
238 + 'descendents_and_self' => $descendents_and_self,
239 + 'selected_cats' => $selected_cats,
240 + 'popular_cats' => false,
241 + 'walker' => $walker,
242 + 'checked_ontop' => true,
243 + ) );
244 +} /* function fwp_category_checklist() */
215 245
216 -function fwp_category_checklist ($post_id = 0, $descendents_and_self = 0, $selected_cats = false) {
217 - if (function_exists('wp_category_checklist')) :
218 - wp_category_checklist($post_id, $descendents_and_self, $selected_cats);
219 - else :
220 - // selected_cats is an array of integer cat_IDs / term_ids for
221 - // the categories that should be checked
222 - global $post_ID;
246 +/**
247 + * Calculates the difference between a timestamp and the current time.
248 + *
249 + * @param int $ts Timestamp.
250 + *
251 + * @return string A human-readable indication of the elapsed time.
252 + */
253 +function fwp_time_elapsed( $ts ) {
254 + if ( ! is_int( $ts ) ) :
223 255
224 - $cats = get_nested_categories();
225 -
226 - // Undo damage from usort() in WP 2.0
227 - $dogs = array();
228 - foreach ($cats as $cat) :
229 - $dogs[$cat['cat_ID']] = $cat;
230 - endforeach;
231 - foreach ($selected_cats as $cat_id) :
232 - $dogs[$cat_id]['checked'] = true;
233 - endforeach;
234 - write_nested_categories($dogs);
235 256 endif;
236 -}
237 -
238 -function fwp_time_elapsed ($ts) {
239 - if (function_exists('human_time_diff')) :
240 - if ($ts >= time()) :
241 - $ret = __(human_time_diff($ts)." from now");
257 + if ( function_exists( 'human_time_diff' ) ) :
258 + if ( $ts >= time() ) :
259 + $ret = human_time_diff( $ts ) . __( " from now" );
242 260 else :
243 - $ret = __(human_time_diff($ts)." ago");
261 + $ret = human_time_diff( $ts ) . __( " ago" );
244 262 endif;
245 263 else :
246 - $ret = strftime('%x %X', $ts);
264 + // $ret = strftime( '%x %X', $ts ); // deprecated
265 + $ret = date( "Y-m-d H:i:s", $ts );
247 266 endif;
248 267 return $ret;
249 -}
268 +} /* function fwp_time_elapsed() */
250 269
251 -################################################################################
252 -## UPGRADE INTERFACE: Have users upgrade DB from older versions of FWP #########
253 -################################################################################
254 -
255 -function fwp_upgrade_page () {
256 - if (isset($GLOBALS['fwp_post']['action']) and $GLOBALS['fwp_post']['action']=='Upgrade') :
257 - $ver = get_option('feedwordpress_version');
258 - if (get_option('feedwordpress_version') != FEEDWORDPRESS_VERSION) :
270 +/**
271 + * UPGRADE INTERFACE: Have users upgrade DB from older versions of FWP.
272 + *
273 + * @uses FeedWordPress
274 + * @uses FeedWordPress::upgrade_database()
275 + * @uses get_option()
276 + * @uses MyPHP::post()
277 + */
278 +function fwp_upgrade_page() {
279 + if ( 'Upgrade' == MyPHP::post( 'action' ) ) :
280 + /** @var string Current FeedWordPress version. */
281 + $ver = get_option( 'feedwordpress_version' );
282 + if ( ! empty( $ver ) and FEEDWORDPRESS_VERSION != $ver ) :
259 283 echo "<div class=\"wrap\">\n";
260 - echo "<h2>Upgrading FeedWordPress...</h2>";
284 + echo "<h2>" . esc_html__( "Upgrading FeedWordPress..." ) . "</h2>";
261 285
262 - $feedwordpress =& new FeedWordPress;
263 - $feedwordpress->upgrade_database($ver);
264 - echo "<p><strong>Done!</strong> Upgraded database to version ".FEEDWORDPRESS_VERSION.".</p>\n";
286 + $feedwordpress = new FeedWordPress;
287 + $feedwordpress->upgrade_database( $ver );
288 + echo "<p><strong>" . esc_html__( "Done!" ) . "</strong> " . esc_html__( "Upgraded database to version " ) . esc_html( FEEDWORDPRESS_VERSION ) . ".</p>\n";
265 289 echo "<form action=\"\" method=\"get\">\n";
266 290 echo "<div class=\"submit\"><input type=\"hidden\" name=\"page\" value=\"syndication.php\" />";
267 291 echo "<input type=\"submit\" value=\"Continue &raquo;\" /></form></div>\n";
268 292 echo "</div>\n";
@@ -267,34 +291,46 @@
267 291 echo "<input type=\"submit\" value=\"Continue &raquo;\" /></form></div>\n";
268 292 echo "</div>\n";
269 293 return;
270 294 else :
271 - echo "<div class=\"updated\"><p>Already at version ".FEEDWORDPRESS_VERSION."!</p></div>";
295 + echo "<div class=\"updated\"><p>" . esc_html__( "Already at version " ) . esc_html( FEEDWORDPRESS_VERSION ) . "!</p></div>";
272 296 endif;
273 297 endif;
274 298 ?>
275 299 <div class="wrap">
276 -<h2>Upgrade FeedWordPress</h2>
300 +<h2><?php esc_html_e( 'Upgrade FeedWordPress' ); ?></h2>
277 301
278 -<p>It appears that you have installed FeedWordPress
279 -<?php echo FEEDWORDPRESS_VERSION; ?> as an upgrade to an existing installation of
280 -FeedWordPress. That's no problem, but you will need to take a minute out first
302 +<p><?php esc_html_e( 'It appears that you have installed FeedWordPress' ); ?>
303 +<?php echo esc_html( FEEDWORDPRESS_VERSION ); ?> <?php esc_html_e( 'as an upgrade to an existing installation of
304 +FeedWordPress. That\'s no problem, but you will need to take a minute out first
281 305 to upgrade your database: some necessary changes in how the software keeps
282 306 track of posts and feeds will cause problems such as duplicate posts and broken
283 -templates if we were to continue without the upgrade.</p>
307 +templates if we were to continue without the upgrade.' ); ?></p>
284 308
285 -<p>Note that most of FeedWordPress's functionality is temporarily disabled
309 +<p><?php esc_html_e( 'Note that most of FeedWordPress\'s functionality is temporarily disabled
286 310 until we have successfully completed the upgrade. Everything should begin
287 -working as normal again once the upgrade is complete. There's extraordinarily
288 -little chance of any damage as the result of the upgrade, but if you're paranoid
289 -like me you may want to back up your database before you proceed.</p>
311 +working as normal again once the upgrade is complete. There\'s extraordinarily
312 +little chance of any damage as the result of the upgrade, but if you\'re paranoid
313 +like me, you may want to back up your database before you proceed.' ); ?></p>
290 314
291 -<p>This may take several minutes for a large installation.</p>
315 +<p><?php esc_html_e( 'This may take several minutes for a large installation.' ); ?></p>
292 316
293 317 <form action="" method="post">
294 -<?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_upgrade'); ?>
318 +<?php FeedWordPressCompatibility::stamp_nonce( 'feedwordpress_upgrade' ); ?>
295 319 <div class="submit"><input type="submit" name="action" value="Upgrade" /></div>
296 320 </form>
297 321 </div>
298 322 <?php
299 -} // function fwp_upgrade_page ()
323 +} /* function fwp_upgrade_page() */
300 324
325 +/**
326 + * Filter action for removing dummy zeroes.
327 + *
328 + * @todo Requires a better explanation! (gwyneth 20230917)
329 + *
330 + * @param mixed $var Variable to test.
331 + *
332 + * @return int Possibly returns filtered result
333 + */
334 +function remove_dummy_zero( $var ) {
335 + return ! ( is_numeric( $var ) and ( 0 == (int) $var ) );
336 +}