| [ Index ] |
WordPress Source Cross Reference |
[Summary view] [Print] [Text view]
1 <?php 2 3 require_once(dirname(__FILE__).'/compat.php'); 4 5 function mysql2date($dateformatstring, $mysqlstring, $translate = true) { 6 global $wp_locale; 7 $m = $mysqlstring; 8 if ( empty($m) ) { 9 return false; 10 } 11 $i = mktime(substr($m,11,2),substr($m,14,2),substr($m,17,2),substr($m,5,2),substr($m,8,2),substr($m,0,4)); 12 13 if( 'U' == $dateformatstring ) 14 return $i; 15 16 if ( -1 == $i || false == $i ) 17 $i = 0; 18 19 if ( !empty($wp_locale->month) && !empty($wp_locale->weekday) && $translate ) { 20 $datemonth = $wp_locale->get_month(date('m', $i)); 21 $datemonth_abbrev = $wp_locale->get_month_abbrev($datemonth); 22 $dateweekday = $wp_locale->get_weekday(date('w', $i)); 23 $dateweekday_abbrev = $wp_locale->get_weekday_abbrev($dateweekday); 24 $datemeridiem = $wp_locale->get_meridiem(date('a', $i)); 25 $datemeridiem_capital = $wp_locale->get_meridiem(date('A', $i)); 26 $dateformatstring = ' '.$dateformatstring; 27 $dateformatstring = preg_replace("/([^\\\])D/", "\\1".backslashit($dateweekday_abbrev), $dateformatstring); 28 $dateformatstring = preg_replace("/([^\\\])F/", "\\1".backslashit($datemonth), $dateformatstring); 29 $dateformatstring = preg_replace("/([^\\\])l/", "\\1".backslashit($dateweekday), $dateformatstring); 30 $dateformatstring = preg_replace("/([^\\\])M/", "\\1".backslashit($datemonth_abbrev), $dateformatstring); 31 $dateformatstring = preg_replace("/([^\\\])a/", "\\1".backslashit($datemeridiem), $dateformatstring); 32 $dateformatstring = preg_replace("/([^\\\])A/", "\\1".backslashit($datemeridiem_capital), $dateformatstring); 33 34 $dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring)-1); 35 } 36 $j = @date($dateformatstring, $i); 37 if ( !$j ) { 38 // for debug purposes 39 // echo $i." ".$mysqlstring; 40 } 41 return $j; 42 } 43 44 function current_time($type, $gmt = 0) { 45 switch ($type) { 46 case 'mysql': 47 if ( $gmt ) $d = gmdate('Y-m-d H:i:s'); 48 else $d = gmdate('Y-m-d H:i:s', (time() + (get_settings('gmt_offset') * 3600))); 49 return $d; 50 break; 51 case 'timestamp': 52 if ( $gmt ) $d = time(); 53 else $d = time() + (get_settings('gmt_offset') * 3600); 54 return $d; 55 break; 56 } 57 } 58 59 function date_i18n($dateformatstring, $unixtimestamp) { 60 global $wp_locale; 61 $i = $unixtimestamp; 62 if ( (!empty($wp_locale->month)) && (!empty($wp_locale->weekday)) ) { 63 $datemonth = $wp_locale->get_month(date('m', $i)); 64 $datemonth_abbrev = $wp_locale->get_month_abbrev($datemonth); 65 $dateweekday = $wp_locale->get_weekday(date('w', $i)); 66 $dateweekday_abbrev = $wp_locale->get_weekday_abbrev($dateweekday); 67 $datemeridiem = $wp_locale->get_meridiem(date('a', $i)); 68 $datemeridiem_capital = $wp_locale->get_meridiem(date('A', $i)); 69 $dateformatstring = ' '.$dateformatstring; 70 $dateformatstring = preg_replace("/([^\\\])D/", "\\1".backslashit($dateweekday_abbrev), $dateformatstring); 71 $dateformatstring = preg_replace("/([^\\\])F/", "\\1".backslashit($datemonth), $dateformatstring); 72 $dateformatstring = preg_replace("/([^\\\])l/", "\\1".backslashit($dateweekday), $dateformatstring); 73 $dateformatstring = preg_replace("/([^\\\])M/", "\\1".backslashit($datemonth_abbrev), $dateformatstring); 74 $dateformatstring = preg_replace("/([^\\\])a/", "\\1".backslashit($datemeridiem), $dateformatstring); 75 $dateformatstring = preg_replace("/([^\\\])A/", "\\1".backslashit($datemeridiem_capital), $dateformatstring); 76 77 $dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring)-1); 78 } 79 $j = @date($dateformatstring, $i); 80 return $j; 81 } 82 83 function get_weekstartend($mysqlstring, $start_of_week) { 84 $my = substr($mysqlstring,0,4); 85 $mm = substr($mysqlstring,8,2); 86 $md = substr($mysqlstring,5,2); 87 $day = mktime(0,0,0, $md, $mm, $my); 88 $weekday = date('w',$day); 89 $i = 86400; 90 91 if ( $weekday < get_settings('start_of_week') ) 92 $weekday = 7 - (get_settings('start_of_week') - $weekday); 93 94 while ($weekday > get_settings('start_of_week')) { 95 $weekday = date('w',$day); 96 if ( $weekday < get_settings('start_of_week') ) 97 $weekday = 7 - (get_settings('start_of_week') - $weekday); 98 99 $day = $day - 86400; 100 $i = 0; 101 } 102 $week['start'] = $day + 86400 - $i; 103 // $week['end'] = $day - $i + 691199; 104 $week['end'] = $week['start'] + 604799; 105 return $week; 106 } 107 108 function get_lastpostdate($timezone = 'server') { 109 global $cache_lastpostdate, $pagenow, $wpdb; 110 $add_seconds_blog = get_settings('gmt_offset') * 3600; 111 $add_seconds_server = date('Z'); 112 if ( !isset($cache_lastpostdate[$timezone]) ) { 113 switch(strtolower($timezone)) { 114 case 'gmt': 115 $lastpostdate = $wpdb->get_var("SELECT post_date_gmt FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1"); 116 break; 117 case 'blog': 118 $lastpostdate = $wpdb->get_var("SELECT post_date FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1"); 119 break; 120 case 'server': 121 $lastpostdate = $wpdb->get_var("SELECT DATE_ADD(post_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1"); 122 break; 123 } 124 $cache_lastpostdate[$timezone] = $lastpostdate; 125 } else { 126 $lastpostdate = $cache_lastpostdate[$timezone]; 127 } 128 return $lastpostdate; 129 } 130 131 function get_lastpostmodified($timezone = 'server') { 132 global $cache_lastpostmodified, $pagenow, $wpdb; 133 $add_seconds_blog = get_settings('gmt_offset') * 3600; 134 $add_seconds_server = date('Z'); 135 if ( !isset($cache_lastpostmodified[$timezone]) ) { 136 switch(strtolower($timezone)) { 137 case 'gmt': 138 $lastpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1"); 139 break; 140 case 'blog': 141 $lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1"); 142 break; 143 case 'server': 144 $lastpostmodified = $wpdb->get_var("SELECT DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1"); 145 break; 146 } 147 $lastpostdate = get_lastpostdate($timezone); 148 if ( $lastpostdate > $lastpostmodified ) { 149 $lastpostmodified = $lastpostdate; 150 } 151 $cache_lastpostmodified[$timezone] = $lastpostmodified; 152 } else { 153 $lastpostmodified = $cache_lastpostmodified[$timezone]; 154 } 155 return $lastpostmodified; 156 } 157 158 function maybe_unserialize($original) { 159 if ( false !== $gm = @ unserialize($original) ) 160 return $gm; 161 else 162 return $original; 163 } 164 165 /* Options functions */ 166 167 function get_settings($setting) { 168 global $wpdb; 169 170 $value = wp_cache_get($setting, 'options'); 171 172 if ( false === $value ) { 173 if ( defined('WP_INSTALLING') ) 174 $wpdb->hide_errors(); 175 $row = $wpdb->get_row("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1"); 176 if ( defined('WP_INSTALLING') ) 177 $wpdb->show_errors(); 178 179 if( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values 180 $value = $row->option_value; 181 wp_cache_set($setting, $value, 'options'); 182 } else { 183 return false; 184 } 185 } 186 187 // If home is not set use siteurl. 188 if ( 'home' == $setting && '' == $value ) 189 return get_settings('siteurl'); 190 191 if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting ) 192 $value = preg_replace('|/+$|', '', $value); 193 194 return apply_filters( 'option_' . $setting, maybe_unserialize($value) ); 195 } 196 197 function get_option($option) { 198 return get_settings($option); 199 } 200 201 function form_option($option) { 202 echo htmlspecialchars( get_option($option), ENT_QUOTES ); 203 } 204 205 function get_alloptions() { 206 global $wpdb, $wp_queries; 207 $wpdb->hide_errors(); 208 if ( !$options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'") ) { 209 $options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options"); 210 } 211 $wpdb->show_errors(); 212 213 foreach ($options as $option) { 214 // "When trying to design a foolproof system, 215 // never underestimate the ingenuity of the fools :)" -- Dougal 216 if ( 'siteurl' == $option->option_name ) 217 $option->option_value = preg_replace('|/+$|', '', $option->option_value); 218 if ( 'home' == $option->option_name ) 219 $option->option_value = preg_replace('|/+$|', '', $option->option_value); 220 if ( 'category_base' == $option->option_name ) 221 $option->option_value = preg_replace('|/+$|', '', $option->option_value); 222 $value = maybe_unserialize($option->option_value); 223 $all_options->{$option->option_name} = apply_filters('pre_option_' . $option->option_name, $value); 224 } 225 return apply_filters('all_options', $all_options); 226 } 227 228 function update_option($option_name, $newvalue) { 229 global $wpdb; 230 231 if ( is_string($newvalue) ) 232 $newvalue = trim($newvalue); 233 234 // If the new and old values are the same, no need to update. 235 $oldvalue = get_option($option_name); 236 if ( $newvalue == $oldvalue ) { 237 return false; 238 } 239 240 if ( false === $oldvalue ) { 241 add_option($option_name, $newvalue); 242 return true; 243 } 244 245 $_newvalue = $newvalue; 246 if ( is_array($newvalue) || is_object($newvalue) ) 247 $newvalue = serialize($newvalue); 248 249 wp_cache_set($option_name, $newvalue, 'options'); 250 251 $newvalue = $wpdb->escape($newvalue); 252 $option_name = $wpdb->escape($option_name); 253 $wpdb->query("UPDATE $wpdb->options SET option_value = '$newvalue' WHERE option_name = '$option_name'"); 254 if ( $wpdb->rows_affected == 1 ) { 255 do_action("update_option_{$option_name}", array('old'=>$oldvalue, 'new'=>$_newvalue)); 256 return true; 257 } 258 return false; 259 } 260 261 // thx Alex Stapleton, http://alex.vort-x.net/blog/ 262 function add_option($name, $value = '', $description = '', $autoload = 'yes') { 263 global $wpdb; 264 265 // Make sure the option doesn't already exist 266 if ( false !== get_option($name) ) 267 return; 268 269 if ( is_array($value) || is_object($value) ) 270 $value = serialize($value); 271 272 wp_cache_set($name, $value, 'options'); 273 274 $name = $wpdb->escape($name); 275 $value = $wpdb->escape($value); 276 $description = $wpdb->escape($description); 277 $wpdb->query("INSERT INTO $wpdb->options (option_name, option_value, option_description, autoload) VALUES ('$name', '$value', '$description', '$autoload')"); 278 279 return; 280 } 281 282 function delete_option($name) { 283 global $wpdb; 284 // Get the ID, if no ID then return 285 $option_id = $wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = '$name'"); 286 if ( !$option_id ) return false; 287 $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = '$name'"); 288 wp_cache_delete($name, 'options'); 289 return true; 290 } 291 292 function gzip_compression() { 293 if ( !get_settings('gzipcompression') ) return false; 294 295 if ( extension_loaded('zlib') ) { 296 ob_start('ob_gzhandler'); 297 } 298 } 299 300 301 // functions to count the page generation time (from phpBB2) 302 // ( or just any time between timer_start() and timer_stop() ) 303 304 function timer_stop($display = 0, $precision = 3) { //if called like timer_stop(1), will echo $timetotal 305 global $timestart, $timeend; 306 $mtime = microtime(); 307 $mtime = explode(' ',$mtime); 308 $mtime = $mtime[1] + $mtime[0]; 309 $timeend = $mtime; 310 $timetotal = $timeend-$timestart; 311 if ( $display ) 312 echo number_format($timetotal,$precision); 313 return $timetotal; 314 } 315 316 function make_url_footnote($content) { 317 preg_match_all('/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches); 318 $j = 0; 319 for ($i=0; $i<count($matches[0]); $i++) { 320 $links_summary = (!$j) ? "\n" : $links_summary; 321 $j++; 322 $link_match = $matches[0][$i]; 323 $link_number = '['.($i+1).']'; 324 $link_url = $matches[2][$i]; 325 $link_text = $matches[4][$i]; 326 $content = str_replace($link_match, $link_text.' '.$link_number, $content); 327 $link_url = ((strtolower(substr($link_url,0,7)) != 'http://') && (strtolower(substr($link_url,0,8)) != 'https://')) ? get_settings('home') . $link_url : $link_url; 328 $links_summary .= "\n".$link_number.' '.$link_url; 329 } 330 $content = strip_tags($content); 331 $content .= $links_summary; 332 return $content; 333 } 334 335 336 function xmlrpc_getposttitle($content) { 337 global $post_default_title; 338 if ( preg_match('/<title>(.+?)<\/title>/is', $content, $matchtitle) ) { 339 $post_title = $matchtitle[0]; 340 $post_title = preg_replace('/<title>/si', '', $post_title); 341 $post_title = preg_replace('/<\/title>/si', '', $post_title); 342 } else { 343 $post_title = $post_default_title; 344 } 345 return $post_title; 346 } 347 348 function xmlrpc_getpostcategory($content) { 349 global $post_default_category; 350 if ( preg_match('/<category>(.+?)<\/category>/is', $content, $matchcat) ) { 351 $post_category = trim($matchcat[1], ','); 352 $post_category = explode(',', $post_category); 353 } else { 354 $post_category = $post_default_category; 355 } 356 return $post_category; 357 } 358 359 function xmlrpc_removepostdata($content) { 360 $content = preg_replace('/<title>(.+?)<\/title>/si', '', $content); 361 $content = preg_replace('/<category>(.+?)<\/category>/si', '', $content); 362 $content = trim($content); 363 return $content; 364 } 365 366 function debug_fopen($filename, $mode) { 367 global $debug; 368 if ( $debug == 1 ) { 369 $fp = fopen($filename, $mode); 370 return $fp; 371 } else { 372 return false; 373 } 374 } 375 376 function debug_fwrite($fp, $string) { 377 global $debug; 378 if ( $debug == 1 ) { 379 fwrite($fp, $string); 380 } 381 } 382 383 function debug_fclose($fp) { 384 global $debug; 385 if ( $debug == 1 ) { 386 fclose($fp); 387 } 388 } 389 390 function do_enclose( $content, $post_ID ) { 391 global $wp_version, $wpdb; 392 include_once (ABSPATH . WPINC . '/class-IXR.php'); 393 394 $log = debug_fopen(ABSPATH . '/enclosures.log', 'a'); 395 $post_links = array(); 396 debug_fwrite($log, 'BEGIN '.date('YmdHis', time())."\n"); 397 398 $pung = get_enclosed( $post_ID ); 399 400 $ltrs = '\w'; 401 $gunk = '/#~:.?+=&%@!\-'; 402 $punc = '.:?\-'; 403 $any = $ltrs . $gunk . $punc; 404 405 preg_match_all("{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp); 406 407 debug_fwrite($log, 'Post contents:'); 408 debug_fwrite($log, $content."\n"); 409 410 foreach($post_links_temp[0] as $link_test) : 411 if ( !in_array($link_test, $pung) ) : // If we haven't pung it already 412 $test = parse_url($link_test); 413 if ( isset($test['query']) ) 414 $post_links[] = $link_test; 415 elseif (($test['path'] != '/') && ($test['path'] != '')) 416 $post_links[] = $link_test; 417 endif; 418 endforeach; 419 420 foreach ($post_links as $url) : 421 if ( $url != '' && !$wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE post_id = '$post_ID' AND meta_key = 'enclosure' AND meta_value LIKE ('$url%')") ) { 422 if ( $headers = wp_get_http_headers( $url) ) { 423 $len = (int) $headers['content-length']; 424 $type = $wpdb->escape( $headers['content-type'] ); 425 $allowed_types = array( 'video', 'audio' ); 426 if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) { 427 $meta_value = "$url\n$len\n$type\n"; 428 $wpdb->query( "INSERT INTO `$wpdb->postmeta` ( `post_id` , `meta_key` , `meta_value` ) 429 VALUES ( '$post_ID', 'enclosure' , '$meta_value')" ); 430 } 431 } 432 } 433 endforeach; 434 } 435 436 function wp_get_http_headers( $url, $red = 1 ) { 437 global $wp_version; 438 @set_time_limit( 60 ); 439 440 if ( $red > 5 ) 441 return false; 442 443 $parts = parse_url( $url ); 444 $file = $parts['path'] . ($parts['query'] ? '?'.$parts['query'] : ''); 445 $host = $parts['host']; 446 if ( !isset( $parts['port'] ) ) 447 $parts['port'] = 80; 448 449 $head = "HEAD $file HTTP/1.1\r\nHOST: $host\r\nUser-Agent: WordPress/" . $wp_version . "\r\n\r\n"; 450 451 $fp = @fsockopen($host, $parts['port'], $err_num, $err_msg, 3); 452 if ( !$fp ) 453 return false; 454 455 $response = ''; 456 fputs( $fp, $head ); 457 while ( !feof( $fp ) && strpos( $response, "\r\n\r\n" ) == false ) 458 $response .= fgets( $fp, 2048 ); 459 fclose( $fp ); 460 preg_match_all('/(.*?): (.*)\r/', $response, $matches); 461 $count = count($matches[1]); 462 for ( $i = 0; $i < $count; $i++) { 463 $key = strtolower($matches[1][$i]); 464 $headers["$key"] = $matches[2][$i]; 465 } 466 467 preg_match('/.*([0-9]{3}).*/', $response, $return); 468 $headers['response'] = $return[1]; // HTTP response code eg 204, 200, 404 469 470 $code = $headers['response']; 471 if ( ('302' == $code || '301' == $code) && isset($headers['location']) ) 472 return wp_get_http_headers( $headers['location'], ++$red ); 473 474 return $headers; 475 } 476 477 function is_new_day() { 478 global $day, $previousday; 479 if ( $day != $previousday ) { 480 return(1); 481 } else { 482 return(0); 483 } 484 } 485 486 function update_post_cache(&$posts) { 487 global $post_cache; 488 489 if ( !$posts ) 490 return; 491 492 for ($i = 0; $i < count($posts); $i++) { 493 $post_cache[$posts[$i]->ID] = &$posts[$i]; 494 } 495 } 496 497 function clean_post_cache($id) { 498 global $post_cache; 499 500 if ( isset( $post_cache[$id] ) ) 501 unset( $post_cache[$id] ); 502 } 503 504 function update_page_cache(&$pages) { 505 global $page_cache; 506 507 if ( !$pages ) 508 return; 509 510 for ($i = 0; $i < count($pages); $i++) { 511 $page_cache[$pages[$i]->ID] = &$pages[$i]; 512 wp_cache_add($pages[$i]->ID, $pages[$i], 'pages'); 513 } 514 } 515 516 517 function clean_page_cache($id) { 518 global $page_cache; 519 520 if ( isset( $page_cache[$id] ) ) 521 unset( $page_cache[$id] ); 522 } 523 524 function update_post_category_cache($post_ids) { 525 global $wpdb, $category_cache; 526 527 if ( empty($post_ids) ) 528 return; 529 530 if ( is_array($post_ids) ) 531 $post_ids = implode(',', $post_ids); 532 533 $dogs = $wpdb->get_results("SELECT post_id, category_id FROM $wpdb->post2cat WHERE post_id IN ($post_ids)"); 534 535 if ( empty($dogs) ) 536 return; 537 538 foreach ($dogs as $catt) 539 $category_cache[$catt->post_id][$catt->category_id] = &get_category($catt->category_id); 540 } 541 542 function update_post_caches(&$posts) { 543 global $post_cache, $category_cache, $post_meta_cache; 544 global $wpdb; 545 546 // No point in doing all this work if we didn't match any posts. 547 if ( !$posts ) 548 return; 549 550 // Get the categories for all the posts 551 for ($i = 0; $i < count($posts); $i++) { 552 $post_id_array[] = $posts[$i]->ID; 553 $post_cache[$posts[$i]->ID] = &$posts[$i]; 554 } 555 556 $post_id_list = implode(',', $post_id_array); 557 558 update_post_category_cache($post_id_list); 559 560 // Get post-meta info 561 if ( $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE post_id IN($post_id_list) ORDER BY post_id, meta_key", ARRAY_A) ) { 562 // Change from flat structure to hierarchical: 563 $post_meta_cache = array(); 564 foreach ($meta_list as $metarow) { 565 $mpid = $metarow['post_id']; 566 $mkey = $metarow['meta_key']; 567 $mval = $metarow['meta_value']; 568 569 // Force subkeys to be array type: 570 if ( !isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]) ) 571 $post_meta_cache[$mpid] = array(); 572 if ( !isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]) ) 573 $post_meta_cache[$mpid]["$mkey"] = array(); 574 575 // Add a value to the current pid/key: 576 $post_meta_cache[$mpid][$mkey][] = $mval; 577 } 578 } 579 } 580 581 function update_category_cache() { 582 return true; 583 } 584 585 /* 586 add_query_arg: Returns a modified querystring by adding 587 a single key & value or an associative array. 588 Setting a key value to emptystring removes the key. 589 Omitting oldquery_or_uri uses the $_SERVER value. 590 591 Parameters: 592 add_query_arg(newkey, newvalue, oldquery_or_uri) or 593 add_query_arg(associative_array, oldquery_or_uri) 594 */ 595 function add_query_arg() { 596 $ret = ''; 597 if ( is_array(func_get_arg(0)) ) { 598 if ( @func_num_args() < 2 || '' == @func_get_arg(1) ) 599 $uri = $_SERVER['REQUEST_URI']; 600 else 601 $uri = @func_get_arg(1); 602 } else { 603 if ( @func_num_args() < 3 || '' == @func_get_arg(2) ) 604 $uri = $_SERVER['REQUEST_URI']; 605 else 606 $uri = @func_get_arg(2); 607 } 608 609 if ( preg_match('|^https?://|i', $uri, $matches) ) { 610 $protocol = $matches[0]; 611 $uri = substr($uri, strlen($protocol)); 612 } else { 613 $protocol = ''; 614 } 615 616 if ( strstr($uri, '?') ) { 617 $parts = explode('?', $uri, 2); 618 if ( 1 == count($parts) ) { 619 $base = '?'; 620 $query = $parts[0]; 621 } else { 622 $base = $parts[0] . '?'; 623 $query = $parts[1]; 624 } 625 } else if ( !empty($protocol) || strstr($uri, '/') ) { 626 $base = $uri . '?'; 627 $query = ''; 628 } else { 629 $base = ''; 630 $query = $uri; 631 } 632 633 parse_str($query, $qs); 634 if ( is_array(func_get_arg(0)) ) { 635 $kayvees = func_get_arg(0); 636 $qs = array_merge($qs, $kayvees); 637 } else { 638 $qs[func_get_arg(0)] = func_get_arg(1); 639 } 640 641 foreach($qs as $k => $v) { 642 if ( $v != '' ) { 643 if ( $ret != '' ) 644 $ret .= '&'; 645 $ret .= "$k=$v"; 646 } 647 } 648 $ret = $protocol . $base . $ret; 649 if ( get_magic_quotes_gpc() ) 650 $ret = stripslashes($ret); // parse_str() adds slashes if magicquotes is on. See: http://php.net/parse_str 651 return trim($ret, '?'); 652 } 653 654 /* 655 remove_query_arg: Returns a modified querystring by removing 656 a single key or an array of keys. 657 Omitting oldquery_or_uri uses the $_SERVER value. 658 659 Parameters: 660 remove_query_arg(removekey, [oldquery_or_uri]) or 661 remove_query_arg(removekeyarray, [oldquery_or_uri]) 662 */ 663 664 function remove_query_arg($key, $query='') { 665 if ( is_array($key) ) { // removing multiple keys 666 foreach ( (array) $key as $k ) 667 $query = add_query_arg($k, '', $query); 668 return $query; 669 } 670 return add_query_arg($key, '', $query); 671 } 672 673 function add_magic_quotes($array) { 674 global $wpdb; 675 676 foreach ($array as $k => $v) { 677 if ( is_array($v) ) { 678 $array[$k] = add_magic_quotes($v); 679 } else { 680 $array[$k] = $wpdb->escape($v); 681 } 682 } 683 return $array; 684 } 685 686 function wp_remote_fopen( $uri ) { 687 if ( ini_get('allow_url_fopen') ) { 688 $fp = fopen( $uri, 'r' ); 689 if ( !$fp ) 690 return false; 691 $linea = ''; 692 while( $remote_read = fread($fp, 4096) ) 693 $linea .= $remote_read; 694 fclose($fp); 695 return $linea; 696 } else if ( function_exists('curl_init') ) { 697 $handle = curl_init(); 698 curl_setopt ($handle, CURLOPT_URL, $uri); 699 curl_setopt ($handle, CURLOPT_CONNECTTIMEOUT, 1); 700 curl_setopt ($handle, CURLOPT_RETURNTRANSFER, 1); 701 $buffer = curl_exec($handle); 702 curl_close($handle); 703 return $buffer; 704 } else { 705 return false; 706 } 707 } 708 709 function wp($query_vars = '') { 710 global $wp; 711 712 $wp->main($query_vars); 713 } 714 715 function status_header( $header ) { 716 if ( 200 == $header ) 717 $text = 'OK'; 718 elseif ( 301 == $header ) 719 $text = 'Moved Permanently'; 720 elseif ( 302 == $header ) 721 $text = 'Moved Temporarily'; 722 elseif ( 304 == $header ) 723 $text = 'Not Modified'; 724 elseif ( 404 == $header ) 725 $text = 'Not Found'; 726 elseif ( 410 == $header ) 727 $text = 'Gone'; 728 729 @header("HTTP/1.1 $header $text"); 730 @header("Status: $header $text"); 731 } 732 733 function nocache_headers() { 734 @ header('Expires: Wed, 11 Jan 1984 05:00:00 GMT'); 735 @ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); 736 @ header('Cache-Control: no-cache, must-revalidate, max-age=0'); 737 @ header('Pragma: no-cache'); 738 } 739 740 function get_num_queries() { 741 global $wpdb; 742 return $wpdb->num_queries; 743 } 744 745 function bool_from_yn($yn) { 746 if ($yn == 'Y') return 1; 747 return 0; 748 } 749 750 function do_feed() { 751 $feed = get_query_var('feed'); 752 753 // Remove the pad, if present. 754 $feed = preg_replace('/^_+/', '', $feed); 755 756 if ($feed == '' || $feed == 'feed') 757 $feed = 'rss2'; 758 759 $for_comments = false; 760 if ( is_single() || (get_query_var('withcomments') == 1) ) { 761 $feed = 'rss2'; 762 $for_comments = true; 763 } 764 765 $hook = 'do_feed_' . $feed; 766 do_action($hook, $for_comments); 767 } 768 769 function do_feed_rdf() { 770 load_template(ABSPATH . 'wp-rdf.php'); 771 } 772 773 function do_feed_rss() { 774 load_template(ABSPATH . 'wp-rss.php'); 775 } 776 777 function do_feed_rss2($for_comments) { 778 if ( $for_comments ) { 779 load_template(ABSPATH . 'wp-commentsrss2.php'); 780 } else { 781 load_template(ABSPATH . 'wp-rss2.php'); 782 } 783 } 784 785 function do_feed_atom() { 786 load_template(ABSPATH . 'wp-atom.php'); 787 } 788 789 function do_robots() { 790 do_action('do_robotstxt'); 791 if ( '0' == get_option('blog_public') ) { 792 echo "User-agent: *\n"; 793 echo "Disallow: /\n"; 794 } else { 795 echo "User-agent: *\n"; 796 echo "Disallow:\n"; 797 } 798 } 799 800 function is_blog_installed() { 801 global $wpdb; 802 $wpdb->hide_errors(); 803 $installed = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'"); 804 $wpdb->show_errors(); 805 return $installed; 806 } 807 808 function wp_nonce_url($actionurl, $action = -1) { 809 return wp_specialchars(add_query_arg('_wpnonce', wp_create_nonce($action), $actionurl)); 810 } 811 812 function wp_nonce_field($action = -1) { 813 echo '<input type="hidden" name="_wpnonce" value="' . wp_create_nonce($action) . '" />'; 814 wp_referer_field(); 815 } 816 817 function wp_referer_field() { 818 $ref = wp_specialchars($_SERVER['REQUEST_URI']); 819 echo '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />'; 820 if ( wp_get_original_referer() ) { 821 $original_ref = wp_specialchars(stripslashes(wp_get_original_referer())); 822 echo '<input type="hidden" name="_wp_original_http_referer" value="'. $original_ref . '" />'; 823 } 824 } 825 826 function wp_original_referer_field() { 827 echo '<input type="hidden" name="_wp_original_http_referer" value="' . wp_specialchars(stripslashes($_SERVER['REQUEST_URI'])) . '" />'; 828 } 829 830 function wp_get_referer() { 831 foreach ( array($_REQUEST['_wp_http_referer'], $_SERVER['HTTP_REFERER']) as $ref ) 832 if ( !empty($ref) ) 833 return $ref; 834 return false; 835 } 836 837 function wp_get_original_referer() { 838 if ( !empty($_REQUEST['_wp_original_http_referer']) ) 839 return $_REQUEST['_wp_original_http_referer']; 840 return false; 841 } 842 843 function wp_mkdir_p($target) { 844 // from php.net/mkdir user contributed notes 845 if (file_exists($target)) { 846 if (! @ is_dir($target)) 847 return false; 848 else 849 return true; 850 } 851 852 // Attempting to create the directory may clutter up our display. 853 if (@ mkdir($target)) { 854 $stat = @ stat(dirname($target)); 855 $dir_perms = $stat['mode'] & 0007777; // Get the permission bits. 856 @ chmod($target, $dir_perms); 857 return true; 858 } else { 859 if ( is_dir(dirname($target)) ) 860 return false; 861 } 862 863 // If the above failed, attempt to create the parent node, then try again. 864 if (wp_mkdir_p(dirname($target))) 865 return wp_mkdir_p($target); 866 867 return false; 868 } 869 870 // Returns an array containing the current upload directory's path and url, or an error message. 871 function wp_upload_dir() { 872 $siteurl = get_settings('siteurl'); 873 //prepend ABSPATH to $dir and $siteurl to $url if they're not already there 874 $path = str_replace(ABSPATH, '', trim(get_settings('upload_path'))); 875 $dir = ABSPATH . $path; 876 $url = trailingslashit($siteurl) . $path; 877 878 if ( $dir == ABSPATH ) { //the option was empty 879 $dir = ABSPATH . 'wp-content/uploads'; 880 } 881 882 if ( defined('UPLOADS') ) { 883 $dir = ABSPATH . UPLOADS; 884 $url = trailingslashit($siteurl) . UPLOADS; 885 } 886 887 if ( get_settings('uploads_use_yearmonth_folders')) { 888 // Generate the yearly and monthly dirs 889 $time = current_time( 'mysql' ); 890 $y = substr( $time, 0, 4 ); 891 $m = substr( $time, 5, 2 ); 892 $dir = $dir . "/$y/$m"; 893 $url = $url . "/$y/$m"; 894 } 895 896 // Make sure we have an uploads dir 897 if ( ! wp_mkdir_p( $dir ) ) { 898 $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), $dir); 899 return array('error' => $message); 900 } 901 902 $uploads = array('path' => $dir, 'url' => $url, 'error' => false); 903 return apply_filters('upload_dir', $uploads); 904 } 905 906 function wp_upload_bits($name, $type, $bits) { 907 if ( empty($name) ) 908 return array('error' => __("Empty filename")); 909 910 $wp_filetype = wp_check_filetype($name); 911 if ( !$wp_filetype['ext'] ) 912 return array('error' => __("Invalid file type")); 913 914 $upload = wp_upload_dir(); 915 916 if ( $upload['error'] !== false ) 917 return $upload; 918 919 $number = ''; 920 $filename = $name; 921 $path_parts = pathinfo($filename); 922 $ext = $path_parts['extension']; 923 if ( empty($ext) ) 924 $ext = ''; 925 else 926 $ext = ".$ext"; 927 while ( file_exists($upload['path'] . "/$filename") ) { 928 if ( '' == "$number$ext" ) 929 $filename = $filename . ++$number . $ext; 930 else 931 $filename = str_replace("$number$ext", ++$number . $ext, $filename); 932 } 933 934 $new_file = $upload['path'] . "/$filename"; 935 if ( ! wp_mkdir_p( dirname($new_file) ) ) { 936 $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), dirname($new_file)); 937 return array('error' => $message); 938 } 939 940 $ifp = @ fopen($new_file, 'wb'); 941 if ( ! $ifp ) 942 return array('error' => "Could not write file $new_file."); 943 944 $success = @ fwrite($ifp, $bits); 945 fclose($ifp); 946 // Set correct file permissions 947 $stat = @ stat(dirname($new_file)); 948 $perms = $stat['mode'] & 0007777; 949 $perms = $perms & 0000666; 950 @ chmod($new_file, $perms); 951 952 // Compute the URL 953 $url = $upload['url'] . "/$filename"; 954 955 return array('file' => $new_file, 'url' => $url, 'error' => false); 956 } 957 958 function wp_check_filetype($filename, $mimes = null) { 959 // Accepted MIME types are set here as PCRE unless provided. 960 $mimes = is_array($mimes) ? $mimes : apply_filters('upload_mimes', array ( 961 'jpg|jpeg|jpe' => 'image/jpeg', 962 'gif' => 'image/gif', 963 'png' => 'image/png', 964 'bmp' => 'image/bmp', 965 'tif|tiff' => 'image/tiff', 966 'ico' => 'image/x-icon', 967 'asf|asx|wax|wmv|wmx' => 'video/asf', 968 'avi' => 'video/avi', 969 'mov|qt' => 'video/quicktime', 970 'mpeg|mpg|mpe' => 'video/mpeg', 971 'txt|c|cc|h' => 'text/plain', 972 'rtx' => 'text/richtext', 973 'css' => 'text/css', 974 'htm|html' => 'text/html', 975 'mp3|mp4' => 'audio/mpeg', 976 'ra|ram' => 'audio/x-realaudio', 977 'wav' => 'audio/wav', 978 'ogg' => 'audio/ogg', 979 'mid|midi' => 'audio/midi', 980 'wma' => 'audio/wma', 981 'rtf' => 'application/rtf', 982 'js' => 'application/javascript', 983 'pdf' => 'application/pdf', 984 'doc' => 'application/msword', 985 'pot|pps|ppt' => 'application/vnd.ms-powerpoint', 986 'wri' => 'application/vnd.ms-write', 987 'xla|xls|xlt|xlw' => 'application/vnd.ms-excel', 988 'mdb' => 'application/vnd.ms-access', 989 'mpp' => 'application/vnd.ms-project', 990 'swf' => 'application/x-shockwave-flash', 991 'class' => 'application/java', 992 'tar' => 'application/x-tar', 993 'zip' => 'application/zip', 994 'gz|gzip' => 'application/x-gzip', 995 'exe' => 'application/x-msdownload' 996 )); 997 998 $type = false; 999 $ext = false; 1000 1001 foreach ($mimes as $ext_preg => $mime_match) { 1002 $ext_preg = '!\.(' . $ext_preg . ')$!i'; 1003 if ( preg_match($ext_preg, $filename, $ext_matches) ) { 1004 $type = $mime_match; 1005 $ext = $ext_matches[1]; 1006 break; 1007 } 1008 } 1009 1010 return compact('ext', 'type'); 1011 } 1012 1013 function wp_proxy_check($ipnum) { 1014 if ( get_option('open_proxy_check') && isset($ipnum) ) { 1015 $ipnum = preg_replace( '/([0-9]{1,3})\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}).*/', '$1', $ipnum ); 1016 $rev_ip = implode( '.', array_reverse( explode( '.', $ipnum ) ) ); 1017 $lookup = $rev_ip . '.sbl-xbl.spamhaus.org.'; 1018 if ( $lookup != gethostbyname( $lookup ) ) 1019 return true; 1020 } 1021 1022 return false; 1023 } 1024 1025 function wp_explain_nonce($action) { 1026 if ( $action !== -1 && preg_match('/([a-z]+)-([a-z]+)(_(.+))?/', $action, $matches) ) { 1027 $verb = $matches[1]; 1028 $noun = $matches[2]; 1029 1030 $trans = array(); 1031 $trans['update']['attachment'] = array(__('Are you sure you want to edit this attachment: "%s"?'), 'get_the_title'); 1032 1033 $trans['add']['category'] = array(__('Are you sure you want to add this category?'), false); 1034 $trans['delete']['category'] = array(__('Are you sure you want to delete this category: "%s"?'), 'get_catname'); 1035 $trans['update']['category'] = array(__('Are you sure you want to edit this category: "%s"?'), 'get_catname'); 1036 1037 $trans['delete']['comment'] = array(__('Are you sure you want to delete this comment: "%s"?'), 'use_id'); 1038 $trans['unapprove']['comment'] = array(__('Are you sure you want to unapprove this comment: "%s"?'), 'use_id'); 1039 $trans['approve']['comment'] = array(__('Are you sure you want to approve this comment: "%s"?'), 'use_id'); 1040 $trans['update']['comment'] = array(__('Are you sure you want to edit this comment: "%s"?'), 'use_id'); 1041 $trans['bulk']['comments'] = array(__('Are you sure you want to bulk modify comments?'), false); 1042 $trans['moderate']['comments'] = array(__('Are you sure you want to moderate comments?'), false); 1043 1044 $trans['add']['bookmark'] = array(__('Are you sure you want to add this bookmark?'), false); 1045 $trans['delete']['bookmark'] = array(__('Are you sure you want to delete this bookmark: "%s"?'), 'use_id'); 1046 $trans['update']['bookmark'] = array(__('Are you sure you want to edit this bookmark: "%s"?'), 'use_id'); 1047 $trans['bulk']['bookmarks'] = array(__('Are you sure you want to bulk modify bookmarks?'), false); 1048 1049 $trans['add']['page'] = array(__('Are you sure you want to add this page?'), false); 1050 $trans['delete']['page'] = array(__('Are you sure you want to delete this page: "%s"?'), 'get_the_title'); 1051 $trans['update']['page'] = array(__('Are you sure you want to edit this page: "%s"?'), 'get_the_title'); 1052 1053 $trans['edit']['plugin'] = array(__('Are you sure you want to edit this plugin file: "%s"?'), 'use_id'); 1054 $trans['activate']['plugin'] = array(__('Are you sure you want to activate this plugin: "%s"?'), 'use_id'); 1055 $trans['deactivate']['plugin'] = array(__('Are you sure you want to deactivate this plugin: "%s"?'), 'use_id'); 1056 1057 $trans['add']['post'] = array(__('Are you sure you want to add this post?'), false); 1058 $trans['delete']['post'] = array(__('Are you sure you want to delete this post: "%s"?'), 'get_the_title'); 1059 $trans['update']['post'] = array(__('Are you sure you want to edit this post: "%s"?'), 'get_the_title'); 1060 1061 $trans['add']['user'] = array(__('Are you sure you want to add this user?'), false); 1062 $trans['delete']['users'] = array(__('Are you sure you want to delete users?'), false); 1063 $trans['bulk']['users'] = array(__('Are you sure you want to bulk modify users?'), false); 1064 $trans['update']['user'] = array(__('Are you sure you want to edit this user: "%s"?'), 'get_author_name'); 1065 $trans['update']['profile'] = array(__('Are you sure you want to modify the profile for: "%s"?'), 'get_author_name'); 1066 1067 $trans['update']['options'] = array(__('Are you sure you want to edit your settings?'), false); 1068 $trans['update']['permalink'] = array(__('Are you sure you want to change your permalink structure to: %s?'), 'use_id'); 1069 $trans['edit']['file'] = array(__('Are you sure you want to edit this file: "%s"?'), 'use_id'); 1070 $trans['edit']['theme'] = array(__('Are you sure you want to edit this theme file: "%s"?'), 'use_id'); 1071 $trans['switch']['theme'] = array(__('Are you sure you want to switch to this theme: "%s"?'), 'use_id'); 1072 1073 if ( isset($trans[$verb][$noun]) ) { 1074 if ( !empty($trans[$verb][$noun][1]) ) { 1075 $lookup = $trans[$verb][$noun][1]; 1076 $object = $matches[4]; 1077 if ( 'use_id' != $lookup ) 1078 $object = call_user_func($lookup, $object); 1079 return sprintf($trans[$verb][$noun][0], $object); 1080 } else { 1081 return $trans[$verb][$noun][0]; 1082 } 1083 } 1084 } 1085 1086 return __('Are you sure you want to do this'); 1087 } 1088 1089 function wp_nonce_ays($action) { 1090 global $pagenow, $menu, $submenu, $parent_file, $submenu_file; 1091 1092 $adminurl = get_settings('siteurl') . '/wp-admin'; 1093 if ( wp_get_referer() ) 1094 $adminurl = wp_get_referer(); 1095 1096 $title = __('WordPress Confirmation'); 1097 // Remove extra layer of slashes. 1098 $_POST = stripslashes_deep($_POST ); 1099 if ( $_POST ) { 1100 $q = http_build_query($_POST); 1101 $q = explode( ini_get('arg_separator.output'), $q); 1102 $html .= "\t<form method='post' action='$pagenow'>\n"; 1103 foreach ( (array) $q as $a ) { 1104 $v = substr(strstr($a, '='), 1); 1105 $k = substr($a, 0, -(strlen($v)+1)); 1106 $html .= "\t\t<input type='hidden' name='" . wp_specialchars( urldecode($k), 1 ) . "' value='" . wp_specialchars( urldecode($v), 1 ) . "' />\n"; 1107 } 1108 $html .= "\t\t<input type='hidden' name='_wpnonce' value='" . wp_create_nonce($action) . "' />\n"; 1109 $html .= "\t\t<div id='message' class='confirm fade'>\n\t\t<p>" . wp_explain_nonce($action) . "</p>\n\t\t<p><a href='$adminurl'>" . __('No') . "</a> <input type='submit' value='" . __('Yes') . "' /></p>\n\t\t</div>\n\t</form>\n"; 1110 } else { 1111 $html .= "\t<div id='message' class='confirm fade'>\n\t<p>" . wp_explain_nonce($action) . "</p>\n\t<p><a href='$adminurl'>" . __('No') . "</a> <a href='" . add_query_arg( '_wpnonce', wp_create_nonce($action), $_SERVER['REQUEST_URI'] ) . "'>" . __('Yes') . "</a></p>\n\t</div>\n"; 1112 } 1113 $html .= "</body>\n</html>"; 1114 wp_die($html, $title); 1115 } 1116 1117 function wp_die($message, $title = '') { 1118 header('Content-Type: text/html; charset=utf-8'); 1119 1120 if ( empty($title) ) 1121 $title = __('WordPress › Error'); 1122 ?> 1123 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 1124 <html xmlns="http://www.w3.org/1999/xhtml"> 1125 <head> 1126 <title><?php echo $title ?></title> 1127 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 1128 <style media="screen" type="text/css"> 1129 <!-- 1130 html { 1131 background: #eee; 1132 } 1133 body { 1134 background: #fff; 1135 color: #000; 1136 font-family: Georgia, "Times New Roman", Times, serif; 1137 margin-left: 25%; 1138 margin-right: 25%; 1139 padding: .2em 2em; 1140 } 1141 1142 h1 { 1143 color: #006; 1144 font-size: 18px; 1145 font-weight: lighter; 1146 } 1147 1148 h2 { 1149 font-size: 16px; 1150 } 1151 1152 p, li, dt { 1153 line-height: 140%; 1154 padding-bottom: 2px; 1155 } 1156 1157 ul, ol { 1158 padding: 5px 5px 5px 20px; 1159 } 1160 #logo { 1161 margin-bottom: 2em; 1162 } 1163 --> 1164 </style> 1165 </head> 1166 <body> 1167 <h1 id="logo"><img alt="WordPress" src="<?php echo get_settings('siteurl'); ?>/wp-admin/images/wordpress-logo.png" /></h1> 1168 <p><?php echo $message; ?></p> 1169 </body> 1170 </html> 1171 <?php 1172 1173 die(); 1174 } 1175 1176 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Jul 15 11:57:04 2006 | Courtesy of Taragana |