1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
val_image_size.php
См. документацию.
1<?php
2
4
6{
7 public static function GetDescription()
8 {
9 return array(
10 "NAME" => "image_size", // unique validator string ID
11 "DESCRIPTION" => GetMessage('FORM_VALIDATOR_IMAGE_SIZE_DESCRIPTION'), // validator description
12 "TYPES" => array("image"), // list of types validator can be applied.
13 "SETTINGS" => array("CFormValidatorImageSize", "GetSettings"), // method returning array of validator settings, optional
14 "CONVERT_TO_DB" => array("CFormValidatorImageSize", "ToDB"), // method, processing validator settings to string to put to db, optional
15 "CONVERT_FROM_DB" => array("CFormValidatorImageSize", "FromDB"), // method, processing validator settings from string from db, optional
16 "HANDLER" => array("CFormValidatorImageSize", "DoValidate") // main validation method
17 );
18 }
19
20 public static function GetSettings()
21 {
22 return array(
23 "WIDTH_FROM" => array(
24 "TITLE" => GetMessage("FORM_VALIDATOR_IMAGE_SIZE_SETTINGS_WIDTH_FROM"),
25 "TYPE" => "TEXT",
26 "DEFAULT" => "0",
27 ),
28
29 "WIDTH_TO" => array(
30 "TITLE" => GetMessage("FORM_VALIDATOR_IMAGE_SIZE_SETTINGS_WIDTH_TO"),
31 "TYPE" => "TEXT",
32 "DEFAULT" => "768",
33 ),
34
35 "HEIGHT_FROM" => array(
36 "TITLE" => GetMessage("FORM_VALIDATOR_IMAGE_SIZE_SETTINGS_HEIGHT_FROM"),
37 "TYPE" => "TEXT",
38 "DEFAULT" => "0",
39 ),
40
41 "HEIGHT_TO" => array(
42 "TITLE" => GetMessage("FORM_VALIDATOR_IMAGE_SIZE_SETTINGS_HEIGHT_TO"),
43 "TYPE" => "TEXT",
44 "DEFAULT" => "1024",
45 ),
46 );
47 }
48
49 public static function ToDB($arParams)
50 {
51 $arParams["WIDTH_FROM"] = intval($arParams["WIDTH_FROM"]);
52 $arParams["WIDTH_TO"] = intval($arParams["WIDTH_TO"]);
53
54 if ($arParams["WIDTH_FROM"] > $arParams["WIDTH_TO"])
55 {
56 $tmp = $arParams["WIDTH_FROM"];
57 $arParams["WIDTH_FROM"] = $arParams["WIDTH_TO"];
58 $arParams["WIDTH_TO"] = $tmp;
59 }
60
61 $arParams["HEIGHT_FROM"] = intval($arParams["HEIGHT_FROM"]);
62 $arParams["HEIGHT_TO"] = intval($arParams["HEIGHT_TO"]);
63
64 if ($arParams["HEIGHT_FROM"] > $arParams["HEIGHT_TO"])
65 {
66 $tmp = $arParams["HEIGHT_FROM"];
67 $arParams["HEIGHT_FROM"] = $arParams["HEIGHT_TO"];
68 $arParams["HEIGHT_TO"] = $tmp;
69 }
70
71 return serialize($arParams);
72 }
73
74 public static function FromDB($strParams)
75 {
76 return unserialize($strParams, ['allowed_classes' => false]);
77 }
78
79 public static function DoValidate($arParams, $arQuestion, $arAnswers, $arValues)
80 {
81 global $APPLICATION;
82
83 if (count($arValues) > 0)
84 {
85 foreach ($arValues as $arImage)
86 {
87 // if image successfully uploaded
88 if (
89 $arImage["tmp_name"] <> ''
90 && ($arImageInfo = CFile::GetImageSize($arImage["tmp_name"]))
91 )
92 {
93 // check minimum image width
94 if ($arParams["WIDTH_FROM"] > 0 && $arImageInfo[0] < $arParams["WIDTH_FROM"])
95 {
96 $APPLICATION->ThrowException(GetMessage("FORM_VALIDATOR_IMAGE_SIZE_ERROR_WIDTH_LESS"));
97 return false;
98 }
99
100 // check maximum image width
101 if ($arParams["WIDTH_TO"] > 0 && $arImageInfo[0] > $arParams["WIDTH_TO"])
102 {
103 $APPLICATION->ThrowException(GetMessage("FORM_VALIDATOR_IMAGE_SIZE_ERROR_WIDTH_MORE"));
104 return false;
105 }
106
107 // check minimum image height
108 if ($arParams["HEIGHT_FROM"] > 0 && $arImageInfo[1] < $arParams["HEIGHT_FROM"])
109 {
110 $APPLICATION->ThrowException(GetMessage("FORM_VALIDATOR_IMAGE_SIZE_ERROR_HEIGHT_LESS"));
111 return false;
112 }
113
114 // check maximum image height
115 if ($arParams["HEIGHT_TO"] > 0 && $arImageInfo[1] > $arParams["HEIGHT_TO"])
116 {
117 $APPLICATION->ThrowException(GetMessage("FORM_VALIDATOR_IMAGE_SIZE_ERROR_HEIGHT_MORE"));
118 return false;
119 }
120 }
121 }
122 }
123
124 return true;
125 }
126}
127
128AddEventHandler("form", "onFormValidatorBuildList", array("CFormValidatorImageSize", "GetDescription"));
$arParams
Определения access_dialog.php:21
global $APPLICATION
Определения include.php:80
static ToDB($arParams)
Определения val_image_size.php:49
static GetSettings()
Определения val_image_size.php:20
static DoValidate($arParams, $arQuestion, $arAnswers, $arValues)
Определения val_image_size.php:79
static FromDB($strParams)
Определения val_image_size.php:74
static GetDescription()
Определения val_image_size.php:7
$arValues
Определения component_props.php:25
if(!is_array($prop["VALUES"])) $tmp
Определения component_props.php:203
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
AddEventHandler($FROM_MODULE_ID, $MESSAGE_ID, $CALLBACK, $SORT=100, $FULL_PATH=false)
Определения tools.php:5165
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936