1 system.admin.inc system_transliteration_retroactive()

Form builder function; generates retroactive transliteration confirm form.

See also

system_transliteration_retroactive_submit()

Related topics

File

core/modules/system/system.admin.inc, line 2585
Admin page callbacks for the system module.

Code

function system_transliteration_retroactive() {
  $query = system_transliteration_file_query();
  $count = $query->countQuery()->execute()->fetchColumn();
  if (!$count) {
    if (empty($_POST)) {
      backdrop_set_message(t('Transliteration is not required.'));
    }
    $form['description']['#markup'] = t('There are currently no file names containing non-ASCII characters. Return to the !file_system page.', array('!file_system' => l('File system', 'admin/config/media/file-system')));
    return $form;
  }

  if (!config_get('system.core', 'file_transliterate_uploads')) {
    backdrop_set_message(t('File transliteration is not yet enabled.'), 'warning');
    $form['description']['#markup'] = t('You must enable the "@option" on the !file_system page to use this form.', array('@option' => t('Transliterate file names during upload'), '!file_system' => l('File system', 'admin/config/media/file-system')));
    return $form;
  }

  $form['#redirect'] = 'admin/config/media/file-system/settings';
  $question = t('Are you sure you want to transliterate existing file names?');

  // Generate a sample list.
  $rows = array();
  $header = array(
    t('Original file name'),
    t('Transliterated file name')
  );
  include_once BACKDROP_ROOT . '/core/includes/transliteration.inc';
  foreach ($query->range(0, 10)->execute() as $file) {
    $filename = backdrop_basename($file->uri);
    $rows[] = array(l($filename, file_create_url($file->uri)), transliteration_clean_filename($filename));
  }
  $description = '<p><strong>' . t('The database currently lists @x_filenames containing non-ASCII characters.', array('@x_filenames' => format_plural($count, '1 file name', '@count file names'))) . '</strong><br />';
  $description .= t('This count might be inaccurate, though, since some files may not need to be renamed. For example, off-site files will never be changed.') . '</p>';
  $description .= theme('table', array('header' => $header, 'sticky' => FALSE, 'rows' => $rows));
  if ($count > 10) {
    $description .= '<p>' . t('Note: table shows only the first 10 entries.') . '</p>';
  }
  $description .= '<p>' . t('<strong>WARNING:</strong> if you have manually entered image or file paths in text fields (for example, text areas or WYSIWYG editors), renaming the files will break these references. Since there is currently no automated way to also fix referenced files in textual contents, it is a very good idea to backup the database and %files directory beforehand. Modules accessing files using their internal system ids are not affected.', array('%files' => backdrop_realpath(file_default_scheme() . '://'))) . '</p>';
  $description .= '<p>' . t('This action cannot be undone.') . '</p>';

  return confirm_form($form, $question, 'admin/config/media/file-system/settings', $description, t('Transliterate'));
}