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 $userid = (int) $userid;
175 return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '$userid' AND post_status = 'publish'");
179 // examine a url (supposedly from this blog) and try to
180 // determine the post ID it represents.
181 function url_to_postid($url) {
184 // First, check to see if there is a 'p=N' or 'page_id=N' to match against
185 preg_match('#[?&](p|page_id)=(\d+)#', $url, $values);
186 $id = intval($values[2]);
187 if ( $id ) return $id;
189 // Check to see if we are using rewrite rules
190 $rewrite = $wp_rewrite->wp_rewrite_rules();
192 // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options
193 if ( empty($rewrite) )
196 // $url cleanup by Mark Jaquith
197 // This fixes things like #anchors, ?query=strings, missing 'www.',
198 // added 'www.', or added 'index.php/' that will mess up our WP_Query
199 // and return a false negative
201 // Get rid of the #anchor
202 $url_split = explode('#', $url);
203 $url = $url_split[0];
205 // Get rid of URI ?query=string
206 $url_split = explode('?', $url);
207 $url = $url_split[0];
209 // Add 'www.' if it is absent and should be there
210 if ( false !== strpos(get_settings('home'), '://www.') && false === strpos($url, '://www.') )
211 $url = str_replace('://', '://www.', $url);
213 // Strip 'www.' if it is present and shouldn't be
214 if ( false === strpos(get_settings('home'), '://www.') )
215 $url = str_replace('://www.', '://', $url);
217 // Strip 'index.php/' if we're not using path info permalinks
218 if ( false === strpos($rewrite, 'index.php/') )
219 $url = str_replace('index.php/', '', $url);
221 if ( false !== strpos($url, get_settings('home')) ) {
222 // Chop off http://domain.com
223 $url = str_replace(get_settings('home'), '', $url);
225 // Chop off /path/to/blog
226 $home_path = parse_url(get_settings('home'));
227 $home_path = $home_path['path'];
228 $url = str_replace($home_path, '', $url);
231 // Trim leading and lagging slashes
232 $url = trim($url, '/');
239 $request_match = $request;
240 foreach ($rewrite as $match => $query) {
241 // If the requesting file is the anchor of the match, prepend it
243 if ( (! empty($url)) && (strpos($match, $url) === 0) ) {
244 $request_match = $url . '/' . $request;
247 if ( preg_match("!^$match!", $request_match, $matches) ) {
249 // Trim the query of everything up to the '?'.
250 $query = preg_replace("!^.+\?!", '', $query);
252 // Substitute the substring matches into the query.
253 eval("\$query = \"$query\";");
254 $query = new WP_Query($query);
255 if ( $query->is_single || $query->is_page )
256 return $query->post->ID;
265 function maybe_unserialize($original) {
266 if ( is_serialized($original) ) // don't attempt to unserialize data that wasn't serialized going in
267 if ( false !== $gm = @ unserialize($original) )
272 function maybe_serialize($data) {
273 if ( is_string($data) )
275 elseif ( is_array($data) || is_object($data) )
276 return serialize($data);
277 if ( is_serialized($data) )
278 return serialize($data);
282 function is_serialized($data) {
283 if ( !is_string($data) ) // if it isn't a string, it isn't serialized
286 if ( preg_match("/^[adobis]:[0-9]+:.*[;}]/si",$data) ) // this should fetch all legitimately serialized data
291 function is_serialized_string($data) {
292 if ( !is_string($data) ) // if it isn't a string, it isn't a serialized string
295 if ( preg_match("/^s:[0-9]+:.*[;}]/si",$data) ) // this should fetch all serialized strings
300 /* Options functions */
302 // expects $setting to already be SQL-escaped
303 function get_settings($setting) {
306 $value = wp_cache_get($setting, 'options');
308 if ( false === $value ) {
309 if ( defined('WP_INSTALLING') )
310 $wpdb->hide_errors();
311 $row = $wpdb->get_row("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1");
312 if ( defined('WP_INSTALLING') )
313 $wpdb->show_errors();
315 if( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
316 $value = $row->option_value;
317 wp_cache_set($setting, $value, 'options');
323 // If home is not set use siteurl.
324 if ( 'home' == $setting && '' == $value )
325 return get_settings('siteurl');
327 if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting )
328 $value = preg_replace('|/+$|', '', $value);
330 return apply_filters( 'option_' . $setting, maybe_unserialize($value) );
333 function get_option($option) {
334 return get_settings($option);
337 function get_user_option( $option, $user = 0 ) {
341 $user = wp_get_current_user();
343 $user = get_userdata($user);
345 if ( isset( $user->{$wpdb->prefix . $option} ) ) // Blog specific
346 return $user->{$wpdb->prefix . $option};
347 elseif ( isset( $user->{$option} ) ) // User specific and cross-blog
348 return $user->{$option};
350 return get_option( $option );
353 function form_option($option) {
354 echo attribute_escape( get_option($option));
357 function get_alloptions() {
358 global $wpdb, $wp_queries;
359 $wpdb->hide_errors();
360 if ( !$options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'") ) {
361 $options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options");
363 $wpdb->show_errors();
365 foreach ($options as $option) {
366 // "When trying to design a foolproof system,
367 // never underestimate the ingenuity of the fools :)" -- Dougal
368 if ( 'siteurl' == $option->option_name )
369 $option->option_value = preg_replace('|/+$|', '', $option->option_value);
370 if ( 'home' == $option->option_name )
371 $option->option_value = preg_replace('|/+$|', '', $option->option_value);
372 if ( 'category_base' == $option->option_name )
373 $option->option_value = preg_replace('|/+$|', '', $option->option_value);
374 $value = maybe_unserialize($option->option_value);
375 $all_options->{$option->option_name} = apply_filters('pre_option_' . $option->option_name, $value);
377 return apply_filters('all_options', $all_options);
380 // expects $option_name to NOT be SQL-escaped
381 function update_option($option_name, $newvalue) {
384 $safe_option_name = $wpdb->escape($option_name);
386 if ( is_string($newvalue) )
387 $newvalue = trim($newvalue);
389 // If the new and old values are the same, no need to update.
390 $oldvalue = get_option($safe_option_name);
391 if ( $newvalue == $oldvalue ) {
395 if ( false === $oldvalue ) {
396 add_option($option_name, $newvalue);
400 $_newvalue = $newvalue;
401 $newvalue = maybe_serialize($newvalue);
403 wp_cache_set($option_name, $newvalue, 'options');
405 $newvalue = $wpdb->escape($newvalue);
406 $option_name = $wpdb->escape($option_name);
407 $wpdb->query("UPDATE $wpdb->options SET option_value = '$newvalue' WHERE option_name = '$option_name'");
408 if ( $wpdb->rows_affected == 1 ) {
409 do_action("update_option_{$option_name}", array('old'=>$oldvalue, 'new'=>$_newvalue));
415 function update_user_option( $user_id, $option_name, $newvalue, $global = false ) {
418 $option_name = $wpdb->prefix . $option_name;
419 return update_usermeta( $user_id, $option_name, $newvalue );
422 // thx Alex Stapleton, http://alex.vort-x.net/blog/
423 // expects $name to NOT be SQL-escaped
424 function add_option($name, $value = '', $description = '', $autoload = 'yes') {
427 $safe_name = $wpdb->escape($name);
429 // Make sure the option doesn't already exist
430 if ( false !== get_option($safe_name) )
433 $value = maybe_serialize($value);
435 wp_cache_set($name, $value, 'options');
437 $name = $wpdb->escape($name);
438 $value = $wpdb->escape($value);
439 $description = $wpdb->escape($description);
440 $wpdb->query("INSERT INTO $wpdb->options (option_name, option_value, option_description, autoload) VALUES ('$name', '$value', '$description', '$autoload')");
445 function delete_option($name) {
447 // Get the ID, if no ID then return
448 $option_id = $wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = '$name'");
449 if ( !$option_id ) return false;
450 $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = '$name'");
451 wp_cache_delete($name, 'options');
455 function add_post_meta($post_id, $key, $value, $unique = false) {
456 global $wpdb, $post_meta_cache;
458 $post_id = (int) $post_id;
461 if ( $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key = '$key' AND post_id = '$post_id'") ) {
466 $post_meta_cache[$post_id][$key][] = $value;
468 $value = maybe_serialize($value);
469 $value = $wpdb->escape($value);
471 $wpdb->query("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value) VALUES ('$post_id','$key','$value')");
476 function delete_post_meta($post_id, $key, $value = '') {
477 global $wpdb, $post_meta_cache;
479 $post_id = (int) $post_id;
481 if ( empty($value) ) {
482 $meta_id = $wpdb->get_var("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key'");
484 $meta_id = $wpdb->get_var("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key' AND meta_value = '$value'");
490 if ( empty($value) ) {
491 $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key'");
492 unset($post_meta_cache[$post_id][$key]);
494 $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key' AND meta_value = '$value'");
495 $cache_key = $post_meta_cache[$post_id][$key];
496 if ($cache_key) foreach ( $cache_key as $index => $data )
497 if ( $data == $value )
498 unset($post_meta_cache[$post_id][$key][$index]);
501 unset($post_meta_cache[$post_id][$key]);
506 function get_post_meta($post_id, $key, $single = false) {
507 global $wpdb, $post_meta_cache;
509 $post_id = (int) $post_id;
511 if ( isset($post_meta_cache[$post_id][$key]) ) {
513 return maybe_unserialize( $post_meta_cache[$post_id][$key][0] );
515 return maybe_unserialize( $post_meta_cache[$post_id][$key] );
519 $metalist = $wpdb->get_results("SELECT meta_value FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key'", ARRAY_N);
523 foreach ($metalist as $metarow) {
524 $values[] = $metarow[0];
529 if ( count($values) ) {
530 $return = maybe_unserialize( $values[0] );
538 return maybe_unserialize($return);
541 function update_post_meta($post_id, $key, $value, $prev_value = '') {
542 global $wpdb, $post_meta_cache;
544 $post_id = (int) $post_id;
546 $original_value = $value;
547 $value = maybe_serialize($value);
548 $value = $wpdb->escape($value);
550 $original_prev = $prev_value;
551 $prev_value = maybe_serialize($prev_value);
552 $prev_value = $wpdb->escape($prev_value);
554 if (! $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key = '$key' AND post_id = '$post_id'") ) {
558 if ( empty($prev_value) ) {
559 $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE meta_key = '$key' AND post_id = '$post_id'");
560 $cache_key = $post_meta_cache[$post_id][$key];
561 if ( !empty($cache_key) )
562 foreach ($cache_key as $index => $data)
563 $post_meta_cache[$post_id][$key][$index] = $original_value;
565 $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE meta_key = '$key' AND post_id = '$post_id' AND meta_value = '$prev_value'");
566 $cache_key = $post_meta_cache[$post_id][$key];
567 if ( !empty($cache_key) )
568 foreach ($cache_key as $index => $data)
569 if ( $data == $original_prev )
570 $post_meta_cache[$post_id][$key][$index] = $original_value;
576 // Deprecated. Use get_post().
577 function get_postdata($postid) {
578 $post = &get_post($postid);
582 'Author_ID' => $post->post_author,
583 'Date' => $post->post_date,
584 'Content' => $post->post_content,
585 'Excerpt' => $post->post_excerpt,
586 'Title' => $post->post_title,
587 'Category' => $post->post_category,
588 'post_status' => $post->post_status,
589 'comment_status' => $post->comment_status,
590 'ping_status' => $post->ping_status,
591 'post_password' => $post->post_password,
592 'to_ping' => $post->to_ping,
593 'pinged' => $post->pinged,
594 'post_name' => $post->post_name
600 // Retrieves post data given a post ID or post object.
601 // Handles post caching.
602 function &get_post(&$post, $output = OBJECT) {
603 global $post_cache, $wpdb;
605 if ( empty($post) ) {
606 if ( isset($GLOBALS['post']) )
607 $_post = & $GLOBALS['post'];
610 } elseif ( is_object($post) ) {
611 if ( 'static' == $post->post_status )
612 return get_page($post, $output);
613 if ( !isset($post_cache[$post->ID]) )
614 $post_cache[$post->ID] = &$post;
615 $_post = & $post_cache[$post->ID];
618 if ( $_post = wp_cache_get($post, 'pages') )
619 return get_page($_post, $output);
620 elseif ( isset($post_cache[$post]) )
621 $_post = & $post_cache[$post];
623 $query = "SELECT * FROM $wpdb->posts WHERE ID = '$post' LIMIT 1";
624 $_post = & $wpdb->get_row($query);
625 if ( 'static' == $_post->post_status )
626 return get_page($_post, $output);
627 $post_cache[$post] = & $_post;
631 if ( defined(WP_IMPORTING) )
634 if ( $output == OBJECT ) {
636 } elseif ( $output == ARRAY_A ) {
637 return get_object_vars($_post);
638 } elseif ( $output == ARRAY_N ) {
639 return array_values(get_object_vars($_post));
645 function &get_children($post = 0, $output = OBJECT) {
646 global $post_cache, $wpdb;
648 if ( empty($post) ) {
649 if ( isset($GLOBALS['post']) )
650 $post_parent = & $GLOBALS['post']->post_parent;
653 } elseif ( is_object($post) ) {
654 $post_parent = $post->post_parent;
656 $post_parent = $post;
659 $post_parent = (int) $post_parent;
661 $query = "SELECT * FROM $wpdb->posts WHERE post_parent = $post_parent";
663 $children = $wpdb->get_results($query);
666 foreach ( $children as $key => $child ) {
667 $post_cache[$child->ID] =& $children[$key];
668 $kids[$child->ID] =& $children[$key];
674 if ( $output == OBJECT ) {
676 } elseif ( $output == ARRAY_A ) {
677 foreach ( $kids as $kid )
678 $weeuns[$kid->ID] = get_object_vars($kids[$kid->ID]);
680 } elseif ( $output == ARRAY_N ) {
681 foreach ( $kids as $kid )
682 $babes[$kid->ID] = array_values(get_object_vars($kids[$kid->ID]));
689 function set_page_path($page) {
690 $page->fullpath = '/' . $page->post_name;
691 $path = $page->fullpath;
693 while ($curpage->post_parent != 0) {
694 $curpage = get_page($curpage->post_parent);
695 $path = '/' . $curpage->post_name . $path;
698 $page->fullpath = $path;
703 // Retrieves page data given a page ID or page object.
704 // Handles page caching.
705 function &get_page(&$page, $output = OBJECT) {
708 if ( empty($page) ) {
709 if ( isset($GLOBALS['page']) ) {
710 $_page = & $GLOBALS['page'];
711 wp_cache_add($_page->ID, $_page, 'pages');
715 } elseif ( is_object($page) ) {
716 if ( 'static' != $page->post_status )
717 return get_post($page, $output);
718 wp_cache_add($page->ID, $page, 'pages');
722 if ( isset($GLOBALS['page']) && ($page == $GLOBALS['page']->ID) ) {
723 $_page = & $GLOBALS['page'];
724 wp_cache_add($_page->ID, $_page, 'pages');
725 } elseif ( $_page = $GLOBALS['post_cache'][$page] ) {
726 return get_post($page, $output);
727 } elseif ( $_page = wp_cache_get($page, 'pages') ) {
730 $query = "SELECT * FROM $wpdb->posts WHERE ID= '$page' LIMIT 1";
731 $_page = & $wpdb->get_row($query);
732 if ( 'static' != $_page->post_status )
733 return get_post($_page, $output);
734 wp_cache_add($_page->ID, $_page, 'pages');
738 if (!isset($_page->fullpath)) {
739 $_page = set_page_path($_page);
740 wp_cache_replace($_page->cat_ID, $_page, 'pages');
743 if ( $output == OBJECT ) {
745 } elseif ( $output == ARRAY_A ) {
746 return get_object_vars($_page);
747 } elseif ( $output == ARRAY_N ) {
748 return array_values(get_object_vars($_page));
754 function set_category_path($cat) {
755 $cat->fullpath = '/' . $cat->category_nicename;
756 $path = $cat->fullpath;
758 while ($curcat->category_parent != 0) {
759 $curcat = get_category($curcat->category_parent);
760 $path = '/' . $curcat->category_nicename . $path;
763 $cat->fullpath = $path;
768 // Retrieves category data given a category ID or category object.
769 // Handles category caching.
770 function &get_category(&$category, $output = OBJECT) {
773 if ( empty($category) )
776 if ( is_object($category) ) {
777 wp_cache_add($category->cat_ID, $category, 'category');
778 $_category = $category;
780 $category = (int) $category;
781 if ( ! $_category = wp_cache_get($category, 'category') ) {
782 $_category = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID = '$category' LIMIT 1");
783 wp_cache_add($category, $_category, 'category');
787 $_category = apply_filters('get_category', $_category);
789 if ( !isset($_category->fullpath) ) {
790 $_category = set_category_path($_category);
791 wp_cache_replace($_category->cat_ID, $_category, 'category');
794 if ( $output == OBJECT ) {
796 } elseif ( $output == ARRAY_A ) {
797 return get_object_vars($_category);
798 } elseif ( $output == ARRAY_N ) {
799 return array_values(get_object_vars($_category));
805 // Retrieves comment data given a comment ID or comment object.
806 // Handles comment caching.
807 function &get_comment(&$comment, $output = OBJECT) {
808 global $comment_cache, $wpdb;
810 if ( empty($comment) )
813 if ( is_object($comment) ) {
814 if ( !isset($comment_cache[$comment->comment_ID]) )
815 $comment_cache[$comment->comment_ID] = &$comment;
816 $_comment = & $comment_cache[$comment->comment_ID];
818 $comment = (int) $comment;
819 if ( !isset($comment_cache[$comment]) ) {
820 $_comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment' LIMIT 1");
821 $comment_cache[$comment->comment_ID] = & $_comment;
823 $_comment = & $comment_cache[$comment];
827 if ( $output == OBJECT ) {
829 } elseif ( $output == ARRAY_A ) {
830 return get_object_vars($_comment);
831 } elseif ( $output == ARRAY_N ) {
832 return array_values(get_object_vars($_comment));
838 function get_catname($cat_ID) {
839 $category = &get_category($cat_ID);
840 return $category->cat_name;
843 function get_all_category_ids() {
846 if ( ! $cat_ids = wp_cache_get('all_category_ids', 'category') ) {
847 $cat_ids = $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories");
848 wp_cache_add('all_category_ids', $cat_ids, 'category');
854 function get_all_page_ids() {
857 if ( ! $page_ids = wp_cache_get('all_page_ids', 'pages') ) {
858 $page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_status='static'");
859 wp_cache_add('all_page_ids', $page_ids, 'pages');
865 function gzip_compression() {
866 if ( !get_settings('gzipcompression') ) return false;
868 if ( extension_loaded('zlib') ) {
869 ob_start('ob_gzhandler');
874 // functions to count the page generation time (from phpBB2)
875 // ( or just any time between timer_start() and timer_stop() )
877 function timer_stop($display = 0, $precision = 3) { //if called like timer_stop(1), will echo $timetotal
878 global $timestart, $timeend;
879 $mtime = microtime();
880 $mtime = explode(' ',$mtime);
881 $mtime = $mtime[1] + $mtime[0];
883 $timetotal = $timeend-$timestart;
884 $r = number_format($timetotal, $precision);
890 function weblog_ping($server = '', $path = '') {
892 include_once (ABSPATH . WPINC . '/class-IXR.php');
894 // using a timeout of 3 seconds should be enough to cover slow servers
895 $client = new IXR_Client($server, ((!strlen(trim($path)) || ('/' == $path)) ? false : $path));
896 $client->timeout = 3;
897 $client->useragent .= ' -- WordPress/'.$wp_version;
899 // when set to true, this outputs debug messages by itself
900 $client->debug = false;
901 $home = trailingslashit( get_option('home') );
902 if ( !$client->query('weblogUpdates.extendedPing', get_settings('blogname'), $home, get_bloginfo('rss2_url') ) ) // then try a normal ping
903 $client->query('weblogUpdates.ping', get_settings('blogname'), $home);
906 function generic_ping($post_id = 0) {
907 $services = get_settings('ping_sites');
908 $services = preg_replace("|(\s)+|", '$1', $services); // Kill dupe lines
909 $services = trim($services);
910 if ( '' != $services ) {
911 $services = explode("\n", $services);
912 foreach ($services as $service) {
913 weblog_ping($service);
921 function trackback($trackback_url, $title, $excerpt, $ID) {
922 global $wpdb, $wp_version;
924 if ( empty($trackback_url) )
927 $title = urlencode($title);
928 $excerpt = urlencode($excerpt);
929 $blog_name = urlencode(get_settings('blogname'));
930 $tb_url = $trackback_url;
931 $url = urlencode(get_permalink($ID));
932 $query_string = "title=$title&url=$url&blog_name=$blog_name&excerpt=$excerpt";
933 $trackback_url = parse_url($trackback_url);
934 $http_request = 'POST ' . $trackback_url['path'] . ($trackback_url['query'] ? '?'.$trackback_url['query'] : '') . " HTTP/1.0\r\n";
935 $http_request .= 'Host: '.$trackback_url['host']."\r\n";
936 $http_request .= 'Content-Type: application/x-www-form-urlencoded; charset='.get_settings('blog_charset')."\r\n";
937 $http_request .= 'Content-Length: '.strlen($query_string)."\r\n";
938 $http_request .= "User-Agent: WordPress/" . $wp_version;
939 $http_request .= "\r\n\r\n";
940 $http_request .= $query_string;
941 if ( '' == $trackback_url['port'] )
942 $trackback_url['port'] = 80;
943 $fs = @fsockopen($trackback_url['host'], $trackback_url['port'], $errno, $errstr, 4);
944 @fputs($fs, $http_request);
946 $debug_file = 'trackback.log';
947 $fp = fopen($debug_file, 'a');
948 fwrite($fp, "\n*****\nRequest:\n\n$http_request\n\nResponse:\n\n");
950 fwrite($fp, @fgets($fs, 4096));
957 $tb_url = addslashes( $tb_url );
958 $wpdb->query("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', '$tb_url') WHERE ID = '$ID'");
959 return $wpdb->query("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, '$tb_url', '')) WHERE ID = '$ID'");
962 function make_url_footnote($content) {
963 preg_match_all('/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches);
965 for ($i=0; $i<count($matches[0]); $i++) {
966 $links_summary = (!$j) ? "\n" : $links_summary;
968 $link_match = $matches[0][$i];
969 $link_number = '['.($i+1).']';
970 $link_url = $matches[2][$i];
971 $link_text = $matches[4][$i];
972 $content = str_replace($link_match, $link_text.' '.$link_number, $content);
973 $link_url = ((strtolower(substr($link_url,0,7)) != 'http://') && (strtolower(substr($link_url,0,8)) != 'https://')) ? get_settings('home') . $link_url : $link_url;
974 $links_summary .= "\n".$link_number.' '.$link_url;
976 $content = strip_tags($content);
977 $content .= $links_summary;
982 function xmlrpc_getposttitle($content) {
983 global $post_default_title;
984 if ( preg_match('/<title>(.+?)<\/title>/is', $content, $matchtitle) ) {
985 $post_title = $matchtitle[0];
986 $post_title = preg_replace('/<title>/si', '', $post_title);
987 $post_title = preg_replace('/<\/title>/si', '', $post_title);
989 $post_title = $post_default_title;
994 function xmlrpc_getpostcategory($content) {
995 global $post_default_category;
996 if ( preg_match('/<category>(.+?)<\/category>/is', $content, $matchcat) ) {
997 $post_category = trim($matchcat[1], ',');
998 $post_category = explode(',', $post_category);
1000 $post_category = $post_default_category;
1002 return $post_category;
1005 function xmlrpc_removepostdata($content) {
1006 $content = preg_replace('/<title>(.+?)<\/title>/si', '', $content);
1007 $content = preg_replace('/<category>(.+?)<\/category>/si', '', $content);
1008 $content = trim($content);
1012 function debug_fopen($filename, $mode) {
1014 if ( $debug == 1 ) {
1015 $fp = fopen($filename, $mode);
1022 function debug_fwrite($fp, $string) {
1024 if ( $debug == 1 ) {
1025 fwrite($fp, $string);
1029 function debug_fclose($fp) {
1031 if ( $debug == 1 ) {
1036 function spawn_pinger() {
1037 global $wpdb, $wp_version;
1039 if ( $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE TRIM(to_ping) != '' LIMIT 1") )
1042 if ( $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pingme' OR meta_key = '_encloseme' LIMIT 1") )
1045 if ( substr(php_sapi_name(), 0, 3) == 'cgi' )
1049 $ping_url = get_settings('siteurl') .'/wp-admin/execute-pings.php';
1050 $parts = parse_url($ping_url);
1051 $argyle = @ fsockopen($parts['host'], $_SERVER['SERVER_PORT'], $errno, $errstr, 0.01);
1053 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");
1057 function do_enclose( $content, $post_ID ) {
1058 global $wp_version, $wpdb;
1059 include_once (ABSPATH . WPINC . '/class-IXR.php');
1061 $log = debug_fopen(ABSPATH . '/enclosures.log', 'a');
1062 $post_links = array();
1063 debug_fwrite($log, 'BEGIN '.date('YmdHis', time())."\n");
1065 $pung = get_enclosed( $post_ID );
1068 $gunk = '/#~:.?+=&%@!\-';
1070 $any = $ltrs . $gunk . $punc;
1072 preg_match_all("{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp);
1074 debug_fwrite($log, 'Post contents:');
1075 debug_fwrite($log, $content."\n");
1077 foreach($post_links_temp[0] as $link_test) :
1078 if ( !in_array($link_test, $pung) ) : // If we haven't pung it already
1079 $test = parse_url($link_test);
1080 if ( isset($test['query']) )
1081 $post_links[] = $link_test;
1082 elseif (($test['path'] != '/') && ($test['path'] != ''))
1083 $post_links[] = $link_test;
1087 foreach ($post_links as $url) :
1088 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%')") ) {
1089 if ( $headers = wp_get_http_headers( $url) ) {
1090 $len = (int) $headers['content-length'];
1091 $type = $wpdb->escape( $headers['content-type'] );
1092 $allowed_types = array( 'video', 'audio' );
1093 if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
1094 $meta_value = "$url\n$len\n$type\n";
1095 $wpdb->query( "INSERT INTO `$wpdb->postmeta` ( `post_id` , `meta_key` , `meta_value` )
1096 VALUES ( '$post_ID', 'enclosure' , '$meta_value')" );
1103 function wp_get_http_headers( $url, $red = 1 ) {
1105 @set_time_limit( 60 );
1110 $parts = parse_url( $url );
1111 $file = $parts['path'] . ($parts['query'] ? '?'.$parts['query'] : '');
1112 $host = $parts['host'];
1113 if ( !isset( $parts['port'] ) )
1114 $parts['port'] = 80;
1116 $head = "HEAD $file HTTP/1.1\r\nHOST: $host\r\nUser-Agent: WordPress/" . $wp_version . "\r\n\r\n";
1118 $fp = @fsockopen($host, $parts['port'], $err_num, $err_msg, 3);
1123 fputs( $fp, $head );
1124 while ( !feof( $fp ) && strpos( $response, "\r\n\r\n" ) == false )
1125 $response .= fgets( $fp, 2048 );
1127 preg_match_all('/(.*?): (.*)\r/', $response, $matches);
1128 $count = count($matches[1]);
1129 for ( $i = 0; $i < $count; $i++) {
1130 $key = strtolower($matches[1][$i]);
1131 $headers["$key"] = $matches[2][$i];
1134 preg_match('/.*([0-9]{3}).*/', $response, $return);
1135 $headers['response'] = $return[1]; // HTTP response code eg 204, 200, 404
1137 $code = $headers['response'];
1138 if ( ('302' == $code || '301' == $code) && isset($headers['location']) )
1139 return wp_get_http_headers( $headers['location'], ++$red );
1144 // Deprecated. Use the new post loop.
1145 function start_wp() {
1146 global $wp_query, $post;
1148 // Since the old style loop is being used, advance the query iterator here.
1149 $wp_query->next_post();
1151 setup_postdata($post);
1154 // Setup global post data.
1155 function setup_postdata($post) {
1156 global $id, $postdata, $authordata, $day, $page, $pages, $multipage, $more, $numpages, $wp_query;
1161 $authordata = get_userdata($post->post_author);
1163 $day = mysql2date('d.m.y', $post->post_date);
1164 $currentmonth = mysql2date('m', $post->post_date);
1166 $page = get_query_var('page');
1169 if ( is_single() || is_page() )
1171 $content = $post->post_content;
1172 if ( preg_match('/<!--nextpage-->/', $content) ) {
1176 $content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content);
1177 $content = str_replace("\n<!--nextpage-->", '<!--nextpage-->', $content);
1178 $content = str_replace("<!--nextpage-->\n", '<!--nextpage-->', $content);
1179 $pages = explode('<!--nextpage-->', $content);
1180 $numpages = count($pages);
1182 $pages[0] = $post->post_content;
1188 // Setup global user vars. Used by set_current_user() for back compat.
1189 function setup_userdata($user_id = '') {
1190 global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_pass_md5, $user_identity;
1192 if ( '' == $user_id )
1193 $user = wp_get_current_user();
1195 $user = new WP_User($user_id);
1197 if ( 0 == $user->ID )
1200 $userdata = $user->data;
1201 $user_login = $user->user_login;
1202 $user_level = $user->user_level;
1203 $user_ID = $user->ID;
1204 $user_email = $user->user_email;
1205 $user_url = $user->user_url;
1206 $user_pass_md5 = md5($user->user_pass);
1207 $user_identity = $user->display_name;
1210 function is_new_day() {
1211 global $day, $previousday;
1212 if ( $day != $previousday ) {
1219 // Filters: these are the core of WP's plugin architecture
1221 function merge_filters($tag) {
1223 if ( isset($wp_filter['all']) ) {
1224 foreach ($wp_filter['all'] as $priority => $functions) {
1225 if ( isset($wp_filter[$tag][$priority]) )
1226 $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], $wp_filter[$tag][$priority]);
1228 $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], array());
1229 $wp_filter[$tag][$priority] = array_unique($wp_filter[$tag][$priority]);
1233 if ( isset($wp_filter[$tag]) )
1234 uksort( $wp_filter[$tag], "strnatcasecmp" );
1237 function apply_filters($tag, $string) {
1240 $args = array_slice(func_get_args(), 2);
1242 merge_filters($tag);
1244 if ( !isset($wp_filter[$tag]) ) {
1247 foreach ($wp_filter[$tag] as $priority => $functions) {
1248 if ( !is_null($functions) ) {
1249 foreach($functions as $function) {
1251 $all_args = array_merge(array($string), $args);
1252 $function_name = $function['function'];
1253 $accepted_args = $function['accepted_args'];
1255 if ( $accepted_args == 1 )
1256 $the_args = array($string);
1257 elseif ( $accepted_args > 1 )
1258 $the_args = array_slice($all_args, 0, $accepted_args);
1259 elseif ( $accepted_args == 0 )
1262 $the_args = $all_args;
1264 $string = call_user_func_array($function_name, $the_args);
1271 function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
1274 // check that we don't already have the same filter at the same priority
1275 if ( isset($wp_filter[$tag]["$priority"]) ) {
1276 foreach($wp_filter[$tag]["$priority"] as $filter) {
1277 // uncomment if we want to match function AND accepted_args
1278 // if ( $filter == array($function, $accepted_args) ) {
1279 if ( $filter['function'] == $function_to_add ) {
1285 // So the format is wp_filter['tag']['array of priorities']['array of ['array (functions, accepted_args)]']
1286 $wp_filter[$tag]["$priority"][] = array('function'=>$function_to_add, 'accepted_args'=>$accepted_args);
1290 function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
1293 // rebuild the list of filters
1294 if ( isset($wp_filter[$tag]["$priority"]) ) {
1295 $new_function_list = array();
1296 foreach($wp_filter[$tag]["$priority"] as $filter) {
1297 if ( $filter['function'] != $function_to_remove ) {
1298 $new_function_list[] = $filter;
1301 $wp_filter[$tag]["$priority"] = $new_function_list;
1306 // The *_action functions are just aliases for the *_filter functions, they take special strings instead of generic content
1308 function do_action($tag, $arg = '') {
1310 $extra_args = array_slice(func_get_args(), 2);
1311 if ( is_array($arg) )
1312 $args = array_merge($arg, $extra_args);
1314 $args = array_merge(array($arg), $extra_args);
1316 merge_filters($tag);
1318 if ( !isset($wp_filter[$tag]) ) {
1321 foreach ($wp_filter[$tag] as $priority => $functions) {
1322 if ( !is_null($functions) ) {
1323 foreach($functions as $function) {
1325 $function_name = $function['function'];
1326 $accepted_args = $function['accepted_args'];
1328 if ( $accepted_args == 1 ) {
1329 if ( is_array($arg) )
1332 $the_args = array($arg);
1333 } elseif ( $accepted_args > 1 ) {
1334 $the_args = array_slice($args, 0, $accepted_args);
1335 } elseif ( $accepted_args == 0 ) {
1341 $string = call_user_func_array($function_name, $the_args);
1347 function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
1348 add_filter($tag, $function_to_add, $priority, $accepted_args);
1351 function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
1352 remove_filter($tag, $function_to_remove, $priority, $accepted_args);
1355 function get_page_uri($page_id) {
1356 $page = get_page($page_id);
1357 $uri = urldecode($page->post_name);
1359 // A page cannot be it's own parent.
1360 if ( $page->post_parent == $page->ID )
1363 while ($page->post_parent != 0) {
1364 $page = get_page($page->post_parent);
1365 $uri = urldecode($page->post_name) . "/" . $uri;
1371 function get_posts($args) {
1373 parse_str($args, $r);
1374 if ( !isset($r['numberposts']) )
1375 $r['numberposts'] = 5;
1376 if ( !isset($r['offset']) )
1378 if ( !isset($r['category']) )
1379 $r['category'] = '';
1380 if ( !isset($r['orderby']) )
1381 $r['orderby'] = 'post_date';
1382 if ( !isset($r['order']) )
1383 $r['order'] = 'DESC';
1385 $now = current_time('mysql');
1387 $posts = $wpdb->get_results(
1388 "SELECT DISTINCT * FROM $wpdb->posts " .
1389 ( empty( $r['category'] ) ? "" : ", $wpdb->post2cat " ) .
1390 " WHERE post_date <= '$now' AND (post_status = 'publish') ".
1391 ( empty( $r['category'] ) ? "" : "AND $wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $r['category']. " " ) .
1392 " GROUP BY $wpdb->posts.ID ORDER BY " . $r['orderby'] . " " . $r['order'] . " LIMIT " . $r['offset'] . ',' . $r['numberposts'] );
1394 update_post_caches($posts);
1399 function &query_posts($query) {
1401 return $wp_query->query($query);
1404 function update_post_cache(&$posts) {
1410 for ($i = 0; $i < count($posts); $i++) {
1411 $post_cache[$posts[$i]->ID] = &$posts[$i];
1415 function clean_post_cache($id) {
1418 if ( isset( $post_cache[$id] ) )
1419 unset( $post_cache[$id] );
1422 function update_page_cache(&$pages) {
1428 for ($i = 0; $i < count($pages); $i++) {
1429 $page_cache[$pages[$i]->ID] = &$pages[$i];
1430 wp_cache_add($pages[$i]->ID, $pages[$i], 'pages');
1435 function clean_page_cache($id) {
1438 if ( isset( $page_cache[$id] ) )
1439 unset( $page_cache[$id] );
1442 function update_post_category_cache($post_ids) {
1443 global $wpdb, $category_cache;
1445 if ( empty($post_ids) )
1448 if ( is_array($post_ids) )
1449 $post_ids = implode(',', $post_ids);
1451 $dogs = $wpdb->get_results("SELECT post_id, category_id FROM $wpdb->post2cat WHERE post_id IN ($post_ids)");
1456 foreach ($dogs as $catt)
1457 $category_cache[$catt->post_id][$catt->category_id] = &get_category($catt->category_id);
1460 function update_post_caches(&$posts) {
1461 global $post_cache, $category_cache, $comment_count_cache, $post_meta_cache;
1464 // No point in doing all this work if we didn't match any posts.
1468 // Get the categories for all the posts
1469 for ($i = 0; $i < count($posts); $i++) {
1470 $post_id_array[] = $posts[$i]->ID;
1471 $post_cache[$posts[$i]->ID] = &$posts[$i];
1472 $comment_count_cache[$posts[$i]->ID] = $posts[$i]->comment_count;
1475 $post_id_list = implode(',', $post_id_array);
1477 update_post_category_cache($post_id_list);
1479 // Get post-meta info
1480 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) ) {
1481 // Change from flat structure to hierarchical:
1482 $post_meta_cache = array();
1483 foreach ($meta_list as $metarow) {
1484 $mpid = (int) $metarow['post_id'];
1485 $mkey = $metarow['meta_key'];
1486 $mval = $metarow['meta_value'];
1488 // Force subkeys to be array type:
1489 if ( !isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]) )
1490 $post_meta_cache[$mpid] = array();
1491 if ( !isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]) )
1492 $post_meta_cache[$mpid]["$mkey"] = array();
1494 // Add a value to the current pid/key:
1495 $post_meta_cache[$mpid][$mkey][] = $mval;
1500 function update_category_cache() {
1504 function wp_head() {
1505 do_action('wp_head');
1508 function wp_footer() {
1509 do_action('wp_footer');
1512 function is_single ($post = '') {
1515 if ( !$wp_query->is_single )
1518 if ( empty( $post) )
1521 $post_obj = $wp_query->get_queried_object();
1523 if ( $post == $post_obj->ID )
1525 elseif ( $post == $post_obj->post_title )
1527 elseif ( $post == $post_obj->post_name )
1533 function is_page ($page = '') {
1536 if ( !$wp_query->is_page )
1542 $page_obj = $wp_query->get_queried_object();
1544 if ( $page == $page_obj->ID )
1546 elseif ( $page == $page_obj->post_title )
1548 else if ( $page == $page_obj->post_name )
1554 function is_attachment () {
1557 return $wp_query->is_attachment;
1560 function is_preview() {
1563 return $wp_query->is_preview;
1566 function is_archive () {
1569 return $wp_query->is_archive;
1572 function is_date () {
1575 return $wp_query->is_date;
1578 function is_year () {
1581 return $wp_query->is_year;
1584 function is_month () {
1587 return $wp_query->is_month;
1590 function is_day () {
1593 return $wp_query->is_day;
1596 function is_time () {
1599 return $wp_query->is_time;
1602 function is_author ($author = '') {
1605 if ( !$wp_query->is_author )
1608 if ( empty($author) )
1611 $author_obj = $wp_query->get_queried_object();
1613 if ( $author == $author_obj->ID )
1615 elseif ( $author == $author_obj->nickname )
1617 elseif ( $author == $author_obj->user_nicename )
1623 function is_category ($category = '') {
1626 if ( !$wp_query->is_category )
1629 if ( empty($category) )
1632 $cat_obj = $wp_query->get_queried_object();
1634 if ( $category == $cat_obj->cat_ID )
1636 else if ( $category == $cat_obj->cat_name )
1638 elseif ( $category == $cat_obj->category_nicename )
1644 function is_search () {
1647 return $wp_query->is_search;
1650 function is_feed () {
1653 return $wp_query->is_feed;
1656 function is_trackback () {
1659 return $wp_query->is_trackback;
1662 function is_admin () {
1665 return ( $wp_query->is_admin || strstr($_SERVER['REQUEST_URI'], 'wp-admin/') );
1668 function is_home () {
1671 return $wp_query->is_home;
1674 function is_404 () {
1677 return $wp_query->is_404;
1680 function is_comments_popup () {
1683 return $wp_query->is_comments_popup;
1686 function is_paged () {
1689 return $wp_query->is_paged;
1692 function in_the_loop() {
1695 return $wp_query->in_the_loop;
1698 function get_query_var($var) {
1701 return $wp_query->get($var);
1704 function have_posts() {
1707 return $wp_query->have_posts();
1710 function rewind_posts() {
1713 return $wp_query->rewind_posts();
1716 function the_post() {
1719 $wp_query->the_post();
1722 function get_theme_root() {
1723 return apply_filters('theme_root', ABSPATH . "wp-content/themes");
1726 function get_theme_root_uri() {
1727 return apply_filters('theme_root_uri', get_settings('siteurl') . "/wp-content/themes", get_settings('siteurl'));
1730 function get_stylesheet() {
1731 return apply_filters('stylesheet', get_settings('stylesheet'));
1734 function get_stylesheet_directory() {
1735 $stylesheet = get_stylesheet();
1736 $stylesheet_dir = get_theme_root() . "/$stylesheet";
1737 return apply_filters('stylesheet_directory', $stylesheet_dir, $stylesheet);
1740 function get_stylesheet_directory_uri() {
1741 $stylesheet = rawurlencode( get_stylesheet() );
1742 $stylesheet_dir_uri = get_theme_root_uri() . "/$stylesheet";
1743 return apply_filters('stylesheet_directory_uri', $stylesheet_dir_uri, $stylesheet);
1746 function get_stylesheet_uri() {
1747 $stylesheet_dir_uri = get_stylesheet_directory_uri();
1748 $stylesheet_uri = $stylesheet_dir_uri . "/style.css";
1749 return apply_filters('stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri);
1752 function get_template() {
1753 $template = get_settings('template');
1754 if (!file_exists(get_theme_root() . "/$template")) { //works for dirs too
1755 update_option('template', 'default');
1756 update_option('stylesheet', 'default');
1758 return apply_filters('template', get_settings('template'));
1761 function get_template_directory() {
1762 $template = get_template();
1763 $template_dir = get_theme_root() . "/$template";
1764 return apply_filters('template_directory', $template_dir, $template);
1767 function get_template_directory_uri() {
1768 $template = get_template();
1769 $template_dir_uri = get_theme_root_uri() . "/$template";
1770 return apply_filters('template_directory_uri', $template_dir_uri, $template);
1773 function get_theme_data($theme_file) {
1774 $theme_data = implode('', file($theme_file));
1775 preg_match("|Theme Name:(.*)|i", $theme_data, $theme_name);
1776 preg_match("|Theme URI:(.*)|i", $theme_data, $theme_uri);
1777 preg_match("|Description:(.*)|i", $theme_data, $description);
1778 preg_match("|Author:(.*)|i", $theme_data, $author_name);
1779 preg_match("|Author URI:(.*)|i", $theme_data, $author_uri);
1780 preg_match("|Template:(.*)|i", $theme_data, $template);
1781 if ( preg_match("|Version:(.*)|i", $theme_data, $version) )
1782 $version = trim($version[1]);
1785 if ( preg_match("|Status:(.*)|i", $theme_data, $status) )
1786 $status = trim($status[1]);
1788 $status = 'publish';
1790 $description = wptexturize(trim($description[1]));
1792 $name = $theme_name[1];
1793 $name = trim($name);
1796 if ( '' == $author_uri[1] ) {
1797 $author = trim($author_name[1]);
1799 $author = '<a href="' . trim($author_uri[1]) . '" title="' . __('Visit author homepage') . '">' . trim($author_name[1]) . '</a>';
1802 return array('Name' => $name, 'Title' => $theme, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1], 'Status' => $status);
1805 function get_themes() {
1807 global $wp_broken_themes;
1809 if ( isset($wp_themes) )
1813 $wp_broken_themes = array();
1814 $theme_root = get_theme_root();
1815 $theme_loc = str_replace(ABSPATH, '', $theme_root);
1817 // Files in wp-content/themes directory
1818 $themes_dir = @ dir($theme_root);
1819 if ( $themes_dir ) {
1820 while(($theme_dir = $themes_dir->read()) !== false) {
1821 if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) {
1822 if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' ) {
1825 $stylish_dir = @ dir($theme_root . '/' . $theme_dir);
1826 $found_stylesheet = false;
1827 while (($theme_file = $stylish_dir->read()) !== false) {
1828 if ( $theme_file == 'style.css' ) {
1829 $theme_files[] = $theme_dir . '/' . $theme_file;
1830 $found_stylesheet = true;
1834 if ( !$found_stylesheet ) {
1835 $wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.'));
1841 if ( !$themes_dir || !$theme_files ) {
1847 foreach($theme_files as $theme_file) {
1848 if ( ! is_readable("$theme_root/$theme_file") ) {
1849 $wp_broken_themes[$theme_file] = array('Name' => $theme_file, 'Title' => $theme_file, 'Description' => __('File not readable.'));
1853 $theme_data = get_theme_data("$theme_root/$theme_file");
1855 $name = $theme_data['Name'];
1856 $title = $theme_data['Title'];
1857 $description = wptexturize($theme_data['Description']);
1858 $version = $theme_data['Version'];
1859 $author = $theme_data['Author'];
1860 $template = $theme_data['Template'];
1861 $stylesheet = dirname($theme_file);
1863 foreach (array('png', 'gif', 'jpg', 'jpeg') as $ext) {
1864 if (file_exists("$theme_root/$stylesheet/screenshot.$ext")) {
1865 $screenshot = "screenshot.$ext";
1870 if ( empty($name) ) {
1871 $name = dirname($theme_file);
1875 if ( empty($template) ) {
1876 if ( file_exists(dirname("$theme_root/$theme_file/index.php")) ) {
1877 $template = dirname($theme_file);
1883 $template = trim($template);
1885 if ( !file_exists("$theme_root/$template/index.php") ) {
1886 $wp_broken_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => __('Template is missing.'));
1890 $stylesheet_files = array();
1891 $stylesheet_dir = @ dir("$theme_root/$stylesheet");
1892 if ( $stylesheet_dir ) {
1893 while(($file = $stylesheet_dir->read()) !== false) {
1894 if ( !preg_match('|^\.+$|', $file) && preg_match('|\.css$|', $file) )
1895 $stylesheet_files[] = "$theme_loc/$stylesheet/$file";
1899 $template_files = array();
1900 $template_dir = @ dir("$theme_root/$template");
1901 if ( $template_dir ) {
1902 while(($file = $template_dir->read()) !== false) {
1903 if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) )
1904 $template_files[] = "$theme_loc/$template/$file";
1908 $template_dir = dirname($template_files[0]);
1909 $stylesheet_dir = dirname($stylesheet_files[0]);
1911 if ( empty($template_dir) )
1912 $template_dir = '/';
1913 if ( empty($stylesheet_dir) )
1914 $stylesheet_dir = '/';
1916 // Check for theme name collision. This occurs if a theme is copied to
1917 // a new theme directory and the theme header is not updated. Whichever
1918 // theme is first keeps the name. Subsequent themes get a suffix applied.
1919 // The Default and Classic themes always trump their pretenders.
1920 if ( isset($themes[$name]) ) {
1921 if ( ('WordPress Default' == $name || 'WordPress Classic' == $name) &&
1922 ('default' == $stylesheet || 'classic' == $stylesheet) ) {
1923 // If another theme has claimed to be one of our default themes, move
1925 $suffix = $themes[$name]['Stylesheet'];
1926 $new_name = "$name/$suffix";
1927 $themes[$new_name] = $themes[$name];
1928 $themes[$new_name]['Name'] = $new_name;
1930 $name = "$name/$stylesheet";
1934 $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);
1937 // Resolve theme dependencies.
1938 $theme_names = array_keys($themes);
1940 foreach ($theme_names as $theme_name) {
1941 $themes[$theme_name]['Parent Theme'] = '';
1942 if ( $themes[$theme_name]['Stylesheet'] != $themes[$theme_name]['Template'] ) {
1943 foreach ($theme_names as $parent_theme_name) {
1944 if ( ($themes[$parent_theme_name]['Stylesheet'] == $themes[$parent_theme_name]['Template']) && ($themes[$parent_theme_name]['Template'] == $themes[$theme_name]['Template']) ) {
1945 $themes[$theme_name]['Parent Theme'] = $themes[$parent_theme_name]['Name'];
1952 $wp_themes = $themes;
1957 function get_theme($theme) {
1958 $themes = get_themes();
1960 if ( array_key_exists($theme, $themes) )
1961 return $themes[$theme];
1966 function get_current_theme() {
1967 $themes = get_themes();
1968 $theme_names = array_keys($themes);
1969 $current_template = get_settings('template');
1970 $current_stylesheet = get_settings('stylesheet');
1971 $current_theme = 'WordPress Default';
1974 foreach ($theme_names as $theme_name) {
1975 if ( $themes[$theme_name]['Stylesheet'] == $current_stylesheet &&
1976 $themes[$theme_name]['Template'] == $current_template ) {
1977 $current_theme = $themes[$theme_name]['Name'];
1983 return $current_theme;
1986 function get_query_template($type) {
1988 if ( file_exists(TEMPLATEPATH . "/{$type}.php") )
1989 $template = TEMPLATEPATH . "/{$type}.php";
1991 return apply_filters("{$type}_template", $template);
1994 function get_404_template() {
1995 return get_query_template('404');
1998 function get_archive_template() {
1999 return get_query_template('archive');
2002 function get_author_template() {
2003 return get_query_template('author');
2006 function get_category_template() {
2008 if ( file_exists(TEMPLATEPATH . "/category-" . get_query_var('cat') . '.php') )
2009 $template = TEMPLATEPATH . "/category-" . get_query_var('cat') . '.php';
2010 else if ( file_exists(TEMPLATEPATH . "/category.php") )
2011 $template = TEMPLATEPATH . "/category.php";
2013 return apply_filters('category_template', $template);
2016 function get_date_template() {
2017 return get_query_template('date');
2020 function get_home_template() {
2023 if ( file_exists(TEMPLATEPATH . "/home.php") )
2024 $template = TEMPLATEPATH . "/home.php";
2025 else if ( file_exists(TEMPLATEPATH . "/index.php") )
2026 $template = TEMPLATEPATH . "/index.php";
2028 return apply_filters('home_template', $template);
2031 function get_page_template() {
2034 $id = (int) $wp_query->post->ID;
2035 $template = get_post_meta($id, '_wp_page_template', true);
2037 if ( 'default' == $template )
2040 if ( ! empty($template) && file_exists(TEMPLATEPATH . "/$template") )
2041 $template = TEMPLATEPATH . "/$template";
2042 else if ( file_exists(TEMPLATEPATH . "/page.php") )
2043 $template = TEMPLATEPATH . "/page.php";
2047 return apply_filters('page_template', $template);
2050 function get_paged_template() {
2051 return get_query_template('paged');
2054 function get_search_template() {
2055 return get_query_template('search');
2058 function get_single_template() {
2059 return get_query_template('single');
2062 function get_attachment_template() {
2064 $type = explode('/', $posts[0]->post_mime_type);
2065 if ( $template = get_query_template($type[0]) )
2067 elseif ( $template = get_query_template($type[1]) )
2069 elseif ( $template = get_query_template("$type[0]_$type[1]") )
2072 return get_query_template('attachment');
2075 function get_comments_popup_template() {
2076 if ( file_exists( TEMPLATEPATH . '/comments-popup.php') )
2077 $template = TEMPLATEPATH . '/comments-popup.php';
2079 $template = get_theme_root() . '/default/comments-popup.php';
2081 return apply_filters('comments_popup_template', $template);
2084 // Borrowed from the PHP Manual user notes. Convert entities, while
2085 // preserving already-encoded entities:
2086 function htmlentities2($myHTML) {
2087 $translation_table=get_html_translation_table (HTML_ENTITIES,ENT_QUOTES);
2088 $translation_table[chr(38)] = '&';
2089 return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&" , strtr($myHTML, $translation_table));
2093 function is_plugin_page() {
2094 global $plugin_page;
2096 if ( isset($plugin_page) )
2103 add_query_arg: Returns a modified querystring by adding
2104 a single key & value or an associative array.
2105 Setting a key value to emptystring removes the key.
2106 Omitting oldquery_or_uri uses the $_SERVER value.
2109 add_query_arg(newkey, newvalue, oldquery_or_uri) or
2110 add_query_arg(associative_array, oldquery_or_uri)
2112 function add_query_arg() {
2114 if ( is_array(func_get_arg(0)) ) {
2115 if ( @func_num_args() < 2 )
2116 $uri = $_SERVER['REQUEST_URI'];
2118 $uri = @func_get_arg(1);
2120 if ( @func_num_args() < 3 )
2121 $uri = $_SERVER['REQUEST_URI'];
2123 $uri = @func_get_arg(2);
2126 if ( $frag = strstr($uri, '#') )
2127 $uri = substr($uri, 0, -strlen($frag));
2131 if ( preg_match('|^https?://|i', $uri, $matches) ) {
2132 $protocol = $matches[0];
2133 $uri = substr($uri, strlen($protocol));
2138 if ( strstr($uri, '?') ) {
2139 $parts = explode('?', $uri, 2);
2140 if ( 1 == count($parts) ) {
2144 $base = $parts[0] . '?';
2147 } else if ( !empty($protocol) || strstr($uri, '/') ) {
2155 parse_str($query, $qs);
2156 if ( is_array(func_get_arg(0)) ) {
2157 $kayvees = func_get_arg(0);
2158 $qs = array_merge($qs, $kayvees);
2160 $qs[func_get_arg(0)] = func_get_arg(1);
2163 foreach($qs as $k => $v) {
2170 $ret = $protocol . $base . $ret . $frag;
2171 return trim($ret, '?');
2174 function remove_query_arg($key, $query) {
2175 return add_query_arg($key, '', $query);
2178 function load_template($_template_file) {
2179 global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query,
2182 if ( is_array($wp_query->query_vars) )
2183 extract($wp_query->query_vars, EXTR_SKIP);
2185 require_once($_template_file);
2188 function add_magic_quotes($array) {
2191 foreach ($array as $k => $v) {
2192 if ( is_array($v) ) {
2193 $array[$k] = add_magic_quotes($v);
2195 $array[$k] = $wpdb->escape($v);
2201 function wp_remote_fopen( $uri ) {
2203 $parsed_url = @parse_url($uri);
2205 if ( !$parsed_url || !is_array($parsed_url) )
2208 if ( !isset($parsed_url['scheme']) || !in_array($parsed_url['scheme'], array('http','https')) )
2209 $uri = 'http://' . $uri;
2211 if ( ini_get('allow_url_fopen') ) {
2212 $fp = @fopen( $uri, 'r' );
2216 //stream_set_timeout($fp, $timeout); // Requires php 4.3
2218 while( $remote_read = fread($fp, 4096) )
2219 $linea .= $remote_read;
2222 } else if ( function_exists('curl_init') ) {
2223 $handle = curl_init();
2224 curl_setopt ($handle, CURLOPT_URL, $uri);
2225 curl_setopt ($handle, CURLOPT_CONNECTTIMEOUT, 1);
2226 curl_setopt ($handle, CURLOPT_RETURNTRANSFER, 1);
2227 curl_setopt ($handle, CURLOPT_TIMEOUT, $timeout);
2228 $buffer = curl_exec($handle);
2229 curl_close($handle);
2236 function wp($query_vars = '') {
2239 $wp->main($query_vars);
2242 function status_header( $header ) {
2243 if ( 200 == $header )
2245 elseif ( 301 == $header )
2246 $text = 'Moved Permanently';
2247 elseif ( 302 == $header )
2248 $text = 'Moved Temporarily';
2249 elseif ( 304 == $header )
2250 $text = 'Not Modified';
2251 elseif ( 404 == $header )
2252 $text = 'Not Found';
2253 elseif ( 410 == $header )
2256 if ( version_compare(phpversion(), '4.3.0', '>=') )
2257 @header("HTTP/1.1 $header $text", true, $header);
2259 @header("HTTP/1.1 $header $text");
2262 function nocache_headers() {
2263 @ header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
2264 @ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
2265 @ header('Cache-Control: no-cache, must-revalidate, max-age=0');
2266 @ header('Pragma: no-cache');
2269 function get_usermeta( $user_id, $meta_key = '') {
2271 $user_id = (int) $user_id;
2273 if ( !empty($meta_key) ) {
2274 $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
2275 $metas = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key'");
2277 $metas = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id'");
2280 if ( empty($metas) ) {
2281 if ( empty($meta_key) )
2287 foreach ($metas as $index => $meta) {
2288 @ $value = unserialize($meta->meta_value);
2289 if ( $value === FALSE )
2290 $value = $meta->meta_value;
2295 if ( count($values) == 1 )
2301 function update_usermeta( $user_id, $meta_key, $meta_value ) {
2303 if ( !is_numeric( $user_id ) )
2305 $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
2307 // FIXME: usermeta data is assumed to be already escaped
2308 if ( is_string($meta_value) )
2309 $meta_value = stripslashes($meta_value);
2310 $meta_value = maybe_serialize($meta_value);
2311 $meta_value = $wpdb->escape($meta_value);
2313 if (empty($meta_value)) {
2314 delete_usermeta($user_id, $meta_key);
2317 $cur = $wpdb->get_row("SELECT * FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key'");
2319 $wpdb->query("INSERT INTO $wpdb->usermeta ( user_id, meta_key, meta_value )
2321 ( '$user_id', '$meta_key', '$meta_value' )");
2322 } else if ( $cur->meta_value != $meta_value ) {
2323 $wpdb->query("UPDATE $wpdb->usermeta SET meta_value = '$meta_value' WHERE user_id = '$user_id' AND meta_key = '$meta_key'");
2328 $user = get_userdata($user_id);
2329 wp_cache_delete($user_id, 'users');
2330 wp_cache_delete($user->user_login, 'userlogins');
2335 function delete_usermeta( $user_id, $meta_key, $meta_value = '' ) {
2337 if ( !is_numeric( $user_id ) )
2339 $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
2341 if ( is_array($meta_value) || is_object($meta_value) )
2342 $meta_value = serialize($meta_value);
2343 $meta_value = trim( $meta_value );
2345 if ( ! empty($meta_value) )
2346 $wpdb->query("DELETE FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key' AND meta_value = '$meta_value'");
2348 $wpdb->query("DELETE FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key'");
2350 $user = get_userdata($user_id);
2351 wp_cache_delete($user_id, 'users');
2352 wp_cache_delete($user->user_login, 'userlogins');
2357 function register_activation_hook($file, $function) {
2358 $file = plugin_basename($file);
2360 add_action('activate_' . $file, $function);
2363 function register_deactivation_hook($file, $function) {
2364 $file = plugin_basename($file);
2366 add_action('deactivate_' . $file, $function);
2369 function plugin_basename($file) {
2370 $file = preg_replace('|\\\\+|', '\\\\', $file);
2371 $file = preg_replace('/^.*wp-content[\\\\\/]plugins[\\\\\/]/', '', $file);
2375 function get_num_queries() {
2377 return $wpdb->num_queries;
2380 function wp_nonce_url($actionurl, $action = -1) {
2381 return wp_specialchars(add_query_arg('_wpnonce', wp_create_nonce($action), $actionurl));
2384 function wp_nonce_field($action = -1, $name = "_wpnonce", $referer = true) {
2385 $name = attribute_escape($name);
2386 echo '<input type="hidden" name="' . $name . '" value="' . wp_create_nonce($action) . '" />';
2391 function wp_referer_field() {
2392 $ref = attribute_escape(stripslashes($_SERVER['REQUEST_URI']));
2393 echo '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />';
2394 if ( wp_get_original_referer() ) {
2395 $original_ref = attribute_escape(stripslashes(wp_get_original_referer()));
2396 echo '<input type="hidden" name="_wp_original_http_referer" value="'. $original_ref . '" />';
2400 function wp_original_referer_field() {
2401 echo '<input type="hidden" name="_wp_original_http_referer" value="' . attribute_escape(stripslashes($_SERVER['REQUEST_URI'])) . '" />';
2404 function wp_get_referer() {
2405 foreach ( array($_REQUEST['_wp_http_referer'], $_SERVER['HTTP_REFERER']) as $ref )
2411 function wp_get_original_referer() {
2412 if ( !empty($_REQUEST['_wp_original_http_referer']) )
2413 return $_REQUEST['_wp_original_http_referer'];
2417 function wp_explain_nonce($action) {
2418 if ( $action !== -1 && preg_match('/([a-z]+)-([a-z]+)(_(.+))?/', $action, $matches) ) {
2419 $verb = $matches[1];
2420 $noun = $matches[2];
2423 $trans['update']['attachment'] = array(__('Are you sure you want to edit this attachment: "%s"?'), 'get_the_title');
2425 $trans['add']['category'] = array(__('Are you sure you want to add this category?'), false);
2426 $trans['delete']['category'] = array(__('Are you sure you want to delete this category: "%s"?'), 'get_catname');
2427 $trans['update']['category'] = array(__('Are you sure you want to edit this category: "%s"?'), 'get_catname');
2429 $trans['delete']['comment'] = array(__('Are you sure you want to delete this comment: "%s"?'), 'use_id');
2430 $trans['unapprove']['comment'] = array(__('Are you sure you want to unapprove this comment: "%s"?'), 'use_id');
2431 $trans['approve']['comment'] = array(__('Are you sure you want to approve this comment: "%s"?'), 'use_id');
2432 $trans['update']['comment'] = array(__('Are you sure you want to edit this comment: "%s"?'), 'use_id');
2433 $trans['bulk']['comments'] = array(__('Are you sure you want to bulk modify comments?'), false);
2434 $trans['moderate']['comments'] = array(__('Are you sure you want to moderate comments?'), false);
2436 $trans['add']['bookmark'] = array(__('Are you sure you want to add this bookmark?'), false);
2437 $trans['delete']['bookmark'] = array(__('Are you sure you want to delete this bookmark: "%s"?'), 'use_id');
2438 $trans['update']['bookmark'] = array(__('Are you sure you want to edit this bookmark: "%s"?'), 'use_id');
2439 $trans['bulk']['bookmarks'] = array(__('Are you sure you want to bulk modify bookmarks?'), false);
2441 $trans['add']['page'] = array(__('Are you sure you want to add this page?'), false);
2442 $trans['delete']['page'] = array(__('Are you sure you want to delete this page: "%s"?'), 'get_the_title');
2443 $trans['update']['page'] = array(__('Are you sure you want to edit this page: "%s"?'), 'get_the_title');
2445 $trans['edit']['plugin'] = array(__('Are you sure you want to edit this plugin file: "%s"?'), 'use_id');
2446 $trans['activate']['plugin'] = array(__('Are you sure you want to activate this plugin: "%s"?'), 'use_id');
2447 $trans['deactivate']['plugin'] = array(__('Are you sure you want to deactivate this plugin: "%s"?'), 'use_id');
2449 $trans['add']['post'] = array(__('Are you sure you want to add this post?'), false);
2450 $trans['delete']['post'] = array(__('Are you sure you want to delete this post: "%s"?'), 'get_the_title');
2451 $trans['update']['post'] = array(__('Are you sure you want to edit this post: "%s"?'), 'get_the_title');
2453 $trans['add']['user'] = array(__('Are you sure you want to add this user?'), false);
2454 $trans['delete']['users'] = array(__('Are you sure you want to delete users?'), false);
2455 $trans['bulk']['users'] = array(__('Are you sure you want to bulk modify users?'), false);
2456 $trans['update']['user'] = array(__('Are you sure you want to edit this user: "%s"?'), 'get_author_name');
2457 $trans['update']['profile'] = array(__('Are you sure you want to modify the profile for: "%s"?'), 'get_author_name');
2459 $trans['update']['options'] = array(__('Are you sure you want to edit your settings?'), false);
2460 $trans['update']['permalink'] = array(__('Are you sure you want to change your permalink structure to: %s?'), 'use_id');
2461 $trans['edit']['file'] = array(__('Are you sure you want to edit this file: "%s"?'), 'use_id');
2462 $trans['edit']['theme'] = array(__('Are you sure you want to edit this theme file: "%s"?'), 'use_id');
2463 $trans['switch']['theme'] = array(__('Are you sure you want to switch to this theme: "%s"?'), 'use_id');
2465 if ( isset($trans[$verb][$noun]) ) {
2466 if ( !empty($trans[$verb][$noun][1]) ) {
2467 $lookup = $trans[$verb][$noun][1];
2468 $object = $matches[4];
2469 if ( 'use_id' != $lookup )
2470 $object = call_user_func($lookup, $object);
2471 return sprintf($trans[$verb][$noun][0], $object);
2473 return $trans[$verb][$noun][0];
2478 return __('Are you sure you want to do this?');
2481 function wp_nonce_ays($action) {
2482 global $pagenow, $menu, $submenu, $parent_file, $submenu_file;
2484 $adminurl = get_settings('siteurl') . '/wp-admin';
2485 if ( wp_get_referer() )
2486 $adminurl = attribute_escape(stripslashes(wp_get_referer()));
2488 $title = __('WordPress Confirmation');
2489 // Remove extra layer of slashes.
2490 $_POST = stripslashes_deep($_POST );
2492 $q = http_build_query($_POST);
2493 $q = explode( ini_get('arg_separator.output'), $q);
2494 $html .= "\t<form method='post' action='$pagenow'>\n";
2495 foreach ( (array) $q as $a ) {
2496 $v = substr(strstr($a, '='), 1);
2497 $k = substr($a, 0, -(strlen($v)+1));
2498 $html .= "\t\t<input type='hidden' name='" . attribute_escape( urldecode($k)) . "' value='" . attribute_escape( urldecode($v)) . "' />\n";
2500 $html .= "\t\t<input type='hidden' name='_wpnonce' value='" . wp_create_nonce($action) . "' />\n";
2501 $html .= "\t\t<div id='message' class='confirm fade'>\n\t\t<p>" . wp_specialchars(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";
2503 $html .= "\t<div id='message' class='confirm fade'>\n\t<p>" . wp_specialchars(wp_explain_nonce($action)) . "</p>\n\t<p><a href='$adminurl'>" . __('No') . "</a> <a href='" . clean_url(add_query_arg('_wpnonce', wp_create_nonce($action), $_SERVER['REQUEST_URI'])) . "'>" . __('Yes') . "</a></p>\n\t</div>\n";
2505 $html .= "</body>\n</html>";
2506 wp_die($html, $title);
2509 function wp_die($message, $title = '') {
2510 header('Content-Type: text/html; charset=utf-8');
2512 if ( empty($title) )
2513 $title = __('WordPress › Error');
2515 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2516 <html xmlns="http://www.w3.org/1999/xhtml">
2518 <title><?php echo $title ?></title>
2519 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
2520 <style media="screen" type="text/css">
2528 font-family: Georgia, "Times New Roman", Times, serif;
2537 font-weight: lighter;
2546 padding-bottom: 2px;
2550 padding: 5px 5px 5px 20px;
2559 <h1 id="logo"><img alt="WordPress" src="<?php echo get_settings('siteurl'); ?>/wp-admin/images/wordpress-logo.png" /></h1>
2560 <p><?php echo $message; ?></p>