| [ Index ] |
WordPress Source Cross Reference |
[Summary view] [Print] [Text view]
1 <?php 2 3 class retrospam_mgr { 4 var $spam_words; 5 var $comments_list; 6 var $found_comments; 7 8 function retrospam_mgr() { 9 global $wpdb; 10 11 $list = explode("\n", get_settings('moderation_keys') ); 12 $list = array_unique( $list ); 13 $this->spam_words = $list; 14 15 $this->comment_list = $wpdb->get_results("SELECT comment_ID AS ID, comment_content AS text, comment_approved AS approved, comment_author_url AS url, comment_author_ip AS ip, comment_author_email AS email FROM $wpdb->comments ORDER BY comment_ID ASC"); 16 } // End of class constructor 17 18 function move_spam( $id_list ) { 19 global $wpdb; 20 $cnt = 0; 21 $id_list = explode( ',', $id_list ); 22 23 foreach ( $id_list as $comment ) { 24 if ( $wpdb->query("update $wpdb->comments set comment_approved = '0' where comment_ID = '$comment'") ) { 25 $cnt++; 26 } 27 } 28 echo "<div class='updated'><p>$cnt comment"; 29 if ($cnt != 1 ) echo "s"; 30 echo " moved to the moderation queue.</p></div>\n"; 31 } // End function move_spam 32 33 function find_spam() { 34 $in_queue = 0; 35 36 foreach( $this->comment_list as $comment ) { 37 if( $comment->approved == 1 ) { 38 foreach( $this->spam_words as $word ) { 39 $word = trim($word); 40 if ( empty( $word ) ) 41 continue; 42 $fulltext = strtolower($comment->email.' '.$comment->url.' '.$comment->ip.' '.$comment->text); 43 if( false !== strpos( $fulltext, strtolower($word) ) ) { 44 $this->found_comments[] = $comment->ID; 45 break; 46 } 47 } 48 } else { 49 $in_queue++; 50 } 51 } 52 return array( 'found' => $this->found_comments, 'in_queue' => $in_queue ); 53 } // End function find_spam 54 55 function display_edit_form( $counters ) { 56 $numfound = count($counters[found]); 57 $numqueue = $counters[in_queue]; 58 59 $body = '<p>' . sprintf(__('Suspected spam comments: <strong>%s</strong>'), $numfound) . '</p>'; 60 61 if ( count($counters[found]) > 0 ) { 62 $id_list = implode( ',', $counters[found] ); 63 $body .= '<p><a href="options-discussion.php?action=retrospam&move=true&ids='.$id_list.'">'. __('Move suspect comments to moderation queue »') . '</a></p>'; 64 65 } 66 $head = '<div class="wrap"><h2>' . __('Check Comments Results:') . '</h2>'; 67 68 $foot .= '<p><a href="options-discussion.php">' . __('« Return to Discussion Options page.') . '</a></p></div>'; 69 70 return $head . $body . $foot; 71 } // End function display_edit_form 72 73 } 74 75 class WP { 76 var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots'); 77 78 var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type'); 79 var $extra_query_vars = array(); 80 81 var $query_vars; 82 var $query_string; 83 var $request; 84 var $matched_rule; 85 var $matched_query; 86 var $did_permalink = false; 87 88 function add_query_var($qv) { 89 $this->public_query_vars[] = $qv; 90 } 91 92 function parse_request($extra_query_vars = '') { 93 global $wp_rewrite; 94 95 $this->query_vars = array(); 96 97 if (! empty($extra_query_vars)) 98 parse_str($extra_query_vars, $this->extra_query_vars); 99 100 // Process PATH_INFO, REQUEST_URI, and 404 for permalinks. 101 102 // Fetch the rewrite rules. 103 $rewrite = $wp_rewrite->wp_rewrite_rules(); 104 105 if (! empty($rewrite)) { 106 // If we match a rewrite rule, this will be cleared. 107 $error = '404'; 108 $this->did_permalink = true; 109 110 $pathinfo = $_SERVER['PATH_INFO']; 111 $pathinfo_array = explode('?', $pathinfo); 112 $pathinfo = $pathinfo_array[0]; 113 $req_uri = $_SERVER['REQUEST_URI']; 114 $req_uri_array = explode('?', $req_uri); 115 $req_uri = $req_uri_array[0]; 116 $self = $_SERVER['PHP_SELF']; 117 $home_path = parse_url(get_settings('home')); 118 $home_path = $home_path['path']; 119 $home_path = trim($home_path, '/'); 120 121 // Trim path info from the end and the leading home path from the 122 // front. For path info requests, this leaves us with the requesting 123 // filename, if any. For 404 requests, this leaves us with the 124 // requested permalink. 125 $req_uri = str_replace($pathinfo, '', $req_uri); 126 $req_uri = trim($req_uri, '/'); 127 $req_uri = preg_replace("|^$home_path|", '', $req_uri); 128 $req_uri = trim($req_uri, '/'); 129 $pathinfo = trim($pathinfo, '/'); 130 $pathinfo = preg_replace("|^$home_path|", '', $pathinfo); 131 $pathinfo = trim($pathinfo, '/'); 132 $self = trim($self, '/'); 133 $self = preg_replace("|^$home_path|", '', $self); 134 $self = str_replace($home_path, '', $self); 135 $self = trim($self, '/'); 136 137 // The requested permalink is in $pathinfo for path info requests and 138 // $req_uri for other requests. 139 if ( ! empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo) ) { 140 $request = $pathinfo; 141 } else { 142 // If the request uri is the index, blank it out so that we don't try to match it against a rule. 143 if ( $req_uri == $wp_rewrite->index ) 144 $req_uri = ''; 145 $request = $req_uri; 146 } 147 148 $this->request = $request; 149 150 // Look for matches. 151 $request_match = $request; 152 foreach ($rewrite as $match => $query) { 153 // If the requesting file is the anchor of the match, prepend it 154 // to the path info. 155 if ((! empty($req_uri)) && (strpos($match, $req_uri) === 0) && ($req_uri != $request)) { 156 $request_match = $req_uri . '/' . $request; 157 } 158 159 if (preg_match("!^$match!", $request_match, $matches) || 160 preg_match("!^$match!", urldecode($request_match), $matches)) { 161 // Got a match. 162 $this->matched_rule = $match; 163 164 // Trim the query of everything up to the '?'. 165 $query = preg_replace("!^.+\?!", '', $query); 166 167 // Substitute the substring matches into the query. 168 eval("\$query = \"$query\";"); 169 $this->matched_query = $query; 170 171 // Parse the query. 172 parse_str($query, $perma_query_vars); 173 174 // If we're processing a 404 request, clear the error var 175 // since we found something. 176 if (isset($_GET['error'])) 177 unset($_GET['error']); 178 179 if (isset($error)) 180 unset($error); 181 182 break; 183 } 184 } 185 186 // If req_uri is empty or if it is a request for ourself, unset error. 187 if ( empty($request) || $req_uri == $self || strstr($_SERVER['PHP_SELF'], 'wp-admin/') ) { 188 if (isset($_GET['error'])) 189 unset($_GET['error']); 190 191 if (isset($error)) 192 unset($error); 193 194 if ( isset($perma_query_vars) && strstr($_SERVER['PHP_SELF'], 'wp-admin/') ) 195 unset($perma_query_vars); 196 197 $this->did_permalink = false; 198 } 199 } 200 201 $this->public_query_vars = apply_filters('query_vars', $this->public_query_vars); 202 203 for ($i=0; $i<count($this->public_query_vars); $i += 1) { 204 $wpvar = $this->public_query_vars[$i]; 205 if (isset($this->extra_query_vars[$wpvar])) 206 $this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar]; 207 elseif (isset($GLOBALS[$wpvar])) 208 $this->query_vars[$wpvar] = $GLOBALS[$wpvar]; 209 elseif (!empty($_POST[$wpvar])) 210 $this->query_vars[$wpvar] = $_POST[$wpvar]; 211 elseif (!empty($_GET[$wpvar])) 212 $this->query_vars[$wpvar] = $_GET[$wpvar]; 213 elseif (!empty($perma_query_vars[$wpvar])) 214 $this->query_vars[$wpvar] = $perma_query_vars[$wpvar]; 215 else 216 $this->query_vars[$wpvar] = ''; 217 } 218 219 for ($i=0; $i<count($this->private_query_vars); $i += 1) { 220 $wpvar = $this->private_query_vars[$i]; 221 if (isset($this->extra_query_vars[$wpvar])) 222 $this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar]; 223 } 224 225 if ( isset($error) ) 226 $this->query_vars['error'] = $error; 227 228 do_action('parse_request', array(&$this)); 229 } 230 231 function send_headers() { 232 @header('X-Pingback: '. get_bloginfo('pingback_url')); 233 if ( is_user_logged_in() ) 234 nocache_headers(); 235 if ( !empty($this->query_vars['error']) && '404' == $this->query_vars['error'] ) { 236 status_header( 404 ); 237 @header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); 238 } else if ( empty($this->query_vars['feed']) ) { 239 @header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); 240 } else { 241 // We're showing a feed, so WP is indeed the only thing that last changed 242 if ( $this->query_vars['withcomments'] ) 243 $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastcommentmodified('GMT'), 0).' GMT'; 244 else 245 $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT'; 246 $wp_etag = '"' . md5($wp_last_modified) . '"'; 247 @header("Last-Modified: $wp_last_modified"); 248 @header("ETag: $wp_etag"); 249 250 // Support for Conditional GET 251 if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) 252 $client_etag = stripslashes(stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])); 253 else $client_etag = false; 254 255 $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE']); 256 // If string is empty, return 0. If not, attempt to parse into a timestamp 257 $client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0; 258 259 // Make a timestamp for our most recent modification... 260 $wp_modified_timestamp = strtotime($wp_last_modified); 261 262 if ( ($client_last_modified && $client_etag) ? 263 (($client_modified_timestamp >= $wp_modified_timestamp) && ($client_etag == $wp_etag)) : 264 (($client_modified_timestamp >= $wp_modified_timestamp) || ($client_etag == $wp_etag)) ) { 265 status_header( 304 ); 266 exit; 267 } 268 } 269 270 do_action('send_headers', array(&$this)); 271 } 272 273 function build_query_string() { 274 $this->query_string = ''; 275 276 foreach (array_keys($this->query_vars) as $wpvar) { 277 if ( '' != $this->query_vars[$wpvar] ) { 278 $this->query_string .= (strlen($this->query_string) < 1) ? '' : '&'; 279 $this->query_string .= $wpvar . '=' . rawurlencode($this->query_vars[$wpvar]); 280 } 281 } 282 283 foreach ($this->private_query_vars as $wpvar) { 284 if (isset($GLOBALS[$wpvar]) && '' != $GLOBALS[$wpvar] && ! isset($this->extra_query_vars[$wpvar]) ) { 285 $this->query_string .= (strlen($this->query_string) < 1) ? '' : '&'; 286 $this->query_string .= $wpvar . '=' . rawurlencode($GLOBALS[$wpvar]); 287 } 288 } 289 290 $this->query_string = apply_filters('query_string', $this->query_string); 291 } 292 293 function register_globals() { 294 global $wp_query; 295 // Extract updated query vars back into global namespace. 296 foreach ($wp_query->query_vars as $key => $value) { 297 $GLOBALS[$key] = $value; 298 } 299 300 $GLOBALS['query_string'] = & $this->query_string; 301 $GLOBALS['posts'] = & $wp_query->posts; 302 $GLOBALS['post'] = & $wp_query->post; 303 $GLOBALS['request'] = & $wp_query->request; 304 305 if ( is_single() || is_page() ) { 306 $GLOBALS['more'] = 1; 307 $GLOBALS['single'] = 1; 308 } 309 } 310 311 function init() { 312 wp_get_current_user(); 313 } 314 315 function query_posts() { 316 $this->build_query_string(); 317 query_posts($this->query_string); 318 } 319 320 function handle_404() { 321 global $wp_query; 322 // Issue a 404 if a permalink request doesn't match any posts. Don't 323 // issue a 404 if one was already issued, if the request was a search, 324 // or if the request was a regular query string request rather than a 325 // permalink request. 326 if ( (0 == count($wp_query->posts)) && !is_404() && !is_search() && ( $this->did_permalink || (!empty($_SERVER['QUERY_STRING']) && (false === strpos($_SERVER['REQUEST_URI'], '?'))) ) ) { 327 $wp_query->set_404(); 328 status_header( 404 ); 329 } elseif( is_404() != true ) { 330 status_header( 200 ); 331 } 332 } 333 334 function main($query_args = '') { 335 $this->init(); 336 $this->parse_request($query_args); 337 $this->send_headers(); 338 $this->query_posts(); 339 $this->handle_404(); 340 $this->register_globals(); 341 do_action('wp', array(&$this)); 342 } 343 344 function WP() { 345 // Empty. 346 } 347 } 348 349 class WP_Error { 350 var $errors = array(); 351 352 function WP_Error($code = '', $message = '') { 353 if ( ! empty($code) ) 354 $this->errors[$code][] = $message; 355 } 356 357 function get_error_codes() { 358 if ( empty($this->errors) ) 359 return array(); 360 361 return array_keys($this->errors); 362 } 363 364 function get_error_code() { 365 $codes = $this->get_error_codes(); 366 367 if ( empty($codes) ) 368 return ''; 369 370 return $codes[0]; 371 } 372 373 function get_error_messages($code = '') { 374 // Return all messages if no code specified. 375 if ( empty($code) ) { 376 $all_messages = array(); 377 foreach ( $this->errors as $code => $messages ) 378 $all_messages = array_merge($all_messages, $messages); 379 380 return $all_messages; 381 } 382 383 if ( isset($this->errors[$code]) ) 384 return $this->errors[$code]; 385 else 386 return array(); 387 } 388 389 function get_error_message($code = '') { 390 if ( empty($code) ) 391 $code = $this->get_error_code(); 392 $messages = $this->get_error_messages($code); 393 if ( empty($messages) ) 394 return ''; 395 return $messages[0]; 396 } 397 398 function add($code, $message) { 399 $this->errors[$code][] = $message; 400 } 401 } 402 403 function is_wp_error($thing) { 404 if ( is_object($thing) && is_a($thing, 'WP_Error') ) 405 return true; 406 return false; 407 } 408 409 410 // A class for displaying various tree-like structures. Extend the Walker class to use it, see examples at the bottom 411 412 class Walker { 413 var $tree_type; 414 var $db_fields; 415 416 //abstract callbacks 417 function start_lvl($output) { return $output; } 418 function end_lvl($output) { return $output; } 419 function start_el($output) { return $output; } 420 function end_el($output) { return $output; } 421 422 function walk($elements, $to_depth) { 423