create-module
2 years ago
create-module.php
5 years ago
delete-module.php
6 years ago
import-module-settings-section.php
6 years ago
import-module.php
5 months ago
manage-tracking.php
6 years ago
import-module.php
268 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Dialog used in the modules' listing pages for importing modules. |
| 4 | * |
| 5 | * @package Hustle |
| 6 | * @since 4.0.0 |
| 7 | */ |
| 8 | |
| 9 | $is_ssharing = Hustle_Module_Model::SOCIAL_SHARING_MODULE === $this->admin->module_type; |
| 10 | $module_instance = Hustle_Module_Model::new_instance(); |
| 11 | |
| 12 | if ( ! $is_ssharing ) { |
| 13 | $smallcaps_singular = Opt_In_Utils::get_module_type_display_name( $this->admin->module_type ); |
| 14 | } |
| 15 | |
| 16 | ob_start(); |
| 17 | |
| 18 | $notice_options = array( |
| 19 | array( |
| 20 | 'type' => 'inline_notice', |
| 21 | 'id' => 'hustle-dialog--import-error-notice', |
| 22 | 'value' => '', |
| 23 | ), |
| 24 | ); |
| 25 | |
| 26 | $this->get_html_for_options( $notice_options ); |
| 27 | ?> |
| 28 | |
| 29 | <div class="sui-form-field"> |
| 30 | |
| 31 | <label class="sui-label"><?php esc_html_e( 'Configuration file', 'hustle' ); ?></label> |
| 32 | |
| 33 | <div class="sui-upload"> |
| 34 | |
| 35 | <input |
| 36 | id="hustle-import-file-input" |
| 37 | class="hustle-file-input" |
| 38 | type="file" |
| 39 | name="import_file" |
| 40 | value="" |
| 41 | readonly="readonly" |
| 42 | accept=".json" |
| 43 | /> |
| 44 | |
| 45 | <label class="sui-upload-button" type="button" for="hustle-import-file-input"> |
| 46 | <span class="sui-icon-upload-cloud" aria-hidden="true"></span> <?php esc_html_e( 'Upload file', 'hustle' ); ?> |
| 47 | </label> |
| 48 | |
| 49 | <div class="sui-upload-file"> |
| 50 | |
| 51 | <span></span> |
| 52 | |
| 53 | <button type="button" aria-label="Remove file"> |
| 54 | <span class="sui-icon-close" aria-hidden="true"></span> |
| 55 | </button> |
| 56 | |
| 57 | </div> |
| 58 | |
| 59 | </div> |
| 60 | |
| 61 | <span class="sui-description" style="margin-top: 10px;"><?php esc_html_e( 'Choose the configuration file (.json) to import the settings from.', 'hustle' ); ?></span> |
| 62 | |
| 63 | </div> |
| 64 | |
| 65 | <div id="hustle-import-modal-options" class="sui-form-field"></div> |
| 66 | |
| 67 | <?php |
| 68 | $body_content = ob_get_clean(); |
| 69 | |
| 70 | $attributes = array( |
| 71 | 'modal_id' => 'import', |
| 72 | 'has_description' => true, |
| 73 | 'modal_size' => 'md', |
| 74 | 'sui_box_tag' => 'form', |
| 75 | 'sui_box_id' => 'hustle-import-module-form', |
| 76 | |
| 77 | 'header' => array( |
| 78 | 'classes' => 'sui-flatten sui-content-center sui-spacing-top--60', |
| 79 | /* translators: current module type display name capitalized and singular */ |
| 80 | 'title' => sprintf( __( 'Import %s', 'hustle' ), $capitalize_singular ), |
| 81 | 'title_classes' => 'sui-lg', |
| 82 | 'description' => __( "Choose the configuration file and the settings you want to import. We'll import the settings which are available and apply them to this module and keep the other settings to their default values.", 'hustle' ), |
| 83 | ), |
| 84 | 'body' => array( |
| 85 | 'content' => $body_content, |
| 86 | ), |
| 87 | 'footer' => array( |
| 88 | 'classes' => 'sui-content-separated', |
| 89 | 'buttons' => array( |
| 90 | array( |
| 91 | 'classes' => 'sui-button-ghost', |
| 92 | 'text' => __( 'Cancel', 'hustle' ), |
| 93 | 'is_close' => true, |
| 94 | ), |
| 95 | array( |
| 96 | 'id' => 'hustle-import-module-submit-button', |
| 97 | 'classes' => 'hustle-single-module-button-action', |
| 98 | 'icon' => 'upload-cloud', |
| 99 | 'has_load' => true, |
| 100 | 'text' => __( 'Import', 'hustle' ), |
| 101 | 'attributes' => array( |
| 102 | 'data-hustle-action' => 'import', |
| 103 | 'data-form-id' => 'hustle-import-module-form', |
| 104 | 'data-type' => $this->admin->module_type, |
| 105 | 'disabled' => 'disabled', |
| 106 | ), |
| 107 | ), |
| 108 | ), |
| 109 | ), |
| 110 | ); |
| 111 | |
| 112 | $this->render_modal( $attributes ); |
| 113 | ?> |
| 114 | |
| 115 | <script id="hustle-import-modal-options-tpl" type="text/template"> |
| 116 | |
| 117 | <?php |
| 118 | /** |
| 119 | * Non Social Sharing Markup. |
| 120 | * We have different set of settings for an "optin" and an "informational" module, |
| 121 | * reason why we need to split these import settings from social sharing settings |
| 122 | * to avoid any error in the future. |
| 123 | */ |
| 124 | if ( ! $is_ssharing ) : |
| 125 | ?> |
| 126 | |
| 127 | <# if ( isNew ) { #> |
| 128 | |
| 129 | <label class="sui-label"><?php esc_html_e( 'Module type', 'hustle' ); ?></label> |
| 130 | |
| 131 | <div class="sui-tabs sui-side-tabs"> |
| 132 | |
| 133 | <input tabindex="-1" type="radio" name="module_mode" value="default" id="hustle-import-options--default" style="display: none;" aria-hidden="true" hidden checked /> |
| 134 | <input tabindex="-1" type="radio" name="module_mode" value="<?php echo esc_attr( Hustle_Module_Model::OPTIN_MODE ); ?>" id="hustle-import-options--optin" style="display: none;" aria-hidden="true" hidden /> |
| 135 | <input tabindex="-1" type="radio" name="module_mode" value="<?php echo esc_attr( Hustle_Module_Model::INFORMATIONAL_MODE ); ?>" id="hustle-import-options--info" style="display: none;" aria-hidden="true" hidden /> |
| 136 | |
| 137 | <div role="tablist" class="sui-tabs-menu"> |
| 138 | |
| 139 | <button |
| 140 | type="button" |
| 141 | role="tab" |
| 142 | id="hustle-import-options--default-tab" |
| 143 | class="sui-tab-item active" |
| 144 | aria-controls="hustle-import-options--default-content" |
| 145 | aria-selected="true" |
| 146 | data-label-for="hustle-import-options--default" |
| 147 | > |
| 148 | <?php esc_html_e( 'Default', 'hustle' ); ?> |
| 149 | </button> |
| 150 | |
| 151 | <button |
| 152 | type="button" |
| 153 | role="tab" |
| 154 | id="hustle-import-options--optin-tab" |
| 155 | class="sui-tab-item" |
| 156 | aria-controls="hustle-import-options--optin-content" |
| 157 | aria-selected="false" |
| 158 | data-label-for="hustle-import-options--optin" |
| 159 | > |
| 160 | <?php esc_html_e( 'Email Opt-in', 'hustle' ); ?> |
| 161 | </button> |
| 162 | |
| 163 | <button |
| 164 | type="button" |
| 165 | role="tab" |
| 166 | id="hustle-import-options--info-tab" |
| 167 | class="sui-tab-item" |
| 168 | aria-controls="hustle-import-options--info-content" |
| 169 | aria-selected="false" |
| 170 | data-label-for="hustle-import-options--info" |
| 171 | > |
| 172 | <?php esc_html_e( 'Informational', 'hustle' ); ?> |
| 173 | </button> |
| 174 | |
| 175 | </div> |
| 176 | |
| 177 | <div class="sui-tabs-content"> |
| 178 | |
| 179 | <div |
| 180 | role="tabpanel" |
| 181 | tabindex="0" |
| 182 | id="hustle-import-options--optin-content" |
| 183 | class="sui-tab-content sui-border-frame" |
| 184 | aria-labelledby="hustle-import-options--optin-tab" |
| 185 | > |
| 186 | |
| 187 | <?php |
| 188 | $this->render( |
| 189 | 'admin/commons/sui-listing/dialogs/import-module-settings-section', |
| 190 | array( |
| 191 | 'metas' => $module_instance->get_module_meta_names( $this->admin->module_type, Hustle_Module_Model::OPTIN_MODE, true ), |
| 192 | 'id' => 'optin', |
| 193 | ) |
| 194 | ); |
| 195 | ?> |
| 196 | |
| 197 | </div> |
| 198 | |
| 199 | <div |
| 200 | role="tabpanel" |
| 201 | tabindex="0" |
| 202 | id="hustle-import-options--info-content" |
| 203 | class="sui-tab-content sui-border-frame" |
| 204 | aria-labelledby="hustle-import-options--info-tab" |
| 205 | hidden |
| 206 | > |
| 207 | |
| 208 | <?php |
| 209 | $this->render( |
| 210 | 'admin/commons/sui-listing/dialogs/import-module-settings-section', |
| 211 | array( |
| 212 | 'metas' => $module_instance->get_module_meta_names( $this->admin->module_type, Hustle_Module_Model::INFORMATIONAL_MODE, true ), |
| 213 | 'id' => 'info', |
| 214 | ) |
| 215 | ); |
| 216 | ?> |
| 217 | |
| 218 | </div> |
| 219 | |
| 220 | </div> |
| 221 | |
| 222 | <?php /* translators: module type in small caps and in singular. */ ?> |
| 223 | <p class="sui-description"><?php printf( esc_html__( 'Choose the module type of the %s you want to create. The default is to take the module type from the configuration file and import all the settings from it.', 'hustle' ), esc_html( $smallcaps_singular ) ); ?></p> |
| 224 | |
| 225 | </div> |
| 226 | |
| 227 | <# } else { #> |
| 228 | |
| 229 | <# if ( isOptin ) { #> |
| 230 | <?php |
| 231 | $this->render( |
| 232 | 'admin/commons/sui-listing/dialogs/import-module-settings-section', |
| 233 | array( |
| 234 | 'metas' => $module_instance->get_module_meta_names( $this->admin->module_type, Hustle_Module_Model::OPTIN_MODE, true ), |
| 235 | 'id' => 'optin', |
| 236 | ) |
| 237 | ); |
| 238 | ?> |
| 239 | <# } else { #> |
| 240 | <?php |
| 241 | $this->render( |
| 242 | 'admin/commons/sui-listing/dialogs/import-module-settings-section', |
| 243 | array( |
| 244 | 'metas' => $module_instance->get_module_meta_names( $this->admin->module_type, Hustle_Module_Model::INFORMATIONAL_MODE, true ), |
| 245 | 'id' => 'info', |
| 246 | ) |
| 247 | ); |
| 248 | ?> |
| 249 | <# } #> |
| 250 | |
| 251 | <# } #> |
| 252 | |
| 253 | <?php else : ?> |
| 254 | |
| 255 | <?php |
| 256 | $this->render( |
| 257 | 'admin/commons/sui-listing/dialogs/import-module-settings-section', |
| 258 | array( |
| 259 | 'metas' => $module_instance->get_module_meta_names( $this->admin->module_type, '', true ), |
| 260 | 'id' => 'ssharing', |
| 261 | ) |
| 262 | ) |
| 263 | ?> |
| 264 | |
| 265 | <?php endif; ?> |
| 266 | |
| 267 | </script> |
| 268 |