Index: feedback.admin.inc =================================================================== --- feedback.admin.inc (revision 35) +++ feedback.admin.inc (working copy) @@ -120,3 +120,32 @@ } } +/** + * Manage feedback module settings. + */ +function feedback_admin_settings_form() { + $form = array(); + + $op = 'type'; + $options = array(); + // Invoke the hook_feedback_storage 'type' op to get available storage options. + foreach (module_invoke_all('feedback_storage', $op) as $type) { + $options[$type] = $type; + } + + $form['feedback_storage_settings'] = array( + '#title' => t('Storage settings'), + '#description' => t('Select where the Feedback module should save data.'), + '#type' => 'select', + // Disable by default, enable later if there's more than one option. + '#disabled' => TRUE, + '#options' => $options, + '#default_value' => variable_get('feedback_storage_settings', 'basic storage'), + ); + + if (count($options) > 1) { + $form['feedback_storage_settings']['#disabled'] = FALSE; + } + + return system_settings_form($form); +} Index: feedback.module =================================================================== --- feedback.module (revision 35) +++ feedback.module (working copy) @@ -10,7 +10,7 @@ * Implementation of hook_perm(). */ function feedback_perm() { - return array('access feedback form', 'view feedback messages'); + return array('access feedback form', 'view feedback messages', 'administer feedback'); } /** @@ -25,6 +25,24 @@ } /** + * Implementation of hook_hook_info(). + */ +function feedback_hook_info() { + return array( + 'feedback' => array( + 'feedback_storage' => array( + 'insert' => array( + 'runs when' => t('Before saving a new feedback entry'), + ), + 'type' => array( + 'runs when' => t('When the admin settings form is built'), + ), + ), + ), + ); +} + +/** * Implementation of hook_menu(). */ function feedback_menu() { @@ -36,6 +54,14 @@ 'access arguments' => array('view feedback messages'), 'file' => 'feedback.admin.inc', ); + $items['admin/settings/feedback'] = array( + 'title' => 'Feedback settings', + 'description' => 'Administer feedback settings.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('feedback_admin_settings_form'), + 'access arguments' => array('administer feedback'), + 'file' => 'feedback.admin.inc', + ); return $items; } @@ -224,8 +250,26 @@ */ function feedback_add_entry($message, $location) { global $user; + + // Invoke hook_feedback_storage. + $op = 'insert'; + $user_agent = $_SERVER['HTTP_USER_AGENT']; + module_invoke_all('feedback_storage', $op, $message, $location, $user, $user_agent); +} - db_query("INSERT INTO {feedback} (uid, message, location, location_masked, url, timestamp, useragent) VALUES (%d, '%s', '%s', '%s', '%s', %d, '%s')", $user->uid, trim($message), $location, feedback_mask_path($location), url($location, array('absolute' => TRUE)), time(), $_SERVER['HTTP_USER_AGENT']); +/** + * Implementation of hook_feedback_storage(). + */ +function feedback_feedback_storage($op, $message = NULL, $location = NULL, $user = NULL, $user_agent = NULL) { + // Ensure this is a store op and basic feedback storage is enabled. + if (variable_get('feedback_storage_settings', 'basic storage') && $op == 'insert') { + // Store feedback in database. + db_query("INSERT INTO {feedback} (uid, message, location, location_masked, url, timestamp, useragent) VALUES (%d, '%s', '%s', '%s', '%s', %d, '%s')", $user->uid, trim($message), $location, feedback_mask_path($location), url($location, array('absolute' => TRUE)), time(), $user_agent); + } + // Otherwise, simply confirm we exist by returning the type of storage. + elseif ($op == 'type') { + return 'basic storage'; + } } /**