| @@ -14,134 +14,8 @@ | ||
| 14 | 14 | endif; |
| 15 | 15 | return $good; |
| 16 | 16 | } /* function fwp_test_wp_version () */ |
| 17 | 17 | |
| 18 | -class FeedWordPressCompatibility { | |
| 19 | - /*static*/ function test_version ($floor, $ceiling = null) { | |
| 20 | - return fwp_test_wp_version($floor, $ceiling); | |
| 21 | - } /* FeedWordPressCompatibility::test_version() */ | |
| 22 | - | |
| 23 | - /*static*/ function insert_link_category ($name) { | |
| 24 | - global $wpdb; | |
| 25 | - | |
| 26 | - $name = $wpdb->escape($name); | |
| 27 | - | |
| 28 | - // 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; | |
| 53 | - | |
| 54 | - // Return newly-created category ID | |
| 55 | - return $cat_id; | |
| 56 | - } /* FeedWordPressCompatibility::insert_link_category () */ | |
| 57 | - | |
| 58 | - /*static*/ function link_category_id ($value, $key = 'cat_name') { | |
| 59 | - global $wpdb; | |
| 60 | - | |
| 61 | - $cat_id = NULL; | |
| 62 | - | |
| 63 | - // WordPress 2.3 introduces a new taxonomy/term API | |
| 64 | - if (function_exists('is_term')) : | |
| 65 | - $the_term = is_term($value, 'link_category'); | |
| 66 | - | |
| 67 | - // Sometimes, in some versions, we get a row | |
| 68 | - if (is_array($the_term)) : | |
| 69 | - $cat_id = $the_term['term_id']; | |
| 70 | - | |
| 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 | - else : | |
| 88 | - FeedWordPress::critical_bug(__CLASS__.'::'.__METHOD__.'::wp_db_version', $wp_db_version, __LINE__); | |
| 89 | - endif; | |
| 90 | - | |
| 91 | - return $cat_id; | |
| 92 | - } /* FeedWordPressCompatibility::link_category_id () */ | |
| 93 | - | |
| 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) { | |
| 99 | - // Only worry about this if we're using a method with significant side-effects | |
| 100 | - if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') : | |
| 101 | - // Limit post by user capabilities | |
| 102 | - if (!is_null($capability) and !current_user_can($capability)) : | |
| 103 | - wp_die(__('Cheatin’ uh?')); | |
| 104 | - endif; | |
| 105 | - | |
| 106 | - // If check_admin_referer() checks a nonce. | |
| 107 | - if (function_exists('wp_verify_nonce')) : | |
| 108 | - check_admin_referer($action); | |
| 109 | - | |
| 110 | - // No nonces means no checking nonces. | |
| 111 | - else : | |
| 112 | - check_admin_referer(); | |
| 113 | - endif; | |
| 114 | - endif; | |
| 115 | - } /* 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); | |
| 121 | - endif; | |
| 122 | - } /* FeedWordPressCompatibility::stamp_nonce() */ | |
| 123 | - | |
| 124 | - /*static*/ function bottom_script_hook ($filename) { | |
| 125 | - global $fwp_path; | |
| 126 | - | |
| 127 | - $hook = 'admin_footer'; | |
| 128 | - if (FeedWordPressCompatibility::test_version(FWP_SCHEMA_28)) : // WordPress 2.8+ | |
| 129 | - $hook = $hook . '-' . $fwp_path . '/' . basename($filename); | |
| 130 | - endif; | |
| 131 | - return $hook; | |
| 132 | - } /* FeedWordPressCompatibility::bottom_script_hook() */ | |
| 133 | -} /* class FeedWordPressCompatibility */ | |
| 134 | - | |
| 135 | -define('FEEDWORDPRESS_AND_TAGS', (FeedWordPressCompatibility::post_tags() ? ' & Tags' : '')); | |
| 136 | - | |
| 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 | -} | |
| 143 | - | |
| 144 | 18 | if (!function_exists('get_option')) { |
| 145 | 19 | function get_option ($option) { |
| 146 | 20 | return get_settings($option); |
| 147 | 21 | } |
| @@ -163,11 +37,8 @@ | ||
| 163 | 37 | break; |
| 164 | 38 | case 'manage_links': |
| 165 | 39 | $can = ($user_level >= 5); |
| 166 | 40 | break; |
| 167 | - case 'edit_files': | |
| 168 | - $can = ($user_level >= 9); | |
| 169 | - break; | |
| 170 | 41 | endswitch; |
| 171 | 42 | return $can; |
| 172 | 43 | } |
| 173 | 44 | } else { |
| @@ -174,9 +45,9 @@ | ||
| 174 | 45 | $fwp_capability['manage_options'] = 'manage_options'; |
| 175 | 46 | $fwp_capability['manage_links'] = 'manage_links'; |
| 176 | 47 | } |
| 177 | 48 | if (!function_exists('sanitize_user')) { |
| 178 | - function sanitize_user ($text, $strict = false) { | |
| 49 | + function sanitize_user ($text, $strict) { | |
| 179 | 50 | return $text; // Don't munge it if it wasn't munged going in... |
| 180 | 51 | } |
| 181 | 52 | } |
| 182 | 53 | if (!function_exists('wp_insert_user')) { |
| @@ -204,51 +75,28 @@ | ||
| 204 | 75 | $id = $wpdb->insert_id; |
| 205 | 76 | |
| 206 | 77 | return $id; |
| 207 | 78 | } |
| 208 | -} /* if (!function_exists('wp_insert_user')) */ | |
| 79 | +} | |
| 209 | 80 | |
| 210 | -if (!function_exists('wp_die')) { | |
| 211 | - function wp_die ( $message, $title = '', $args = array() ) { | |
| 212 | - die($message); | |
| 213 | - } /* wp_die() */ | |
| 214 | -} /* if */ | |
| 215 | - | |
| 216 | 81 | function fwp_category_checklist ($post_id = 0, $descendents_and_self = 0, $selected_cats = false) { |
| 217 | 82 | if (function_exists('wp_category_checklist')) : |
| 218 | 83 | wp_category_checklist($post_id, $descendents_and_self, $selected_cats); |
| 219 | 84 | else : |
| 85 | + global $checked_categories; | |
| 86 | + | |
| 220 | 87 | // selected_cats is an array of integer cat_IDs / term_ids for |
| 221 | 88 | // the categories that should be checked |
| 222 | - global $post_ID; | |
| 223 | - | |
| 224 | - $cats = get_nested_categories(); | |
| 89 | + $cats = array(); | |
| 90 | + if ($post_id) : $cats = wp_get_post_categories($post_id); | |
| 91 | + else : $cats = $selected_cats; | |
| 92 | + endif; | |
| 225 | 93 | |
| 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); | |
| 94 | + $checked_categories = $cats; | |
| 95 | + dropdown_categories(); | |
| 235 | 96 | endif; |
| 236 | 97 | } |
| 237 | 98 | |
| 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"); | |
| 242 | - else : | |
| 243 | - $ret = __(human_time_diff($ts)." ago"); | |
| 244 | - endif; | |
| 245 | - else : | |
| 246 | - $ret = strftime('%x %X', $ts); | |
| 247 | - endif; | |
| 248 | - return $ret; | |
| 249 | -} | |
| 250 | - | |
| 251 | 99 | ################################################################################ |
| 252 | 100 | ## UPGRADE INTERFACE: Have users upgrade DB from older versions of FWP ######### |
| 253 | 101 | ################################################################################ |
| 254 | 102 | |
| @@ -290,9 +138,8 @@ | ||
| 290 | 138 | |
| 291 | 139 | <p>This may take several minutes for a large installation.</p> |
| 292 | 140 | |
| 293 | 141 | <form action="" method="post"> |
| 294 | -<?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_upgrade'); ?> | |
| 295 | 142 | <div class="submit"><input type="submit" name="action" value="Upgrade" /></div> |
| 296 | 143 | </form> |
| 297 | 144 | </div> |
| 298 | 145 | <?php |