Wordpress 2.0.2
[autoinstalls/wordpress.git] / wp-admin / options.php
1 <?php
2 require_once('admin.php');
3
4 $title = __('Options');
5 $this_file = 'options.php';
6 $parent_file = 'options-general.php';
7
8 $wpvarstoreset = array('action');
9 for ($i=0; $i<count($wpvarstoreset); $i += 1) {
10         $wpvar = $wpvarstoreset[$i];
11         if (!isset($$wpvar)) {
12                 if (empty($_POST["$wpvar"])) {
13                         if (empty($_GET["$wpvar"])) {
14                                 $$wpvar = '';
15                         } else {
16                                 $$wpvar = $_GET["$wpvar"];
17                         }
18                 } else {
19                         $$wpvar = $_POST["$wpvar"];
20                 }
21         }
22 }
23
24 if ( !current_user_can('manage_options') )
25         die ( __('Cheatin&#8217; uh?') );
26
27 switch($action) {
28
29 case 'update':
30         $any_changed = 0;
31         
32         check_admin_referer();
33
34         if (!$_POST['page_options']) {
35                 foreach ($_POST as $key => $value) {
36                         $options[] = $key;
37                 }
38         } else {
39                 $options = explode(',', stripslashes($_POST['page_options']));
40         }
41
42         // Save for later.
43         $old_siteurl = get_settings('siteurl');
44         $old_home = get_settings('home');
45
46         // HACK
47         // Options that if not there have 0 value but need to be something like "closed"
48         $nonbools = array('default_ping_status', 'default_comment_status');
49         if ($options) {
50                 foreach ($options as $option) {
51                         $option = trim($option);
52                         $value = trim(stripslashes($_POST[$option]));
53                                 if( in_array($option, $nonbools) && ( $value == '0' || $value == '') )
54                                 $value = 'closed';
55                         
56                         if( $option == 'blogdescription' || $option == 'blogname' )
57                                 if (current_user_can('unfiltered_html') == false)
58                                         $value = wp_filter_post_kses( $value );
59                         
60                         if (update_option($option, $value) ) {
61                                 $any_changed++;
62                         }
63                 }
64         }
65     
66         if ($any_changed) {
67                         // If siteurl or home changed, reset cookies.
68                         if ( get_settings('siteurl') != $old_siteurl || get_settings('home') != $old_home ) {
69                                 // If home changed, write rewrite rules to new location.
70                                 $wp_rewrite->flush_rules();
71                                 // Get currently logged in user and password.
72                                 get_currentuserinfo();
73                                 // Clear cookies for old paths.
74                                 wp_clearcookie();
75                                 // Set cookies for new paths.
76                                 wp_setcookie($user_login, $user_pass_md5, true, get_settings('home'), get_settings('siteurl'));
77                         }
78
79                         //$message = sprintf(__('%d setting(s) saved... '), $any_changed);
80     }
81     
82         $referred = remove_query_arg('updated' , $_SERVER['HTTP_REFERER']);
83         $goback = add_query_arg('updated', 'true', $_SERVER['HTTP_REFERER']);
84         $goback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $goback);
85         wp_redirect($goback);
86     break;
87
88 default:
89         include('admin-header.php'); ?>
90
91 <div class="wrap">
92   <h2><?php _e('All options'); ?></h2>
93   <form name="form" action="options.php" method="post">
94   <input type="hidden" name="action" value="update" />
95   <table width="98%">
96 <?php
97 $options = $wpdb->get_results("SELECT * FROM $wpdb->options ORDER BY option_name");
98
99 foreach ($options as $option) :
100         $value = wp_specialchars($option->option_value);
101         echo "
102 <tr>
103         <th scope='row'><label for='$option->option_name'>$option->option_name</label></th>
104         <td><input type='text' name='$option->option_name' id='$option->option_name' size='30' value='" . $value . "' /></td>
105         <td>$option->option_description</td>
106 </tr>";
107 endforeach;
108 ?>
109   </table>
110 <p class="submit"><input type="submit" name="Update" value="<?php _e('Update Settings &raquo;') ?>" /></p>
111   </form>
112 </div>
113
114
115 <?php
116 break;
117 } // end switch
118
119 include('admin-footer.php');
120 ?>