Wordpress 3.7
[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( dirname( __FILE__ ) . '/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 /**
35  * Fires when Customizer controls are initialized, before scripts are enqueued.
36  *
37  * @since 3.4.0
38  */
39 do_action( 'customize_controls_init' );
40
41 wp_enqueue_script( 'customize-controls' );
42 wp_enqueue_style( 'customize-controls' );
43
44 wp_enqueue_script( 'accordion' );
45
46 /**
47  * Enqueue Customizer control scripts.
48  *
49  * @since 3.4.0
50  */
51 do_action( 'customize_controls_enqueue_scripts' );
52
53 // Let's roll.
54 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
55
56 wp_user_settings();
57 _wp_admin_html_begin();
58
59 $body_class = 'wp-core-ui js';
60
61 if ( wp_is_mobile() ) :
62         $body_class .= ' mobile';
63
64         ?><meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=0.8, minimum-scale=0.5, maximum-scale=1.2"><?php
65 endif;
66
67 $is_ios = wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] );
68
69 if ( $is_ios )
70         $body_class .= ' ios';
71
72 if ( is_rtl() )
73         $body_class .=  ' rtl';
74 $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
75
76 $admin_title = sprintf( __( '%1$s &#8212; WordPress' ), strip_tags( sprintf( __( 'Customize %s' ), $wp_customize->theme()->display('Name') ) ) );
77 ?><title><?php echo $admin_title; ?></title><?php
78
79 /**
80  * Print Customizer control styles.
81  *
82  * @since 3.4.0
83  */
84 do_action( 'customize_controls_print_styles' );
85
86 /**
87  * Print Customizer control scripts.
88  *
89  * @since 3.4.0
90  */
91 do_action( 'customize_controls_print_scripts' );
92 ?>
93 </head>
94 <body class="<?php echo esc_attr( $body_class ); ?>">
95 <div class="wp-full-overlay expanded">
96         <form id="customize-controls" class="wrap wp-full-overlay-sidebar">
97
98                 <div id="customize-header-actions" class="wp-full-overlay-header">
99                         <?php
100                                 $save_text = $wp_customize->is_theme_active() ? __( 'Save &amp; Publish' ) : __( 'Save &amp; Activate' );
101                                 submit_button( $save_text, 'primary save', 'save', false );
102                         ?>
103                         <span class="spinner"></span>
104                         <a class="back button" href="<?php echo esc_url( $return ? $return : admin_url( 'themes.php' ) ); ?>">
105                                 <?php _e( 'Cancel' ); ?>
106                         </a>
107                 </div>
108
109                 <?php
110                         $screenshot = $wp_customize->theme()->get_screenshot();
111                         $cannot_expand = ! ( $screenshot || $wp_customize->theme()->get('Description') );
112                 ?>
113
114                 <div class="wp-full-overlay-sidebar-content accordion-container" tabindex="-1">
115                         <div id="customize-info" class="accordion-section <?php if ( $cannot_expand ) echo ' cannot-expand'; ?>">
116                                 <div class="accordion-section-title" aria-label="<?php esc_attr_e( 'Theme Customizer Options' ); ?>" tabindex="0">
117                                         <span class="preview-notice"><?php
118                                                 /* translators: %s is the theme name in the Customize/Live Preview pane */
119                                                 echo sprintf( __( 'You are previewing %s' ), '<strong class="theme-name">' . $wp_customize->theme()->display('Name') . '</strong>' );
120                                         ?></span>
121                                 </div>
122                                 <?php if ( ! $cannot_expand ) : ?>
123                                 <div class="accordion-section-content">
124                                         <?php if ( $screenshot ) : ?>
125                                                 <img class="theme-screenshot" src="<?php echo esc_url( $screenshot ); ?>" />
126                                         <?php endif; ?>
127
128                                         <?php if ( $wp_customize->theme()->get('Description') ): ?>
129                                                 <div class="theme-description"><?php echo $wp_customize->theme()->display('Description'); ?></div>
130                                         <?php endif; ?>
131                                 </div>
132                                 <?php endif; ?>
133                         </div>
134
135                         <div id="customize-theme-controls"><ul>
136                                 <?php
137                                 foreach ( $wp_customize->sections() as $section )
138                                         $section->maybe_render();
139                                 ?>
140                         </ul></div>
141                 </div>
142
143                 <div id="customize-footer-actions" class="wp-full-overlay-footer">
144                         <a href="#" class="collapse-sidebar button-secondary" title="<?php esc_attr_e('Collapse Sidebar'); ?>">
145                                 <span class="collapse-sidebar-arrow"></span>
146                                 <span class="collapse-sidebar-label"><?php _e('Collapse'); ?></span>
147                         </a>
148                 </div>
149         </form>
150         <div id="customize-preview" class="wp-full-overlay-main"></div>
151         <?php
152
153         /**
154          * Print Customizer control scripts in the footer.
155          *
156          * @since 3.4.0
157          */
158         do_action( 'customize_controls_print_footer_scripts' );
159
160         // If the frontend and the admin are served from the same domain, load the
161         // preview over ssl if the customizer is being loaded over ssl. This avoids
162         // insecure content warnings. This is not attempted if the admin and frontend
163         // are on different domains to avoid the case where the frontend doesn't have
164         // ssl certs. Domain mapping plugins can allow other urls in these conditions
165         // using the customize_allowed_urls filter.
166
167         $allowed_urls = array( home_url('/') );
168         $admin_origin = parse_url( admin_url() );
169         $home_origin  = parse_url( home_url() );
170         $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) );
171
172         if ( is_ssl() && ! $cross_domain )
173                 $allowed_urls[] = home_url( '/', 'https' );
174
175         /**
176          * Filter the list of URLs allowed to be clicked and followed in the Customizer preview.
177          *
178          * @since 3.4.0
179          *
180          * @param array $allowed_urls An array of allowed URLs.
181          */
182         $allowed_urls = array_unique( apply_filters( 'customize_allowed_urls', $allowed_urls ) );
183
184         $fallback_url = add_query_arg( array(
185                 'preview'        => 1,
186                 'template'       => $wp_customize->get_template(),
187                 'stylesheet'     => $wp_customize->get_stylesheet(),
188                 'preview_iframe' => true,
189                 'TB_iframe'      => 'true'
190         ), home_url( '/' ) );
191
192         $login_url = add_query_arg( array(
193                 'interim-login' => 1,
194                 'customize-login' => 1
195         ), wp_login_url() );
196
197         $settings = array(
198                 'theme'    => array(
199                         'stylesheet' => $wp_customize->get_stylesheet(),
200                         'active'     => $wp_customize->is_theme_active(),
201                 ),
202                 'url'      => array(
203                         'preview'       => esc_url( $url ? $url : home_url( '/' ) ),
204                         'parent'        => esc_url( admin_url() ),
205                         'activated'     => admin_url( 'themes.php?activated=true&previewed' ),
206                         'ajax'          => esc_url( admin_url( 'admin-ajax.php', 'relative' ) ),
207                         'allowed'       => array_map( 'esc_url', $allowed_urls ),
208                         'isCrossDomain' => $cross_domain,
209                         'fallback'      => $fallback_url,
210                         'home'          => esc_url( home_url( '/' ) ),
211                         'login'         => $login_url,
212                 ),
213                 'browser'  => array(
214                         'mobile' => wp_is_mobile(),
215                         'ios'    => $is_ios,
216                 ),
217                 'settings' => array(),
218                 'controls' => array(),
219                 'nonce'    => array(
220                         'save'    => wp_create_nonce( 'save-customize_' . $wp_customize->get_stylesheet() ),
221                         'preview' => wp_create_nonce( 'preview-customize_' . $wp_customize->get_stylesheet() )
222                 ),
223         );
224
225         foreach ( $wp_customize->settings() as $id => $setting ) {
226                 $settings['settings'][ $id ] = array(
227                         'value'     => $setting->js_value(),
228                         'transport' => $setting->transport,
229                 );
230         }
231
232         foreach ( $wp_customize->controls() as $id => $control ) {
233                 $control->to_json();
234                 $settings['controls'][ $id ] = $control->json;
235         }
236
237         ?>
238         <script type="text/javascript">
239                 var _wpCustomizeSettings = <?php echo json_encode( $settings ); ?>;
240         </script>
241 </div>
242 </body>
243 </html>