You are here

function mobile_codes_process_url in Mobile Codes 7.2

Same name and namespace in other branches
  1. 6.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.

2 calls to mobile_codes_process_url()
mobile_codes_mobile_codes_tokens_alter_alter in includes/mobile_codes.inc
Implements hook_mobile_codes_tokens_alter_alter().
theme_mobilecode in ./mobile_codes.module
Theme function for displaying Mobile Codes

File

./mobile_codes.module, line 193
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'])) {
      if (is_string($attributes['#preset'])) {
        $attributes['#preset'] = ctools_export_crud_load('mobile_codes_presets', $attributes['#preset']);
      }
      if (is_object($attributes['#preset'])) {
        $preset = clone $attributes['#preset'];
        $attributes['#provider'] = $preset->provider;
        $attributes = array_merge($attributes, $preset->defaults);
      }
      else {
        watchdog('mobile_codes', 'Error: Preset !preset doesn\'t exist.', array(
          '!preset' => $attributes['#preset'],
        ));
        return FALSE;
      }
    }
    if (is_string($attributes['#provider'])) {
      $attributes['#provider'] = ctools_export_crud_load('mobile_codes_providers', $attributes['#provider']);
    }
    if (is_object($attributes['#provider'])) {
      $provider = clone $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;
    }
    else {
      watchdog('mobile_codes', 'Error: Provider !provider doesn\'t exist.', array(
        '!provider' => $attributes['#provider'],
      ));
    }
  }
  return FALSE;
}