XPressME Integration Kit

Trac

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

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

WP2.1.3MEへの対応 fixed #199
但しWP2.1.3ME自体のバグ(MySQL4.1以上でEUC-JPを使用したときの文字化け)があるので注意

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