You are here

function fillpdf_link_to_stub_context in FillPDF 7

Parse a URI into context.

Parameters

string $uri: The URI to parse.

Return value

array The context.

3 calls to fillpdf_link_to_stub_context()
FillPdfLinkBooleansTestCase::testBooleans in tests/FillPdfLinkBooleansTestCase.test
Tests boolean query parameters.
fillpdf_file_download in ./fillpdf.module
Implements hook_file_download().
fillpdf_parse_uri in ./fillpdf.module
Get the input data and print the PDF.

File

./fillpdf.module, line 350

Code

function fillpdf_link_to_stub_context($uri) {
  $parsed_url = drupal_parse_url($uri);
  $query_string = $parsed_url['query'];
  $context = array(
    'nids' => array(),
    'webforms' => array(),
    'uc_order_ids' => array(),
    'uc_order_product_ids' => array(),
    'entity_ids' => array(),
    'force_download' => FALSE,
    'flatten' => TRUE,
    'sample' => FALSE,
  );

  // Avoid undefined index warnings, but don't clobber existing values.
  $query_string += array(
    'nid' => NULL,
    'nids' => NULL,
    'entity_id' => NULL,
    'entity_ids' => NULL,
    'webform' => NULL,
    'webforms' => NULL,
    'uc_order_id' => NULL,
    'uc_order_ids' => NULL,
    'uc_order_product_id' => NULL,
    'uc_order_product_ids' => NULL,
    'fid' => NULL,
    'sample' => NULL,
    'download' => NULL,
    'flatten' => NULL,
  );
  $context['fid'] = $query_string['fid'];
  if (isset($query_string['download']) && filter_var($query_string['download'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) === TRUE) {
    $context['force_download'] = TRUE;
  }
  if (isset($query_string['flatten']) && $query_string['flatten'] !== '' && filter_var($query_string['flatten'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) === FALSE) {
    $context['flatten'] = FALSE;
  }
  if (isset($query_string['sample']) && filter_var($query_string['sample'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) === TRUE) {
    $context['sample'] = TRUE;
  }
  if ($query_string['nid'] || $query_string['nids']) {
    $context['nids'] = $query_string['nid'] ? array(
      $query_string['nid'],
    ) : $query_string['nids'];
  }
  if ($query_string['webform'] || $query_string['webforms']) {
    $context['webforms'] = $query_string['webform'] ? array(
      $query_string['webform'],
    ) : $query_string['webforms'];
  }
  if ($query_string['uc_order_id'] || $query_string['uc_order_ids']) {
    $context['uc_order_ids'] = $query_string['uc_order_id'] ? array(
      $query_string['uc_order_id'],
    ) : $query_string['uc_order_ids'];
  }
  if ($query_string['uc_order_product_id'] || $query_string['uc_order_product_ids']) {
    $context['uc_order_product_ids'] = $query_string['uc_order_product_id'] ? array(
      $query_string['uc_order_product_id'],
    ) : $query_string['uc_order_product_ids'];
  }

  // 'entities' and 'entity' are deprecated legacy formats from the original
  // patch that added entity support. They're supported to help users, but they
  // are not documented or official.
  if ($query_string['entity_ids'] || $query_string['entity_id'] || isset($query_string['entity']) || isset($query_string['entities'])) {

    // Translate legacy format into modern format. For simplicity, this will
    // overwrite the official parameter if they specify both. Specifying both is
    // not a supported link format anyway. A single entity_id is also more
    // powerful than entity_ids (this is consistent with the behavior of other
    // query string parameters, and specifying both is also not a supported
    // format).
    if (isset($query_string['entities'])) {
      $query_string['entity_ids'] = $query_string['entities'];
      unset($query_string['entities']);
    }
    if (isset($query_string['entity'])) {
      $query_string['entity_id'] = $query_string['entity'];
      unset($query_string['entity']);
    }

    // If entity_type was specified, we assume that entity_id is just an integer
    // and parse it as an entity of that type.
    if (isset($query_string['entity_type'], $query_string['entity_id'])) {
      $query_string['entity_id'] = "{$query_string['entity_type']}:{$query_string['entity_id']}";
      unset($query_string['entity_type']);
    }
    $context['entity_ids'] = isset($query_string['entity_id']) ? array(
      $query_string['entity_id'],
    ) : $query_string['entity_ids'];
  }
  return $context;
}