7use \Bitrix\Main\UI\FileInputUtility;
8use \Bitrix\Main\Web\Json;
9use \Bitrix\Main\Context;
10use \Bitrix\Main\Loader;
11use \Bitrix\Main\Localization\Loc;
17 "bitrix\\main\\ui\\uploader\\storage" =>
"lib/ui/uploader/storage.php",
18 "bitrix\\main\\ui\\uploader\\cloudstorage" =>
"lib/ui/uploader/storage.php"
21class Log implements \ArrayAccess
38 $this->file = \CBXVirtualIo::GetInstance()->GetFile($path);
40 if ($this->file->IsExists())
42 $data = unserialize($this->file->GetContents(), [
"allowed_classes" =>
false]);
43 foreach(
$data as $key => $val)
45 if (array_key_exists($key , $this->data) && is_array($this->data[$key]) && is_array($val))
46 $this->data[$key] = array_merge($this->data[$key], $val);
48 $this->data[$key] = $val;
66 if (array_key_exists($key, $this->data) && is_array($this->data) && is_array($value))
67 $this->data[$key] = array_merge($this->data[$key], $value);
69 $this->data[$key] = $value;
81 return $this->data[$key];
91 $this->file->PutContents(serialize($this->data));
114 if ($this->file instanceof \CBXVirtualFileFileSystem && $this->file->IsExists())
115 $this->file->unlink();
117 catch (\Throwable $e)
129 return array_key_exists($offset, $this->data);
136 #[\ReturnTypeWillChange]
139 if (array_key_exists($offset, $this->data))
140 return $this->data[$offset];
150 $this->
setLog($offset, $value);
158 if (array_key_exists($offset, $this->data))
160 unset($this->data[$offset]);
171 "allowUpload" =>
"A",
172 "allowUploadExt" =>
"",
184 "moduleId" =>
"main",
220 $this->script = $APPLICATION->GetCurPageParam();
224 $params[
"storage"] = (isset(
$params[
"storage"]) && is_array(
$params[
"storage"]) ?
$params[
"storage"] : array()) + $this->params[
"storage"];
225 $params[
"storage"][
"moduleId"] = preg_replace(
"/[^a-z_-]/i",
"_",
$params[
"storage"][
"moduleId"]);
227 if (array_key_exists(
"controlId",
$params))
228 $this->controlId =
$params[
"controlId"];
229 if (array_key_exists(
"events",
$params) && is_array(
$params[
"events"]))
231 foreach(
$params[
"events"] as $key => $val)
236 unset($this->params[
"events"]);
238 $this->path = \CTempFile::GetDirectoryName(
242 $this->params[
"storage"][
"moduleId"],
246 \CMain::GetServerUniqID()
261 AddEventHandler(self::EVENT_NAME, $name, $callback);
273 if (array_key_exists(
"tmp_name", $item))
275 unset($item[
"tmp_name"]);
277 foreach ($item as $key => $val)
279 if ($key ==
"chunksInfo")
281 $item[$key][
"uploaded"] = count($item[$key][
"uploaded"]);
282 $item[$key][
"written"] = count($item[$key][
"written"]);
284 else if (is_array($val))
295 array_walk_recursive(
300 $v = preg_replace(
"/<(.+?)>/is".BX_UTF_PCRE_MODIFIER,
"", $v);
316 if (!in_array($this->mode, array(
"upload",
"delete",
"view")))
319 if ($this->mode !=
"view" && !check_bitrix_sessid())
322 $this->version = (int) $this->
getRequest(
"version");
324 $directory = \CBXVirtualIo::GetInstance()->GetDirectory($this->path);
325 $directoryExists = $directory->IsExists();
326 if (!$directory->Create())
328 if (!$directoryExists)
330 $access = \CBXVirtualIo::GetInstance()->GetFile($directory->GetPath().
"/.access.php");
331 $content =
'<?$PERM["'.$directory->GetName().
'"]["*"]="X";?>';
333 if (!$access->IsExists() || mb_strpos($access->GetContents(), $content) ===
false)
335 if (($fd = $access->Open(
'ab')))
337 fwrite($fd, $content);
348 if (!defined(
"PUBLIC_AJAX_MODE"))
349 define(
"PUBLIC_AJAX_MODE",
true);
350 if (!defined(
"NO_KEEP_STATISTIC"))
351 define(
"NO_KEEP_STATISTIC",
"Y");
352 if (!defined(
"NO_AGENT_STATISTIC"))
353 define(
"NO_AGENT_STATISTIC",
"Y");
354 if (!defined(
"NO_AGENT_CHECK"))
355 define(
"NO_AGENT_CHECK",
true);
356 if (!defined(
"DisableEventsCheck"))
357 define(
"DisableEventsCheck",
true);
359 require_once(\
Bitrix\Main\
Application::getInstance()->getContext()->getServer()->getDocumentRoot().
"/bitrix/modules/main/include/prolog_before.php");
362 $APPLICATION->RestartBuffer();
366 header(
'Content-Type:application/json; charset=UTF-8');
368 echo Json::encode($result);
369 \CMain::finalActions();
380 foreach ($this->requestMethods as $method => $value)
381 $this->requestMethods[$method] = in_array($method, $methods);
390 if ($this->requestMethods[
"post"] &&
391 is_array($this->request->getPost(self::INFO_NAME)) &&
392 array_key_exists($key, $this->request->getPost(self::INFO_NAME)))
394 $res = $this->request->getPost(self::INFO_NAME);
397 if ($this->requestMethods[
"get"] &&
398 is_array($this->request->getQuery(self::INFO_NAME)) &&
399 array_key_exists($key, $this->request->getQuery(self::INFO_NAME)))
401 $res = $this->request->getQuery(self::INFO_NAME);
414 return $this->params[$key];
423 if ($checkPost ===
false && !is_array($this->request->getQuery(self::INFO_NAME)) ||
424 $checkPost !==
false && !is_array($this->request->getPost(self::INFO_NAME)))
427 if ($checkPost ===
false)
435 if ($this->mode ==
"upload")
443 ->setStorage($this->params[
"storage"])
444 ->setCopies($this->params[
"copies"]);
446 $response = $package->checkPost($this->params);
448 if ($this->version <= 1)
450 $response2 = array();
451 foreach ($response as $k => $r)
453 $response2[$k] = array(
454 "hash" => $r[
"hash"],
455 "status" => $r[
"status"],
458 if (isset($r[
"error"]))
459 $response2[$k][
"error"] = $r[
"error"];
462 "status" => $package->getLog(
"uploadStatus") ==
"uploaded" ?
"done" :
"inprogress",
464 $package->getIndex() => array_merge(
467 "executed" => $package->getLog(
"executeStatus") ==
"executed",
468 "filesCount" => $package->getLog(
"filesCount")
473 "uploading" => array(
474 $package->getCid() => $package->getCidLog()
482 else if ($this->mode ==
"delete")
497 "error" =>
"Something went wrong with the temporary file."
500 catch (\Exception $e)
504 "error" => $e->getMessage()
517 public function checkCanvases($hash, &$file, $canvases = array(), $watermark = array())
519 if (!empty($watermark))
522 $file[
"files"][
"default"],
523 $file[
"files"][
"default"],
528 if (is_array($canvases))
530 foreach ($canvases as $canvas => $canvasParams)
532 if (!array_key_exists($canvas, $file[
"files"]))
534 $source = $file[
"files"][
"default"];
538 "tmp_name" => mb_substr($source[
"tmp_name"], 0, -7).$canvas,
539 "url" => mb_substr($source[
"url"], 0, -7).$canvas
540 ), $canvasParams, $watermark);
558 $io = \CBXVirtualIo::GetInstance();
559 if (($tempRoot = \CTempFile::GetAbsoluteRoot()) && ($strFilePath = $tempRoot.$tmpName) &&
564 "tmp_name" => $strFilePath
567 else if ((($docRoot = \
Bitrix\Main\
Application::getInstance()->getContext()->getServer()->getDocumentRoot()) && $strFilePath = $docRoot.$tmpName) && $io->FileExists($strFilePath))
570 "tmp_url" => $tmpName,
571 "tmp_name" => $strFilePath
575 mb_strpos($tmpName, $docRoot) === 0)
578 "tmp_url" => str_replace(
"//",
"/",
"/".mb_substr($tmpName, mb_strlen($docRoot))),
579 "tmp_name" => $tmpName
static registerAutoLoadClasses($moduleName, array $classes)
static loadMessages($file)
static viewFile($cid, $hash, $path)
static createCanvas($source, $dest, $canvasParams=array(), $watermarkParams=array())
static getUrlFromRelativePath($tmpName)
static deleteFile($cid, $hash, $path)
offsetSet($offset, $value)
static getPaths($tmpName)
static prepareData($data)
__construct($params=array())
checkCanvases($hash, &$file, $canvases=array(), $watermark=array())
checkPost($checkPost=true)
setHandler($name, $callback)
setRequestMethodToCheck(array $methods)
static removeTmpPath($item)