'Conditions', 'description' => 'Configure conditions other modules use to trigger actions.', 'page callback' => 'drupal_get_form', 'page arguments' => array('condition_list_form'), 'access arguments' => array('administer conditions'), 'file' => 'condition.admin.inc', ); $items['admin/build/condition/list'] = array( 'title' => t('List'), 'weight' => -10, 'type' => MENU_DEFAULT_LOCAL_TASK, ); $items['admin/build/condition/add'] = array( 'title' => t('Add'), 'page callback' => 'drupal_get_form', 'page arguments' => array('condition_edit_form'), 'type' => MENU_LOCAL_TASK, 'file' => 'condition.admin.inc', ); $items['admin/build/condition/%condition/edit'] = array( 'title' => t('Edit'), 'page callback' => 'drupal_get_form', 'page arguments' => array('condition_edit_form', 3), 'type' => MENU_CALLBACK, 'file' => 'condition.admin.inc', ); $items['admin/build/condition/%condition/delete'] = array( 'title' => t('Delete'), 'page callback' => 'drupal_get_form', 'page arguments' => array('condition_delete_form', 3), 'type' => MENU_CALLBACK, 'file' => 'condition.admin.inc', ); return $items; } /** * Implementation of hook_perm(). */ function condition_perm() { return array('administer conditions'); } /** * Implementation of hook_theme(). */ function condition_theme() { return array( 'condition_edit_form' => array('arguments' => array('form' => NULL)), 'condition_list_form' => array('arguments' => array('form' => NULL)), ); } /** * Implementation of hook_help(). */ function condition_help($path, $arg) { switch ($path) { case 'admin/build/condition': return '
'.t('Conditions are sets of requirements that make the condition met (TRUE) or not (FALSE). Other modules can provide requirements (e.g. requested path is admin/*) or use the Condition API to trigger some kind of action (e.g. switch theme to Garland) in case a condition is met. Start by !adding a condition.', array('!adding' => l(t('adding'), 'admin/build/condition/add'))).'
'; } } /** * Loading one, more or all conditions. */ function condition_load($cid = NULL) { static $conditions; if (!is_array($conditions)) { if (is_numeric($cid)) { $condition = db_fetch_object(db_query("SELECT * FROM {conditions} WHERE cid = %d", $cid)); $condition->parameters = (array) unserialize($condition->parameters); return $condition; } else { $result = db_query("SELECT * FROM {conditions} ORDER BY weight ASC"); $conditions = array(); while ($condition = db_fetch_object($result)) { $condition->parameters = (array) unserialize($condition->parameters); $conditions[$condition->cid] = $condition; } } } if (is_array($conditions)) { if (is_numeric($cid)) { return $conditions[$cid]; } elseif (is_array($cid)) { return array_intersect_key($conditions, array_flip($cid)); } else { return $conditions; } } } /** * Saving one or more conditions. */ function condition_save($condition) { if (is_array($condition)) { foreach (array_keys($condition) as $key) { $condition[$key]->saved = condition_save($condition[$key]); } return $condition; } if ($condition->parameters) { $condition->parameters = serialize($condition->parameters); } return drupal_write_record('conditions', $condition, $condition->cid ? 'cid' : array()); } /** * Deleting one or more conditions. */ function condition_delete($condition) { if (is_array($condition)) { foreach (array_keys($condition) as $key) { $condition[$key]->deleted = condition_delete($condition[$key]); } return $condition; } if (!is_object($condition)) { $condition = condition_load($condition); } return db_query("DELETE FROM {conditions} WHERE cid = %d", $condition->cid); } /** * Validating a condition. */ function condition_validate($condition) { static $validations; if (is_array($condition)) { foreach (array_keys($condition) as $key) { $condition[$key]->valid = condition_validate($condition[$key]); } return $condition; } if (is_array($validations) && isset($validations[$condition->cid])) { $condition->valid = $validations[$condition->cid]; return $condition; } $requirements = module_invoke_all('requirement_info'); $valid = TRUE; if (is_array($requirements) && count($requirements)) { foreach ($requirements as $requirement => $info) { if ($condition->parameters[$requirement]) { if ($name($condition->parameters[$requirement]) === FALSE) { $valid = FALSE; break; } } } } return $validations[$condition->cid] = $valid; } ?>