PluginProbe
FeedWordPress / 2010.0905
FeedWordPress v2010.0905
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 +134 -83 2008.12142010.0905 View file →
@@ -2,20 +2,96 @@
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 + // version testing based on database schema version
8 + /*static*/ function test_version ($floor, $ceiling = null) {
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;
17 + } /* FeedWordPressCompatibility::test_version() */
18 +
19 + /*static*/ function insert_link_category ($name) {
20 + global $wpdb;
21 +
22 + $name = $wpdb->escape($name);
23 +
24 + // WordPress 2.3+ term/taxonomy API
25 + $term = wp_insert_term($name, 'link_category');
26 + $cat_id = $term['term_id'];
27 +
28 + // Return newly-created category ID
29 + return $cat_id;
30 + } /* FeedWordPressCompatibility::insert_link_category () */
31 +
32 + /*static*/ function link_category_id ($value, $key = 'cat_name') {
33 + global $wpdb;
34 +
35 + $cat_id = NULL;
36 +
37 + $the_term = term_exists($value, 'link_category');
38 +
39 + // Sometimes, in some versions, we get a row
40 + if (is_array($the_term)) :
41 + $cat_id = $the_term['term_id'];
42 +
43 + // other times we get an integer result
44 + else :
45 + $cat_id = $the_term;
46 + endif;
47 +
48 + return $cat_id;
49 + } /* FeedWordPressCompatibility::link_category_id () */
50 +
51 + /*static*/ function post_tags () {
52 + return FeedWordPressCompatibility::test_version(FWP_SCHEMA_23);
53 + } /* FeedWordPressCompatibility::post_tags () */
54 +
55 + /*static*/ function validate_http_request ($action = -1, $capability = null) {
56 + // Only worry about this if we're using a method with significant side-effects
57 + if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') :
58 + // Limit post by user capabilities
59 + if (!is_null($capability) and !current_user_can($capability)) :
60 + wp_die(__('Cheatin&#8217; uh?'));
61 + endif;
62 +
63 + // If check_admin_referer() checks a nonce.
64 + if (function_exists('wp_verify_nonce')) :
65 + check_admin_referer($action);
66 +
67 + // No nonces means no checking nonces.
68 + else :
69 + check_admin_referer();
70 + endif;
71 + endif;
72 + } /* FeedWordPressCompatibility::validate_http_request() */
9 73
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 () */
74 + /*static*/ function stamp_nonce ($action = -1) {
75 + // stamp form with hidden fields for a nonce in WP 2.0.3 & later
76 + if (function_exists('wp_nonce_field')) :
77 + wp_nonce_field($action);
78 + endif;
79 + } /* FeedWordPressCompatibility::stamp_nonce() */
80 +
81 + /*static*/ function bottom_script_hook ($filename) {
82 + global $fwp_path;
17 83
84 + $hook = 'admin_footer';
85 + if (FeedWordPressCompatibility::test_version(FWP_SCHEMA_28)) : // WordPress 2.8+
86 + $hook = $hook . '-' . $fwp_path . '/' . basename($filename);
87 + endif;
88 + return $hook;
89 + } /* FeedWordPressCompatibility::bottom_script_hook() */
90 +} /* class FeedWordPressCompatibility */
91 +
92 +define('FEEDWORDPRESS_AND_TAGS', (FeedWordPressCompatibility::post_tags() ? ' & Tags' : ''));
93 +
18 94 if (!function_exists('stripslashes_deep')) {
19 95 function stripslashes_deep($value) {
20 96 $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
21 97 return $value;
@@ -21,91 +97,61 @@
21 97 return $value;
22 98 }
23 99 }
24 100
25 -if (!function_exists('get_option')) {
26 - function get_option ($option) {
27 - return get_settings($option);
28 - }
29 -}
30 -if (!function_exists('current_user_can')) {
31 - $fwp_capability['manage_options'] = 6;
32 - $fwp_capability['manage_links'] = 5;
33 - function current_user_can ($task) {
34 - global $user_level;
35 -
36 - $can = false;
37 -
38 - // This is **not** a full replacement for current_user_can. It
39 - // is only for checking the capabilities we care about via the
40 - // WordPress 1.5 user levels.
41 - switch ($task) :
42 - case 'manage_options':
43 - $can = ($user_level >= 6);
44 - break;
45 - case 'manage_links':
46 - $can = ($user_level >= 5);
47 - break;
48 - endswitch;
49 - return $can;
50 - }
51 -} else {
52 - $fwp_capability['manage_options'] = 'manage_options';
53 - $fwp_capability['manage_links'] = 'manage_links';
54 -}
55 101 if (!function_exists('sanitize_user')) {
56 102 function sanitize_user ($text, $strict = false) {
57 103 return $text; // Don't munge it if it wasn't munged going in...
58 104 }
59 105 }
60 -if (!function_exists('wp_insert_user')) {
61 - function wp_insert_user ($userdata) {
62 - global $wpdb;
63 106
64 - #-- Help WordPress 1.5.x quack like a duck
65 - $login = $userdata['user_login'];
66 - $author = $userdata['display_name'];
67 - $nice_author = $userdata['user_nicename'];
68 - $email = $userdata['user_email'];
69 - $url = $userdata['user_url'];
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' );
122 + }
123 +} /* if */
70 124
71 - $wpdb->query (
72 - "INSERT INTO $wpdb->users
73 - SET
74 - ID='0',
75 - user_login='$login',
76 - user_firstname='$author',
77 - user_nickname='$author',
78 - user_nicename='$nice_author',
79 - user_description='$author',
80 - user_email='$email',
81 - user_url='$url'");
82 - $id = $wpdb->insert_id;
83 -
84 - return $id;
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);
85 129 }
86 -}
130 +} /* if */
87 131
88 -function fwp_category_checklist ($post_id = 0, $descendents_and_self = 0, $selected_cats = false) {
89 - if (function_exists('wp_category_checklist')) :
90 - wp_category_checklist($post_id, $descendents_and_self, $selected_cats);
91 - else :
92 - // selected_cats is an array of integer cat_IDs / term_ids for
93 - // the categories that should be checked
94 - global $post_ID;
132 +require_once(dirname(__FILE__).'/feedwordpress-walker-category-checklist.class.php');
95 133
96 - $cats = get_nested_categories();
97 -
98 - // Undo damage from usort() in WP 2.0
99 - $dogs = array();
100 - foreach ($cats as $cat) :
101 - $dogs[$cat['cat_ID']] = $cat;
102 - endforeach;
103 - foreach ($selected_cats as $cat_id) :
104 - $dogs[$cat_id]['checked'] = true;
105 - endforeach;
106 - 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');
107 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 + ));
108 154 }
109 155
110 156 function fwp_time_elapsed ($ts) {
111 157 if (function_exists('human_time_diff')) :
@@ -130,9 +176,9 @@
130 176 if (get_option('feedwordpress_version') != FEEDWORDPRESS_VERSION) :
131 177 echo "<div class=\"wrap\">\n";
132 178 echo "<h2>Upgrading FeedWordPress...</h2>";
133 179
134 - $feedwordpress =& new FeedWordPress;
180 + $feedwordpress = new FeedWordPress;
135 181 $feedwordpress->upgrade_database($ver);
136 182 echo "<p><strong>Done!</strong> Upgraded database to version ".FEEDWORDPRESS_VERSION.".</p>\n";
137 183 echo "<form action=\"\" method=\"get\">\n";
138 184 echo "<div class=\"submit\"><input type=\"hidden\" name=\"page\" value=\"syndication.php\" />";
@@ -162,10 +208,15 @@
162 208
163 209 <p>This may take several minutes for a large installation.</p>
164 210
165 211 <form action="" method="post">
212 +<?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_upgrade'); ?>
166 213 <div class="submit"><input type="submit" name="action" value="Upgrade" /></div>
167 214 </form>
168 215 </div>
169 216 <?php
170 217 } // function fwp_upgrade_page ()
218 +
219 +function remove_dummy_zero ($var) {
220 + return !(is_numeric($var) and ((int) $var == 0));
221 +}
171 222