Index: stringoverrides.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/stringoverrides/Attic/stringoverrides.info,v retrieving revision 1.2 diff -u -r1.2 stringoverrides.info --- stringoverrides.info 21 Nov 2007 09:41:32 -0000 1.2 +++ stringoverrides.info 20 Oct 2009 21:38:15 -0000 @@ -1,4 +1,7 @@ ; $Id: stringoverrides.info,v 1.2 2007/11/21 09:41:32 robloach Exp $ name = String Overrides description = Provides a quick and easy way of replacing text. -core = 6.x +core = 7.x +php = 5.x +files[] = stringoverrides.module +files[] = stringoverrides.admin.inc Index: stringoverrides.admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/stringoverrides/Attic/stringoverrides.admin.inc,v retrieving revision 1.1.2.12 diff -u -r1.1.2.12 stringoverrides.admin.inc --- stringoverrides.admin.inc 8 Mar 2009 10:37:14 -0000 1.1.2.12 +++ stringoverrides.admin.inc 20 Oct 2009 21:38:15 -0000 @@ -9,7 +9,7 @@ /** * Menu callback for the String Overrides module to display its administration */ -function stringoverrides_admin($form_state = NULL, $lang = NULL) { +function stringoverrides_admin($form, &$form_state, $lang = NULL) { // See which language we're modifying if (empty($lang)) { global $language; @@ -50,20 +50,7 @@ $delta++; } - // Add the buttons to the form - $form['more_strings'] = array( - '#type' => 'button', - '#value' => t('Add row'), - '#description' => t("If the amount of boxes above isn't enough, click here to add more choices."), - '#weight' => 2, - '#ahah' => array( - 'path' => 'admin/settings/stringoverrides/js', - 'wrapper' => 'stringoverrides-wrapper', - 'method' => 'replace', - 'effect' => 'fade', - 'progress' => 'none', - ), - ); + // The form action buttons. $form['save'] = array( '#type' => 'submit', '#value' => t('Save configuration'), @@ -177,182 +164,6 @@ } /** - * Menu callback for the String Overrides module to display a new string override - */ -function stringoverrides_js() { - $delta = count($_POST['string']); - - // Build our new form element. - $form_element = stringoverrides_textbox_combo($delta); - drupal_alter('form', $form_element, array(), 'stringoverrides_js'); - - // Build the new form. - $form_state = array('submitted' => FALSE); - $form_build_id = $_POST['form_build_id']; - // Add the new element to the stored form. Without adding the element to the - // form, Drupal is not aware of this new elements existence and will not - // process it. We retreive the cached form, add the element, and resave. - $form = form_get_cache($form_build_id, $form_state); - $form['string'][$delta] = $form_element; - form_set_cache($form_build_id, $form, $form_state); - $form += array( - '#post' => $_POST, - '#programmed' => FALSE, - ); - - // Rebuild the form. - $form = form_builder('stringoverrides_admin', $form, $form_state); - - // Render the new output. - $string_form = $form['string']; - $string_form[$delta]['enabled']['#value'] = TRUE; - $string_form[$delta]['#attributes']['class'] = empty($string_form[$delta]['#attributes']['class']) ? 'ahah-new-content' : $string_form[$delta]['#attributes']['class'] .' ahah-new-content'; - $output = theme('status_messages') . drupal_render($string_form); - - drupal_json(array('status' => TRUE, 'data' => $output)); -} - -/** - * Menu callback for the String Overrides module to display the import administration - */ -function stringoverrides_admin_import() { - $form = array(); - $form['#attributes'] = array('enctype' => "multipart/form-data"); - $languages = module_exists('locale') ? locale_language_list() : array('en' => t('English')); - $form['file'] = array( - '#type' => 'file', - '#title' => t('File'), - '#description' => t('Attach your *.po file here to import the string overrides.'), - ); - $form['lang'] = array( - '#type' => 'select', - '#title' => t('Language'), - '#description' => t('Which language to import the overrides to.'), - '#options' => $languages, - ); - $form['import'] = array( - '#type' => 'submit', - '#value' => t('Import'), - '#weight' => 3, - ); - return $form; -} - -/** - * Triggered when the user imports data - */ -function stringoverrides_admin_import_submit($form, &$form_state) { - // Check if the file uploaded correctly - if ($file = file_save_upload('file')) { - $overrides = array(); - - // Start reading the file - $handle = @fopen($file->filepath, "r"); - if ($handle) { - $currentoverride = NULL; - $currentstring = NULL; - $operation = 'msgstr'; - - // Loop through the whole file - while (!feof($handle)) { - // Retrieve a single line - $buffer = trim(fgets($handle)); - // Skip empty or comment lines - if (empty($buffer) || $buffer[0] == '#') { - continue; - } - // Continued string - if ($buffer[0] == '"') { - // See what we're reading in - $string = trim(substr($buffer, 1, -1)); - if ($operation == 'msgstr' && !empty($string)) { - $currentstring .= $string; - } - else { - $currentoverride .= $string; - } - } - else if (substr($buffer, 0, 6) == 'msgstr') { - // Retrieve the override string - $operation = 'msgstr'; - $currentstring = substr($buffer, 8, -1); - } - else if (substr($buffer, 0, 5) == 'msgid') { // New string - // Save old string - if (!empty($currentoverride)) { - $overrides[$currentoverride] = $currentstring; - $currentoverride = $currentstring = ''; - } - // Read what's next - $operation = 'msgid'; - $currentoverride = substr($buffer, 7, -1); - } - } - - // Save old string - if (!empty($currentstring) && !empty($currentoverride)) { - $overrides[$currentoverride] = $currentstring; - } - - // Clean up and save the imported data - fclose($handle); - file_delete($file->filepath); - variable_set('locale_custom_strings_'. $form_state['values']['lang'], $overrides); - drupal_set_message(t('The overrides have been imported.')); - } - } - else { - form_set_error('file', t('A file to import is required.')); - } -} - -/** - * Ability to export a *.po file. - */ -function stringoverrides_admin_export() { - $form = array(); - $languages = module_exists('locale') ? locale_language_list() : array('en' => t('English')); - $form['lang'] = array( - '#type' => 'select', - '#title' => t('Language'), - '#description' => t('The language you would like to export.'), - '#options' => $languages, - '#required' => TRUE - ); - $form['export'] = array( - '#type' => 'submit', - '#value' => t('Export'), - '#weight' => 3, - ); - $form['#submit'][] = 'stringoverrides_admin_export_submit'; - return $form; -} - -/** - * Submit-handler for stringoverrides_admin_export. - */ -function stringoverrides_admin_export_submit($form, &$form_state) { - drupal_set_header('Content-Type: text/plain'); - drupal_set_header('Content-Disposition: attachment; filename: "stringoverrides.po"'); - $export = stringoverrides_admin_export_text($form_state['values']['lang']); - drupal_set_header('Content-Length: '. strlen($export)); - echo $export; - $form_state['redirect'] = FALSE; -} - -/** - * Returns the exported *.po text from the given language. - */ -function stringoverrides_admin_export_text($lang = 'en') { - $export = "# String Overrides Export\n"; - $overrides = variable_get('locale_custom_strings_'. $lang, array()); - foreach ($overrides as $override => $string) { - $export .= 'msgid "'. $override ."\"\nmsgstr \"$string\"\n"; - } - return $export; -} - -/** * Sorts two words based on their original text. */ function stringoverrides_admin_word_sort($word1, $word2) { Index: stringoverrides.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/stringoverrides/Attic/stringoverrides.module,v retrieving revision 1.5.2.8 diff -u -r1.5.2.8 stringoverrides.module --- stringoverrides.module 18 Feb 2009 19:59:57 -0000 1.5.2.8 +++ stringoverrides.module 20 Oct 2009 21:38:15 -0000 @@ -7,7 +7,7 @@ */ /** - * Implementation of hook_help() + * Implement hook_help(). */ function stringoverrides_help($path, $arg) { $output = ''; @@ -44,18 +44,22 @@ } /** - * Implementation of hook_perm() + * Implement hook_permission(). */ -function stringoverrides_perm() { - return array('administer string overrides'); +function stringoverrides_permission() { + return array( + 'administer string overrides' => array( + 'title' => t('Administer String Overrides'), + 'description' => t('Replace text strings on the site.'), + ), + ); } /** - * Implementation of hook_menu() + * Implement hook_menu(). */ function stringoverrides_menu() { - $items = array(); - $items['admin/settings/stringoverrides'] = array( + $items['admin/config/regional/stringoverrides'] = array( 'title' => 'String overrides', 'description' => 'Provides a quick and easy way of replacing text on the site.', 'page callback' => 'drupal_get_form', @@ -64,29 +68,13 @@ 'type' => MENU_NORMAL_ITEM, 'file' => 'stringoverrides.admin.inc', ); - $items['admin/settings/stringoverrides/import'] = array( - 'title' => 'Import', - 'description' => 'Import a set of overrides from a *.po file.', - 'page arguments' => array('stringoverrides_admin_import'), - 'access arguments' => array('administer string overrides'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 9, - ); - $items['admin/settings/stringoverrides/export'] = array( - 'title' => 'Export', - 'description' => 'Import a set of overrides from a *.po file.', - 'page arguments' => array('stringoverrides_admin_export'), - 'access arguments' => array('administer string overrides'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 10, - ); - + // Add the language tabs if there are other languages if (module_exists('locale')) { global $language; $languages = locale_language_list(); foreach ($languages as $code => $name) { - $items["admin/settings/stringoverrides/$code"] = array( + $items["admin/config/regional/stringoverrides/$code"] = array( 'title' => '@lang', 'title arguments' => array('@lang' => $name), 'page arguments' => array('stringoverrides_admin', $code), @@ -96,7 +84,7 @@ } } else { - $items['admin/settings/stringoverrides/en'] = array( + $items['admin/config/regional/stringoverrides/en'] = array( 'title' => 'Overrides', 'page callback' => 'drupal_get_form', 'page arguments' => array('stringoverrides_admin', 'en'), @@ -105,8 +93,8 @@ 'file' => 'stringoverrides.admin.inc', ); } - - $items['admin/settings/stringoverrides/js'] = array( + + $items['admin/config/regional/stringoverrides/js'] = array( 'title' => 'String Overrides Javascript', 'page callback' => 'stringoverrides_js', 'type' => MENU_CALLBACK, @@ -117,7 +105,7 @@ } /** - * Implementation of hook_theme() + * Implement hook_theme(). */ function stringoverrides_theme() { return array(