You are here

private function CSSCompression_Combine_BorderRadius::base in Advanced CSS/JS Aggregation 7

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

Expands short handed border radius props for combination

Parameters

(string) val: Rule Set:

1 call to CSSCompression_Combine_BorderRadius::base()
CSSCompression_Combine_BorderRadius::fix in advagg_css_compress/css-compressor-3.x/src/lib/Combine/BorderRadius.inc
Does the actual combining

File

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

Class

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

Code

private function base($val, $regex) {
  $pos = 0;
  while (preg_match($regex['base'], $val, $match, PREG_OFFSET_CAPTURE, $pos)) {
    $replace = '';
    $colon = strlen($match[1][0]);
    $parts = preg_split($this->rslash, trim($match[2][0]), 2);
    $positions = array(
      'top-left' => 0,
      'top-right' => 0,
      'bottom-right' => 0,
      'bottom-left' => 0,
    );
    $base = array(
      'horizontal' => array(
        'parts' => preg_split($this->rspace, trim($parts[0])),
        'pos' => $positions,
      ),
      'vertical' => array(
        'parts' => isset($parts[1]) ? preg_split($this->rspace, trim($parts[1])) : '',
        'pos' => $positions,
      ),
    );
    foreach ($base as &$config) {

      // Skip uncombinables
      if ($this->Combine
        ->checkUncombinables($config['parts'])) {
        $pos = $match[0][1] + strlen($match[0][0]) - 1;
        continue 2;
      }
      else {
        if ($config['parts'] === '') {
          continue;
        }
      }

      // Each position needs a value
      switch (count($config['parts'])) {
        case 1:
          $config['pos']['top-left'] = $config['pos']['top-right'] = $config['parts'][0];
          $config['pos']['bottom-left'] = $config['pos']['bottom-right'] = $config['parts'][0];
          break;
        case 2:
          $config['pos']['top-left'] = $config['pos']['bottom-right'] = $config['parts'][0];
          $config['pos']['bottom-left'] = $config['pos']['top-right'] = $config['parts'][1];
          break;
        case 3:
          $config['pos']['top-left'] = $config['parts'][0];
          $config['pos']['bottom-left'] = $config['pos']['top-right'] = $config['parts'][1];
          $config['pos']['bottom-right'] = $config['parts'][2];
          break;
        case 4:
          $config['pos']['top-left'] = $config['parts'][0];
          $config['pos']['top-right'] = $config['parts'][1];
          $config['pos']['bottom-right'] = $config['parts'][2];
          $config['pos']['bottom-left'] = $config['parts'][3];
          break;
        default:
          continue 2;
      }
    }

    // Build the replacement
    foreach ($positions as $p => $v) {
      if ($regex['mod'] == '-moz-') {
        $replace .= "-moz-border-radius-" . preg_replace("/-/", '', $p) . ":" . $base['horizontal']['pos'][$p] . ($base['vertical']['parts'] === '' ? '' : ' ' . $base['vertical']['pos'][$p]) . ';';
      }
      else {
        $replace .= $regex['mod'] . "border-{$p}-radius:" . $base['horizontal']['pos'][$p] . ($base['vertical']['parts'] === '' ? '' : ' ' . $base['vertical']['pos'][$p]) . ';';
      }
    }
    $pos += strlen($replace);
    $val = substr_replace($val, $replace, $match[0][1] + $colon, strlen($match[0][0]) - $colon);
  }
  return $val;
}