public static function generateMargin($arrValues, $strType = 'margin')
{
// Initialize an empty array (see #5217)
if (!is_array($arrValues)) {
$arrValues = array('top' => '', 'right' => '', 'bottom' => '', 'left' => '', 'unit' => '');
}
$top = $arrValues['top'];
$right = $arrValues['right'];
$bottom = $arrValues['bottom'];
$left = $arrValues['left'];
// Try to shorten the definition
if ($top != '' && $right != '' && $bottom != '' && $left != '') {
if ($top == $right && $top == $bottom && $top == $left) {
return $strType . ':' . $top . $arrValues['unit'] . ';';
} elseif ($top == $bottom && $right == $left) {
return $strType . ':' . $top . $arrValues['unit'] . ' ' . $left . $arrValues['unit'] . ';';
} elseif ($top != $bottom && $right == $left) {
return $strType . ':' . $top . $arrValues['unit'] . ' ' . $right . $arrValues['unit'] . ' ' . $bottom . $arrValues['unit'] . ';';
} else {
return $strType . ':' . $top . $arrValues['unit'] . ' ' . $right . $arrValues['unit'] . ' ' . $bottom . $arrValues['unit'] . ' ' . $left . $arrValues['unit'] . ';';
}
}
$return = array();
$arrDir = array('top' => $top, 'right' => $right, 'bottom' => $bottom, 'left' => $left);
foreach ($arrDir as $k => $v) {
if ($v != '') {
$return[] = $strType . '-' . $k . ':' . $v . $arrValues['unit'] . ';';
}
}
return implode($return);
}