1 | <?php
|
---|
2 | ################################################################################
|
---|
3 | ## LEGACY API: Replicate or mock up functions for legacy support purposes ######
|
---|
4 | ################################################################################
|
---|
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 | class FeedWordPressCompatibility {
|
---|
19 | /*static*/ function validate_http_request ($action = -1, $capability = null) {
|
---|
20 | // Only worry about this if we're using a method with significant side-effects
|
---|
21 | if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') :
|
---|
22 | // Limit post by user capabilities
|
---|
23 | if (!is_null($capability) and !current_user_can($capability)) :
|
---|
24 | wp_die(__('Cheatin’ uh?'));
|
---|
25 | endif;
|
---|
26 |
|
---|
27 | // If check_admin_referer() checks a nonce.
|
---|
28 | if (function_exists('wp_verify_nonce')) :
|
---|
29 | check_admin_referer($action);
|
---|
30 |
|
---|
31 | // No nonces means no checking nonces.
|
---|
32 | else :
|
---|
33 | check_admin_referer();
|
---|
34 | endif;
|
---|
35 | endif;
|
---|
36 | } /* FeedWordPressCompatibility::validate_http_request() */
|
---|
37 |
|
---|
38 | /*static*/ function stamp_nonce ($action = -1) {
|
---|
39 | // stamp form with hidden fields for a nonce in WP 2.0.3 & later
|
---|
40 | if (function_exists('wp_nonce_field')) :
|
---|
41 | wp_nonce_field($action);
|
---|
42 | endif;
|
---|
43 | } /* FeedWordPressCompatibility::stamp_nonce() */
|
---|
44 | } /* class FeedWordPressCompatibility */
|
---|
45 |
|
---|
46 | if (!function_exists('stripslashes_deep')) {
|
---|
47 | function stripslashes_deep($value) {
|
---|
48 | $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
|
---|
49 | return $value;
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | if (!function_exists('get_option')) {
|
---|
54 | function get_option ($option) {
|
---|
55 | return get_settings($option);
|
---|
56 | }
|
---|
57 | }
|
---|
58 | if (!function_exists('current_user_can')) {
|
---|
59 | $fwp_capability['manage_options'] = 6;
|
---|
60 | $fwp_capability['manage_links'] = 5;
|
---|
61 | function current_user_can ($task) {
|
---|
62 | global $user_level;
|
---|
63 |
|
---|
64 | $can = false;
|
---|
65 |
|
---|
66 | // This is **not** a full replacement for current_user_can. It
|
---|
67 | // is only for checking the capabilities we care about via the
|
---|
68 | // WordPress 1.5 user levels.
|
---|
69 | switch ($task) :
|
---|
70 | case 'manage_options':
|
---|
71 | $can = ($user_level >= 6);
|
---|
72 | break;
|
---|
73 | case 'manage_links':
|
---|
74 | $can = ($user_level >= 5);
|
---|
75 | break;
|
---|
76 | case 'edit_files':
|
---|
77 | $can = ($user_level >= 9);
|
---|
78 | break;
|
---|
79 | endswitch;
|
---|
80 | return $can;
|
---|
81 | }
|
---|
82 | } else {
|
---|
83 | $fwp_capability['manage_options'] = 'manage_options';
|
---|
84 | $fwp_capability['manage_links'] = 'manage_links';
|
---|
85 | }
|
---|
86 | if (!function_exists('sanitize_user')) {
|
---|
87 | function sanitize_user ($text, $strict = false) {
|
---|
88 | return $text; // Don't munge it if it wasn't munged going in...
|
---|
89 | }
|
---|
90 | }
|
---|
91 | if (!function_exists('wp_insert_user')) {
|
---|
92 | function wp_insert_user ($userdata) {
|
---|
93 | global $wpdb;
|
---|
94 |
|
---|
95 | #-- Help WordPress 1.5.x quack like a duck
|
---|
96 | $login = $userdata['user_login'];
|
---|
97 | $author = $userdata['display_name'];
|
---|
98 | $nice_author = $userdata['user_nicename'];
|
---|
99 | $email = $userdata['user_email'];
|
---|
100 | $url = $userdata['user_url'];
|
---|
101 |
|
---|
102 | $wpdb->query (
|
---|
103 | "INSERT INTO $wpdb->users
|
---|
104 | SET
|
---|
105 | ID='0',
|
---|
106 | user_login='$login',
|
---|
107 | user_firstname='$author',
|
---|
108 | user_nickname='$author',
|
---|
109 | user_nicename='$nice_author',
|
---|
110 | user_description='$author',
|
---|
111 | user_email='$email',
|
---|
112 | user_url='$url'");
|
---|
113 | $id = $wpdb->insert_id;
|
---|
114 |
|
---|
115 | return $id;
|
---|
116 | }
|
---|
117 | } /* if (!function_exists('wp_insert_user')) */
|
---|
118 |
|
---|
119 | if (!function_exists('wp_die')) {
|
---|
120 | function wp_die ( $message, $title = '', $args = array() ) {
|
---|
121 | die($message);
|
---|
122 | } /* wp_die() */
|
---|
123 | } /* if */
|
---|
124 |
|
---|
125 | function fwp_category_checklist ($post_id = 0, $descendents_and_self = 0, $selected_cats = false) {
|
---|
126 | if (function_exists('wp_category_checklist')) :
|
---|
127 | wp_category_checklist($post_id, $descendents_and_self, $selected_cats);
|
---|
128 | else :
|
---|
129 | // selected_cats is an array of integer cat_IDs / term_ids for
|
---|
130 | // the categories that should be checked
|
---|
131 | global $post_ID;
|
---|
132 |
|
---|
133 | $cats = get_nested_categories();
|
---|
134 |
|
---|
135 | // Undo damage from usort() in WP 2.0
|
---|
136 | $dogs = array();
|
---|
137 | foreach ($cats as $cat) :
|
---|
138 | $dogs[$cat['cat_ID']] = $cat;
|
---|
139 | endforeach;
|
---|
140 | foreach ($selected_cats as $cat_id) :
|
---|
141 | $dogs[$cat_id]['checked'] = true;
|
---|
142 | endforeach;
|
---|
143 | write_nested_categories($dogs);
|
---|
144 | endif;
|
---|
145 | }
|
---|
146 |
|
---|
147 | function fwp_time_elapsed ($ts) {
|
---|
148 | if (function_exists('human_time_diff')) :
|
---|
149 | if ($ts >= time()) :
|
---|
150 | $ret = __(human_time_diff($ts)." from now");
|
---|
151 | else :
|
---|
152 | $ret = __(human_time_diff($ts)." ago");
|
---|
153 | endif;
|
---|
154 | else :
|
---|
155 | $ret = strftime('%x %X', $ts);
|
---|
156 | endif;
|
---|
157 | return $ret;
|
---|
158 | }
|
---|
159 |
|
---|
160 | ################################################################################
|
---|
161 | ## UPGRADE INTERFACE: Have users upgrade DB from older versions of FWP #########
|
---|
162 | ################################################################################
|
---|
163 |
|
---|
164 | function fwp_upgrade_page () {
|
---|
165 | if (isset($GLOBALS['fwp_post']['action']) and $GLOBALS['fwp_post']['action']=='Upgrade') :
|
---|
166 | $ver = get_option('feedwordpress_version');
|
---|
167 | if (get_option('feedwordpress_version') != FEEDWORDPRESS_VERSION) :
|
---|
168 | echo "<div class=\"wrap\">\n";
|
---|
169 | echo "<h2>Upgrading FeedWordPress...</h2>";
|
---|
170 |
|
---|
171 | $feedwordpress =& new FeedWordPress;
|
---|
172 | $feedwordpress->upgrade_database($ver);
|
---|
173 | echo "<p><strong>Done!</strong> Upgraded database to version ".FEEDWORDPRESS_VERSION.".</p>\n";
|
---|
174 | echo "<form action=\"\" method=\"get\">\n";
|
---|
175 | echo "<div class=\"submit\"><input type=\"hidden\" name=\"page\" value=\"syndication.php\" />";
|
---|
176 | echo "<input type=\"submit\" value=\"Continue »\" /></form></div>\n";
|
---|
177 | echo "</div>\n";
|
---|
178 | return;
|
---|
179 | else :
|
---|
180 | echo "<div class=\"updated\"><p>Already at version ".FEEDWORDPRESS_VERSION."!</p></div>";
|
---|
181 | endif;
|
---|
182 | endif;
|
---|
183 | ?>
|
---|
184 | <div class="wrap">
|
---|
185 | <h2>Upgrade FeedWordPress</h2>
|
---|
186 |
|
---|
187 | <p>It appears that you have installed FeedWordPress
|
---|
188 | <?php echo FEEDWORDPRESS_VERSION; ?> as an upgrade to an existing installation of
|
---|
189 | FeedWordPress. That's no problem, but you will need to take a minute out first
|
---|
190 | to upgrade your database: some necessary changes in how the software keeps
|
---|
191 | track of posts and feeds will cause problems such as duplicate posts and broken
|
---|
192 | templates if we were to continue without the upgrade.</p>
|
---|
193 |
|
---|
194 | <p>Note that most of FeedWordPress's functionality is temporarily disabled
|
---|
195 | until we have successfully completed the upgrade. Everything should begin
|
---|
196 | working as normal again once the upgrade is complete. There's extraordinarily
|
---|
197 | little chance of any damage as the result of the upgrade, but if you're paranoid
|
---|
198 | like me you may want to back up your database before you proceed.</p>
|
---|
199 |
|
---|
200 | <p>This may take several minutes for a large installation.</p>
|
---|
201 |
|
---|
202 | <form action="" method="post">
|
---|
203 | <?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_upgrade'); ?>
|
---|
204 | <div class="submit"><input type="submit" name="action" value="Upgrade" /></div>
|
---|
205 | </form>
|
---|
206 | </div>
|
---|
207 | <?php
|
---|
208 | } // function fwp_upgrade_page ()
|
---|
209 |
|
---|