11<?php
22
33/**
4- * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2021
4+ * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2022
55 * @package yii2-widgets
66 * @subpackage yii2-widget-fileinput
77 * @version 1.1.1
@@ -43,6 +43,11 @@ class FileInput extends InputWidget
4343 */
4444 public $ autoOrientImages = true ;
4545
46+ /**
47+ * @var boolean whether to use advanced mime parsing to detect file content irrespective of the file name extension
48+ */
49+ public $ autoFileTypeParsing = true ;
50+
4651 /**
4752 * @var boolean whether to load sortable plugin to rearrange initial preview images on client side
4853 */
@@ -73,7 +78,17 @@ class FileInput extends InputWidget
7378 /**
7479 * @var array the list of inbuilt themes
7580 */
76- protected static $ _themes = ['fa ' , 'fas ' , 'gly ' , 'explorer ' , 'explorer-fa ' , 'explorer-fas ' ];
81+ protected static $ _themes = [
82+ 'bs5 ' ,
83+ 'fa4 ' ,
84+ 'fa5 ' ,
85+ 'fa6 ' ,
86+ 'gly ' ,
87+ 'explorer ' ,
88+ 'explorer-fa4 ' ,
89+ 'explorer-fa5 ' ,
90+ 'explorer-fa6 ' ,
91+ ];
7792
7893 /**
7994 * @inheritdoc
@@ -87,6 +102,7 @@ public function run()
87102
88103 /**
89104 * Initializes widget
105+ *
90106 * @throws ReflectionException
91107 * @throws InvalidConfigException
92108 */
@@ -108,7 +124,8 @@ protected function initWidget()
108124 /**
109125 * Auto-set multiple file upload naming convention
110126 */
111- if (ArrayHelper::getValue ($ this ->options , 'multiple ' ) && !ArrayHelper::getValue ($ this ->pluginOptions , 'uploadUrl ' )) {
127+ if (ArrayHelper::getValue ($ this ->options , 'multiple ' ) && !ArrayHelper::getValue ($ this ->pluginOptions ,
128+ 'uploadUrl ' )) {
112129 $ hasModel = $ this ->hasModel ();
113130 if ($ hasModel && strpos ($ this ->attribute , '[] ' ) === false ) {
114131 $ this ->attribute .= '[] ' ;
@@ -117,28 +134,29 @@ protected function initWidget()
117134 }
118135 }
119136 $ input = $ this ->getInput ('fileInput ' );
120- $ script = 'document.getElementById(" ' . $ this ->options ['id ' ] . '").className.replace(/\bfile-loading\b/,""); ' ;
137+ $ script = 'document.getElementById(" ' . $ this ->options ['id ' ]. '").className.replace(/\bfile-loading\b/,""); ' ;
121138 if ($ this ->showMessage ) {
122139 $ validation = ArrayHelper::getValue ($ this ->pluginOptions , 'showPreview ' , true ) ?
123140 Yii::t ('fileinput ' , 'file preview and multiple file upload ' ) :
124141 Yii::t ('fileinput ' , 'multiple file upload ' );
125- $ message = '<strong> ' . Yii::t ('fileinput ' , 'Note: ' ) . '</strong> ' .
142+ $ message = '<strong> ' . Yii::t ('fileinput ' , 'Note: ' ). '</strong> ' .
126143 Yii::t (
127144 'fileinput ' ,
128145 'Your browser does not support {validation}. Try an alternative or more recent browser to access these features. ' ,
129146 ['validation ' => $ validation ]
130147 );
131- $ content = Html::tag ('div ' , $ message , $ this ->messageOptions ) . "<script> {$ script };</script> " ;
132- $ input .= "\n" . $ this ->validateIE ($ content );
148+ $ content = Html::tag ('div ' , $ message , $ this ->messageOptions ). "<script> {$ script };</script> " ;
149+ $ input .= "\n" . $ this ->validateIE ($ content );
133150 }
151+
134152 return $ input ;
135153 }
136154
137155 /**
138156 * Validates and returns content based on IE browser version validation
139157 *
140- * @param string $content
141- * @param string $validation
158+ * @param string $content
159+ * @param string $validation
142160 *
143161 * @return string
144162 */
@@ -149,13 +167,17 @@ protected function validateIE($content, $validation = 'lt IE 10')
149167
150168 /**
151169 * Registers the asset bundle and locale
170+ *
152171 * @throws InvalidConfigException|Exception
153172 */
154173 public function registerAssetBundle ()
155174 {
156175 $ view = $ this ->getView ();
157176 $ this ->pluginOptions ['resizeImage ' ] = $ this ->resizeImages ;
158177 $ this ->pluginOptions ['autoOrientImage ' ] = $ this ->autoOrientImages ;
178+ if ($ this ->autoFileTypeParsing ) {
179+ FileTypeParserAsset::register ($ view );
180+ }
159181 if ($ this ->resizeImages || $ this ->autoOrientImages ) {
160182 PiExifAsset::register ($ view );
161183 }
@@ -178,6 +200,7 @@ public function registerAssetBundle()
178200
179201 /**
180202 * Registers the needed assets
203+ *
181204 * @throws InvalidConfigException
182205 */
183206 public function registerAssets ()
0 commit comments