You are here

function _themekey_match_properties in ThemeKey 6

Function _themekey_match_properties().

2 calls to _themekey_match_properties()
_themekey_match_paths in ./themekey_base.inc
Function _themekey_match_paths().
_themekey_node_callback in modules/themekey.node.inc

File

./themekey_base.inc, line 148

Code

function _themekey_match_properties($parameters, $object = NULL) {

  //
  if (isset($object)) {
    $parameters = _themkey_prepare_object(array_merge($parameters, (array) drupal_clone($object)));
  }

  //
  $properties = variable_get('themekey_properties', array());
  foreach (array_keys($properties) as $property) {
    $value = _themekey_property_value($parameters, $property);
    if (!empty($value) || count($value)) {
      $query = 'SELECT * FROM {themekey_properties} WHERE property = \'' . $property . '\' AND value ';
      $query .= is_array($value) ? 'IN (' . db_placeholders($value, 'varchar') . ') ORDER BY weight' : '= \'%s\'';
      $result = db_query($query, $value);
      while ($item = db_fetch_array($result)) {

        //
        $item['conditions'] = unserialize($item['conditions']);
        if (_themekey_match_conditions($item['conditions'], $parameters)) {

          //
          $callbacks = unserialize($item['callbacks']);
          if (is_array($callbacks) && count($callbacks)) {
            foreach ($callbacks as $callback) {
              $callback($item, $parameters);
            }
          }

          //
          return $item['theme'];
        }
      }
    }
  }
  return NULL;
}