bulk-edit.php
7 years ago
col-sidebars.php
7 years ago
import.php
7 years ago
metabox.php
5 years ago
quick-edit.php
9 years ago
widgets-delete.php
8 years ago
widgets-editor.php
8 years ago
widgets-export.php
8 years ago
widgets-location.php
7 years ago
widgets.php
7 years ago
import.php
397 lines
| 1 | <?php |
| 2 | /** |
| 3 | * PRO section: Show interface for import preview. |
| 4 | */ |
| 5 | |
| 6 | global $wp_version; |
| 7 | |
| 8 | $import = CustomSidebarsExport::get_import_data(); |
| 9 | |
| 10 | $date_format = get_option( 'date_format' ) . ', ' . get_option( 'time_format' ); |
| 11 | $theme = wp_get_theme(); |
| 12 | $current_sidebars = CustomSidebars::get_custom_sidebars(); |
| 13 | $theme_sidebars = CustomSidebars::get_sidebars(); |
| 14 | $current_keys = array(); |
| 15 | foreach ( $current_sidebars as $c_sidebar ) { |
| 16 | $current_keys[] = $c_sidebar['id']; |
| 17 | } |
| 18 | |
| 19 | $csb_info = get_plugin_data( CSB_PLUGIN ); |
| 20 | |
| 21 | /** |
| 22 | * Helper function used only in this view. |
| 23 | * It renders a list with sidebar-replacement details |
| 24 | */ |
| 25 | if ( ! function_exists( 'list_sidebar_replacement' ) ) { |
| 26 | function list_sidebar_replacement( $label, $list ) { |
| 27 | $import = CustomSidebarsExport::get_import_data(); |
| 28 | $theme_sidebars = CustomSidebars::get_sidebars(); |
| 29 | if ( is_array( $list ) ) { |
| 30 | foreach ( $list as $from_id => $to_id ) { |
| 31 | $from = $theme_sidebars[ $from_id ]; |
| 32 | $to = array(); |
| 33 | if ( isset( $theme_sidebars[ $to_id ] ) ) { |
| 34 | $to = $theme_sidebars[ $to_id ]; |
| 35 | } else { |
| 36 | $to = $import['sidebars'][ $to_id ]; |
| 37 | } |
| 38 | ?> |
| 39 | <tr> |
| 40 | <th scope="row"><?php echo esc_html( $label ); ?></th> |
| 41 | <td><?php echo esc_html( $from['name'] ); ?></td> |
| 42 | <td><i class="dashicons dashicons-arrow-right-alt hint"></i></td> |
| 43 | <td><?php echo esc_html( $to['name'] ); ?></td> |
| 44 | </tr> |
| 45 | <?php |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | ?> |
| 51 | <div> |
| 52 | <div class="wpmui-form"> |
| 53 | <?php if ( ! empty( $import ) ) : ?> |
| 54 | <?php |
| 55 | /* ***************************************************************** |
| 56 | * |
| 57 | * Show basic infos about the WordPress configuration at time of |
| 58 | * the export. |
| 59 | */ |
| 60 | $filename = ''; |
| 61 | if ( |
| 62 | isset( $import['meta'] ) |
| 63 | && isset( $import['meta']['filename'] ) |
| 64 | ) { |
| 65 | $filename = $import['meta']['filename']; |
| 66 | } |
| 67 | ?> |
| 68 | <h2 class="no-pad-top"><?php _e( 'Import', 'custom-sidebars' ); ?></h2> |
| 69 | <div class="show-infos"> |
| 70 | <i class="dashicons dashicons-info"></i> |
| 71 | <div class="export-infos" style="display:none"> |
| 72 | <table cellspacing="1" cellpadding="4" class="csb-export-head"> |
| 73 | <tbody> |
| 74 | <tr> |
| 75 | <th><?php _e( 'Filename', 'custom-sidebars' ); ?></th> |
| 76 | <td colspan="2"><?php echo esc_html( $filename ); ?></td> |
| 77 | </tr> |
| 78 | <tr> |
| 79 | <th><?php _e( 'Exported on', 'custom-sidebars' ); ?></th> |
| 80 | <td colspan="2"><?php echo esc_html( ' ' . date( $date_format, $import['meta']['created'] ) ); ?></td> |
| 81 | </tr> |
| 82 | </tbody> |
| 83 | </table> |
| 84 | |
| 85 | <div class="section"><?php _e( 'WordPress Settings', 'custom-sidebars' ); ?></div> |
| 86 | <table cellspacing="1" cellpadding="4" class="csb-export-head"> |
| 87 | <thead> |
| 88 | <tr> |
| 89 | <th></th> |
| 90 | <td>Export</td> |
| 91 | <td>Current</td> |
| 92 | </tr> |
| 93 | </thead> |
| 94 | <tbody> |
| 95 | <tr> |
| 96 | <th><?php _e( 'WordPress Version', 'custom-sidebars' ); ?></th> |
| 97 | <td><?php echo esc_html( $import['meta']['wp_version'] ); ?></td> |
| 98 | <td><?php echo esc_html( $wp_version ); ?></td> |
| 99 | </tr> |
| 100 | <tr> |
| 101 | <th><?php _e( 'Plugin Version', 'custom-sidebars' ); ?></th> |
| 102 | <td><?php echo esc_html( $import['meta']['csb_version'] ); ?></td> |
| 103 | <td><?php echo esc_html( isset( $csb_info['Version'] )? $csb_info['Version'] : __( 'Unknown', 'custom-sidebars' ) ); ?></td> |
| 104 | </tr> |
| 105 | <tr> |
| 106 | <th><?php _e( 'Theme', 'custom-sidebars' ); ?></th> |
| 107 | <td><?php echo esc_html( $import['meta']['theme_name'] . ' (' . $import['meta']['theme_version'] . ')' ); ?></td> |
| 108 | <td><?php echo esc_html( $theme->get( 'Name' ) . ' (' . $theme->get( 'Version' ) . ')' ); ?></td> |
| 109 | </tr> |
| 110 | </tbody> |
| 111 | </table> |
| 112 | </div> |
| 113 | </div> |
| 114 | |
| 115 | <?php if ( ! empty( $import['meta']['description'] ) ) : ?> |
| 116 | <pre><?php echo esc_html( stripslashes( $import['meta']['description'] ) ); ?></pre> |
| 117 | <?php endif; ?> |
| 118 | |
| 119 | <form class="frm-import csb-form"> |
| 120 | <input type="hidden" name="do" value="import" /> |
| 121 | |
| 122 | <?php |
| 123 | /* ***************************************************************** |
| 124 | * |
| 125 | * List all sidebars in the import file |
| 126 | */ |
| 127 | $alternate = ''; |
| 128 | ?> |
| 129 | <h3 class="title"><?php _e( 'Custom Sidebars', 'custom-sidebars' ); ?></h3> |
| 130 | <p> |
| 131 | <?php _e( 'Mark the sidebars that you want to import.', 'custom-sidebars' ); ?> |
| 132 | </p> |
| 133 | <p> |
| 134 | <label for="import-widgets"> |
| 135 | <input type="checkbox" id="import-widgets" name="import_widgets" /> |
| 136 | <?php _e( 'Also import all widgets of the selected sidebars.', 'custom-sidebars' ); ?> |
| 137 | </label> |
| 138 | </p> |
| 139 | <table class="widefat"> |
| 140 | <thead> |
| 141 | <tr> |
| 142 | <th scope="col" id="cb" class="manage-column column-cb check-column"><input type="checkbox" /></th> |
| 143 | <th scope="col" id="name" class="manage-column column-name"><?php _e( 'Name', 'custom-sidebars' ); ?></th> |
| 144 | <th scope="col" id="description" class="manage-column column-description"><?php _e( 'Description', 'custom-sidebars' ); ?></th> |
| 145 | <th scope="col" id="note" class="manage-column column-note"><?php _e( 'Note', 'custom-sidebars' ); ?></th> |
| 146 | <th scope="col" id="widgets" class="manage-column column-widgets" style="display:none"><?php _e( 'Widgets', 'custom-sidebars' ); ?></th> |
| 147 | </tr> |
| 148 | </thead> |
| 149 | <tbody> |
| 150 | <?php |
| 151 | foreach ( $import['sidebars'] as $sidebar ) { |
| 152 | $alternate = ('' == $alternate ? 'alternate' : ''); |
| 153 | $note = __( 'New sidebar will be created', 'custom-sidebars' ); |
| 154 | if ( in_array( $sidebar['id'], $current_keys ) ) { |
| 155 | $note = __( 'Existing sidebar will be replaced!', 'custom-sidebars' ); |
| 156 | } |
| 157 | $import_sidebar = array(); |
| 158 | if ( |
| 159 | isset( $sidebar['id'] ) |
| 160 | && isset( $import['widgets'] ) |
| 161 | && isset( $import['widgets'][ $sidebar['id'] ] ) |
| 162 | && is_array( $import['widgets'][ $sidebar['id'] ] ) |
| 163 | ) { |
| 164 | $import_sidebar = $import['widgets'][ $sidebar['id'] ]; |
| 165 | } |
| 166 | $id = sprintf( 'import_sb_id_%s', $sidebar['id'] ); |
| 167 | ?> |
| 168 | <tr class="<?php echo esc_attr( $alternate ); ?>"> |
| 169 | <th scope="row" class="check-column"> |
| 170 | <input type="checkbox" name="import_sb_<?php echo esc_attr( $sidebar['id'] ); ?>" id="<?php echo esc_attr( $id ); ?>"/> |
| 171 | </th> |
| 172 | <td class="name column-name"><label for="<?php echo esc_attr( $id ); ?>"><?php echo esc_html( $sidebar['name'] ); ?></label></td> |
| 173 | <td class="description column-description"><?php echo esc_html( $sidebar['description'] ); ?></td> |
| 174 | <td class="note column-note"><?php echo esc_html( $note ); ?></td> |
| 175 | <td class="widgets column-widgets" style="display:none"> |
| 176 | <?php |
| 177 | if ( count( $import_sidebar ) ) { |
| 178 | echo '<ul>'; |
| 179 | foreach ( $import_sidebar as $key => $data ) { |
| 180 | printf( '<li>%s</li>', esc_html( $data['name'] ) ); |
| 181 | } |
| 182 | echo '</ul>'; |
| 183 | } else { |
| 184 | echo '-'; |
| 185 | } |
| 186 | ?> |
| 187 | </td> |
| 188 | </tr> |
| 189 | <?php |
| 190 | } |
| 191 | |
| 192 | |
| 193 | /* ***************************************************************** |
| 194 | * |
| 195 | * List all default theme sidebars that exist in the import file |
| 196 | */ |
| 197 | |
| 198 | foreach ( $theme_sidebars as $sidebar ) { |
| 199 | if ( isset( $import['widgets'][ $sidebar['id'] ] ) ) { |
| 200 | $alternate = ('' == $alternate ? 'alternate' : ''); |
| 201 | $import_sidebar = array(); |
| 202 | if ( |
| 203 | isset( $sidebar['id'] ) |
| 204 | && isset( $import['widgets'] ) |
| 205 | && isset( $import['widgets'][ $sidebar['id'] ] ) |
| 206 | ) { |
| 207 | $import_sidebar = $import['widgets'][ $sidebar['id'] ]; |
| 208 | } |
| 209 | if ( ! is_array( $import_sidebar ) ) { |
| 210 | $import_sidebar = array(); |
| 211 | } |
| 212 | if ( ! count( $import_sidebar ) ) { |
| 213 | continue; |
| 214 | } |
| 215 | $id = sprintf( 'import_sb_id_%s', $sidebar['id'] ); |
| 216 | ?> |
| 217 | <tr class="import-widgets <?php echo esc_attr( $alternate ); ?>" style="display: none"> |
| 218 | <th scope="row" class="check-column"> |
| 219 | <input type="checkbox" name="import_sb_<?php echo esc_attr( $sidebar['id'] ); ?>" id="<?php echo esc_attr( $id ); ?>"/> |
| 220 | </th> |
| 221 | <td class="name column-name"><label for="<?php echo esc_attr( $id ); ?>"><?php echo esc_html( $sidebar['name'] ); ?></label></td> |
| 222 | <td class="description column-description"><?php echo esc_html( $sidebar['description'] ); ?></td> |
| 223 | <td><em><?php _e( '(Theme sidebar)', 'custom-sidebars' ); ?></em></td> |
| 224 | <td class="widgets column-widgets"> |
| 225 | <?php |
| 226 | if ( count( $import_sidebar ) ) { |
| 227 | echo '<ul>'; |
| 228 | foreach ( $import_sidebar as $key => $data ) { |
| 229 | printf( '<li>%s</li>', esc_html( $data['name'] ) ); |
| 230 | } |
| 231 | echo '</ul>'; |
| 232 | } else { |
| 233 | echo '-'; |
| 234 | } |
| 235 | ?> |
| 236 | </td> |
| 237 | </tr> |
| 238 | <?php |
| 239 | } |
| 240 | } |
| 241 | ?> |
| 242 | </tbody> |
| 243 | </table> |
| 244 | <?php |
| 245 | /* ***************************************************************** |
| 246 | * |
| 247 | * Show the custom sidebar configuration |
| 248 | */ |
| 249 | ?> |
| 250 | <p> </p> |
| 251 | <h3 class="title"><?php _e( 'Configuration', 'custom-sidebars' ); ?> |
| 252 | <div class="show-infos"> |
| 253 | <i class="dashicons dashicons-info"></i> |
| 254 | <div class="export-infos" style="display:none"> |
| 255 | <div class="section"><?php _e( 'Replaceable Sidebars', 'custom-sidebars' ); ?></div> |
| 256 | <table cellspacing="1" cellpadding="4" class="csb-export-head"> |
| 257 | <tr> |
| 258 | <th scope="row"><?php _e( 'Replaceable Sidebars', 'custom-sidebars' ); ?></th> |
| 259 | <td> |
| 260 | <?php foreach ( $import['options']['modifiable'] as $sb_id ) : ?> |
| 261 | <?php echo esc_html( $theme_sidebars[ $sb_id ]['name'] ); ?><br /> |
| 262 | <?php endforeach; ?> |
| 263 | </td> |
| 264 | </tr> |
| 265 | </table> |
| 266 | <?php |
| 267 | /** |
| 268 | * single-posttype |
| 269 | */ |
| 270 | if ( |
| 271 | isset( $import['options'] ) |
| 272 | && isset( $import['options']['post_type_single'] ) |
| 273 | && is_array( $import['options']['post_type_single'] ) |
| 274 | ) { |
| 275 | printf( |
| 276 | '<div class="section">%s/div>', |
| 277 | esc_html__( 'By Post Type', 'custom-sidebars' ) |
| 278 | ); |
| 279 | echo '<table cellspacing="1" cellpadding="4" class="csb-export-head">'; |
| 280 | $list = $import['options']['post_type_single']; |
| 281 | $list['foo'] = array(); |
| 282 | foreach ( $list as $key => $values ) { |
| 283 | if ( ! count( $values ) ) { |
| 284 | continue; |
| 285 | } |
| 286 | /** |
| 287 | * check post type exists |
| 288 | */ |
| 289 | $type = get_post_type_object( $key ); |
| 290 | if ( ! is_a( $type, 'WP_Post_Type' ) ) { |
| 291 | continue; |
| 292 | } |
| 293 | list_sidebar_replacement( $type->labels->name, $values ); |
| 294 | } |
| 295 | echo '</table>'; |
| 296 | } |
| 297 | /** |
| 298 | * archive-posttype |
| 299 | */ |
| 300 | if ( |
| 301 | isset( $import['options'] ) |
| 302 | && isset( $import['options']['post_type_archive'] ) |
| 303 | && is_array( $import['options']['post_type_archive'] ) |
| 304 | ) { |
| 305 | ?> |
| 306 | <div class="section"><?php _e( 'Post-Type Archives', 'custom-sidebars' ); ?></div> |
| 307 | <table cellspacing="1" cellpadding="4" class="csb-export-head"> |
| 308 | <?php |
| 309 | $list = $import['options']['post_type_archive']; |
| 310 | foreach ( $list as $key => $values ) { |
| 311 | $type = get_post_type_object( $key ); |
| 312 | if ( ! count( $values ) ) { continue; } |
| 313 | list_sidebar_replacement( $type->labels->name, $values ); |
| 314 | } |
| 315 | echo '</table>'; |
| 316 | } |
| 317 | /* |
| 318 | * single-category |
| 319 | */ |
| 320 | if ( |
| 321 | isset( $import['options'] ) |
| 322 | && isset( $import['options']['category_single'] ) |
| 323 | && is_array( $import['options']['category_single'] ) |
| 324 | ) { |
| 325 | |
| 326 | ?> |
| 327 | <div class="section"><?php _e( 'By Category', 'custom-sidebars' ); ?></div> |
| 328 | <table cellspacing="1" cellpadding="4" class="csb-export-head"> |
| 329 | <?php |
| 330 | $list = $import['options']['category_single']; |
| 331 | foreach ( $list as $key => $values ) { |
| 332 | $cat = get_category( $key ); |
| 333 | if ( ! count( $values ) ) { continue; } |
| 334 | list_sidebar_replacement( $cat->name, $values ); |
| 335 | } |
| 336 | echo '</table>'; |
| 337 | } |
| 338 | /** |
| 339 | * archive-category |
| 340 | */ |
| 341 | if ( |
| 342 | isset( $import['options'] ) |
| 343 | && isset( $import['options']['category_archive'] ) |
| 344 | && is_array( $import['options']['category_archive'] ) |
| 345 | ) { |
| 346 | ?> |
| 347 | <div class="section"><?php _e( 'Category Archives', 'custom-sidebars' ); ?></div> |
| 348 | <table cellspacing="1" cellpadding="4" class="csb-export-head"> |
| 349 | <?php |
| 350 | $list = $import['options']['category_archive']; |
| 351 | foreach ( $list as $key => $values ) { |
| 352 | $cat = get_category( $key ); |
| 353 | if ( ! is_a( $cat, 'WP_Term' ) ) { |
| 354 | continue; |
| 355 | } |
| 356 | if ( ! count( $values ) ) { |
| 357 | continue; |
| 358 | } |
| 359 | list_sidebar_replacement( $cat->name, $values ); |
| 360 | } |
| 361 | echo '</table>'; |
| 362 | } |
| 363 | ?> |
| 364 | <?php /* special pages */ ?> |
| 365 | <div class="section"><?php _e( 'Special Pages', 'custom-sidebars' ); ?></div> |
| 366 | <table cellspacing="1" cellpadding="4" class="csb-export-head"> |
| 367 | <?php |
| 368 | list_sidebar_replacement( __( 'Main Blog Page', 'custom-sidebars' ), $import['options']['blog'] ); |
| 369 | list_sidebar_replacement( __( 'Date Archives', 'custom-sidebars' ), $import['options']['date'] ); |
| 370 | list_sidebar_replacement( __( 'Author Archives', 'custom-sidebars' ), $import['options']['authors'] ); |
| 371 | list_sidebar_replacement( __( 'Tag Archives', 'custom-sidebars' ), $import['options']['tags'] ); |
| 372 | list_sidebar_replacement( __( 'Search Results Page', 'custom-sidebars' ), $import['options']['search'] ); |
| 373 | ?> |
| 374 | </table> |
| 375 | </div> |
| 376 | </div> |
| 377 | </h3> |
| 378 | |
| 379 | <p> |
| 380 | <label for="import-config"> |
| 381 | <input type="checkbox" id="import-config" name="import_plugin_config" /> |
| 382 | <?php _e( 'Replace the current plugin configuration with the imported configuration.', 'custom-sidebars' ); ?> |
| 383 | </label> |
| 384 | </p> |
| 385 | |
| 386 | <input type="hidden" name="import_data" value="<?php echo esc_attr( base64_encode( json_encode( (object) $import ) ) ); ?>" /> |
| 387 | <p class="buttons"> |
| 388 | <button type="button" class="btn-cancel button-link">Cancel</button> |
| 389 | <button class="button-primary btn-import"><i class="dashicons dashicons-migrate"></i> Import selected items</button> |
| 390 | </p> |
| 391 | <?php wp_nonce_field( 'custom-sidebars-import' ); ?> |
| 392 | </form> |
| 393 | |
| 394 | <?php endif; ?> |
| 395 | </div> |
| 396 | </div> |
| 397 |