You are here

function patterns_import_url in Patterns 7.2

Same name and namespace in other branches
  1. 5 patterns.module \patterns_import_url()
  2. 6.2 patterns.module \patterns_import_url()
  3. 6 patterns.module \patterns_import_url()
  4. 7 includes/forms/import.inc \patterns_import_url()

Display the import pattern url form

1 string reference to 'patterns_import_url'
patterns_menu in ./patterns.module
Implements hook_menu().

File

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

Code

function patterns_import_url($form, &$form_state) {

  //$form = array();

  //if (!patterns_parser_ready()) {

  //  $form['noparser'] = array(
  //    '#markup' => t('No Patterns parser found. Impossible to continue. Please enable at least one valid Patterns parser first.'),
  //    '#prefix' => '<strong>',
  //    '#suffix' => '</strong></br>',
  //  );
  //  $form['parsers'] = array(
  //    '#markup' => t('Go to the !modules page to enable more Patterns parsers.', array('!modules' => l(t('modules'), 'admin/modules'))),
  //  );
  //  return $form;

  //}
  $form = array();
  if (!patterns_parser_ready()) {
    $messages = t('No available patterns parser was found.</br>');
    $messages .= t(' Go to the !modules page to enable more Patterns parsers.', array(
      '!modules' => l(t('modules'), 'admin/modules'),
    ));
    drupal_set_message($messages, 'warning');
    return $form;
  }
  $text = 'Insert the uri of a remote file to be downloaded and imported in the database.';
  $title = 'Import from URL';
  patterns_forms_add_page_header($form, $title, $text);
  if (!ini_get('allow_url_fopen')) {
    $form['import_url'] = array(
      // The string 'Feature disabled' is checked inside the test directory
      // do not change or change both
      '#prefix' => '<strong>' . t('Feature disabled:') . '</strong>',
      '#markup' => t('directive "allow_url_fopen" must be enabled in your PHP configuration in order to use this feature.'),
    );
    return $form;
  }
  $def_dir = patterns_path_get_files_dir();
  $form['pattern_uri'] = array(
    '#type' => 'textfield',
    '#title' => t('Specify an URI'),
    '#description' => t('Import a pattern from a remote URL. Imported patterns are not executed until you run them manually.'),
    '#size' => 48,
    '#required' => TRUE,
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Pattern Identifier'),
    '#description' => t('The new name of the pattern file. If the extension is missing it will be automatically added.'),
    '#required' => TRUE,
  );
  $form = patterns_forms_get_formats_selector($form, PATTERNS_FORMAT_UNKNOWN, 'If unknown, it will be determined by the extension.');
  $form['destination'] = array(
    '#type' => 'textfield',
    '#title' => t('Destination'),
    '#description' => t('Pattern will be saved in this directory. Must be writable. Default dir: @dir', array(
      '@dir' => $def_dir,
    )),
    '#default_value' => $def_dir,
    '#required' => TRUE,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Import'),
  );

  // Now it has his own
  $form['#validate'][] = 'patterns_import_validate';
  $form['#submit'][] = 'patterns_import_submit';
  return $form;
}