Browse Source

Button [Class]: Update for PHP 8.1

fusionate 2 years ago
parent
commit
3c7e700086
1 changed files with 24 additions and 20 deletions
  1. 24 20
      resources/classes/button.php

+ 24 - 20
resources/classes/button.php

@@ -36,9 +36,11 @@ if (!class_exists('button')) {
 				if (!empty($array['style'])) {
 					$tmp = explode(';',$array['style']);
 					foreach ($tmp as $style) {
-						if ($style) {
+						if (!empty($style)) {
 							$style = explode(':', $style);
-							$styles[trim($style[0])] = trim($style[1]);
+							if (is_array($style) && @sizeof($style) == 2) {
+								$styles[trim($style[0])] = trim($style[1]);
+							}
 						}
 					}
 					$array['style'] = $styles;
@@ -46,36 +48,37 @@ if (!class_exists('button')) {
 				}
 			//button: open
 				$button = "<button ";
-				$button .= "type='".($array['type'] ? $array['type'] : 'button')."' ";
+				$button .= "type='".(!empty($array['type']) ? $array['type'] : 'button')."' ";
 				$button .= !empty($array['name']) ? "name=".self::quote($array['name'])." " : null;
 				$button .= !empty($array['value']) ? "value=".self::quote($array['value'])." " : null;
 				$button .= !empty($array['id']) ? "id='".$array['id']."' " : null;
-				$button .= !empty($array['label']) ? "alt=".self::quote($array['label'])." " : ($array['title'] ? "alt=".self::quote($array['title'])." " : null);
+				$button .= !empty($array['label']) ? "alt=".self::quote($array['label'])." " : (!empty($array['title']) ? "alt=".self::quote($array['title'])." " : null);
 				if ($button_icons == 'only' || $button_icons == 'auto' || $array['title']) {
-					if ($array['title'] || $array['label']) {
-						$button .= "title=".($array['title'] ? self::quote($array['title']) : self::quote($array['label']))." ";
+					if (!empty($array['title']) || !empty($array['label'])) {
+						$button .= "title=".(!empty($array['title']) ? self::quote($array['title']) : self::quote($array['label']))." ";
 					}
 				}
 				$button .= !empty($array['onclick']) ? "onclick=".self::quote($array['onclick'])." " : null;
 				$button .= !empty($array['onmouseover']) ? "onmouseenter=".self::quote($array['onmouseover'])." " : null;
  				$button .= !empty($array['onmouseout']) ? "onmouseleave=".self::quote($array['onmouseout'])." " : null;
 				//detect class addition (using + prefix)
-				$button_class = $array['class'] && $array['class'][0] == '+' ? 'default '.substr($array['class'], 1) : $array['class'];
-				$button .= "class='btn btn-".($button_class ? $button_class : 'default')." ".($array['disabled'] ? 'disabled' : null)."' ";
+				$button_class = !empty($array['class']) && substr($array['class'],0,1) == '+' ? 'default '.substr($array['class'], 1) : $array['class'] ?? '';
+				$button .= "class='btn btn-".(!empty($button_class) ? $button_class : 'default')." ".(isset($array['disabled']) && $array['disabled'] ? 'disabled' : null)."' ";
 				//ensure margin* styles are not applied to the button element when a link is defined
-				if (is_array($array['style']) && @sizeof($array['style']) != 0) {
+				if (!empty($array['style']) && is_array($array['style']) && @sizeof($array['style']) != 0) {
+					$styles = '';
 					foreach ($array['style'] as $property => $value) {
-						if (!$array['link'] || !substr_count($property, 'margin')) {
+						if (empty($array['link']) || !substr_count($property, 'margin')) {
 							$styles .= $property.': '.$value.'; ';
 						}
 					}
 					$button .= $styles ? "style=".self::quote($styles)." " : null;
 					unset($styles);
 				}
-				$button .= $array['disabled'] ? "disabled='disabled' " : null;
+				$button .= isset($array['disabled']) && $array['disabled'] ? "disabled='disabled' " : null;
 				$button .= ">";
 			//icon
-				if ($array['icon'] && (
+				if (!empty($array['icon']) && (
 					$button_icons == 'only' ||
 					$button_icons == 'always' ||
 					$button_icons == 'auto' ||
@@ -85,12 +88,12 @@ if (!class_exists('button')) {
 					$button .= "<span class='".$icon_class." fa-fw'></span>";
 				}
 			//label
-				if ($array['label'] && (
+				if (!empty($array['label']) && (
 					$button_icons != 'only' ||
 					!$array['icon'] ||
 					$array['class'] == 'link'
 					)) {
-					if ($array['icon'] && $button_icons != 'always' && $button_icons != 'never' && $array['collapse'] !== false) {
+					if (!empty($array['icon']) && $button_icons != 'always' && $button_icons != 'never' && isset($array['collapse']) && $array['collapse'] !== false) {
 						if ($array['collapse'] != '') {
 							$collapse_class = $array['collapse'];
 						}
@@ -98,18 +101,19 @@ if (!class_exists('button')) {
 							$collapse_class = self::$collapse;
 						}
 					}
-					$pad_class = $array['icon'] ? 'pad' : null;
-					$button .= "<span class='button-label ".$collapse_class." ".$pad_class."'>".$array['label']."</span>";
+					$pad_class = !empty($array['icon']) ? 'pad' : null;
+					$button .= "<span class='button-label ".($collapse_class ?? '')." ".$pad_class."'>".$array['label']."</span>";
 				}
 			//button: close
 				$button .= "</button>";
 			//link
-				if ($array['link']) {
+				if (!empty($array['link'])) {
 					$anchor = "<a ";
 					$anchor .= "href='".$array['link']."' ";
-					$anchor .= "target='".($array['target'] ? $array['target'] : '_self')."' ";
+					$anchor .= "target='".(!empty($array['target']) ? $array['target'] : '_self')."' ";
 					//ensure only margin* styles are applied to the anchor element
-					if (is_array($array['style']) && @sizeof($array['style']) != 0) {
+					if (!empty($array['style']) && is_array($array['style']) && @sizeof($array['style']) != 0) {
+						$styles = '';
 						foreach ($array['style'] as $property => $value) {
 							if (substr_count($property, 'margin')) {
 								$styles .= $property.': '.$value.'; ';
@@ -118,7 +122,7 @@ if (!class_exists('button')) {
 						$anchor .= $styles ? "style=".self::quote($styles)." " : null;
 						unset($styles);
 					}
-					$anchor .= $array['disabled'] ? "class='disabled' onclick='return false;' " : null;
+					$anchor .= isset($array['disabled']) && $array['disabled'] ? "class='disabled' onclick='return false;' " : null;
 					$anchor .= ">";
 					$button = $anchor.$button."</a>";
 				}