mirror of https://github.com/movim/movim
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.9 KiB
75 lines
1.9 KiB
<?php
|
|
|
|
use Movim\Widget\Base;
|
|
|
|
use Moxl\Xec\Action\Upload\Request;
|
|
|
|
class Upload extends Base
|
|
{
|
|
public function load()
|
|
{
|
|
$this->addjs('upload.js');
|
|
$this->addcss('upload.css');
|
|
|
|
$this->registerEvent('upload_request_handle', 'onRequested');
|
|
$this->registerEvent('upload_request_error', 'onError');
|
|
$this->registerEvent('upload_request_errornotallowed', 'onErrorNotAllowed');
|
|
$this->registerEvent('upload_request_errorfiletoolarge', 'onErrorFileTooLarge');
|
|
$this->registerEvent('upload_request_errorresourceconstraint', 'onErrorResourceConstraint');
|
|
|
|
if (php_sapi_name() != 'cli') {
|
|
header('Access-Control-Allow-Origin: *');
|
|
}
|
|
}
|
|
|
|
public function onRequested($package)
|
|
{
|
|
list($get, $put) = array_values($package->content);
|
|
$this->rpc('Upload.request', $get, $put);
|
|
}
|
|
|
|
public function onError()
|
|
{
|
|
Notification::toast($this->__('upload.error_failed'));
|
|
}
|
|
|
|
public function onErrorFileTooLarge()
|
|
{
|
|
Notification::toast($this->__('upload.error_filesize'));
|
|
}
|
|
|
|
public function onErrorResourceConstraint()
|
|
{
|
|
Notification::toast($this->__('upload.error_resource_constraint'));
|
|
}
|
|
|
|
public function onErrorNotAllowed()
|
|
{
|
|
Notification::toast($this->__('upload.error_not_allowed'));
|
|
}
|
|
|
|
public function ajaxRequest()
|
|
{
|
|
$view = $this->tpl();
|
|
Dialog::fill($view->draw('_upload'));
|
|
}
|
|
|
|
public function ajaxSend($file)
|
|
{
|
|
$upload = $this->user->session->getUploadService();
|
|
|
|
if ($upload) {
|
|
$r = new Request;
|
|
$r->setTo($upload->server)
|
|
->setName($file->name)
|
|
->setSize($file->size)
|
|
->setType($file->type)
|
|
->request();
|
|
}
|
|
}
|
|
|
|
public function ajaxFailed()
|
|
{
|
|
Notification::toast($this->__('upload.error_failed'));
|
|
}
|
|
}
|