PluginProbe
FeedWordPress / 2010.0903
FeedWordPress v2010.0903
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 +61 -163 2010.05282010.0903 View file →
@@ -2,23 +2,19 @@
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;
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 -
18 6 class FeedWordPressCompatibility {
7 + // version testing based on database schema version
19 8 /*static*/ function test_version ($floor, $ceiling = null) {
20 - return fwp_test_wp_version($floor, $ceiling);
9 + global $wp_db_version;
10 +
11 + $ver = (isset($wp_db_version) ? $wp_db_version : 0);
12 + $good = ($ver >= $floor);
13 + if (!is_null($ceiling)) :
14 + $good = ($good and ($ver < $ceiling));
15 + endif;
16 + return $good;
21 17 } /* FeedWordPressCompatibility::test_version() */
22 18
23 19 /*static*/ function insert_link_category ($name) {
24 20 global $wpdb;
@@ -25,32 +21,10 @@
25 21
26 22 $name = $wpdb->escape($name);
27 23
28 24 // WordPress 2.3+ term/taxonomy API
29 - if (function_exists('wp_insert_term')) :
30 - $term = wp_insert_term($name, 'link_category');
31 - $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.
50 - else :
51 - FeedWordPress::critical_bug('FeedWordPress::link_category_id::wp_db_version', $wp_db_version, __LINE__);
52 - endif;
25 + $term = wp_insert_term($name, 'link_category');
26 + $cat_id = $term['term_id'];
53 27
54 28 // Return newly-created category ID
55 29 return $cat_id;
56 30 } /* FeedWordPressCompatibility::insert_link_category () */
@@ -59,34 +33,17 @@
59 33 global $wpdb;
60 34
61 35 $cat_id = NULL;
62 36
63 - // WordPress 2.3 introduces a new taxonomy/term API
64 - if (function_exists('is_term')) :
65 - $the_term = is_term($value, 'link_category');
37 + $the_term = term_exists($value, 'link_category');
66 38
67 - // Sometimes, in some versions, we get a row
68 - if (is_array($the_term)) :
69 - $cat_id = $the_term['term_id'];
39 + // Sometimes, in some versions, we get a row
40 + if (is_array($the_term)) :
41 + $cat_id = $the_term['term_id'];
70 42
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.
43 + // other times we get an integer result
87 44 else :
88 - FeedWordPress::critical_bug(__CLASS__.'::'.__METHOD__.'::wp_db_version', $wp_db_version, __LINE__);
45 + $cat_id = $the_term;
89 46 endif;
90 47
91 48 return $cat_id;
92 49 } /* FeedWordPressCompatibility::link_category_id () */
@@ -140,124 +97,61 @@
140 97 return $value;
141 98 }
142 99 }
143 100
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;
154 -
155 - $can = false;
156 -
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;
172 - }
173 -} else {
174 - $fwp_capability['manage_options'] = 'manage_options';
175 - $fwp_capability['manage_links'] = 'manage_links';
176 -}
177 101 if (!function_exists('sanitize_user')) {
178 102 function sanitize_user ($text, $strict = false) {
179 103 return $text; // Don't munge it if it wasn't munged going in...
180 104 }
181 105 }
182 -if (!function_exists('wp_insert_user')) {
183 - function wp_insert_user ($userdata) {
184 - global $wpdb;
185 106
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'];
192 -
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;
107 +if (!function_exists('disabled')) {
108 + /**
109 + * Outputs the html disabled attribute.
110 + *
111 + * Compares the first two arguments and if identical marks as disabled
112 + *
113 + * @since 3.0.0
114 + *
115 + * @param mixed $disabled One of the values to compare
116 + * @param mixed $current (true) The other value to compare if not just true
117 + * @param bool $echo Whether to echo or just return the string
118 + * @return string html attribute or empty string
119 + */
120 + function disabled( $disabled, $current = true, $echo = true ) {
121 + return __checked_selected_helper( $disabled, $current, $echo, 'disabled' );
207 122 }
208 -} /* if (!function_exists('wp_insert_user')) */
209 -
210 -if (!function_exists('wp_die')) {
211 - function wp_die ( $message, $title = '', $args = array() ) {
212 - die($message);
213 - } /* wp_die() */
214 123 } /* if */
215 124
216 -if (!function_exists('add_post_meta')) {
217 - function add_post_meta ($postId, $key, $value, $unique) {
218 - global $wpdb;
219 -
220 - $postId = (int) $postId;
221 - $key = $wpdb->escape($key);
222 - $value = $wpdb->escape($value);
223 -
224 - $result = $wpdb->query("
225 - INSERT INTO $wpdb->postmeta
226 - SET
227 - post_id='$postId',
228 - meta_key='$key',
229 - meta_value='$value'
230 - ");
231 - if (!$result) :
232 - $err = mysql_error();
233 - if (FEEDWORDPRESS_DEBUG) :
234 - echo "[DEBUG:".date('Y-m-d H:i:S')."][feedwordpress]: post metadata insertion FAILED for field '$key' := '$value': [$err]";
235 - endif;
236 - endif;
237 - } /* add_post_meta() */
125 +if (!function_exists('term_exists')) {
126 + // Fucking WordPress 3.0 wordsmithing.
127 + function term_exists ( $term, $taxonomy = '', $parent = 0 ) {
128 + return is_term($term, $taxonomy, $parent);
129 + }
238 130 } /* if */
239 131
240 -function fwp_category_checklist ($post_id = 0, $descendents_and_self = 0, $selected_cats = false) {
241 - if (function_exists('wp_category_checklist')) :
242 - wp_category_checklist($post_id, $descendents_and_self, $selected_cats);
243 - else :
244 - // selected_cats is an array of integer cat_IDs / term_ids for
245 - // the categories that should be checked
246 - global $post_ID;
132 +require_once(dirname(__FILE__).'/feedwordpress-walker-category-checklist.class.php');
247 133
248 - $cats = get_nested_categories();
249 -
250 - // Undo damage from usort() in WP 2.0
251 - $dogs = array();
252 - foreach ($cats as $cat) :
253 - $dogs[$cat['cat_ID']] = $cat;
254 - endforeach;
255 - foreach ($selected_cats as $cat_id) :
256 - $dogs[$cat_id]['checked'] = true;
257 - endforeach;
258 - write_nested_categories($dogs);
134 +function fwp_category_checklist ($post_id = 0, $descendents_and_self = 0, $selected_cats = false, $params = array()) {
135 + if (is_string($params)) :
136 + $prefix = $params;
137 + $taxonomy = 'category';
138 + elseif (is_array($params)) :
139 + $prefix = (isset($params['prefix']) ? $params['prefix'] : '');
140 + $taxonomy = (isset($params['taxonomy']) ? $params['taxonomy'] : 'category');
259 141 endif;
142 +
143 + $walker = new FeedWordPress_Walker_Category_Checklist;
144 + $walker->set_prefix($prefix);
145 + $walker->set_taxonomy($taxonomy);
146 + wp_terms_checklist(/*post_id=*/ $post_id, array(
147 + 'taxonomy' => $taxonomy,
148 + 'descendents_and_self' => $descendents_and_self,
149 + 'selected_cats' => $selected_cats,
150 + 'popular_cats' => false,
151 + 'walker' => $walker,
152 + 'checked_ontop' => true,
153 + ));
260 154 }
261 155
262 156 function fwp_time_elapsed ($ts) {
263 157 if (function_exists('human_time_diff')) :
@@ -320,5 +214,9 @@
320 214 </form>
321 215 </div>
322 216 <?php
323 217 } // function fwp_upgrade_page ()
218 +
219 +function remove_dummy_zero ($var) {
220 + return !(is_numeric($var) and ((int) $var == 0));
221 +}
324 222