1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
blog_image.php
См. документацию.
1<?php
2
4
5$GLOBALS["BLOG_IMAGE"] = Array();
6
8{
9 const NOT_ATTACHED_IMAGES_LIFETIME = 86400; //one day
10
11 /*************** ADD, UPDATE, DELETE *****************/
12 public static function CheckFields($ACTION, &$arFields, $ID = 0)
13 {
14 global $APPLICATION;
15
16 if (is_set($arFields, "FILE_ID"))
17 {
18 $arFile = null;
19 if (is_array($arFields['FILE_ID']))
20 {
21 if ($arFields["FILE_ID"]["name"] == '' && $arFields["FILE_ID"]["del"] == '')
22 {
23 unset($arFields["FILE_ID"]);
24 }
25
26 $arFile = $arFields["FILE_ID"];
27 }
28 else
29 {
30 $arFields['FILE_ID'] = intval($arFields['FILE_ID']);
31 if ($arFields['FILE_ID'] > 0)
32 {
33 $arFile = CFile::GetFileArray($arFields['FILE_ID']);
34 }
35 }
36
37 if ($arFile)
38 {
39 $res = CFile::CheckImageFile($arFile, 0, 0, 0);
40 if ($res <> '')
41 {
42 $APPLICATION->ThrowException($res, "ERROR_ATTACH_IMG");
43 return false;
44 }
45 }
46
47 if(
48 $arFields["IMAGE_SIZE_CHECK"] != "N"
49 && intval($arFields["IMAGE_SIZE"]) > 0
50 && intval($arFields["IMAGE_SIZE"]) > COption::GetOptionString("blog", "image_max_size", 5000000)
51 )
52 {
53 $APPLICATION->ThrowException(GetMessage("ERROR_ATTACH_IMG_SIZE", Array("#SIZE#" => DoubleVal(COption::GetOptionString("blog", "image_max_size", 5000000)/1000000))), "ERROR_ATTACH_IMG_SIZE");
54 return false;
55 }
56
57 unset($arFields["IMAGE_SIZE_CHECK"]);
58 }
59
60 return True;
61 }
62
63 public static function ImageFixSize($aFile)
64 {
65 $file = $aFile['tmp_name'];
66 preg_match("#/([a-z]+)#is", $aFile['type'], $regs);
67 $ext_tmp = $regs[1];
68
71
72 switch ($ext_tmp)
73 {
74 case 'jpeg':
75 case 'pjpeg':
76 case 'jpg':
77 if(!function_exists("imageJPEG") || !function_exists("imagecreatefromjpeg"))
78 return false;
79 break;
80 case 'gif':
81 if(!function_exists("imageGIF") || !function_exists("imagecreatefromgif"))
82 return false;
83 break;
84 case 'png':
85 if(!function_exists("imagePNG") || !function_exists("imagecreatefrompng"))
86 return false;
87 break;
88 }
89
90 switch ($ext_tmp)
91 {
92 case 'jpeg':
93 case 'pjpeg':
94 case 'jpg':
95 $imageInput = imagecreatefromjpeg($file);
96 $ext_tmp = 'jpg';
97 break;
98 case 'gif':
99 $imageInput = imagecreatefromgif($file);
100 break;
101 case 'png':
102 $imageInput = imagecreatefrompng($file);
103 break;
104 }
105
106 $imgX = imagesx($imageInput);
107 $imgY = imagesy($imageInput);
108
109 if ($imgX > $sizeX || $imgY > $sizeY)
110 {
111 $newX = $sizeX;
112 $newY = $imgY * ($newX / $imgX);
113
114 if ($newY > $sizeY)
115 {
116 $newY = $sizeY;
117 $newX = $imgX * ($newY / $imgY);
118 }
119
120 if (function_exists("imagecreatetruecolor"))
121 $imageOutput = ImageCreateTrueColor($newX, $newY);
122 else
123 $imageOutput = ImageCreate($newX, $newY);
124
125 if(function_exists("imagecopyresampled"))
126 imagecopyresampled($imageOutput, $imageInput, 0, 0, 0, 0, $newX, $newY, $imgX, $imgY);
127 else
128 imagecopyresized($imageOutput, $imageInput, 0, 0, 0, 0, $newX, $newY, $imgX, $imgY);
129
130 switch ($ext_tmp)
131 {
132 case 'jpg':
133 return (imageJPEG($imageOutput, $file));
134 case 'gif':
135 return (imageGIF($imageOutput, $file));
136 case 'png':
137 return (imagePNG($imageOutput, $file));
138 }
139 }
140 return true;
141 }
142
143 public static function Delete($ID)
144 {
145 global $DB;
146
147 $ID = intval($ID);
148 unset($GLOBALS["BLOG_IMAGE"]["BLOG_IMAGE_CACHE_".$ID]);
150 {
151 CFile::Delete($res['FILE_ID']);
152 return $DB->Query("DELETE FROM b_blog_image WHERE ID = ".$ID, true);
153 }
154 return false;
155 }
156
157 //*************** SELECT *********************/
158 public static function GetByID($ID)
159 {
160 global $DB;
161
162 $ID = intval($ID);
163
164 if (isset($GLOBALS["BLOG_IMAGE"]["BLOG_IMAGE_CACHE_".$ID]) && is_array($GLOBALS["BLOG_IMAGE"]["BLOG_IMAGE_CACHE_".$ID]) && is_set($GLOBALS["BLOG_IMAGE"]["BLOG_IMAGE_CACHE_".$ID], "ID"))
165 {
166 return $GLOBALS["BLOG_IMAGE"]["BLOG_IMAGE_CACHE_".$ID];
167 }
168 else
169 {
170 $strSql =
171 "SELECT G.* ".
172 "FROM b_blog_image G ".
173 "WHERE G.ID = ".$ID."";
174 $dbResult = $DB->Query($strSql);
175 if ($arResult = $dbResult->Fetch())
176 {
177 $GLOBALS["BLOG_IMAGE"]["BLOG_IMAGE_CACHE_".$ID] = $arResult;
178 return $arResult;
179 }
180 }
181
182 return False;
183 }
184
185 public static function AddImageResizeHandler($arParams)
186 {
187 AddEventHandler('main', "main.file.input.upload", array(__class__, 'ImageResizeHandler'));
188 $bNull = null;
190 }
191
192 public static function AddImageCreateHandler($arParams)
193 {
194 AddEventHandler('main', "main.file.input.upload", array(__class__, 'ImageCreateHandler'));
195 $bNull = null;
197 }
198
199 public static function ImageResizeHandler(&$arCustomFile, $arParams = null)
200 {
201// static for save values from arParams to next method call
202 static $arResizeParams = array();
203
204 if ($arParams !== null)
205 $arResizeParams = $arParams;
206
207 if ((!is_array($arCustomFile)) || !isset($arCustomFile['fileID']))
208 return false;
209
210 $fileID = $arCustomFile['fileID'];
211 $arFile = CFile::MakeFileArray($fileID);
212 $arCustomFile['content_type'] = $arFile['CONTENT_TYPE'];
213 if ($arFile && CFile::CheckImageFile($arFile) === null)
214 {
215 $aImgThumb = CFile::ResizeImageGet(
216 $fileID,
217 array("width" => 90, "height" => 90),
219 true
220 );
221 $arCustomFile['img_thumb_src'] = $aImgThumb['src'];
222
223 $aImgSource = CFile::ResizeImageGet(
224 $fileID,
225 array("width" => $arResizeParams["width"], "height" => $arResizeParams["height"]),
227 true
228 );
229 $arCustomFile['img_source_src'] = $aImgSource['src'];
230 }
231 }
232
233 public static function ImageCreateHandler(&$arCustomFile, $arParams = null)
234 {
235// static for save values from arParams to next method call
236 static $arCreateParams = array();
237 global $DB;
238
239 if ($arParams !== null)
240 $arCreateParams = $arParams;
241
242 if ((!is_array($arCustomFile)) || !isset($arCustomFile['fileID']))
243 return false;
244
245 $fileID = $arCustomFile['fileID'];
246 $arFile = CFile::MakeFileArray($fileID);
247 $arCustomFile['content_type'] = $arFile['CONTENT_TYPE'];
248 if ($arFile && CFile::CheckImageFile($arFile) === null)
249 {
250 $imageFields = array(
251 "FILE_ID" => $fileID,
252 "BLOG_ID" => 0,
253 "POST_ID" => 0,
254 "USER_ID" => $arCreateParams['USER_ID'],
255 "=TIMESTAMP_X" => $DB->GetNowFunction(),
256 "TITLE" => $arFile['originalName'] ? $arFile['originalName'] : $arFile['name'],
257 "IMAGE_SIZE" => $arFile['~filesize'],
258 "IS_COMMENT" => $arCreateParams['IS_COMMENT'],
259 );
260 if($arCreateParams['IS_COMMENT'] == 'Y')
261 $imageFields["COMMENT_ID"] = 0;
262
263 $imageId = CBlogImage::Add($imageFields);
264 if (intval($imageId) <= 0)
265 {
266 $GLOBALS["APPLICATION"]->ThrowException("Error Adding file by CBlogImage::Add");
267 }
268 }
269 }
270}
$arParams
Определения access_dialog.php:21
global $APPLICATION
Определения include.php:80
$arResult
Определения generate_coupon.php:16
static getImageMaxWidth()
Определения util.php:23
static getImageMaxHeight()
Определения util.php:32
Определения blog_image.php:8
static Delete($ID)
Определения blog_image.php:143
static GetByID($ID)
Определения blog_image.php:158
static ImageResizeHandler(&$arCustomFile, $arParams=null)
Определения blog_image.php:199
const NOT_ATTACHED_IMAGES_LIFETIME
Определения blog_image.php:9
static CheckFields($ACTION, &$arFields, $ID=0)
Определения blog_image.php:12
static AddImageCreateHandler($arParams)
Определения blog_image.php:192
static AddImageResizeHandler($arParams)
Определения blog_image.php:185
static ImageCreateHandler(&$arCustomFile, $arParams=null)
Определения blog_image.php:233
static ImageFixSize($aFile)
Определения blog_image.php:63
static Add($arFields)
Определения blog_image.php:8
$arFields
Определения dblapprove.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$GLOBALS["BLOG_IMAGE"]
Определения blog_image.php:5
if($ajaxMode) $ID
Определения get_user.php:27
global $DB
Определения cron_frame.php:29
$ACTION
Определения csv_new_setup.php:27
const BX_RESIZE_IMAGE_EXACT
Определения constants.php:12
const BX_RESIZE_IMAGE_PROPORTIONAL
Определения constants.php:11
AddEventHandler($FROM_MODULE_ID, $MESSAGE_ID, $CALLBACK, $SORT=100, $FULL_PATH=false)
Определения tools.php:5165
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
is_set($a, $k=false)
Определения tools.php:2133
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$GLOBALS['_____370096793']
Определения update_client.php:1
$dbResult
Определения updtr957.php:3