You are here

protected function Exporter::filenameSafe in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/aklump/loft_data_grids/src/AKlump/LoftDataGrids/Exporter.php \AKlump\LoftDataGrids\Exporter::filenameSafe()

Return a string as a safe filename

Parameters

string $string: The candidtate filename.

array $options:

  • array extensions: allowable extensions no periods
  • string ext: default extension if non found; blank for none no period

Return value

string

  • lowercased, with only letters, numbers, dots and hyphens

See also

file_munge_filename().

1 call to Exporter::filenameSafe()
Exporter::setFilename in vendor/aklump/loft_data_grids/src/AKlump/LoftDataGrids/Exporter.php
Getter/Setter for the filename

File

vendor/aklump/loft_data_grids/src/AKlump/LoftDataGrids/Exporter.php, line 96

Class

Exporter
Class Exporter

Namespace

AKlump\LoftDataGrids

Code

protected function filenameSafe($string, $options = array()) {
  $options += array(
    'extensions' => array(
      'txt',
      'md',
    ),
    'ext' => 'txt',
  );
  $string = preg_replace('/[^a-z0-9\\-\\.]/', '-', strtolower($string));
  $string = preg_replace('/-{2,}/', '-', $string);

  // Add an extension if not found
  if ($options['ext'] && !preg_match('/\\.[a-z]{1,5}$/', $string)) {
    $string .= '.' . trim($options['ext'], '.');
  }
  if ($string && function_exists('file_munge_filename')) {
    $string = file_munge_filename($string, implode(' ', $options['extensions']), FALSE);
  }

  //@todo Add in the module that cleans name if it's installed
  return $string;
}