24 if (isset($button[
'BOT_ID']) && intval($button[
'BOT_ID']) > 0)
26 $button[
'BOT_ID'] = intval($button[
'BOT_ID']);
30 $button[
'BOT_ID'] = $this->botId;
32 if (!isset($params[
'TEXT']) || trim($params[
'TEXT']) ==
'')
37 if (isset($params[
'LINK']) && preg_match(
'#^(?:/|https?://)#', $params[
'LINK']))
39 $button[
'LINK'] = htmlspecialcharsbx($params[
'LINK']);
41 else if (isset($params[
'FUNCTION']))
43 $button[
'FUNCTION'] = htmlspecialcharsbx($params[
'FUNCTION']);
45 else if (isset($params[
'APP_ID']))
47 $button[
'APP_ID'] = intval($params[
'APP_ID']);
48 if (isset($params[
'APP_PARAMS']) && trim($params[
'APP_PARAMS']) <>
'')
50 $button[
'APP_PARAMS'] = $params[
'APP_PARAMS'];
54 isset($params[
'ACTION'])
55 && in_array($params[
'ACTION'], [
'PUT',
'SEND',
'COPY',
'CALL',
'DIALOG'])
56 && trim($params[
'ACTION_VALUE']) <>
''
59 $button[
'ACTION'] = $params[
'ACTION'];
60 $button[
'ACTION_VALUE'] = $params[
'ACTION_VALUE'];
62 else if ($this->botId > 0 && isset($params[
'COMMAND']) && trim($params[
'COMMAND']) <>
'')
64 $button[
'COMMAND'] = mb_substr($params[
'COMMAND'], 0, 1) ==
'/'? mb_substr($params[
'COMMAND'], 1) : $params[
'COMMAND'];
65 $button[
'COMMAND_PARAMS'] = isset($params[
'COMMAND_PARAMS']) && trim($params[
'COMMAND_PARAMS']) <>
''? $params[
'COMMAND_PARAMS']:
'';
72 $button[
'TEXT'] = htmlspecialcharsbx(trim($params[
'TEXT']));
74 $button[
'CONTEXT'] = isset($params[
'CONTEXT']) && in_array($params[
'CONTEXT'], [
'MOBILE',
'DESKTOP']) ? $params[
'CONTEXT'] :
'ALL';
76 $button[
'DISABLED'] = (isset($params[
'DISABLED']) && $params[
'DISABLED'] ==
'Y') ?
'Y' :
'N';
78 $this->items[] = $button;
83 public static function getByJson($params, $textReplace = array(), $options = Array())
85 if (is_string($params))
87 $params = \CUtil::JsObjectToPhp($params);
89 if (!is_array($params))
94 $menu =
new self($params[
'BOT_ID']);
95 foreach ($params[
'ITEMS'] as $button)
97 if (isset($button[
'FUNCTION']) && $options[
'ENABLE_FUNCTIONS'] !=
'Y')
102 if (isset($button[
'TEXT']))
104 foreach ($textReplace as $key => $value)
106 $button[
'TEXT'] = str_replace($key, $value, $button[
'TEXT']);
109 $menu->addItem($button);
113 return $menu->isEmpty()?
null: $menu;