Log in with username/password: lyceum/lyceum

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

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

slugs!

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 trace('$oldslug', $oldslug);
88     if ($slug != $oldslug){
89         $wpdb->query("UPDATE $wpdb->blogs SET slug = '$slug' WHERE id = '$blogdata->id'");
90         update_option('home', get_option('siteurl') .  '/' . $slug);
91         $any_changed++;               
92     }
93     
94     if ($any_changed) {
95             // If siteurl or home or slug changed, reset cookies.
96             if ( get_settings('home') != $old_home ) {
97                 // If home changed, write rewrite rules to new location.
98                 $wp_rewrite->flush_rules();
99                 // Get currently logged in user and password.
100                 get_currentuserinfo();
101                 // Clear cookies for old paths.
102                 wp_clearcookie();
103                 // Set cookies for new paths.
104                 wp_setcookie($user_login, $user_pass_md5, true, get_settings('home'), get_settings('siteurl'));
105             }
106
107         //$message = sprintf(__('%d setting(s) saved... '), $any_changed);
108     }
109     
110     $referred = remove_query_arg('updated' , $_SERVER['HTTP_REFERER']);
111     $goback = add_query_arg('updated', 'true', $_SERVER['HTTP_REFERER']);
112     $goback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $goback);
113     trace('$goback, $oldslug, $slug', "$goback, $oldslug, $slug");
114     $goback = preg_replace("|$oldslug|", $slug, $goback);
115     wp_redirect($goback);
116     break;
117
118 default:
119     include(WPADMININC . 'admin-header.php'); ?>
120
121 <div class="wrap">
122   <h2><?php _e('All options'); ?></h2>
123   <form name="form" action="options.php" method="post">
124   <input type="hidden" name="action" value="update" />
125   <table width="98%">
126 <?php
127 $options = $wpdb->get_results("SELECT * FROM $wpdb->options WHERE blog = '$blog' ORDER BY option_name");
128
129 foreach ($options as $option) :
130     $value = wp_specialchars($option->option_value);
131     echo "
132 <tr>
133     <th scope='row'><label for='$option->option_name'>$option->option_name</label></th>
134     <td><input type='text' name='$option->option_name' id='$option->option_name' size='30' value='" . $value . "' /></td>
135     <td>$option->option_description</td>
136 </tr>";
137 endforeach;
138 ?>
139   </table>
140 <p class="submit"><input type="submit" name="Update" value="<?php _e('Update Settings &raquo;') ?>" /></p>
141   </form>
142 </div>
143
144
145 <?php
146 break;
147 } // end switch
148
149 include(WPADMININC . 'admin-footer.php');
150 ?>
151
Note: See TracBrowser for help on using the browser.
Log in with username/password: lyceum/lyceum