Log in with username/password: lyceum/lyceum

root/trunk/src/lyceum/wp-admin/options.php

Revision 616, 4.2 kB (checked in by jjb, 4 years ago)

Subdomains!

Most of the pieces in order to use subdomains. The way that cookies are set needs to be adapted to this system. As it is now, users have to keep re-logging-in when they switch from one domain to another.

Many thanks to coffelius of http://bloggear.net for help and code.

ticket:326

Line 
1 <?php
2 require('../private.php');
3 require_once(WPADMININC . 'admin.php');
4
5 $title = __('Options');
6 $this_file = 'options.php';
7 $parent_file = 'options-general.php';
8
9 $wpvarstoreset = array('action');
10 for ($i=0; $i<count($wpvarstoreset); $i += 1) {
11     $wpvar = $wpvarstoreset[$i];
12     if (!isset($$wpvar)) {
13         if (empty($_POST["$wpvar"])) {
14             if (empty($_GET["$wpvar"])) {
15                 $$wpvar = '';
16             } else {
17                 $$wpvar = $_GET["$wpvar"];
18             }
19         } else {
20             $$wpvar = $_POST["$wpvar"];
21         }
22     }
23 }
24
25 if ( !current_user_can('manage_options') )
26     die ( __('No.') );
27
28 switch($action) {
29
30 case 'update':
31     $any_changed = 0;
32     
33     check_admin_referer();
34
35     validateToken($_POST['token'], 'options.php', 'update', $_POST['page_options']);
36
37     if ('registered' == $_POST['commentpolicy']) {
38         $_POST['comment_registration']=1;
39         $_POST['comment_priviliges']=0;
40     }
41     elseif ('priviliges' == $_POST['commentpolicy']){
42         $_POST['comment_registration']=1;
43         $_POST['comment_priviliges']=1;
44     }
45     elseif ('anonymous' == $_POST['commentpolicy']){
46         $_POST['comment_registration']=0;
47         $_POST['comment_priviliges']=0;
48     }
49     elseif (isset($_POST['commentpolicy'])){
50         die('Wrong commenting policy flag');
51     }
52
53     if (!$_POST['page_options']) {
54         foreach ($_POST as $key => $value) {
55             $options[] = $key;
56         }
57     } else {
58         $options = explode(',', stripslashes($_POST['page_options']));
59     }
60
61     // Save for later.
62 //    $old_siteurl = get_settings('siteurl');
63     $old_home = get_settings('home');
64
65     // HACK
66     // Options that if not there have 0 value but need to be something like "closed"
67     $nonbools = array('default_ping_status', 'default_comment_status');
68     if ($options) {
69         foreach ($options as $option) {
70             $option = trim($option);
71             $value = trim(stripslashes($_POST[$option]));
72                 if( in_array($option, $nonbools) && ( $value == '0' || $value == '') )
73                 $value = 'closed';
74             
75             if( $option == 'blogdescription' || $option == 'blogname' )
76                 if (current_user_can('unfiltered_html') == false)
77                     $value = wp_filter_post_kses( $value );
78             
79             if (update_option($option, $value) ) {
80                 $any_changed++;
81             }
82         }
83     }
84
85     $slug = $_POST['slug'];
86     $oldslug = $wpdb->get_var("SELECT slug FROM $wpdb->blogs WHERE id = '$blogdata->id'");
87     if ($slug != $oldslug){
88         $wpdb->query("UPDATE $wpdb->blogs SET slug = '$slug' WHERE id = '$blogdata->id'");
89         if (SUBDOMAINS)
90             $home = 'http://' . $slug . '.' . MAINDOMAIN;
91         else
92             $home = get_option('siteurl') . '/' . $slug;
93         update_option('home', $home);
94         $any_changed++;               
95     }
96     
97     if ($any_changed) {
98             // If siteurl or home or slug changed, reset cookies.
99             if ( get_settings('home') != $old_home ) {
100                 // If home changed, write rewrite rules to new location.
101                 $wp_rewrite->flush_rules();
102                 // Get currently logged in user and password.
103                 get_currentuserinfo();
104                 // Clear cookies for old paths.
105                 wp_clearcookie();
106                 // Set cookies for new paths.
107                 wp_setcookie($user_login, $user_pass_md5, true, get_settings('home'), get_settings('siteurl'));
108             }
109
110         //$message = sprintf(__('%d setting(s) saved... '), $any_changed);
111     }
112     
113     $referred = remove_query_arg('updated' , $_SERVER['HTTP_REFERER']);
114     $goback = add_query_arg('updated', 'true', $_SERVER['HTTP_REFERER']);
115     $goback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $goback);
116     trace('$goback, $oldslug, $slug', "$goback, $oldslug, $slug");
117     $goback = preg_replace("|$oldslug|", $slug, $goback);
118     wp_redirect($goback);
119     break;
120
121 default:
122     include(WPADMININC . 'admin-header.php'); ?>
123
124 <div class="wrap">
125   <h2><?php _e('All options'); ?></h2>
126   <form name="form" action="options.php" method="post">
127   <input type="hidden" name="action" value="update" />
128   <table width="98%">
129 <?php
130 $options = $wpdb->get_results("SELECT * FROM $wpdb->options WHERE blog = '$blog' ORDER BY option_name");
131
132 foreach ($options as $option) :
133     $value = wp_specialchars($option->option_value);
134     echo "
135 <tr>
136     <th scope='row'><label for='$option->option_name'>$option->option_name</label></th>
137     <td><input type='text' name='$option->option_name' id='$option->option_name' size='30' value='" . $value . "' /></td>
138     <td>$option->option_description</td>
139 </tr>";
140 endforeach;
141 ?>
142   </table>
143 <p class="submit"><input type="submit" name="Update" value="<?php _e('Update Settings &raquo;') ?>" /></p>
144   </form>
145 </div>
146
147
148 <?php
149 break;
150 } // end switch
151
152 include(WPADMININC . 'admin-footer.php');
153 ?>
154
Note: See TracBrowser for help on using the browser.
Log in with username/password: lyceum/lyceum