You are here

function patterns_io_import_file in Patterns 7.2

Same name and namespace in other branches
  1. 7 includes/io/import.inc \patterns_io_import_file()
3 calls to patterns_io_import_file()
drush_patterns_import_file in ./patterns.drush.inc
Imports the specified patterns file
drush_patterns_run in ./patterns.drush.inc
Imports, enables, and runs the specified pattern file
patterns_io_import_file_remote in includes/io/import.inc

File

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

Code

function patterns_io_import_file($file, $format = PATTERNS_FORMAT_UNKNOWN, $name = NULL, $level = PATTERNS_VALIDATE_ALL) {
  $ready = _patterns_io_import_pre_checkings();
  if ($ready) {
    return FALSE;
  }
  $format = patterns_io_get_format_from_file($file, $format);
  if (!$format) {
    return FALSE;
  }
  if (is_null($name)) {
    $name = patterns_io_get_name_from_file($file);
    if (!$name) {
      return FALSE;
    }
  }
  $content = file_get_contents($file);
  if (!$content) {
    drupal_set_message(t('An error occurred while opening file.'), 'error');
    return FALSE;
  }
  $pattern = patterns_parser_parse($content, $format);
  if (!$pattern) {
    drupal_set_message(t('Patterns syntax seems invalid.'), 'error');
    return FALSE;
  }
  $valid = _patterns_io_import_validate_content($pattern, $level);
  if (!$valid) {
    return FALSE;
  }
  return patterns_io_save_pattern($pattern, $name, $format);
}