diff options
author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2007-03-26 15:46:27 +0000 |
---|---|---|
committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2007-03-26 15:46:27 +0000 |
commit | b7fe2aee15c1f3ad0673d105624ea81f16f14288 (patch) | |
tree | 7b88927675de4b121e104a958647f10cfe438c10 | |
parent | 244e8f75fcb7110a9ded532d76e5bcba50bc45f6 (diff) | |
download | wordpress-mu-b7fe2aee15c1f3ad0673d105624ea81f16f14288.tar.gz wordpress-mu-b7fe2aee15c1f3ad0673d105624ea81f16f14288.tar.xz wordpress-mu-b7fe2aee15c1f3ad0673d105624ea81f16f14288.zip |
Index allowed_themes by stylesheet path instead of name. (fixes #284)
Important! Make sure you visit and save wp-admin/wpmu-themes.php to update the list!
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@936 7be80a69-a1ef-0310-a953-fb0f7c49ff36
-rw-r--r-- | wp-admin/admin-db.php | 32 | ||||
-rw-r--r-- | wp-admin/themes.php | 28 | ||||
-rw-r--r-- | wp-admin/wpmu-blogs.php | 69 | ||||
-rw-r--r-- | wp-admin/wpmu-edit.php | 19 |
4 files changed, 88 insertions, 60 deletions
diff --git a/wp-admin/admin-db.php b/wp-admin/admin-db.php index d4df176..6800881 100644 --- a/wp-admin/admin-db.php +++ b/wp-admin/admin-db.php @@ -627,4 +627,36 @@ function wpmu_delete_user($id) { return true; } +function wpmu_get_blog_allowedthemes( $blog_id = 0 ) { + $themes = get_themes(); + if( $blog_id == 0 ) + $blog_allowed_themes = get_option( "allowedthemes" ); + else + $blog_allowed_themes = get_blog_option( $blog_id, "allowedthemes" ); + if( !is_array( $blog_allowed_themes ) || empty( $blog_allowed_themes ) ) { // convert old allowed_themes to new allowedthemes + if( $blog_id == 0 ) + $blog_allowed_themes = get_option( "allowed_themes" ); + else + $blog_allowed_themes = get_blog_option( $blog_id, "allowed_themes" ); + if( is_array( $blog_allowed_themes ) ) { + foreach( $themes as $key => $theme ) { + $theme_key = wp_specialchars( $theme[ 'Stylesheet' ] ); + if( isset( $blog_allowed_themes[ $key ] ) == true ) { + $blog_allowedthemes[ $theme_key ] = 1; + } + } + $blog_allowed_themes = $blog_allowedthemes; + if( $blog_id == 0 ) { + add_option( "allowedthemes", $blog_allowed_themes ); + delete_option( "allowed_themes" ); + } else { + add_blog_option( $blog_id, "allowedthemes", $blog_allowed_themes ); + delete_blog_option( $blog_id, "allowed_themes" ); + } + } + } + + return $blog_allowed_themes; +} + ?> diff --git a/wp-admin/themes.php b/wp-admin/themes.php index af7791f..ee84375 100644 --- a/wp-admin/themes.php +++ b/wp-admin/themes.php @@ -3,24 +3,23 @@ require_once('admin.php'); $themes = get_themes(); $ct = current_theme_info(); -$allowed_themes = get_site_option( "allowed_themes" ); -if( $allowed_themes == false ) { - $allowed_themes = array(); - if( $blog_id != 1 ) - unset( $allowed_themes[ "WordPress MU Home Default" ] ); -} -$blog_allowed_themes = get_option( "allowed_themes" ); +$allowed_themes = get_site_option( "allowedthemes" ); +if( $allowed_themes == false ) + $allowed_themes = array(); +$blog_allowed_themes = wpmu_get_blog_allowedthemes(); if( is_array( $blog_allowed_themes ) ) $allowed_themes = array_merge( $allowed_themes, $blog_allowed_themes ); +if( $blog_id != 1 ) + unset( $allowed_themes[ "h3" ] ); + +if( isset( $allowed_themes[ wp_specialchars( $ct->stylesheet ) ] ) == false ) + $allowed_themes[ wp_specialchars( $ct->stylesheet ) ] = true; -if( isset( $allowed_themes[ $ct->title ] ) == false ) { - $allowed_themes[ $ct->title ] = true; -} reset( $themes ); -while( list( $key, $val ) = each( $themes ) ) { - if( isset( $allowed_themes[ $key ] ) == false ) { - unset( $themes[ $key ] ); +foreach( $themes as $key => $theme ) { + if( isset( $allowed_themes[ wp_specialchars( $theme[ 'Stylesheet' ] ) ] ) == false ) { + unset( $themes[ $key ] ); } } reset( $themes ); @@ -75,6 +74,7 @@ require_once('admin-header.php'); <p><?php echo $ct->description; ?></p> </div> +<br style="clear: both" /> <h2><?php _e('Available Themes'); ?></h2> <?php if ( 1 < count($themes) ) { ?> @@ -118,7 +118,7 @@ $broken_themes = get_broken_themes(); if ( is_site_admin() && count($broken_themes) ) { ?> -<h2><?php _e('Broken Themes'); ?></h2> +<h2><?php _e('Broken Themes'); ?> (Site admin only)</h2> <p><?php _e('The following themes are installed but incomplete. Themes must have a stylesheet and a template.'); ?></p> <table width="100%" cellpadding="3" cellspacing="3"> diff --git a/wp-admin/wpmu-blogs.php b/wp-admin/wpmu-blogs.php index bfcb52c..3ea0891 100644 --- a/wp-admin/wpmu-blogs.php +++ b/wp-admin/wpmu-blogs.php @@ -13,12 +13,13 @@ if (isset($_GET['updated'])) { print '<div class="wrap">'; switch( $_GET[ 'action' ] ) { case "editblog": - $options_table_name = $wpmuBaseTablePrefix . $_GET[ 'id' ] ."_options"; - $options = $wpdb->get_results( "SELECT * FROM {$options_table_name} WHERE option_name NOT LIKE 'rss%' AND option_name NOT LIKE '%user_roles'", ARRAY_A ); - $details = $wpdb->get_row( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = '{$_GET[ 'id' ]}'", ARRAY_A ); + $id = intval( $_GET[ 'id' ] ); + $options_table_name = "$wpmuBaseTablePrefix{$id}_options"; + $options = $wpdb->get_results( "SELECT * FROM {$options_table_name} WHERE option_name NOT LIKE 'rss%' AND option_name NOT LIKE '%user_roles'", ARRAY_A ); + $details = $wpdb->get_row( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = '{$_GET[ 'id' ]}'", ARRAY_A ); - print "<h2>" . __('Edit Blog') . "</h2>"; - print "<a href='http://{$details[ 'domain' ]}/'>{$details[ 'domain' ]}</a>"; + print "<h2>" . __('Edit Blog') . "</h2>"; + print "<a href='http://{$details[ 'domain' ]}/'>{$details[ 'domain' ]}</a>"; ?> <form name="form1" method="post" action="wpmu-edit.php?action=updateblog"> <?php wp_nonce_field( "editblog" ); ?> @@ -103,40 +104,36 @@ switch( $_GET[ 'action' ] ) { </td> <td valign='top'> <?php - $themes = get_themes(); - $query = "SELECT option_value - FROM ".$options_table_name." - WHERE option_name = 'allowed_themes'"; - $blog_allowed_themes = $wpdb->get_var( $query ); - if( $blog_allowed_themes != false ) - $blog_allowed_themes = unserialize( $blog_allowed_themes ); - $allowed_themes = get_site_option( "allowed_themes" ); - if( $allowed_themes == false ) { - $allowed_themes = array_keys( $themes ); - } - $out = ''; - while( list( $key, $val ) = each( $themes ) ) { - if( isset( $allowed_themes[ $key ] ) == false ) { - if( isset( $blog_allowed_themes[ $key ] ) == true ) { - $checked = 'checked '; - } else { - $checked = ''; - } - - $out .= ' - <tr valign="top"> - <th title="' . htmlspecialchars( $val[ "Description" ] ) . '" scope="row">'.$key.'</th> - <td><input name="theme['.$key.']" type="checkbox" id="'.$key.'" value="on" '.$checked.'/></td> - </tr> '; + $themes = get_themes(); + $blog_allowed_themes = wpmu_get_blog_allowedthemes( $id ); + $allowed_themes = get_site_option( "allowedthemes" ); + if( $allowed_themes == false ) { + $allowed_themes = array_keys( $themes ); } + $out = ''; + foreach( $themes as $key => $theme ) { + $theme_key = wp_specialchars( $theme[ 'Stylesheet' ] ); + if( isset( $allowed_themes[ $theme_key ] ) == false ) { + if( isset( $blog_allowed_themes[ $theme_key ] ) == true ) { + $checked = 'checked '; + } else { + $checked = ''; + } + + $out .= ' + <tr valign="top"> + <th title="' . htmlspecialchars( $theme[ "Description" ] ) . '" scope="row">'.$key.'</th> + <td><input name="theme['.$theme_key.']" type="checkbox" id="'.$key.'" value="on" '.$checked.'/></td> + </tr> '; + } } if( $out != '' ) { - print "<div class='wrap'><h3>" . __('Blog Themes') . "</h3>"; - print '<table width="100%" border="0" cellspacing="2" cellpadding="5" class="editform">'; - print '<tr><th>' . __('Theme') . '</th><th>' . __('Enable') . '</th></tr>'; - print $out; - print "</table></div>"; - } + print "<div class='wrap'><h3>" . __('Blog Themes') . "</h3>"; + print '<table width="100%" border="0" cellspacing="2" cellpadding="5" class="editform">'; + print '<tr><th>' . __('Theme') . '</th><th>' . __('Enable') . '</th></tr>'; + print $out; + print "</table></div>"; + } $blogusers = get_users_of_blog( $_GET[ 'id' ] ); print '<div class="wrap"><h3>' . __('Blog Users') . '</h3>'; if( is_array( $blogusers ) ) { diff --git a/wp-admin/wpmu-edit.php b/wp-admin/wpmu-edit.php index b7827e2..f891694 100644 --- a/wp-admin/wpmu-edit.php +++ b/wp-admin/wpmu-edit.php @@ -158,9 +158,9 @@ switch( $_REQUEST[ 'action' ] ) { // themes if( is_array( $_POST[ 'theme' ] ) ) { $allowed_themes = $_POST[ 'theme' ]; - $_POST[ 'option' ][ 'allowed_themes' ] = $_POST[ 'theme' ]; + $_POST[ 'option' ][ 'allowedthemes' ] = $_POST[ 'theme' ]; } else { - $_POST[ 'option' ][ 'allowed_themes' ] = ''; + $_POST[ 'option' ][ 'allowedthemes' ] = ''; } if( is_array( $_POST[ 'option' ] ) ) { $c = 1; @@ -382,18 +382,17 @@ switch( $_REQUEST[ 'action' ] ) { die(); break; case "updatethemes": - if( is_site_admin() == false ) { + if( is_site_admin() == false ) die( __('<p>You do not have permission to access this page.</p>') ); - } + if( is_array( $_POST[ 'theme' ] ) ) { - $themes = array_flip( array_keys( get_themes() ) ); + $themes = get_themes(); reset( $themes ); - while( list( $key, $val ) = each( $themes ) ) - { - if( $_POST[ 'theme' ][ addslashes( $key ) ] == 'enabled' ) - $allowed_themes[ $key ] = true; + foreach( $themes as $key => $theme ) { + if( $_POST[ 'theme' ][ wp_specialchars( $theme[ 'Stylesheet' ] ) ] == 'enabled' ) + $allowed_themes[ wp_specialchars( $theme[ 'Stylesheet' ] ) ] = true; } - update_site_option( 'allowed_themes', $allowed_themes ); + update_site_option( 'allowedthemes', $allowed_themes ); } wp_redirect( add_query_arg( "updated", "themesupdated", $_SERVER[ 'HTTP_REFERER' ] ) ); die(); |