dbt-export.php
6 years ago
dbt-import.php
6 years ago
dop-export.php
6 years ago
dop-import.php
6 years ago
dpt-export.php
6 years ago
dpt-import.php
6 years ago
dt-export.php
6 years ago
dt-import.php
6 years ago
fg-local.php
6 years ago
dop-export.php
184 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')) |
| 4 | exit; |
| 5 | |
| 6 | // Check setting |
| 7 | if(!acf_get_setting('acfe/modules/dynamic_options_pages')) |
| 8 | return; |
| 9 | |
| 10 | if(!class_exists('ACFE_Admin_Tool_Export_DOP')): |
| 11 | |
| 12 | class ACFE_Admin_Tool_Export_DOP extends ACF_Admin_Tool{ |
| 13 | |
| 14 | function initialize(){ |
| 15 | |
| 16 | // vars |
| 17 | $this->name = 'acfe_tool_dop_export'; |
| 18 | $this->title = __('Export Options Pages'); |
| 19 | $this->icon = 'dashicons-upload'; |
| 20 | |
| 21 | } |
| 22 | |
| 23 | function html(){ |
| 24 | |
| 25 | // vars |
| 26 | $choices = array(); |
| 27 | |
| 28 | $dynamic_options_pages = get_option('acfe_dynamic_options_pages', array()); |
| 29 | |
| 30 | if($dynamic_options_pages){ |
| 31 | foreach($dynamic_options_pages as $options_page_name => $args){ |
| 32 | |
| 33 | $choices[$options_page_name] = esc_html($args['page_title']); |
| 34 | |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | ?> |
| 39 | <p><?php _e('Export Options Pages', 'acf'); ?></p> |
| 40 | |
| 41 | <div class="acf-fields"> |
| 42 | <?php |
| 43 | |
| 44 | if(!empty($choices)){ |
| 45 | |
| 46 | // render |
| 47 | acf_render_field_wrap(array( |
| 48 | 'label' => __('Select Options Pages', 'acf'), |
| 49 | 'type' => 'checkbox', |
| 50 | 'name' => 'keys', |
| 51 | 'prefix' => false, |
| 52 | 'value' => false, |
| 53 | 'toggle' => true, |
| 54 | 'choices' => $choices, |
| 55 | )); |
| 56 | |
| 57 | } |
| 58 | |
| 59 | else{ |
| 60 | |
| 61 | echo '<div style="padding:15px 12px;">'; |
| 62 | _e('No options page available.'); |
| 63 | echo '</div>'; |
| 64 | |
| 65 | } |
| 66 | |
| 67 | ?> |
| 68 | </div> |
| 69 | |
| 70 | <?php |
| 71 | |
| 72 | $disabled = ''; |
| 73 | if(empty($choices)) |
| 74 | $disabled = 'disabled="disabled"'; |
| 75 | |
| 76 | ?> |
| 77 | |
| 78 | <p class="acf-submit"> |
| 79 | <button type="submit" name="action" class="button button-primary" value="download" <?php echo $disabled; ?>><?php _e('Export File'); ?></button> |
| 80 | </p> |
| 81 | <?php |
| 82 | |
| 83 | } |
| 84 | |
| 85 | function load(){ |
| 86 | |
| 87 | // check $_GET |
| 88 | if($this->is_active() && acf_maybe_get_GET('keys')){ |
| 89 | |
| 90 | $this->submit(); |
| 91 | |
| 92 | } |
| 93 | |
| 94 | } |
| 95 | |
| 96 | function submit(){ |
| 97 | |
| 98 | $json = $this->get_selected(); |
| 99 | |
| 100 | // validate |
| 101 | if($json === false) |
| 102 | return acf_add_admin_notice(__('No options page selected'), 'warning'); |
| 103 | |
| 104 | $keys = array(); |
| 105 | foreach($json as $key => $args){ |
| 106 | |
| 107 | $keys[] = $key; |
| 108 | |
| 109 | } |
| 110 | |
| 111 | // Prefix |
| 112 | $prefix = (count($keys) > 1) ? 'options-pages' : 'options-page'; |
| 113 | |
| 114 | // Slugs |
| 115 | $slugs = implode('-', $keys); |
| 116 | |
| 117 | // Date |
| 118 | $date = date('Y-m-d'); |
| 119 | |
| 120 | // file |
| 121 | $file_name = 'acfe-export-' . $prefix . '-' . $slugs . '-' . $date . '.json'; |
| 122 | |
| 123 | // headers |
| 124 | header("Content-Description: File Transfer"); |
| 125 | header("Content-Disposition: attachment; filename={$file_name}"); |
| 126 | header("Content-Type: application/json; charset=utf-8"); |
| 127 | |
| 128 | // return |
| 129 | echo acf_json_encode($json); |
| 130 | die; |
| 131 | |
| 132 | } |
| 133 | |
| 134 | function get_selected(){ |
| 135 | |
| 136 | // vars |
| 137 | $selected = $this->get_selected_keys(); |
| 138 | $json = array(); |
| 139 | |
| 140 | if(!$selected) |
| 141 | return false; |
| 142 | |
| 143 | $dynamic_options_pages = get_option('acfe_dynamic_options_pages', array()); |
| 144 | if(empty($dynamic_options_pages)) |
| 145 | return false; |
| 146 | |
| 147 | // construct JSON |
| 148 | foreach($selected as $key){ |
| 149 | |
| 150 | if(!isset($dynamic_options_pages[$key])) |
| 151 | continue; |
| 152 | |
| 153 | // add to json array |
| 154 | $json[$key] = $dynamic_options_pages[$key]; |
| 155 | |
| 156 | } |
| 157 | |
| 158 | // return |
| 159 | return $json; |
| 160 | |
| 161 | } |
| 162 | |
| 163 | function get_selected_keys(){ |
| 164 | |
| 165 | // check $_POST |
| 166 | if($keys = acf_maybe_get_POST('keys')) |
| 167 | return (array) $keys; |
| 168 | |
| 169 | // check $_GET |
| 170 | if($keys = acf_maybe_get_GET('keys')){ |
| 171 | $keys = str_replace(' ', '+', $keys); |
| 172 | return explode('+', $keys); |
| 173 | } |
| 174 | |
| 175 | // return |
| 176 | return false; |
| 177 | |
| 178 | } |
| 179 | |
| 180 | } |
| 181 | |
| 182 | acf_register_admin_tool('ACFE_Admin_Tool_Export_DOP'); |
| 183 | |
| 184 | endif; |