You are here

function patterns_io_get_format_from_file in Patterns 7.2

Same name and namespace in other branches
  1. 7 includes/io/import.inc \patterns_io_get_format_from_file()

Extracts and validates the pattern format from a file string

The pattern format can be specified as parameter, and it this case the first parameter will be ignored. The format will be anyway validated.

Parameters

string $file A path to a file:

string $format Optional. Enforces the format type:

Return value

string|bool $format The pattern format, or FALSE, if the format is invalid

4 calls to patterns_io_get_format_from_file()
drush_patterns_export in ./patterns.drush.inc
Export data from the patterns components to file, zip archive, or database
patterns_drush_get_file_format in ./patterns.drush.inc
patterns_export_start_engine in patterns_export/patterns_export.module
Start the exporting process
patterns_io_import_file in includes/io/import.inc

File

includes/io/import.inc, line 79
Importing Patterns from a file or using an URL.

Code

function patterns_io_get_format_from_file($file, $format = PATTERNS_FORMAT_UNKNOWN, $verbose = TRUE) {
  if ($format == PATTERNS_FORMAT_UNKNOWN) {
    $format = pathinfo($file, PATHINFO_EXTENSION);
  }
  if (!patterns_parser_exists($format)) {
    if ($verbose) {
      drupal_set_message(t('Unknown pattern format: %format. Please check available parsers.', array(
        '%format' => $format,
      )), 'error');
    }
    return FALSE;
  }
  return $format;
}