3 require_once(dirname(__FILE__).'/functions-compat.php');
5 if ( !function_exists('_') ) {
11 function get_profile($field, $user = false) {
14 $user = $wpdb->escape($_COOKIE[USER_COOKIE]);
15 return $wpdb->get_var("SELECT $field FROM $wpdb->users WHERE user_login = '$user'");
18 function mysql2date($dateformatstring, $mysqlstring, $translate = true) {
19 global $month, $weekday, $month_abbrev, $weekday_abbrev;
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));
26 if ( -1 == $i || false == $i )
29 if ( !empty($month) && !empty($weekday) && $translate ) {
30 $datemonth = $month[date('m', $i)];
31 $datemonth_abbrev = $month_abbrev[$datemonth];
32 $dateweekday = $weekday[date('w', $i)];
33 $dateweekday_abbrev = $weekday_abbrev[$dateweekday];
34 $dateformatstring = ' '.$dateformatstring;
35 $dateformatstring = preg_replace("/([^\\\])D/", "\\1".backslashit($dateweekday_abbrev), $dateformatstring);
36 $dateformatstring = preg_replace("/([^\\\])F/", "\\1".backslashit($datemonth), $dateformatstring);
37 $dateformatstring = preg_replace("/([^\\\])l/", "\\1".backslashit($dateweekday), $dateformatstring);
38 $dateformatstring = preg_replace("/([^\\\])M/", "\\1".backslashit($datemonth_abbrev), $dateformatstring);
40 $dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring)-1);
42 $j = @date($dateformatstring, $i);
45 // echo $i." ".$mysqlstring;
50 function current_time($type, $gmt = 0) {
53 if ( $gmt ) $d = gmdate('Y-m-d H:i:s');
54 else $d = gmdate('Y-m-d H:i:s', (time() + (get_settings('gmt_offset') * 3600)));
58 if ( $gmt ) $d = time();
59 else $d = time() + (get_settings('gmt_offset') * 3600);
65 function date_i18n($dateformatstring, $unixtimestamp) {
66 global $month, $weekday, $month_abbrev, $weekday_abbrev;
68 if ( (!empty($month)) && (!empty($weekday)) ) {
69 $datemonth = $month[date('m', $i)];
70 $datemonth_abbrev = $month_abbrev[$datemonth];
71 $dateweekday = $weekday[date('w', $i)];
72 $dateweekday_abbrev = $weekday_abbrev[$dateweekday];
73 $dateformatstring = ' '.$dateformatstring;
74 $dateformatstring = preg_replace("/([^\\\])D/", "\\1".backslashit($dateweekday_abbrev), $dateformatstring);
75 $dateformatstring = preg_replace("/([^\\\])F/", "\\1".backslashit($datemonth), $dateformatstring);
76 $dateformatstring = preg_replace("/([^\\\])l/", "\\1".backslashit($dateweekday), $dateformatstring);
77 $dateformatstring = preg_replace("/([^\\\])M/", "\\1".backslashit($datemonth_abbrev), $dateformatstring);
78 $dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring)-1);
80 $j = @date($dateformatstring, $i);
84 function get_weekstartend($mysqlstring, $start_of_week) {
85 $my = substr($mysqlstring,0,4);
86 $mm = substr($mysqlstring,8,2);
87 $md = substr($mysqlstring,5,2);
88 $day = mktime(0,0,0, $md, $mm, $my);
89 $weekday = date('w',$day);
92 if ( $weekday < get_settings('start_of_week') )
93 $weekday = 7 - (get_settings('start_of_week') - $weekday);
95 while ($weekday > get_settings('start_of_week')) {
96 $weekday = date('w',$day);
97 if ( $weekday < get_settings('start_of_week') )
98 $weekday = 7 - (get_settings('start_of_week') - $weekday);
103 $week['start'] = $day + 86400 - $i;
104 // $week['end'] = $day - $i + 691199;
105 $week['end'] = $week['start'] + 604799;
109 function get_lastpostdate($timezone = 'server') {
110 global $cache_lastpostdate, $pagenow, $wpdb;
111 $add_seconds_blog = get_settings('gmt_offset') * 3600;
112 $add_seconds_server = date('Z');
113 $now = current_time('mysql', 1);
114 if ( !isset($cache_lastpostdate[$timezone]) ) {
115 switch(strtolower($timezone)) {
117 $lastpostdate = $wpdb->get_var("SELECT post_date_gmt FROM $wpdb->posts WHERE post_date_gmt <= '$now' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
120 $lastpostdate = $wpdb->get_var("SELECT post_date FROM $wpdb->posts WHERE post_date_gmt <= '$now' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
123 $lastpostdate = $wpdb->get_var("SELECT DATE_ADD(post_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_date_gmt <= '$now' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
126 $cache_lastpostdate[$timezone] = $lastpostdate;
128 $lastpostdate = $cache_lastpostdate[$timezone];
130 return $lastpostdate;
133 function get_lastpostmodified($timezone = 'server') {
134 global $cache_lastpostmodified, $pagenow, $wpdb;
135 $add_seconds_blog = get_settings('gmt_offset') * 3600;
136 $add_seconds_server = date('Z');
137 $now = current_time('mysql', 1);
138 if ( !isset($cache_lastpostmodified[$timezone]) ) {
139 switch(strtolower($timezone)) {
141 $lastpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_modified_gmt <= '$now' AND post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
144 $lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_modified_gmt <= '$now' AND post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
147 $lastpostmodified = $wpdb->get_var("SELECT DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_modified_gmt <= '$now' AND post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
150 $lastpostdate = get_lastpostdate($timezone);
151 if ( $lastpostdate > $lastpostmodified ) {
152 $lastpostmodified = $lastpostdate;
154 $cache_lastpostmodified[$timezone] = $lastpostmodified;
156 $lastpostmodified = $cache_lastpostmodified[$timezone];
158 return $lastpostmodified;
161 function user_pass_ok($user_login,$user_pass) {
162 global $cache_userdata;
163 if ( empty($cache_userdata[$user_login]) ) {
164 $userdata = get_userdatabylogin($user_login);
166 $userdata = $cache_userdata[$user_login];
168 return (md5($user_pass) == $userdata->user_pass);
172 function get_usernumposts($userid) {
174 return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '$userid' AND post_status = 'publish'");
178 // examine a url (supposedly from this blog) and try to
179 // determine the post ID it represents.
180 function url_to_postid($url) {
183 // First, check to see if there is a 'p=N' or 'page_id=N' to match against
184 preg_match('#[?&](p|page_id)=(\d+)#', $url, $values);
185 $id = intval($values[2]);
186 if ( $id ) return $id;
188 // Check to see if we are using rewrite rules
189 $rewrite = $wp_rewrite->wp_rewrite_rules();
191 // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options
192 if ( empty($rewrite) )
195 // $url cleanup by Mark Jaquith
196 // This fixes things like #anchors, ?query=strings, missing 'www.',
197 // added 'www.', or added 'index.php/' that will mess up our WP_Query
198 // and return a false negative
200 // Get rid of the #anchor
201 $url_split = explode('#', $url);
202 $url = $url_split[0];
204 // Get rid of URI ?query=string
205 $url_split = explode('?', $url);
206 $url = $url_split[0];
208 // Add 'www.' if it is absent and should be there
209 if ( false !== strpos(get_settings('home'), '://www.') && false === strpos($url, '://www.') )
210 $url = str_replace('://', '://www.', $url);
212 // Strip 'www.' if it is present and shouldn't be
213 if ( false === strpos(get_settings('home'), '://www.') )
214 $url = str_replace('://www.', '://', $url);
216 // Strip 'index.php/' if we're not using path info permalinks
217 if ( false === strpos($rewrite, 'index.php/') )
218 $url = str_replace('index.php/', '', $url);
220 if ( false !== strpos($url, get_settings('home')) ) {
221 // Chop off http://domain.com
222 $url = str_replace(get_settings('home'), '', $url);
224 // Chop off /path/to/blog
225 $home_path = parse_url(get_settings('home'));
226 $home_path = $home_path['path'];
227 $url = str_replace($home_path, '', $url);
230 // Trim leading and lagging slashes
231 $url = trim($url, '/');
238 $request_match = $request;
239 foreach ($rewrite as $match => $query) {
240 // If the requesting file is the anchor of the match, prepend it
242 if ( (! empty($url)) && (strpos($match, $url) === 0) ) {
243 $request_match = $url . '/' . $request;
246 if ( preg_match("!^$match!", $request_match, $matches) ) {
248 // Trim the query of everything up to the '?'.
249 $query = preg_replace("!^.+\?!", '', $query);
251 // Substitute the substring matches into the query.
252 eval("\$query = \"$query\";");
253 $query = new WP_Query($query);
254 if ( $query->is_single || $query->is_page )
255 return $query->post->ID;
264 function maybe_unserialize($original) {
265 if ( false !== $gm = @ unserialize($original) )
271 /* Options functions */
273 function get_settings($setting) {
276 $value = wp_cache_get($setting, 'options');
278 if ( false === $value ) {
279 if ( defined('WP_INSTALLING') )
280 $wpdb->hide_errors();
281 $row = $wpdb->get_row("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1");
282 if ( defined('WP_INSTALLING') )
283 $wpdb->show_errors();
285 if( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
286 $value = $row->option_value;
287 wp_cache_set($setting, $value, 'options');
293 // If home is not set use siteurl.
294 if ( 'home' == $setting && '' == $value )
295 return get_settings('siteurl');
297 if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting )
298 $value = preg_replace('|/+$|', '', $value);
300 return apply_filters( 'option_' . $setting, maybe_unserialize($value) );
303 function get_option($option) {
304 return get_settings($option);
307 function get_user_option( $option, $user = 0 ) {
311 $user = wp_get_current_user();
313 $user = get_userdata($user);
315 if ( isset( $user->{$wpdb->prefix . $option} ) ) // Blog specific
316 return $user->{$wpdb->prefix . $option};
317 elseif ( isset( $user->{$option} ) ) // User specific and cross-blog
318 return $user->{$option};
320 return get_option( $option );
323 function form_option($option) {
324 echo htmlspecialchars( get_option($option), ENT_QUOTES );
327 function get_alloptions() {
328 global $wpdb, $wp_queries;
329 $wpdb->hide_errors();
330 if ( !$options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'") ) {
331 $options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options");
333 $wpdb->show_errors();
335 foreach ($options as $option) {
336 // "When trying to design a foolproof system,
337 // never underestimate the ingenuity of the fools :)" -- Dougal
338 if ( 'siteurl' == $option->option_name )
339 $option->option_value = preg_replace('|/+$|', '', $option->option_value);
340 if ( 'home' == $option->option_name )
341 $option->option_value = preg_replace('|/+$|', '', $option->option_value);
342 if ( 'category_base' == $option->option_name )
343 $option->option_value = preg_replace('|/+$|', '', $option->option_value);
344 $value = maybe_unserialize($option->option_value);
345 $all_options->{$option->option_name} = apply_filters('pre_option_' . $option->option_name, $value);
347 return apply_filters('all_options', $all_options);
350 function update_option($option_name, $newvalue) {
353 if ( is_string($newvalue) )
354 $newvalue = trim($newvalue);
356 // If the new and old values are the same, no need to update.
357 $oldvalue = get_option($option_name);
358 if ( $newvalue == $oldvalue ) {
362 if ( false === $oldvalue ) {
363 add_option($option_name, $newvalue);
367 $_newvalue = $newvalue;
368 if ( is_array($newvalue) || is_object($newvalue) )
369 $newvalue = serialize($newvalue);
371 wp_cache_set($option_name, $newvalue, 'options');
373 $newvalue = $wpdb->escape($newvalue);
374 $option_name = $wpdb->escape($option_name);
375 $wpdb->query("UPDATE $wpdb->options SET option_value = '$newvalue' WHERE option_name = '$option_name'");
376 if ( $wpdb->rows_affected == 1 ) {
377 do_action("update_option_{$option_name}", array('old'=>$oldvalue, 'new'=>$_newvalue));
383 function update_user_option( $user_id, $option_name, $newvalue, $global = false ) {
386 $option_name = $wpdb->prefix . $option_name;
387 return update_usermeta( $user_id, $option_name, $newvalue );
390 // thx Alex Stapleton, http://alex.vort-x.net/blog/
391 function add_option($name, $value = '', $description = '', $autoload = 'yes') {
394 // Make sure the option doesn't already exist
395 if ( false !== get_option($name) )
398 if ( is_array($value) || is_object($value) )
399 $value = serialize($value);
401 wp_cache_set($name, $value, 'options');
403 $name = $wpdb->escape($name);
404 $value = $wpdb->escape($value);
405 $description = $wpdb->escape($description);
406 $wpdb->query("INSERT INTO $wpdb->options (option_name, option_value, option_description, autoload) VALUES ('$name', '$value', '$description', '$autoload')");
411 function delete_option($name) {
413 // Get the ID, if no ID then return
414 $option_id = $wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = '$name'");
415 if ( !$option_id ) return false;
416 $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = '$name'");
417 wp_cache_delete($name, 'options');
421 function add_post_meta($post_id, $key, $value, $unique = false) {
422 global $wpdb, $post_meta_cache;
425 if ( $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key
426 = '$key' AND post_id = '$post_id'") ) {
432 if ( is_array($value) || is_object($value) )
433 $value = $wpdb->escape(serialize($value));
435 $wpdb->query("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value) VALUES ('$post_id','$key','$value')");
437 $post_meta_cache['$post_id'][$key][] = $original;
442 function delete_post_meta($post_id, $key, $value = '') {
443 global $wpdb, $post_meta_cache;
445 if ( empty($value) ) {
446 $meta_id = $wpdb->get_var("SELECT meta_id FROM $wpdb->postmeta WHERE
447 post_id = '$post_id' AND meta_key = '$key'");
449 $meta_id = $wpdb->get_var("SELECT meta_id FROM $wpdb->postmeta WHERE
450 post_id = '$post_id' AND meta_key = '$key' AND meta_value = '$value'");
456 if ( empty($value) ) {
457 $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id'
458 AND meta_key = '$key'");
459 unset($post_meta_cache['$post_id'][$key]);
461 $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id'
462 AND meta_key = '$key' AND meta_value = '$value'");
463 $cache_key = $post_meta_cache['$post_id'][$key];
464 if ($cache_key) foreach ( $cache_key as $index => $data )
465 if ( $data == $value )
466 unset($post_meta_cache['$post_id'][$key][$index]);
469 unset($post_meta_cache['$post_id'][$key]);
474 function get_post_meta($post_id, $key, $single = false) {
475 global $wpdb, $post_meta_cache;
477 if ( isset($post_meta_cache[$post_id][$key]) ) {
479 return maybe_unserialize( $post_meta_cache[$post_id][$key][0] );
481 return maybe_unserialize( $post_meta_cache[$post_id][$key] );
485 $metalist = $wpdb->get_results("SELECT meta_value FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key'", ARRAY_N);
489 foreach ($metalist as $metarow) {
490 $values[] = $metarow[0];
495 if ( count($values) ) {
496 $return = maybe_unserialize( $values[0] );
504 return maybe_unserialize($return);
507 function update_post_meta($post_id, $key, $value, $prev_value = '') {
508 global $wpdb, $post_meta_cache;
510 $original_value = $value;
511 if ( is_array($value) || is_object($value) )
512 $value = $wpdb->escape(serialize($value));
514 $original_prev = $prev_value;
515 if ( is_array($prev_value) || is_object($prev_value) )
516 $prev_value = $wpdb->escape(serialize($prev_value));
518 if (! $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key
519 = '$key' AND post_id = '$post_id'") ) {
523 if ( empty($prev_value) ) {
524 $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE
525 meta_key = '$key' AND post_id = '$post_id'");
526 $cache_key = $post_meta_cache['$post_id'][$key];
527 if ( !empty($cache_key) )
528 foreach ($cache_key as $index => $data)
529 $post_meta_cache['$post_id'][$key][$index] = $original_value;
531 $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE
532 meta_key = '$key' AND post_id = '$post_id' AND meta_value = '$prev_value'");
533 $cache_key = $post_meta_cache['$post_id'][$key];
534 if ( !empty($cache_key) )
535 foreach ($cache_key as $index => $data)
536 if ( $data == $original_prev )
537 $post_meta_cache['$post_id'][$key][$index] = $original_value;
543 // Deprecated. Use get_post().
544 function get_postdata($postid) {
545 $post = &get_post($postid);
549 'Author_ID' => $post->post_author,
550 'Date' => $post->post_date,
551 'Content' => $post->post_content,
552 'Excerpt' => $post->post_excerpt,
553 'Title' => $post->post_title,
554 'Category' => $post->post_category,
555 'post_status' => $post->post_status,
556 'comment_status' => $post->comment_status,
557 'ping_status' => $post->ping_status,
558 'post_password' => $post->post_password,
559 'to_ping' => $post->to_ping,
560 'pinged' => $post->pinged,
561 'post_name' => $post->post_name
567 // Retrieves post data given a post ID or post object.
568 // Handles post caching.
569 function &get_post(&$post, $output = OBJECT) {
570 global $post_cache, $wpdb;
572 if ( empty($post) ) {
573 if ( isset($GLOBALS['post']) )
574 $_post = & $GLOBALS['post'];
577 } elseif ( is_object($post) ) {
578 if ( 'static' == $post->post_status )
579 return get_page($post, $output);
580 if ( !isset($post_cache[$post->ID]) )
581 $post_cache[$post->ID] = &$post;
582 $_post = & $post_cache[$post->ID];
584 if ( $_post = wp_cache_get($post, 'pages') )
585 return get_page($_post, $output);
586 elseif ( isset($post_cache[$post]) )
587 $_post = & $post_cache[$post];
589 $query = "SELECT * FROM $wpdb->posts WHERE ID = '$post' LIMIT 1";
590 $_post = & $wpdb->get_row($query);
591 if ( 'static' == $_post->post_status )
592 return get_page($_post, $output);
593 $post_cache[$post] = & $_post;
597 if ( defined(WP_IMPORTING) )
600 if ( $output == OBJECT ) {
602 } elseif ( $output == ARRAY_A ) {
603 return get_object_vars($_post);
604 } elseif ( $output == ARRAY_N ) {
605 return array_values(get_object_vars($_post));
611 function &get_children($post = 0, $output = OBJECT) {
612 global $post_cache, $wpdb;
614 if ( empty($post) ) {
615 if ( isset($GLOBALS['post']) )
616 $post_parent = & $GLOBALS['post']->post_parent;
619 } elseif ( is_object($post) ) {
620 $post_parent = $post->post_parent;
622 $post_parent = $post;
625 $post_parent = (int) $post_parent;
627 $query = "SELECT * FROM $wpdb->posts WHERE post_parent = $post_parent";
629 $children = $wpdb->get_results($query);
632 foreach ( $children as $key => $child ) {
633 $post_cache[$child->ID] =& $children[$key];
634 $kids[$child->ID] =& $children[$key];
640 if ( $output == OBJECT ) {
642 } elseif ( $output == ARRAY_A ) {
643 foreach ( $kids as $kid )
644 $weeuns[$kid->ID] = get_object_vars($kids[$kid->ID]);
646 } elseif ( $output == ARRAY_N ) {
647 foreach ( $kids as $kid )
648 $babes[$kid->ID] = array_values(get_object_vars($kids[$kid->ID]));
655 function set_page_path($page) {
656 $page->fullpath = '/' . $page->post_name;
657 $path = $page->fullpath;
659 while ($curpage->post_parent != 0) {
660 $curpage = get_page($curpage->post_parent);
661 $path = '/' . $curpage->post_name . $path;
664 $page->fullpath = $path;
669 // Retrieves page data given a page ID or page object.
670 // Handles page caching.
671 function &get_page(&$page, $output = OBJECT) {
674 if ( empty($page) ) {
675 if ( isset($GLOBALS['page']) ) {
676 $_page = & $GLOBALS['page'];
677 wp_cache_add($_page->ID, $_page, 'pages');
681 } elseif ( is_object($page) ) {
682 if ( 'static' != $page->post_status )
683 return get_post($page, $output);
684 wp_cache_add($page->ID, $page, 'pages');
687 if ( isset($GLOBALS['page']) && ($page == $GLOBALS['page']->ID) ) {
688 $_page = & $GLOBALS['page'];
689 wp_cache_add($_page->ID, $_page, 'pages');
690 } elseif ( $_page = $GLOBALS['post_cache'][$page] ) {
691 return get_post($page, $output);
692 } elseif ( $_page = wp_cache_get($page, 'pages') ) {
695 $query = "SELECT * FROM $wpdb->posts WHERE ID= '$page' LIMIT 1";
696 $_page = & $wpdb->get_row($query);
697 if ( 'static' != $_page->post_status )
698 return get_post($_page, $output);
699 wp_cache_add($_page->ID, $_page, 'pages');
703 if (!isset($_page->fullpath)) {
704 $_page = set_page_path($_page);
705 wp_cache_replace($_page->cat_ID, $_page, 'pages');
708 if ( $output == OBJECT ) {
710 } elseif ( $output == ARRAY_A ) {
711 return get_object_vars($_page);
712 } elseif ( $output == ARRAY_N ) {
713 return array_values(get_object_vars($_page));
719 function set_category_path($cat) {
720 $cat->fullpath = '/' . $cat->category_nicename;
721 $path = $cat->fullpath;
723 while ($curcat->category_parent != 0) {
724 $curcat = get_category($curcat->category_parent);
725 $path = '/' . $curcat->category_nicename . $path;
728 $cat->fullpath = $path;
733 // Retrieves category data given a category ID or category object.
734 // Handles category caching.
735 function &get_category(&$category, $output = OBJECT) {
738 if ( empty($category) )
741 if ( is_object($category) ) {
742 wp_cache_add($category->cat_ID, $category, 'category');
743 $_category = $category;
745 if ( ! $_category = wp_cache_get($category, 'category') ) {
746 $_category = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID = '$category' LIMIT 1");
747 wp_cache_add($category, $_category, 'category');
751 $_category = apply_filters('get_category', $_category);
753 if ( !isset($_category->fullpath) ) {
754 $_category = set_category_path($_category);
755 wp_cache_replace($_category->cat_ID, $_category, 'category');
758 if ( $output == OBJECT ) {
760 } elseif ( $output == ARRAY_A ) {
761 return get_object_vars($_category);
762 } elseif ( $output == ARRAY_N ) {
763 return array_values(get_object_vars($_category));
769 // Retrieves comment data given a comment ID or comment object.
770 // Handles comment caching.
771 function &get_comment(&$comment, $output = OBJECT) {
772 global $comment_cache, $wpdb;
774 if ( empty($comment) )
777 if ( is_object($comment) ) {
778 if ( !isset($comment_cache[$comment->comment_ID]) )
779 $comment_cache[$comment->comment_ID] = &$comment;
780 $_comment = & $comment_cache[$comment->comment_ID];
782 if ( !isset($comment_cache[$comment]) ) {
783 $_comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment' LIMIT 1");
784 $comment_cache[$comment->comment_ID] = & $_comment;
786 $_comment = & $comment_cache[$comment];
790 if ( $output == OBJECT ) {
792 } elseif ( $output == ARRAY_A ) {
793 return get_object_vars($_comment);
794 } elseif ( $output == ARRAY_N ) {
795 return array_values(get_object_vars($_comment));
801 function get_catname($cat_ID) {
802 $category = &get_category($cat_ID);
803 return $category->cat_name;
806 function get_all_category_ids() {
809 if ( ! $cat_ids = wp_cache_get('all_category_ids', 'category') ) {
810 $cat_ids = $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories");
811 wp_cache_add('all_category_ids', $cat_ids, 'category');
817 function get_all_page_ids() {
820 if ( ! $page_ids = wp_cache_get('all_page_ids', 'pages') ) {
821 $page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_status='static'");
822 wp_cache_add('all_page_ids', $page_ids, 'pages');
828 function gzip_compression() {
829 if ( !get_settings('gzipcompression') ) return false;
831 if ( extension_loaded('zlib') ) {
832 ob_start('ob_gzhandler');
837 // functions to count the page generation time (from phpBB2)
838 // ( or just any time between timer_start() and timer_stop() )
840 function timer_stop($display = 0, $precision = 3) { //if called like timer_stop(1), will echo $timetotal
841 global $timestart, $timeend;
842 $mtime = microtime();
843 $mtime = explode(' ',$mtime);
844 $mtime = $mtime[1] + $mtime[0];
846 $timetotal = $timeend-$timestart;
848 echo number_format($timetotal,$precision);
852 function weblog_ping($server = '', $path = '') {
854 include_once (ABSPATH . WPINC . '/class-IXR.php');
856 // using a timeout of 3 seconds should be enough to cover slow servers
857 $client = new IXR_Client($server, ((!strlen(trim($path)) || ('/' == $path)) ? false : $path));
858 $client->timeout = 3;
859 $client->useragent .= ' -- WordPress/'.$wp_version;
861 // when set to true, this outputs debug messages by itself
862 $client->debug = false;
863 $home = trailingslashit( get_option('home') );
864 if ( !$client->query('weblogUpdates.extendedPing', get_settings('blogname'), $home, get_bloginfo('rss2_url') ) ) // then try a normal ping
865 $client->query('weblogUpdates.ping', get_settings('blogname'), $home);
868 function generic_ping($post_id = 0) {
869 $services = get_settings('ping_sites');
870 $services = preg_replace("|(\s)+|", '$1', $services); // Kill dupe lines
871 $services = trim($services);
872 if ( '' != $services ) {
873 $services = explode("\n", $services);
874 foreach ($services as $service) {
875 weblog_ping($service);
883 function trackback($trackback_url, $title, $excerpt, $ID) {
884 global $wpdb, $wp_version;
886 if ( empty($trackback_url) )
889 $title = urlencode($title);
890 $excerpt = urlencode($excerpt);
891 $blog_name = urlencode(get_settings('blogname'));
892 $tb_url = $trackback_url;
893 $url = urlencode(get_permalink($ID));
894 $query_string = "title=$title&url=$url&blog_name=$blog_name&excerpt=$excerpt";
895 $trackback_url = parse_url($trackback_url);
896 $http_request = 'POST ' . $trackback_url['path'] . ($trackback_url['query'] ? '?'.$trackback_url['query'] : '') . " HTTP/1.0\r\n";
897 $http_request .= 'Host: '.$trackback_url['host']."\r\n";
898 $http_request .= 'Content-Type: application/x-www-form-urlencoded; charset='.get_settings('blog_charset')."\r\n";
899 $http_request .= 'Content-Length: '.strlen($query_string)."\r\n";
900 $http_request .= "User-Agent: WordPress/" . $wp_version;
901 $http_request .= "\r\n\r\n";
902 $http_request .= $query_string;
903 if ( '' == $trackback_url['port'] )
904 $trackback_url['port'] = 80;
905 $fs = @fsockopen($trackback_url['host'], $trackback_url['port'], $errno, $errstr, 4);
906 @fputs($fs, $http_request);
908 $debug_file = 'trackback.log';
909 $fp = fopen($debug_file, 'a');
910 fwrite($fp, "\n*****\nRequest:\n\n$http_request\n\nResponse:\n\n");
912 fwrite($fp, @fgets($fs, 4096));
919 $tb_url = addslashes( $tb_url );
920 $wpdb->query("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', '$tb_url') WHERE ID = '$ID'");
921 return $wpdb->query("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, '$tb_url', '')) WHERE ID = '$ID'");
924 function make_url_footnote($content) {
925 preg_match_all('/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches);
927 for ($i=0; $i<count($matches[0]); $i++) {
928 $links_summary = (!$j) ? "\n" : $links_summary;
930 $link_match = $matches[0][$i];
931 $link_number = '['.($i+1).']';
932 $link_url = $matches[2][$i];
933 $link_text = $matches[4][$i];
934 $content = str_replace($link_match, $link_text.' '.$link_number, $content);
935 $link_url = ((strtolower(substr($link_url,0,7)) != 'http://') && (strtolower(substr($link_url,0,8)) != 'https://')) ? get_settings('home') . $link_url : $link_url;
936 $links_summary .= "\n".$link_number.' '.$link_url;
938 $content = strip_tags($content);
939 $content .= $links_summary;
944 function xmlrpc_getposttitle($content) {
945 global $post_default_title;
946 if ( preg_match('/<title>(.+?)<\/title>/is', $content, $matchtitle) ) {
947 $post_title = $matchtitle[0];
948 $post_title = preg_replace('/<title>/si', '', $post_title);
949 $post_title = preg_replace('/<\/title>/si', '', $post_title);
951 $post_title = $post_default_title;
956 function xmlrpc_getpostcategory($content) {
957 global $post_default_category;
958 if ( preg_match('/<category>(.+?)<\/category>/is', $content, $matchcat) ) {
959 $post_category = trim($matchcat[1], ',');
960 $post_category = explode(',', $post_category);
962 $post_category = $post_default_category;
964 return $post_category;
967 function xmlrpc_removepostdata($content) {
968 $content = preg_replace('/<title>(.+?)<\/title>/si', '', $content);
969 $content = preg_replace('/<category>(.+?)<\/category>/si', '', $content);
970 $content = trim($content);
974 function debug_fopen($filename, $mode) {
977 $fp = fopen($filename, $mode);
984 function debug_fwrite($fp, $string) {
987 fwrite($fp, $string);
991 function debug_fclose($fp) {
998 function spawn_pinger() {
999 global $wpdb, $wp_version;
1001 if ( $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE TRIM(to_ping) != '' LIMIT 1") )
1004 if ( $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pingme' OR meta_key = '_encloseme' LIMIT 1") )
1007 if ( substr(php_sapi_name(), 0, 3) == 'cgi' )
1011 $ping_url = get_settings('siteurl') .'/wp-admin/execute-pings.php';
1012 $parts = parse_url($ping_url);
1013 $argyle = @ fsockopen($parts['host'], $_SERVER['SERVER_PORT'], $errno, $errstr, 0.01);
1015 fputs($argyle, "GET {$parts['path']}?time=".time()." HTTP/1.0\r\nHost: {$_SERVER['HTTP_HOST']}\r\nUser-Agent: WordPress/{$wp_version}\r\n\r\n");
1019 function do_enclose( $content, $post_ID ) {
1020 global $wp_version, $wpdb;
1021 include_once (ABSPATH . WPINC . '/class-IXR.php');
1023 $log = debug_fopen(ABSPATH . '/enclosures.log', 'a');
1024 $post_links = array();
1025 debug_fwrite($log, 'BEGIN '.date('YmdHis', time())."\n");
1027 $pung = get_enclosed( $post_ID );
1030 $gunk = '/#~:.?+=&%@!\-';
1032 $any = $ltrs . $gunk . $punc;
1034 preg_match_all("{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp);
1036 debug_fwrite($log, 'Post contents:');
1037 debug_fwrite($log, $content."\n");
1039 foreach($post_links_temp[0] as $link_test) :
1040 if ( !in_array($link_test, $pung) ) : // If we haven't pung it already
1041 $test = parse_url($link_test);
1042 if ( isset($test['query']) )
1043 $post_links[] = $link_test;
1044 elseif (($test['path'] != '/') && ($test['path'] != ''))
1045 $post_links[] = $link_test;
1049 foreach ($post_links as $url) :
1050 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%')") ) {
1051 if ( $headers = wp_get_http_headers( $url) ) {
1052 $len = (int) $headers['content-length'];
1053 $type = $wpdb->escape( $headers['content-type'] );
1054 $allowed_types = array( 'video', 'audio' );
1055 if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
1056 $meta_value = "$url\n$len\n$type\n";
1057 $wpdb->query( "INSERT INTO `$wpdb->postmeta` ( `post_id` , `meta_key` , `meta_value` )
1058 VALUES ( '$post_ID', 'enclosure' , '$meta_value')" );
1065 function wp_get_http_headers( $url, $red = 1 ) {
1067 @set_time_limit( 60 );
1072 $parts = parse_url( $url );
1073 $file = $parts['path'] . ($parts['query'] ? '?'.$parts['query'] : '');
1074 $host = $parts['host'];
1075 if ( !isset( $parts['port'] ) )
1076 $parts['port'] = 80;
1078 $head = "HEAD $file HTTP/1.1\r\nHOST: $host\r\nUser-Agent: WordPress/" . $wp_version . "\r\n\r\n";
1080 $fp = @fsockopen($host, $parts['port'], $err_num, $err_msg, 3);
1085 fputs( $fp, $head );
1086 while ( !feof( $fp ) && strpos( $response, "\r\n\r\n" ) == false )
1087 $response .= fgets( $fp, 2048 );
1089 preg_match_all('/(.*?): (.*)\r/', $response, $matches);
1090 $count = count($matches[1]);
1091 for ( $i = 0; $i < $count; $i++) {
1092 $key = strtolower($matches[1][$i]);
1093 $headers["$key"] = $matches[2][$i];
1096 preg_match('/.*([0-9]{3}).*/', $response, $return);
1097 $headers['response'] = $return[1]; // HTTP response code eg 204, 200, 404
1099 $code = $headers['response'];
1100 if ( ('302' == $code || '301' == $code) && isset($headers['location']) )
1101 return wp_get_http_headers( $headers['location'], ++$red );
1106 // Deprecated. Use the new post loop.
1107 function start_wp() {
1108 global $wp_query, $post;
1110 // Since the old style loop is being used, advance the query iterator here.
1111 $wp_query->next_post();
1113 setup_postdata($post);
1116 // Setup global post data.
1117 function setup_postdata($post) {
1118 global $id, $postdata, $authordata, $day, $page, $pages, $multipage, $more, $numpages, $wp_query;
1123 $authordata = get_userdata($post->post_author);
1125 $day = mysql2date('d.m.y', $post->post_date);
1126 $currentmonth = mysql2date('m', $post->post_date);
1128 $page = get_query_var('page');
1131 if ( is_single() || is_page() )
1133 $content = $post->post_content;
1134 if ( preg_match('/<!--nextpage-->/', $content) ) {
1138 $content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content);
1139 $content = str_replace("\n<!--nextpage-->", '<!--nextpage-->', $content);
1140 $content = str_replace("<!--nextpage-->\n", '<!--nextpage-->', $content);
1141 $pages = explode('<!--nextpage-->', $content);
1142 $numpages = count($pages);
1144 $pages[0] = $post->post_content;
1150 // Setup global user vars. Used by set_current_user() for back compat.
1151 function setup_userdata($user_id = '') {
1152 global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_pass_md5, $user_identity;
1154 if ( '' == $user_id )
1155 $user = wp_get_current_user();
1157 $user = new WP_User($user_id);
1159 if ( 0 == $user->ID )
1162 $userdata = $user->data;
1163 $user_login = $user->user_login;
1164 $user_level = $user->user_level;
1165 $user_ID = $user->ID;
1166 $user_email = $user->user_email;
1167 $user_url = $user->user_url;
1168 $user_pass_md5 = md5($user->user_pass);
1169 $user_identity = $user->display_name;
1172 function is_new_day() {
1173 global $day, $previousday;
1174 if ( $day != $previousday ) {
1181 // Filters: these are the core of WP's plugin architecture
1183 function merge_filters($tag) {
1185 if ( isset($wp_filter['all']) ) {
1186 foreach ($wp_filter['all'] as $priority => $functions) {
1187 if ( isset($wp_filter[$tag][$priority]) )
1188 $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], $wp_filter[$tag][$priority]);
1190 $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], array());
1191 $wp_filter[$tag][$priority] = array_unique($wp_filter[$tag][$priority]);
1195 if ( isset($wp_filter[$tag]) )
1196 ksort( $wp_filter[$tag] );
1199 function apply_filters($tag, $string) {
1202 $args = array_slice(func_get_args(), 2);
1204 merge_filters($tag);
1206 if ( !isset($wp_filter[$tag]) ) {
1209 foreach ($wp_filter[$tag] as $priority => $functions) {
1210 if ( !is_null($functions) ) {
1211 foreach($functions as $function) {
1213 $all_args = array_merge(array($string), $args);
1214 $function_name = $function['function'];
1215 $accepted_args = $function['accepted_args'];
1217 if ( $accepted_args == 1 )
1218 $the_args = array($string);
1219 elseif ( $accepted_args > 1 )
1220 $the_args = array_slice($all_args, 0, $accepted_args);
1221 elseif ( $accepted_args == 0 )
1224 $the_args = $all_args;
1226 $string = call_user_func_array($function_name, $the_args);
1233 function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
1236 // check that we don't already have the same filter at the same priority
1237 if ( isset($wp_filter[$tag]["$priority"]) ) {
1238 foreach($wp_filter[$tag]["$priority"] as $filter) {
1239 // uncomment if we want to match function AND accepted_args
1240 // if ( $filter == array($function, $accepted_args) ) {
1241 if ( $filter['function'] == $function_to_add ) {
1247 // So the format is wp_filter['tag']['array of priorities']['array of ['array (functions, accepted_args)]']
1248 $wp_filter[$tag]["$priority"][] = array('function'=>$function_to_add, 'accepted_args'=>$accepted_args);
1252 function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
1255 // rebuild the list of filters
1256 if ( isset($wp_filter[$tag]["$priority"]) ) {
1257 $new_function_list = array();
1258 foreach($wp_filter[$tag]["$priority"] as $filter) {
1259 if ( $filter['function'] != $function_to_remove ) {
1260 $new_function_list[] = $filter;
1263 $wp_filter[$tag]["$priority"] = $new_function_list;
1268 // The *_action functions are just aliases for the *_filter functions, they take special strings instead of generic content
1270 function do_action($tag, $arg = '') {
1272 $extra_args = array_slice(func_get_args(), 2);
1273 if ( is_array($arg) )
1274 $args = array_merge($arg, $extra_args);
1276 $args = array_merge(array($arg), $extra_args);
1278 merge_filters($tag);
1280 if ( !isset($wp_filter[$tag]) ) {
1283 foreach ($wp_filter[$tag] as $priority => $functions) {
1284 if ( !is_null($functions) ) {
1285 foreach($functions as $function) {
1287 $function_name = $function['function'];
1288 $accepted_args = $function['accepted_args'];
1290 if ( $accepted_args == 1 ) {
1291 if ( is_array($arg) )
1294 $the_args = array($arg);
1295 } elseif ( $accepted_args > 1 ) {
1296 $the_args = array_slice($args, 0, $accepted_args);
1297 } elseif ( $accepted_args == 0 ) {
1303 $string = call_user_func_array($function_name, $the_args);
1309 function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
1310 add_filter($tag, $function_to_add, $priority, $accepted_args);
1313 function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
1314 remove_filter($tag, $function_to_remove, $priority, $accepted_args);
1317 function get_page_uri($page_id) {
1318 $page = get_page($page_id);
1319 $uri = urldecode($page->post_name);
1321 // A page cannot be it's own parent.
1322 if ( $page->post_parent == $page->ID )
1325 while ($page->post_parent != 0) {
1326 $page = get_page($page->post_parent);
1327 $uri = urldecode($page->post_name) . "/" . $uri;
1333 function get_posts($args) {
1335 parse_str($args, $r);
1336 if ( !isset($r['numberposts']) )
1337 $r['numberposts'] = 5;
1338 if ( !isset($r['offset']) )
1340 if ( !isset($r['category']) )
1341 $r['category'] = '';
1342 if ( !isset($r['orderby']) )
1343 $r['orderby'] = 'post_date';
1344 if ( !isset($r['order']) )
1345 $r['order'] = 'DESC';
1347 $now = current_time('mysql');
1349 $posts = $wpdb->get_results(
1350 "SELECT DISTINCT * FROM $wpdb->posts " .
1351 ( empty( $r['category'] ) ? "" : ", $wpdb->post2cat " ) .
1352 " WHERE post_date <= '$now' AND (post_status = 'publish') ".
1353 ( empty( $r['category'] ) ? "" : "AND $wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $r['category']. " " ) .
1354 " GROUP BY $wpdb->posts.ID ORDER BY " . $r['orderby'] . " " . $r['order'] . " LIMIT " . $r['offset'] . ',' . $r['numberposts'] );
1356 update_post_caches($posts);
1361 function &query_posts($query) {
1363 return $wp_query->query($query);
1366 function update_post_cache(&$posts) {
1372 for ($i = 0; $i < count($posts); $i++) {
1373 $post_cache[$posts[$i]->ID] = &$posts[$i];
1377 function clean_post_cache($id) {
1380 if ( isset( $post_cache[$id] ) )
1381 unset( $post_cache[$id] );
1384 function update_page_cache(&$pages) {
1390 for ($i = 0; $i < count($pages); $i++) {
1391 $page_cache[$pages[$i]->ID] = &$pages[$i];
1392 wp_cache_add($pages[$i]->ID, $pages[$i], 'pages');
1397 function clean_page_cache($id) {
1400 if ( isset( $page_cache[$id] ) )
1401 unset( $page_cache[$id] );
1404 function update_post_category_cache($post_ids) {
1405 global $wpdb, $category_cache;
1407 if ( empty($post_ids) )
1410 if ( is_array($post_ids) )
1411 $post_ids = implode(',', $post_ids);
1413 $dogs = $wpdb->get_results("SELECT post_id, category_id FROM $wpdb->post2cat WHERE post_id IN ($post_ids)");
1418 foreach ($dogs as $catt)
1419 $category_cache[$catt->post_id][$catt->category_id] = &get_category($catt->category_id);
1422 function update_post_caches(&$posts) {
1423 global $post_cache, $category_cache, $comment_count_cache, $post_meta_cache;
1426 // No point in doing all this work if we didn't match any posts.
1430 // Get the categories for all the posts
1431 for ($i = 0; $i < count($posts); $i++) {
1432 $post_id_array[] = $posts[$i]->ID;
1433 $post_cache[$posts[$i]->ID] = &$posts[$i];
1434 $comment_count_cache[$posts[$i]->ID] = $posts[$i]->comment_count;
1437 $post_id_list = implode(',', $post_id_array);
1439 update_post_category_cache($post_id_list);
1441 // Get post-meta info
1442 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) ) {
1443 // Change from flat structure to hierarchical:
1444 $post_meta_cache = array();
1445 foreach ($meta_list as $metarow) {
1446 $mpid = $metarow['post_id'];
1447 $mkey = $metarow['meta_key'];
1448 $mval = $metarow['meta_value'];
1450 // Force subkeys to be array type:
1451 if ( !isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]) )
1452 $post_meta_cache[$mpid] = array();
1453 if ( !isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]) )
1454 $post_meta_cache[$mpid]["$mkey"] = array();
1456 // Add a value to the current pid/key:
1457 $post_meta_cache[$mpid][$mkey][] = $mval;
1462 function update_category_cache() {
1466 function wp_head() {
1467 do_action('wp_head');
1470 function wp_footer() {
1471 do_action('wp_footer');
1474 function is_single ($post = '') {
1477 if ( !$wp_query->is_single )
1480 if ( empty( $post) )
1483 $post_obj = $wp_query->get_queried_object();
1485 if ( $post == $post_obj->ID )
1487 elseif ( $post == $post_obj->post_title )
1489 elseif ( $post == $post_obj->post_name )
1495 function is_page ($page = '') {
1498 if ( !$wp_query->is_page )
1504 $page_obj = $wp_query->get_queried_object();
1506 if ( $page == $page_obj->ID )
1508 elseif ( $page == $page_obj->post_title )
1510 else if ( $page == $page_obj->post_name )
1516 function is_attachment () {
1519 return $wp_query->is_attachment;
1522 function is_preview() {
1525 return $wp_query->is_preview;
1528 function is_archive () {
1531 return $wp_query->is_archive;
1534 function is_date () {
1537 return $wp_query->is_date;
1540 function is_year () {
1543 return $wp_query->is_year;
1546 function is_month () {
1549 return $wp_query->is_month;
1552 function is_day () {
1555 return $wp_query->is_day;
1558 function is_time () {
1561 return $wp_query->is_time;
1564 function is_author ($author = '') {
1567 if ( !$wp_query->is_author )
1570 if ( empty($author) )
1573 $author_obj = $wp_query->get_queried_object();
1575 if ( $author == $author_obj->ID )
1577 elseif ( $author == $author_obj->nickname )
1579 elseif ( $author == $author_obj->user_nicename )
1585 function is_category ($category = '') {
1588 if ( !$wp_query->is_category )
1591 if ( empty($category) )
1594 $cat_obj = $wp_query->get_queried_object();
1596 if ( $category == $cat_obj->cat_ID )
1598 else if ( $category == $cat_obj->cat_name )
1600 elseif ( $category == $cat_obj->category_nicename )
1606 function is_search () {
1609 return $wp_query->is_search;
1612 function is_feed () {
1615 return $wp_query->is_feed;
1618 function is_trackback () {
1621 return $wp_query->is_trackback;
1624 function is_admin () {
1627 return ( $wp_query->is_admin || strstr($_SERVER['REQUEST_URI'], 'wp-admin/') );
1630 function is_home () {
1633 return $wp_query->is_home;
1636 function is_404 () {
1639 return $wp_query->is_404;
1642 function is_comments_popup () {
1645 return $wp_query->is_comments_popup;
1648 function is_paged () {
1651 return $wp_query->is_paged;
1654 function in_the_loop() {
1657 return $wp_query->in_the_loop;
1660 function get_query_var($var) {
1663 return $wp_query->get($var);
1666 function have_posts() {
1669 return $wp_query->have_posts();
1672 function rewind_posts() {
1675 return $wp_query->rewind_posts();
1678 function the_post() {
1681 $wp_query->the_post();
1684 function get_theme_root() {
1685 return apply_filters('theme_root', ABSPATH . "wp-content/themes");
1688 function get_theme_root_uri() {
1689 return apply_filters('theme_root_uri', get_settings('siteurl') . "/wp-content/themes", get_settings('siteurl'));
1692 function get_stylesheet() {
1693 return apply_filters('stylesheet', get_settings('stylesheet'));
1696 function get_stylesheet_directory() {
1697 $stylesheet = get_stylesheet();
1698 $stylesheet_dir = get_theme_root() . "/$stylesheet";
1699 return apply_filters('stylesheet_directory', $stylesheet_dir, $stylesheet);
1702 function get_stylesheet_directory_uri() {
1703 $stylesheet = rawurlencode( get_stylesheet() );
1704 $stylesheet_dir_uri = get_theme_root_uri() . "/$stylesheet";
1705 return apply_filters('stylesheet_directory_uri', $stylesheet_dir_uri, $stylesheet);
1708 function get_stylesheet_uri() {
1709 $stylesheet_dir_uri = get_stylesheet_directory_uri();
1710 $stylesheet_uri = $stylesheet_dir_uri . "/style.css";
1711 return apply_filters('stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri);
1714 function get_template() {
1715 $template = get_settings('template');
1716 if (!file_exists(get_theme_root() . "/$template")) { //works for dirs too
1717 update_option('template', 'default');
1718 update_option('stylesheet', 'default');
1720 return apply_filters('template', get_settings('template'));
1723 function get_template_directory() {
1724 $template = get_template();
1725 $template_dir = get_theme_root() . "/$template";
1726 return apply_filters('template_directory', $template_dir, $template);
1729 function get_template_directory_uri() {
1730 $template = get_template();
1731 $template_dir_uri = get_theme_root_uri() . "/$template";
1732 return apply_filters('template_directory_uri', $template_dir_uri, $template);
1735 function get_theme_data($theme_file) {
1736 $theme_data = implode('', file($theme_file));
1737 preg_match("|Theme Name:(.*)|i", $theme_data, $theme_name);
1738 preg_match("|Theme URI:(.*)|i", $theme_data, $theme_uri);
1739 preg_match("|Description:(.*)|i", $theme_data, $description);
1740 preg_match("|Author:(.*)|i", $theme_data, $author_name);
1741 preg_match("|Author URI:(.*)|i", $theme_data, $author_uri);
1742 preg_match("|Template:(.*)|i", $theme_data, $template);
1743 if ( preg_match("|Version:(.*)|i", $theme_data, $version) )
1744 $version = trim($version[1]);
1747 if ( preg_match("|Status:(.*)|i", $theme_data, $status) )
1748 $status = trim($status[1]);
1750 $status = 'publish';
1752 $description = wptexturize(trim($description[1]));
1754 $name = $theme_name[1];
1755 $name = trim($name);
1758 if ( '' == $author_uri[1] ) {
1759 $author = trim($author_name[1]);
1761 $author = '<a href="' . trim($author_uri[1]) . '" title="' . __('Visit author homepage') . '">' . trim($author_name[1]) . '</a>';
1764 return array('Name' => $name, 'Title' => $theme, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1], 'Status' => $status);
1767 function get_themes() {
1769 global $wp_broken_themes;
1771 if ( isset($wp_themes) )
1775 $wp_broken_themes = array();
1776 $theme_root = get_theme_root();
1777 $theme_loc = str_replace(ABSPATH, '', $theme_root);
1779 // Files in wp-content/themes directory
1780 $themes_dir = @ dir($theme_root);
1781 if ( $themes_dir ) {
1782 while(($theme_dir = $themes_dir->read()) !== false) {
1783 if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) {
1784 if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' ) {
1787 $stylish_dir = @ dir($theme_root . '/' . $theme_dir);
1788 $found_stylesheet = false;
1789 while (($theme_file = $stylish_dir->read()) !== false) {
1790 if ( $theme_file == 'style.css' ) {
1791 $theme_files[] = $theme_dir . '/' . $theme_file;
1792 $found_stylesheet = true;
1796 if ( !$found_stylesheet ) {
1797 $wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.'));
1803 if ( !$themes_dir || !$theme_files ) {
1809 foreach($theme_files as $theme_file) {
1810 if ( ! is_readable("$theme_root/$theme_file") ) {
1811 $wp_broken_themes[$theme_file] = array('Name' => $theme_file, 'Title' => $theme_file, 'Description' => __('File not readable.'));
1815 $theme_data = get_theme_data("$theme_root/$theme_file");
1817 $name = $theme_data['Name'];
1818 $title = $theme_data['Title'];
1819 $description = wptexturize($theme_data['Description']);
1820 $version = $theme_data['Version'];
1821 $author = $theme_data['Author'];
1822 $template = $theme_data['Template'];
1823 $stylesheet = dirname($theme_file);
1825 foreach (array('png', 'gif', 'jpg', 'jpeg') as $ext) {
1826 if (file_exists("$theme_root/$stylesheet/screenshot.$ext")) {
1827 $screenshot = "screenshot.$ext";
1832 if ( empty($name) ) {
1833 $name = dirname($theme_file);
1837 if ( empty($template) ) {
1838 if ( file_exists(dirname("$theme_root/$theme_file/index.php")) ) {
1839 $template = dirname($theme_file);
1845 $template = trim($template);
1847 if ( !file_exists("$theme_root/$template/index.php") ) {
1848 $wp_broken_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => __('Template is missing.'));
1852 $stylesheet_files = array();
1853 $stylesheet_dir = @ dir("$theme_root/$stylesheet");
1854 if ( $stylesheet_dir ) {
1855 while(($file = $stylesheet_dir->read()) !== false) {
1856 if ( !preg_match('|^\.+$|', $file) && preg_match('|\.css$|', $file) )
1857 $stylesheet_files[] = "$theme_loc/$stylesheet/$file";
1861 $template_files = array();
1862 $template_dir = @ dir("$theme_root/$template");
1863 if ( $template_dir ) {
1864 while(($file = $template_dir->read()) !== false) {
1865 if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) )
1866 $template_files[] = "$theme_loc/$template/$file";
1870 $template_dir = dirname($template_files[0]);
1871 $stylesheet_dir = dirname($stylesheet_files[0]);
1873 if ( empty($template_dir) )
1874 $template_dir = '/';
1875 if ( empty($stylesheet_dir) )
1876 $stylesheet_dir = '/';
1878 // Check for theme name collision. This occurs if a theme is copied to
1879 // a new theme directory and the theme header is not updated. Whichever
1880 // theme is first keeps the name. Subsequent themes get a suffix applied.
1881 // The Default and Classic themes always trump their pretenders.
1882 if ( isset($themes[$name]) ) {
1883 if ( ('WordPress Default' == $name || 'WordPress Classic' == $name) &&
1884 ('default' == $stylesheet || 'classic' == $stylesheet) ) {
1885 // If another theme has claimed to be one of our default themes, move
1887 $suffix = $themes[$name]['Stylesheet'];
1888 $new_name = "$name/$suffix";
1889 $themes[$new_name] = $themes[$name];
1890 $themes[$new_name]['Name'] = $new_name;
1892 $name = "$name/$stylesheet";
1896 $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);
1899 // Resolve theme dependencies.
1900 $theme_names = array_keys($themes);
1902 foreach ($theme_names as $theme_name) {
1903 $themes[$theme_name]['Parent Theme'] = '';
1904 if ( $themes[$theme_name]['Stylesheet'] != $themes[$theme_name]['Template'] ) {
1905 foreach ($theme_names as $parent_theme_name) {
1906 if ( ($themes[$parent_theme_name]['Stylesheet'] == $themes[$parent_theme_name]['Template']) && ($themes[$parent_theme_name]['Template'] == $themes[$theme_name]['Template']) ) {
1907 $themes[$theme_name]['Parent Theme'] = $themes[$parent_theme_name]['Name'];
1914 $wp_themes = $themes;
1919 function get_theme($theme) {
1920 $themes = get_themes();
1922 if ( array_key_exists($theme, $themes) )
1923 return $themes[$theme];
1928 function get_current_theme() {
1929 $themes = get_themes();
1930 $theme_names = array_keys($themes);
1931 $current_template = get_settings('template');
1932 $current_stylesheet = get_settings('stylesheet');
1933 $current_theme = 'WordPress Default';
1936 foreach ($theme_names as $theme_name) {
1937 if ( $themes[$theme_name]['Stylesheet'] == $current_stylesheet &&
1938 $themes[$theme_name]['Template'] == $current_template ) {
1939 $current_theme = $themes[$theme_name]['Name'];
1945 return $current_theme;
1948 function get_query_template($type) {
1950 if ( file_exists(TEMPLATEPATH . "/{$type}.php") )
1951 $template = TEMPLATEPATH . "/{$type}.php";
1953 return apply_filters("{$type}_template", $template);
1956 function get_404_template() {
1957 return get_query_template('404');
1960 function get_archive_template() {
1961 return get_query_template('archive');
1964 function get_author_template() {
1965 return get_query_template('author');
1968 function get_category_template() {
1970 if ( file_exists(TEMPLATEPATH . "/category-" . get_query_var('cat') . '.php') )
1971 $template = TEMPLATEPATH . "/category-" . get_query_var('cat') . '.php';
1972 else if ( file_exists(TEMPLATEPATH . "/category.php") )
1973 $template = TEMPLATEPATH . "/category.php";
1975 return apply_filters('category_template', $template);
1978 function get_date_template() {
1979 return get_query_template('date');
1982 function get_home_template() {
1985 if ( file_exists(TEMPLATEPATH . "/home.php") )
1986 $template = TEMPLATEPATH . "/home.php";
1987 else if ( file_exists(TEMPLATEPATH . "/index.php") )
1988 $template = TEMPLATEPATH . "/index.php";
1990 return apply_filters('home_template', $template);
1993 function get_page_template() {
1996 $id = $wp_query->post->ID;
1997 $template = get_post_meta($id, '_wp_page_template', true);
1999 if ( 'default' == $template )
2002 if ( ! empty($template) && file_exists(TEMPLATEPATH . "/$template") )
2003 $template = TEMPLATEPATH . "/$template";
2004 else if ( file_exists(TEMPLATEPATH . "/page.php") )
2005 $template = TEMPLATEPATH . "/page.php";
2009 return apply_filters('page_template', $template);
2012 function get_paged_template() {
2013 return get_query_template('paged');
2016 function get_search_template() {
2017 return get_query_template('search');
2020 function get_single_template() {
2021 return get_query_template('single');
2024 function get_attachment_template() {
2026 $type = explode('/', $posts[0]->post_mime_type);
2027 if ( $template = get_query_template($type[0]) )
2029 elseif ( $template = get_query_template($type[1]) )
2031 elseif ( $template = get_query_template("$type[0]_$type[1]") )
2034 return get_query_template('attachment');
2037 function get_comments_popup_template() {
2038 if ( file_exists( TEMPLATEPATH . '/comments-popup.php') )
2039 $template = TEMPLATEPATH . '/comments-popup.php';
2041 $template = get_theme_root() . '/default/comments-popup.php';
2043 return apply_filters('comments_popup_template', $template);
2046 // Borrowed from the PHP Manual user notes. Convert entities, while
2047 // preserving already-encoded entities:
2048 function htmlentities2($myHTML) {
2049 $translation_table=get_html_translation_table (HTML_ENTITIES,ENT_QUOTES);
2050 $translation_table[chr(38)] = '&';
2051 return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&" , strtr($myHTML, $translation_table));
2055 function is_plugin_page() {
2056 global $plugin_page;
2058 if ( isset($plugin_page) )
2065 add_query_arg: Returns a modified querystring by adding
2066 a single key & value or an associative array.
2067 Setting a key value to emptystring removes the key.
2068 Omitting oldquery_or_uri uses the $_SERVER value.
2071 add_query_arg(newkey, newvalue, oldquery_or_uri) or
2072 add_query_arg(associative_array, oldquery_or_uri)
2074 function add_query_arg() {
2076 if ( is_array(func_get_arg(0)) ) {
2077 if ( @func_num_args() < 2 )
2078 $uri = $_SERVER['REQUEST_URI'];
2080 $uri = @func_get_arg(1);
2082 if ( @func_num_args() < 3 )
2083 $uri = $_SERVER['REQUEST_URI'];
2085 $uri = @func_get_arg(2);
2088 if ( preg_match('|^https?://|i', $uri, $matches) ) {
2089 $protocol = $matches[0];
2090 $uri = substr($uri, strlen($protocol));
2095 if ( strstr($uri, '?') ) {
2096 $parts = explode('?', $uri, 2);
2097 if ( 1 == count($parts) ) {
2101 $base = $parts[0] . '?';
2104 } else if ( !empty($protocol) || strstr($uri, '/') ) {
2112 parse_str($query, $qs);
2113 if ( is_array(func_get_arg(0)) ) {
2114 $kayvees = func_get_arg(0);
2115 $qs = array_merge($qs, $kayvees);
2117 $qs[func_get_arg(0)] = func_get_arg(1);
2120 foreach($qs as $k => $v) {
2127 $ret = $protocol . $base . $ret;
2128 return trim($ret, '?');
2131 function remove_query_arg($key, $query) {
2132 return add_query_arg($key, '', $query);
2135 function load_template($file) {
2136 global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query,
2139 extract($wp_query->query_vars);
2141 require_once($file);
2144 function add_magic_quotes($array) {
2147 foreach ($array as $k => $v) {
2148 if ( is_array($v) ) {
2149 $array[$k] = add_magic_quotes($v);
2151 $array[$k] = $wpdb->escape($v);
2157 function wp_remote_fopen( $uri ) {
2158 if ( ini_get('allow_url_fopen') ) {
2159 $fp = fopen( $uri, 'r' );
2163 while( $remote_read = fread($fp, 4096) )
2164 $linea .= $remote_read;
2167 } else if ( function_exists('curl_init') ) {
2168 $handle = curl_init();
2169 curl_setopt ($handle, CURLOPT_URL, $uri);
2170 curl_setopt ($handle, CURLOPT_CONNECTTIMEOUT, 1);
2171 curl_setopt ($handle, CURLOPT_RETURNTRANSFER, 1);
2172 $buffer = curl_exec($handle);
2173 curl_close($handle);
2180 function wp($query_vars = '') {
2183 $wp->main($query_vars);
2186 function status_header( $header ) {
2187 if ( 200 == $header )
2189 elseif ( 301 == $header )
2190 $text = 'Moved Permanently';
2191 elseif ( 302 == $header )
2192 $text = 'Moved Temporarily';
2193 elseif ( 304 == $header )
2194 $text = 'Not Modified';
2195 elseif ( 404 == $header )
2196 $text = 'Not Found';
2197 elseif ( 410 == $header )
2200 @header("HTTP/1.1 $header $text");
2201 @header("Status: $header $text");
2204 function nocache_headers() {
2205 @ header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
2206 @ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
2207 @ header('Cache-Control: no-cache, must-revalidate, max-age=0');
2208 @ header('Pragma: no-cache');
2211 function get_usermeta( $user_id, $meta_key = '') {
2213 $user_id = (int) $user_id;
2215 if ( !empty($meta_key) ) {
2216 $meta_key = preg_replace('|a-z0-9_|i', '', $meta_key);
2217 $metas = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key'");
2219 $metas = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id'");
2222 if ( empty($metas) ) {
2223 if ( empty($meta_key) )
2229 foreach ($metas as $index => $meta) {
2230 @ $value = unserialize($meta->meta_value);
2231 if ( $value === FALSE )
2232 $value = $meta->meta_value;
2237 if ( count($values) == 1 )
2243 function update_usermeta( $user_id, $meta_key, $meta_value ) {
2245 if ( !is_numeric( $user_id ) )
2247 $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
2249 if ( is_array($meta_value) || is_object($meta_value) )
2250 $meta_value = serialize($meta_value);
2251 $meta_value = trim( $meta_value );
2253 if (empty($meta_value)) {
2254 delete_usermeta($user_id, $meta_key);
2257 $cur = $wpdb->get_row("SELECT * FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key'");
2259 $wpdb->query("INSERT INTO $wpdb->usermeta ( user_id, meta_key, meta_value )
2261 ( '$user_id', '$meta_key', '$meta_value' )");
2262 } else if ( $cur->meta_value != $meta_value ) {
2263 $wpdb->query("UPDATE $wpdb->usermeta SET meta_value = '$meta_value' WHERE user_id = '$user_id' AND meta_key = '$meta_key'");
2268 $user = get_userdata($user_id);
2269 wp_cache_delete($user_id, 'users');
2270 wp_cache_delete($user->user_login, 'userlogins');
2275 function delete_usermeta( $user_id, $meta_key, $meta_value = '' ) {
2277 if ( !is_numeric( $user_id ) )
2279 $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
2281 if ( is_array($meta_value) || is_object($meta_value) )
2282 $meta_value = serialize($meta_value);
2283 $meta_value = trim( $meta_value );
2285 if ( ! empty($meta_value) )
2286 $wpdb->query("DELETE FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key' AND meta_value = '$meta_value'");
2288 $wpdb->query("DELETE FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key'");
2290 $user = get_userdata($user_id);
2291 wp_cache_delete($user_id, 'users');
2292 wp_cache_delete($user->user_login, 'userlogins');
2297 function register_activation_hook($file, $function) {
2298 $file = plugin_basename($file);
2300 add_action('activate_' . $file, $function);
2303 function register_deactivation_hook($file, $function) {
2304 $file = plugin_basename($file);
2306 add_action('deactivate_' . $file, $function);
2309 function plugin_basename($file) {
2310 $file = preg_replace('|\\\\+|', '\\\\', $file);
2311 $file = preg_replace('/^.*wp-content[\\\\\/]plugins[\\\\\/]/', '', $file);
2315 function get_num_queries() {
2317 return $wpdb->num_queries;
2320 function wp_nonce_url($actionurl, $action = -1) {
2321 return wp_specialchars(add_query_arg('_wpnonce', wp_create_nonce($action), $actionurl));
2324 function wp_nonce_field($action = -1) {
2325 echo '<input type="hidden" name="_wpnonce" value="' . wp_create_nonce($action) . '" />';
2329 function wp_referer_field() {
2330 $ref = wp_specialchars($_SERVER['REQUEST_URI']);
2331 echo '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />';
2332 if ( wp_get_original_referer() ) {
2333 $original_ref = wp_specialchars(stripslashes(wp_get_original_referer()));
2334 echo '<input type="hidden" name="_wp_original_http_referer" value="'. $original_ref . '" />';
2338 function wp_original_referer_field() {
2339 echo '<input type="hidden" name="_wp_original_http_referer" value="' . wp_specialchars(stripslashes($_SERVER['REQUEST_URI'])) . '" />';
2342 function wp_get_referer() {
2343 foreach ( array($_REQUEST['_wp_http_referer'], $_SERVER['HTTP_REFERER']) as $ref )
2349 function wp_get_original_referer() {
2350 if ( !empty($_REQUEST['_wp_original_http_referer']) )
2351 return $_REQUEST['_wp_original_http_referer'];
2355 function wp_explain_nonce($action) {
2356 if ( $action !== -1 && preg_match('/([a-z]+)-([a-z]+)(_(.+))?/', $action, $matches) ) {
2357 $verb = $matches[1];
2358 $noun = $matches[2];
2361 $trans['update']['attachment'] = array(__('Are you sure you want to edit this attachment: "%s"?'), 'get_the_title');
2363 $trans['add']['category'] = array(__('Are you sure you want to add this category?'), false);
2364 $trans['delete']['category'] = array(__('Are you sure you want to delete this category: "%s"?'), 'get_catname');
2365 $trans['update']['category'] = array(__('Are you sure you want to edit this category: "%s"?'), 'get_catname');
2367 $trans['delete']['comment'] = array(__('Are you sure you want to delete this comment: "%s"?'), 'use_id');
2368 $trans['unapprove']['comment'] = array(__('Are you sure you want to unapprove this comment: "%s"?'), 'use_id');
2369 $trans['approve']['comment'] = array(__('Are you sure you want to approve this comment: "%s"?'), 'use_id');
2370 $trans['update']['comment'] = array(__('Are you sure you want to edit this comment: "%s"?'), 'use_id');
2371 $trans['bulk']['comments'] = array(__('Are you sure you want to bulk modify comments?'), false);
2372 $trans['moderate']['comments'] = array(__('Are you sure you want to moderate comments?'), false);
2374 $trans['add']['bookmark'] = array(__('Are you sure you want to add this bookmark?'), false);
2375 $trans['delete']['bookmark'] = array(__('Are you sure you want to delete this bookmark: "%s"?'), 'use_id');
2376 $trans['update']['bookmark'] = array(__('Are you sure you want to edit this bookmark: "%s"?'), 'use_id');
2377 $trans['bulk']['bookmarks'] = array(__('Are you sure you want to bulk modify bookmarks?'), false);
2379 $trans['add']['page'] = array(__('Are you sure you want to add this page?'), false);
2380 $trans['delete']['page'] = array(__('Are you sure you want to delete this page: "%s"?'), 'get_the_title');
2381 $trans['update']['page'] = array(__('Are you sure you want to edit this page: "%s"?'), 'get_the_title');
2383 $trans['edit']['plugin'] = array(__('Are you sure you want to edit this plugin file: "%s"?'), 'use_id');
2384 $trans['activate']['plugin'] = array(__('Are you sure you want to activate this plugin: "%s"?'), 'use_id');
2385 $trans['deactivate']['plugin'] = array(__('Are you sure you want to deactivate this plugin: "%s"?'), 'use_id');
2387 $trans['add']['post'] = array(__('Are you sure you want to add this post?'), false);
2388 $trans['delete']['post'] = array(__('Are you sure you want to delete this post: "%s"?'), 'get_the_title');
2389 $trans['update']['post'] = array(__('Are you sure you want to edit this post: "%s"?'), 'get_the_title');
2391 $trans['add']['user'] = array(__('Are you sure you want to add this user?'), false);
2392 $trans['delete']['users'] = array(__('Are you sure you want to delete users?'), false);
2393 $trans['bulk']['users'] = array(__('Are you sure you want to bulk modify users?'), false);
2394 $trans['update']['user'] = array(__('Are you sure you want to edit this user: "%s"?'), 'get_author_name');
2395 $trans['update']['profile'] = array(__('Are you sure you want to modify the profile for: "%s"?'), 'get_author_name');
2397 $trans['update']['options'] = array(__('Are you sure you want to edit your settings?'), false);
2398 $trans['update']['permalink'] = array(__('Are you sure you want to change your permalink structure to: %s?'), 'use_id');
2399 $trans['edit']['file'] = array(__('Are you sure you want to edit this file: "%s"?'), 'use_id');
2400 $trans['edit']['theme'] = array(__('Are you sure you want to edit this theme file: "%s"?'), 'use_id');
2401 $trans['switch']['theme'] = array(__('Are you sure you want to switch to this theme: "%s"?'), 'use_id');
2403 if ( isset($trans[$verb][$noun]) ) {
2404 if ( !empty($trans[$verb][$noun][1]) ) {
2405 $lookup = $trans[$verb][$noun][1];
2406 $object = $matches[4];
2407 if ( 'use_id' != $lookup )
2408 $object = call_user_func($lookup, $object);
2409 return sprintf($trans[$verb][$noun][0], $object);
2411 return $trans[$verb][$noun][0];
2416 return __('Are you sure you want to do this');
2419 function wp_nonce_ays($action) {
2420 global $pagenow, $menu, $submenu, $parent_file, $submenu_file;
2422 $adminurl = get_settings('siteurl') . '/wp-admin';
2423 if ( wp_get_referer() )
2424 $adminurl = wp_get_referer();
2426 $title = __('WordPress Confirmation');
2427 // Remove extra layer of slashes.
2428 $_POST = stripslashes_deep($_POST );
2430 $q = http_build_query($_POST);
2431 $q = explode( ini_get('arg_separator.output'), $q);
2432 $html .= "\t<form method='post' action='$pagenow'>\n";
2433 foreach ( (array) $q as $a ) {
2434 $v = substr(strstr($a, '='), 1);
2435 $k = substr($a, 0, -(strlen($v)+1));
2436 $html .= "\t\t<input type='hidden' name='" . wp_specialchars( urldecode($k), 1 ) . "' value='" . wp_specialchars( urldecode($v), 1 ) . "' />\n";
2438 $html .= "\t\t<input type='hidden' name='_wpnonce' value='" . wp_create_nonce($action) . "' />\n";
2439 $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";
2441 $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";
2443 $html .= "</body>\n</html>";
2444 wp_die($html, $title);
2447 function wp_die($message, $title = '') {
2448 header('Content-Type: text/html; charset=utf-8');
2450 if ( empty($title) )
2451 $title = __('WordPress › Error');
2453 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2454 <html xmlns="http://www.w3.org/1999/xhtml">
2456 <title><?php echo $title ?></title>
2457 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
2458 <style media="screen" type="text/css">
2466 font-family: Georgia, "Times New Roman", Times, serif;
2475 font-weight: lighter;
2484 padding-bottom: 2px;
2488 padding: 5px 5px 5px 20px;
2497 <h1 id="logo"><img alt="WordPress" src="<?php echo get_settings('siteurl'); ?>/wp-admin/images/wordpress-logo.png" /></h1>
2498 <p><?php echo $message; ?></p>