XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/functions_for_wp_old.php @ 378

Last change on this file since 378 was 378, checked in by toemon, 15 years ago

WP2011でwp_logoutエラー対策 fixes #210

File size: 8.8 KB
Line 
1<?php
2// wp_login override for wp2.3 under
3if ( !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        }
42endif;
43
44// Under WP2.1
45if (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        }
59endif;  // Under WP2.1
60
61// Under WP2.2
62if (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        }
94endif;  // Under WP2.2
95
96// Under WP2.2.1
97if (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
106endif;  // Under WP2.2.1
107
108// Under WP2.3
109if (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
166endif;  // Under WP2.3
167
168// Under WP2.5
169if (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
191endif;  // Under WP2.5
192
193// Under WP2.7
194if (version_compare($xoops_config->wp_version,'2.7', '<')) :
195        // Added WP2.7 separate_comments()
196        function &separate_comments(&$comments) {
197                $comments_by_type = array('comment' => array(), 'trackback' => array(), 'pingback' => array(), 'pings' => array());
198                $count = count($comments);
199                for ( $i = 0; $i < $count; $i++ ) {
200                        $type = $comments[$i]->comment_type;
201                        if ( empty($type) )
202                                $type = 'comment';
203                        $comments_by_type[$type][] = &$comments[$i];
204                        if ( 'trackback' == $type || 'pingback' == $type )
205                                $comments_by_type['pings'][] = &$comments[$i];
206                }
207
208                return $comments_by_type;
209        }
210
211        // Added WP2.7 get_comments()
212        function get_comments( $args = '' ) {
213                global $wpdb;
214
215                $defaults = array('status' => '', 'orderby' => 'comment_date_gmt', 'order' => 'DESC', 'number' => '', 'offset' => '', 'post_id' => 0);
216
217                $args = wp_parse_args( $args, $defaults );
218                extract( $args, EXTR_SKIP );
219
220                // $args can be whatever, only use the args defined in defaults to compute the key
221                $key = md5( serialize( compact(array_keys($defaults)) )  );
222                $last_changed = wp_cache_get('last_changed', 'comment');
223                if ( !$last_changed ) {
224                        $last_changed = time();
225                        wp_cache_set('last_changed', $last_changed, 'comment');
226                }
227                $cache_key = "get_comments:$key:$last_changed";
228
229                if ( $cache = wp_cache_get( $cache_key, 'comment' ) ) {
230                        return $cache;
231                }
232
233                $post_id = absint($post_id);
234
235                if ( 'hold' == $status )
236                        $approved = "comment_approved = '0'";
237                elseif ( 'approve' == $status )
238                        $approved = "comment_approved = '1'";
239                elseif ( 'spam' == $status )
240                        $approved = "comment_approved = 'spam'";
241                else
242                        $approved = "( comment_approved = '0' OR comment_approved = '1' )";
243
244                $order = ( 'ASC' == $order ) ? 'ASC' : 'DESC';
245
246                $orderby = 'comment_date_gmt';  // Hard code for now
247
248                $number = absint($number);
249                $offset = absint($offset);
250
251                if ( !empty($number) ) {
252                        if ( $offset )
253                                $number = 'LIMIT ' . $offset . ',' . $number;
254                        else
255                                $number = 'LIMIT ' . $number;
256
257                } else {
258                        $number = '';
259                }
260
261                if ( ! empty($post_id) )
262                        $post_where = "comment_post_ID = $post_id AND" ;
263                else
264                        $post_where = '';
265
266                $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE $post_where $approved ORDER BY $orderby $order $number" );
267                wp_cache_add( $cache_key, $comments, 'comment' );
268
269                return $comments;
270        }
271
272        // Added WP2.7 absint()
273        function locate_template($template_names, $load = false) {
274                if (!is_array($template_names))
275                        return '';
276
277                $located = '';
278                foreach($template_names as $template_name) {
279                        if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
280                                $located = STYLESHEETPATH . '/' . $template_name;
281                                break;
282                        } else if ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {
283                                $located = TEMPLATEPATH . '/' . $template_name;
284                                break;
285                        }
286                }
287
288                if ($load && '' != $located)
289                        load_template($located);
290
291                return $located;
292        }
293        // Added WP2.7 post_password_required()
294        function post_password_required( $post = null ) {
295                $post = get_post($post);
296
297                if ( empty($post->post_password) )
298                        return false;
299
300                if ( !isset($_COOKIE['wp-postpass_' . COOKIEHASH]) )
301                        return true;
302
303                if ( $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password )
304                        return true;
305
306                return false;
307        }
308        // Added WP2.7 comment_form_title()
309        function comment_form_title( $noreplytext = 'Leave a Reply', $replytext = 'Leave a Reply to %s', $linktoparent = TRUE ) {
310                global $comment;
311
312                $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
313
314                if ( 0 == $replytoid )
315                        echo $noreplytext;
316                else {
317                        $comment = get_comment($replytoid);
318                        $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author() . '</a>' : get_comment_author();
319                        printf( $replytext, $author );
320                }
321        }
322endif;  // Under WP2.7
323?>
Note: See TracBrowser for help on using the repository browser.