You are here

protected function ContextConditionBreakpoint::parseBreakpoint in Context Breakpoint 7

2 calls to ContextConditionBreakpoint::parseBreakpoint()
ContextConditionBreakpoint::condition_values in plugins/context_condition_breakpoint.inc
Condition values.
ContextConditionBreakpoint::getJSConfig in plugins/context_condition_breakpoint.inc

File

plugins/context_condition_breakpoint.inc, line 12
context_condition_resolution.inc Provides the context CTools plugin base class.

Class

ContextConditionBreakpoint
@file context_condition_resolution.inc Provides the context CTools plugin base class.

Code

protected function parseBreakpoint($query) {
  $query = str_replace(' ', '', $query);
  preg_match_all('/\\(([a-z\\-]+)\\:(.+?)\\)/', $query, $matches);
  $point = array();
  for ($i = 0; $i < count($matches[0]); $i++) {
    $cmd = $matches[1][$i];
    $value = $matches[2][$i];
    switch ($cmd) {
      case 'width':
      case 'min-width':
      case 'max-width':
      case 'height':
      case 'min-height':
      case 'max-height':
      case 'device-width':
      case 'min-device-width':
      case 'max-device-width':
      case 'device-height':
      case 'min-device-height':
      case 'max-device-height':

        // Only px values are supported.
        if (strpos($value, 'px') !== false) {
          $point[$cmd] = (int) str_replace('px', '', $value);
        }
        break;
      case 'aspect-ratio':
      case 'min-aspect-ratio':
      case 'max-aspect-ratio':
      case 'device-aspect-ratio':
      case 'min-device-aspect-ratio':
      case 'max-device-aspect-ratio':
        $parts = explode('/', $value);
        if (count($parts) === 2 && is_numeric($parts[0]) && is_numeric($parts[1])) {
          $point[$cmd] = (double) $parts[0] / (double) $parts[1];
        }
        break;
      default:

        // Unsupported.
        break;
    }
  }
  return count($point) ? $point : FALSE;
}