PluginProbe
FeedWordPress / 2022.0208
FeedWordPress v2022.0208
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 +97 -177 trunk2022.0208 View file →
@@ -1,15 +1,9 @@
1 1 <?php
2 -/**
3 - * LEGACY API: Replicate or mock up functions for legacy support purposes.
4 - *
5 - * @author radgeek
6 - */
2 +################################################################################
3 +## LEGACY API: Replicate or mock up functions for legacy support purposes ######
4 +################################################################################
7 5
8 -/**
9 - * Implements legacy functionality no longer present in the current WordPress
10 - * versions
11 - */
12 6 class FeedWordPressCompatibility {
13 7
14 8 /**
15 9 * FeedWordPressCompatibility::test_version: test version of WordPress
@@ -14,47 +8,39 @@
14 8 /**
15 9 * FeedWordPressCompatibility::test_version: test version of WordPress
16 10 * based on the database schema version.
17 11 *
18 - * @param int $floor The minimum version necessary.
12 + * @param int $floor The minimum version necessary
19 13 * @param mixed $ceiling The first version that is too high. If omitted
20 14 * or NULL, no version is too high.
21 - * @return bool TRUE if within the range of versions, FALSE if too low
15 + * @return bool TRUE if within the range of versions, FALSE if too low
22 16 * or too high.
23 17 */
24 - static function test_version( $floor, $ceiling = null ) {
18 + static function test_version ($floor, $ceiling = null) {
25 19 global $wp_db_version;
26 20
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 ) );
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));
31 25 endif;
32 26 return $good;
33 27 } /* FeedWordPressCompatibility::test_version() */
34 28
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 ) {
29 + static function insert_link_category ($name) {
30 + global $wpdb;
31 +
46 32 // WordPress 2.3+ term/taxonomy API
47 - $term = wp_insert_term( $name, 'link_category' );
33 + $term = wp_insert_term($name, 'link_category');
48 34
49 35 // OK: returned array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id)
50 - if ( ! is_wp_error( $term ) ) :
36 + if (!is_wp_error($term)) :
51 37 $cat_id = $term['term_id'];
52 38
53 39 // Error: term with this name already exists. Well, let's use that then.
54 - elseif ( 'term_exists' == $term->get_error_code() ) :
40 + elseif ($term->get_error_code() == 'term_exists') :
55 41 // Already-existing term ID is returned in data field
56 - $cat_id = $term->get_error_data( 'term_exists' );
42 + $cat_id = $term->get_error_data('term_exists');
57 43
58 44 // Error: another kind of error, harder to recover from. Return WP_Error.
59 45 else :
60 46 $cat_id = $term;
@@ -63,26 +49,17 @@
63 49 // Return newly-created category ID
64 50 return $cat_id;
65 51 } /* FeedWordPressCompatibility::insert_link_category () */
66 52
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' ) {
53 + static function link_category_id ($value, $key = 'cat_name') {
54 + global $wpdb;
55 +
79 56 $cat_id = NULL;
80 57
81 - $the_term = term_exists( $value, 'link_category' );
58 + $the_term = term_exists($value, 'link_category');
82 59
83 60 // Sometimes, in some versions, we get a row
84 - if ( is_array( $the_term ) ) :
61 + if (is_array($the_term)) :
85 62 $cat_id = $the_term['term_id'];
86 63
87 64 // other times we get an integer result
88 65 else :
@@ -91,28 +68,19 @@
91 68
92 69 return $cat_id;
93 70 } /* FeedWordPressCompatibility::link_category_id () */
94 71
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 ) {
72 + static function validate_http_request ($action = -1, $capability = null) {
105 73 // Only worry about this if we're using a method with significant side-effects
106 - if ( 'POST' == strtoupper( $_SERVER['REQUEST_METHOD'] ) ) :
74 + if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') :
107 75 // Limit post by user capabilities
108 - if ( ! is_null( $capability ) and ! current_user_can( $capability ) ) :
109 - wp_die( esc_html__( 'Cheatin&rsquo; uh?' ) );
76 + if (!is_null($capability) and !current_user_can($capability)) :
77 + wp_die(__('Cheatin&#8217; uh?'));
110 78 endif;
111 79
112 80 // If check_admin_referer() checks a nonce.
113 - if ( function_exists( 'wp_verify_nonce' ) ) :
114 - check_admin_referer( $action );
81 + if (function_exists('wp_verify_nonce')) :
82 + check_admin_referer($action);
115 83
116 84 // No nonces means no checking nonces.
117 85 else :
118 86 check_admin_referer();
@@ -119,25 +87,12 @@
119 87 endif;
120 88 endif;
121 89 } /* FeedWordPressCompatibility::validate_http_request() */
122 90
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 );
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);
140 95 endif;
141 96 } /* FeedWordPressCompatibility::stamp_nonce() */
142 97
143 98 static function bottom_script_hook ($filename) {
@@ -149,11 +104,12 @@
149 104 } /* class FeedWordPressCompatibility */
150 105
151 106 // Compat
152 107
153 -if ( ! function_exists( 'set_post_field' ) ) {
108 +if (!function_exists('set_post_field')) {
109 +
154 110 /**
155 - * Update data from a post field based on Post ID.
111 + * Update data from a post field based on Post ID
156 112 *
157 113 * Examples of the post field will be, 'post_type', 'post_status', 'post_content', etc.
158 114 *
159 115 * The context values are based off of the taxonomy filter functions and
@@ -160,12 +116,12 @@
160 116 * supported values are found within those functions.
161 117 *
162 118 * @uses sanitize_post_field()
163 119 *
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.
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
168 124 *
169 125 * Included under terms of GPL from WordPress Ticket #10946 <http://core.trac.wordpress.org/attachment/ticket/10946/post.php.diff>
170 126 */
171 127 function set_post_field ($field, $value, $post_id) {
@@ -178,17 +134,17 @@
178 134 } /* function set_post_field () */
179 135
180 136 } /* if */
181 137
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 - */
138 +if (!function_exists('is_countable')) {
187 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 +
188 144 /**
189 145 * Polyfill for is_countable() function added in PHP 7.3.
190 - *
146 + *
191 147 * Verify that the content of a variable is an array or an object
192 148 * implementing the Countable interface.
193 149 *
194 150 * @since 4.9.6
@@ -203,90 +159,62 @@
203 159 || $var instanceof SimpleXMLElement
204 160 || $var instanceof ResourceBundle
205 161 );
206 162 }
163 +
207 164 } /* if */
208 165
209 -require_once dirname(__FILE__) . '/feedwordpress-walker-category-checklist.class.php';
166 +require_once(dirname(__FILE__).'/feedwordpress-walker-category-checklist.class.php');
210 167
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 ) ) :
168 +function fwp_category_checklist ($post_id = 0, $descendents_and_self = 0, $selected_cats = false, $params = array()) {
169 + if (is_string($params)) :
226 170 $prefix = $params;
227 171 $taxonomy = 'category';
228 - elseif ( is_array( $params ) ) :
229 - $prefix = ( isset( $params['prefix'] ) ? $params['prefix'] : '' );
230 - $taxonomy = ( isset( $params['taxonomy'] ) ? $params['taxonomy'] : 'category' );
172 + elseif (is_array($params)) :
173 + $prefix = (isset($params['prefix']) ? $params['prefix'] : '');
174 + $taxonomy = (isset($params['taxonomy']) ? $params['taxonomy'] : 'category');
231 175 endif;
232 176
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,
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,
238 182 '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() */
183 + 'selected_cats' => $selected_cats,
184 + 'popular_cats' => false,
185 + 'walker' => $walker,
186 + 'checked_ontop' => true,
187 + ));
188 +}
245 189
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 ) ) :
255 -
256 - endif;
257 - if ( function_exists( 'human_time_diff' ) ) :
258 - if ( $ts >= time() ) :
259 - $ret = human_time_diff( $ts ) . __( " from now" );
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");
260 194 else :
261 - $ret = human_time_diff( $ts ) . __( " ago" );
195 + $ret = __(human_time_diff($ts)." ago");
262 196 endif;
263 197 else :
264 - // $ret = strftime( '%x %X', $ts ); // deprecated
265 - $ret = date( "Y-m-d H:i:s", $ts );
198 + $ret = strftime('%x %X', $ts);
266 199 endif;
267 200 return $ret;
268 -} /* function fwp_time_elapsed() */
201 +}
269 202
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 ) :
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) :
283 211 echo "<div class=\"wrap\">\n";
284 - echo "<h2>" . esc_html__( "Upgrading FeedWordPress..." ) . "</h2>";
212 + echo "<h2>Upgrading FeedWordPress...</h2>";
285 213
286 214 $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";
215 + $feedwordpress->upgrade_database($ver);
216 + echo "<p><strong>Done!</strong> Upgraded database to version ".FEEDWORDPRESS_VERSION.".</p>\n";
289 217 echo "<form action=\"\" method=\"get\">\n";
290 218 echo "<div class=\"submit\"><input type=\"hidden\" name=\"page\" value=\"syndication.php\" />";
291 219 echo "<input type=\"submit\" value=\"Continue &raquo;\" /></form></div>\n";
292 220 echo "</div>\n";
@@ -291,46 +219,38 @@
291 219 echo "<input type=\"submit\" value=\"Continue &raquo;\" /></form></div>\n";
292 220 echo "</div>\n";
293 221 return;
294 222 else :
295 - echo "<div class=\"updated\"><p>" . esc_html__( "Already at version " ) . esc_html( FEEDWORDPRESS_VERSION ) . "!</p></div>";
223 + echo "<div class=\"updated\"><p>Already at version ".FEEDWORDPRESS_VERSION."!</p></div>";
296 224 endif;
297 225 endif;
298 226 ?>
299 227 <div class="wrap">
300 -<h2><?php esc_html_e( 'Upgrade FeedWordPress' ); ?></h2>
228 +<h2>Upgrade FeedWordPress</h2>
301 229
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
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
305 233 to upgrade your database: some necessary changes in how the software keeps
306 234 track of posts and feeds will cause problems such as duplicate posts and broken
307 -templates if we were to continue without the upgrade.' ); ?></p>
235 +templates if we were to continue without the upgrade.</p>
308 236
309 -<p><?php esc_html_e( 'Note that most of FeedWordPress\'s functionality is temporarily disabled
237 +<p>Note that most of FeedWordPress's functionality is temporarily disabled
310 238 until we have successfully completed the upgrade. Everything should begin
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>
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>
314 242
315 -<p><?php esc_html_e( 'This may take several minutes for a large installation.' ); ?></p>
243 +<p>This may take several minutes for a large installation.</p>
316 244
317 245 <form action="" method="post">
318 -<?php FeedWordPressCompatibility::stamp_nonce( 'feedwordpress_upgrade' ); ?>
246 +<?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_upgrade'); ?>
319 247 <div class="submit"><input type="submit" name="action" value="Upgrade" /></div>
320 248 </form>
321 249 </div>
322 250 <?php
323 -} /* function fwp_upgrade_page() */
251 +} // function fwp_upgrade_page ()
324 252
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 ) );
253 +function remove_dummy_zero ($var) {
254 + return !(is_numeric($var) and ((int) $var == 0));
336 255 }
256 +