=== added directory 'modules/macro' === added file 'modules/macro/macro.info' --- modules/macro/macro.info 1970-01-01 00:00:00 +0000 +++ modules/macro/macro.info 2006-08-31 23:30:47 +0000 @@ -0,0 +1,3 @@ +; $Id +name = Macro +description = Allows administrators to record and playback form submission. \ No newline at end of file === added file 'modules/macro/macro.module' --- modules/macro/macro.module 1970-01-01 00:00:00 +0000 +++ modules/macro/macro.module 2006-08-31 23:48:22 +0000 @@ -0,0 +1,198 @@ + 'admin/settings/macro', + 'title' => t('macro engine'), + 'description' => t('Configure the Drupal macro engine. Export recorded macros or import previously recorded macros.'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('macro_admin_settings'), + 'access' => user_access('administer macro settings'), + 'type' => MENU_NORMAL_ITEM, + ); + $items[] = array( + 'title' => t('export'), + 'path' => 'admin/settings/macro/export', + 'access' => true, + 'callback' => 'drupal_get_form', + 'callback arguments' => array(t('macro_export_macro')), + 'access' => user_access('macro access'), + 'type' => MENU_LOCAL_TASK, + ); + $items[] = array( + 'title' => t('import'), + 'path' => 'admin/settings/macro/import', + 'access' => true, + 'callback' => 'drupal_get_form', + 'callback arguments' => array(t('macro_import_macro')), + 'access' => user_access('macro access'), + 'type' => MENU_LOCAL_TASK, + ); + $items[] = array('path' => 'admin/settings/macro/settings', + 'title' => t('configure'), + 'description' => t('Configure the Drupal macro engine. Export recorded macros or import previously recorded macros.'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('macro_admin_settings'), + 'access' => user_access('administer macro settings'), + 'type' => MENU_DEFAULT_LOCAL_TASK, + ); + + } + + return $items; +} + + +/** + * Implementation of hook_perm(). + */ +function macro_perm() { + return array('macro access'); +} + +/** + * Implementation of hook_form_alter(). + * Optionally record all form submissions, for later use in building distributions + */ +function macro_form_alter($form_id, &$form) { + if ($form_id != 'macro_import_macro' && variable_get('macro_enabled', TRUE)) { + $form['#submit']['macro_record_macro'] = array($form); + } + if (variable_get('macro_delete', FALSE)) { + variable_set('macro_submissions', array()); + variable_set('macro_delete', FALSE); + } +} + +/** + * A form submission handler, that stores the form submissions into the variables table + */ +function macro_record_macro($form_id, $edit, $form) { + $subs = variable_get('macro_submissions', array()); + $subs[] = array('form_id' => $form_id, 'parameters' => $form['#parameters'], 'values' => $edit); + variable_set('macro_submissions', $subs); +} + + +/** + * A form callback that displays the macro exported. + * + * The output of this callback should be saved to the profiles/$profile/macros.inc file, to be + * automatically played back upon completed install. + * @return a textarea containing the recorded macros + */ +function macro_export_macro() { + $form['code'] = array( + '#type' => 'textarea', + '#title' => 'macros exported', + '#default_value' => macro_get_macro(), + '#rows' => 20, + ); + return $form; + +} + +/** + * The output of this callback should be saved to the profiles/$profile/macros.inc file, to be + * automatically played back upon completed install. + * @return a code representation of the recorded macro. + */ +function macro_get_macro() { + $subs = variable_get('macro_submissions', array()); + foreach ($subs as $key => $form) { + $string .= "\$macro[$key]['form_id'] = " . var_export($form['form_id'], TRUE) . ";\n"; + $string .= "\$macro[$key]['values'] = " . var_export((array) $form['values'], TRUE) . ";\n"; + + // the form parameters are being used here. + array_shift($form['parameters']); + $string .= "\$macro[$key]['parameters'] = " . var_export(serialize($form['parameters']), TRUE) . ";\n\n"; + + } + + return $string; +} + +/** + * A form callback that displays the macro import form. + * + * @return a form for importing a previously recorded macro + */ +function macro_import_macro() { + $form['macro'] = array( + '#type' => 'textarea', + '#title' => 'macro to import', + '#rows' => 20, + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('play macro'), + ); + return $form; +} + +/** + * Implementation of macro_import_macro hook_submit function. + * + * Plays back the submitted macro. + */ +function macro_import_macro_submit($form_id, $form_values) { + include_once './includes/install.inc'; + eval($form_values['macro']); + drupal_execute_macro($macro); +} + + +/** + * Menu callback for the macro settings form. + */ +function macro_admin_settings() { + + $form['settings_general'] = array( + '#type' => 'fieldset', + '#title' => t('Macro settings'), + '#collapsible' => TRUE, + ); + $form['settings_general']['macro_enabled'] = array( + '#type' => 'checkbox', + '#title' => t('Enable macro recording'), + '#default_value' => variable_get('macro_enabled', TRUE), + '#description' => t('Set whether the macro engine will record form submissions.'), + ); + $form['settings_general']['macro_delete'] = array( + '#type' => 'checkbox', + '#title' => t('Delete recorded macro'), + '#default_value' => variable_get('macro_delete', FALSE), + '#description' => t('Set whether to clear previously recorded macro.'), + ); + + return system_settings_form($form); +} === added directory 'profiles/macro' === added file 'profiles/macro/macro.profile' --- profiles/macro/macro.profile 1970-01-01 00:00:00 +0000 +++ profiles/macro/macro.profile 2006-08-31 18:53:14 +0000 @@ -0,0 +1,23 @@ + 'Macro Recorder', + 'description' => 'A standard Drupal install, that records a macro of all the forms submitted.' + ); +} + === modified file 'includes/install.inc' --- includes/install.inc 2006-08-23 08:25:43 +0000 +++ includes/install.inc 2006-08-31 21:51:27 +0000 @@ -317,6 +317,32 @@ function drupal_install_profile($profile if (function_exists($function)) { $function(); } + drupal_install_execute_macro($profile); +} + +/** + * Check for the existance of a $profile.macro file and plays back the defined macro. + */ +function drupal_install_execute_macro($profile) { + $file = 'profiles/'. $profile .'/'. $profile .'.macro'; + if (file_exists($file)) { + include_once $file; + drupal_execute_macro($macro); + } +} + +/** + * Attempts to programmatically submit all the forms that have been specified in the $macros collection. + */ +function drupal_execute_macro($macro) { + foreach ($macro as $key => $data) { + print_r($data); + $args = array( $data['form_id'], $data['values']) + unserialize($data['parameters']); + call_user_func_array('drupal_execute', $args); + if (form_get_errors()) { + drupal_set_message(t("An error has occured with macro #%macro_number , form_id %form_id. Please check the errors displayed for more details.", array('%macro_number' => $key, '%form_id' => $data['form_id']))); + } + } } === modified file 'sites/default/settings.php' --- sites/default/settings.php 2006-08-03 01:12:03 +0000 +++ sites/default/settings.php 2006-08-31 23:41:49 +0000 @@ -84,7 +84,7 @@ * $db_url = 'mysqli://username:password@localhost/databasename'; * $db_url = 'pgsql://username:password@localhost/databasename'; */ -$db_url = 'mysql://username:password@localhost/databasename'; +$db_url = 'mysql://root:root@localhost%3A8889/testmacro'; $db_prefix = ''; /**