| 1 |
<?php |
| 2 |
|
| 3 |
namespace BitCode\BitForm\Frontend\Form\View\Theme\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 ClassicInputWrapper($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 ClassicFieldHelpers($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 |
$readonlyCls = isset($field->readonly) ? 'readonly' : ''; |
| 24 |
$disabledCls = isset($field->disabled) ? 'disabled' : ''; |
| 25 |
$btnTxt = isset($field->btnTxt) ? $field->btnTxt : ''; |
| 26 |
$showSelectStatus = ''; |
| 27 |
$maxSizeSection = ''; |
| 28 |
$maxSize = isset($field->config->maxSize) ? $field->config->maxSize : ''; |
| 29 |
$sizeUnit = isset($field->config->sizeUnit) ? $field->config->sizeUnit : ''; |
| 30 |
$bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds; |
| 31 |
$contentCount = count($bfFrontendFormIds); |
| 32 |
|
| 33 |
if ($fh->property_exists_nested($field, 'config->showSelectStatus', true)) { |
| 34 |
$showSelectStatus = sprintf( |
| 35 |
'<div |
| 36 |
%1$s |
| 37 |
class="%2$s %3$s" |
| 38 |
> |
| 39 |
No Choosen File |
| 40 |
</div>', |
| 41 |
$fh->getCustomAttributes('file-select-status'), |
| 42 |
$fh->getAtomicCls('file-select-status'), |
| 43 |
$fh->getCustomClasses('file-select-status') |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
if ( |
| 48 |
$fh->property_exists_nested($field, 'config->allowMaxSize', true) |
| 49 |
&& $fh->property_exists_nested($field, 'config->showMaxSize', true) |
| 50 |
&& $fh->property_exists_nested($field, 'config->maxSize') |
| 51 |
&& 0 !== $field->config->maxSize |
| 52 |
) { |
| 53 |
$maxSizeLbl = $fh->property_exists_nested($field, 'config->maxSizeLabel', '', 1) ? $field->config->maxSizeLabel : "(Max {$maxSize} {$sizeUnit})"; |
| 54 |
$maxSizeSection = sprintf( |
| 55 |
'<small |
| 56 |
%1$s |
| 57 |
class="%2$s %3$s" |
| 58 |
> |
| 59 |
%4$s |
| 60 |
</small>', |
| 61 |
$fh->getCustomAttributes('max-size-lbl'), |
| 62 |
$fh->getAtomicCls('max-size-lbl'), |
| 63 |
$fh->getCustomClasses('max-size-lbl'), |
| 64 |
$fh->esc_html($maxSizeLbl) |
| 65 |
); |
| 66 |
} |
| 67 |
|
| 68 |
return sprintf( |
| 69 |
'<div |
| 70 |
%1$s |
| 71 |
class="%2$s %3$s" |
| 72 |
> |
| 73 |
<div |
| 74 |
%4$s |
| 75 |
class="%5$s %6$s %7$s %8$s" |
| 76 |
> |
| 77 |
<div |
| 78 |
%9$s |
| 79 |
class="%10$s %11$s" |
| 80 |
> |
| 81 |
<div |
| 82 |
%12$s |
| 83 |
class="%13$s %14$s" |
| 84 |
> |
| 85 |
<button |
| 86 |
%15$s |
| 87 |
type="button" |
| 88 |
class="%16$s %17$s" |
| 89 |
> |
| 90 |
%18$s |
| 91 |
<span |
| 92 |
%19$s |
| 93 |
class="%20$s %21$s" |
| 94 |
> |
| 95 |
%22$s |
| 96 |
</span> |
| 97 |
%23$s |
| 98 |
</button> |
| 99 |
%24$s |
| 100 |
%25$s |
| 101 |
<input |
| 102 |
%26$s |
| 103 |
type="file" |
| 104 |
class="%27$s %28$s" |
| 105 |
id="%29$s-%30$s" |
| 106 |
%31$s |
| 107 |
%32$s |
| 108 |
%33$s |
| 109 |
%34$s |
| 110 |
aria-disabled="true" |
| 111 |
tabindex="-1" |
| 112 |
/> |
| 113 |
</div> |
| 114 |
<div |
| 115 |
%35$s |
| 116 |
class="err-wrp %36$s" |
| 117 |
></div> |
| 118 |
</div> |
| 119 |
</div> |
| 120 |
</div>', |
| 121 |
$fh->getCustomAttributes('file-up-container'), |
| 122 |
$fh->getAtomicCls('file-up-container'), |
| 123 |
$fh->getCustomClasses('file-up-container'), |
| 124 |
$fh->getCustomAttributes('file-up-wrpr'), |
| 125 |
$fh->getAtomicCls('file-up-wrpr'), |
| 126 |
$fh->getCustomClasses('file-up-wrpr'), |
| 127 |
$readonlyCls, |
| 128 |
$disabledCls, |
| 129 |
$fh->getCustomAttributes('file-input-wrpr'), |
| 130 |
$fh->getAtomicCls('file-input-wrpr'), |
| 131 |
$fh->getCustomClasses('file-input-wrpr'), |
| 132 |
$fh->getCustomAttributes('btn-wrpr'), |
| 133 |
$fh->getAtomicCls('btn-wrpr'), |
| 134 |
$fh->getCustomClasses('btn-wrpr'), |
| 135 |
$fh->getCustomAttributes('inp-btn'), |
| 136 |
$fh->getAtomicCls('inp-btn'), |
| 137 |
$fh->getCustomClasses('inp-btn'), |
| 138 |
$prefixIcn, |
| 139 |
$fh->getCustomAttributes('btn-txt'), |
| 140 |
$fh->getAtomicCls('btn-txt'), |
| 141 |
$fh->getCustomClasses('btn-txt'), |
| 142 |
$fh->kses_post($btnTxt), |
| 143 |
$suffixIcn, |
| 144 |
$showSelectStatus, |
| 145 |
$maxSizeSection, |
| 146 |
$fh->getCustomAttributes('file-upload-input'), |
| 147 |
$fh->getAtomicCls('file-upload-input'), |
| 148 |
$fh->getCustomClasses('file-upload-input'), |
| 149 |
$rowID, |
| 150 |
$contentCount, |
| 151 |
$name, |
| 152 |
$req, |
| 153 |
$fh->disabled(), |
| 154 |
$fh->readonly(), |
| 155 |
$fh->getCustomAttributes('err-wrp'), |
| 156 |
$fh->getCustomClasses('err-wrp') |
| 157 |
); |
| 158 |
} |
| 159 |
} |
| 160 |
|