Wordpress 3.5
[autoinstalls/wordpress.git] / wp-admin / customize.php
1 <?php
2 /**
3  * Customize Controls
4  *
5  * @package WordPress
6  * @subpackage Customize
7  * @since 3.4.0
8  */
9
10 define( 'IFRAME_REQUEST', true );
11
12 require_once( './admin.php' );
13 if ( ! current_user_can( 'edit_theme_options' ) )
14         wp_die( __( 'Cheatin&#8217; uh?' ) );
15
16 wp_reset_vars( array( 'url', 'return' ) );
17 $url = urldecode( $url );
18 $url = wp_validate_redirect( $url, home_url( '/' ) );
19 if ( $return )
20         $return = wp_validate_redirect( urldecode( $return ) );
21 if ( ! $return )
22         $return = $url;
23
24 global $wp_scripts, $wp_customize;
25
26 $registered = $wp_scripts->registered;
27 $wp_scripts = new WP_Scripts;
28 $wp_scripts->registered = $registered;
29
30 add_action( 'customize_controls_print_scripts',        'print_head_scripts', 20 );
31 add_action( 'customize_controls_print_footer_scripts', '_wp_footer_scripts'     );
32 add_action( 'customize_controls_print_styles',         'print_admin_styles', 20 );
33
34 do_action( 'customize_controls_init' );
35
36 wp_enqueue_script( 'customize-controls' );
37 wp_enqueue_style( 'customize-controls' );
38
39 do_action( 'customize_controls_enqueue_scripts' );
40
41 // Let's roll.
42 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
43
44 wp_user_settings();
45 _wp_admin_html_begin();
46
47 $body_class = 'wp-core-ui';
48
49 if ( wp_is_mobile() ) :
50         $body_class .= ' mobile';
51
52         ?><meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=0.8, minimum-scale=0.5, maximum-scale=1.2"><?php
53 endif;
54
55 $is_ios = wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] );
56
57 if ( $is_ios )
58         $body_class .= ' ios';
59
60 if ( is_rtl() )
61         $body_class .=  ' rtl';
62 $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
63
64 $admin_title = sprintf( __( '%1$s &#8212; WordPress' ), strip_tags( sprintf( __( 'Customize %s' ), $wp_customize->theme()->display('Name') ) ) );
65 ?><title><?php echo $admin_title; ?></title><?php
66
67 do_action( 'customize_controls_print_styles' );
68 do_action( 'customize_controls_print_scripts' );
69 ?>
70 </head>
71 <body class="<?php echo esc_attr( $body_class ); ?>">
72 <div class="wp-full-overlay expanded">
73         <form id="customize-controls" class="wrap wp-full-overlay-sidebar">
74
75                 <div id="customize-header-actions" class="wp-full-overlay-header">
76                         <?php
77                                 $save_text = $wp_customize->is_theme_active() ? __( 'Save &amp; Publish' ) : __( 'Save &amp; Activate' );
78                                 submit_button( $save_text, 'primary save', 'save', false );
79                         ?>
80                         <span class="spinner"></span>
81                         <a class="back button" href="<?php echo esc_url( $return ? $return : admin_url( 'themes.php' ) ); ?>">
82                                 <?php _e( 'Cancel' ); ?>
83                         </a>
84                 </div>
85
86                 <?php
87                         $screenshot = $wp_customize->theme()->get_screenshot();
88                         $cannot_expand = ! ( $screenshot || $wp_customize->theme()->get('Description') );
89                 ?>
90
91                 <div class="wp-full-overlay-sidebar-content" tabindex="-1">
92                         <div id="customize-info" class="customize-section<?php if ( $cannot_expand ) echo ' cannot-expand'; ?>">
93                                 <div class="customize-section-title" aria-label="<?php esc_attr_e( 'Theme Customizer Options' ); ?>" tabindex="0">
94                                         <span class="preview-notice"><?php
95                                                 /* translators: %s is the theme name in the Customize/Live Preview pane */
96                                                 echo sprintf( __( 'You are previewing %s' ), '<strong class="theme-name">' . $wp_customize->theme()->display('Name') . '</strong>' );
97                                         ?></span>
98                                 </div>
99                                 <?php if ( ! $cannot_expand ) : ?>
100                                 <div class="customize-section-content">
101                                         <?php if ( $screenshot ) : ?>
102                                                 <img class="theme-screenshot" src="<?php echo esc_url( $screenshot ); ?>" />
103                                         <?php endif; ?>
104
105                                         <?php if ( $wp_customize->theme()->get('Description') ): ?>
106                                                 <div class="theme-description"><?php echo $wp_customize->theme()->display('Description'); ?></div>
107                                         <?php endif; ?>
108                                 </div>
109                                 <?php endif; ?>
110                         </div>
111
112                         <div id="customize-theme-controls"><ul>
113                                 <?php
114                                 foreach ( $wp_customize->sections() as $section )
115                                         $section->maybe_render();
116                                 ?>
117                         </ul></div>
118                 </div>
119
120                 <div id="customize-footer-actions" class="wp-full-overlay-footer">
121                         <a href="#" class="collapse-sidebar button-secondary" title="<?php esc_attr_e('Collapse Sidebar'); ?>">
122                                 <span class="collapse-sidebar-arrow"></span>
123                                 <span class="collapse-sidebar-label"><?php _e('Collapse'); ?></span>
124                         </a>
125                 </div>
126         </form>
127         <div id="customize-preview" class="wp-full-overlay-main"></div>
128         <?php
129
130         do_action( 'customize_controls_print_footer_scripts' );
131
132         // If the frontend and the admin are served from the same domain, load the
133         // preview over ssl if the customizer is being loaded over ssl. This avoids
134         // insecure content warnings. This is not attempted if the admin and frontend
135         // are on different domains to avoid the case where the frontend doesn't have
136         // ssl certs. Domain mapping plugins can allow other urls in these conditions
137         // using the customize_allowed_urls filter.
138
139         $allowed_urls = array( home_url('/') );
140         $admin_origin = parse_url( admin_url() );
141         $home_origin  = parse_url( home_url() );
142         $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) );
143
144         if ( is_ssl() && ! $cross_domain )
145                 $allowed_urls[] = home_url( '/', 'https' );
146
147         $allowed_urls = array_unique( apply_filters( 'customize_allowed_urls', $allowed_urls ) );
148
149         $fallback_url = add_query_arg( array(
150                 'preview'        => 1,
151                 'template'       => $wp_customize->get_template(),
152                 'stylesheet'     => $wp_customize->get_stylesheet(),
153                 'preview_iframe' => true,
154                 'TB_iframe'      => 'true'
155         ), home_url( '/' ) );
156
157         $login_url = add_query_arg( array(
158                 'interim-login' => 1,
159                 'customize-login' => 1
160         ), wp_login_url() );
161
162         $settings = array(
163                 'theme'    => array(
164                         'stylesheet' => $wp_customize->get_stylesheet(),
165                         'active'     => $wp_customize->is_theme_active(),
166                 ),
167                 'url'      => array(
168                         'preview'       => esc_url( $url ? $url : home_url( '/' ) ),
169                         'parent'        => esc_url( admin_url() ),
170                         'activated'     => admin_url( 'themes.php?activated=true&previewed' ),
171                         'ajax'          => esc_url( admin_url( 'admin-ajax.php', 'relative' ) ),
172                         'allowed'       => array_map( 'esc_url', $allowed_urls ),
173                         'isCrossDomain' => $cross_domain,
174                         'fallback'      => $fallback_url,
175                         'home'          => esc_url( home_url( '/' ) ),
176                         'login'         => $login_url,
177                 ),
178                 'browser'  => array(
179                         'mobile' => wp_is_mobile(),
180                         'ios'    => $is_ios,
181                 ),
182                 'settings' => array(),
183                 'controls' => array(),
184                 'nonce'    => array(
185                         'save'    => wp_create_nonce( 'save-customize_' . $wp_customize->get_stylesheet() ),
186                         'preview' => wp_create_nonce( 'preview-customize_' . $wp_customize->get_stylesheet() )
187                 ),
188         );
189
190         foreach ( $wp_customize->settings() as $id => $setting ) {
191                 $settings['settings'][ $id ] = array(
192                         'value'     => $setting->js_value(),
193                         'transport' => $setting->transport,
194                 );
195         }
196
197         foreach ( $wp_customize->controls() as $id => $control ) {
198                 $control->to_json();
199                 $settings['controls'][ $id ] = $control->json;
200         }
201
202         ?>
203         <script type="text/javascript">
204                 var _wpCustomizeSettings = <?php echo json_encode( $settings ); ?>;
205         </script>
206 </div>
207 </body>
208 </html>