1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Admin Page Framework |
4
|
|
|
* |
5
|
|
|
* http://admin-page-framework.michaeluno.jp/ |
6
|
|
|
* Copyright (c) 2013-2020, Michael Uno; Licensed MIT |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Defines the `submit` field type. |
12
|
|
|
* |
13
|
|
|
* <h2>Field Definition Arguments</h2> |
14
|
|
|
* <h3>Field Type Specific Arguments</h3> |
15
|
|
|
* <ul> |
16
|
|
|
* <li>**href** - (optional, string) the url(s) linked to the submit button.</li> |
17
|
|
|
* <li>**redirect_url** - (optional, string) the url(s) redirected to after submitting the input form.</li> |
18
|
|
|
* <li>**reset** - [2.1.2+] (optional, boolean|string|array) the option key to delete. Set 1 for the entire option. [3.5.3+] In order to reset a particular field that belongs to a section, set an array representing the dimensional keys such as `array( 'my_sectio_id', 'my_field_id' )`.</li> |
19
|
|
|
* <li>**confirm** - [3.8.24+] (optional, string|array) A confirmation checkbox to be enabled. If non-empty value is set, it will appear. An empty string by default. An array of the following arguments is accepted. |
20
|
|
|
* <ul> |
21
|
|
|
* <li>**label** - (string) the checkbox label.</li> |
22
|
|
|
* <li>**error** - (string) the error message to display when the user does not check it but presses the submit button.</li> |
23
|
|
|
* </ul> |
24
|
|
|
* </li> |
25
|
|
|
* <li>**skip_confirmation** - [3.7.6+] (optional, boolean) Whether to skip confirmation. Default: `false`.</li> |
26
|
|
|
* <li>**email** - [3.3.0+] (optional, array) Coming soon... |
27
|
|
|
* <ul> |
28
|
|
|
* <li>**to** - (string|array) the email address to send the email to. For multiple email addressed, set comma delimited items.</li> |
29
|
|
|
* <li>**subject** - (string|array) the email title.</li> |
30
|
|
|
* <li>**message** - (string|array) the email body text.</li> |
31
|
|
|
* <li>**attachments** - (string|array) the file path.</li> |
32
|
|
|
* <li>**name** - (string|array) the sender name.</li> |
33
|
|
|
* <li>**from** - (string|array) the sender email.</li> |
34
|
|
|
* <li>**is_html** - (boolean|array) indicates whether the message should be sent as an html or plain text.</li> |
35
|
|
|
* </ul> |
36
|
|
|
* </li> |
37
|
|
|
* </ul> |
38
|
|
|
* |
39
|
|
|
* <h3>Common Field Definition Arguments</h3> |
40
|
|
|
* For common field definition arguments, see {@link AdminPageFramework_Factory_Controller::addSettingField()}. |
41
|
|
|
* |
42
|
|
|
* <h2>Example</h2> |
43
|
|
|
* <code> |
44
|
|
|
* array( |
45
|
|
|
* 'field_id' => 'submit_button_field', |
46
|
|
|
* 'title' => __( 'Submit Button', 'admin-page-framework-loader' ), |
47
|
|
|
* 'type' => 'submit', |
48
|
|
|
* 'save' => false, |
49
|
|
|
* ) |
50
|
|
|
* </code> |
51
|
|
|
* <h3>Submit Button as a Link</h3> |
52
|
|
|
* <code> |
53
|
|
|
* array( |
54
|
|
|
* 'field_id' => 'submit_button_link', |
55
|
|
|
* 'type' => 'submit', |
56
|
|
|
* 'title' => __( 'Link Button', 'admin-page-framework-loader' ), |
57
|
|
|
* 'label' => 'WordPress', |
58
|
|
|
* 'href' => 'https://wordpress.org', |
59
|
|
|
* 'attributes' => array( |
60
|
|
|
* 'class' => 'button button-secondary', |
61
|
|
|
* 'title' => __( 'Go to Google!', 'admin-page-framework-loader' ), |
62
|
|
|
* 'style' => 'background-color: #C1DCFA;', |
63
|
|
|
* 'field' => array( |
64
|
|
|
* 'style' => 'display: inline; clear: none;', |
65
|
|
|
* ), |
66
|
|
|
* ), |
67
|
|
|
* ) |
68
|
|
|
* </code> |
69
|
|
|
* <h3>Download Button</h3> |
70
|
|
|
* <code> |
71
|
|
|
* array( |
72
|
|
|
* 'field_id' => 'submit_button_download', |
73
|
|
|
* 'title' => __( 'Download Button', 'admin-page-framework-loader' ), |
74
|
|
|
* 'type' => 'submit', |
75
|
|
|
* 'label' => __( 'Admin Page Framework', 'admin-page-framework-loader' ), |
76
|
|
|
* 'href' => 'http://downloads.wordpress.org/plugin/admin-page-framework.latest-stable.zip', |
77
|
|
|
* ) |
78
|
|
|
* </code> |
79
|
|
|
* |
80
|
|
|
* <h3>Redirect Button</h3> |
81
|
|
|
* Unlike the `href` argument, with the `redirect` argument, the form data will be saved and the user gets redirected. |
82
|
|
|
* <code> |
83
|
|
|
* array( |
84
|
|
|
* 'field_id' => 'submit_button_redirect', |
85
|
|
|
* 'title' => __( 'Redirect Button', 'admin-page-framework-loader' ), |
86
|
|
|
* 'type' => 'submit', |
87
|
|
|
* 'label' => __( 'Dashboard', 'admin-page-framework-loader' ), |
88
|
|
|
* 'redirect_url' => admin_url(), |
89
|
|
|
* 'attributes' => array( |
90
|
|
|
* 'class' => 'button button-secondary', |
91
|
|
|
* ), |
92
|
|
|
* ) |
93
|
|
|
* </code> |
94
|
|
|
* |
95
|
|
|
* <h3>Submit Button with an Image</h3> |
96
|
|
|
* Instead of a text label, an image can be used for the button. |
97
|
|
|
* <code> |
98
|
|
|
* array( |
99
|
|
|
* 'field_id' => 'image_submit_button', |
100
|
|
|
* 'title' => __( 'Image Submit Button', 'admin-page-framework-loader' ), |
101
|
|
|
* 'type' => 'submit', |
102
|
|
|
* 'href' => 'http://en.michaeluno.jp/donate', |
103
|
|
|
* 'attributes' => array( |
104
|
|
|
* 'src' => AdminPageFrameworkLoader_Registry::$sDirPath . '/asset/image/donation.gif', |
105
|
|
|
* 'alt' => __( 'Submit', 'admin-page-framework-loader' ), |
106
|
|
|
* 'class' => '', |
107
|
|
|
* ), |
108
|
|
|
* ) |
109
|
|
|
* </code> |
110
|
|
|
* |
111
|
|
|
* <h3>Reset Button</h3> |
112
|
|
|
* With the `reset` argument, the user can reset stored form data. |
113
|
|
|
* <code> |
114
|
|
|
* array( |
115
|
|
|
* 'field_id' => 'submit_button_reset', |
116
|
|
|
* 'title' => __( 'Reset Button', 'admin-page-framework-loader' ), |
117
|
|
|
* 'type' => 'submit', |
118
|
|
|
* 'label' => __( 'Reset', 'admin-page-framework-loader' ), |
119
|
|
|
* 'reset' => true, |
120
|
|
|
* 'attributes' => array( |
121
|
|
|
* 'class' => 'button button-secondary', |
122
|
|
|
* ), |
123
|
|
|
* ) |
124
|
|
|
* </code> |
125
|
|
|
* |
126
|
|
|
* <h3>Email</h3> |
127
|
|
|
* With the `email` argument, the user can send form data as an email. |
128
|
|
|
* <code> |
129
|
|
|
* $this->addSettingFields( |
130
|
|
|
* 'report', // section ID |
131
|
|
|
* array( |
132
|
|
|
* 'field_id' => 'name', |
133
|
|
|
* 'title' => __( 'Your Name', 'admin-page-framework-loader' ), |
134
|
|
|
* 'type' => 'text', |
135
|
|
|
* 'attributes' => array( |
136
|
|
|
* 'required' => 'required', |
137
|
|
|
* 'placeholder' => __( 'Type your name.', 'admin-page-framewrok-demo' ), |
138
|
|
|
* ), |
139
|
|
|
* ), |
140
|
|
|
* array( |
141
|
|
|
* 'field_id' => 'from', |
142
|
|
|
* 'title' => __( 'Your Email Address', 'admin-page-framework-loader' ), |
143
|
|
|
* 'type' => 'text', |
144
|
|
|
* 'default' => $_oCurrentUser->user_email, |
145
|
|
|
* 'attributes' => array( |
146
|
|
|
* 'required' => 'required', |
147
|
|
|
* 'placeholder' => __( 'Type your email that the developer replies backt to.', 'admin-page-framework-loader' ) |
148
|
|
|
* ), |
149
|
|
|
* ), |
150
|
|
|
* array( |
151
|
|
|
* 'field_id' => 'message', |
152
|
|
|
* 'title' => __( 'Message', 'admin-page-framework-loader' ), |
153
|
|
|
* 'type' => 'textarea', |
154
|
|
|
* 'attributes' => array( |
155
|
|
|
* 'required' => 'required', |
156
|
|
|
* ), |
157
|
|
|
* ), |
158
|
|
|
* |
159
|
|
|
* array( |
160
|
|
|
* 'field_id' => 'send', |
161
|
|
|
* 'type' => 'submit', |
162
|
|
|
* 'label_min_width' => 0, |
163
|
|
|
* 'value' => $oFactory->oUtil->getAOrB( |
164
|
|
|
* 'email' === $oFactory->oUtil->getElement( $_GET, 'confirmation' ), |
165
|
|
|
* __( 'Send', 'admin-page-framework-demo' ), |
166
|
|
|
* __( 'Preview', 'admin-page-framework-demo' ) |
167
|
|
|
* ), |
168
|
|
|
* 'email' => array( |
169
|
|
|
* // Each argument can accept a string or an array representing the dimensional array key. |
170
|
|
|
* // For example, if there is a field for the email title, and its section id is 'my_section' and the field id is 'my_field', pass an array, array( 'my_section', 'my_field' ) |
171
|
|
|
* 'to' => '[email protected]', |
172
|
|
|
* 'subject' => 'Reporting Issue', |
173
|
|
|
* 'message' => array( 'report', 'message' ), // the section name enclosed in an array. If it is a field, set it to the second element like array( 'seciton id', 'field id' ). |
174
|
|
|
* 'headers' => '', |
175
|
|
|
* 'attachments' => '', // the file path(s) |
176
|
|
|
* 'name' => '', // The email sender name. If the 'name' argument is empty, the field named 'name' in this section will be applied |
177
|
|
|
* 'from' => '', // The sender email address. If the 'from' argument is empty, the field named 'from' in this section will be applied. |
178
|
|
|
* // 'is_html' => true, |
179
|
|
|
* ), |
180
|
|
|
* ) |
181
|
|
|
* ); |
182
|
|
|
* </code> |
183
|
|
|
* |
184
|
|
|
* @image http://admin-page-framework.michaeluno.jp/image/common/form/field_type/submit.png |
185
|
|
|
* @package AdminPageFramework/Common/Form/FieldType |
186
|
|
|
* @since 2.1.5 |
187
|
|
|
* @since 3.3.1 Changed to extend `AdminPageFramework_FieldType` from `AdminPageFramework_FieldType_Base`. |
188
|
|
|
*/ |
189
|
|
|
class AdminPageFramework_FieldType_submit extends AdminPageFramework_FieldType { |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Defines the field type slugs used for this field type. |
193
|
|
|
*/ |
194
|
|
|
public $aFieldTypeSlugs = array( 'submit', ); |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Defines the default key-values of this field type. |
198
|
|
|
* |
199
|
|
|
* @remark $_aDefaultKeys holds shared default key-values defined in the base class. |
200
|
|
|
*/ |
201
|
|
|
protected $aDefaultKeys = array( |
202
|
|
|
'redirect_url' => null, |
203
|
|
|
'href' => null, |
204
|
|
|
'reset' => null, |
205
|
|
|
'email' => null, // [3.3.0+] string of an email address to send to or it can be an array with the following keys. |
206
|
|
|
'confirm' => '', |
207
|
|
|
/* |
208
|
|
|
array( |
209
|
|
|
'to' => null, // string|array The email address to send to or an array representing the key structure of the submitted form data holding the value. The first key should be the section ID and the second key is the the field ID. |
210
|
|
|
'subject' => null, // string|array The email title or an array representing the key structure of the submitted form data holding the value. The first key should be the section ID and the second key is the the field ID. |
211
|
|
|
'message' => null, // string|array The email body or an array representing the key structure of the submitted form data holding the value. The first key should be the section ID and the second key is the the field ID. |
212
|
|
|
'headers' => null, // string|array The email header or an array representing the key structure of the submitted form data holding the value. The first key should be the section ID and the second key is the the field ID. |
213
|
|
|
'attachments' => null, // string|array The file path(s) or an array representing the key structure of the submitted form data holding the value. The first key should be the section ID and the second key is the the field ID. |
214
|
|
|
) |
215
|
|
|
*/ |
216
|
|
|
'skip_confirmation' => false, // 3.7.6+ For emails. |
217
|
|
|
'attributes' => array( |
218
|
|
|
'class' => 'button button-primary', |
219
|
|
|
), |
220
|
|
|
); |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Returns the field type specific CSS rules. |
224
|
|
|
* |
225
|
|
|
* @since 2.1.5 |
226
|
|
|
* @since 3.3.1 Changed from `_replyToGetStyles()`. |
227
|
|
|
* @internal |
228
|
|
|
* @return string |
229
|
|
|
*/ |
230
|
|
|
protected function getStyles() { |
231
|
|
|
return <<<CSSRULES |
232
|
|
|
/* Submit Buttons */ |
233
|
|
|
.admin-page-framework-field input[type='submit'] { |
234
|
|
|
margin-bottom: 0.5em; |
235
|
|
|
} |
236
|
|
|
/* Confirmation */ |
237
|
|
|
.admin-page-framework-field-submit .submit-confirm-container { |
238
|
|
|
display: inline-block; |
239
|
|
|
margin-left: 1em; |
240
|
|
|
vertical-align: middle; |
241
|
|
|
} |
242
|
|
|
.admin-page-framework-field-submit .field-error.submit-confirmation-warning { |
243
|
|
|
float: none; |
244
|
|
|
} |
245
|
|
|
CSSRULES; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Returns the field type specific JavaScript script. |
250
|
|
|
* |
251
|
|
|
* @since 3.8.24 |
252
|
|
|
* @internal |
253
|
|
|
*/ |
254
|
|
|
protected function getScripts() { |
255
|
|
|
return <<<JAVASCRIPTS |
256
|
|
|
jQuery( document ).ready( function(){ |
257
|
|
|
jQuery( '.admin-page-framework-field-submit .submit-confirm-container input[type=checkbox]' ).each( function( index, value ){ |
258
|
|
|
jQuery( this ).closest( '.admin-page-framework-field-submit' ).find( 'input[type=submit]' ).click( function( event ){ |
259
|
|
|
var _fieldSubmit = jQuery( this ).closest( '.admin-page-framework-field-submit' ); |
260
|
|
|
_fieldSubmit.find( '.submit-confirmation-warning' ).remove(); // previous error message |
261
|
|
|
var _confirmCheckbox = jQuery( this ).closest( '.admin-page-framework-field-submit' ).find( '.submit-confirm-container input[type=checkbox]' ); |
262
|
|
|
if ( ! _confirmCheckbox.length ) { |
263
|
|
|
return true; |
264
|
|
|
} |
265
|
|
|
if ( _confirmCheckbox.is( ':checked' ) ) { |
266
|
|
|
return true; |
267
|
|
|
} |
268
|
|
|
// At this point, the checkbox is not checked. |
269
|
|
|
var _sErrorTag = "<p class='field-error submit-confirmation-warning'><span>* " + _confirmCheckbox.attr( 'data-error-message' ) + "</span></p>"; |
270
|
|
|
_fieldSubmit.find( '.submit-confirm-container' ).append( _sErrorTag ); |
271
|
|
|
return false; |
272
|
|
|
} ); |
273
|
|
|
}); |
274
|
|
|
}); |
275
|
|
|
JAVASCRIPTS; |
276
|
|
|
|
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Returns the output of the field type. |
281
|
|
|
* |
282
|
|
|
* @since 2.1.5 Moved from `AdminPageFramework_FormField`. |
283
|
|
|
* @since 3.3.1 Changed from `_replyToGetField()`. |
284
|
|
|
* @internal |
285
|
|
|
* @param array $aField |
286
|
|
|
* @return string |
287
|
|
|
*/ |
288
|
|
|
protected function getField( $aField ) { |
289
|
|
|
|
290
|
|
|
$aField = $this->___getFormattedFieldArray( $aField ); |
291
|
|
|
$_aInputAttributes = $this->_getInputAttributes( $aField ); |
292
|
|
|
$_aLabelAttributes = $this->_getLabelAttributes( $aField, $_aInputAttributes ); |
293
|
|
|
$_aLabelContainerAttributes = $this->_getLabelContainerAttributes( $aField ); |
294
|
|
|
|
295
|
|
|
return |
296
|
|
|
$aField[ 'before_label' ] |
297
|
|
|
. "<div " . $this->getAttributes( $_aLabelContainerAttributes ) . ">" |
298
|
|
|
. $this->_getExtraFieldsBeforeLabel( $aField ) // this is for the import field type that cannot place file input tag inside the label tag. |
299
|
|
|
. "<label " . $this->getAttributes( $_aLabelAttributes ) . ">" |
300
|
|
|
. $aField[ 'before_input' ] |
301
|
|
|
. $this->_getExtraInputFields( $aField ) |
302
|
|
|
. "<input " . $this->getAttributes( $_aInputAttributes ) . " />" // this method is defined in the base class |
303
|
|
|
. $aField[ 'after_input' ] |
304
|
|
|
. "</label>" |
305
|
|
|
. $this->___getConfirmationCheckbox( $aField ) |
306
|
|
|
. "</div>" |
307
|
|
|
. $aField['after_label']; |
308
|
|
|
|
309
|
|
|
} |
310
|
|
|
/** |
311
|
|
|
* @param array $aField |
312
|
|
|
* @return string |
313
|
|
|
* @since 3.8.24 |
314
|
|
|
*/ |
315
|
|
|
private function ___getConfirmationCheckbox( $aField ) { |
316
|
|
|
if ( empty( $aField[ 'confirm' ] ) ) { |
317
|
|
|
return ''; |
318
|
|
|
} |
319
|
|
|
$_aConfirm = is_string( $aField[ 'confirm' ] ) |
320
|
|
|
? array( |
321
|
|
|
'label' => $aField[ 'confirm' ] |
322
|
|
|
) |
323
|
|
|
: $this->getAsArray( $aField[ 'confirm' ] ); |
324
|
|
|
$_aConfirm = $_aConfirm + array( |
325
|
|
|
'label' => $this->oMsg->get( 'submit_confirmation_label' ), |
326
|
|
|
'error' => $this->oMsg->get( 'submit_confirmation_error' ), |
327
|
|
|
); |
328
|
|
|
$_aAttributes = $this->getElementAsArray( $aField, array( 'attributes', 'confirm' ) ); |
329
|
|
|
$_sInput = $this->getHTMLTag( |
330
|
|
|
'input', |
331
|
|
|
array( |
332
|
|
|
'type' => 'checkbox', |
333
|
|
|
'name' => "{$aField[ 'input_id' ]}[confirm]", |
334
|
|
|
'class' => 'confirm-submit', |
335
|
|
|
'value' => 0, // unchecked by default |
336
|
|
|
'data-error-message' => $_aConfirm[ 'error' ], |
337
|
|
|
) + $_aAttributes |
338
|
|
|
); |
339
|
|
|
return "<p class='submit-confirm-container'><label>" |
340
|
|
|
. $_sInput |
341
|
|
|
. "<span>{$_aConfirm[ 'label' ]}</span>" |
342
|
|
|
. "</label></p>"; |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* Returns the formatted field definition array. |
347
|
|
|
* |
348
|
|
|
* @since 3.5.3 |
349
|
|
|
* @param array $aField |
350
|
|
|
* @return array The formatted field definition array. |
351
|
|
|
* @internal |
352
|
|
|
*/ |
353
|
|
|
private function ___getFormattedFieldArray( array $aField ) { |
354
|
|
|
|
355
|
|
|
$aField[ 'label' ] = $aField[ 'label' ] |
356
|
|
|
? $aField[ 'label' ] |
357
|
|
|
: $this->oMsg->get( 'submit' ); |
358
|
|
|
|
359
|
|
|
if ( isset( $aField[ 'attributes' ][ 'src' ] ) ) { |
360
|
|
|
$aField[ 'attributes' ][ 'src' ] = esc_url( $this->getResolvedSRC( $aField[ 'attributes' ][ 'src' ] ) ); |
361
|
|
|
} |
362
|
|
|
return $aField; |
363
|
|
|
|
364
|
|
|
} |
365
|
|
|
/** |
366
|
|
|
* Returns the label attribute array. |
367
|
|
|
* |
368
|
|
|
* @since 3.5.3 |
369
|
|
|
* @return array The label attribute array. |
370
|
|
|
* @internal |
371
|
|
|
*/ |
372
|
|
|
private function _getLabelAttributes( array $aField, array $aInputAttributes ) { |
373
|
|
|
return array( |
374
|
|
|
'style' => $aField[ 'label_min_width' ] |
375
|
|
|
? "min-width:" . $this->getLengthSanitized( $aField[ 'label_min_width' ] ) . ";" |
376
|
|
|
: null, |
377
|
|
|
'for' => $aInputAttributes[ 'id' ], |
378
|
|
|
'class' => $aInputAttributes[ 'disabled' ] |
379
|
|
|
? 'disabled' |
380
|
|
|
: null, |
381
|
|
|
); |
382
|
|
|
} |
383
|
|
|
/** |
384
|
|
|
* Returns the label container attribute array. |
385
|
|
|
* |
386
|
|
|
* @since 3.5.3 |
387
|
|
|
* @param array $aField |
388
|
|
|
* @return array The label container attribute array. |
389
|
|
|
* @internal |
390
|
|
|
*/ |
391
|
|
|
private function _getLabelContainerAttributes( array $aField ) { |
392
|
|
|
return array( |
393
|
|
|
'style' => $aField[ 'label_min_width' ] || '0' === ( string ) $aField[ 'label_min_width' ] |
394
|
|
|
? "min-width:" . $this->getLengthSanitized( $aField[ 'label_min_width' ] ) . ";" |
395
|
|
|
: null, |
396
|
|
|
'class' => 'admin-page-framework-input-label-container' |
397
|
|
|
. ' admin-page-framework-input-button-container' |
398
|
|
|
. ' admin-page-framework-input-container', |
399
|
|
|
); |
400
|
|
|
} |
401
|
|
|
/** |
402
|
|
|
* Returns the input attribute array. |
403
|
|
|
* |
404
|
|
|
* @param array $aField |
405
|
|
|
* @since 3.5.3 |
406
|
|
|
* @return array The input attribute array. |
407
|
|
|
* @internal |
408
|
|
|
*/ |
409
|
|
|
private function _getInputAttributes( array $aField ) { |
410
|
|
|
$_bIsImageButton = isset( $aField[ 'attributes' ][ 'src' ] ) && filter_var( $aField[ 'attributes' ][ 'src' ], FILTER_VALIDATE_URL ); |
411
|
|
|
$_sValue = $this->_getInputFieldValueFromLabel( $aField ); |
412
|
|
|
return array( |
413
|
|
|
// the type must be set because child class including export will use this method; in that case, the export type will be assigned which input tag does not support |
414
|
|
|
'type' => $_bIsImageButton ? 'image' : 'submit', |
415
|
|
|
'value' => $_sValue, |
416
|
|
|
) |
417
|
|
|
+ $aField[ 'attributes' ] |
418
|
|
|
+ array( |
419
|
|
|
'title' => $_sValue, |
420
|
|
|
'alt' => $_bIsImageButton ? 'submit' : '', |
421
|
|
|
); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* Returns extra output for the field. |
426
|
|
|
* |
427
|
|
|
* This is for the import field type that extends this class. The import field type cannot place the file input tag inside the label tag that causes a problem in FireFox. |
428
|
|
|
* |
429
|
|
|
* @since 3.0.0 |
430
|
|
|
* @param array $aField |
431
|
|
|
* @return string |
432
|
|
|
* @internal |
433
|
|
|
*/ |
434
|
|
|
protected function _getExtraFieldsBeforeLabel( &$aField ) { |
435
|
|
|
return ''; |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
/** |
439
|
|
|
* Returns the output of hidden fields for this field type that enables custom submit buttons. |
440
|
|
|
* @since 3.0.0 |
441
|
|
|
* @internal |
442
|
|
|
* @param array $aField |
443
|
|
|
* @return string |
444
|
|
|
*/ |
445
|
|
|
protected function _getExtraInputFields( &$aField ) { |
446
|
|
|
|
447
|
|
|
$_aOutput = array(); |
448
|
|
|
$_aOutput[] = $this->getHTMLTag( |
449
|
|
|
'input', |
450
|
|
|
array( |
451
|
|
|
'type' => 'hidden', |
452
|
|
|
'name' => "__submit[{$aField[ 'input_id' ]}][input_id]", |
453
|
|
|
'value' => $aField[ 'input_id' ], |
454
|
|
|
) |
455
|
|
|
); |
456
|
|
|
$_aOutput[] = $this->getHTMLTag( |
457
|
|
|
'input', |
458
|
|
|
array( |
459
|
|
|
'type' => 'hidden', |
460
|
|
|
'name' => "__submit[{$aField[ 'input_id' ]}][field_id]", |
461
|
|
|
'value' => $aField[ 'field_id' ], |
462
|
|
|
) |
463
|
|
|
); |
464
|
|
|
$_aOutput[] = $this->getHTMLTag( |
465
|
|
|
'input', |
466
|
|
|
array( |
467
|
|
|
'type' => 'hidden', |
468
|
|
|
'name' => "__submit[{$aField[ 'input_id' ]}][name]", |
469
|
|
|
'value' => $aField[ '_input_name_flat' ], |
470
|
|
|
) |
471
|
|
|
); |
472
|
|
|
$_aOutput[] = $this->_getHiddenInput_SectionID( $aField ); |
473
|
|
|
$_aOutput[] = $this->_getHiddenInputByKey( $aField, 'redirect_url' ); |
474
|
|
|
$_aOutput[] = $this->_getHiddenInputByKey( $aField, 'href' ); |
475
|
|
|
$_aOutput[] = $this->_getHiddenInput_Reset( $aField ); |
476
|
|
|
$_aOutput[] = $this->_getHiddenInput_Email( $aField ); |
477
|
|
|
return implode( PHP_EOL, array_filter( $_aOutput ) ); |
478
|
|
|
|
479
|
|
|
} |
480
|
|
|
/** |
481
|
|
|
* Returns the hidden input tag for the section id argument. |
482
|
|
|
* |
483
|
|
|
* @since 3.5.3 |
484
|
|
|
* @internal |
485
|
|
|
* @return string the HTML input tag output for the section id argument. |
486
|
|
|
* @param array $aField |
487
|
|
|
*/ |
488
|
|
|
private function _getHiddenInput_SectionID( array $aField ) { |
489
|
|
|
return $this->getHTMLTag( |
490
|
|
|
'input', |
491
|
|
|
array( |
492
|
|
|
'type' => 'hidden', |
493
|
|
|
'name' => "__submit[{$aField['input_id']}][section_id]", |
494
|
|
|
'value' => isset( $aField['section_id'] ) && '_default' !== $aField['section_id'] |
495
|
|
|
? $aField['section_id'] |
496
|
|
|
: '', |
497
|
|
|
) |
498
|
|
|
); |
499
|
|
|
} |
500
|
|
|
/** |
501
|
|
|
* Returns the hidden input tag for the given key argument. |
502
|
|
|
* |
503
|
|
|
* @since 3.5.3 |
504
|
|
|
* @internal |
505
|
|
|
* @param array $aField |
506
|
|
|
* @param string $sKey |
507
|
|
|
* @return string the HTML input tag output for the given key argument. |
508
|
|
|
*/ |
509
|
|
|
private function _getHiddenInputByKey( array $aField, $sKey ) { |
510
|
|
|
return isset( $aField[ $sKey ] ) |
511
|
|
|
? $this->getHTMLTag( |
512
|
|
|
'input', |
513
|
|
|
array( |
514
|
|
|
'type' => 'hidden', |
515
|
|
|
'name' => "__submit[{$aField['input_id']}][{$sKey}]", |
516
|
|
|
'value' => $aField[ $sKey ], |
517
|
|
|
) |
518
|
|
|
) |
519
|
|
|
: ''; |
520
|
|
|
} |
521
|
|
|
/** |
522
|
|
|
* Returns the hidden input tag for the 'reset' argument. |
523
|
|
|
* |
524
|
|
|
* @since 3.5.3 |
525
|
|
|
* @internal |
526
|
|
|
* @param array $aField |
527
|
|
|
* @return string the HTML input tag output for the 'reset' argument. |
528
|
|
|
*/ |
529
|
|
|
private function _getHiddenInput_Reset( array $aField ) { |
530
|
|
|
if ( ! $aField[ 'reset' ] ) { |
531
|
|
|
return ''; |
532
|
|
|
} |
533
|
|
|
return ! $this->_checkConfirmationDisplayed( $aField, $aField[ '_input_name_flat' ], 'reset' ) |
534
|
|
|
? $this->getHTMLTag( |
535
|
|
|
'input', |
536
|
|
|
array( |
537
|
|
|
'type' => 'hidden', |
538
|
|
|
'name' => "__submit[{$aField['input_id']}][is_reset]", |
539
|
|
|
'value' => '1', |
540
|
|
|
) |
541
|
|
|
) |
542
|
|
|
: $this->getHTMLTag( |
543
|
|
|
'input', |
544
|
|
|
array( |
545
|
|
|
'type' => 'hidden', |
546
|
|
|
'name' => "__submit[{$aField[ 'input_id' ]}][reset_key]", |
547
|
|
|
'value' => is_array( $aField[ 'reset' ] ) // set the option array key to delete. |
548
|
|
|
? implode( '|', $aField[ 'reset' ] ) |
549
|
|
|
: $aField[ 'reset' ], |
550
|
|
|
) |
551
|
|
|
); |
552
|
|
|
} |
553
|
|
|
/** |
554
|
|
|
* Returns the hidden input tag for the 'email' argument. |
555
|
|
|
* |
556
|
|
|
* @since 3.5.3 |
557
|
|
|
* @internal |
558
|
|
|
* @param array $aField |
559
|
|
|
* @return string the HTML input tag output for the 'email' argument. |
560
|
|
|
*/ |
561
|
|
|
private function _getHiddenInput_Email( array $aField ) { |
562
|
|
|
|
563
|
|
|
if ( empty( $aField[ 'email' ] ) ) { |
564
|
|
|
return ''; |
565
|
|
|
} |
566
|
|
|
$this->setTransient( |
567
|
|
|
'apf_em_' . md5( $aField[ '_input_name_flat' ] . get_current_user_id() ), |
568
|
|
|
$aField[ 'email' ] |
569
|
|
|
); |
570
|
|
|
return ! $this->_checkConfirmationDisplayed( $aField, $aField[ '_input_name_flat' ], 'email' ) |
571
|
|
|
? $this->getHTMLTag( |
572
|
|
|
'input', |
573
|
|
|
array( |
574
|
|
|
'type' => 'hidden', |
575
|
|
|
'name' => "__submit[{$aField[ 'input_id' ]}][confirming_sending_email]", |
576
|
|
|
'value' => '1', |
577
|
|
|
) |
578
|
|
|
) |
579
|
|
|
: $this->getHTMLTag( |
580
|
|
|
'input', |
581
|
|
|
array( |
582
|
|
|
'type' => 'hidden', |
583
|
|
|
'name' => "__submit[{$aField[ 'input_id' ]}][confirmed_sending_email]", |
584
|
|
|
'value' => '1', |
585
|
|
|
) |
586
|
|
|
); |
587
|
|
|
} |
588
|
|
|
|
589
|
|
|
/** |
590
|
|
|
* A helper function for the above `getSubmitField()` that checks if a reset confirmation message has been displayed or not when the `reset` key is set. |
591
|
|
|
* |
592
|
|
|
* @param array $aField |
593
|
|
|
* @param string $sFlatFieldName |
594
|
|
|
* @param string $sType |
595
|
|
|
* @return boolean |
596
|
|
|
* @internal |
597
|
|
|
*/ |
598
|
|
|
private function _checkConfirmationDisplayed( $aField, $sFlatFieldName, $sType='reset' ) { |
599
|
|
|
|
600
|
|
|
switch( $sType ) { |
601
|
|
|
default: |
602
|
|
|
case 'reset': // admin page framework _ reset confirmation |
603
|
|
|
$_sTransientKey = 'apf_rc_' . md5( $sFlatFieldName . get_current_user_id() ); |
604
|
|
|
break; |
605
|
|
|
case 'email': // admin page framework _ email confirmation |
606
|
|
|
$_sTransientKey = 'apf_ec_' . md5( $sFlatFieldName . get_current_user_id() ); |
607
|
|
|
break; |
608
|
|
|
} |
609
|
|
|
|
610
|
|
|
$_bConfirmed = false === $this->getTransient( $_sTransientKey ) && ! $aField[ 'skip_confirmation' ] |
611
|
|
|
? false |
612
|
|
|
: true; |
613
|
|
|
|
614
|
|
|
if ( $_bConfirmed ) { |
615
|
|
|
$this->deleteTransient( $_sTransientKey ); |
616
|
|
|
} |
617
|
|
|
|
618
|
|
|
return $_bConfirmed; |
619
|
|
|
|
620
|
|
|
} |
621
|
|
|
|
622
|
|
|
/* |
623
|
|
|
* Shared Methods |
624
|
|
|
*/ |
625
|
|
|
|
626
|
|
|
/** |
627
|
|
|
* Retrieves the input field value from the label. |
628
|
|
|
* |
629
|
|
|
* This method is similar to the above <em>getInputFieldValue()</em> but this does not check the stored option value. |
630
|
|
|
* It uses the value set to the <var>label</var> key. |
631
|
|
|
* This is for submit buttons including export custom field type that the label should serve as the value. |
632
|
|
|
* |
633
|
|
|
* @remark The `submit`, `import`, and `export` field types use this method. |
634
|
|
|
* @since 2.0.0 |
635
|
|
|
* @since 2.1.5 Moved from `AdminPageFramwrork_InputField`. Changed the scope to protected from private. Removed the second parameter. |
636
|
|
|
* @internal |
637
|
|
|
* @param array $aField |
638
|
|
|
*/ |
639
|
|
|
protected function _getInputFieldValueFromLabel( $aField ) { |
640
|
|
|
|
641
|
|
|
// If the value key is explicitly set, use it. But the empty string will be ignored. |
642
|
|
|
if ( isset( $aField[ 'value' ] ) && $aField[ 'value' ] != '' ) { |
643
|
|
|
return $aField[ 'value' ]; |
644
|
|
|
} |
645
|
|
|
|
646
|
|
|
if ( isset( $aField[ 'label' ] ) ) { |
647
|
|
|
return $aField[ 'label' ]; |
648
|
|
|
} |
649
|
|
|
|
650
|
|
|
// If the default value is set, |
651
|
|
|
if ( isset( $aField[ 'default' ] ) ) { |
652
|
|
|
return $aField[ 'default' ]; |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
} |
656
|
|
|
|
657
|
|
|
} |