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