media_youtube.variables.inc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * @file media_youtube/includes/media_youtube.variables.inc
  4. * Variable defaults for Media: YouTube.
  5. */
  6. /**
  7. * Define our constants.
  8. */
  9. /**
  10. * This is the variable namespace, automatically prepended to module variables.
  11. */
  12. define('MEDIA_YOUTUBE_NAMESPACE', 'media_youtube__');
  13. /**
  14. * Wrapper for variable_get() using the Media: YouTube variable registry.
  15. *
  16. * @param string $name
  17. * The variable name to retrieve. Note that it will be namespaced by
  18. * pre-pending MEDIA_YOUTUBE_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_youtube_variable_default() function.
  24. * @return unknown
  25. * Returns the stored variable or its default.
  26. *
  27. * @see media_youtube_variable_set()
  28. * @see media_youtube_variable_del()
  29. * @see media_youtube_variable_default()
  30. */
  31. function media_youtube_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_youtube_variable_default($name);
  37. }
  38. // Namespace all variables.
  39. $variable_name = MEDIA_YOUTUBE_NAMESPACE . $name;
  40. return variable_get($variable_name, $default);
  41. }
  42. /**
  43. * Wrapper for variable_set() using the Media: YouTube variable registry.
  44. *
  45. * @param string $name
  46. * The variable name to set. Note that it will be namespaced by
  47. * pre-pending MEDIA_YOUTUBE_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_youtube_variable_get()
  55. * @see media_youtube_variable_del()
  56. * @see media_youtube_variable_default()
  57. */
  58. function media_youtube_variable_set($name, $value) {
  59. $variable_name = MEDIA_YOUTUBE_NAMESPACE . $name;
  60. return variable_set($variable_name, $value);
  61. }
  62. /**
  63. * Wrapper for variable_del() using the Media: YouTube variable registry.
  64. *
  65. * @param string $name
  66. * The variable name to delete. Note that it will be namespaced by
  67. * pre-pending MEDIA_YOUTUBE_NAMESPACE, as to avoid variable collisions with
  68. * other modules.
  69. *
  70. * @see media_youtube_variable_get()
  71. * @see media_youtube_variable_set()
  72. * @see media_youtube_variable_default()
  73. */
  74. function media_youtube_variable_del($name) {
  75. $variable_name = MEDIA_YOUTUBE_NAMESPACE . $name;
  76. variable_del($variable_name);
  77. }
  78. /**
  79. * The default variables within the Media: YouTube 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_YOUTUBE_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_youtube_variable_get()
  89. * @see media_youtube_variable_set()
  90. * @see media_youtube_variable_del()
  91. */
  92. function media_youtube_variable_default($name = NULL) {
  93. static $defaults;
  94. if (!isset($defaults)) {
  95. $defaults = array(
  96. 'width' => 560,
  97. 'height' =>340,
  98. 'autoplay' => FALSE,
  99. 'related' => TRUE,
  100. 'hd' => FALSE,
  101. 'showsearch' => TRUE,
  102. 'modestbranding' => FALSE,
  103. 'showinfo'=> TRUE,
  104. 'version' => 3,
  105. 'theme' => 'dark',
  106. 'fullscreen' => TRUE,
  107. 'wmode' => 'transparent',
  108. 'chromeless' => FALSE,
  109. 'preview_uri' => 'youtube://v/-jubiv7QUco',
  110. );
  111. }
  112. if (!isset($name)) {
  113. return $defaults;
  114. }
  115. if (isset($defaults[$name])) {
  116. return $defaults[$name];
  117. }
  118. }
  119. /**
  120. * Return the fully namespace variable name.
  121. *
  122. * @param string $name
  123. * The variable name to retrieve the namespaced name.
  124. * @return string
  125. * The fully namespace variable name, prepended with
  126. * MEDIA_YOUTUBE_NAMESPACE.
  127. */
  128. function media_youtube_variable_name($name) {
  129. return MEDIA_YOUTUBE_NAMESPACE . $name;
  130. }