Skip to content

Commit b5500b6

Browse files
committed
Fix #186: New property autoFileTypeParsing for parsing file types
1 parent 61cfc4a commit b5500b6

File tree

10 files changed

+72
-18
lines changed

10 files changed

+72
-18
lines changed

CHANGE.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ Change Log: `yii2-widget-fileinput`
33

44
## Version 1.1.1
55

6-
**Date:** 03-Sep-2021
6+
**Date:** 28-Jun-2022
77

8+
- (enh #186): New property `autoFileTypeParsing` for parsing file types.
9+
- (enh #185): Add Uzbek (Cyrillic) language translations.
10+
- (enh #184): Add Uzbek (Cyrillic) language in messages config.
811
- (enh #180): Enhancements to support Bootstrap v5.x.
912
- (bug #179): Support translations for language codes with hyphen.
1013

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2014 - 2021, Kartik Visweswaran
1+
Copyright (c) 2014 - 2022, Kartik Visweswaran
22
Krajee.com
33
All rights reserved.
44

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
}
1414
],
1515
"require": {
16-
"kartik-v/yii2-krajee-base": ">=3.0.1",
17-
"kartik-v/bootstrap-fileinput": ">=5.0.0"
16+
"kartik-v/yii2-krajee-base": ">=3.0.5",
17+
"kartik-v/bootstrap-fileinput": ">=5.5.0"
1818
},
1919
"autoload": {
2020
"psr-4": {

src/BaseAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
4+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
55
* @package yii2-widgets
66
* @subpackage yii2-widget-fileinput
77
* @version 1.1.1

src/FileInput.php

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
4+
* @copyright Copyright &copy; 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()

src/FileInputAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
4+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
55
* @package yii2-widgets
66
* @subpackage yii2-widget-fileinput
77
* @version 1.1.1

src/FileInputThemeAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
4+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
55
* @package yii2-widgets
66
* @subpackage yii2-widget-fileinput
77
* @version 1.1.1

src/FileTypeParserAsset.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
5+
* @package yii2-widgets
6+
* @subpackage yii2-widget-fileinput
7+
* @version 1.1.1
8+
*/
9+
10+
namespace kartik\file;
11+
12+
/**
13+
* File type parser asset bundle for FileInput Widget
14+
*
15+
* @author Kartik Visweswaran <[email protected]>
16+
* @since 1.0
17+
*/
18+
class FileTypeParserAsset extends BaseAsset
19+
{
20+
/**
21+
* @inheritdoc
22+
*/
23+
public function init()
24+
{
25+
$this->setupAssets('js', ['js/plugins/buffer', 'js/plugins/filetype']);
26+
parent::init();
27+
}
28+
}

src/PiExifAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
4+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
55
* @package yii2-widgets
66
* @subpackage yii2-widget-fileinput
77
* @version 1.1.1

src/SortableAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
4+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
55
* @package yii2-widgets
66
* @subpackage yii2-widget-fileinput
77
* @version 1.1.1

0 commit comments

Comments
 (0)