class-foogallery-export-view-helper.php
3 days ago
class-foogallery-import-export-extension.php
3 days ago
class-foogallery-import-export.php
3 days ago
class-foogallery-import-view-helper.php
3 days ago
functions.php
3 days ago
view-import-export.php
3 days ago
class-foogallery-export-view-helper.php
131 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if ( ! class_exists( 'FooGallery_Export_View_Helper' ) ) { |
| 8 | |
| 9 | /** |
| 10 | * Class FooGallery_Export_View_Helper |
| 11 | */ |
| 12 | class FooGallery_Export_View_Helper { |
| 13 | /** |
| 14 | * Renders the export form for a number of galleries. |
| 15 | * |
| 16 | * @param $galleries |
| 17 | * @return void |
| 18 | */ |
| 19 | public function render_export_form( $galleries ) { |
| 20 | ?> |
| 21 | <style> |
| 22 | #foogallery_gallery_export_output { |
| 23 | width: 100%; |
| 24 | height: 500px; |
| 25 | } |
| 26 | </style> |
| 27 | <script> |
| 28 | jQuery(function ($) { |
| 29 | $('#foogallery_export_form').on('click', '.foogallery_gallery_export', function (e) { |
| 30 | e.preventDefault(); |
| 31 | |
| 32 | $('#foogallery_gallery_export_output_container').hide(); |
| 33 | $('.foogallery_export_spinner').addClass('is-active'); |
| 34 | |
| 35 | var data = { |
| 36 | action: 'foogallery_gallery_export', |
| 37 | galleries: $('#foogallery_export_form .foogallery_id:checkbox:checked').map(function() { |
| 38 | return this.value; |
| 39 | }).get(), |
| 40 | '_wpnonce' : $('#foogallery_gallery_export').val() |
| 41 | }; |
| 42 | |
| 43 | $.ajax({ |
| 44 | type: "POST", |
| 45 | url: ajaxurl, |
| 46 | data: data, |
| 47 | success: function(data) { |
| 48 | $('#foogallery_gallery_export_output').val(data); |
| 49 | $('#foogallery_gallery_export_output_container').show(); |
| 50 | }, |
| 51 | complete: function() { |
| 52 | $('.foogallery_export_spinner').removeClass('is-active'); |
| 53 | }, |
| 54 | error: function() { |
| 55 | //something went wrong! Alert the user and reload the page |
| 56 | alert('<?php esc_html_e( 'Something went wrong with the export!', 'foogallery' ); ?>'); |
| 57 | } |
| 58 | }); |
| 59 | }); |
| 60 | }); |
| 61 | </script> |
| 62 | <?php |
| 63 | wp_nonce_field( 'foogallery_gallery_export', 'foogallery_gallery_export', false ); |
| 64 | ?> |
| 65 | <form id="foogallery_export_form" method="POST"> |
| 66 | <table class="wp-list-table widefat" cellspacing="0"> |
| 67 | <thead> |
| 68 | <tr> |
| 69 | <td scope="col" id="cb" class="manage-column column-cb check-column"> |
| 70 | <label class="screen-reader-text" for="cb-select-all-1"><?php esc_html_e( 'Select All', 'foogallery' ); ?></label> |
| 71 | <input id="cb-select-all-1" type="checkbox" /> |
| 72 | </td> |
| 73 | <th scope="col" class="manage-column"> |
| 74 | <span><?php esc_html_e( 'Gallery Name', 'foogallery' ); ?></span> |
| 75 | </th> |
| 76 | <th scope="col" class="manage-column"> |
| 77 | <span><?php esc_html_e( 'Template', 'foogallery' ); ?></span> |
| 78 | </th> |
| 79 | <th scope="col" class="manage-column"> |
| 80 | <span><?php esc_html_e( 'Datasource', 'foogallery' ); ?></span> |
| 81 | </th> |
| 82 | <th scope="col" class="manage-column"> |
| 83 | <span><?php esc_html_e( 'Attachments', 'foogallery' ); ?></span> |
| 84 | </th> |
| 85 | </tr> |
| 86 | </thead> |
| 87 | <tbody> |
| 88 | <?php |
| 89 | $counter = 0; |
| 90 | foreach ( $galleries as $gallery ) { |
| 91 | $counter++; ?> |
| 92 | <tr class="<?php echo ($counter % 2 === 0) ? 'alternate' : ''; ?>"> |
| 93 | <th scope="row" class="column-cb check-column"> |
| 94 | <input name="foogallery-id[]" class="foogallery_id" type="checkbox" value="<?php echo esc_attr( $gallery->ID ); ?>"> |
| 95 | </th> |
| 96 | <td> |
| 97 | <?php echo esc_html( $gallery->name ); ?> |
| 98 | </td> |
| 99 | <td> |
| 100 | <?php echo esc_html( $gallery->gallery_template ); ?> |
| 101 | </td> |
| 102 | <td> |
| 103 | <?php echo esc_html( $gallery->datasource_name ); ?> |
| 104 | </td> |
| 105 | <td> |
| 106 | <?php |
| 107 | if ( 'media_library' === $gallery->datasource_name ) { |
| 108 | echo absint( $gallery->item_count() ); |
| 109 | } else { |
| 110 | echo '0'; |
| 111 | } |
| 112 | ?> |
| 113 | </td> |
| 114 | </tr> |
| 115 | <?php } ?> |
| 116 | </tbody> |
| 117 | </table> |
| 118 | <br /> |
| 119 | <input type="submit" name="foogallery_gallery_export" class="button button-primary foogallery_gallery_export" value="<?php esc_attr_e( 'Export', 'foogallery' ); ?>"> |
| 120 | <span class="foogallery_export_spinner spinner" style="float: none"></span> |
| 121 | </form> |
| 122 | <br /> |
| 123 | <div id="foogallery_gallery_export_output_container" style="display:none"> |
| 124 | <p><?php echo esc_html( __( 'Copy the export data below and paste it into the import form on the destination site.', 'foogallery' ) ); ?></p> |
| 125 | <textarea id="foogallery_gallery_export_output"></textarea> |
| 126 | </div> |
| 127 | <?php |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 |