Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
fileinputunclouder.php
1<?php
2namespace Bitrix\Main\UI;
3use \Bitrix\Main\Security\Sign\Signer;
4
6{
7 protected $id;
8 protected $signature;
9 protected $file;
10 protected static $salt = "fileinput";
11
12 public static function getSrc($file = array())
13 {
14 $src = $file['SRC'];
15 if ($file['HANDLER_ID'] > 0)
16 {
17 $src = "/".\COption::GetOptionString("main", "upload_dir", "upload")."/".$file["SUBDIR"]."/".$file["FILE_NAME"];
18 $path = $_SERVER["DOCUMENT_ROOT"].$src;
19 if (!(is_file($path) && file_exists($path)))
20 {
21 $sign = new Signer();
22 $s = $sign->sign($file["ID"], self::$salt);
23 $src = \COption::GetOptionString("main.fileinput", "entryPointUrl", "/bitrix/tools/upload.php")."?".
24 http_build_query(array(
25 "action" => "uncloud",
26 "file" => $file["ID"],
27 "signature" => $s
28 ));
29 }
30 }
31 else
32 {
33 $src = \Bitrix\Main\IO\Path::convertLogicalToUri($src);
34 }
35 return $src;
36 }
37
38 public static function getSrcWithResize($file = array(), $size = array())
39 {
40 $file1 = \CFile::ResizeImageGet($file["ID"], $size, BX_RESIZE_IMAGE_PROPORTIONAL, false);
41 $src = $file1['src'];
42 if ($file['HANDLER_ID'] > 0)
43 {
44 $src = "/".\COption::GetOptionString("main", "upload_dir", "upload")."/".$file["SUBDIR"]."/".$file["FILE_NAME"];
45 $path = $_SERVER["DOCUMENT_ROOT"].$src;
46 if (!(is_file($path) && file_exists($path)))
47 {
48 $sign = new Signer();
49 $s = $sign->sign($file["ID"] . "x" . $size["width"]. "x" . $size["height"], self::$salt);
50 $src = \COption::GetOptionString("main.fileinput", "entryPointUrl", "/bitrix/tools/upload.php")."?".
51 http_build_query(array(
52 "action" => "uncloud",
53 "mode" => "resize",
54 "file" => $file["ID"],
55 "width" => $size["width"],
56 "height" => $size["height"],
57 "signature" => $s
58 ));
59 }
60 }
61 else
62 {
63 $src = \Bitrix\Main\IO\Path::convertLogicalToUri($src);
64 }
65 return $src;
66 }
67
68
69 public function setValue($id)
70 {
71 $this->id = (int) $id;
72 return $this;
73 }
74
75 public function setSignature($signature)
76 {
77 $this->signature = $signature;
78 return $this;
79 }
80
81 protected function check($params = array())
82 {
83 $sign = new Signer;
84
85 $str = (string) $sign->unsign($this->signature, self::$salt);
86 $str2 = (string) $this->id;
87
88 if (is_array($params) && array_key_exists("width", $params) && $params["width"] > 0 && array_key_exists("height", $params) && $params["height"] > 0)
89 {
90 $str2 = $this->id . "x" . $params["width"] . "x" . $params["height"];
91 }
92 return ($str == $str2);
93 }
94
95 public function exec($mode = "basic", $params = array())
96 {
97 $res = $this->check($params);
98 if ($this->check($params))
99 {
100 $this->file = \CFile::getFileArray($this->id);
101 if ($mode == "resize")
102 {
103 $file = \CFile::ResizeImageGet($this->file, $params, BX_RESIZE_IMAGE_PROPORTIONAL, true, false, true);
104 if ($file)
105 {
106 $this->file["SRC"] = $file["src"];
107 $this->file["WIDTH"] = $file["width"];
108 $this->file["HEIGHT"] = $file["height"];
109 $this->file["FILE_SIZE"] = $file["size"];
110 }
111 }
112 \CFile::ViewByUser($this->file, array("force_download" => false, "cache_time" => 0));
113 }
114 }
115}
unsign($signedValue, $salt=null)
Definition signer.php:153
exec($mode="basic", $params=array())
static getSrcWithResize($file=array(), $size=array())