XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/functions_for_wp20.php @ 272

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

#130 カスタムテンプレートタグでwp_parse_argsを利用
get_xpress_excerpt_contents()
xpress_the_content()
を除き修正

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