Skip to content

Commit

Permalink
Merge branch '2.0.0-beta'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/FileUploadControl.php
  • Loading branch information
JZechy committed Sep 28, 2017
2 parents 35d7b11 + d3e3fc5 commit 06b1202
Show file tree
Hide file tree
Showing 52 changed files with 1,596 additions and 1,548 deletions.
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
],
"require": {
"php": ">=5.6.0",
"nette/forms": ">=2.2.0",
"nette/http": ">=2.2.0",
"nette/utils": ">=2.2.0",
"nette/di": ">=2.2.0",
"nette/application": ">=2.2.0",
"tracy/tracy": ">=2.2.0",
"latte/latte": ">=2.2.0"
"nette/forms": "^v2.4.0",
"nette/http": "^v2.4.0",
"nette/utils": "^v2.4.0",
"nette/di": "^v2.4.0",
"nette/application": "^v2.4.0",
"latte/latte": "^v2.4.0"
},
"autoload": {
"classmap": ["src/"]
Expand Down
113 changes: 33 additions & 80 deletions src/FileUploadControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Zet\FileUpload;

use Tracy\Debugger;

/**
* Class FileUploadControl
* @author Zechy <[email protected]>
Expand Down Expand Up @@ -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>';
}

Expand All @@ -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>';
}

# --------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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();
Expand Down Expand Up @@ -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));
}

# --------------------------------------------------------------------
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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;
}
Expand Down
19 changes: 2 additions & 17 deletions src/FileUploadExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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'
];

/**
Expand All @@ -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;
}
}
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/Filter/ArchiveFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
];
}
}
10 changes: 6 additions & 4 deletions src/Filter/AudioFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
];
}
}
Loading

0 comments on commit 06b1202

Please sign in to comment.