You are here

function transliteration_file_query in Transliteration 6.3

Same name and namespace in other branches
  1. 7.3 transliteration.admin.inc \transliteration_file_query()

Build a query that returns all file names from the database containing non-ASCII characters.

Parameters

$count: Set to TRUE to return a count query.

3 calls to transliteration_file_query()
transliteration_install in ./transliteration.install
Implementation of hook_install().
transliteration_retroactive in ./transliteration.admin.inc
Form builder function; generate retroactive transliteration confirm form.
transliteration_retroactive_submit in ./transliteration.admin.inc
Form submit function; retroactively transliterate existing file names.

File

./transliteration.admin.inc, line 112
Retroactive transliteration and admin settings UI.

Code

function transliteration_file_query($count = FALSE) {

  // Regular expressions are not supported by Drupal's database layer and
  // operators differ between manufacturers.
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $operator = 'NOT REGEXP';
      if (variable_get('transliteration_file_lowercase', TRUE)) {
        $operator .= ' BINARY';
      }
      $regex = '/[a-z0-9_.-]+$';
      break;
    case 'pgsql':
      $operator = '!~*';
      $regex = '/[a-z0-9_.-]+$';
      break;
    case 'mssql':
      $operator = 'LIKE';
      $regex = '%[^a-z0-9_.-]%';
      break;
    default:
      return FALSE;
  }
  $fields = $count ? 'COUNT(*)' : '*';
  return "SELECT {$fields} FROM {files} WHERE filepath {$operator} '{$regex}'";
}