PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/youtube-embed/includes/set-option-defaults.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 226 lines | 123 code | 30 blank | 73 comment | 64 complexity | 862aa6239b4048bdcfa03c0a6cb43da2 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. /**
  3. * Set Default Options
  4. *
  5. * Set up default values for the various options
  6. *
  7. * @package YouTubeEmbed
  8. */
  9. /**
  10. * Function to set Shortcode option
  11. *
  12. * Looks up shortcode option - if it's not set, assign a default
  13. *
  14. * @since 2.0
  15. *
  16. * @return string Alternative Shortcode
  17. */
  18. function ye_set_shortcode_option() {
  19. $shortcode = get_option( 'youtube_embed_shortcode' );
  20. // If setting doesn't exist, set defaults
  21. if ( $shortcode == '' ) {
  22. $shortcode[ 1 ] = 'youtube_video';
  23. $shortcode[ 2 ] = '';
  24. update_option( 'youtube_embed_shortcode', $shortcode );
  25. }
  26. return $shortcode;
  27. }
  28. /**
  29. * Function to set URL option
  30. *
  31. * Looks up URL option - if it's not set, override the WP URL embedding
  32. *
  33. * @since 2.0
  34. *
  35. * @return string URL override
  36. */
  37. function ye_set_url_option() {
  38. $url = get_option( 'youtube_embed_url' );
  39. // If setting doesn't exist, set defaults
  40. if ( $url == '' ) { update_option( 'youtube_embed_url', '' ); }
  41. return $url;
  42. }
  43. /**
  44. * Function to set general YouTube options
  45. *
  46. * Looks up options. If none exist, or some are missing, set default values
  47. *
  48. * @since 2.0
  49. *
  50. * @return strings Options array
  51. */
  52. function ye_set_general_defaults() {
  53. $options = get_option( 'youtube_embed_general' );
  54. $changed = false;
  55. $default_error = htmlspecialchars( '<p>The video cannot be shown at the moment. Please try again later.</p>' );
  56. if ( !is_array( $options ) ) {
  57. if ( get_option( 'youtube_embed_editor' ) ) {
  58. // If the old options exist, import them and then delete them
  59. $old_opts = get_option( 'youtube_embed_editor' );
  60. $options[ 'editor_button' ] = $old_opts[ 'youtube' ];
  61. delete_option( 'youtube_embed_editor' );
  62. $changed = true;
  63. } else {
  64. // If array doesn't exist, set defaults
  65. $options = array( 'editor_button' => 1, 'admin_bar' => 1, 'profile_no' => 5, 'list_no' => 5, 'info_cache' => 1, 'embed_cache' => 24, 'transcript_cache' => 24, 'alt_profile' => 0, 'alt_profile2' => 0, 'bracket' => '', 'alt' => 0, 'url_profile' => 0, 'other_profile' => 0, 'comments' => '', 'comments_profile' => 0, 'metadata' => 1, 'feed' => 'b', 'api' => 1, 'error_message' => $default_error, 'thumbnail' => 2 );
  66. $changed = true;
  67. }
  68. }
  69. // Set current version level. Because this can be used to detect version changes (and to what extent), this
  70. // information may be useful in future upgrades
  71. if ( $options[ 'current_version' ] != youtube_embed_version ) {
  72. $options[ 'current_version' ] = youtube_embed_version;
  73. $changed = true;
  74. }
  75. // Because of upgrading, check each option - if not set, apply default
  76. if ( !array_key_exists( 'editor_button', $options ) ) { $options[ 'editor_button' ] = 1; $changed = true; }
  77. if ( !array_key_exists( 'admin_bar', $options ) ) { $options[ 'admin_bar' ] = 1; $changed = true; }
  78. if ( !array_key_exists( 'profile_no', $options ) ) { $options[ 'profile_no' ] = 5; $changed = true; }
  79. if ( !array_key_exists( 'list_no', $options ) ) { $options[ 'list_no' ] = 5; $changed = true; }
  80. if ( !array_key_exists( 'info_cache', $options ) ) { $options[ 'info_cache' ] = 1; $changed = true; }
  81. if ( !array_key_exists( 'embed_cache', $options ) ) { $options[ 'embed_cache' ] = 24; $changed = true; }
  82. if ( !array_key_exists( 'transcript_cache', $options ) ) { $options[ 'transcript_cache' ] = 24; $changed = true; }
  83. if ( !array_key_exists( 'alt_profile', $options ) ) { $options[ 'alt_profile' ] = 0; $changed = true; }
  84. if ( !array_key_exists( 'alt_profile2', $options ) ) { $options[ 'alt_profile2' ] = 0; $changed = true; }
  85. if ( !array_key_exists( 'url_profile', $options ) ) { $options[ 'url_profile' ] = 0; $changed = true; }
  86. if ( !array_key_exists( 'other_profile', $options ) ) { $options[ 'other_profile' ] = 0; $changed = true; }
  87. if ( !array_key_exists( 'comments_profile', $options ) ) { $options[ 'comments_profile' ] = 0; $changed = true; }
  88. if ( !array_key_exists( 'metadata', $options ) ) { $options[ 'metadata' ] = 1; $changed = true; }
  89. if ( !array_key_exists( 'feed', $options ) ) { $options[ 'feed' ] = 'b'; $changed = true; }
  90. if ( !array_key_exists( 'api', $options ) ) { $options[ 'api' ] = 1; $changed = true; }
  91. if ( !array_key_exists( 'error_message', $options ) ) { $options[ 'error_message' ] = $default_error; $changed = true; }
  92. if ( !array_key_exists( 'thumbnail', $options ) ) { $options[ 'thumbnail' ] = 2; $changed = true; }
  93. // Update the options, if changed, and return the result
  94. if ( $changed ) { update_option( 'youtube_embed_general', $options ); }
  95. return $options;
  96. }
  97. /**
  98. * Function to set YouTube profile options
  99. *
  100. * Looks up profile options, based on passed profile numer.
  101. * If none exist, or some are missing, set default values
  102. *
  103. * @since 2.0
  104. *
  105. * @param string $profile Profile number
  106. * @return string Options array
  107. */
  108. function ye_set_profile_defaults( $profile ) {
  109. if ( $profile == 0 ) {
  110. $profname = 'Default';
  111. } else {
  112. $profname = 'Profile ' . $profile;
  113. }
  114. $options = get_option( 'youtube_embed_profile' . $profile );
  115. $changed = false;
  116. $new_user = false;
  117. // Work out default dimensions
  118. if ( isset( $GLOBALS[ 'content_width' ] ) ) {
  119. $width = $GLOBALS[ 'content_width' ];
  120. } else {
  121. $width = 560;
  122. }
  123. $height = round( ( $width / 16 ) * 9, 0 );
  124. if ( !is_array( $options ) ) {
  125. if ( ( $profile == 0 ) && ( get_option( 'youtube_embed' ) ) ) {
  126. // If the old options exist, import them and then delete them
  127. $old_opts = get_option( 'youtube_embed' );
  128. $options = $old_opts;
  129. delete_option( 'youtube_embed' );
  130. $changed = true;
  131. } else {
  132. // If array doesn't exist, set defaults
  133. $options = array( 'width' => $width, 'height' => $height, 'fullscreen' => '', 'template' => '%video%', 'autoplay' => '', 'start' => '0', 'loop' => '', 'cc' => '', 'annotation' => '1', 'related' => '', 'info' => '1', 'link' => '1', 'react' => '1', 'stop' => '0', 'sweetspot' => '1', 'type' => 'v', 'disablekb' => '', 'autohide' => '2', 'controls' => '1', 'playlist' => 'v', 'fallback' => 'v', 'wmode' => 'opaque', 'shadow' => '0', 'audio' => '', 'hd' => '1', 'style' => '', 'color' => 'red', 'theme' => 'dark', 'https' => '0' );
  134. $changed = true;
  135. }
  136. }
  137. // Because of upgrading, check each option - if not set, apply default
  138. if ( !array_key_exists( 'name', $options ) ) { $options[ 'name' ] = $profname; $changed = true; }
  139. if ( !array_key_exists( 'width', $options ) ) {
  140. $option[ 'width' ] = $width;
  141. $options[ 'height' ] = $height;
  142. $changed = true;
  143. }
  144. if ( !array_key_exists( 'height', $options ) ) { $options[ 'height' ] = '340'; $changed = true; }
  145. if ( !array_key_exists( 'annotation', $options ) ) { $options[ 'annotation' ] = '1'; $changed = true; }
  146. if ( !array_key_exists( 'info', $options ) ) { $options[ 'info' ] = '1'; $changed = true; }
  147. if ( !array_key_exists( 'link', $options ) ) { $options[ 'link' ] = '1'; $changed = true; }
  148. if ( !array_key_exists( 'react', $options ) ) { $options[ 'react' ] = '1'; $changed = true; }
  149. if ( !array_key_exists( 'sweetspot', $options ) ) { $options[ 'sweetspot' ] = '1'; $changed = true; }
  150. if ( !array_key_exists( 'type', $options ) ) { $options[ 'type' ] = 'v'; $changed = true; }
  151. if ( !array_key_exists( 'link', $options ) ) { $options[ 'link' ] = '1'; $changed = true; }
  152. if ( !array_key_exists( 'react', $options ) ) { $options[ 'react' ] = '1'; $changed = true; }
  153. if ( !array_key_exists( 'sweetspot', $options ) ) { $options[ 'sweetspot' ] = '1'; $changed = true; }
  154. if ( !array_key_exists( 'autohide', $options ) ) { $options[ 'autohide' ] = '2'; $changed = true; }
  155. if ( !array_key_exists( 'controls', $options ) ) { $options[ 'controls' ] = '1'; $changed = true; }
  156. if ( !array_key_exists( 'playlist', $options ) ) { $options[ 'playlist' ] = 'v'; $changed = true; }
  157. if ( !array_key_exists( 'fallback', $options ) ) { $options[ 'fallback' ] = 'v'; $changed = true; }
  158. if ( !array_key_exists( 'wmode', $options ) ) { $options[ 'wmode' ] = 'opaque'; $changed = true; }
  159. if ( !array_key_exists( 'shadow', $options ) ) { $options[ 'shadow' ] = '0'; $changed = true; }
  160. if ( !array_key_exists( 'template', $options ) ) { $options[ 'template' ] = '%video%'; $changed = true; }
  161. if ( !array_key_exists( 'hd', $options ) ) { $options[ 'hd' ] = '1'; $changed = true; }
  162. if ( !array_key_exists( 'color', $options ) ) { $options[ 'color' ] = 'red'; $changed = true; }
  163. if ( !array_key_exists( 'theme', $options ) ) { $options[ 'theme' ] = 'dark'; $changed = true; }
  164. // Update the options, if changed, and return the result
  165. if ( $changed ) { update_option( 'youtube_embed_profile' . $profile, $options ); }
  166. // Remove added slashes from template XHTML
  167. $options[ 'template' ] = stripslashes( $options[ 'template' ] );
  168. return $options;
  169. }
  170. /**
  171. * Function to set default list options
  172. *
  173. * Looks up list options, based on passed list number.
  174. * If none exist, or some are missing, set default values
  175. *
  176. * @since 2.0
  177. *
  178. * @param string $list List number
  179. * @return string Options array
  180. */
  181. function ye_set_list_defaults( $list ) {
  182. $options = get_option( 'youtube_embed_list' . $list );
  183. $changed = false;
  184. // If array doesn't exist, set defaults
  185. if ( !is_array( $options ) ) {
  186. $options = array( 'name' => 'List ' . $list, 'list' => '' );
  187. $changed = true;
  188. }
  189. // Because of upgrading, check each option - if not set, apply default
  190. if ( !array_key_exists( 'name',$options ) ) { $options[ 'name' ] = 'List ' . $list; $changed = true; }
  191. if ( !array_key_exists( 'list',$options ) ) { $options[ 'list' ] = ''; $changed = true; }
  192. // Update the options, if changed, and return the result
  193. if ( $changed ) { update_option( 'youtube_embed_list' . $list, $options ); }
  194. return $options;
  195. }
  196. ?>