You are here

private function CSSCompression_Combine_BorderRadius::fix in Advanced CSS/JS Aggregation 6

Same name and namespace in other branches
  1. 7 advagg_css_compress/css-compressor-3.x/src/lib/Combine/BorderRadius.inc \CSSCompression_Combine_BorderRadius::fix()

Does the actual combining

Parameters

(string) val: Rule Set:

1 call to CSSCompression_Combine_BorderRadius::fix()
CSSCompression_Combine_BorderRadius::combine in advagg_css_compress/css-compressor-3.x/src/lib/Combine/BorderRadius.inc
Main handler to combine border-radii into a single rule

File

advagg_css_compress/css-compressor-3.x/src/lib/Combine/BorderRadius.inc, line 70

Class

CSSCompression_Combine_BorderRadius
CSS Compressor [VERSION] [DATE] Corey Hart @ http://www.codenothing.com

Code

private function fix($val, $regex) {
  $val = $this
    ->base($val, $regex);
  $replace = $regex['mod'];

  // Storage builder
  if (($storage = $this
    ->storage($val, $regex)) === false) {
    return $val;
  }

  // Setup horizontal/vertical radii
  foreach ($storage as $dir => &$config) {

    // Verticals are optional
    if ($dir == 'vertical' && !$config['keep']) {
      break;
    }
    else {
      if ($config['top-left'] == $config['top-right'] && $config['top-right'] == $config['bottom-right'] && $config['bottom-right'] == $config['bottom-left']) {
        $config['replace'] .= $config['top-left'];
      }
      else {
        if ($config['top-left'] == $config['bottom-right'] && $config['top-right'] == $config['bottom-left']) {
          $config['replace'] .= $config['top-left'] . ' ' . $config['top-right'];
        }
        else {
          if ($config['top-right'] == $config['bottom-left']) {
            $config['replace'] .= $config['top-left'] . ' ' . $config['top-right'] . ' ' . $config['bottom-right'];
          }
          else {
            $config['replace'] .= $config['top-left'] . ' ' . $config['top-right'] . ' ' . $config['bottom-right'] . ' ' . $config['bottom-left'];
          }
        }
      }
    }
  }

  // Now rebuild the string replacing all instances of margin/padding if shorthand exists
  $pos = 0;
  $replace = $regex['mod'] . "border-radius:" . $storage['horizontal']['replace'] . $storage['vertical']['replace'] . ';';
  while (preg_match($regex['full'], $val, $match, PREG_OFFSET_CAPTURE, $pos)) {
    $colon = strlen($match[1][0]);
    $val = substr_replace($val, $replace, $match[0][1] + $colon, strlen($match[0][0]) - $colon);
    $pos = $match[0][1] + strlen($replace) - $colon - 1;
    $replace = '';
  }

  // Return converted val
  return $val;
}