Skip to content
media.variables.inc 5.6 KiB
Newer Older
/**
 * @file
 * Contains the variables used by media and their defaults.
 */

/* ***************************************** */
/* CONSTANTS                                 */
/* ***************************************** */

/**
 * @TODO: iz_cruft?
 * @var unknown_type
 */
define('MEDIA_RESOURCE_URI_DEFAULT', 'public://');
define('MEDIA_TYPES_DEFAULT', '*');

/**
 * Define constants.
 */
define('MEDIA_VARIABLE_NAMESPACE', 'media__');

/**
 * Wrapper for variable_get() that uses the Media variable registry.
 * @param string $name
 *   The variable name to retrieve. Note that it will be namespaced by
 *   pre-pending MEDIA_VARIABLE_NAMESPACE, as to avoid variable collisions with
 *   other modules.
 * @param unknown $default
 *   An optional default variable to return if the variable hasn't been set
 *   yet. Note that within this module, all variables should already be set
 *   in the media_variable_default() function.
 *
 * @return string
 *   Returns the stored variable or its default.
 *
 *  @see media_variable_set()
 *  @see media_variable_del()
 *  @see media_variable_default()
 */
function media_variable_get($name, $default = NULL) {
  // Allow for an override of the default. Useful when a variable is required
  // (like $path), but namespacing still desired.
  if (!isset($default)) {
    $default = media_variable_default($name);
  }
  $variable_name = MEDIA_VARIABLE_NAMESPACE . $name;
  return variable_get($variable_name, $default);
}

/**
 * Wrapper for variable_set() that uses the Media variable registry.
 * @param string $name
 *   The variable name to set. Note that it will be namespaced by
 *   pre-pending MEDIA_VARIABLE_NAMESPACE, as to avoid variable collisions with
 *   other modules.
 * @param unknown $value
 *   The value for which to set the variable.
 * @return unknown
 *   Returns the stored variable after setting.
 *
 * @see media_variable_get()
 * @see media_variable_del()
 * @see media_variable_default()
 */
function media_variable_set($name, $value) {
  $variable_name = MEDIA_VARIABLE_NAMESPACE . $name;
  return variable_set($variable_name, $value);
}

/**
 * Wrapper for variable_del() that uses the Media variable registry.
 * @param string $name
 *   The variable name to delete. Note that it will be namespaced by
 *   pre-pending MEDIA_VARIABLE_NAMESPACE, as to avoid variable collisions with
 *   other modules.
 * @see media_variable_get()
 * @see media_variable_set()
 * @see media_variable_default()
 */
function media_variable_del($name) {
  $variable_name = MEDIA_VARIABLE_NAMESPACE . $name;
  variable_del($variable_name);
}

/**
 * Returns the final machine name of a Media namespaced variable.
 */
function media_variable_name($name) {
  return MEDIA_VARIABLE_NAMESPACE . $name;
}

/**
 * The default variables within the Media namespace.
 * @param string $name
 *   Optional variable name to retrieve the default. Note that it has not yet
 *   been pre-pended with the MEDIA_VARIABLE_NAMESPACE namespace at this time.
 * @return unknown
 *   The default value of this variable, if it's been set, or NULL, unless
 *   $name is NULL, in which case we return an array of all default values.
 *
 * @see media_variable_get()
 * @see media_variable_set()
 * @see media_variable_del()
 */
function media_variable_default($name = NULL) {
  static $defaults;

  if (!isset($defaults)) {
    $defaults = array(
      'wysiwyg_title' => t('Media browser'),
      'wysiwyg_icon_title' => t('Add media'),
      // @todo: We should do this per type actually. For "other" it should be a
      // link.
      'wysiwyg_default_view_mode' => 'full',
      // Directory to store media uploaded via WYSIWYG.
      'wysiwyg_upload_directory' => '',
      // Types which can be selected when embedding media vs wysiwyg.
      'wysiwyg_allowed_types' => array('audio', 'image', 'video', 'document'),
      // Attributes which can be modified via the wysiwyg and persist.
      'wysiwyg_allowed_attributes' => array('height', 'width', 'hspace', 'vspace', 'border', 'align', 'style', 'class', 'id', 'usemap', 'data-picture-group', 'data-picture-align'),
      // WYSIWYG browser plugins in WYSIWYG config page.
      // Name of the theme to use in the media popup dialog, defaults to
      // admin_theme.
      // @TODO: Make a configuration form with this.
      'file_extensions' => variable_get('file_entity_default_allowed_extensions', 'jpg jpeg gif png txt doc docx xls xlsx pdf ppt pptx pps ppsx odt ods odp') . ' mp3 mov mp4 m4a m4v mpeg avi ogg oga ogv wmv ico',
      'max_filesize' => '',
      'debug' => FALSE,

      'file_list_size' => 10,

      // Used in media.xml.inc: how long to cache retrieved remote data.
      'xml_cache_expire' => 3600,

      'import_batch_size' => 20,
      'fromurl_supported_schemes' => array('http', 'https', 'ftp', 'smb', 'ftps'),
      'icon_base_directory' => drupal_get_path('module', 'media') . '/images/icons',
      'icon_set' => 'default',
      // Whether to show the legacy Link and Original view modes. Set to TRUE
      // in media_update_7203() to not break sites updating from 1.x.
      'show_deprecated_view_modes' => FALSE,

      // Deprecated variables no longer in use, but should still be uninstalled.
      'show_file_type_rebuild_nag' => NULL,
      'field_select_media_text' => NULL,
      'field_remove_media_text' => NULL,
      'browser_library_empty_message' => NULL,
      'browser_pager_limit' => NULL,
      'browser_viewtype_default' => NULL,
    );
  }

  if (!isset($name)) {
    return $defaults;
  }

  if (isset($defaults[$name])) {
    return $defaults[$name];
  }
}