1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
eventmessage.php
См. документацию.
1<?php
2
9
10namespace Bitrix\Main\Mail\Internal;
11
12use Bitrix\Main\Type;
13use Bitrix\Main\ORM;
14use Bitrix\Main\ORM\Data\DataManager;
15use Bitrix\Main\ORM\Fields\ArrayField;
16
34{
38 public static function getTableName()
39 {
40 return 'b_event_message';
41 }
42
46 public static function getMap()
47 {
48 return array(
49 'ID' => array(
50 'data_type' => 'integer',
51 'primary' => true,
52 'autocomplete' => true,
53 ),
54 'TIMESTAMP_X' => array(
55 'data_type' => 'datetime',
56 'required' => true,
57 'default_value' => function() {
58 return new Type\DateTime();
59 },
60 ),
61 'EVENT_NAME' => array(
62 'data_type' => 'string',
63 'required' => true,
64 ),
65 'LID' => array(
66 'data_type' => 'string',
67 ),
68 'ACTIVE' => array(
69 'data_type' => 'string',
70 'required' => true,
71 'default_value' => 'Y'
72 ),
73 'EMAIL_FROM' => array(
74 'data_type' => 'string',
75 'required' => true,
76 'default_value' => '#EMAIL_FROM#'
77 ),
78 'EMAIL_TO' => array(
79 'data_type' => 'string',
80 'required' => true,
81 'default_value' => '#EMAIL_TO#'
82 ),
83 'SUBJECT' => array(
84 'data_type' => 'string',
85 ),
86 'MESSAGE' => array(
87 'data_type' => 'string',
88 ),
89 'MESSAGE_PHP' => array(
90 'data_type' => 'string',
91 ),
92 'BODY_TYPE' => array(
93 'data_type' => 'string',
94 'required' => true,
95 'default_value' => 'text'
96 ),
97 'BCC' => array(
98 'data_type' => 'string',
99 ),
100 'REPLY_TO' => array(
101 'data_type' => 'string',
102 ),
103 'CC' => array(
104 'data_type' => 'string',
105 ),
106 'IN_REPLY_TO' => array(
107 'data_type' => 'string',
108 ),
109 'PRIORITY' => array(
110 'data_type' => 'string',
111 ),
112 'FIELD1_NAME' => array(
113 'data_type' => 'string',
114 ),
115 'FIELD1_VALUE' => array(
116 'data_type' => 'string',
117 ),
118 'FIELD2_NAME' => array(
119 'data_type' => 'string',
120 ),
121 'FIELD2_VALUE' => array(
122 'data_type' => 'string',
123 ),
124 'SITE_TEMPLATE_ID' => array(
125 'data_type' => 'string',
126 ),
127 (new ArrayField('ADDITIONAL_FIELD'))->configureSerializationPhp(),
128 'EVENT_MESSAGE_SITE' => array(
129 'data_type' => 'Bitrix\Main\Mail\Internal\EventMessageSite',
130 'reference' => array('=this.ID' => 'ref.EVENT_MESSAGE_ID'),
131 ),
132 'LANGUAGE_ID' => array(
133 'data_type' => 'string',
134 ),
135 );
136 }
137
138 public static function replaceTemplateToPhp($str, $fromTemplateToPhp=true)
139 {
140 preg_match_all("/#([0-9a-zA-Z_.]+?)#/", $str, $matchesFindPlaceHolders);
141 $matchesFindPlaceHoldersCount = count($matchesFindPlaceHolders[1]);
142 for($i=0; $i<$matchesFindPlaceHoldersCount; $i++)
143 if(mb_strlen($matchesFindPlaceHolders[1][$i]) > 200)
144 unset($matchesFindPlaceHolders[1][$i]);
145
146 if(empty($matchesFindPlaceHolders[1]))
147 return $str;
148 $ar = $matchesFindPlaceHolders[1];
149
150 $strResult = $str;
151 $arReplaceTagsOne = array();
152
153 if(!$fromTemplateToPhp)
154 {
155 foreach($ar as $k)
156 {
157 $replaceTo = '#'.$k.'#';
158
159 $replaceFrom = '$arParams["'.$k.'"]';
160 $replaceFromQuote = '$arParams[\''.$k.'\']';
161 $replaceFromPhp = '<?='.$replaceFrom.';?>';
162
163 $arReplaceTagsOne[$replaceFromPhp] = $replaceTo;
164 $arReplaceTagsOne[$replaceFrom] = $replaceTo;
165 $arReplaceTagsOne[$replaceFromQuote] = $replaceTo;
166 }
167 }
168 else
169 {
170 $replaceTemplateString = '';
171 foreach($ar as $k) $replaceTemplateString .= '|#'.$k.'#';
172
173 $arReplaceTags = array();
174 $bOpenPhpTag = false;
175 preg_match_all('/(<\?|\?>'.$replaceTemplateString.')/', $str, $matchesTag, PREG_OFFSET_CAPTURE);
176 foreach($matchesTag[0] as $tag)
177 {
178 $placeHolder = $tag[0];
179 $placeHolderPosition = $tag[1];
180 $ch1 = mb_substr($placeHolder, 0, 1);
181 $ch2 = mb_substr($placeHolder, 0, 2);
182
183 if($ch2 == "<?")
184 $bOpenPhpTag = true;
185 elseif($ch2 == "?>")
186 $bOpenPhpTag = false;
187 elseif($ch1 == "#")
188 {
189 $placeHolderClear = mb_substr($placeHolder, 1, mb_strlen($placeHolder) - 2);
190
191 $bOpenQuote = (mb_substr($str, $placeHolderPosition - 2, 2) == '"{');
192 $bCloseQuote = (mb_substr($str, $placeHolderPosition + mb_strlen($placeHolder), 2) == '}"');
193 if($bOpenPhpTag && $bOpenQuote && $bCloseQuote)
194 $replaceTo = '$arParams[\''.$placeHolderClear.'\']';
195 else
196 $replaceTo = '$arParams["'.$placeHolderClear.'"]';
197
198 if(!$bOpenPhpTag) $replaceTo = '<?=' . $replaceTo . ';?>';
199 $arReplaceTags[$tag[0]][] = $replaceTo;
200 }
201 }
202
203 foreach($arReplaceTags as $k => $v)
204 {
205 if(count($v)>1)
206 {
207 foreach($v as $replaceTo)
208 {
209 $resultReplace = preg_replace('/'.$k.'/', $replaceTo, $strResult, 1);
210 if($resultReplace !== null)
211 $strResult = $resultReplace;
212 }
213 }
214 else
215 {
216 $arReplaceTagsOne[$k] = $v[0];
217 }
218 }
219 }
220
221 if(!empty($arReplaceTagsOne))
222 $strResult = str_replace(array_keys($arReplaceTagsOne), array_values($arReplaceTagsOne), $strResult);
223
224 // php parser delete newline following the closing tag in string passed to eval
225 $strResult = str_replace(array("?>\n", "?>\r\n"), array("?>\n\n", "?>\r\n\r\n"), $strResult);
226
227 return $strResult;
228 }
229
234 public static function onBeforeUpdate(ORM\Event $event)
235 {
236 $result = new ORM\EventResult();
237 $data = $event->getParameters();
238
239 if(array_key_exists('MESSAGE', $data['fields']))
240 {
241 $data['fields']['MESSAGE_PHP'] = static::replaceTemplateToPhp($data['fields']['MESSAGE']);
242 $result->modifyFields($data['fields']);
243 }
244
245 return $result;
246 }
247
252 public static function onBeforeAdd(ORM\Event $event)
253 {
254 $result = new ORM\EventResult();
255 $data = $event->getParameters();
256
257 if(array_key_exists('MESSAGE', $data['fields']))
258 {
259 $data['fields']['MESSAGE_PHP'] = static::replaceTemplateToPhp($data['fields']['MESSAGE']);
260 $result->modifyFields($data['fields']);
261 }
262
263 return $result;
264 }
265}
$arParams
Определения access_dialog.php:21
static replaceTemplateToPhp($str, $fromTemplateToPhp=true)
Определения eventmessage.php:138
$str
Определения commerceml2.php:63
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$ar
Определения options.php:199
$i
Определения factura.php:643
</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
$k
Определения template_pdf.php:567