Changeset 2941 for trunk/wp-includes/functions.php
- Timestamp:
- 10/10/2005 09:25:38 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r2933 r2941 3 3 require_once(dirname(__FILE__).'/functions-compat.php'); 4 4 5 if ( !function_exists('_')) {5 if ( !function_exists('_') ) { 6 6 function _($string) { 7 7 return $string; … … 11 11 function get_profile($field, $user = false) { 12 12 global $wpdb; 13 if ( !$user)13 if ( !$user ) 14 14 $user = $wpdb->escape($_COOKIE[USER_COOKIE]); 15 15 return $wpdb->get_var("SELECT $field FROM $wpdb->users WHERE user_login = '$user'"); … … 19 19 global $month, $weekday, $month_abbrev, $weekday_abbrev; 20 20 $m = $mysqlstring; 21 if ( empty($m)) {21 if ( empty($m) ) { 22 22 return false; 23 23 } 24 $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)); 25 if ( !empty($month) && !empty($weekday) && $translate) {24 $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)); 25 if ( !empty($month) && !empty($weekday) && $translate ) { 26 26 $datemonth = $month[date('m', $i)]; 27 27 $datemonth_abbrev = $month_abbrev[$datemonth]; 28 28 $dateweekday = $weekday[date('w', $i)]; 29 $dateweekday_abbrev = $weekday_abbrev[$dateweekday]; 29 $dateweekday_abbrev = $weekday_abbrev[$dateweekday]; 30 30 $dateformatstring = ' '.$dateformatstring; 31 31 $dateformatstring = preg_replace("/([^\\\])D/", "\\1".backslashit($dateweekday_abbrev), $dateformatstring); … … 33 33 $dateformatstring = preg_replace("/([^\\\])l/", "\\1".backslashit($dateweekday), $dateformatstring); 34 34 $dateformatstring = preg_replace("/([^\\\])M/", "\\1".backslashit($datemonth_abbrev), $dateformatstring); 35 35 36 36 $dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring)-1); 37 37 } 38 38 $j = @date($dateformatstring, $i); 39 if ( !$j) {39 if ( !$j ) { 40 40 // for debug purposes 41 41 // echo $i." ".$mysqlstring; … … 47 47 switch ($type) { 48 48 case 'mysql': 49 if ( $gmt) $d = gmdate('Y-m-d H:i:s');49 if ( $gmt ) $d = gmdate('Y-m-d H:i:s'); 50 50 else $d = gmdate('Y-m-d H:i:s', (time() + (get_settings('gmt_offset') * 3600))); 51 51 return $d; 52 52 break; 53 53 case 'timestamp': 54 if ( $gmt) $d = time();54 if ( $gmt ) $d = time(); 55 55 else $d = time() + (get_settings('gmt_offset') * 3600); 56 56 return $d; … … 61 61 function date_i18n($dateformatstring, $unixtimestamp) { 62 62 global $month, $weekday, $month_abbrev, $weekday_abbrev; 63 $i = $unixtimestamp; 64 if ( (!empty($month)) && (!empty($weekday))) {63 $i = $unixtimestamp; 64 if ( (!empty($month)) && (!empty($weekday)) ) { 65 65 $datemonth = $month[date('m', $i)]; 66 66 $datemonth_abbrev = $month_abbrev[$datemonth]; 67 67 $dateweekday = $weekday[date('w', $i)]; 68 $dateweekday_abbrev = $weekday_abbrev[$dateweekday]; 68 $dateweekday_abbrev = $weekday_abbrev[$dateweekday]; 69 69 $dateformatstring = ' '.$dateformatstring; 70 70 $dateformatstring = preg_replace("/([^\\\])D/", "\\1".backslashit($dateweekday_abbrev), $dateformatstring); … … 86 86 $i = 86400; 87 87 88 if ( $weekday < get_settings('start_of_week'))88 if ( $weekday < get_settings('start_of_week') ) 89 89 $weekday = 7 - (get_settings('start_of_week') - $weekday); 90 90 91 91 while ($weekday > get_settings('start_of_week')) { 92 92 $weekday = date('w',$day); 93 if ( $weekday < get_settings('start_of_week'))93 if ( $weekday < get_settings('start_of_week') ) 94 94 $weekday = 7 - (get_settings('start_of_week') - $weekday); 95 95 … … 98 98 } 99 99 $week['start'] = $day + 86400 - $i; 100 // $week['end']= $day - $i + 691199;100 // $week['end'] = $day - $i + 691199; 101 101 $week['end'] = $week['start'] + 604799; 102 102 return $week; … … 145 145 } 146 146 $lastpostdate = get_lastpostdate($timezone); 147 if ( $lastpostdate > $lastpostmodified) {147 if ( $lastpostdate > $lastpostmodified ) { 148 148 $lastpostmodified = $lastpostdate; 149 149 } … … 180 180 preg_match('#[?&](p|page_id)=(\d+)#', $url, $values); 181 181 $id = intval($values[2]); 182 if ( $id) return $id;182 if ( $id ) return $id; 183 183 184 184 // Check to see if we are using rewrite rules … … 188 188 if ( empty($rewrite) ) 189 189 return 0; 190 190 191 191 // $url cleanup by Mark Jaquith 192 192 // This fixes things like #anchors, ?query=strings, missing 'www.', 193 193 // added 'www.', or added 'index.php/' that will mess up our WP_Query 194 194 // and return a false negative 195 195 196 196 // Get rid of the #anchor 197 197 $url_split = explode('#', $url); 198 198 $url = $url_split[0]; 199 199 200 200 // Get rid of URI ?query=string 201 201 $url_split = explode('?', $url); 202 202 $url = $url_split[0]; 203 203 204 204 // Add 'www.' if it is absent and should be there 205 205 if ( false !== strpos(get_settings('home'), '://www.') && false === strpos($url, '://www.') ) 206 206 $url = str_replace('://', '://www.', $url); 207 207 208 208 // Strip 'www.' if it is present and shouldn't be 209 209 if ( false === strpos(get_settings('home'), '://www.') ) 210 210 $url = str_replace('://www.', '://', $url); 211 211 212 212 // Strip 'index.php/' if we're not using path info permalinks 213 213 if ( false === strpos($rewrite, 'index.php/') ) 214 214 $url = str_replace('index.php/', '', $url); 215 215 216 // Chop off http://domain.com217 216 if ( false !== strpos($url, get_settings('home')) ) { 217 // Chop off http://domain.com 218 218 $url = str_replace(get_settings('home'), '', $url); 219 219 } else { 220 // Chop off /path/to/blog220 // Chop off /path/to/blog 221 221 $home_path = parse_url(get_settings('home')); 222 222 $home_path = $home_path['path']; … … 226 226 // Trim leading and lagging slashes 227 227 $url = trim($url, '/'); 228 228 229 229 $request = $url; 230 230 231 231 // Done with cleanup 232 232 233 233 // Look for matches. 234 234 $request_match = $request; … … 236 236 // If the requesting file is the anchor of the match, prepend it 237 237 // to the path info. 238 if ( (! empty($url)) && (strpos($match, $url) === 0)) {238 if ( (! empty($url)) && (strpos($match, $url) === 0) ) { 239 239 $request_match = $url . '/' . $request; 240 240 } 241 241 242 if ( preg_match("!^$match!", $request_match, $matches)) {242 if ( preg_match("!^$match!", $request_match, $matches) ) { 243 243 // Got a match. 244 244 // Trim the query of everything up to the '?'. 245 245 $query = preg_replace("!^.+\?!", '', $query); 246 246 247 247 // Substitute the substring matches into the query. 248 248 eval("\$query = \"$query\";"); … … 254 254 } 255 255 } 256 257 256 return 0; 258 257 } … … 262 261 263 262 function get_settings($setting) { 264 263 global $wpdb, $cache_settings, $cache_nonexistantoptions; 265 264 if ( strstr($_SERVER['REQUEST_URI'], 'wp-admin/install.php') || defined('WP_INSTALLING') ) 266 265 return false; … … 272 271 $cache_nonexistantoptions = array(); 273 272 274 if ( 'home' == $setting && '' == $cache_settings->home)273 if ( 'home' == $setting && '' == $cache_settings->home ) 275 274 return apply_filters('option_' . $setting, $cache_settings->siteurl); 276 275 … … 290 289 291 290 @ $kellogs = unserialize($option); 292 if ( $kellogs !== FALSE)291 if ( $kellogs !== FALSE ) 293 292 return apply_filters('option_' . $setting, $kellogs); 294 293 else return apply_filters('option_' . $setting, $option); … … 317 316 global $wpdb, $wp_queries; 318 317 $wpdb->hide_errors(); 319 if ( !$options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'")) {318 if ( !$options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'") ) { 320 319 $options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options"); 321 320 } … … 323 322 324 323 foreach ($options as $option) { 325 // "When trying to design a foolproof system, 324 // "When trying to design a foolproof system, 326 325 // never underestimate the ingenuity of the fools :)" -- Dougal 327 if ('siteurl' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value); 328 if ('home' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value); 329 if ('category_base' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value); 326 if ( 'siteurl' == $option->option_name ) 327 $option->option_value = preg_replace('|/+$|', '', $option->option_value); 328 if ( 'home' == $option->option_name ) 329 $option->option_value = preg_replace('|/+$|', '', $option->option_value); 330 if ( 'category_base' == $option->option_name ) 331 $option->option_value = preg_replace('|/+$|', '', $option->option_value); 330 332 @ $value = unserialize($option->option_value); 331 if ( $value === FALSE)333 if ( $value === FALSE ) 332 334 $value = $option->option_value; 333 335 $all_options->{$option->option_name} = apply_filters('pre_option_' . $option->option_name, $value); … … 341 343 if ( is_string($newvalue) ) 342 344 $newvalue = trim($newvalue); 343 345 344 346 // If the new and old values are the same, no need to update. 345 347 if ( $newvalue == get_option($option_name) ) … … 379 381 $value = serialize($value); 380 382 381 if ( !$wpdb->get_var("SELECT option_name FROM $wpdb->options WHERE option_name = '$name'") ) {383 if ( !$wpdb->get_var("SELECT option_name FROM $wpdb->options WHERE option_name = '$name'") ) { 382 384 $name = $wpdb->escape($name); 383 385 $value = $wpdb->escape($value); … … 385 387 $wpdb->query("INSERT INTO $wpdb->options (option_name, option_value, option_description, autoload) VALUES ('$name', '$value', '$description', '$autoload')"); 386 388 387 if ($wpdb->insert_id) {389 if ( $wpdb->insert_id ) { 388 390 global $cache_settings; 389 391 $cache_settings->{$name} = $original; … … 397 399 // Get the ID, if no ID then return 398 400 $option_id = $wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = '$name'"); 399 if ( !$option_id) return false;401 if ( !$option_id ) return false; 400 402 $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = '$name'"); 401 403 return true; … … 404 406 function add_post_meta($post_id, $key, $value, $unique = false) { 405 407 global $wpdb, $post_meta_cache; 406 407 if ( $unique) {408 if ( $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key408 409 if ( $unique ) { 410 if ( $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key 409 411 = '$key' AND post_id = '$post_id'") ) { 410 412 return false; … … 416 418 $value = $wpdb->escape(serialize($value)); 417 419 418 $wpdb->query("INSERT INTO $wpdb->postmeta 419 (post_id,meta_key,meta_value) 420 VALUES ('$post_id','$key','$value') 421 "); 420 $wpdb->query("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value) VALUES ('$post_id','$key','$value')"); 422 421 423 422 $post_meta_cache['$post_id'][$key][] = $original; … … 429 428 global $wpdb, $post_meta_cache; 430 429 431 if ( empty($value)) {430 if ( empty($value) ) { 432 431 $meta_id = $wpdb->get_var("SELECT meta_id FROM $wpdb->postmeta WHERE 433 432 post_id = '$post_id' AND meta_key = '$key'"); … … 437 436 } 438 437 439 if (!$meta_id) return false; 440 441 if (empty($value)) { 438 if ( !$meta_id ) 439 return false; 440 441 if ( empty($value) ) { 442 442 $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id' 443 443 AND meta_key = '$key'"); … … 453 453 454 454 unset($post_meta_cache['$post_id'][$key]); 455 455 456 456 return true; 457 457 } … … 460 460 global $wpdb, $post_meta_cache; 461 461 462 if ( isset($post_meta_cache[$post_id][$key])) {463 if ( $single) {462 if ( isset($post_meta_cache[$post_id][$key]) ) { 463 if ( $single ) { 464 464 return $post_meta_cache[$post_id][$key][0]; 465 465 } else { … … 471 471 472 472 $values = array(); 473 if ( $metalist) {473 if ( $metalist ) { 474 474 foreach ($metalist as $metarow) { 475 475 $values[] = $metarow[0]; … … 477 477 } 478 478 479 if ( $single) {480 if ( count($values)) {479 if ( $single ) { 480 if ( count($values) ) { 481 481 $return = $values[0]; 482 482 } else { … … 488 488 489 489 @ $kellogs = unserialize($return); 490 if ( $kellogs !== FALSE)490 if ( $kellogs !== FALSE ) 491 491 return $kellogs; 492 492 else return $return; … … 503 503 if ( is_array($prev_value) || is_object($prev_value) ) 504 504 $prev_value = serialize($value); 505 506 if (! $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key505 506 if (! $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key 507 507 = '$key' AND post_id = '$post_id'") ) { 508 508 return false; 509 509 } 510 510 511 if ( empty($prev_value)) {511 if ( empty($prev_value) ) { 512 512 $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE 513 513 meta_key = '$key' AND post_id = '$post_id'"); … … 530 530 function get_postdata($postid) { 531 531 $post = &get_post($postid); 532 532 533 533 $postdata = array ( 534 'ID' => $post->ID, 535 'Author_ID' => $post->post_author, 536 'Date' => $post->post_date, 537 'Content' => $post->post_content, 538 'Excerpt' => $post->post_excerpt, 539 'Title' => $post->post_title, 534 'ID' => $post->ID, 535 'Author_ID' => $post->post_author, 536 'Date' => $post->post_date, 537 'Content' => $post->post_content, 538 'Excerpt' => $post->post_excerpt, 539 'Title' => $post->post_title, 540 540 'Category' => $post->post_category, 541 541 'post_status' => $post->post_status, … … 551 551 } 552 552 553 // Retrieves post data given a post ID or post object. 553 // Retrieves post data given a post ID or post object. 554 554 // Handles post caching. 555 555 function &get_post(&$post, $output = OBJECT) { … … 561 561 else 562 562 $_post = null; 563 } elseif ( is_object($post) ) {564 if ( ! isset($post_cache[$post->ID]))563 } elseif ( is_object($post) ) { 564 if ( !isset($post_cache[$post->ID]) ) 565 565 $post_cache[$post->ID] = &$post; 566 566 $_post = & $post_cache[$post->ID]; 567 567 } else { 568 if ( isset($post_cache[$post]))568 if ( isset($post_cache[$post]) ) 569 569 $_post = & $post_cache[$post]; 570 570 else { … … 586 586 } 587 587 588 // Retrieves page data given a page ID or page object. 588 // Retrieves page data given a page ID or page object. 589 589 // Handles page caching. 590 590 function &get_page(&$page, $output = OBJECT) { … … 596 596 else 597 597 $_page = null; 598 } elseif ( is_object($page) ) {599 if ( ! isset($page_cache[$page->ID]))598 } elseif ( is_object($page) ) { 599 if ( !isset($page_cache[$page->ID]) ) 600 600 $page_cache[$page->ID] = &$page; 601 601 $_page = & $page_cache[$page->ID]; … … 603 603 if ( isset($GLOBALS['page']) && ($page == $GLOBALS['page']->ID) ) 604 604 $_page = & $GLOBALS['page']; 605 elseif ( isset($page_cache[$page]))605 elseif ( isset($page_cache[$page]) ) 606 606 $_page = & $page_cache[$page]; 607 607 else { … … 623 623 } 624 624 625 // Retrieves category data given a category ID or category object. 625 // Retrieves category data given a category ID or category object. 626 626 // Handles category caching. 627 627 function &get_category(&$category, $output = OBJECT) { … … 631 631 return null; 632 632 633 if ( ! isset($cache_categories))633 if ( !isset($cache_categories) ) 634 634 update_category_cache(); 635 635 636 if ( is_object($category)) {637 if ( ! isset($cache_categories[$category->cat_ID]))636 if ( is_object($category) ) { 637 if ( !isset($cache_categories[$category->cat_ID]) ) 638 638 $cache_categories[$category->cat_ID] = &$category; 639 639 $_category = & $cache_categories[$category->cat_ID]; … … 658 658 } 659 659 660 // Retrieves comment data given a comment ID or comment object. 660 // Retrieves comment data given a comment ID or comment object. 661 661 // Handles comment caching. 662 662 function &get_comment(&$comment, $output = OBJECT) { … … 666 666 return null; 667 667 668 if ( is_object($comment)) {669 if ( ! isset($comment_cache[$comment->comment_ID]))668 if ( is_object($comment) ) { 669 if ( !isset($comment_cache[$comment->comment_ID]) ) 670 670 $comment_cache[$comment->comment_ID] = &$comment; 671 671 $_comment = & $comment_cache[$comment->comment_ID]; … … 699 699 if ( !get_settings('gzipcompression') ) return false; 700 700 701 if ( extension_loaded('zlib') ) {701 if ( extension_loaded('zlib') ) { 702 702 ob_start('ob_gzhandler'); 703 703 } … … 715 715 $timeend = $mtime; 716 716 $timetotal = $timeend-$timestart; 717 if ( $display)717 if ( $display ) 718 718 echo number_format($timetotal,$precision); 719 719 return $timetotal; … … 740 740 $services = preg_replace("|(\s)+|", '$1', $services); // Kill dupe lines 741 741 $services = trim($services); 742 if ( '' != $services) {742 if ( '' != $services ) { 743 743 $services = explode("\n", $services); 744 744 foreach ($services as $service) { … … 754 754 global $wpdb, $wp_version; 755 755 756 if ( empty($trackback_url))756 if ( empty($trackback_url) ) 757 757 return; 758 758 … … 764 764 $query_string = "title=$title&url=$url&blog_name=$blog_name&excerpt=$excerpt"; 765 765 $trackback_url = parse_url($trackback_url); 766 $http_request 766 $http_request = 'POST ' . $trackback_url['path'] . ($trackback_url['query'] ? '?'.$trackback_url['query'] : '') . " HTTP/1.0\r\n"; 767 767 $http_request .= 'Host: '.$trackback_url['host']."\r\n"; 768 768 $http_request .= 'Content-Type: application/x-www-form-urlencoded; charset='.get_settings('blog_charset')."\r\n"; … … 815 815 function xmlrpc_getposttitle($content) { 816 816 global $post_default_title; 817 if ( preg_match('/<title>(.+?)<\/title>/is', $content, $matchtitle)) {817 if ( preg_match('/<title>(.+?)<\/title>/is', $content, $matchtitle) ) { 818 818 $post_title = $matchtitle[0]; 819 819 $post_title = preg_replace('/<title>/si', '', $post_title); … … 824 824 return $post_title; 825 825 } 826 826 827 827 function xmlrpc_getpostcategory($content) { 828 828 global $post_default_category; 829 if ( preg_match('/<category>(.+?)<\/category>/is', $content, $matchcat)) {829 if ( preg_match('/<category>(.+?)<\/category>/is', $content, $matchcat) ) { 830 830 $post_category = trim($matchcat[1], ','); 831 831 $post_category = explode(',', $post_category); … … 845 845 function debug_fopen($filename, $mode) { 846 846 global $debug; 847 if ( $debug == 1) {847 if ( $debug == 1 ) { 848 848 $fp = fopen($filename, $mode); 849 849 return $fp; … … 855 855 function debug_fwrite($fp, $string) { 856 856 global $debug; 857 if ( $debug == 1) {857 if ( $debug == 1 ) { 858 858 fwrite($fp, $string); 859 859 } … … 862 862 function debug_fclose($fp) { 863 863 global $debug; 864 if ( $debug == 1) {864 if ( $debug == 1 ) { 865 865 fclose($fp); 866 866 } … … 870 870 global $wpdb; 871 871 $doping = false; 872 if ($wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE TRIM(to_ping) != '' LIMIT 1")) {872 if ( $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE TRIM(to_ping) != '' LIMIT 1") ) 873 873 $doping = true; 874 } 875 if ($wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pingme' OR meta_key = '_encloseme' LIMIT 1")) {874 875 if ( $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pingme' OR meta_key = '_encloseme' LIMIT 1") ) 876 876 $doping = true; 877 } 878 if ($doping)879 echo '<iframe id="pingcheck" src="' . 877 878 if ( $doping ) 879 echo '<iframe id="pingcheck" src="' . get_settings('siteurl') .'/wp-admin/execute-pings.php?time=' . time() . '" style="border:none;width:1px;height:1px;"></iframe>'; 880 880 } 881 881 … … 903 903 if ( !in_array($link_test, $pung) ) : // If we haven't pung it already 904 904 $test = parse_url($link_test); 905 if ( isset($test['query']))905 if ( isset($test['query']) ) 906 906 $post_links[] = $link_test; 907 elseif (($test['path'] != '/') && ($test['path'] != ''))907 elseif (($test['path'] != '/') && ($test['path'] != '')) 908 908 $post_links[] = $link_test; 909 909 endif; … … 913 913 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%')") ) { 914 914 if ( $headers = wp_get_http_headers( $url) ) { 915 $len 915 $len = (int) $headers['content-length']; 916 916 $type = $wpdb->escape( $headers['content-type'] ); 917 917 $allowed_types = array( 'video', 'audio' ); 918 if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {918 if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) { 919 919 $meta_value = "$url\n$len\n$type\n"; 920 920 $wpdb->query( "INSERT INTO `$wpdb->postmeta` ( `post_id` , `meta_key` , `meta_value` ) … … 927 927 928 928 function wp_get_http_headers( $url ) { 929 @set_time_limit( 60 ); 929 @set_time_limit( 60 ); 930 930 $parts = parse_url( $url ); 931 $file 932 $host 931 $file = $parts['path'] . ($parts['query'] ? '?'.$parts['query'] : ''); 932 $host = $parts['host']; 933 933 if ( !isset( $parts['port'] ) ) 934 934 $parts['port'] = 80; … … 969 969 // Setup global post data. 970 970 function setup_postdata($post) { 971 971 global $id, $postdata, $authordata, $day, $page, $pages, $multipage, $more, $numpages, $wp_query; 972 972 global $pagenow; 973 973 … … 980 980 $numpages = 1; 981 981 $page = get_query_var('page'); 982 if ( !$page)982 if ( !$page ) 983 983 $page = 1; 984 if ( is_single() || is_page())984 if ( is_single() || is_page() ) 985 985 $more = 1; 986 986 $content = $post->post_content; 987 if ( preg_match('/<!--nextpage-->/', $content)) {988 if ( $page > 1)987 if ( preg_match('/<!--nextpage-->/', $content) ) { 988 if ( $page > 1 ) 989 989 $more = 1; 990 990 $multipage = 1; … … 1003 1003 function is_new_day() { 1004 1004 global $day, $previousday; 1005 if ( $day != $previousday) {1005 if ( $day != $previousday ) { 1006 1006 return(1); 1007 1007 } else { … … 1014 1014 function merge_filters($tag) { 1015 1015 global $wp_filter; 1016 if ( isset($wp_filter['all'])) {1016 if ( isset($wp_filter['all']) ) { 1017 1017 foreach ($wp_filter['all'] as $priority => $functions) { 1018 if ( isset($wp_filter[$tag][$priority]))1018 if ( isset($wp_filter[$tag][$priority]) ) 1019 1019 $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], $wp_filter[$tag][$priority]); 1020 1020 else … … 1030 1030 function apply_filters($tag, $string) { 1031 1031 global $wp_filter; 1032 1032 1033 1033 $args = array_slice(func_get_args(), 2); 1034 1034 1035 1035 merge_filters($tag); 1036 1037 if ( !isset($wp_filter[$tag])) {1036 1037 if ( !isset($wp_filter[$tag]) ) { 1038 1038 return $string; 1039 1039 } 1040 1040 foreach ($wp_filter[$tag] as $priority => $functions) { 1041 if ( !is_null($functions)) {1041 if ( !is_null($functions) ) { 1042 1042 foreach($functions as $function) { 1043 1043 … … 1046 1046 $accepted_args = $function['accepted_args']; 1047 1047 1048 if ($accepted_args == 1) {1048 if ( $accepted_args == 1 ) 1049 1049 $the_args = array($string); 1050 } elseif ($accepted_args > 1) {1050 elseif ( $accepted_args > 1 ) 1051 1051 $the_args = array_slice($all_args, 0, $accepted_args); 1052 } elseif($accepted_args == 0) {1052 elseif ( $accepted_args == 0 ) 1053 1053 $the_args = NULL; 1054 } else {1054 else 1055 1055 $the_args = $all_args; 1056 }1057 1056 1058 1057 $string = call_user_func_array($function_name, $the_args); … … 1067 1066 1068 1067 // check that we don't already have the same filter at the same priority 1069 if ( isset($wp_filter[$tag]["$priority"])) {1068 if ( isset($wp_filter[$tag]["$priority"]) ) { 1070 1069 foreach($wp_filter[$tag]["$priority"] as $filter) { 1071 1070 // uncomment if we want to match function AND accepted_args 1072 // if ($filter == array($function, $accepted_args)) {1073 if ( $filter['function'] == $function_to_add) {1071 // if ( $filter == array($function, $accepted_args) ) { 1072 if ( $filter['function'] == $function_to_add ) { 1074 1073 return true; 1075 1074 } … … 1086 1085 1087 1086 // rebuild the list of filters 1088 if ( isset($wp_filter[$tag]["$priority"])) {1087 if ( isset($wp_filter[$tag]["$priority"]) ) { 1089 1088 foreach($wp_filter[$tag]["$priority"] as $filter) { 1090 if ( $filter['function'] != $function_to_remove) {1089 if ( $filter['function'] != $function_to_remove ) { 1091 1090 $new_function_list[] = $filter; 1092 1091 } … … 1106 1105 else 1107 1106 $args = array_merge(array($arg), $extra_args); 1108 1107 1109 1108 merge_filters($tag); 1110 1111 if ( !isset($wp_filter[$tag])) {1109 1110 if ( !isset($wp_filter[$tag]) ) { 1112 1111 return; 1113 1112 } 1114 1113 foreach ($wp_filter[$tag] as $priority => $functions) { 1115 if ( !is_null($functions)) {1114 if ( !is_null($functions) ) { 1116 1115 foreach($functions as $function) { 1117 1116 … … 1119 1118 $accepted_args = $function['accepted_args']; 1120 1119 1121 if ($accepted_args == 1) {1120 if ( $accepted_args == 1 ) { 1122 1121 if ( is_array($arg) ) 1123 1122 $the_args = $arg; 1124 1123 else 1125 1124 $the_args = array($arg); 1126 } elseif ( $accepted_args > 1) {1125 } elseif ( $accepted_args > 1 ) { 1127 1126 $the_args = array_slice($args, 0, $accepted_args); 1128 } elseif ($accepted_args == 0) {1127 } elseif ( $accepted_args == 0 ) { 1129 1128 $the_args = NULL; 1130 1129 } else { … … 1151 1150 1152 1151 // A page cannot be it's own parent. 1153 if ( $page->post_parent == $page->ID) {1152 if ( $page->post_parent == $page->ID ) 1154 1153 return $uri; 1155 } 1156 1154 1157 1155 while ($page->post_parent != 0) { 1158 1156 $page = get_page($page->post_parent); … … 1166 1164 global $wpdb; 1167 1165 parse_str($args, $r); 1168 if (!isset($r['numberposts'])) $r['numberposts'] = 5; 1169 if (!isset($r['offset'])) $r['offset'] = 0; 1170 if (!isset($r['category'])) $r['category'] = ''; 1171 if (!isset($r['orderby'])) $r['orderby'] = 'post_date'; 1172 if (!isset($r['order'])) $r['order'] = 'DESC'; 1166 if ( !isset($r['numberposts']) ) 1167 $r['numberposts'] = 5; 1168 if ( !isset($r['offset']) ) 1169 $r['offset'] = 0; 1170 if ( !isset($r['category']) ) 1171 $r['category'] = ''; 1172 if ( !isset($r['orderby']) ) 1173 $r['orderby'] = 'post_date'; 1174 if ( !isset($r['order']) ) 1175 $r['order'] = 'DESC'; 1173 1176 1174 1177 $now = current_time('mysql'); … … 1179 1182 " WHERE post_date <= '$now' AND (post_status = 'publish') ". 1180 1183 ( empty( $r['category'] ) ? "" : "AND $wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $r['category']. " " ) . 1181 " GROUP BY $wpdb->posts.ID ORDER BY " . $r['orderby'] . " " . $r['order'] . " 1182 1183 1184 1184 " GROUP BY $wpdb->posts.ID ORDER BY " . $r['orderby'] . " " . $r['order'] . " LIMIT " . $r['offset'] . ',' . $r['numberposts'] ); 1185 1186 update_post_caches($posts); 1187 1185 1188 return $posts; 1186 1189 } … … 1204 1207 function clean_post_cache($id) { 1205 1208 global $post_cache; 1206 1209 1207 1210 if ( isset( $post_cache[$id] ) ) 1208 1211 unset( $post_cache[$id] ); … … 1223 1226 function clean_page_cache($id) { 1224 1227 global $page_cache; 1225 1228 1226 1229 if ( isset( $page_cache[$id] ) ) 1227 1230 unset( $page_cache[$id] ); … … 1231 1234 global $wpdb, $category_cache, $cache_categories; 1232 1235 1233 if ( empty($post_ids))1236 if ( empty($post_ids) ) 1234 1237 return; 1235 1238 1236 if ( is_array($post_ids))1239 if ( is_array($post_ids) ) 1237 1240 $post_ids = implode(',', $post_ids); 1238 1241 … … 1241 1244 WHERE category_id = cat_ID AND post_id IN ($post_ids)"); 1242 1245 1243 if ( ! isset($cache_categories))1246 if ( !isset($cache_categories) ) 1244 1247 update_category_cache(); 1245 1248 1246 1249 if ( !empty($dogs) ) { 1247 1250 foreach ($dogs as $catt) { … … 1254 1257 global $post_cache, $category_cache, $comment_count_cache, $post_meta_cache; 1255 1258 global $wpdb; 1256 1259 1257 1260 // No point in doing all this work if we didn't match any posts. 1258 1261 if ( !$posts ) … … 1266 1269 1267 1270 $post_id_list = implode(',', $post_id_list); 1268 1271 1269 1272 update_post_category_cache($post_id_list); 1270 1273 … … 1272 1275 $comment_counts = $wpdb->get_results("SELECT ID, COUNT( comment_ID ) AS ccount 1273 1276 FROM $wpdb->posts 1274 LEFT JOIN $wpdb->comments ON ( comment_post_ID = ID AND comment_approved ='1')1277 LEFT JOIN $wpdb->comments ON ( comment_post_ID = ID AND comment_approved = '1') 1275 1278 WHERE ID IN ($post_id_list) 1276 1279 GROUP BY ID"); 1277 1278 if ( $comment_counts) {1280 1281 if ( $comment_counts ) { 1279 1282 foreach ($comment_counts as $comment_count) 1280 1283 $comment_count_cache["$comment_count->ID"] = $comment_count->ccount; 1281 1284 } 1282 1285 1283 1284 if ( $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta 1286 // Get post-meta info 1287 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) ) { 1285 1288 // Change from flat structure to hierarchical: 1286 1289 $post_meta_cache = array(); … … 1291 1294 1292 1295 // Force subkeys to be array type: 1293 if ( !isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]))1296 if ( !isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]) ) 1294 1297 $post_meta_cache[$mpid] = array(); 1295 if ( !isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]))1298 if ( !isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]) ) 1296 1299 $post_meta_cache[$mpid]["$mkey"] = array(); 1297 1300 … … 1304 1307 function update_category_cache() { 1305 1308 global $cache_categories, $wpdb; 1306 if ($dogs = $wpdb->get_results("SELECT * FROM $wpdb->categories")):1309 if ( $dogs = $wpdb->get_results("SELECT * FROM $wpdb->categories") ): 1307 1310 foreach ($dogs as $catt) 1308 1311 $cache_categories[$catt->cat_ID] = $catt; 1309 1312 return true; 1310 else : 1313 else : 1311 1314 return false; 1312 1315 endif; … … 1339 1342 $post_obj = $wp_query->get_queried_object(); 1340 1343 1341 if ( $post == $post_obj->ID ) 1344 if ( $post == $post_obj->ID ) 1342 1345 return true; 1343 elseif ( $post == $post_obj->post_title ) 1346 elseif ( $post == $post_obj->post_title ) 1344 1347 return true; 1345 1348 elseif ( $post == $post_obj->post_name ) … … 1352 1355 global $wp_query; 1353 1356 1354 if ( ! $wp_query->is_page) {1357 if ( !$wp_query->is_page ) 1355 1358 return false; 1356 } 1357 1358 if (empty($page)) { 1359 1360 if ( empty($page) ) 1359 1361 return true; 1360 }1361 1362 1362 1363 $page_obj = $wp_query->get_queried_object(); 1363 1364 if ( $page == $page_obj->ID) {1364 1365 if ( $page == $page_obj->ID ) 1365 1366 return true; 1366 } else if ($page == $page_obj->post_title) {1367 elseif ( $page == $page_obj->post_title ) 1367 1368 return true; 1368 } else if ($page == $page_obj->post_name) {1369 else if ( $page == $page_obj->post_name ) 1369 1370 return true; 1370 }1371 1371 1372 1372 return false; … … 1374 1374 1375 1375 function is_archive () { 1376 1377 1378 1376 global $wp_query; 1377 1378 return $wp_query->is_archive; 1379 1379 } 1380 1380 1381 1381 function is_date () { 1382 1383 1384 1382 global $wp_query; 1383 1384 return $wp_query->is_date; 1385 1385 } 1386 1386 1387 1387 function is_year () { 1388 1389 1390 1388 global $wp_query; 1389 1390 return $wp_query->is_year; 1391 1391 } 1392 1392 1393 1393 function is_month () { 1394 1395 1396 1394 global $wp_query; 1395 1396 return $wp_query->is_month; 1397 1397 } 1398 1398 1399 1399 function is_day () { 1400 1401 1402 1400 global $wp_query; 1401 1402 return $wp_query->is_day; 1403 1403 } 1404 1404 1405 1405 function is_time () { 1406 1407 1408 1406 global $wp_query; 1407 1408 return $wp_query->is_time; 1409 1409 } 1410 1410 … … 1412 1412 global $wp_query; 1413 1413 1414 if ( ! $wp_query->is_author) {1414 if ( !$wp_query->is_author ) 1415 1415 return false; 1416 } 1417 1418 if (empty($author)) { 1416 1417 if ( empty($author) ) 1419 1418 return true; 1420 }1421 1419 1422 1420 $author_obj = $wp_query->get_queried_object(); 1423 1424 if ( $author == $author_obj->ID) {1421 1422 if ( $author == $author_obj->ID ) 1425 1423 return true; 1426 } else if ($author == $author_obj->nickname) {1424 elseif ( $author == $author_obj->nickname ) 1427 1425 return true; 1428 } else if ($author == $author_obj->user_nicename) {1426 elseif ( $author == $author_obj->user_nicename ) 1429 1427 return true; 1430 }1431 1428 1432 1429 return false; … … 1436 1433 global $wp_query; 1437 1434 1438 if ( ! $wp_query->is_category) {1435 if ( !$wp_query->is_category ) 1439 1436 return false; 1440 } 1441 1442 if (empty($category)) { 1437 1438 if ( empty($category) ) 1443 1439 return true; 1444 }1445 1440 1446 1441 $cat_obj = $wp_query->get_queried_object(); 1447 1448 if ( $category == $cat_obj->cat_ID) {1442 1443 if ( $category == $cat_obj->cat_ID ) 1449 1444 return true; 1450 } else if ($category == $cat_obj->cat_name) {1445 else if ( $category == $cat_obj->cat_name ) 1451 1446 return true; 1452 } else if ($category == $cat_obj->category_nicename) {1447 elseif ( $category == $cat_obj->category_nicename ) 1453 1448 return true; 1454 }1455 1449 1456 1450 return false; … … 1458 1452 1459 1453 function is_search () { 1460 1461 1462 1454 global $wp_query; 1455 1456 return $wp_query->is_search; 1463 1457 } 1464 1458 1465 1459 function is_feed () { 1466 1467 1468 1460 global $wp_query; 1461 1462 return $wp_query->is_feed; 1469 1463 } 1470 1464 1471 1465 function is_trackback () { 1472 1473 1474 1466 global $wp_query; 1467 1468 return $wp_query->is_trackback; 1475 1469 } 1476 1470 1477 1471 function is_admin () { 1478 1479 1480 1472 global $wp_query; 1473 1474 return $wp_query->is_admin; 1481 1475 } 1482 1476 1483 1477 function is_home () { 1484 1485 1486 1478 global $wp_query; 1479 1480 return $wp_query->is_home; 1487 1481 } 1488 1482 1489 1483 function is_404 () { 1490 1491 1492 1484 global $wp_query; 1485 1486 return $wp_query->is_404; 1493 1487 } 1494 1488 1495 1489 function is_comments_popup () { 1496 1497 1498 1490 global $wp_query; 1491 1492 return $wp_query->is_comments_popup; 1499 1493 } 1500 1494 1501 1495 function is_paged () { 1502 1503 1504 1496 global $wp_query; 1497 1498 return $wp_query->is_paged; 1505 1499 } 1506 1500 1507 1501 function in_the_loop() { 1508 1502 global $wp_query; 1509 1503 1510 1504 return $wp_query->in_the_loop; 1511 1505 } 1512 1506 1513 1507 function get_query_var($var) { 1514 1515 1516 1508 global $wp_query; 1509 1510 return $wp_query->get($var); 1517 1511 } 1518 1512 1519 1513 function have_posts() { 1520 1521 1522 1514 global $wp_query; 1515 1516 return $wp_query->have_posts(); 1523 1517 } 1524 1518 1525 1519 function rewind_posts() { 1526 1527 1528 1520 global $wp_query; 1521 1522 return $wp_query->rewind_posts(); 1529 1523 } 1530 1524 1531 1525 function the_post() { 1532 global $wp_query; 1533 $wp_query->the_post(); 1526 global $wp_query; 1527 1528 $wp_query->the_post(); 1534 1529 } 1535 1530 … … 1603 1598 $theme = $name; 1604 1599 1605 if ( '' == $author_uri[1]) {1600 if ( '' == $author_uri[1] ) { 1606 1601 $author = $author_name[1]; 1607 1602 } else { … … 1616 1611 global $wp_broken_themes; 1617 1612 1618 if ( isset($wp_themes)) {1613 if ( isset($wp_themes) ) 1619 1614 return $wp_themes; 1620 }1621 1615 1622 1616 $themes = array(); … … 1627 1621 // Files in wp-content/themes directory 1628 1622 $themes_dir = @ dir($theme_root); 1629 if ( $themes_dir) {1623 if ( $themes_dir ) { 1630 1624 while(($theme_dir = $themes_dir->read()) !== false) { 1631 1625 if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) { 1632 if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS') {1626 if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' ) { 1633 1627 continue; 1634 1628 } 1635 1629 $stylish_dir = @ dir($theme_root . '/' . $theme_dir); 1636 1630 $found_stylesheet = false; 1637 while (($theme_file = $stylish_dir->read()) !== false) {1631 while (($theme_file = $stylish_dir->read()) !== false) { 1638 1632 if ( $theme_file == 'style.css' ) { 1639 1633 $theme_files[] = $theme_dir . '/' . $theme_file; … … 1642 1636 } 1643 1637 } 1644 if ( !$found_stylesheet) {1638 if ( !$found_stylesheet ) { 1645 1639 $wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.')); 1646 1640 } … … 1649 1643 } 1650 1644 1651 if ( !$themes_dir || !$theme_files) {1645 if ( !$themes_dir || !$theme_files ) { 1652 1646 return $themes; 1653 1647 } … … 1658 1652 $theme_data = get_theme_data("$theme_root/$theme_file"); 1659 1653 1660 $name = $theme_data['Name']; 1654 $name = $theme_data['Name']; 1661 1655 $title = $theme_data['Title']; 1662 1656 $description = wptexturize($theme_data['Description']); … … 1672 1666 $screenshot = false; 1673 1667 1674 if ( empty($name)) {1668 if ( empty($name) ) { 1675 1669 $name = dirname($theme_file); 1676 1670 $title = $name; 1677 1671 } 1678 1672 1679 if ( empty($template)) {1680 if ( file_exists(dirname("$theme_root/$theme_file/index.php"))) {1673 if ( empty($template) ) { 1674 if ( file_exists(dirname("$theme_root/$theme_file/index.php")) ) { 1681 1675 $template = dirname($theme_file); 1682 1676 } else { … … 1687 1681 $template = trim($template); 1688 1682 1689 if ( ! file_exists("$theme_root/$template/index.php")) {1683 if ( !file_exists("$theme_root/$template/index.php") ) { 1690 1684 $wp_broken_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => __('Template is missing.')); 1691 1685 continue; 1692 1686 } 1693 1687 1694 1688 $stylesheet_files = array(); 1695 1689 $stylesheet_dir = @ dir("$theme_root/$stylesheet"); 1696 if ( $stylesheet_dir) {1690 if ( $stylesheet_dir ) { 1697 1691 while(($file = $stylesheet_dir->read()) !== false) { 1698 if ( !preg_match('|^\.+$|', $file) && preg_match('|\.css$|', $file) ) 1692 if ( !preg_match('|^\.+$|', $file) && preg_match('|\.css$|', $file) ) 1699 1693 $stylesheet_files[] = "$theme_loc/$stylesheet/$file"; 1700 1694 } 1701 1695 } 1702 1696 1703 $template_files = array(); 1697 $template_files = array(); 1704 1698 $template_dir = @ dir("$theme_root/$template"); 1705 if ( $template_dir) {1699 if ( $template_dir ) { 1706 1700 while(($file = $template_dir->read()) !== false) { 1707 if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) ) 1701 if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) ) 1708 1702 $template_files[] = "$theme_loc/$template/$file"; 1709 1703 } … … 1713 1707 $stylesheet_dir = dirname($stylesheet_files[0]); 1714 1708 1715 if (empty($template_dir)) $template_dir = '/'; 1716 if (empty($stylesheet_dir)) $stylesheet_dir = '/'; 1709 if ( empty($template_dir) ) 1710 $template_dir = '/'; 1711 if ( empty($stylesheet_dir) ) 1712 $stylesheet_dir = '/'; 1717 1713 1718 1714 // Check for theme name collision. This occurs if a theme is copied to … … 1733 1729 } 1734 1730 } 1735 1731 1736 1732 $themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template, 'Stylesheet' => $stylesheet, 'Template Files' => $template_files, 'Stylesheet Files' => $stylesheet_files, 'Template Dir' => $template_dir, 'Stylesheet Dir' => $stylesheet_dir, 'Status' => $theme_data['Status'], 'Screenshot' => $screenshot); 1737 1733 } … … 1742 1738 foreach ($theme_names as $theme_name) { 1743 1739 $themes[$theme_name]['Parent Theme'] = ''; 1744 if ( $themes[$theme_name]['Stylesheet'] != $themes[$theme_name]['Template']) {1740 if ( $themes[$theme_name]['Stylesheet'] != $themes[$theme_name]['Template'] ) { 1745 1741 foreach ($theme_names as $parent_theme_name) { 1746 if ( ($themes[$parent_theme_name]['Stylesheet'] == $themes[$parent_theme_name]['Template']) && ($themes[$parent_theme_name]['Template'] == $themes[$theme_name]['Template'])) {1742 if ( ($themes[$parent_theme_name]['Stylesheet'] == $themes[$parent_theme_name]['Template']) && ($themes[$parent_theme_name]['Template'] == $themes[$theme_name]['Template']) ) { 1747 1743 $themes[$theme_name]['Parent Theme'] = $themes[$parent_theme_name]['Name']; 1748 1744 break; … … 1760 1756 $themes = get_themes(); 1761 1757 1762 if ( array_key_exists($theme, $themes)) {1758 if ( array_key_exists($theme, $themes) ) 1763 1759 return $themes[$theme]; 1764 }1765 1760 1766 1761 return NULL; … … 1774 1769 $current_theme = 'WordPress Default'; 1775 1770 1776 if ( $themes) {1771 if ( $themes ) { 1777 1772 foreach ($theme_names as $theme_name) { 1778 if ( $themes[$theme_name]['Stylesheet'] == $current_stylesheet &&1779 $themes[$theme_name]['Template'] == $current_template ) {1773 if ( $themes[$theme_name]['Stylesheet'] == $current_stylesheet && 1774 $themes[$theme_name]['Template'] == $current_template ) { 1780 1775 $current_theme = $themes[$theme_name]['Name']; 1781 1776 break; … … 1835 1830 global $wp_query; 1836 1831 1837 $id = $wp_query->post->ID; 1832 $id = $wp_query->post->ID; 1838 1833 $template = get_post_meta($id, '_wp_page_template', true); 1839 1834 … … 1843 1838 if ( ! empty($template) && file_exists(TEMPLATEPATH . "/$template") ) 1844 1839 $template = TEMPLATEPATH . "/$template"; 1845 else if ( file_exists(TEMPLATEPATH . 1846 $template = TEMPLATEPATH . 1840 else if ( file_exists(TEMPLATEPATH . "/page.php") ) 1841 $template = TEMPLATEPATH . "/page.php"; 1847 1842 else 1848 1843 $template = ''; … … 1884 1879 global $plugin_page; 1885 1880 1886 if ( isset($plugin_page)) {1881 if ( isset($plugin_page) ) 1887 1882 return true; 1888 }1889 1883 1890 1884 return false; … … 1903 1897 function add_query_arg() { 1904 1898 $ret = ''; 1905 if (is_array(func_get_arg(0))) {1899 if ( is_array(func_get_arg(0)) ) { 1906 1900 $uri = @func_get_arg(1); 1907 } 1908 else { 1909 if (@func_num_args() < 3) { 1901 } else { 1902 if ( @func_num_args() < 3 ) 1910 1903 $uri = $_SERVER['REQUEST_URI']; 1911 } else {1904 else 1912 1905 $uri = @func_get_arg(2); 1913 } 1914 } 1915 1916 if (strstr($uri, '?')) { 1906 } 1907 1908 if ( strstr($uri, '?') ) { 1917 1909 $parts = explode('?', $uri, 2); 1918 if ( 1 == count($parts)) {1910 if ( 1 == count($parts) ) { 1919 1911 $base = '?'; 1920 1912 $query = $parts[0]; 1921 } 1922 else { 1913 } else { 1923 1914 $base = $parts[0] . '?'; 1924 1915 $query = $parts[1]; 1925 1916 } 1926 1917 } 1927 else if ( strstr($uri, '/')) {1918 else if ( strstr($uri, '/') ) { 1928 1919 $base = $uri . '?'; 1929 1920 $query = ''; … … 1934 1925 1935 1926 parse_str($query, $qs); 1936 if ( is_array(func_get_arg(0))) {1927 if ( is_array(func_get_arg(0)) ) { 1937 1928 $kayvees = func_get_arg(0); 1938 1929 $qs = array_merge($qs, $kayvees); 1939 } 1940 else 1941 { 1942 $qs[func_get_arg(0)] = func_get_arg(1); 1943 } 1944 1945 foreach($qs as $k => $v) 1946 { 1947 if($v != '') 1948 { 1949 if($ret != '') $ret .= '&'; 1950 $ret .= "$k=$v"; 1951 } 1952 } 1953 $ret = $base . $ret; 1930 } else { 1931 $qs[func_get_arg(0)] = func_get_arg(1); 1932 } 1933 1934 foreach($qs as $k => $v) { 1935 if ( $v != '' ) { 1936 if ( $ret != '' ) 1937 $ret .= '&'; 1938 $ret .= "$k=$v"; 1939 } 1940 } 1941 $ret = $base . $ret; 1954 1942 return trim($ret, '?'); 1955 1943 } … … 1972 1960 1973 1961 foreach ($array as $k => $v) { 1974 if ( is_array($v)) {1962 if ( is_array($v) ) { 1975 1963 $array[$k] = add_magic_quotes($v); 1976 1964 } else { … … 1990 1978 $linea .= $remote_read; 1991 1979 fclose($fp); 1992 return $linea; 1980 return $linea; 1993 1981 } else if ( function_exists('curl_init') ) { 1994 1982 $handle = curl_init(); … … 2001 1989 } else { 2002 1990 return false; 2003 } 1991 } 2004 1992 } 2005 1993 2006 1994 function wp($query_vars = '') { 2007 1995 global $wp; 1996 2008 1997 $wp->main($query_vars); 2009 1998 } 2010 1999 2011 2000 function status_header( $header ) { 2012 if ( 200 == $header ) {2001 if ( 200 == $header ) 2013 2002 $text = 'OK'; 2014 } elseif ( 301 == $header ) {2003 elseif ( 301 == $header ) 2015 2004 $text = 'Moved Permanently'; 2016 } elseif ( 302 == $header ) {2005 elseif ( 302 == $header ) 2017 2006 $text = 'Moved Temporarily'; 2018 } elseif ( 304 == $header ) {2007 elseif ( 304 == $header ) 2019 2008 $text = 'Not Modified'; 2020 } elseif ( 404 == $header ) {2009 elseif ( 404 == $header ) 2021 2010 $text = 'Not Found'; 2022 } elseif ( 410 == $header ) {2011 elseif ( 410 == $header ) 2023 2012 $text = 'Gone'; 2024 } 2013 2025 2014 if ( preg_match('/cgi/',php_sapi_name()) ) { 2026 2015 @header("Status: $header $text"); … … 2057 2046 return ''; 2058 2047 } 2059 2048 2060 2049 foreach ($metas as $index => $meta) { 2061 2050 @ $value = unserialize($meta->meta_value); 2062 if ( $value === FALSE)2051 if ( $value === FALSE ) 2063 2052 $value = $meta->meta_value; 2064 2053 2065 2054 $values[] = $value; 2066 2055 } … … 2094 2083 function register_activation_hook($file, $function) { 2095 2084 $file = plugin_basename($file); 2096 2085 2097 2086 add_action('activate_' . $file, $function); 2098 2087 } … … 2100 2089 function register_deactivation_hook($file, $function) { 2101 2090 $file = plugin_basename($file); 2102 2091 2103 2092 add_action('deactivate_' . $file, $function); 2104 2093 }
Note: See TracChangeset
for help on using the changeset viewer.