1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
ajax_tools.php
См. документацию.
1<?php
2
4
5class CAjax
6{
7 public static function Init()
8 {
9 // old version should be here because of compatibility
10 global $APPLICATION;
11
12 $APPLICATION->SetTemplateCSS('ajax/ajax.css');
13 $APPLICATION->AddHeadScript('/bitrix/js/main/ajax.js');
14 }
15
16 public static function GetComponentID($componentName, $componentTemplate, $additionalID)
17 {
18 $aTrace = Bitrix\Main\Diag\Helper::getBackTrace(0, DEBUG_BACKTRACE_IGNORE_ARGS);
19
20 $trace_count = count($aTrace);
21 $trace_current = $trace_count - 1;
22 for ($i = 0; $i < $trace_count; $i++)
23 {
24 if (strtolower($aTrace[$i]['function']) == 'includecomponent' && (($c = strtolower($aTrace[$i]['class'])) == 'callmain' || $c == 'cmain'))
25 {
26 $trace_current = $i;
27 break;
28 }
29 }
30
31 $sSrcFile = $aTrace[$trace_current]["file"];
32 $iSrcLine = intval($aTrace[$trace_current]["line"]);
33
34 if ($iSrcLine > 0 && $sSrcFile != '')
35 {
36 $session_string = $sSrcFile
37 . '|' . $iSrcLine
38 . '|' . $componentName
39 . '|' . ($componentTemplate ?: '.default')
40 . '|' . $additionalID
41 ;
42
43 return md5($session_string);
44 }
45 return false;
46 }
47
48 public static function GetSession()
49 {
50 return $_REQUEST[BX_AJAX_PARAM_ID] ?? false;
51 }
52
53 public static function GetSessionParam($ajax_id = false)
54 {
55 if (!$ajax_id)
56 {
57 $ajax_id = CAjax::GetSession();
58 }
59 if ($ajax_id)
60 {
61 return BX_AJAX_PARAM_ID . '=' . $ajax_id;
62 }
63 return '';
64 }
65
66 public static function AddSessionParam($url, $ajax_id = false)
67 {
68 $url_anchor = mb_strstr($url, '#');
69 if ($url_anchor !== false)
70 {
71 $url = mb_substr($url, 0, -mb_strlen($url_anchor));
72 }
73
74 $url .= str_contains($url, '?') ? '&' : '?';
75 $url .= CAjax::GetSessionParam($ajax_id);
76
77 if (isset($_REQUEST['AJAX_CALL']))
78 {
79 $url .= '&AJAX_CALL=Y';
80 }
81
82 if ($url_anchor !== false)
83 {
84 $url .= $url_anchor;
85 }
86
87 return $url;
88 }
89
90 // $text = htmlspecialcharred
91 public static function GetLinkEx($real_url, $public_url, $text, $container_id, $additional = '')
92 {
93 if (!$public_url)
94 {
95 $public_url = $real_url;
96 }
97
98 return sprintf(
99 '<a href="%s" onclick="BX.ajax.insertToNode(\'%s\', \'%s\'); return false;" %s>%s</a>',
100 htmlspecialcharsbx($public_url),
101 CUtil::JSEscape(htmlspecialcharsbx($real_url)),
102 CUtil::JSEscape(htmlspecialcharsbx($container_id)),
103 $additional,
104 $text
105 );
106 }
107
108 // $text - no htmlspecialchar
109 public static function GetLink($url, $text, $container_id, $additional = '')
110 {
111 return CAjax::GetLinkEx($url, false, htmlspecialcharsbx($text), htmlspecialcharsbx($container_id), $additional);
112 }
113
114 public static function GetForm($form_params, $container_id, $ajax_id, $bReplace = true, $bShadow = true)
115 {
116 static $rndGenerator = null;
117 if (!$rndGenerator)
118 {
119 $rndGenerator = new \Bitrix\Main\Type\RandomSequence("BX_AJAX");
120 }
121 $rnd = $rndGenerator->randString(6);
122 return '
123<form ' . trim($form_params) . '><input type="hidden" name="' . BX_AJAX_PARAM_ID . '" id="' . BX_AJAX_PARAM_ID . '_' . $ajax_id . '_' . $rnd . '" value="' . $ajax_id . '" /><input type="hidden" name="AJAX_CALL" value="Y" /><script>
124function _processform_' . $rnd . '(){
125 if (BX(\'' . BX_AJAX_PARAM_ID . '_' . $ajax_id . '_' . $rnd . '\'))
126 {
127 var obForm = BX(\'' . BX_AJAX_PARAM_ID . '_' . $ajax_id . '_' . $rnd . '\').form;
128 BX.bind(obForm, \'submit\', function() {' . CAjax::GetFormEventValue($container_id, $bReplace, $bShadow, '"') . '});
129 }
130 BX.removeCustomEvent(\'onAjaxSuccess\', _processform_' . $rnd . ');
131}
132if (BX(\'' . BX_AJAX_PARAM_ID . '_' . $ajax_id . '_' . $rnd . '\'))
133 _processform_' . $rnd . '();
134else
135 BX.addCustomEvent(\'onAjaxSuccess\', _processform_' . $rnd . ');
136</script>';
137 }
138
139 public static function ClearForm($form_params, $ajax_id = false)
140 {
141 $form_params = str_replace(CAjax::GetSessionParam($ajax_id), '', $form_params);
142
143 return '<form ' . trim($form_params) . '>';
144 }
145
146 public static function GetFormEvent($container_id)
147 {
148 return 'onsubmit="BX.ajax.submitComponentForm(this, \'' . htmlspecialcharsbx(CUtil::JSEscape($container_id)) . '\', true);"';
149 }
150
151 public static function GetFormEventValue($container_id, $bReplace = true, $bShadow = true, $event_delimiter = '\'')
152 {
153 $delimiter = $event_delimiter == '\'' ? '"' : '\'';
154 return 'BX.ajax.submitComponentForm(this, ' . $delimiter . CUtil::JSEscape($container_id) . $delimiter . ', true)';
155 //return 'jsAjaxUtil.'.($bReplace ? 'Insert' : 'Append').'FormDataToNode(this, '.$delimiter.$container_id.$delimiter.', '.($bShadow ? 'true' : 'false').')';
156 }
157
158 public static function encodeURI($str)
159 {
160 //$str = 'view'.$str;
161 return $str;
162 }
163
164 public static function decodeURI($str)
165 {
166 global $APPLICATION;
167
168 $pos = mb_strpos($str, 'view');
169 if ($pos !== 0)
170 {
171 $APPLICATION->ThrowException(GetMessage('AJAX_REDIRECTOR_BAD_URL'));
172 return false;
173 }
174
175 $str = str_replace(["\r", "\n"], "", mb_substr($str, 4));
176
177 if (preg_match("'^(/bitrix/|http://|https://|ftp://)'i", $str))
178 {
179 $APPLICATION->ThrowException(GetMessage('AJAX_REDIRECTOR_BAD_URL'));
180 return false;
181 }
182
183 return $str;
184 }
185}
global $APPLICATION
Определения include.php:80
static getBackTrace($limit=0, $options=null, $skip=1)
Определения helper.php:26
Определения ajax_tools.php:6
static GetComponentID($componentName, $componentTemplate, $additionalID)
Определения ajax_tools.php:16
static encodeURI($str)
Определения ajax_tools.php:158
static GetLink($url, $text, $container_id, $additional='')
Определения ajax_tools.php:109
static GetFormEventValue($container_id, $bReplace=true, $bShadow=true, $event_delimiter='\'')
Определения ajax_tools.php:151
static GetSessionParam($ajax_id=false)
Определения ajax_tools.php:53
static ClearForm($form_params, $ajax_id=false)
Определения ajax_tools.php:139
static GetSession()
Определения ajax_tools.php:48
static decodeURI($str)
Определения ajax_tools.php:164
static Init()
Определения ajax_tools.php:7
static GetLinkEx($real_url, $public_url, $text, $container_id, $additional='')
Определения ajax_tools.php:91
static GetForm($form_params, $container_id, $ajax_id, $bReplace=true, $bShadow=true)
Определения ajax_tools.php:114
static AddSessionParam($url, $ajax_id=false)
Определения ajax_tools.php:66
static GetFormEvent($container_id)
Определения ajax_tools.php:146
$str
Определения commerceml2.php:63
$componentTemplate
Определения component_props2.php:50
$componentName
Определения component_props2.php:49
$_REQUEST["admin_mnu_menu_id"]
Определения get_menu.php:8
const BX_AJAX_PARAM_ID(!defined('TAGGED_user_card_size'))
Определения constants.php:99
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
$text
Определения template_pdf.php:79
$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
$url
Определения iframe.php:7