1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
listfile.php
См. документацию.
1<?
2
4
6
8{
9 private $_list_id;
10 private $_section_id;
11 private $_element_id;
12 private $_field_id;
13 private $_file_id;
14 private $_socnet_group_id;
15
16 private $_file;
17 private $_width = 0;
18 private $_height = 0;
19
21 private static $_counter = 0;
22
23 function __construct($list_id, $section_id, $element_id, $field_id, $file_id)
24 {
25 $this->_list_id = intval($list_id);
26 $this->_section_id = intval($section_id);
27 $this->_element_id = intval($element_id);
28 $this->_field_id = $field_id;
29 $this->_file_id = intval($file_id);
30 $this->_socnet_group_id = "";
31
32 $this->_file = CFile::GetFileArray($this->_file_id);
33 if(is_array($this->_file))
34 {
35 $this->_width = intval($this->_file['WIDTH']);
36 $this->_height = intval($this->_file['HEIGHT']);
37 }
38 }
39
40 function SetSocnetGroup($socnet_group_id)
41 {
42 if($socnet_group_id > 0)
43 $this->_socnet_group_id = intval($socnet_group_id);
44 }
45
47 {
48 $html = '';
49
50 if(is_array($this->_file))
51 {
52 $intWidth = $this->_width;
53 $intHeight = $this->_height;
54 $img_src = '';
55 $divId = '';
56 if (isset($params['url_template']))
57 {
58 $img_src = $this->GetImgSrc(array('url_template' => $params['url_template']));
59 if ($img_src)
60 {
61 self::$_counter++;
62 $divId = 'lists-image-info-'.self::$_counter;
63 }
64 }
65
66 $attributes = ItemAttributes::buildByFileData($this->_file, $img_src);
67 $attributes->setTitle($this->_file['FILE_NAME']);
68
69 if ($divId)
70 {
71 $html .= '<div id="'.$divId.'">';
72 }
73 else
74 {
75 $html .= '<div>';
76 }
77
78 if (isset($params['view']) && $params['view'] == 'short')
79 {
80 $info = $this->_file["ORIGINAL_NAME"].' (';
81 if($intWidth > 0 && $intHeight > 0)
82 {
83 $info .= $intWidth.'x'.$intHeight.', ';
84 }
85 $info .= CFile::FormatSize($this->_file['FILE_SIZE']).')';
86 $html .= GetMessage('FILE_TEXT').': <span class="lists-file-preview-data" '.$attributes.'>'.htmlspecialcharsex($info).'</span>';
87 }
88 else
89 {
90 $html .= GetMessage('FILE_TEXT').': <span class="lists-file-preview-data" '.$attributes.'>'.htmlspecialcharsex($this->_file["ORIGINAL_NAME"]).'</span>';
91
92 if($intWidth > 0 && $intHeight > 0)
93 {
94 $html .= '<br>'.GetMessage('FILE_WIDTH').': '.$intWidth;
95 $html .= '<br>'.GetMessage('FILE_HEIGHT').': '.$intHeight;
96 }
97 $html .= '<br>'.GetMessage('FILE_SIZE').': '.CFile::FormatSize($this->_file['FILE_SIZE']);
98 }
99
100 $html .= '</div>';
101 }
102
103 return $html;
104 }
105
107 {
108 $input_name = $this->_field_id;
109 $size = 20;
110 $show_info = false;
111
112 if(is_array($params))
113 {
114 if(isset($params['input_name']))
115 $input_name = $params['input_name'];
116 if(isset($params['size']))
117 $size = intval($params['size']);
118 if(isset($params['show_info']))
119 $show_info = (bool)$params['show_info'];
120 }
121
122 $strReturn = ' <input name="'.htmlspecialcharsbx($input_name).'" size="'.$size.'" type="file" />';
123
124 if(is_array($this->_file))
125 {
126 if($show_info)
127 {
128 $strReturn .= $this->GetInfoHTML(array(
129 'url_template' => $params['url_template'],
130 'view' => 'short',
131 ));
132 }
133
134 $p = mb_strpos($input_name, "[");
135 if($p > 0)
136 $del_name = mb_substr($input_name, 0, $p)."_del".mb_substr($input_name, $p);
137 else
138 $del_name = $input_name."_del";
139
140 $strReturn .= '<input type="checkbox" name="'.htmlspecialcharsbx($del_name).'" value="Y" id="'.htmlspecialcharsbx($del_name).'" />';
141 $strReturn .= ' <label for="'.htmlspecialcharsbx($del_name).'">'.GetMessage('FILE_DELETE').'</label><br>';
142 }
143
144 return $strReturn;
145 }
146
147 function GetImgSrc($params = array())
148 {
149 if(is_array($params) && isset($params['url_template']) && ($params['url_template'] <> ''))
150 {
151 $result = str_replace(
152 array('#list_id#', '#section_id#', '#element_id#', '#field_id#', '#file_id#', '#group_id#'),
153 array($this->_list_id, $this->_section_id, $this->_element_id, $this->_field_id, $this->_file_id, $this->_socnet_group_id),
154 $params['url_template']
155 );
156 return CHTTP::urlAddParams($result, array("ncc" => "y", "download" => "y"));
157 }
158 elseif(is_array($this->_file))
159 {
160 return $this->_file['SRC'];
161 }
162 else
163 {
164 return '';
165 }
166
167 }
169 {
170 $max_width = 0;
171 $max_height = 0;
172
173 if(is_array($params))
174 {
175 if(isset($params['max_width']))
176 $max_width = intval($params['max_width']);
177 if(isset($params['max_height']))
178 $max_height = intval($params['max_height']);
179 }
180
181 if(is_array($this->_file))
182 {
183 $intWidth = $this->_width;
184 $intHeight = $this->_height;
185 if($intWidth > 0 && $intHeight > 0 && $max_width > 0 && $max_height > 0)
186 {
187 if($intWidth > $max_width || $intHeight > $max_height)
188 {
189 $coeff = ($intWidth/$max_width > $intHeight/$max_height? $intWidth/$max_width : $intHeight/$max_height);
190 $intWidth = intval(roundEx($intWidth/$coeff));
191 $intHeight= intval(roundEx($intHeight/$coeff));
192 }
193 }
194
195 $src = $this->GetImgSrc($params);
196 $attributes = ItemAttributes::buildByFileData($this->_file, $src);
197 $html = '<img class="lists-file-preview-data" src="'.htmlspecialcharsbx($src).'" '.$attributes.' width="'.$intWidth.'" height="'.$intHeight.'"';
198 if(is_array($params) && isset($params['html_attributes']) && is_array($params['html_attributes']))
199 {
200 foreach($params['html_attributes'] as $name => $value)
201 if(preg_match('/^[a-zA-Z-]+$/', $name))
202 $html .= ' '.$name.'="'.htmlspecialcharsbx($value).'"';
203 }
204 $html .= '/>';
205 return $html;
206 }
207 else
208 {
209 return '';
210 }
211 }
212
214 {
215 if(is_array($this->_file))
216 {
217 $src = CHTTP::urlAddParams($this->GetImgSrc($params), array("download" => "y"));
218 return ' [ <a href="'.htmlspecialcharsbx($src).'" target="_self">'.$params['download_text'].'</a> ] ';
219 }
220 else
221 {
222 return '';
223 }
224 }
225
226 function GetWidth()
227 {
228 return $this->_width;
229 }
230
231 function GetHeight()
232 {
233 return $this->_height;
234 }
235
236 function GetSize()
237 {
238 if(is_array($this->_file))
239 return $this->_file["FILE_SIZE"];
240 else
241 return 0;
242 }
243
244 function IsImage()
245 {
246 return is_array($this->_file) && ($this->_width > 0) && ($this->_height > 0);
247 }
248}
249?>
static urlAddParams($url, $add_params, $options=[])
Определения http.php:521
Определения listfile.php:8
SetSocnetGroup($socnet_group_id)
Определения listfile.php:40
IsImage()
Определения listfile.php:244
GetHeight()
Определения listfile.php:231
GetInputHTML($params=array())
Определения listfile.php:106
GetSize()
Определения listfile.php:236
GetLinkHtml($params=array())
Определения listfile.php:213
GetImgHtml($params=array())
Определения listfile.php:168
GetImgSrc($params=array())
Определения listfile.php:147
GetWidth()
Определения listfile.php:226
GetInfoHTML($params=array())
Определения listfile.php:46
__construct($list_id, $section_id, $element_id, $field_id, $file_id)
Определения listfile.php:23
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$p
Определения group_list_element_edit.php:23
if($NS['step']==6) if( $NS[ 'step']==7) if(COption::GetOptionInt('main', 'disk_space', 0) > 0) $info
Определения backup.php:924
roundEx($value, $prec=0)
Определения tools.php:4635
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$name
Определения menu_edit.php:35
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799