You are here

function media_set_browser_params in D7 Media 7.2

Same name and namespace in other branches
  1. 7.4 media.module \media_set_browser_params()
  2. 7 includes/media.browser.inc \media_set_browser_params()
  3. 7.3 media.module \media_set_browser_params()

Provides a singleton of the params passed to the media browser.

This is useful in situations like form alters because callers can pass id="wysiywg_form" or whatever they want, and a form alter could pick this up. We may want to change the hook_media_browser_plugin_view() implementations to use this function instead of being passed params for consistency.

It also offers a chance for some meddler to meddle with them.

See also

media_browser()

1 call to media_set_browser_params()
media_get_browser_params in ./media.module
For sanity in grammar.

File

./media.module, line 1225
Media API

Code

function media_set_browser_params() {
  $params =& drupal_static(__FUNCTION__, array());
  if (empty($params)) {

    // Build out browser settings. Permissions- and security-related behaviors
    // should not rely on these parameters, since they come from the HTTP query.
    // There are two ways of passing secure data:
    // - Store the options in the 'cache_form' cache bin, using a random key
    //   prefixed with 'media_options:'. Pass the random key in the 'options'
    //   query argument.
    // - Inject the options by altering the browser parameters.
    //   @see hook_media_browser_params_alter()
    $params = drupal_get_query_parameters();

    // Filter out everything except a whitelist of known safe options.
    $safe_options = array(
      'enabledPlugins',
      'fid',
      'id',
      'multiselect',
      'field',
      'options',
      'plugins',
      'render',
      'types',
      'render_multi_edit_form',
    );
    $params = array_intersect_key($params, array_flip($safe_options));

    // If the cache is present, use its values instead of the GET parameters.
    if (!empty($params['options']) && is_string($params['options']) && ($options = cache_get('media_options:' . $params['options'], 'cache_form'))) {
      $params = $options->data;
    }

    // Transform text 'true' and 'false' to actual booleans.
    foreach ($params as $k => $v) {
      if ($v === 'true') {
        $params[$k] = TRUE;
      }
      elseif ($v === 'false') {
        $params[$k] = FALSE;
      }
    }
    media_array_walk_recursive($params);

    // Provide some default parameters.
    $params += array(
      'types' => array(),
      'multiselect' => FALSE,
    );

    // Allow modules to alter the parameters.
    drupal_alter('media_browser_params', $params);
  }
  return $params;
}