| 1 |
<?php |
| 2 |
|
| 3 |
namespace BitCode\BitForm\Frontend\Form\View\Conversational\Fields; |
| 4 |
|
| 5 |
use BitCode\BitForm\Core\Util\FrontendHelpers; |
| 6 |
|
| 7 |
class FileUploadField |
| 8 |
{ |
| 9 |
public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null) |
| 10 |
{ |
| 11 |
$inputWrapper = new ConversationalInputWrapper($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 12 |
$input = self::field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 13 |
return $inputWrapper->wrapper($input); |
| 14 |
} |
| 15 |
|
| 16 |
private static function field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null) |
| 17 |
{ |
| 18 |
$fh = new ConversationalFieldHelpers($formID, $field, $rowID, $form_atomic_Cls_map); |
| 19 |
$prefixIcn = $fh->icon('prefixIcn', 'pre-i'); |
| 20 |
$suffixIcn = $fh->icon('suffixIcn', 'suf-i'); |
| 21 |
$name = $fh->name(); |
| 22 |
$req = $fh->required(); |
| 23 |
$ariaDescribedBy = $fh->ariaDescribedBy(); |
| 24 |
$ariaRequired = $fh->ariaRequired(); |
| 25 |
$readonlyCls = isset($field->readonly) ? 'readonly' : ''; |
| 26 |
$disabledCls = isset($field->disabled) ? 'disabled' : ''; |
| 27 |
$btnTxt = isset($field->btnTxt) ? $field->btnTxt : ''; |
| 28 |
$showSelectStatus = ''; |
| 29 |
$maxSizeSection = ''; |
| 30 |
$maxSize = isset($field->config->maxSize) ? $field->config->maxSize : ''; |
| 31 |
$sizeUnit = isset($field->config->sizeUnit) ? $field->config->sizeUnit : ''; |
| 32 |
$bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds; |
| 33 |
$contentCount = count($bfFrontendFormIds); |
| 34 |
|
| 35 |
if ($fh->property_exists_nested($field, 'config->showSelectStatus', true)) { |
| 36 |
$showSelectStatus = sprintf( |
| 37 |
'<div |
| 38 |
%1$s |
| 39 |
class="%2$s %3$s" |
| 40 |
> |
| 41 |
No Choosen File |
| 42 |
</div> |
| 43 |
', |
| 44 |
$fh->getCustomAttributes('file-select-status'), |
| 45 |
$fh->getConversationalMultiCls('file-select-status'), |
| 46 |
$fh->getCustomClasses('file-select-status') |
| 47 |
); |
| 48 |
} |
| 49 |
|
| 50 |
if ( |
| 51 |
$fh->property_exists_nested($field, 'config->allowMaxSize', true) |
| 52 |
&& $fh->property_exists_nested($field, 'config->showMaxSize', true) |
| 53 |
&& $fh->property_exists_nested($field, 'config->maxSize') |
| 54 |
&& 0 !== $field->config->maxSize |
| 55 |
) { |
| 56 |
$maxSizeLbl = $fh->property_exists_nested($field, 'config->maxSizeLabel', '', 1) ? $field->config->maxSizeLabel : "(Max {$maxSize} ${sizeUnit})"; |
| 57 |
$maxSizeSection = sprintf( |
| 58 |
'<small |
| 59 |
%1$s |
| 60 |
class="%2$s %3$s" |
| 61 |
> |
| 62 |
%4$s |
| 63 |
</small> |
| 64 |
', |
| 65 |
$fh->getCustomAttributes('max-size-lbl'), |
| 66 |
$fh->getConversationalMultiCls('max-size-lbl'), |
| 67 |
$fh->getCustomClasses('max-size-lbl'), |
| 68 |
$fh->esc_html($maxSizeLbl) |
| 69 |
); |
| 70 |
} |
| 71 |
|
| 72 |
return ' <div |
| 73 |
' . $fh->getCustomAttributes('file-up-container') . ' |
| 74 |
class="' . $fh->getConversationalMultiCls('file-up-container') . ' ' . $fh->getCustomClasses('file-up-container') . '" |
| 75 |
> |
| 76 |
<div |
| 77 |
' . $fh->getCustomAttributes('file-up-wrpr') . ' |
| 78 |
class="' . $fh->getConversationalMultiCls('file-up-wrpr') . ' ' . $fh->getCustomClasses('file-up-wrpr') . ' ' . $readonlyCls . ' ' . $disabledCls . '" |
| 79 |
> |
| 80 |
<div |
| 81 |
' . $fh->getCustomAttributes('file-input-wrpr') . ' |
| 82 |
class="' . $fh->getConversationalMultiCls('file-input-wrpr') . ' ' . $fh->getCustomClasses('file-input-wrpr') . '" |
| 83 |
> |
| 84 |
<div |
| 85 |
' . $fh->getCustomAttributes('btn-wrpr') . ' |
| 86 |
class="' . $fh->getConversationalMultiCls('btn-wrpr') . ' ' . $fh->getCustomClasses('btn-wrpr') . '" |
| 87 |
> |
| 88 |
<button |
| 89 |
' . $fh->getCustomAttributes('inp-btn') . ' |
| 90 |
type="button" |
| 91 |
class="' . $fh->getConversationalMultiCls('inp-btn') . ' ' . $fh->getCustomClasses('inp-btn') . '" |
| 92 |
> |
| 93 |
' . $prefixIcn . ' |
| 94 |
<span |
| 95 |
' . $fh->getCustomAttributes('btn-txt') . ' |
| 96 |
class="' . $fh->getConversationalMultiCls('btn-txt') . ' ' . $fh->getCustomClasses('btn-txt') . '" |
| 97 |
> |
| 98 |
' . $fh->kses_post($btnTxt) . ' |
| 99 |
</span> |
| 100 |
' . $suffixIcn . ' |
| 101 |
</button> |
| 102 |
' . $showSelectStatus . ' |
| 103 |
' . $maxSizeSection . ' |
| 104 |
<input |
| 105 |
' . $fh->getCustomAttributes('file-upload-input') . ' |
| 106 |
type="file" |
| 107 |
class="' . $fh->getConversationalMultiCls('file-upload-input') . ' ' . $fh->getCustomClasses('file-upload-input') . '" |
| 108 |
id="' . $rowID . '-' . $contentCount . '" |
| 109 |
' . $name . ' |
| 110 |
' . $req . ' |
| 111 |
' . $ariaRequired . ' |
| 112 |
' . $ariaDescribedBy . ' |
| 113 |
' . $fh->disabled() . ' |
| 114 |
' . $fh->readonly() . ' |
| 115 |
aria-disabled="true" |
| 116 |
tabindex="-1" |
| 117 |
/> |
| 118 |
</div> |
| 119 |
<div |
| 120 |
' . $fh->getCustomAttributes('err-wrp') . ' |
| 121 |
class="err-wrp ' . $fh->getCustomClasses('err-wrp') . '" |
| 122 |
></div> |
| 123 |
</div> |
| 124 |
</div> |
| 125 |
</div>'; |
| 126 |
} |
| 127 |
} |
| 128 |
|