1 | <?php
|
---|
2 | // wp_login override for wp2.3 under
|
---|
3 | if ( !function_exists('wp_login') && version_compare($xoops_config->wp_version,'2.3', '<')) :
|
---|
4 | function wp_login($username, $password, $already_md5 = false) {
|
---|
5 | global $wpdb, $error;
|
---|
6 |
|
---|
7 |
|
---|
8 | if(is_object($GLOBALS["xoopsModule"]) && WP_BLOG_DIRNAME == $GLOBALS["xoopsModule"]->getVar("dirname")){
|
---|
9 | if(!is_object($GLOBALS["xoopsUser"])){
|
---|
10 | wp_clearcookie();
|
---|
11 | return false;
|
---|
12 | }
|
---|
13 | }
|
---|
14 |
|
---|
15 | $username = sanitize_user($username);
|
---|
16 |
|
---|
17 | if ( '' == $username )
|
---|
18 | return false;
|
---|
19 |
|
---|
20 | if ( '' == $password ) {
|
---|
21 | $error = __('<strong>ERROR</strong>: The password field is empty.');
|
---|
22 | return false;
|
---|
23 | }
|
---|
24 |
|
---|
25 | $login = get_userdatabylogin($username);
|
---|
26 | //$login = $wpdb->get_row("SELECT ID, user_login, user_pass FROM $wpdb->users WHERE user_login = '$username'");
|
---|
27 |
|
---|
28 | if (!$login) {
|
---|
29 | $error = __('<strong>ERROR</strong>: Invalid username.');
|
---|
30 | return false;
|
---|
31 | } else {
|
---|
32 | if ($login->user_login == $username) {
|
---|
33 | if ($login->user_pass == $password) return true;
|
---|
34 | if ($login->user_pass == md5($password)) return true;
|
---|
35 | }
|
---|
36 |
|
---|
37 | $error = __('<strong>ERROR</strong>: Incorrect password.');
|
---|
38 | $pwd = '';
|
---|
39 | return false;
|
---|
40 | }
|
---|
41 | }
|
---|
42 | endif;
|
---|
43 |
|
---|
44 | // Under WP2.1
|
---|
45 | if (version_compare($xoops_config->wp_version,'2.1', '<')) :
|
---|
46 | // ADD WP 2.1.0
|
---|
47 | function the_modified_date($d = '') {
|
---|
48 | echo apply_filters('the_modified_date', get_the_modified_date($d), $d);
|
---|
49 | }
|
---|
50 |
|
---|
51 | // ADD WP 2.1.0
|
---|
52 | function get_the_modified_date($d = '') {
|
---|
53 | if ( '' == $d )
|
---|
54 | $the_time = get_post_modified_time(get_option('date_format'));
|
---|
55 | else
|
---|
56 | $the_time = get_post_modified_time($d);
|
---|
57 | return apply_filters('get_the_modified_date', $the_time, $d);
|
---|
58 | }
|
---|
59 | endif; // Under WP2.1
|
---|
60 |
|
---|
61 | // Under WP2.2
|
---|
62 | if (version_compare($xoops_config->wp_version,'2.2', '<')):
|
---|
63 | // Added WP2.2 wp_parse_args()
|
---|
64 | function wp_parse_args( $args, $defaults = '' ) {
|
---|
65 | if ( is_object( $args ) )
|
---|
66 | $r = get_object_vars( $args );
|
---|
67 | elseif ( is_array( $args ) )
|
---|
68 | $r =& $args;
|
---|
69 | else
|
---|
70 | wp_parse_str( $args, $r );
|
---|
71 |
|
---|
72 | if ( is_array( $defaults ) )
|
---|
73 | return array_merge( $defaults, $r );
|
---|
74 | return $r;
|
---|
75 | }
|
---|
76 | // Added WP2.2 translate()
|
---|
77 | function translate($text, $domain = 'default') {
|
---|
78 | global $l10n;
|
---|
79 |
|
---|
80 | if (isset($l10n[$domain]))
|
---|
81 | return apply_filters('gettext', $l10n[$domain]->translate($text), $text, $domain);
|
---|
82 | else
|
---|
83 | return apply_filters('gettext', $text, $text, $domain);
|
---|
84 | }
|
---|
85 |
|
---|
86 | // Added WP2.2 translate_with_context()
|
---|
87 | function before_last_bar( $string ) {
|
---|
88 | $last_bar = strrpos( $string, '|' );
|
---|
89 | if ( false == $last_bar )
|
---|
90 | return $string;
|
---|
91 | else
|
---|
92 | return substr( $string, 0, $last_bar );
|
---|
93 | }
|
---|
94 | endif; // Under WP2.2
|
---|
95 |
|
---|
96 | // Under WP2.2.1
|
---|
97 | if (version_compare($xoops_config->wp_version,'2.2.1', '<')) :
|
---|
98 | // Added WP2.2.1 wp_parse_str()
|
---|
99 | function wp_parse_str( $string, &$array ) {
|
---|
100 | parse_str( $string, $array );
|
---|
101 | if ( get_magic_quotes_gpc() )
|
---|
102 | $array = stripslashes_deep( $array );
|
---|
103 | $array = apply_filters( 'wp_parse_str', $array );
|
---|
104 | }
|
---|
105 |
|
---|
106 | endif; // Under WP2.2.1
|
---|
107 |
|
---|
108 | // Under WP2.3
|
---|
109 | if (version_compare($xoops_config->wp_version,'2.3', '<')) :
|
---|
110 | if ( !function_exists('wp_sanitize_redirect') ) :
|
---|
111 | /**
|
---|
112 | * Sanitizes a URL for use in a redirect.
|
---|
113 | *
|
---|
114 | * @since 2.3
|
---|
115 | *
|
---|
116 | * @return string redirect-sanitized URL
|
---|
117 | **/
|
---|
118 | function wp_sanitize_redirect($location) {
|
---|
119 | $location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%]|i', '', $location);
|
---|
120 | $location = wp_kses_no_null($location);
|
---|
121 |
|
---|
122 | // remove %0d and %0a from location
|
---|
123 | $strip = array('%0d', '%0a');
|
---|
124 | $found = true;
|
---|
125 | while($found) {
|
---|
126 | $found = false;
|
---|
127 | foreach( (array) $strip as $val ) {
|
---|
128 | while(strpos($location, $val) !== false) {
|
---|
129 | $found = true;
|
---|
130 | $location = str_replace($val, '', $location);
|
---|
131 | }
|
---|
132 | }
|
---|
133 | }
|
---|
134 | return $location;
|
---|
135 | }
|
---|
136 | endif;
|
---|
137 |
|
---|
138 | if ( !function_exists('wp_sanitize_redirect') ) :
|
---|
139 | /**
|
---|
140 | * Sanitizes a URL for use in a redirect.
|
---|
141 | *
|
---|
142 | * @since 2.3
|
---|
143 | *
|
---|
144 | * @return string redirect-sanitized URL
|
---|
145 | **/
|
---|
146 | function wp_sanitize_redirect($location) {
|
---|
147 | $location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%]|i', '', $location);
|
---|
148 | $location = wp_kses_no_null($location);
|
---|
149 |
|
---|
150 | // remove %0d and %0a from location
|
---|
151 | $strip = array('%0d', '%0a');
|
---|
152 | $found = true;
|
---|
153 | while($found) {
|
---|
154 | $found = false;
|
---|
155 | foreach( (array) $strip as $val ) {
|
---|
156 | while(strpos($location, $val) !== false) {
|
---|
157 | $found = true;
|
---|
158 | $location = str_replace($val, '', $location);
|
---|
159 | }
|
---|
160 | }
|
---|
161 | }
|
---|
162 | return $location;
|
---|
163 | }
|
---|
164 | endif;
|
---|
165 |
|
---|
166 | endif; // Under WP2.3
|
---|
167 |
|
---|
168 | // Under WP2.5
|
---|
169 | if (version_compare($xoops_config->wp_version,'2.5', '<')) :
|
---|
170 | // Added WP2.5 absint()
|
---|
171 | function absint( $maybeint ) {
|
---|
172 | return abs( intval( $maybeint ) );
|
---|
173 | }
|
---|
174 | // Added WP2.5 translate_with_context()
|
---|
175 | function translate_with_context( $text, $domain = 'default' ) {
|
---|
176 | return before_last_bar(translate( $text, $domain ) );
|
---|
177 | }
|
---|
178 | /**
|
---|
179 | * @ignore
|
---|
180 | */
|
---|
181 | function _c() {}
|
---|
182 |
|
---|
183 | if ( !function_exists('wp_logout') ) {
|
---|
184 | function wp_logout() {
|
---|
185 | wp_clear_auth_cookie();
|
---|
186 | do_action('wp_logout');
|
---|
187 | }
|
---|
188 | }
|
---|
189 |
|
---|
190 |
|
---|
191 | endif; // Under WP2.5
|
---|
192 |
|
---|
193 | // Under WP2.7
|
---|
194 | if (version_compare($xoops_config->wp_version,'2.6', '<')) :
|
---|
195 | /**
|
---|
196 | * Guess the URL for the site.
|
---|
197 | *
|
---|
198 | * Will remove wp-admin links to retrieve only return URLs not in the wp-admin
|
---|
199 | * directory.
|
---|
200 | *
|
---|
201 | * @since 2.6.0
|
---|
202 | *
|
---|
203 | * @return string
|
---|
204 | */
|
---|
205 | function wp_guess_url() {
|
---|
206 | if ( defined('WP_SITEURL') && '' != WP_SITEURL ) {
|
---|
207 | $url = WP_SITEURL;
|
---|
208 | } else {
|
---|
209 | $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
|
---|
210 | $url = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
|
---|
211 | }
|
---|
212 | return $url;
|
---|
213 | }
|
---|
214 | endif; // Under WP2.6
|
---|
215 |
|
---|
216 | // Under WP2.7
|
---|
217 | if (version_compare($xoops_config->wp_version,'2.7', '<')) :
|
---|
218 | // Added WP2.7 separate_comments()
|
---|
219 | function &separate_comments(&$comments) {
|
---|
220 | $comments_by_type = array('comment' => array(), 'trackback' => array(), 'pingback' => array(), 'pings' => array());
|
---|
221 | $count = count($comments);
|
---|
222 | for ( $i = 0; $i < $count; $i++ ) {
|
---|
223 | $type = $comments[$i]->comment_type;
|
---|
224 | if ( empty($type) )
|
---|
225 | $type = 'comment';
|
---|
226 | $comments_by_type[$type][] = &$comments[$i];
|
---|
227 | if ( 'trackback' == $type || 'pingback' == $type )
|
---|
228 | $comments_by_type['pings'][] = &$comments[$i];
|
---|
229 | }
|
---|
230 |
|
---|
231 | return $comments_by_type;
|
---|
232 | }
|
---|
233 |
|
---|
234 | // Added WP2.7 get_comments()
|
---|
235 | function get_comments( $args = '' ) {
|
---|
236 | global $wpdb;
|
---|
237 |
|
---|
238 | $defaults = array('status' => '', 'orderby' => 'comment_date_gmt', 'order' => 'DESC', 'number' => '', 'offset' => '', 'post_id' => 0);
|
---|
239 |
|
---|
240 | $args = wp_parse_args( $args, $defaults );
|
---|
241 | extract( $args, EXTR_SKIP );
|
---|
242 |
|
---|
243 | // $args can be whatever, only use the args defined in defaults to compute the key
|
---|
244 | $key = md5( serialize( compact(array_keys($defaults)) ) );
|
---|
245 | $last_changed = wp_cache_get('last_changed', 'comment');
|
---|
246 | if ( !$last_changed ) {
|
---|
247 | $last_changed = time();
|
---|
248 | wp_cache_set('last_changed', $last_changed, 'comment');
|
---|
249 | }
|
---|
250 | $cache_key = "get_comments:$key:$last_changed";
|
---|
251 |
|
---|
252 | if ( $cache = wp_cache_get( $cache_key, 'comment' ) ) {
|
---|
253 | return $cache;
|
---|
254 | }
|
---|
255 |
|
---|
256 | $post_id = absint($post_id);
|
---|
257 |
|
---|
258 | if ( 'hold' == $status )
|
---|
259 | $approved = "comment_approved = '0'";
|
---|
260 | elseif ( 'approve' == $status )
|
---|
261 | $approved = "comment_approved = '1'";
|
---|
262 | elseif ( 'spam' == $status )
|
---|
263 | $approved = "comment_approved = 'spam'";
|
---|
264 | else
|
---|
265 | $approved = "( comment_approved = '0' OR comment_approved = '1' )";
|
---|
266 |
|
---|
267 | $order = ( 'ASC' == $order ) ? 'ASC' : 'DESC';
|
---|
268 |
|
---|
269 | $orderby = 'comment_date_gmt'; // Hard code for now
|
---|
270 |
|
---|
271 | $number = absint($number);
|
---|
272 | $offset = absint($offset);
|
---|
273 |
|
---|
274 | if ( !empty($number) ) {
|
---|
275 | if ( $offset )
|
---|
276 | $number = 'LIMIT ' . $offset . ',' . $number;
|
---|
277 | else
|
---|
278 | $number = 'LIMIT ' . $number;
|
---|
279 |
|
---|
280 | } else {
|
---|
281 | $number = '';
|
---|
282 | }
|
---|
283 |
|
---|
284 | if ( ! empty($post_id) )
|
---|
285 | $post_where = "comment_post_ID = $post_id AND" ;
|
---|
286 | else
|
---|
287 | $post_where = '';
|
---|
288 |
|
---|
289 | $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE $post_where $approved ORDER BY $orderby $order $number" );
|
---|
290 | wp_cache_add( $cache_key, $comments, 'comment' );
|
---|
291 |
|
---|
292 | return $comments;
|
---|
293 | }
|
---|
294 |
|
---|
295 | // Added WP2.7 absint()
|
---|
296 | function locate_template($template_names, $load = false) {
|
---|
297 | if (!is_array($template_names))
|
---|
298 | return '';
|
---|
299 |
|
---|
300 | $located = '';
|
---|
301 | foreach($template_names as $template_name) {
|
---|
302 | if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
|
---|
303 | $located = STYLESHEETPATH . '/' . $template_name;
|
---|
304 | break;
|
---|
305 | } else if ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {
|
---|
306 | $located = TEMPLATEPATH . '/' . $template_name;
|
---|
307 | break;
|
---|
308 | }
|
---|
309 | }
|
---|
310 |
|
---|
311 | if ($load && '' != $located)
|
---|
312 | load_template($located);
|
---|
313 |
|
---|
314 | return $located;
|
---|
315 | }
|
---|
316 | // Added WP2.7 post_password_required()
|
---|
317 | function post_password_required( $post = null ) {
|
---|
318 | $post = get_post($post);
|
---|
319 |
|
---|
320 | if ( empty($post->post_password) )
|
---|
321 | return false;
|
---|
322 |
|
---|
323 | if ( !isset($_COOKIE['wp-postpass_' . COOKIEHASH]) )
|
---|
324 | return true;
|
---|
325 |
|
---|
326 | if ( $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password )
|
---|
327 | return true;
|
---|
328 |
|
---|
329 | return false;
|
---|
330 | }
|
---|
331 | // Added WP2.7 comment_form_title()
|
---|
332 | function comment_form_title( $noreplytext = 'Leave a Reply', $replytext = 'Leave a Reply to %s', $linktoparent = TRUE ) {
|
---|
333 | global $comment;
|
---|
334 |
|
---|
335 | $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
|
---|
336 |
|
---|
337 | if ( 0 == $replytoid )
|
---|
338 | echo $noreplytext;
|
---|
339 | else {
|
---|
340 | $comment = get_comment($replytoid);
|
---|
341 | $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author() . '</a>' : get_comment_author();
|
---|
342 | printf( $replytext, $author );
|
---|
343 | }
|
---|
344 | }
|
---|
345 | endif; // Under WP2.7
|
---|
346 | ?> |
---|