You are here

protected function Textimage::getStyledImageClearFileUri in Textimage 7.3

Set URI to a human readable name for the image file, if possible.

If a style-based image is requested, then hopefully a human readable file name can be set.

Return value

bool TRUE if URI is set to human readable file name

1 call to Textimage::getStyledImageClearFileUri()
Textimage::buildUri in classes/Textimage.inc
Set URI to image file.

File

classes/Textimage.inc, line 643
Textimage - Textimage class.

Class

Textimage
@file Textimage - Textimage class.

Code

protected function getStyledImageClearFileUri() {

  // Get a single string out of all the text.
  $file_name = implode('-+-', $this->text);

  // Filenames longer than 200 characters will fail in most filesystems.
  if (drupal_strlen($file_name) > 200) {

    // Need to proceed with hash-based file names.
    _textimage_diag(t("Textimage clear file name too long: @file_name...", array(
      '@file_name' => drupal_substr($file_name, 0, 60),
    )), WATCHDOG_DEBUG, NULL, $this->userMessages);
    return FALSE;
  }

  // Strip control characters (ASCII value < 32). Though these are allowed
  // in some filesystems, not many applications handle them well. Also, strip
  // slashes and backslashes that usually indicate directories.
  $base_name = preg_replace('/[\\x00-\\x1F]|\\/|\\\\/u', '_', $file_name);
  if (drupal_substr(PHP_OS, 0, 3) == 'WIN') {

    // These characters are not allowed in Windows filenames.
    $base_name = str_replace(array(
      ':',
      '*',
      '?',
      '"',
      '<',
      '>',
      '|',
    ), '_', $base_name);
  }
  if ($file_name != $base_name) {

    // Need to proceed with hash-based file names.
    _textimage_diag(t("Textimage clear file name contains unallowed characters: @file_name...", array(
      '@file_name' => drupal_substr($file_name, 0, 60),
    )), WATCHDOG_DEBUG, NULL, $this->userMessages);
    return FALSE;
  }
  $base_name = $file_name . '.' . $this->extension;
  $this->uri = $this->style['textimage']['uri_scheme'] . '://textimage/' . $this->style['name'] . '/' . $base_name;
  return TRUE;
}