-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # src/FileUploadControl.php
- Loading branch information
Showing
52 changed files
with
1,596 additions
and
1,548 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
namespace Zet\FileUpload; | ||
|
||
use Tracy\Debugger; | ||
|
||
/** | ||
* Class FileUploadControl | ||
* @author Zechy <[email protected]> | ||
|
@@ -30,35 +32,20 @@ public static function register(\Nette\DI\Container $systemContainer, $configura | |
$component->setContainer($systemContainer); | ||
$component->setUploadModel($configuration["uploadModel"]); | ||
$component->setFileFilter($configuration["fileFilter"]); | ||
$component->setUIMode($configuration["uiMode"]); | ||
$component->setRenderer($configuration["renderer"]); | ||
|
||
$container->addComponent($component, $name); | ||
|
||
return $component; | ||
}); | ||
} | ||
|
||
/** | ||
* Vloží CSS do stránky. | ||
* @static | ||
* @param string $basePath | ||
* @throws \Nette\DeprecatedException Use FileUploadControl::getHead() | ||
*/ | ||
public static function getStyleSheet($basePath) { | ||
throw new \Nette\DeprecatedException("Use FileUploadControl::getHead() instead."); | ||
|
||
echo '<link rel="stylesheet" type="text/css" href="' . $basePath . '/fileupload/css/jquery.fileupload.css">'; | ||
echo '<link rel="stylesheet" type="text/css" href="' . $basePath . '/fileupload/style.css">'; | ||
} | ||
|
||
/** | ||
* Vloží CSS do stránky. | ||
* @static | ||
* @param string $basePath | ||
*/ | ||
public static function getHead($basePath) { | ||
echo '<link rel="stylesheet" type="text/css" href="' . $basePath . '/fileupload/css/jquery.fileupload.css">'; | ||
echo '<link rel="stylesheet" type="text/css" href="' . $basePath . '/fileupload/style.css">'; | ||
echo '<script type="text/javascript" src="' . $basePath . '/fileupload/functions.js"></script>'; | ||
} | ||
|
||
|
@@ -70,16 +57,11 @@ public static function getHead($basePath) { | |
public static function getScripts($basePath) { | ||
echo '<script type="text/javascript" src="' . $basePath . '/fileupload/js/vendor/jquery.ui.widget.js"></script>'; | ||
echo '<script type="text/javascript" src="' . $basePath . '/fileupload/js/load-image.all.min.js"></script>'; | ||
echo '<script type="text/javascript" src="' . $basePath . '/fileupload/js/canvas-to-blob.min.js"></script>'; | ||
echo '<script type="text/javascript" src="' . $basePath . '/fileupload/js/jquery.iframe-transport.js"></script>'; | ||
echo '<script type="text/javascript" src="' . $basePath . '/fileupload/js/jquery.fileupload.js"></script>'; | ||
echo '<script type="text/javascript" src="' . $basePath . '/fileupload/js/jquery.fileupload-process.js"></script>'; | ||
echo '<script type="text/javascript" src="' . $basePath . '/fileupload/js/jquery.fileupload-image.js"></script>'; | ||
echo '<script type="text/javascript" src="' . $basePath . '/fileupload/js/jquery.fileupload-video.js"></script>'; | ||
echo '<script type="text/javascript" src="' . $basePath . '/fileupload/controller.js"></script>'; | ||
echo '<script type="text/javascript" src="' . $basePath . '/fileupload/ui/uiRenderer.js"></script>'; | ||
echo '<script type="text/javascript" src="' . $basePath . '/fileupload/ui/full.js"></script>'; | ||
echo '<script type="text/javascript" src="' . $basePath . '/fileupload/ui/minimal.js"></script>'; | ||
} | ||
|
||
# -------------------------------------------------------------------- | ||
|
@@ -108,18 +90,6 @@ public static function getScripts($basePath) { | |
* @var string | ||
*/ | ||
const FILTER_AUDIO = 'Zet\FileUpload\Filter\AudioFilter'; | ||
|
||
/** | ||
* Plnohodntné a detailní rozhraní pro nahrávání souborů. | ||
* @var int | ||
*/ | ||
const UI_FULL = 1; | ||
|
||
/** | ||
* Minimální rozhraní. | ||
* @var int | ||
*/ | ||
const UI_MINIMAL = 2; | ||
|
||
/** | ||
* @var \Nette\DI\Container | ||
|
@@ -156,11 +126,6 @@ public static function getScripts($basePath) { | |
*/ | ||
private $uploadModel; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $uiMode = self::UI_FULL; | ||
|
||
/** | ||
* Třída pro filtrování nahrávaných souborů. | ||
* @var string | ||
|
@@ -172,19 +137,16 @@ public static function getScripts($basePath) { | |
* @var array | ||
*/ | ||
private $params = []; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $token; | ||
private $renderer; | ||
|
||
/** | ||
* @var array | ||
* @var string | ||
*/ | ||
private $uiTemplates = [ | ||
self::UI_FULL => __DIR__ . "/Template/full.latte", | ||
self::UI_MINIMAL => __DIR__ . "/Template/minimal.latte" | ||
]; | ||
private $token; | ||
|
||
/** | ||
* FileUploadControl constructor. | ||
|
@@ -196,11 +158,11 @@ public function __construct($name, $maxFiles, $maxFileSize = NULL) { | |
parent::__construct($name); | ||
$this->maxFiles = $maxFiles; | ||
if(is_null($maxFileSize)) { | ||
$this->maxFileSize = $this->parseIniSize(ini_get("upload_max_filesize")); | ||
$this->fileSizeString = ini_get("upload_max_filesize") . "B"; | ||
$this->maxFileSize = $this->parseIniSize(ini_get("upload_max_filesize")); | ||
} else { | ||
$this->maxFileSize = $this->parseIniSize($maxFileSize); | ||
$this->fileSizeString = $maxFileSize . "B"; | ||
$this->maxFileSize = $this->parseIniSize($maxFileSize); | ||
} | ||
$this->controller = new Model\UploadController($this); | ||
$this->token = uniqid(); | ||
|
@@ -231,30 +193,12 @@ private function checkSettings() { | |
} | ||
} | ||
|
||
/** | ||
* @param int $type | ||
* @return int|NULL | ||
*/ | ||
public function getUiTemplate($type) { | ||
return isset($this->uiTemplates[$type]) ? $this->uiTemplates[$type] : NULL; | ||
} | ||
|
||
/** | ||
* @param int $type | ||
* @param string $file | ||
* @return \Zet\FileUpload\FileUploadControl | ||
*/ | ||
public function setUiTemplate($type, $file) { | ||
$this->uiTemplates[$type] = $file; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param $form | ||
*/ | ||
protected function attached($form) { | ||
parent::attached($form); | ||
$this->form->addComponent($this->controller, "uploadController"); | ||
$this->form->addComponent($this->controller, "uploadController" . ucfirst($this->name)); | ||
} | ||
|
||
# -------------------------------------------------------------------- | ||
|
@@ -413,11 +357,9 @@ public function getToken() { | |
/** | ||
* Nastavení vlastních parametrů k uploadovanému souboru. | ||
* @param array $params | ||
* @return \Zet\FileUpload\FileUploadControl | ||
*/ | ||
public function setParams(array $params) { | ||
$this->params = $params; | ||
return $this; | ||
} | ||
|
||
/** | ||
|
@@ -426,6 +368,20 @@ public function setParams(array $params) { | |
public function getParams() { | ||
return $this->params; | ||
} | ||
|
||
/** | ||
* @param string $renderer | ||
*/ | ||
public function setRenderer($renderer) { | ||
$this->renderer = $renderer; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getRenderer() { | ||
return $this->renderer; | ||
} | ||
|
||
# -------------------------------------------------------------------- | ||
# Methods | ||
|
@@ -435,12 +391,15 @@ public function getParams() { | |
*/ | ||
public function loadHttpData() { | ||
parent::loadHttpData(); | ||
$request = $this->getContainer()->getByType('\Nette\Http\Request'); /** @var \Nette\Http\Request $request */ | ||
|
||
/** @var \Nette\Http\Request $request */ | ||
$request = $this->getContainer()->getByType('\Nette\Http\Request'); | ||
$this->token = $request->getPost($this->getHtmlName() ."-token"); | ||
} | ||
|
||
/** | ||
* @return \Nette\Utils\Html | ||
* @throws InvalidValueException | ||
*/ | ||
public function getControl() { | ||
$this->checkSettings(); | ||
|
@@ -453,15 +412,9 @@ public function getControl() { | |
$token = \Nette\Utils\Html::el("input type='hidden' value='" . $this->token . "'"); | ||
$token->addAttributes(["name" => $this->getHtmlName() ."-token"]); | ||
|
||
if(method_exists(\Nette\Utils\Html::class, "addHtml")) { | ||
$container->addHtml($token); | ||
$container->addHtml($this->controller->getJavaScriptTemplate()); | ||
$container->addHtml($this->controller->getControlTemplate()); | ||
} else { // pro starší nette | ||
$container->add($token); | ||
$container->add($this->controller->getJavaScriptTemplate()); | ||
$container->add($this->controller->getControlTemplate()); | ||
} | ||
$container->addHtml($token); | ||
$container->addHtml($this->controller->getJavaScriptTemplate()); | ||
$container->addHtml($this->controller->getControlTemplate()); | ||
|
||
return $container; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
* @author Zechy <[email protected]> | ||
* @package Zet\FileUpload | ||
*/ | ||
class FileUploadExtension extends \Nette\DI\CompilerExtension { | ||
final class FileUploadExtension extends \Nette\DI\CompilerExtension { | ||
|
||
/** | ||
* Výchozí konfigurační hodnoty. | ||
|
@@ -18,7 +18,7 @@ class FileUploadExtension extends \Nette\DI\CompilerExtension { | |
"maxFileSize" => NULL, | ||
"uploadModel" => NULL, | ||
"fileFilter" => NULL, | ||
"uiMode" => FileUploadControl::UI_FULL | ||
"renderer" => '\Zet\FileUpload\Template\Renderer\Html5Renderer' | ||
]; | ||
|
||
/** | ||
|
@@ -32,21 +32,6 @@ class FileUploadExtension extends \Nette\DI\CompilerExtension { | |
*/ | ||
public function loadConfiguration() { | ||
$this->configuration = $this->getConfig($this->defaults); | ||
if(is_string($this->configuration["uiMode"])) { | ||
$value = $this->configuration["uiMode"]; | ||
|
||
switch($value) { | ||
case "full": | ||
$this->configuration["uiMode"] = FileUploadControl::UI_FULL; | ||
break; | ||
case "minimal": | ||
$this->configuration["uiMode"] = FileUploadControl::UI_MINIMAL; | ||
break; | ||
default: | ||
$this->configuration["uiMode"] = FileUploadControl::UI_FULL; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,22 +4,24 @@ | |
|
||
/** | ||
* Class ArchiveFilter | ||
* @author Zechy <[email protected]> | ||
* | ||
* @author Zechy <[email protected]> | ||
* @package Zet\FileUpload\Filter | ||
*/ | ||
class ArchiveFilter extends BaseFilter { | ||
|
||
/** | ||
* Vrátí seznam povolených typů souborů s jejich typickou koncovkou. | ||
* | ||
* @example array("text/plain" => "txt") | ||
* @return string[] | ||
*/ | ||
protected function getMimeTypes() { | ||
return array( | ||
return [ | ||
"application/zip" => "zip", | ||
"application/x-rar-compressed" => "rar", | ||
"application/x-tar" => "tar", | ||
"application/x-7z-compressed" => "7z" | ||
); | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,22 +4,24 @@ | |
|
||
/** | ||
* Class AudioFilter | ||
* @author Zechy <[email protected]> | ||
* | ||
* @author Zechy <[email protected]> | ||
* @package Zet\FileUpload\Filter | ||
*/ | ||
class AudioFilter extends BaseFilter { | ||
|
||
/** | ||
* Vrátí seznam povolených typů souborů s jejich typickou koncovkou. | ||
* | ||
* @example array("text/plain" => "txt") | ||
* @return string[] | ||
*/ | ||
protected function getMimeTypes() { | ||
return array( | ||
return [ | ||
"audio/mpeg3" => "mp3", | ||
"audio/x-mpeg-3" => "mp3", | ||
"audio/ogg" => "ogg", | ||
"audio/x-aiff" => "aiff" | ||
); | ||
]; | ||
} | ||
} |
Oops, something went wrong.