Skip to content

Commit

Permalink
Fix #186: New property autoFileTypeParsing for parsing file types
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Jun 28, 2022
1 parent 61cfc4a commit b5500b6
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 18 deletions.
5 changes: 4 additions & 1 deletion CHANGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ Change Log: `yii2-widget-fileinput`

## Version 1.1.1

**Date:** 03-Sep-2021
**Date:** 28-Jun-2022

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

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014 - 2021, Kartik Visweswaran
Copyright (c) 2014 - 2022, Kartik Visweswaran
Krajee.com
All rights reserved.

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
}
],
"require": {
"kartik-v/yii2-krajee-base": ">=3.0.1",
"kartik-v/bootstrap-fileinput": ">=5.0.0"
"kartik-v/yii2-krajee-base": ">=3.0.5",
"kartik-v/bootstrap-fileinput": ">=5.5.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/BaseAsset.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @package yii2-widgets
* @subpackage yii2-widget-fileinput
* @version 1.1.1
Expand Down
41 changes: 32 additions & 9 deletions src/FileInput.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @package yii2-widgets
* @subpackage yii2-widget-fileinput
* @version 1.1.1
Expand Down Expand Up @@ -43,6 +43,11 @@ class FileInput extends InputWidget
*/
public $autoOrientImages = true;

/**
* @var boolean whether to use advanced mime parsing to detect file content irrespective of the file name extension
*/
public $autoFileTypeParsing = true;

/**
* @var boolean whether to load sortable plugin to rearrange initial preview images on client side
*/
Expand Down Expand Up @@ -73,7 +78,17 @@ class FileInput extends InputWidget
/**
* @var array the list of inbuilt themes
*/
protected static $_themes = ['fa', 'fas', 'gly', 'explorer', 'explorer-fa', 'explorer-fas'];
protected static $_themes = [
'bs5',
'fa4',
'fa5',
'fa6',
'gly',
'explorer',
'explorer-fa4',
'explorer-fa5',
'explorer-fa6',
];

/**
* @inheritdoc
Expand All @@ -87,6 +102,7 @@ public function run()

/**
* Initializes widget
*
* @throws ReflectionException
* @throws InvalidConfigException
*/
Expand All @@ -108,7 +124,8 @@ protected function initWidget()
/**
* Auto-set multiple file upload naming convention
*/
if (ArrayHelper::getValue($this->options, 'multiple') && !ArrayHelper::getValue($this->pluginOptions, 'uploadUrl')) {
if (ArrayHelper::getValue($this->options, 'multiple') && !ArrayHelper::getValue($this->pluginOptions,
'uploadUrl')) {
$hasModel = $this->hasModel();
if ($hasModel && strpos($this->attribute, '[]') === false) {
$this->attribute .= '[]';
Expand All @@ -117,28 +134,29 @@ protected function initWidget()
}
}
$input = $this->getInput('fileInput');
$script = 'document.getElementById("' . $this->options['id'] . '").className.replace(/\bfile-loading\b/,"");';
$script = 'document.getElementById("'.$this->options['id'].'").className.replace(/\bfile-loading\b/,"");';
if ($this->showMessage) {
$validation = ArrayHelper::getValue($this->pluginOptions, 'showPreview', true) ?
Yii::t('fileinput', 'file preview and multiple file upload') :
Yii::t('fileinput', 'multiple file upload');
$message = '<strong>' . Yii::t('fileinput', 'Note:') . '</strong> ' .
$message = '<strong>'.Yii::t('fileinput', 'Note:').'</strong> '.
Yii::t(
'fileinput',
'Your browser does not support {validation}. Try an alternative or more recent browser to access these features.',
['validation' => $validation]
);
$content = Html::tag('div', $message, $this->messageOptions) . "<script>{$script};</script>";
$input .= "\n" . $this->validateIE($content);
$content = Html::tag('div', $message, $this->messageOptions)."<script>{$script};</script>";
$input .= "\n".$this->validateIE($content);
}

return $input;
}

/**
* Validates and returns content based on IE browser version validation
*
* @param string $content
* @param string $validation
* @param string $content
* @param string $validation
*
* @return string
*/
Expand All @@ -149,13 +167,17 @@ protected function validateIE($content, $validation = 'lt IE 10')

/**
* Registers the asset bundle and locale
*
* @throws InvalidConfigException|Exception
*/
public function registerAssetBundle()
{
$view = $this->getView();
$this->pluginOptions['resizeImage'] = $this->resizeImages;
$this->pluginOptions['autoOrientImage'] = $this->autoOrientImages;
if ($this->autoFileTypeParsing) {
FileTypeParserAsset::register($view);
}
if ($this->resizeImages || $this->autoOrientImages) {
PiExifAsset::register($view);
}
Expand All @@ -178,6 +200,7 @@ public function registerAssetBundle()

/**
* Registers the needed assets
*
* @throws InvalidConfigException
*/
public function registerAssets()
Expand Down
2 changes: 1 addition & 1 deletion src/FileInputAsset.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @package yii2-widgets
* @subpackage yii2-widget-fileinput
* @version 1.1.1
Expand Down
2 changes: 1 addition & 1 deletion src/FileInputThemeAsset.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @package yii2-widgets
* @subpackage yii2-widget-fileinput
* @version 1.1.1
Expand Down
28 changes: 28 additions & 0 deletions src/FileTypeParserAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @package yii2-widgets
* @subpackage yii2-widget-fileinput
* @version 1.1.1
*/

namespace kartik\file;

/**
* File type parser asset bundle for FileInput Widget
*
* @author Kartik Visweswaran <[email protected]>
* @since 1.0
*/
class FileTypeParserAsset extends BaseAsset
{
/**
* @inheritdoc
*/
public function init()
{
$this->setupAssets('js', ['js/plugins/buffer', 'js/plugins/filetype']);
parent::init();
}
}
2 changes: 1 addition & 1 deletion src/PiExifAsset.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @package yii2-widgets
* @subpackage yii2-widget-fileinput
* @version 1.1.1
Expand Down
2 changes: 1 addition & 1 deletion src/SortableAsset.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @package yii2-widgets
* @subpackage yii2-widget-fileinput
* @version 1.1.1
Expand Down

2 comments on commit b5500b6

@fejan-malek
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2022-06-28 at 5 40 45 PM

Yesterday's composer update was working fine just today after this commit I am facing an issue on the live server.

@kartik-v
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retry again... the yii2-krajee-base v3.0.5 was not tagged. Its done now.

Please sign in to comment.