You are here

function mobile_codes_process_url in Mobile Codes 6.2

Same name and namespace in other branches
  1. 7.2 mobile_codes.module \mobile_codes_process_url()

Process Mobile Codes request URL.

Parameters

$data: The data as provided for use in a Mobile Code.

$attributes: An associative array of attributes necessary to create a Mobile Code.

  • #preset: A string containing the name of a Mobile Code Preset.

Return value

The processed Mobile Codes request URL if all required attributes are provided, or FALSE if they aren't.

1 call to mobile_codes_process_url()
theme_mobilecode in ./mobile_codes.module
Theme function for displaying Mobile Codes

File

./mobile_codes.module, line 183
Mobile Codes core functions.

Code

function mobile_codes_process_url($data, $attributes) {
  if (isset($attributes['#preset']) || isset($attributes['#provider'])) {
    ctools_include('export');
    if (isset($attributes['#preset'])) {
      $preset = clone ctools_export_crud_load('mobile_codes_presets', $attributes['#preset']);
      $attributes['#provider'] = $preset->provider;
      $attributes = array_merge($attributes, $preset->defaults);
    }
    $provider = clone ctools_export_crud_load('mobile_codes_providers', $attributes['#provider']);
    foreach (element_children($provider->parameters) as $parameter) {
      if (!isset($attributes[$parameter])) {
        switch ($provider->parameters[$parameter]['type']) {
          case 'data':
            mobile_codes_process_data($data);
            $attributes[$parameter] = urlencode($data);
            break;
          case 'select':
            $provider->parameters[$parameter]['value'] = explode("\n", $provider->parameters[$parameter]['value']);
            $provider->parameters[$parameter]['value'][0] = explode("|", $provider->parameters[$parameter]['value'][0]);
            $attributes[$parameter] = $provider->parameters[$parameter]['value'][0][0];
            break;
          case 'text':
            drupal_set_message(t('Mobile Codes argument %arg missing.', array(
              '%arg' => $parameter,
            )), 'error');
            return '';
        }
      }
      $provider->url = str_replace("[{$parameter}]", $attributes[$parameter], $provider->url);
    }
    return $provider->url;
  }
  return FALSE;
}