15 protected $HB_ENV = [];
18 protected $params = [];
21 protected $menu_array = [];
24 protected $menu_html =
'';
27 protected $errors = [];
35 if (count($HB_ENV) == 0) {
39 $this->HB_ENV = $HB_ENV;
49 isset($this->HB_ENV[
'Cu']) &&
50 (strlen($this->HB_ENV[
'Cu']) > 0) &&
51 isset($this->HB_ENV[
'Uid']) &&
52 (strlen($this->HB_ENV[
'Uid']) > 0)
65 ->setMenuArray($params)
66 ->setMenuParams($params)
84 ->setMenuArray($params)
85 ->setMenuParams($params);
88 if (count($node) > 0) {
104 if (! (isset($this->menu_array[
'items']) && is_array($this->menu_array[
'items']))) {
108 foreach ($this->menu_array[
'items'] as $item) {
111 if (count($arr) > 0) {
127 if (! is_array($item)) {
133 if (($id == $node_id)) {
138 foreach ($item as $key => $value) {
141 if (($id == $node_id)) {
147 if (count($element_array) > 0) {
148 return $element_array;
166 foreach ($sub_array as $node_array) {
171 if (($id == $node_id)) {
172 return $element_array;
189 if (! is_readable($json_path)) {
190 $this->errors[] =
"File $json_path is not readable.";
194 $arr = json_decode(file_get_contents($json_path), 1);
199 $this->menu_array = $arr;
211 if (! (isset($params[
'json_path']) && ! empty($params[
'json_path']))) {
215 return $params[
'json_path'];
225 if ($arr ===
false) {
226 $this->errors[] =
"Could not read the JSON configuration.";
230 if (! (isset($arr[
'container']) && is_array($arr[
'container']))) {
231 $this->errors[] =
"There is no container element in the configuration.";
234 if (! (isset($arr[
'items']) && is_array($arr[
'items']))) {
235 $this->errors[] =
"There is no menu items array in the configuration.";
253 ! isset($params[
'substitute_values']) &&
254 is_array($params[
'substitute_values'])
259 foreach ($params[
'substitute_values'] as $key => $value) {
260 $this->params[$key] = $value;
277 $container = $this->menu_array[
'container'];
278 $items = $this->menu_array[
'items'];
297 isset($this->menu_array[
'toggle-element']) &&
298 is_array($this->menu_array[
'toggle-element'])
315 foreach ($items as $item) {
332 if (isset($arr[0]) && is_string($arr[0])) {
333 return $arr . PHP_EOL;
362 if (! isset($element[
'attributes'][
'id'])) {
366 return $element[
'attributes'][
'id'];
376 if (! is_array($arr)) {
380 return array_keys($arr) !== range(0, count($arr) - 1);
391 if (! isset($element[
'display'])) {
406 $key = $id .
'.display';
407 if (array_key_exists($key, $this->params)) {
408 return $this->params[$key];
411 return $display ===
true;
421 if (! isset($element[
'html-element'])) {
426 $this->
addIndent($element[
'html-element']) .
427 "<{$element['html-element']}";
438 if (! isset($element[
'html-element'])) {
443 "</{$element['html-element']}>" .
455 if (in_array($tag, [
'p',
'li',
'div'])) {
470 if (in_array($tag, [
'ul',
'li',
'p',
'div'])) {
485 if (! array_key_exists(
'html-element', $element)) {
490 if (in_array($element[
'html-element'], [
'i',
'em',
'b',
'strong',
'label',
'span'])) {
494 return '>' . PHP_EOL;
511 foreach ($element[
'attributes'] as $attr => $value) {
512 if ($attr ==
'class') {
520 $attributes .=
" $attr=\"$set_value\" ";
525 return rtrim($attributes);
535 if (! in_array($attr, [
'title',
'aria-label',
'alt',
'label'])) {
538 $translate = $this->HB_ENV[
'MC']->msg($value);
539 return (! empty($translate))? $translate : $value;
550 isset($element[
'attributes']) &&
551 is_array($element[
'attributes']);
568 foreach ($element[
'attributes'][
'class'] as $classname => $value) {
570 $set_value = $this->
setMemberValue($id, $value, $classname, $element);
573 $classes .=
"$classname ";
577 return (empty($classes))? null :
' class="' . rtrim($classes) .
'"';
590 $sub_value = $this->
setSubValue($id, $key_to_find, $element);
592 if (! is_null($sub_value)) {
608 foreach ($this->params as $identifier => $value) {
610 $ret = $this->
isKeyInArray($id, $key_to_find, $identifier, $element);
630 protected function isKeyInArray($id, $key_to_find, $input_string, $element = [])
632 if (!is_string($input_string) || empty($input_string) || !count($element))
637 if (strpos($input_string,
'.') !==
false)
640 $keys = explode(
'.', $input_string);
642 $find_id = array_shift($keys);
643 if (! ($find_id == $id)) {
647 foreach ($keys as $inner_key)
649 if (array_key_exists($inner_key, $element)) {
651 if ($inner_key == $key_to_find) {
656 $element = $element[$inner_key];
675 isset($element[
'attributes'][
'class']) &&
676 is_array($element[
'attributes'][
'class']);
694 if (! empty($user_content)) {
695 return $user_content;
700 foreach ($element[
'content'] as $content_arr) {
716 foreach ($this->params as $identifier => $value) {
718 $path = explode(
'.', $identifier);
719 $find_id = array_shift($path);
720 $target = array_pop($path);
722 if (($target ==
'content') && ($find_id == $id)) {
738 isset($element[
'content']) &&
739 is_array($element[
'content']);
752 return $this->menu_html;
762 return filter_var($value, FILTER_UNSAFE_RAW);
771 $errors =
"<ul class=\"error\">";
773 foreach ($this->errors as $error) {
774 $errors .=
"<li>$error</li>";
777 return "$errors</ul>";
786 return (count($this->errors) > 0);