]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/functions.php
Wordpress 2.0.11-scripts
[autoinstalls/wordpress.git] / wp-includes / functions.php
1 <?php
2
3 require_once(dirname(__FILE__).'/functions-compat.php');
4
5 if ( !function_exists('_') ) {
6         function _($string) {
7                 return $string;
8         }
9 }
10
11 function get_profile($field, $user = false) {
12         global $wpdb;
13         if ( !$user )
14                 $user = $wpdb->escape($_COOKIE[USER_COOKIE]);
15         return $wpdb->get_var("SELECT $field FROM $wpdb->users WHERE user_login = '$user'");
16 }
17
18 function mysql2date($dateformatstring, $mysqlstring, $translate = true) {
19         global $month, $weekday, $month_abbrev, $weekday_abbrev;
20         $m = $mysqlstring;
21         if ( empty($m) ) {
22                 return false;
23         }
24         $i = mktime(substr($m,11,2),substr($m,14,2),substr($m,17,2),substr($m,5,2),substr($m,8,2),substr($m,0,4));
25         
26         if ( -1 == $i || false == $i )
27                 $i = 0;
28
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);
39
40                 $dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring)-1);
41         }
42         $j = @date($dateformatstring, $i);
43         if ( !$j ) {
44         // for debug purposes
45         //      echo $i." ".$mysqlstring;
46         }
47         return $j;
48 }
49
50 function current_time($type, $gmt = 0) {
51         switch ($type) {
52                 case 'mysql':
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)));
55                         return $d;
56                         break;
57                 case 'timestamp':
58                         if ( $gmt ) $d = time();
59                         else $d = time() + (get_settings('gmt_offset') * 3600);
60                         return $d;
61                         break;
62         }
63 }
64
65 function date_i18n($dateformatstring, $unixtimestamp) {
66         global $month, $weekday, $month_abbrev, $weekday_abbrev;
67         $i = $unixtimestamp;
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);
79         }
80         $j = @date($dateformatstring, $i);
81         return $j;
82         }
83
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);
90         $i = 86400;
91
92         if ( $weekday < get_settings('start_of_week') )
93                 $weekday = 7 - (get_settings('start_of_week') - $weekday);
94
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);
99
100                 $day = $day - 86400;
101                 $i = 0;
102         }
103         $week['start'] = $day + 86400 - $i;
104         // $week['end'] = $day - $i + 691199;
105         $week['end'] = $week['start'] + 604799;
106         return $week;
107 }
108
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)) {
116                         case 'gmt':
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");
118                                 break;
119                         case 'blog':
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");
121                                 break;
122                         case 'server':
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");
124                                 break;
125                 }
126                 $cache_lastpostdate[$timezone] = $lastpostdate;
127         } else {
128                 $lastpostdate = $cache_lastpostdate[$timezone];
129         }
130         return $lastpostdate;
131 }
132
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)) {
140                         case 'gmt':
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");
142                                 break;
143                         case 'blog':
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");
145                                 break;
146                         case 'server':
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");
148                                 break;
149                 }
150                 $lastpostdate = get_lastpostdate($timezone);
151                 if ( $lastpostdate > $lastpostmodified ) {
152                         $lastpostmodified = $lastpostdate;
153                 }
154                 $cache_lastpostmodified[$timezone] = $lastpostmodified;
155         } else {
156                 $lastpostmodified = $cache_lastpostmodified[$timezone];
157         }
158         return $lastpostmodified;
159 }
160
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);
165         } else {
166                 $userdata = $cache_userdata[$user_login];
167         }
168         return (md5($user_pass) == $userdata->user_pass);
169 }
170
171
172 function get_usernumposts($userid) {
173         global $wpdb;
174         $userid = (int) $userid;
175         return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '$userid' AND post_status = 'publish'");
176 }
177
178
179 // examine a url (supposedly from this blog) and try to
180 // determine the post ID it represents.
181 function url_to_postid($url) {
182         global $wp_rewrite;
183
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;
188
189         // Check to see if we are using rewrite rules
190         $rewrite = $wp_rewrite->wp_rewrite_rules();
191
192         // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options
193         if ( empty($rewrite) )
194                 return 0;
195
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
200
201         // Get rid of the #anchor
202         $url_split = explode('#', $url);
203         $url = $url_split[0];
204
205         // Get rid of URI ?query=string
206         $url_split = explode('?', $url);
207         $url = $url_split[0];
208
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);
212
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);
216
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);
220
221         if ( false !== strpos($url, get_settings('home')) ) {
222                 // Chop off http://domain.com
223                 $url = str_replace(get_settings('home'), '', $url);
224         } else {
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);
229         }
230
231         // Trim leading and lagging slashes
232         $url = trim($url, '/');
233
234         $request = $url;
235
236         // Done with cleanup
237
238         // Look for matches.
239         $request_match = $request;
240         foreach ($rewrite as $match => $query) {
241                 // If the requesting file is the anchor of the match, prepend it
242                 // to the path info.
243                 if ( (! empty($url)) && (strpos($match, $url) === 0) ) {
244                         $request_match = $url . '/' . $request;
245                 }
246
247                 if ( preg_match("!^$match!", $request_match, $matches) ) {
248                         // Got a match.
249                         // Trim the query of everything up to the '?'.
250                         $query = preg_replace("!^.+\?!", '', $query);
251
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;
257                         else
258                                 return 0;
259                 }
260         }
261         return 0;
262 }
263
264
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) )
268                         return $gm;
269         return $original;
270 }
271
272 function maybe_serialize($data) {
273         if ( is_string($data) )
274                 $data = trim($data);
275         elseif ( is_array($data) || is_object($data) )
276                 return serialize($data);
277         if ( is_serialized($data) )
278                 return serialize($data);
279         return $data;
280 }
281
282 function is_serialized($data) {
283         if ( !is_string($data) ) // if it isn't a string, it isn't serialized
284                 return false;
285         $data = trim($data);
286         if ( preg_match("/^[adobis]:[0-9]+:.*[;}]/si",$data) ) // this should fetch all legitimately serialized data
287                 return true;
288         return false;
289 }
290
291 function is_serialized_string($data) {
292         if ( !is_string($data) ) // if it isn't a string, it isn't a serialized string
293                 return false;
294         $data = trim($data);
295         if ( preg_match("/^s:[0-9]+:.*[;}]/si",$data) ) // this should fetch all serialized strings
296                 return true;
297         return false;
298 }
299
300 /* Options functions */
301
302 // expects $setting to already be SQL-escaped
303 function get_settings($setting) {
304         global $wpdb;
305
306         $value = wp_cache_get($setting, 'options');
307
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();
314
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');
318                 } else {
319                         return false;
320                 }
321         }
322
323         // If home is not set use siteurl.
324         if ( 'home' == $setting && '' == $value )
325                 return get_settings('siteurl');
326
327         if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting )
328                 $value = preg_replace('|/+$|', '', $value);
329
330         return apply_filters( 'option_' . $setting, maybe_unserialize($value) );
331 }
332
333 function get_option($option) {
334         return get_settings($option);
335 }
336
337 function get_user_option( $option, $user = 0 ) {
338         global $wpdb;
339         
340         if ( empty($user) )
341                 $user = wp_get_current_user();
342         else
343                 $user = get_userdata($user);
344
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};
349         else // Blog global
350                 return get_option( $option );
351 }
352
353 function form_option($option) {
354         echo attribute_escape( get_option($option));
355 }
356
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");
362         }
363         $wpdb->show_errors();
364
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);
376         }
377         return apply_filters('all_options', $all_options);
378 }
379
380 // expects $option_name to NOT be SQL-escaped
381 function update_option($option_name, $newvalue) {
382         global $wpdb;
383
384         $safe_option_name = $wpdb->escape($option_name);
385
386         if ( is_string($newvalue) )
387                 $newvalue = trim($newvalue);
388
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 ) {
392                 return false;
393         }
394
395         if ( false === $oldvalue ) {
396                 add_option($option_name, $newvalue);
397                 return true;
398         }
399
400         $_newvalue = $newvalue;
401         $newvalue = maybe_serialize($newvalue);
402
403         wp_cache_set($option_name, $newvalue, 'options');
404
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));
410                 return true;
411         }
412         return false;
413 }
414
415 function update_user_option( $user_id, $option_name, $newvalue, $global = false ) {
416         global $wpdb;
417         if ( !$global )
418                 $option_name = $wpdb->prefix . $option_name;
419         return update_usermeta( $user_id, $option_name, $newvalue );
420 }
421
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') {
425         global $wpdb;
426
427         $safe_name = $wpdb->escape($name);
428
429         // Make sure the option doesn't already exist
430         if ( false !== get_option($safe_name) )
431                 return;
432
433         $value = maybe_serialize($value);
434
435         wp_cache_set($name, $value, 'options');
436
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')");
441
442         return;
443 }
444
445 function delete_option($name) {
446         global $wpdb;
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');
452         return true;
453 }
454
455 function add_post_meta($post_id, $key, $value, $unique = false) {
456         global $wpdb, $post_meta_cache;
457
458         $post_id = (int) $post_id;
459
460         if ( $unique ) {
461                 if ( $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key = '$key' AND post_id = '$post_id'") ) {
462                         return false;
463                 }
464         }
465
466         $post_meta_cache[$post_id][$key][] = $value;
467
468         $value = maybe_serialize($value);
469         $value = $wpdb->escape($value);
470
471         $wpdb->query("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value) VALUES ('$post_id','$key','$value')");
472
473         return true;
474 }
475
476 function delete_post_meta($post_id, $key, $value = '') {
477         global $wpdb, $post_meta_cache;
478
479         $post_id = (int) $post_id;
480
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'");
483         } else {
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'");
485         }
486
487         if ( !$meta_id )
488                 return false;
489
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]);
493         } else {
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]);
499         }
500
501         unset($post_meta_cache[$post_id][$key]);
502
503         return true;
504 }
505
506 function get_post_meta($post_id, $key, $single = false) {
507         global $wpdb, $post_meta_cache;
508
509         $post_id = (int) $post_id;
510
511         if ( isset($post_meta_cache[$post_id][$key]) ) {
512                 if ( $single ) {
513                         return maybe_unserialize( $post_meta_cache[$post_id][$key][0] );
514                 } else {
515                         return maybe_unserialize( $post_meta_cache[$post_id][$key] );
516                 }
517         }
518
519         $metalist = $wpdb->get_results("SELECT meta_value FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key'", ARRAY_N);
520
521         $values = array();
522         if ( $metalist ) {
523                 foreach ($metalist as $metarow) {
524                         $values[] = $metarow[0];
525                 }
526         }
527
528         if ( $single ) {
529                 if ( count($values) ) {
530                         $return = maybe_unserialize( $values[0] );
531                 } else {
532                         return '';
533                 }
534         } else {
535                 $return = $values;
536         }
537
538         return maybe_unserialize($return);
539 }
540
541 function update_post_meta($post_id, $key, $value, $prev_value = '') {
542         global $wpdb, $post_meta_cache;
543
544         $post_id = (int) $post_id;
545
546         $original_value = $value;
547         $value = maybe_serialize($value);
548         $value = $wpdb->escape($value);
549
550         $original_prev = $prev_value;
551         $prev_value = maybe_serialize($prev_value);
552         $prev_value = $wpdb->escape($prev_value);
553
554         if (! $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key = '$key' AND post_id = '$post_id'") ) {
555                 return false;
556         }
557
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;
564         } else {
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;
571         }
572
573         return true;
574 }
575
576 // Deprecated.  Use get_post().
577 function get_postdata($postid) {
578         $post = &get_post($postid);
579
580         $postdata = array (
581                 'ID' => $post->ID,
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
595         );
596
597         return $postdata;
598 }
599
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;
604
605         if ( empty($post) ) {
606                 if ( isset($GLOBALS['post']) )
607                         $_post = & $GLOBALS['post'];
608                 else
609                         $_post = null;
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];
616         } else {
617                 $post = (int) $post;
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];
622                 else {
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;
628                 }
629         }
630
631         if ( defined(WP_IMPORTING) )
632                 unset($post_cache);
633
634         if ( $output == OBJECT ) {
635                 return $_post;
636         } elseif ( $output == ARRAY_A ) {
637                 return get_object_vars($_post);
638         } elseif ( $output == ARRAY_N ) {
639                 return array_values(get_object_vars($_post));
640         } else {
641                 return $_post;
642         }
643 }
644
645 function &get_children($post = 0, $output = OBJECT) {
646         global $post_cache, $wpdb;
647
648         if ( empty($post) ) {
649                 if ( isset($GLOBALS['post']) )
650                         $post_parent = & $GLOBALS['post']->post_parent;
651                 else
652                         return false;
653         } elseif ( is_object($post) ) {
654                 $post_parent = $post->post_parent;
655         } else {
656                 $post_parent = $post;
657         }
658
659         $post_parent = (int) $post_parent;
660
661         $query = "SELECT * FROM $wpdb->posts WHERE post_parent = $post_parent";
662
663         $children = $wpdb->get_results($query);
664
665         if ( $children ) {
666                 foreach ( $children as $key => $child ) {
667                         $post_cache[$child->ID] =& $children[$key];
668                         $kids[$child->ID] =& $children[$key];
669                 }
670         } else {
671                 return false;
672         }
673
674         if ( $output == OBJECT ) {
675                 return $kids;
676         } elseif ( $output == ARRAY_A ) {
677                 foreach ( $kids as $kid )
678                         $weeuns[$kid->ID] = get_object_vars($kids[$kid->ID]);
679                 return $weeuns;
680         } elseif ( $output == ARRAY_N ) {
681                 foreach ( $kids as $kid )
682                         $babes[$kid->ID] = array_values(get_object_vars($kids[$kid->ID]));
683                 return $babes;
684         } else {
685                 return $kids;
686         }
687 }
688
689 function set_page_path($page) {
690         $page->fullpath = '/' . $page->post_name;
691         $path = $page->fullpath;
692         $curpage = $page;
693         while ($curpage->post_parent != 0) {
694                 $curpage = get_page($curpage->post_parent);
695                 $path = '/' . $curpage->post_name . $path;
696         }
697         
698         $page->fullpath = $path;
699
700         return $page;
701 }
702
703 // Retrieves page data given a page ID or page object.
704 // Handles page caching.
705 function &get_page(&$page, $output = OBJECT) {
706         global $wpdb;
707
708         if ( empty($page) ) {
709                 if ( isset($GLOBALS['page']) ) {
710                         $_page = & $GLOBALS['page'];
711                         wp_cache_add($_page->ID, $_page, 'pages');
712                 } else {
713                         $_page = null;
714                 }
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');
719                 $_page = $page;
720         } else {
721                 $page = (int) $page;
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') ) {
728                         // Got it.
729                 } else {
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');
735                 }
736         }
737         
738         if (!isset($_page->fullpath)) {
739                 $_page = set_page_path($_page);
740                 wp_cache_replace($_page->cat_ID, $_page, 'pages');
741         }
742
743         if ( $output == OBJECT ) {
744                 return $_page;
745         } elseif ( $output == ARRAY_A ) {
746                 return get_object_vars($_page);
747         } elseif ( $output == ARRAY_N ) {
748                 return array_values(get_object_vars($_page));
749         } else {
750                 return $_page;
751         }
752 }
753
754 function set_category_path($cat) {
755         $cat->fullpath = '/' . $cat->category_nicename;
756         $path = $cat->fullpath;
757         $curcat = $cat;
758         while ($curcat->category_parent != 0) {
759                 $curcat = get_category($curcat->category_parent);
760                 $path = '/' . $curcat->category_nicename . $path;
761         }
762         
763         $cat->fullpath = $path;
764
765         return $cat;
766 }
767
768 // Retrieves category data given a category ID or category object.
769 // Handles category caching.
770 function &get_category(&$category, $output = OBJECT) {
771         global $wpdb;
772
773         if ( empty($category) )
774                 return null;
775
776         if ( is_object($category) ) {
777                 wp_cache_add($category->cat_ID, $category, 'category');
778                 $_category = $category;
779         } else {
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');
784                 }
785         }
786
787         $_category = apply_filters('get_category', $_category);
788
789         if ( !isset($_category->fullpath) ) {
790                 $_category = set_category_path($_category);
791                 wp_cache_replace($_category->cat_ID, $_category, 'category');   
792         }
793
794         if ( $output == OBJECT ) {
795                 return $_category;
796         } elseif ( $output == ARRAY_A ) {
797                 return get_object_vars($_category);
798         } elseif ( $output == ARRAY_N ) {
799                 return array_values(get_object_vars($_category));
800         } else {
801                 return $_category;
802         }
803 }
804
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;
809
810         if ( empty($comment) )
811                 return null;
812
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];
817         } else {
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;
822                 } else {
823                         $_comment = & $comment_cache[$comment];
824                 }
825         }
826
827         if ( $output == OBJECT ) {
828                 return $_comment;
829         } elseif ( $output == ARRAY_A ) {
830                 return get_object_vars($_comment);
831         } elseif ( $output == ARRAY_N ) {
832                 return array_values(get_object_vars($_comment));
833         } else {
834                 return $_comment;
835         }
836 }
837
838 function get_catname($cat_ID) {
839         $category = &get_category($cat_ID);
840         return $category->cat_name;
841 }
842
843 function get_all_category_ids() {
844         global $wpdb;
845         
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');
849         }
850         
851         return $cat_ids;
852 }
853
854 function get_all_page_ids() {
855         global $wpdb;
856         
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');
860         }
861         
862         return $page_ids;
863 }
864
865 function gzip_compression() {
866         if ( !get_settings('gzipcompression') ) return false;
867
868         if ( extension_loaded('zlib') ) {
869                 ob_start('ob_gzhandler');
870         }
871 }
872
873
874 // functions to count the page generation time (from phpBB2)
875 // ( or just any time between timer_start() and timer_stop() )
876
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];
882         $timeend = $mtime;
883         $timetotal = $timeend-$timestart;
884         $r = number_format($timetotal, $precision);
885         if ( $display )
886                 echo $r;
887         return $r;
888 }
889
890 function weblog_ping($server = '', $path = '') {
891         global $wp_version;
892         include_once (ABSPATH . WPINC . '/class-IXR.php');
893
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;
898
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);
904 }
905
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);
914                 }
915         }
916
917         return $post_id;
918 }
919
920 // Send a Trackback
921 function trackback($trackback_url, $title, $excerpt, $ID) {
922         global $wpdb, $wp_version;
923
924         if ( empty($trackback_url) )
925                 return;
926
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);
945 /*
946         $debug_file = 'trackback.log';
947         $fp = fopen($debug_file, 'a');
948         fwrite($fp, "\n*****\nRequest:\n\n$http_request\n\nResponse:\n\n");
949         while(!@feof($fs)) {
950                 fwrite($fp, @fgets($fs, 4096));
951         }
952         fwrite($fp, "\n\n");
953         fclose($fp);
954 */
955         @fclose($fs);
956
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'");
960 }
961
962 function make_url_footnote($content) {
963         preg_match_all('/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches);
964         $j = 0;
965         for ($i=0; $i<count($matches[0]); $i++) {
966                 $links_summary = (!$j) ? "\n" : $links_summary;
967                 $j++;
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;
975         }
976         $content = strip_tags($content);
977         $content .= $links_summary;
978         return $content;
979 }
980
981
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);
988         } else {
989                 $post_title = $post_default_title;
990         }
991         return $post_title;
992 }
993
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);
999         } else {
1000                 $post_category = $post_default_category;
1001         }
1002         return $post_category;
1003 }
1004
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);
1009         return $content;
1010 }
1011
1012 function debug_fopen($filename, $mode) {
1013         global $debug;
1014         if ( $debug == 1 ) {
1015                 $fp = fopen($filename, $mode);
1016                 return $fp;
1017         } else {
1018                 return false;
1019         }
1020 }
1021
1022 function debug_fwrite($fp, $string) {
1023         global $debug;
1024         if ( $debug == 1 ) {
1025                 fwrite($fp, $string);
1026         }
1027 }
1028
1029 function debug_fclose($fp) {
1030         global $debug;
1031         if ( $debug == 1 ) {
1032                 fclose($fp);
1033         }
1034 }
1035
1036 function spawn_pinger() {
1037         global $wpdb, $wp_version;
1038         $doping = false;
1039         if ( $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE TRIM(to_ping) != '' LIMIT 1") )
1040                 $doping = true;
1041
1042         if ( $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pingme' OR meta_key = '_encloseme' LIMIT 1") )
1043                 $doping = true;
1044
1045         if ( substr(php_sapi_name(), 0, 3) == 'cgi' )
1046                 return $doping;
1047
1048         if ( $doping ) {
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);
1052                 if ( $argyle )
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");
1054        }
1055 }
1056
1057 function do_enclose( $content, $post_ID ) {
1058         global $wp_version, $wpdb;
1059         include_once (ABSPATH . WPINC . '/class-IXR.php');
1060
1061         $log = debug_fopen(ABSPATH . '/enclosures.log', 'a');
1062         $post_links = array();
1063         debug_fwrite($log, 'BEGIN '.date('YmdHis', time())."\n");
1064
1065         $pung = get_enclosed( $post_ID );
1066
1067         $ltrs = '\w';
1068         $gunk = '/#~:.?+=&%@!\-';
1069         $punc = '.:?\-';
1070         $any = $ltrs . $gunk . $punc;
1071
1072         preg_match_all("{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp);
1073
1074         debug_fwrite($log, 'Post contents:');
1075         debug_fwrite($log, $content."\n");
1076
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;
1084                 endif;
1085         endforeach;
1086
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')" );
1097                                 }
1098                         }
1099                 }
1100         endforeach;
1101 }
1102
1103 function wp_get_http_headers( $url, $red = 1 ) {
1104         global $wp_version;
1105         @set_time_limit( 60 );
1106
1107         if ( $red > 5 )
1108            return false;
1109
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;
1115
1116         $head = "HEAD $file HTTP/1.1\r\nHOST: $host\r\nUser-Agent: WordPress/" . $wp_version . "\r\n\r\n";
1117
1118         $fp = @fsockopen($host, $parts['port'], $err_num, $err_msg, 3);
1119         if ( !$fp )
1120                 return false;
1121
1122         $response = '';
1123         fputs( $fp, $head );
1124         while ( !feof( $fp ) && strpos( $response, "\r\n\r\n" ) == false )
1125                 $response .= fgets( $fp, 2048 );
1126         fclose( $fp );
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];
1132         }
1133
1134         preg_match('/.*([0-9]{3}).*/', $response, $return);
1135         $headers['response'] = $return[1]; // HTTP response code eg 204, 200, 404
1136
1137     $code = $headers['response'];
1138     if ( ('302' == $code || '301' == $code) && isset($headers['location']) )
1139         return wp_get_http_headers( $headers['location'], ++$red );
1140
1141         return $headers;
1142 }
1143
1144 // Deprecated.  Use the new post loop.
1145 function start_wp() {
1146         global $wp_query, $post;
1147
1148         // Since the old style loop is being used, advance the query iterator here.
1149         $wp_query->next_post();
1150
1151         setup_postdata($post);
1152 }
1153
1154 // Setup global post data.
1155 function setup_postdata($post) {
1156         global $id, $postdata, $authordata, $day, $page, $pages, $multipage, $more, $numpages, $wp_query;
1157         global $pagenow;
1158
1159         $id = $post->ID;
1160
1161         $authordata = get_userdata($post->post_author);
1162
1163         $day = mysql2date('d.m.y', $post->post_date);
1164         $currentmonth = mysql2date('m', $post->post_date);
1165         $numpages = 1;
1166         $page = get_query_var('page');
1167         if ( !$page )
1168                 $page = 1;
1169         if ( is_single() || is_page() )
1170                 $more = 1;
1171         $content = $post->post_content;
1172         if ( preg_match('/<!--nextpage-->/', $content) ) {
1173                 if ( $page > 1 )
1174                         $more = 1;
1175                 $multipage = 1;
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);
1181         } else {
1182                 $pages[0] = $post->post_content;
1183                 $multipage = 0;
1184         }
1185         return true;
1186 }
1187
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;
1191
1192         if ( '' == $user_id )
1193                 $user = wp_get_current_user();
1194         else 
1195                 $user = new WP_User($user_id);
1196
1197         if ( 0 == $user->ID )
1198                 return;
1199
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;
1208 }
1209
1210 function is_new_day() {
1211         global $day, $previousday;
1212         if ( $day != $previousday ) {
1213                 return(1);
1214         } else {
1215                 return(0);
1216         }
1217 }
1218
1219 // Filters: these are the core of WP's plugin architecture
1220
1221 function merge_filters($tag) {
1222         global $wp_filter;
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]);
1227                         else
1228                                 $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], array());
1229                         $wp_filter[$tag][$priority] = array_unique($wp_filter[$tag][$priority]);
1230                 }
1231         }
1232
1233         if ( isset($wp_filter[$tag]) )
1234                 uksort( $wp_filter[$tag], "strnatcasecmp" );
1235 }
1236
1237 function apply_filters($tag, $string) {
1238         global $wp_filter;
1239
1240         $args = array_slice(func_get_args(), 2);
1241
1242         merge_filters($tag);
1243
1244         if ( !isset($wp_filter[$tag]) ) {
1245                 return $string;
1246         }
1247         foreach ($wp_filter[$tag] as $priority => $functions) {
1248                 if ( !is_null($functions) ) {
1249                         foreach($functions as $function) {
1250
1251                                 $all_args = array_merge(array($string), $args);
1252                                 $function_name = $function['function'];
1253                                 $accepted_args = $function['accepted_args'];
1254
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 )
1260                                         $the_args = NULL;
1261                                 else
1262                                         $the_args = $all_args;
1263
1264                                 $string = call_user_func_array($function_name, $the_args);
1265                         }
1266                 }
1267         }
1268         return $string;
1269 }
1270
1271 function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
1272         global $wp_filter;
1273
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 ) {
1280                                 return true;
1281                         }
1282                 }
1283         }
1284
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);
1287         return true;
1288 }
1289
1290 function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
1291         global $wp_filter;
1292
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;
1299                         }
1300                 }
1301                 $wp_filter[$tag]["$priority"] = $new_function_list;
1302         }
1303         return true;
1304 }
1305
1306 // The *_action functions are just aliases for the *_filter functions, they take special strings instead of generic content
1307
1308 function do_action($tag, $arg = '') {
1309         global $wp_filter;
1310         $extra_args = array_slice(func_get_args(), 2);
1311         if ( is_array($arg) )
1312                 $args = array_merge($arg, $extra_args);
1313         else
1314                 $args = array_merge(array($arg), $extra_args);
1315
1316         merge_filters($tag);
1317
1318         if ( !isset($wp_filter[$tag]) ) {
1319                 return;
1320         }
1321         foreach ($wp_filter[$tag] as $priority => $functions) {
1322                 if ( !is_null($functions) ) {
1323                         foreach($functions as $function) {
1324
1325                                 $function_name = $function['function'];
1326                                 $accepted_args = $function['accepted_args'];
1327
1328                                 if ( $accepted_args == 1 ) {
1329                                         if ( is_array($arg) )
1330                                                 $the_args = $arg;
1331                                         else
1332                                                 $the_args = array($arg);
1333                                 } elseif ( $accepted_args > 1 ) {
1334                                         $the_args = array_slice($args, 0, $accepted_args);
1335                                 } elseif ( $accepted_args == 0 ) {
1336                                         $the_args = NULL;
1337                                 } else {
1338                                         $the_args = $args;
1339                                 }
1340
1341                                 $string = call_user_func_array($function_name, $the_args);
1342                         }
1343                 }
1344         }
1345 }
1346
1347 function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
1348         add_filter($tag, $function_to_add, $priority, $accepted_args);
1349 }
1350
1351 function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
1352         remove_filter($tag, $function_to_remove, $priority, $accepted_args);
1353 }
1354
1355 function get_page_uri($page_id) {
1356         $page = get_page($page_id);
1357         $uri = urldecode($page->post_name);
1358
1359         // A page cannot be it's own parent.
1360         if ( $page->post_parent == $page->ID )
1361                 return $uri;
1362
1363         while ($page->post_parent != 0) {
1364                 $page = get_page($page->post_parent);
1365                 $uri = urldecode($page->post_name) . "/" . $uri;
1366         }
1367
1368         return $uri;
1369 }
1370
1371 function get_posts($args) {
1372         global $wpdb;
1373         parse_str($args, $r);
1374         if ( !isset($r['numberposts']) )
1375                 $r['numberposts'] = 5;
1376         if ( !isset($r['offset']) )
1377                 $r['offset'] = 0;
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';
1384
1385         $now = current_time('mysql');
1386
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'] );
1393
1394         update_post_caches($posts);
1395
1396         return $posts;
1397 }
1398
1399 function &query_posts($query) {
1400         global $wp_query;
1401         return $wp_query->query($query);
1402 }
1403
1404 function update_post_cache(&$posts) {
1405         global $post_cache;
1406
1407         if ( !$posts )
1408                 return;
1409
1410         for ($i = 0; $i < count($posts); $i++) {
1411                 $post_cache[$posts[$i]->ID] = &$posts[$i];
1412         }
1413 }
1414
1415 function clean_post_cache($id) {
1416         global $post_cache;
1417
1418         if ( isset( $post_cache[$id] ) )
1419                 unset( $post_cache[$id] );
1420 }
1421
1422 function update_page_cache(&$pages) {
1423         global $page_cache;
1424
1425         if ( !$pages )
1426                 return;
1427
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');
1431         }
1432 }
1433
1434
1435 function clean_page_cache($id) {
1436         global $page_cache;
1437
1438         if ( isset( $page_cache[$id] ) )
1439                 unset( $page_cache[$id] );
1440 }
1441
1442 function update_post_category_cache($post_ids) {
1443         global $wpdb, $category_cache;
1444
1445         if ( empty($post_ids) )
1446                 return;
1447
1448         if ( is_array($post_ids) )
1449                 $post_ids = implode(',', $post_ids);
1450
1451         $dogs = $wpdb->get_results("SELECT post_id, category_id FROM $wpdb->post2cat WHERE post_id IN ($post_ids)");
1452
1453         if ( empty($dogs) )
1454                 return;
1455                 
1456         foreach ($dogs as $catt)
1457                 $category_cache[$catt->post_id][$catt->category_id] = &get_category($catt->category_id);
1458 }
1459
1460 function update_post_caches(&$posts) {
1461         global $post_cache, $category_cache, $comment_count_cache, $post_meta_cache;
1462         global $wpdb;
1463
1464         // No point in doing all this work if we didn't match any posts.
1465         if ( !$posts )
1466                 return;
1467
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;
1473         }
1474
1475         $post_id_list = implode(',', $post_id_array);
1476
1477         update_post_category_cache($post_id_list);
1478
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'];
1487
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();
1493
1494                         // Add a value to the current pid/key:
1495                         $post_meta_cache[$mpid][$mkey][] = $mval;
1496                 }
1497         }
1498 }
1499
1500 function update_category_cache() {
1501         return true;
1502 }
1503
1504 function wp_head() {
1505         do_action('wp_head');
1506 }
1507
1508 function wp_footer() {
1509         do_action('wp_footer');
1510 }
1511
1512 function is_single ($post = '') {
1513         global $wp_query;
1514
1515         if ( !$wp_query->is_single )
1516                 return false;
1517
1518         if ( empty( $post) )
1519                 return true;
1520
1521         $post_obj = $wp_query->get_queried_object();
1522
1523         if ( $post == $post_obj->ID )
1524                 return true;
1525         elseif ( $post == $post_obj->post_title )
1526                 return true;
1527         elseif ( $post == $post_obj->post_name )
1528                 return true;
1529
1530         return false;
1531 }
1532
1533 function is_page ($page = '') {
1534         global $wp_query;
1535
1536         if ( !$wp_query->is_page )
1537                 return false;
1538
1539         if ( empty($page) )
1540                 return true;
1541
1542         $page_obj = $wp_query->get_queried_object();
1543
1544         if ( $page == $page_obj->ID )
1545                 return true;
1546         elseif ( $page == $page_obj->post_title )
1547                 return true;
1548         else if ( $page == $page_obj->post_name )
1549                 return true;
1550
1551         return false;
1552 }
1553
1554 function is_attachment () {
1555         global $wp_query;
1556
1557         return $wp_query->is_attachment;
1558 }
1559
1560 function is_preview() {
1561         global $wp_query;
1562         
1563         return $wp_query->is_preview;
1564 }
1565
1566 function is_archive () {
1567         global $wp_query;
1568
1569         return $wp_query->is_archive;
1570 }
1571
1572 function is_date () {
1573         global $wp_query;
1574
1575         return $wp_query->is_date;
1576 }
1577
1578 function is_year () {
1579         global $wp_query;
1580
1581         return $wp_query->is_year;
1582 }
1583
1584 function is_month () {
1585         global $wp_query;
1586
1587         return $wp_query->is_month;
1588 }
1589
1590 function is_day () {
1591         global $wp_query;
1592
1593         return $wp_query->is_day;
1594 }
1595
1596 function is_time () {
1597         global $wp_query;
1598
1599         return $wp_query->is_time;
1600 }
1601
1602 function is_author ($author = '') {
1603         global $wp_query;
1604
1605         if ( !$wp_query->is_author )
1606                 return false;
1607
1608         if ( empty($author) )
1609                 return true;
1610
1611         $author_obj = $wp_query->get_queried_object();
1612
1613         if ( $author == $author_obj->ID )
1614                 return true;
1615         elseif ( $author == $author_obj->nickname )
1616                 return true;
1617         elseif ( $author == $author_obj->user_nicename )
1618                 return true;
1619
1620         return false;
1621 }
1622
1623 function is_category ($category = '') {
1624         global $wp_query;
1625
1626         if ( !$wp_query->is_category )
1627                 return false;
1628
1629         if ( empty($category) )
1630                 return true;
1631
1632         $cat_obj = $wp_query->get_queried_object();
1633
1634         if ( $category == $cat_obj->cat_ID )
1635                 return true;
1636         else if ( $category == $cat_obj->cat_name )
1637                 return true;
1638         elseif ( $category == $cat_obj->category_nicename )
1639                 return true;
1640
1641         return false;
1642 }
1643
1644 function is_search () {
1645         global $wp_query;
1646
1647         return $wp_query->is_search;
1648 }
1649
1650 function is_feed () {
1651         global $wp_query;
1652
1653         return $wp_query->is_feed;
1654 }
1655
1656 function is_trackback () {
1657         global $wp_query;
1658
1659         return $wp_query->is_trackback;
1660 }
1661
1662 function is_admin () {
1663         global $wp_query;
1664
1665         return ( $wp_query->is_admin || strstr($_SERVER['REQUEST_URI'], 'wp-admin/') );
1666 }
1667
1668 function is_home () {
1669         global $wp_query;
1670
1671         return $wp_query->is_home;
1672 }
1673
1674 function is_404 () {
1675         global $wp_query;
1676
1677         return $wp_query->is_404;
1678 }
1679
1680 function is_comments_popup () {
1681         global $wp_query;
1682
1683         return $wp_query->is_comments_popup;
1684 }
1685
1686 function is_paged () {
1687         global $wp_query;
1688
1689         return $wp_query->is_paged;
1690 }
1691
1692 function in_the_loop() {
1693         global $wp_query;
1694
1695         return $wp_query->in_the_loop;
1696 }
1697
1698 function get_query_var($var) {
1699         global $wp_query;
1700
1701         return $wp_query->get($var);
1702 }
1703
1704 function have_posts() {
1705         global $wp_query;
1706
1707         return $wp_query->have_posts();
1708 }
1709
1710 function rewind_posts() {
1711         global $wp_query;
1712
1713         return $wp_query->rewind_posts();
1714 }
1715
1716 function the_post() {
1717         global $wp_query;
1718
1719         $wp_query->the_post();
1720 }
1721
1722 function get_theme_root() {
1723         return apply_filters('theme_root', ABSPATH . "wp-content/themes");
1724 }
1725
1726 function get_theme_root_uri() {
1727         return apply_filters('theme_root_uri', get_settings('siteurl') . "/wp-content/themes", get_settings('siteurl'));
1728 }
1729
1730 function get_stylesheet() {
1731         return apply_filters('stylesheet', get_settings('stylesheet'));
1732 }
1733
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);
1738 }
1739
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);
1744 }
1745
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);
1750 }
1751
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');
1757         }
1758         return apply_filters('template', get_settings('template'));
1759 }
1760
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);
1765 }
1766
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);
1771 }
1772
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]);
1783         else
1784                 $version ='';
1785         if ( preg_match("|Status:(.*)|i", $theme_data, $status) )
1786                 $status = trim($status[1]);
1787         else
1788                 $status = 'publish';
1789
1790         $description = wptexturize(trim($description[1]));
1791
1792         $name = $theme_name[1];
1793         $name = trim($name);
1794         $theme = $name;
1795
1796         if ( '' == $author_uri[1] ) {
1797                 $author = trim($author_name[1]);
1798         } else {
1799                 $author = '<a href="' . trim($author_uri[1]) . '" title="' . __('Visit author homepage') . '">' . trim($author_name[1]) . '</a>';
1800         }
1801
1802         return array('Name' => $name, 'Title' => $theme, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1], 'Status' => $status);
1803 }
1804
1805 function get_themes() {
1806         global $wp_themes;
1807         global $wp_broken_themes;
1808
1809         if ( isset($wp_themes) )
1810                 return $wp_themes;
1811
1812         $themes = array();
1813         $wp_broken_themes = array();
1814         $theme_root = get_theme_root();
1815         $theme_loc = str_replace(ABSPATH, '', $theme_root);
1816
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' ) {
1823                                         continue;
1824                                 }
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;
1831                                                 break;
1832                                         }
1833                                 }
1834                                 if ( !$found_stylesheet ) {
1835                                         $wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.'));
1836                                 }
1837                         }
1838                 }
1839         }
1840
1841         if ( !$themes_dir || !$theme_files ) {
1842                 return $themes;
1843         }
1844
1845         sort($theme_files);
1846
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.'));
1850                         continue;
1851                 }
1852
1853                 $theme_data = get_theme_data("$theme_root/$theme_file");
1854
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);
1862
1863                 foreach (array('png', 'gif', 'jpg', 'jpeg') as $ext) {
1864                         if (file_exists("$theme_root/$stylesheet/screenshot.$ext")) {
1865                                 $screenshot = "screenshot.$ext";
1866                                 break;
1867                         }
1868                 }
1869
1870                 if ( empty($name) ) {
1871                         $name = dirname($theme_file);
1872                         $title = $name;
1873                 }
1874
1875                 if ( empty($template) ) {
1876                         if ( file_exists(dirname("$theme_root/$theme_file/index.php")) ) {
1877                                 $template = dirname($theme_file);
1878                         } else {
1879                                 continue;
1880                         }
1881                 }
1882
1883                 $template = trim($template);
1884
1885                 if ( !file_exists("$theme_root/$template/index.php") ) {
1886                         $wp_broken_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => __('Template is missing.'));
1887                         continue;
1888                 }
1889
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";
1896                         }
1897                 }
1898
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";
1905                         }
1906                 }
1907
1908                 $template_dir = dirname($template_files[0]);
1909                 $stylesheet_dir = dirname($stylesheet_files[0]);
1910
1911                 if ( empty($template_dir) )
1912                         $template_dir = '/';
1913                 if ( empty($stylesheet_dir) )
1914                         $stylesheet_dir = '/';
1915
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
1924                                 // them aside.
1925                                 $suffix = $themes[$name]['Stylesheet'];
1926                                 $new_name = "$name/$suffix";
1927                                 $themes[$new_name] = $themes[$name];
1928                                 $themes[$new_name]['Name'] = $new_name;
1929                         } else {
1930                                 $name = "$name/$stylesheet";
1931                         }
1932                 }
1933
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);
1935         }
1936
1937         // Resolve theme dependencies.
1938         $theme_names = array_keys($themes);
1939
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'];
1946                                         break;
1947                                 }
1948                         }
1949                 }
1950         }
1951
1952         $wp_themes = $themes;
1953
1954         return $themes;
1955 }
1956
1957 function get_theme($theme) {
1958         $themes = get_themes();
1959
1960         if ( array_key_exists($theme, $themes) )
1961                 return $themes[$theme];
1962
1963         return NULL;
1964 }
1965
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';
1972
1973         if ( $themes ) {
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'];
1978                                 break;
1979                         }
1980                 }
1981         }
1982
1983         return $current_theme;
1984 }
1985
1986 function get_query_template($type) {
1987         $template = '';
1988         if ( file_exists(TEMPLATEPATH . "/{$type}.php") )
1989                 $template = TEMPLATEPATH . "/{$type}.php";
1990
1991         return apply_filters("{$type}_template", $template);
1992 }
1993
1994 function get_404_template() {
1995         return get_query_template('404');
1996 }
1997
1998 function get_archive_template() {
1999         return get_query_template('archive');
2000 }
2001
2002 function get_author_template() {
2003         return get_query_template('author');
2004 }
2005
2006 function get_category_template() {
2007         $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";
2012
2013         return apply_filters('category_template', $template);
2014 }
2015
2016 function get_date_template() {
2017         return get_query_template('date');
2018 }
2019
2020 function get_home_template() {
2021         $template = '';
2022
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";
2027
2028         return apply_filters('home_template', $template);
2029 }
2030
2031 function get_page_template() {
2032         global $wp_query;
2033
2034         $id = (int) $wp_query->post->ID;
2035         $template = get_post_meta($id, '_wp_page_template', true);
2036
2037         if ( 'default' == $template )
2038                 $template = '';
2039
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";
2044         else
2045                 $template = '';
2046
2047         return apply_filters('page_template', $template);
2048 }
2049
2050 function get_paged_template() {
2051         return get_query_template('paged');
2052 }
2053
2054 function get_search_template() {
2055         return get_query_template('search');
2056 }
2057
2058 function get_single_template() {
2059         return get_query_template('single');
2060 }
2061
2062 function get_attachment_template() {
2063         global $posts;
2064         $type = explode('/', $posts[0]->post_mime_type);
2065         if ( $template = get_query_template($type[0]) )
2066                 return $template;
2067         elseif ( $template = get_query_template($type[1]) )
2068                 return $template;
2069         elseif ( $template = get_query_template("$type[0]_$type[1]") )
2070                 return $template;
2071         else
2072                 return get_query_template('attachment');
2073 }
2074
2075 function get_comments_popup_template() {
2076         if ( file_exists( TEMPLATEPATH . '/comments-popup.php') )
2077                 $template = TEMPLATEPATH . '/comments-popup.php';
2078         else
2079                 $template = get_theme_root() . '/default/comments-popup.php';
2080
2081         return apply_filters('comments_popup_template', $template);
2082 }
2083
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};)/","&amp;" , strtr($myHTML, $translation_table));
2090 }
2091
2092
2093 function is_plugin_page() {
2094         global $plugin_page;
2095
2096         if ( isset($plugin_page) )
2097                 return true;
2098
2099         return false;
2100 }
2101
2102 /*
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.
2107
2108 Parameters:
2109 add_query_arg(newkey, newvalue, oldquery_or_uri) or
2110 add_query_arg(associative_array, oldquery_or_uri)
2111 */
2112 function add_query_arg() {
2113         $ret = '';
2114         if ( is_array(func_get_arg(0)) ) {
2115                 if ( @func_num_args() < 2 )
2116                         $uri = $_SERVER['REQUEST_URI'];
2117                 else
2118                         $uri = @func_get_arg(1);
2119         } else {
2120                 if ( @func_num_args() < 3 )
2121                         $uri = $_SERVER['REQUEST_URI'];
2122                 else
2123                         $uri = @func_get_arg(2);
2124         }
2125
2126         if ( $frag = strstr($uri, '#') )
2127                 $uri = substr($uri, 0, -strlen($frag));
2128         else
2129                 $frag = '';
2130
2131         if ( preg_match('|^https?://|i', $uri, $matches) ) {
2132                 $protocol = $matches[0];
2133                 $uri = substr($uri, strlen($protocol));
2134         } else {
2135                 $protocol = '';
2136         }
2137
2138         if ( strstr($uri, '?') ) {
2139                 $parts = explode('?', $uri, 2);
2140                 if ( 1 == count($parts) ) {
2141                         $base = '?';
2142                         $query = $parts[0];
2143                 } else {
2144                         $base = $parts[0] . '?';
2145                         $query = $parts[1];
2146                 }
2147         } else if ( !empty($protocol) || strstr($uri, '/') ) {
2148                 $base = $uri . '?';
2149                 $query = '';
2150         } else {
2151                 $base = '';
2152                 $query = $uri;
2153         }
2154
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);
2159         } else {
2160                 $qs[func_get_arg(0)] = func_get_arg(1);
2161         }
2162
2163         foreach($qs as $k => $v) {
2164                 if ( $v != '' ) {
2165                         if ( $ret != '' )
2166                                 $ret .= '&';
2167                         $ret .= "$k=$v";
2168                 }
2169         }
2170         $ret = $protocol . $base . $ret . $frag;
2171         return trim($ret, '?');
2172 }
2173
2174 function remove_query_arg($key, $query) {
2175         return add_query_arg($key, '', $query);
2176 }
2177
2178 function load_template($_template_file) {
2179         global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query,
2180                 $wp_rewrite, $wpdb;
2181
2182         if ( is_array($wp_query->query_vars) )
2183                 extract($wp_query->query_vars, EXTR_SKIP);
2184
2185         require_once($_template_file);
2186 }
2187
2188 function add_magic_quotes($array) {
2189         global $wpdb;
2190
2191         foreach ($array as $k => $v) {
2192                 if ( is_array($v) ) {
2193                         $array[$k] = add_magic_quotes($v);
2194                 } else {
2195                         $array[$k] = $wpdb->escape($v);
2196                 }
2197         }
2198         return $array;
2199 }
2200
2201 function wp_remote_fopen( $uri ) {
2202         $timeout = 10;
2203         $parsed_url = @parse_url($uri);
2204
2205         if ( !$parsed_url || !is_array($parsed_url) )
2206                 return false;
2207
2208         if ( !isset($parsed_url['scheme']) || !in_array($parsed_url['scheme'], array('http','https')) )
2209                 $uri = 'http://' . $uri;
2210
2211         if ( ini_get('allow_url_fopen') ) {
2212                 $fp = @fopen( $uri, 'r' );
2213                 if ( !$fp )
2214                         return false;
2215
2216                 //stream_set_timeout($fp, $timeout); // Requires php 4.3
2217                 $linea = '';
2218                 while( $remote_read = fread($fp, 4096) )
2219                         $linea .= $remote_read;
2220                 fclose($fp);
2221                 return $linea;
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);
2230                 return $buffer;
2231         } else {
2232                 return false;
2233         }
2234 }
2235
2236 function wp($query_vars = '') {
2237         global $wp;
2238         
2239         $wp->main($query_vars);
2240 }
2241
2242 function status_header( $header ) {
2243         if ( 200 == $header )
2244                 $text = 'OK';
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 )
2254                 $text = 'Gone';
2255
2256         if ( version_compare(phpversion(), '4.3.0', '>=') )
2257                 @header("HTTP/1.1 $header $text", true, $header);
2258         else
2259                 @header("HTTP/1.1 $header $text");
2260 }
2261
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');
2267 }
2268
2269 function get_usermeta( $user_id, $meta_key = '') {
2270         global $wpdb;
2271         $user_id = (int) $user_id;
2272
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'");
2276         } else {
2277                 $metas = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id'");
2278         }
2279
2280         if ( empty($metas) ) {
2281                 if ( empty($meta_key) )
2282                         return array();
2283                 else
2284                         return '';
2285         }
2286
2287         foreach ($metas as $index => $meta) {
2288                 @ $value = unserialize($meta->meta_value);
2289                 if ( $value === FALSE )
2290                         $value = $meta->meta_value;
2291
2292                 $values[] = $value;
2293         }
2294
2295         if ( count($values) == 1 )
2296                 return $values[0];
2297         else
2298                 return $values;
2299 }
2300
2301 function update_usermeta( $user_id, $meta_key, $meta_value ) {
2302         global $wpdb;
2303         if ( !is_numeric( $user_id ) )
2304                 return false;
2305         $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
2306
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);
2312         
2313         if (empty($meta_value)) {
2314                 delete_usermeta($user_id, $meta_key);
2315         }
2316
2317         $cur = $wpdb->get_row("SELECT * FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key'");
2318         if ( !$cur ) {
2319                 $wpdb->query("INSERT INTO $wpdb->usermeta ( user_id, meta_key, meta_value )
2320                 VALUES
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'");
2324         } else {
2325                 return false;   
2326         }
2327         
2328         $user = get_userdata($user_id);
2329         wp_cache_delete($user_id, 'users');
2330         wp_cache_delete($user->user_login, 'userlogins');
2331         
2332         return true;
2333 }
2334
2335 function delete_usermeta( $user_id, $meta_key, $meta_value = '' ) {
2336         global $wpdb;
2337         if ( !is_numeric( $user_id ) )
2338                 return false;
2339         $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
2340
2341         if ( is_array($meta_value) || is_object($meta_value) )
2342                 $meta_value = serialize($meta_value);
2343         $meta_value = trim( $meta_value );
2344
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'");
2347         else
2348                 $wpdb->query("DELETE FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key'");
2349                 
2350         $user = get_userdata($user_id);
2351         wp_cache_delete($user_id, 'users');
2352         wp_cache_delete($user->user_login, 'userlogins');
2353         
2354         return true;
2355 }
2356
2357 function register_activation_hook($file, $function) {
2358         $file = plugin_basename($file);
2359
2360         add_action('activate_' . $file, $function);
2361 }
2362
2363 function register_deactivation_hook($file, $function) {
2364         $file = plugin_basename($file);
2365
2366         add_action('deactivate_' . $file, $function);
2367 }
2368
2369 function plugin_basename($file) {
2370         $file = preg_replace('|\\\\+|', '\\\\', $file);
2371         $file = preg_replace('/^.*wp-content[\\\\\/]plugins[\\\\\/]/', '', $file);
2372         return $file;
2373 }
2374
2375 function get_num_queries() {
2376         global $wpdb;
2377         return $wpdb->num_queries;
2378 }
2379
2380 function wp_nonce_url($actionurl, $action = -1) {
2381         return wp_specialchars(add_query_arg('_wpnonce', wp_create_nonce($action), $actionurl));
2382 }
2383
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) . '" />';
2387         if ( $referer )
2388                 wp_referer_field();
2389 }
2390
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 . '" />';
2397         }
2398 }
2399
2400 function wp_original_referer_field() {
2401         echo '<input type="hidden" name="_wp_original_http_referer" value="' . attribute_escape(stripslashes($_SERVER['REQUEST_URI'])) . '" />';
2402 }
2403
2404 function wp_get_referer() {
2405         foreach ( array($_REQUEST['_wp_http_referer'], $_SERVER['HTTP_REFERER']) as $ref )
2406                 if ( !empty($ref) )
2407                         return $ref;
2408         return false;
2409 }
2410
2411 function wp_get_original_referer() {
2412         if ( !empty($_REQUEST['_wp_original_http_referer']) )
2413                 return $_REQUEST['_wp_original_http_referer'];
2414         return false;
2415 }
2416
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];
2421
2422                 $trans = array();
2423                 $trans['update']['attachment'] = array(__('Are you sure you want to edit this attachment: &quot;%s&quot;?'), 'get_the_title');
2424
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: &quot;%s&quot;?'), 'get_catname');
2427                 $trans['update']['category'] = array(__('Are you sure you want to edit this category: &quot;%s&quot;?'), 'get_catname');
2428
2429                 $trans['delete']['comment'] = array(__('Are you sure you want to delete this comment: &quot;%s&quot;?'), 'use_id');
2430                 $trans['unapprove']['comment'] = array(__('Are you sure you want to unapprove this comment: &quot;%s&quot;?'), 'use_id');
2431                 $trans['approve']['comment'] = array(__('Are you sure you want to approve this comment: &quot;%s&quot;?'), 'use_id');
2432                 $trans['update']['comment'] = array(__('Are you sure you want to edit this comment: &quot;%s&quot;?'), '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);
2435
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: &quot;%s&quot;?'), 'use_id');
2438                 $trans['update']['bookmark'] = array(__('Are you sure you want to edit this bookmark: &quot;%s&quot;?'), 'use_id');
2439                 $trans['bulk']['bookmarks'] = array(__('Are you sure you want to bulk modify bookmarks?'), false);
2440
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: &quot;%s&quot;?'), 'get_the_title');
2443                 $trans['update']['page'] = array(__('Are you sure you want to edit this page: &quot;%s&quot;?'), 'get_the_title');
2444
2445                 $trans['edit']['plugin'] = array(__('Are you sure you want to edit this plugin file: &quot;%s&quot;?'), 'use_id');
2446                 $trans['activate']['plugin'] = array(__('Are you sure you want to activate this plugin: &quot;%s&quot;?'), 'use_id');
2447                 $trans['deactivate']['plugin'] = array(__('Are you sure you want to deactivate this plugin: &quot;%s&quot;?'), 'use_id');
2448
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: &quot;%s&quot;?'), 'get_the_title');
2451                 $trans['update']['post'] = array(__('Are you sure you want to edit this post: &quot;%s&quot;?'), 'get_the_title');
2452
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: &quot;%s&quot;?'), 'get_author_name');
2457                 $trans['update']['profile'] = array(__('Are you sure you want to modify the profile for: &quot;%s&quot;?'), 'get_author_name');
2458
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: &quot;%s&quot;?'), 'use_id');
2462                 $trans['edit']['theme'] = array(__('Are you sure you want to edit this theme file: &quot;%s&quot;?'), 'use_id');
2463                 $trans['switch']['theme'] = array(__('Are you sure you want to switch to this theme: &quot;%s&quot;?'), 'use_id');
2464
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);
2472                         } else {
2473                                 return $trans[$verb][$noun][0];
2474                         }
2475                 }
2476         }
2477
2478         return __('Are you sure you want to do this?');
2479 }
2480
2481 function wp_nonce_ays($action) {
2482         global $pagenow, $menu, $submenu, $parent_file, $submenu_file;
2483
2484         $adminurl = get_settings('siteurl') . '/wp-admin';
2485         if ( wp_get_referer() )
2486                 $adminurl = attribute_escape(stripslashes(wp_get_referer()));
2487
2488         $title = __('WordPress Confirmation');
2489         // Remove extra layer of slashes.
2490         $_POST   = stripslashes_deep($_POST  );
2491         if ( $_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";
2499                 }
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";
2502         } else {
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";
2504         }
2505         $html .= "</body>\n</html>";
2506         wp_die($html, $title);
2507 }
2508
2509 function wp_die($message, $title = '') {
2510         header('Content-Type: text/html; charset=utf-8');
2511
2512         if ( empty($title) )
2513                 $title = __('WordPress &rsaquo; Error');
2514 ?>
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">
2517 <head>
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">
2521         <!--
2522         html {
2523                 background: #eee;
2524         }
2525         body {
2526                 background: #fff;
2527                 color: #000;
2528                 font-family: Georgia, "Times New Roman", Times, serif;
2529                 margin-left: 25%;
2530                 margin-right: 25%;
2531                 padding: .2em 2em;
2532         }
2533
2534         h1 {
2535                 color: #006;
2536                 font-size: 18px;
2537                 font-weight: lighter;
2538         }
2539
2540         h2 {
2541                 font-size: 16px;
2542         }
2543
2544         p, li, dt {
2545                 line-height: 140%;
2546                 padding-bottom: 2px;
2547         }
2548
2549         ul, ol {
2550                 padding: 5px 5px 5px 20px;
2551         }
2552         #logo {
2553                 margin-bottom: 2em;
2554         }
2555         -->
2556         </style>
2557 </head>
2558 <body>
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>
2561 </body>
2562 </html>
2563 <?php
2564
2565         die();
2566 }
2567
2568 ?>