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
feedwordpress / compatability.php

compatability.php in FeedWordPress 2010.0905, at compatability.php

223 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 ################################################################################
3 ## LEGACY API: Replicate or mock up functions for legacy support purposes ######
4 ################################################################################
5
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() */
73
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;
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
94 if (!function_exists('stripslashes_deep')) {
95 function stripslashes_deep($value) {
96 $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
97 return $value;
98 }
99 }
100
101 if (!function_exists('sanitize_user')) {
102 function sanitize_user ($text, $strict = false) {
103 return $text; // Don't munge it if it wasn't munged going in...
104 }
105 }
106
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 */
124
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 }
130 } /* if */
131
132 require_once(dirname(__FILE__).'/feedwordpress-walker-category-checklist.class.php');
133
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');
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 ));
154 }
155
156 function fwp_time_elapsed ($ts) {
157 if (function_exists('human_time_diff')) :
158 if ($ts >= time()) :
159 $ret = __(human_time_diff($ts)." from now");
160 else :
161 $ret = __(human_time_diff($ts)." ago");
162 endif;
163 else :
164 $ret = strftime('%x %X', $ts);
165 endif;
166 return $ret;
167 }
168
169 ################################################################################
170 ## UPGRADE INTERFACE: Have users upgrade DB from older versions of FWP #########
171 ################################################################################
172
173 function fwp_upgrade_page () {
174 if (isset($GLOBALS['fwp_post']['action']) and $GLOBALS['fwp_post']['action']=='Upgrade') :
175 $ver = get_option('feedwordpress_version');
176 if (get_option('feedwordpress_version') != FEEDWORDPRESS_VERSION) :
177 echo "<div class=\"wrap\">\n";
178 echo "<h2>Upgrading FeedWordPress...</h2>";
179
180 $feedwordpress = new FeedWordPress;
181 $feedwordpress->upgrade_database($ver);
182 echo "<p><strong>Done!</strong> Upgraded database to version ".FEEDWORDPRESS_VERSION.".</p>\n";
183 echo "<form action=\"\" method=\"get\">\n";
184 echo "<div class=\"submit\"><input type=\"hidden\" name=\"page\" value=\"syndication.php\" />";
185 echo "<input type=\"submit\" value=\"Continue &raquo;\" /></form></div>\n";
186 echo "</div>\n";
187 return;
188 else :
189 echo "<div class=\"updated\"><p>Already at version ".FEEDWORDPRESS_VERSION."!</p></div>";
190 endif;
191 endif;
192 ?>
193 <div class="wrap">
194 <h2>Upgrade FeedWordPress</h2>
195
196 <p>It appears that you have installed FeedWordPress
197 <?php echo FEEDWORDPRESS_VERSION; ?> as an upgrade to an existing installation of
198 FeedWordPress. That's no problem, but you will need to take a minute out first
199 to upgrade your database: some necessary changes in how the software keeps
200 track of posts and feeds will cause problems such as duplicate posts and broken
201 templates if we were to continue without the upgrade.</p>
202
203 <p>Note that most of FeedWordPress's functionality is temporarily disabled
204 until we have successfully completed the upgrade. Everything should begin
205 working as normal again once the upgrade is complete. There's extraordinarily
206 little chance of any damage as the result of the upgrade, but if you're paranoid
207 like me you may want to back up your database before you proceed.</p>
208
209 <p>This may take several minutes for a large installation.</p>
210
211 <form action="" method="post">
212 <?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_upgrade'); ?>
213 <div class="submit"><input type="submit" name="action" value="Upgrade" /></div>
214 </form>
215 </div>
216 <?php
217 } // function fwp_upgrade_page ()
218
219 function remove_dummy_zero ($var) {
220 return !(is_numeric($var) and ((int) $var == 0));
221 }
222
223