audio.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. /**
  3. * @class FLAudioModule
  4. */
  5. class FLAudioModule extends FLBuilderModule {
  6. /**
  7. * @property $data
  8. */
  9. public $data = null;
  10. /**
  11. * @method __construct
  12. */
  13. public function __construct() {
  14. parent::__construct(array(
  15. 'name' => __( 'Audio', 'fl-builder' ),
  16. 'description' => __( 'Render a WordPress audio shortcode.', 'fl-builder' ),
  17. 'category' => __( 'Basic', 'fl-builder' ),
  18. 'partial_refresh' => true,
  19. 'icon' => 'format-audio.svg',
  20. ));
  21. }
  22. /**
  23. * @method get_data
  24. */
  25. public function get_data() {
  26. if ( ! $this->data ) {
  27. // Get audio data if user selected only one audio file
  28. if ( is_array( $this->settings->audios ) && count( $this->settings->audios ) == 1 ) {
  29. $this->data = FLBuilderPhoto::get_attachment_data( $this->settings->audios[0] );
  30. if ( ! $this->data && isset( $this->settings->data ) ) {
  31. $this->data = $this->settings->data;
  32. }
  33. }
  34. }
  35. return $this->data;
  36. }
  37. /**
  38. * @method update
  39. * @param $settings {object}
  40. */
  41. public function update( $settings ) {
  42. // Cache the attachment data.
  43. if ( 'media_library' == $settings->audio_type ) {
  44. // Get audio data if user selected only one audio file
  45. if ( is_array( $settings->audios ) && count( $settings->audios ) == 1 ) {
  46. $audios = FLBuilderPhoto::get_attachment_data( $settings->audios[0] );
  47. if ( $audios ) {
  48. $settings->data = $audios;
  49. }
  50. }
  51. }
  52. return $settings;
  53. }
  54. }
  55. /**
  56. * Register the module and its form settings.
  57. */
  58. FLBuilder::register_module('FLAudioModule', array(
  59. 'general' => array(
  60. 'title' => __( 'General', 'fl-builder' ),
  61. 'sections' => array(
  62. 'general' => array(
  63. 'title' => '',
  64. 'fields' => array(
  65. 'audio_type' => array(
  66. 'type' => 'select',
  67. 'label' => __( 'Audio Type', 'fl-builder' ),
  68. 'default' => 'wordpress',
  69. 'options' => array(
  70. 'media_library' => __( 'Media Library', 'fl-builder' ),
  71. 'link' => __( 'Link', 'fl-builder' ),
  72. ),
  73. 'toggle' => array(
  74. 'link' => array(
  75. 'fields' => array( 'link' ),
  76. ),
  77. 'media_library' => array(
  78. 'fields' => array( 'audios' ),
  79. ),
  80. ),
  81. ),
  82. 'audios' => array(
  83. 'type' => 'multiple-audios',
  84. 'label' => __( 'Audio', 'fl-builder' ),
  85. 'toggle' => array(
  86. 'playlist' => array(
  87. 'fields' => array( 'style', 'tracklist', 'tracknumbers', 'images', 'artists' ),
  88. ),
  89. 'single_audio' => array(
  90. 'fields' => array( 'autoplay', 'loop' ),
  91. ),
  92. ),
  93. ),
  94. 'link' => array(
  95. 'type' => 'text',
  96. 'label' => __( 'Link', 'fl-builder' ),
  97. 'connections' => array( 'url' ),
  98. ),
  99. /**
  100. * Single audio options
  101. */
  102. 'autoplay' => array(
  103. 'type' => 'select',
  104. 'label' => __( 'Auto Play', 'fl-builder' ),
  105. 'default' => '0',
  106. 'options' => array(
  107. '0' => __( 'No', 'fl-builder' ),
  108. '1' => __( 'Yes', 'fl-builder' ),
  109. ),
  110. 'preview' => array(
  111. 'type' => 'none',
  112. ),
  113. ),
  114. 'loop' => array(
  115. 'type' => 'select',
  116. 'label' => __( 'Loop', 'fl-builder' ),
  117. 'default' => '0',
  118. 'options' => array(
  119. '0' => __( 'No', 'fl-builder' ),
  120. '1' => __( 'Yes', 'fl-builder' ),
  121. ),
  122. 'preview' => array(
  123. 'type' => 'none',
  124. ),
  125. ),
  126. /**
  127. * Playlist options - show only if user selected more than one files
  128. */
  129. 'style' => array(
  130. 'type' => 'select',
  131. 'label' => __( 'Style', 'fl-builder' ),
  132. 'default' => 'light',
  133. 'options' => array(
  134. 'light' => __( 'Light', 'fl-builder' ),
  135. 'dark' => __( 'Dark', 'fl-builder' ),
  136. ),
  137. ),
  138. 'tracklist' => array(
  139. 'type' => 'select',
  140. 'label' => __( 'Show Playlist', 'fl-builder' ),
  141. 'default' => '1',
  142. 'options' => array(
  143. '0' => __( 'No', 'fl-builder' ),
  144. '1' => __( 'Yes', 'fl-builder' ),
  145. ),
  146. 'toggle' => array(
  147. '1' => array(
  148. 'fields' => array( 'tracknumbers' ),
  149. ),
  150. ),
  151. ),
  152. 'tracknumbers' => array(
  153. 'type' => 'select',
  154. 'label' => __( 'Show Track Numbers', 'fl-builder' ),
  155. 'default' => '1',
  156. 'options' => array(
  157. '0' => __( 'No', 'fl-builder' ),
  158. '1' => __( 'Yes', 'fl-builder' ),
  159. ),
  160. 'preview' => array(
  161. 'type' => 'none',
  162. ),
  163. ),
  164. 'images' => array(
  165. 'type' => 'select',
  166. 'label' => __( 'Show Thumbnail', 'fl-builder' ),
  167. 'default' => '1',
  168. 'options' => array(
  169. '0' => __( 'No', 'fl-builder' ),
  170. '1' => __( 'Yes', 'fl-builder' ),
  171. ),
  172. ),
  173. 'artists' => array(
  174. 'type' => 'select',
  175. 'label' => __( 'Show Artist Name', 'fl-builder' ),
  176. 'default' => '1',
  177. 'options' => array(
  178. '0' => __( 'No', 'fl-builder' ),
  179. '1' => __( 'Yes', 'fl-builder' ),
  180. ),
  181. ),
  182. ),
  183. ),
  184. ),
  185. ),
  186. ));