media_archive.variables.inc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * @file media_archive/includes/media_archive.variables.inc
  4. * Variable defaults for Media: Archive.
  5. */
  6. /**
  7. * Define our constants.
  8. */
  9. /**
  10. * This is the variable namespace, automatically prepended to module variables.
  11. */
  12. define('MEDIA_ARCHIVE_NAMESPACE', 'media_archive__');
  13. /**
  14. * Wrapper for variable_get() using the Media: Archive variable registry.
  15. *
  16. * @param string $name
  17. * The variable name to retrieve. Note that it will be namespaced by
  18. * pre-pending MEDIA_ARCHIVE_NAMESPACE, as to avoid variable collisions
  19. * with other modules.
  20. * @param unknown $default
  21. * An optional default variable to return if the variable hasn't been set
  22. * yet. Note that within this module, all variables should already be set
  23. * in the media_archive_variable_default() function.
  24. * @return unknown
  25. * Returns the stored variable or its default.
  26. *
  27. * @see media_archive_variable_set()
  28. * @see media_archive_variable_del()
  29. * @see media_archive_variable_default()
  30. */
  31. function media_archive_variable_get($name, $default = NULL) {
  32. // Allow for an override of the default.
  33. // Useful when a variable is required (like $path), but namespacing is still
  34. // desired.
  35. if (!isset($default)) {
  36. $default = media_archive_variable_default($name);
  37. }
  38. // Namespace all variables.
  39. $variable_name = MEDIA_ARCHIVE_NAMESPACE . $name;
  40. return variable_get($variable_name, $default);
  41. }
  42. /**
  43. * Wrapper for variable_set() using the Media: Archive variable registry.
  44. *
  45. * @param string $name
  46. * The variable name to set. Note that it will be namespaced by
  47. * pre-pending MEDIA_ARCHIVE_NAMESPACE, as to avoid variable collisions with
  48. * other modules.
  49. * @param unknown $value
  50. * The value for which to set the variable.
  51. * @return unknown
  52. * Returns the stored variable after setting.
  53. *
  54. * @see media_archive_variable_get()
  55. * @see media_archive_variable_del()
  56. * @see media_archive_variable_default()
  57. */
  58. function media_archive_variable_set($name, $value) {
  59. $variable_name = MEDIA_ARCHIVE_NAMESPACE . $name;
  60. return variable_set($variable_name, $value);
  61. }
  62. /**
  63. * Wrapper for variable_del() using the Media: Archive variable registry.
  64. *
  65. * @param string $name
  66. * The variable name to delete. Note that it will be namespaced by
  67. * pre-pending MEDIA_ARCHIVE_NAMESPACE, as to avoid variable collisions with
  68. * other modules.
  69. *
  70. * @see media_archive_variable_get()
  71. * @see media_archive_variable_set()
  72. * @see media_archive_variable_default()
  73. */
  74. function media_archive_variable_del($name) {
  75. $variable_name = MEDIA_ARCHIVE_NAMESPACE . $name;
  76. variable_del($variable_name);
  77. }
  78. /**
  79. * The default variables within the Media: Archive namespace.
  80. *
  81. * @param string $name
  82. * Optional variable name to retrieve the default. Note that it has not yet
  83. * been pre-pended with the MEDIA_ARCHIVE_NAMESPACE namespace at this time.
  84. * @return unknown
  85. * The default value of this variable, if it's been set, or NULL, unless
  86. * $name is NULL, in which case we return an array of all default values.
  87. *
  88. * @see media_archive_variable_get()
  89. * @see media_archive_variable_set()
  90. * @see media_archive_variable_del()
  91. */
  92. function media_archive_variable_default($name = NULL) {
  93. static $defaults;
  94. if (!isset($defaults)) {
  95. $defaults = array(
  96. 'width' => 560,
  97. 'height' =>340,
  98. 'autoplay' => FALSE,
  99. 'fullscreen' => TRUE,
  100. 'preview_uri' => 'archive://v/-jubiv7QUco',
  101. );
  102. }
  103. if (!isset($name)) {
  104. return $defaults;
  105. }
  106. if (isset($defaults[$name])) {
  107. return $defaults[$name];
  108. }
  109. }
  110. /**
  111. * Return the fully namespace variable name.
  112. *
  113. * @param string $name
  114. * The variable name to retrieve the namespaced name.
  115. * @return string
  116. * The fully namespace variable name, prepended with
  117. * MEDIA_ARCHIVE_NAMESPACE.
  118. */
  119. function media_archive_variable_name($name) {
  120. return MEDIA_ARCHIVE_NAMESPACE . $name;
  121. }