PageRenderTime 26ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/builder/module/CountdownTimer.php

https://bitbucket.org/eoscreativeteam/divi
PHP | 249 lines | 231 code | 17 blank | 1 comment | 3 complexity | 623c19cfc963b0b8af850eb945c7f5a8 MD5 | raw file
Possible License(s): AGPL-1.0, BSD-3-Clause
  1. <?php
  2. class ET_Builder_Module_Countdown_Timer extends ET_Builder_Module {
  3. function init() {
  4. $this->name = esc_html__( 'Countdown Timer', 'et_builder' );
  5. $this->plural = esc_html__( 'Countdown Timers', 'et_builder' );
  6. $this->slug = 'et_pb_countdown_timer';
  7. $this->vb_support = 'on';
  8. $this->main_css_element = '%%order_class%%.et_pb_countdown_timer';
  9. $this->settings_modal_toggles = array(
  10. 'general' => array(
  11. 'toggles' => array(
  12. 'main_content' => esc_html__( 'Text', 'et_builder' ),
  13. ),
  14. ),
  15. 'advanced' => array(
  16. 'toggles' => array(
  17. 'text' => esc_html__( 'Text', 'et_builder' ),
  18. ),
  19. ),
  20. );
  21. $this->advanced_fields = array(
  22. 'fonts' => array(
  23. 'header' => array(
  24. 'label' => esc_html__( 'Title', 'et_builder' ),
  25. 'css' => array(
  26. 'main' => "{$this->main_css_element} h4, {$this->main_css_element} h1.title, {$this->main_css_element} h2.title, {$this->main_css_element} h3.title, {$this->main_css_element} h5.title, {$this->main_css_element} h6.title",
  27. 'important' => array( 'size', 'plugin_all' ),
  28. ),
  29. 'header_level' => array(
  30. 'default' => 'h4',
  31. ),
  32. ),
  33. 'numbers' => array(
  34. 'label' => esc_html__( 'Numbers', 'et_builder' ),
  35. 'css' => array(
  36. 'main' => ".et_pb_column {$this->main_css_element} .section p.value, .et_pb_column {$this->main_css_element} .section.sep p",
  37. 'important' => 'all',
  38. ),
  39. 'line_height' => array(
  40. 'range_settings' => array(
  41. 'min' => '1',
  42. 'max' => '100',
  43. 'step' => '1',
  44. ),
  45. ),
  46. ),
  47. 'label' => array(
  48. 'label' => esc_html__( 'Label', 'et_builder' ),
  49. 'css' => array(
  50. 'main' => ".et_pb_column {$this->main_css_element} .section p.label",
  51. 'important' => array(
  52. 'size',
  53. 'line-height',
  54. ),
  55. ),
  56. 'line_height' => array(
  57. 'range_settings' => array(
  58. 'min' => '1',
  59. 'max' => '100',
  60. 'step' => '1',
  61. ),
  62. ),
  63. ),
  64. ),
  65. 'background' => array(
  66. 'has_background_color_toggle' => true,
  67. 'use_background_color' => true,
  68. 'options' => array(
  69. 'background_color' => array(
  70. 'depends_show_if' => 'on',
  71. 'default' => et_builder_accent_color(),
  72. ),
  73. 'use_background_color' => array(
  74. 'default' => 'on',
  75. ),
  76. ),
  77. ),
  78. 'margin_padding' => array(
  79. 'css' => array(
  80. 'important' => 'all',
  81. ),
  82. ),
  83. 'text' => array(
  84. 'use_background_layout' => true,
  85. 'css' => array(
  86. 'main' => '%%order_class%% .et_pb_countdown_timer_container, %%order_class%% .title',
  87. 'text_orientation' => '%%order_class%% .et_pb_countdown_timer_container, %%order_class%% .title',
  88. ),
  89. 'options' => array(
  90. 'text_orientation' => array(
  91. 'default' => 'center',
  92. ),
  93. 'background_layout' => array(
  94. 'default' => 'dark',
  95. 'hover' => 'tabs',
  96. ),
  97. ),
  98. ),
  99. 'button' => false,
  100. );
  101. $this->custom_css_fields = array(
  102. 'container' => array(
  103. 'label' => esc_html__( 'Container', 'et_builder' ),
  104. 'selector' => '.et_pb_countdown_timer_container',
  105. ),
  106. 'title' => array(
  107. 'label' => esc_html__( 'Title', 'et_builder' ),
  108. 'selector' => '.title',
  109. ),
  110. 'timer_section' => array(
  111. 'label' => esc_html__( 'Timer Section', 'et_builder' ),
  112. 'selector' => '.section',
  113. ),
  114. );
  115. $this->help_videos = array(
  116. array(
  117. 'id' => esc_html( 'irIXKlOw6JA' ),
  118. 'name' => esc_html__( 'An introduction to the Countdown Timer module', 'et_builder' ),
  119. ),
  120. );
  121. }
  122. function get_fields() {
  123. $fields = array(
  124. 'title' => array(
  125. 'label' => esc_html__( 'Countdown Timer Title', 'et_builder' ),
  126. 'type' => 'text',
  127. 'option_category' => 'basic_option',
  128. 'description' => esc_html__( 'This is the title displayed for the countdown timer.', 'et_builder' ),
  129. 'toggle_slug' => 'main_content',
  130. 'dynamic_content' => 'text',
  131. ),
  132. 'date_time' => array(
  133. 'label' => esc_html__( 'Countdown To', 'et_builder' ),
  134. 'type' => 'date_picker',
  135. 'option_category' => 'basic_option',
  136. 'description' => et_get_safe_localization( sprintf( __( 'This is the date the countdown timer is counting down to. Your countdown timer is based on your timezone settings in your <a href="%1$s" target="_blank" title="WordPress General Settings">WordPress General Settings</a>', 'et_builder' ), esc_url( admin_url( 'options-general.php' ) ) ) ),
  137. 'toggle_slug' => 'main_content',
  138. ),
  139. );
  140. return $fields;
  141. }
  142. function render( $attrs, $content = null, $render_slug ) {
  143. $title = $this->_esc_attr( 'title' );
  144. $date_time = $this->props['date_time'];
  145. $background_layout = $this->props['background_layout'];
  146. $background_layout_hover = et_pb_hover_options()->get_value( 'background_layout', $this->props, 'light' );
  147. $background_layout_hover_enabled = et_pb_hover_options()->is_enabled( 'background_layout', $this->props );
  148. $use_background_color = $this->props['use_background_color'];
  149. $header_level = $this->props['header_level'];
  150. $end_date = gmdate( 'M d, Y H:i:s', strtotime( $date_time ) );
  151. $gmt_offset = get_option( 'gmt_offset' );
  152. $gmt_divider = '-' === substr( $gmt_offset, 0, 1 ) ? '-' : '+';
  153. $gmt_offset_hour = str_pad( abs( intval( $gmt_offset ) ), 2, "0", STR_PAD_LEFT );
  154. $gmt_offset_minute = str_pad( ( ( abs( $gmt_offset ) * 100 ) % 100 ) * ( 60 / 100 ), 2, "0", STR_PAD_LEFT );
  155. $gmt = "GMT{$gmt_divider}{$gmt_offset_hour}{$gmt_offset_minute}";
  156. if ( '' !== $title ) {
  157. $title = sprintf(
  158. '<%2$s class="title">%s</%2$s>',
  159. et_core_esc_previously( $title ),
  160. et_pb_process_header_level( $header_level, 'h4' )
  161. );
  162. }
  163. $video_background = $this->video_background();
  164. $parallax_image_background = $this->get_parallax_image_background();
  165. $data_background_layout = '';
  166. $data_background_layout_hover = '';
  167. if ( $background_layout_hover_enabled ) {
  168. $data_background_layout = sprintf(
  169. ' data-background-layout="%1$s"',
  170. esc_attr( $background_layout )
  171. );
  172. $data_background_layout_hover = sprintf(
  173. ' data-background-layout-hover="%1$s"',
  174. esc_attr( $background_layout_hover )
  175. );
  176. }
  177. // Module classnames
  178. $this->add_classname( array(
  179. "et_pb_bg_layout_{$background_layout}",
  180. ) );
  181. if ( 'on' !== $use_background_color ) {
  182. $this->add_classname( 'et_pb_no_bg' );
  183. }
  184. $output = sprintf(
  185. '<div%1$s class="%2$s"%3$s data-end-timestamp="%4$s"%16$s%17$s>
  186. %15$s
  187. %14$s
  188. <div class="et_pb_countdown_timer_container clearfix">
  189. %5$s
  190. <div class="days section values" data-short="%13$s" data-full="%6$s">
  191. <p class="value"></p>
  192. <p class="label">%6$s</p>
  193. </div><div class="sep section">
  194. <p>:</p>
  195. </div><div class="hours section values" data-short="%8$s" data-full="%7$s">
  196. <p class="value"></p>
  197. <p class="label">%7$s</p>
  198. </div><div class="sep section">
  199. <p>:</p>
  200. </div><div class="minutes section values" data-short="%10$s" data-full="%9$s">
  201. <p class="value"></p>
  202. <p class="label">%9$s</p>
  203. </div><div class="sep section">
  204. <p>:</p>
  205. </div><div class="seconds section values" data-short="%12$s" data-full="%11$s">
  206. <p class="value"></p>
  207. <p class="label">%11$s</p>
  208. </div>
  209. </div>
  210. </div>',
  211. $this->module_id(),
  212. $this->module_classname( $render_slug ),
  213. '',
  214. esc_attr( strtotime( "{$end_date} {$gmt}" ) ),
  215. et_core_esc_previously( $title ), // #5
  216. esc_html__( 'Day(s)', 'et_builder' ),
  217. esc_html__( 'Hour(s)', 'et_builder' ),
  218. esc_attr__( 'Hrs', 'et_builder' ),
  219. esc_html__( 'Minute(s)', 'et_builder' ),
  220. esc_attr__( 'Min', 'et_builder' ), // #10
  221. esc_html__( 'Second(s)', 'et_builder' ),
  222. esc_attr__( 'Sec', 'et_builder' ),
  223. esc_attr__( 'Day', 'et_builder' ),
  224. $video_background,
  225. $parallax_image_background, // #15
  226. et_core_esc_previously( $data_background_layout ),
  227. et_core_esc_previously( $data_background_layout_hover )
  228. );
  229. return $output;
  230. }
  231. }
  232. new ET_Builder_Module_Countdown_Timer;