array( 'name' => t('Sites'), 'description' => t('Validates on a selection of multi-site configurations.'), ), ); } function condition_sites_requirement_form($context) { $options = array(); $handle = opendir('./sites'); while ($dir = readdir($handle)) { if (is_dir('./sites/'.$dir) && file_exists('./sites/'.$dir.'/settings.php')) { $options[$dir] = (substr(conf_path(), 6) == $dir) ? ''.$dir.'' : $dir; } } $form['sites_operator'] = array( '#type' => 'radios', '#title' => t('Validate'), '#options' => array( '' => t("Always (skip requirement)"), CONDITION_NONE => t('Except on the listed sites.'), CONDITION_ANY => t('Only on the listed sites.'), ), '#default_value' => $context['operator'], ); $form['sites_sites'] = array( '#type' => 'checkboxes', '#title' => t('Sites'), '#options' => $options, '#description' => t('Listed are all Drupal !multisite directories. The currently active is bold.', array('!multisite' => l(t('multi-site'), 'http://drupal.org/getting-started/5/install/multi-site', array('attributes' => array('target' => '_blank'))))), '#default_value' => is_array($context['sites']) ? $context['sites'] : array(), ); return $form; } function condition_sites_requirement_form_submit($form, &$form_state) { if ($form_state['values']['sites_operator'] || $form_state['values']['sites_sites']) { return array( 'operator' => $form_state['values']['sites_operator'], 'sites' => $form_state['values']['sites_sites'], ); } } function condition_sites_requirement(&$condition, $context = array()) { if (!$context['operator'] || ($context['operator'] == CONDITION_NONE && !$context['sites'])) { return TRUE; } if (!$context['sites'] && $context['operator'] == CONDITION_ANY) { return FALSE; } $site = substr(conf_path(), 6); $regexp = '/^('.preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/'), array('|', '.*'), preg_quote($context['sites'], '/')).')$/'; return ($context['operator'] == CONDITION_NONE xor preg_match($regexp, $site)); } ?>