PluginProbe
FeedWordPress / 2011.0531
FeedWordPress v2011.0531
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 +203 -75 2008.11012011.0531 View file →
@@ -2,99 +2,222 @@
2 2 ################################################################################
3 3 ## LEGACY API: Replicate or mock up functions for legacy support purposes ######
4 4 ################################################################################
5 5
6 -// version testing
7 -function fwp_test_wp_version ($floor, $ceiling = NULL) {
8 - global $wp_db_version;
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;
9 48
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 () */
49 + // Return newly-created category ID
50 + return $cat_id;
51 + } /* FeedWordPressCompatibility::insert_link_category () */
17 52
18 -if (!function_exists('get_option')) {
19 - function get_option ($option) {
20 - return get_settings($option);
21 - }
22 -}
23 -if (!function_exists('current_user_can')) {
24 - $fwp_capability['manage_options'] = 6;
25 - $fwp_capability['manage_links'] = 5;
26 - function current_user_can ($task) {
27 - global $user_level;
53 + /*static*/ function link_category_id ($value, $key = 'cat_name') {
54 + global $wpdb;
28 55
29 - $can = false;
56 + $cat_id = NULL;
30 57
31 - // This is **not** a full replacement for current_user_can. It
32 - // is only for checking the capabilities we care about via the
33 - // WordPress 1.5 user levels.
34 - switch ($task) :
35 - case 'manage_options':
36 - $can = ($user_level >= 6);
37 - break;
38 - case 'manage_links':
39 - $can = ($user_level >= 5);
40 - break;
41 - endswitch;
42 - return $can;
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 post_tags () {
73 + return FeedWordPressCompatibility::test_version(FWP_SCHEMA_23);
74 + } /* FeedWordPressCompatibility::post_tags () */
75 +
76 + /*static*/ function validate_http_request ($action = -1, $capability = null) {
77 + // Only worry about this if we're using a method with significant side-effects
78 + if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') :
79 + // Limit post by user capabilities
80 + if (!is_null($capability) and !current_user_can($capability)) :
81 + wp_die(__('Cheatin&#8217; uh?'));
82 + endif;
83 +
84 + // If check_admin_referer() checks a nonce.
85 + if (function_exists('wp_verify_nonce')) :
86 + check_admin_referer($action);
87 +
88 + // No nonces means no checking nonces.
89 + else :
90 + check_admin_referer();
91 + endif;
92 + endif;
93 + } /* FeedWordPressCompatibility::validate_http_request() */
94 +
95 + /*static*/ function stamp_nonce ($action = -1) {
96 + // stamp form with hidden fields for a nonce in WP 2.0.3 & later
97 + if (function_exists('wp_nonce_field')) :
98 + wp_nonce_field($action);
99 + endif;
100 + } /* FeedWordPressCompatibility::stamp_nonce() */
101 +
102 + /*static*/ function bottom_script_hook ($filename) {
103 + global $fwp_path;
104 +
105 + $hook = 'admin_footer';
106 + if (FeedWordPressCompatibility::test_version(FWP_SCHEMA_28)) : // WordPress 2.8+
107 + $hook = $hook . '-' . $fwp_path . '/' . basename($filename);
108 + endif;
109 + return $hook;
110 + } /* FeedWordPressCompatibility::bottom_script_hook() */
111 +} /* class FeedWordPressCompatibility */
112 +
113 +define('FEEDWORDPRESS_AND_TAGS', (FeedWordPressCompatibility::post_tags() ? ' & Tags' : ''));
114 +
115 +if (!function_exists('stripslashes_deep')) {
116 + function stripslashes_deep($value) {
117 + $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
118 + return $value;
43 119 }
44 -} else {
45 - $fwp_capability['manage_options'] = 'manage_options';
46 - $fwp_capability['manage_links'] = 'manage_links';
47 120 }
121 +
48 122 if (!function_exists('sanitize_user')) {
49 - function sanitize_user ($text, $strict) {
123 + function sanitize_user ($text, $strict = false) {
50 124 return $text; // Don't munge it if it wasn't munged going in...
51 125 }
52 126 }
53 -if (!function_exists('wp_insert_user')) {
54 - function wp_insert_user ($userdata) {
55 - global $wpdb;
56 127
57 - #-- Help WordPress 1.5.x quack like a duck
58 - $login = $userdata['user_login'];
59 - $author = $userdata['display_name'];
60 - $nice_author = $userdata['user_nicename'];
61 - $email = $userdata['user_email'];
62 - $url = $userdata['user_url'];
128 +if (!function_exists('disabled')) {
129 + /**
130 + * Outputs the html disabled attribute.
131 + *
132 + * Compares the first two arguments and if identical marks as disabled
133 + *
134 + * @since 3.0.0
135 + *
136 + * @param mixed $disabled One of the values to compare
137 + * @param mixed $current (true) The other value to compare if not just true
138 + * @param bool $echo Whether to echo or just return the string
139 + * @return string html attribute or empty string
140 + */
141 + function disabled( $disabled, $current = true, $echo = true ) {
142 + return __checked_selected_helper( $disabled, $current, $echo, 'disabled' );
143 + }
144 +} /* if */
63 145
64 - $wpdb->query (
65 - "INSERT INTO $wpdb->users
66 - SET
67 - ID='0',
68 - user_login='$login',
69 - user_firstname='$author',
70 - user_nickname='$author',
71 - user_nicename='$nice_author',
72 - user_description='$author',
73 - user_email='$email',
74 - user_url='$url'");
75 - $id = $wpdb->insert_id;
76 -
77 - return $id;
146 +// Compat
147 +
148 +if (!function_exists('set_post_field')) {
149 +
150 + /**
151 + * Update data from a post field based on Post ID
152 + *
153 + * Examples of the post field will be, 'post_type', 'post_status', 'post_content', etc.
154 + *
155 + * The context values are based off of the taxonomy filter functions and
156 + * supported values are found within those functions.
157 + *
158 + * @uses sanitize_post_field()
159 + *
160 + * @param string $field Post field name
161 + * @param mixed $value New value for post field
162 + * @param id $post Post ID
163 + * @return bool Result of UPDATE query
164 + *
165 + * Included under terms of GPL from WordPress Ticket #10946 <http://core.trac.wordpress.org/attachment/ticket/10946/post.php.diff>
166 + */
167 + function set_post_field ($field, $value, $post_id) {
168 + global $wpdb;
169 +
170 + $post_id = absint($post_id);
171 + // sigh ... when FWP is active, I need to avoid avoid_kses_munge
172 + // $value = sanitize_post_field($field, $value, $post_id, 'db');
173 + return $wpdb->update($wpdb->posts, array($field => $value), array('ID' => $post_id));
174 + } /* function set_post_field () */
175 +
176 +} /* if */
177 +
178 +if (!function_exists('term_exists')) {
179 + // Fucking WordPress 3.0 wordsmithing.
180 + function term_exists ( $term, $taxonomy = '', $parent = 0 ) {
181 + return is_term($term, $taxonomy, $parent);
78 182 }
183 +} /* if */
184 +
185 +require_once(dirname(__FILE__).'/feedwordpress-walker-category-checklist.class.php');
186 +
187 +function fwp_category_checklist ($post_id = 0, $descendents_and_self = 0, $selected_cats = false, $params = array()) {
188 + if (is_string($params)) :
189 + $prefix = $params;
190 + $taxonomy = 'category';
191 + elseif (is_array($params)) :
192 + $prefix = (isset($params['prefix']) ? $params['prefix'] : '');
193 + $taxonomy = (isset($params['taxonomy']) ? $params['taxonomy'] : 'category');
194 + endif;
195 +
196 + $walker = new FeedWordPress_Walker_Category_Checklist($params);
197 + $walker->set_prefix($prefix);
198 + $walker->set_taxonomy($taxonomy);
199 + wp_terms_checklist(/*post_id=*/ $post_id, array(
200 + 'taxonomy' => $taxonomy,
201 + 'descendents_and_self' => $descendents_and_self,
202 + 'selected_cats' => $selected_cats,
203 + 'popular_cats' => false,
204 + 'walker' => $walker,
205 + 'checked_ontop' => true,
206 + ));
79 207 }
80 208
81 -function fwp_category_checklist ($post_id = 0, $descendents_and_self = 0, $selected_cats = false) {
82 - if (function_exists('wp_category_checklist')) :
83 - wp_category_checklist($post_id, $descendents_and_self, $selected_cats);
209 +function fwp_time_elapsed ($ts) {
210 + if (function_exists('human_time_diff')) :
211 + if ($ts >= time()) :
212 + $ret = __(human_time_diff($ts)." from now");
213 + else :
214 + $ret = __(human_time_diff($ts)." ago");
215 + endif;
84 216 else :
85 - global $checked_categories;
86 -
87 - // selected_cats is an array of integer cat_IDs / term_ids for
88 - // the categories that should be checked
89 - $cats = array();
90 - if ($post_id) : $cats = wp_get_post_categories($post_id);
91 - else : $cats = $selected_cats;
92 - endif;
93 -
94 - $checked_categories = $cats;
95 - dropdown_categories();
217 + $ret = strftime('%x %X', $ts);
96 218 endif;
219 + return $ret;
97 220 }
98 221
99 222 ################################################################################
100 223 ## UPGRADE INTERFACE: Have users upgrade DB from older versions of FWP #########
@@ -106,9 +229,9 @@
106 229 if (get_option('feedwordpress_version') != FEEDWORDPRESS_VERSION) :
107 230 echo "<div class=\"wrap\">\n";
108 231 echo "<h2>Upgrading FeedWordPress...</h2>";
109 232
110 - $feedwordpress =& new FeedWordPress;
233 + $feedwordpress = new FeedWordPress;
111 234 $feedwordpress->upgrade_database($ver);
112 235 echo "<p><strong>Done!</strong> Upgraded database to version ".FEEDWORDPRESS_VERSION.".</p>\n";
113 236 echo "<form action=\"\" method=\"get\">\n";
114 237 echo "<div class=\"submit\"><input type=\"hidden\" name=\"page\" value=\"syndication.php\" />";
@@ -138,10 +261,15 @@
138 261
139 262 <p>This may take several minutes for a large installation.</p>
140 263
141 264 <form action="" method="post">
265 +<?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_upgrade'); ?>
142 266 <div class="submit"><input type="submit" name="action" value="Upgrade" /></div>
143 267 </form>
144 268 </div>
145 269 <?php
146 270 } // function fwp_upgrade_page ()
271 +
272 +function remove_dummy_zero ($var) {
273 + return !(is_numeric($var) and ((int) $var == 0));
274 +}
147 275