PageRenderTime 52ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/godaddy-email-marketing-sign-up-forms/includes/render.php

https://bitbucket.org/madiha303/clickitplugins-web
PHP | 393 lines | 226 code | 79 blank | 88 comment | 28 complexity | 1abb554a01f3f48f567d4463cd7183cf MD5 | raw file
  1. <?php
  2. /**
  3. * Render classes
  4. *
  5. * @package GEM
  6. */
  7. /**
  8. * GoDaddy Email Marketing form.
  9. *
  10. * @since 1.0
  11. */
  12. class GEM_Form_Renderer {
  13. /**
  14. * Form instance number.
  15. *
  16. * @var int
  17. */
  18. private static $loops = 0;
  19. /**
  20. * Generates the form.
  21. *
  22. * @param string $form_id Form ID.
  23. * @param bool $echo Wether to echo the form field. Default false.
  24. *
  25. * @return string
  26. */
  27. public function process( $form_id, $echo = false ) {
  28. $form = GEM_Dispatcher::get_fields( (int) $form_id );
  29. $forms = GEM_Dispatcher::get_forms();
  30. $form_ids = array();
  31. if ( ! empty( $forms->signups ) ) {
  32. foreach ( $forms->signups as $signup_form ) {
  33. $form_ids[] = $signup_form->id;
  34. }
  35. }
  36. if ( ! empty( $form->fields ) && in_array( (int) $form_id, $form_ids, true ) ) :
  37. self::$loops++;
  38. ob_start();
  39. ?>
  40. <div class="gem-form-wrapper" id="form-<?php echo absint( $form_id ); ?>">
  41. <form action="<?php echo esc_url( $form->submit ); ?>" method="post" class="gem-form">
  42. <?php do_action( 'gem_before_fields', $form_id, $form->fields ); ?>
  43. <?php foreach ( $form->fields as $count => $field ) : ?>
  44. <p><?php GEM_Form_Fields::dispatch_field( $field, self::$loops ); ?></p>
  45. <?php endforeach; ?>
  46. <?php do_action( 'gem_after_fields', $form_id, $form->fields ); ?>
  47. <p>
  48. <input type="hidden" name="form_id" value="<?php echo absint( $form->id ); ?>" />
  49. <input type="submit" value="<?php echo esc_attr( $form->button_text ); ?>" class="button gem-submit" />
  50. <span class="gem-spinner"></span>
  51. </p>
  52. <?php $show_powered_by = GEM_Settings_Controls::get_option( 'display_powered_by' ) ? true : false;
  53. if ( $show_powered_by ) : ?>
  54. <p>
  55. <a href="https://www.godaddy.com/online-marketing/email-marketing" rel="nofollow" target="_blank"><?php esc_html_e( 'Powered by GoDaddy', 'godaddy-email-marketing' ); ?></a>
  56. </p>
  57. <?php endif; ?>
  58. </form>
  59. </div>
  60. <?php $output = ob_get_clean();
  61. if ( $echo ) {
  62. echo $output; // xss ok
  63. }
  64. return $output;
  65. endif;
  66. }
  67. }
  68. /**
  69. * GoDaddy Email Marketing form fields.
  70. *
  71. * @since 1.0
  72. */
  73. class GEM_Form_Fields {
  74. /**
  75. * Form instance number.
  76. *
  77. * @var int
  78. */
  79. private static $cycle = 0;
  80. /**
  81. * Dispatches the method used to display fields.
  82. *
  83. * @param object $field Form field.
  84. * @param int $cycle Form instance number.
  85. */
  86. public static function dispatch_field( $field, $cycle = 1 ) {
  87. if ( ! is_object( $field ) || ! method_exists( __CLASS__, $field->type ) ) {
  88. return;
  89. }
  90. self::$cycle = absint( $cycle );
  91. if ( ! is_null( $field->field_type ) ) {
  92. call_user_func( array( __CLASS__, $field->field_type ), $field );
  93. } else {
  94. call_user_func( array( __CLASS__, $field->type ), $field );
  95. }
  96. }
  97. /**
  98. * Generates the ID form the form name.
  99. *
  100. * @param string $field_name Form name.
  101. * @return string The form ID.
  102. */
  103. public static function get_form_id( $field_name ) {
  104. // Since HTML ID's can't exist in the same exact spelling more than once... make it special.
  105. return sprintf( 'form_%s_%s', self::$cycle, $field_name );
  106. }
  107. /**
  108. * Displays the string field.
  109. *
  110. * @todo How is this differnt from the GEM_Form_Fields::text_field method?
  111. *
  112. * @param array $args Settings field arguments.
  113. */
  114. public static function string( $args ) {
  115. $field_classes = array( 'gem-field' );
  116. // Is this field required?
  117. if ( $args->required ) {
  118. $field_classes[] = 'gem-required';
  119. }
  120. $field_classes = (array) apply_filters( 'gem_required_field_class', $field_classes, $args );
  121. ?>
  122. <label for="<?php echo esc_attr( self::get_form_id( $args->name ) ); ?>">
  123. <?php echo esc_html( $args->display ); ?>
  124. <?php if ( $args->required && apply_filters( 'gem_required_field_indicator', true, $args ) ) : ?>
  125. <span class="required">*</span>
  126. <?php endif; ?>
  127. </label>
  128. <br/>
  129. <input type="text" name="<?php echo esc_attr( $args->name ); ?>" id="<?php echo esc_attr( self::get_form_id( $args->name ) ); ?>" class="<?php echo esc_attr( join( ' ', $field_classes ) ); ?>" data-label="<?php echo esc_attr( $args->display ); ?>" />
  130. <?php
  131. }
  132. /**
  133. * Displays the checkbox field.
  134. *
  135. * @todo This appears to be deprecated.
  136. *
  137. * @param array $args Settings field arguments.
  138. */
  139. public static function checkbox( $args ) {
  140. $field_classes = array( 'gem-checkbox' );
  141. // Is this field required?
  142. if ( $args->required ) {
  143. $field_classes[] = 'gem-required';
  144. }
  145. $field_classes = (array) apply_filters( 'gem_required_field_class', $field_classes, $args );
  146. ?>
  147. <label for="<?php echo esc_attr( self::get_form_id( $args->name ) . $args->value ); ?>">
  148. <input type="checkbox" value="<?php echo esc_attr( $args->value ); ?>" name="<?php echo esc_attr( $args->name ); ?>" id="<?php echo esc_attr( self::get_form_id( $args->name ) . $args->value ); ?>" class="<?php echo esc_attr( join( ' ', $field_classes ) ); ?>" />
  149. <?php echo esc_html( $args->display ); ?>
  150. <?php if ( $args->required && apply_filters( 'gem_required_field_indicator', true, $args ) ) : ?>
  151. <span class="required">*</span>
  152. <?php endif; ?>
  153. </label>
  154. <br/>
  155. <?php
  156. }
  157. /**
  158. * Displays the checkboxes field.
  159. *
  160. * @param array $args Settings field arguments.
  161. */
  162. public static function checkboxes( $args ) {
  163. ?>
  164. <label for="<?php echo esc_attr( self::get_form_id( $args->name ) ); ?>">
  165. <?php echo esc_html( $args->display ); ?>
  166. <?php if ( $args->required && apply_filters( 'gem_required_field_indicator', true, $args ) ) : ?>
  167. <span class="required">*</span>
  168. <?php endif; ?>
  169. </label>
  170. </br>
  171. <?php
  172. $trim_values = array( '[', ']' );
  173. $options = $args->options;
  174. foreach ( $trim_values as $trim ) {
  175. $options = trim( $options, $trim );
  176. }
  177. $trimmed_options = array();
  178. $options = str_replace( '"', '', $options );
  179. $trimmed_options = explode( ',', $options );
  180. foreach ( $trimmed_options as $key => $value ) : ?>
  181. <input type="checkbox" data-id="<?php echo esc_attr( self::get_form_id( $args->name ) ); ?>" data-name="<?php echo esc_attr( $args->name ); ?>" value="<?php echo esc_attr( $value ); ?>" /> <?php echo esc_attr( $value ); ?><br>
  182. <?php endforeach; ?>
  183. <input type="hidden" id="<?php echo esc_attr( self::get_form_id( $args->name ) ); ?>" name="<?php echo esc_attr( $args->name ); ?>" value="" class="<?php echo $args->required ? 'gem-required' : ''; ?>" data-label="<?php echo esc_attr( $args->display ); ?>" />
  184. <?php
  185. }
  186. /**
  187. * Displays the select dropdown field.
  188. *
  189. * @param array $args Settings field arguments.
  190. */
  191. public static function dropdown( $args ) {
  192. ?>
  193. <label for="<?php echo esc_attr( self::get_form_id( $args->name ) ); ?>">
  194. <?php echo esc_html( $args->display ); ?>
  195. <?php if ( $args->required && apply_filters( 'gem_required_field_indicator', true, $args ) ) : ?>
  196. <span class="required">*</span>
  197. <?php endif; ?>
  198. </label>
  199. </br>
  200. <select id="<?php echo esc_attr( self::get_form_id( $args->name ) ); ?>" name="<?php echo esc_attr( $args->name ); ?>" class="<?php echo $args->required ? 'gem-required' : ''; ?>" data-label="<?php echo esc_attr( $args->display ); ?>">
  201. <?php $trim_values = array( '[', ']' );
  202. $options = $args->options;
  203. foreach ( $trim_values as $trim ) {
  204. $options = trim( $options, $trim );
  205. }
  206. $trimmed_options = array();
  207. $options = str_replace( '"', '', $options );
  208. $trimmed_options = explode( ',', $options );
  209. foreach ( $trimmed_options as $dropdown_options ) : ?>
  210. <option value="<?php echo esc_attr( $dropdown_options ); ?>"> <?php echo esc_html( $dropdown_options ); ?><br>
  211. <?php endforeach; ?>
  212. </select>
  213. <?php
  214. }
  215. /**
  216. * Displays the radio buttons field.
  217. *
  218. * @param array $args Settings field arguments.
  219. */
  220. public static function radio_buttons( $args ) {
  221. ?>
  222. <label for="<?php echo esc_attr( self::get_form_id( $args->name ) ); ?>" class="<?php echo $args->required ? 'gem-required' : ''; ?>" data-label="<?php echo esc_attr( $args->display ); ?>" data-name="<?php echo esc_attr( $args->name ); ?>">
  223. <?php echo esc_html( $args->display ); ?>
  224. <?php if ( $args->required && apply_filters( 'gem_required_field_indicator', true, $args ) ) : ?>
  225. <span class="required">*</span>
  226. <?php endif; ?>
  227. </label>
  228. </br>
  229. <?php $trim_values = array( '[', ']' );
  230. $options = $args->options;
  231. foreach ( $trim_values as $trim ) {
  232. $options = trim( $options, $trim );
  233. }
  234. $trimmed_options = array();
  235. $options = str_replace( '"', '', $options );
  236. $trimmed_options = explode( ',', $options );
  237. foreach ( $trimmed_options as $key => $value ) : ?>
  238. <input type="radio" id="<?php echo esc_attr( self::get_form_id( $args->name ) ); ?>" name="<?php echo esc_attr( $args->name ); ?>" value="<?php echo esc_attr( $value ); ?>" /> <?php echo esc_html( $value ); ?><br>
  239. <?php endforeach;
  240. }
  241. /**
  242. * Displays the date field.
  243. *
  244. * @param array $args Settings field arguments.
  245. */
  246. public static function date( $args ) {
  247. ?>
  248. <label for="<?php echo esc_attr( self::get_form_id( $args->name ) ); ?>">
  249. <?php echo esc_html( $args->display ); ?>
  250. <?php if ( $args->required && apply_filters( 'gem_required_field_indicator', true, $args ) ) : ?>
  251. <span class="required">*</span>
  252. <?php endif; ?>
  253. </label>
  254. </br>
  255. <?php $current_year = date( 'Y' ); ?>
  256. <span class="third">
  257. <select fingerprint="date" data-id="<?php echo esc_attr( self::get_form_id( $args->name ) ); ?>" data-name="<?php echo esc_attr( $args->name ); ?>">
  258. <option value=""> <?php esc_html_e( 'Month', 'godaddy-email-marketing' ) ?> </option>
  259. <option value="<?php esc_attr_e( 'January', 'godaddy-email-marketing' ) ?>"> <?php esc_html_e( 'January', 'godaddy-email-marketing' ) ?> </option>
  260. <option value="<?php esc_attr_e( 'Febuary', 'godaddy-email-marketing' ) ?>"> <?php esc_html_e( 'Febuary', 'godaddy-email-marketing' ) ?> </option>
  261. <option value="<?php esc_attr_e( 'March', 'godaddy-email-marketing' ) ?>"> <?php esc_html_e( 'March', 'godaddy-email-marketing' ) ?> </option>
  262. <option value="<?php esc_attr_e( 'April', 'godaddy-email-marketing' ) ?>"> <?php esc_html_e( 'April', 'godaddy-email-marketing' ) ?> </option>
  263. <option value="<?php esc_attr_e( 'May', 'godaddy-email-marketing' ) ?>"> <?php esc_html_e( 'May', 'godaddy-email-marketing' ) ?> </option>
  264. <option value="<?php esc_attr_e( 'June', 'godaddy-email-marketing' ) ?>"> <?php esc_html_e( 'June', 'godaddy-email-marketing' ) ?> </option>
  265. <option value="<?php esc_attr_e( 'July', 'godaddy-email-marketing' ) ?>"> <?php esc_html_e( 'July', 'godaddy-email-marketing' ) ?> </option>
  266. <option value="<?php esc_attr_e( 'August', 'godaddy-email-marketing' ) ?>"> <?php esc_html_e( 'August', 'godaddy-email-marketing' ) ?> </option>
  267. <option value="<?php esc_attr_e( 'September', 'godaddy-email-marketing' ) ?>"> <?php esc_html_e( 'September', 'godaddy-email-marketing' ) ?> </option>
  268. <option value="<?php esc_attr_e( 'October', 'godaddy-email-marketing' ) ?>"> <?php esc_html_e( 'October', 'godaddy-email-marketing' ) ?> </option>
  269. <option value="<?php esc_attr_e( 'November', 'godaddy-email-marketing' ) ?>"> <?php esc_html_e( 'November', 'godaddy-email-marketing' ) ?> </option>
  270. <option value="<?php esc_attr_e( 'December', 'godaddy-email-marketing' ) ?>"> <?php esc_html_e( 'December', 'godaddy-email-marketing' ) ?> </option>
  271. </select>
  272. </span>
  273. <span class="third">
  274. <select fingerprint="date" data-id="<?php echo esc_attr( self::get_form_id( $args->name ) ); ?>" data-name="<?php echo esc_attr( $args->name ); ?>">
  275. <option value=""> <?php esc_html_e( 'Day', 'godaddy-email-marketing' ) ?> </option>
  276. <?php for ( $i = 1; $i < 32; $i++ ) : ?>
  277. <option value="<?php echo strlen( $i ) < 2 ? '0' . esc_attr( $i ) : esc_attr( $i ); ?>"> <?php echo esc_attr( $i ); ?> </option>
  278. <?php endfor; ?>
  279. </select>
  280. </span>
  281. <span class="third">
  282. <select fingerprint="date" data-id="<?php echo esc_attr( self::get_form_id( $args->name ) ); ?>" data-name="<?php echo esc_attr( $args->name ); ?>">
  283. <option value=""> <?php esc_html_e( 'Year', 'godaddy-email-marketing' ) ?> </option>
  284. <?php for ( $x = $current_year + 5 ; $x > $current_year - 81 ; $x-- ) : ?>
  285. <option value="<?php echo absint( $x ); ?>"> <?php echo absint( $x ); ?> </option>
  286. <?php endfor; ?>
  287. </select>
  288. </span>
  289. <input type="hidden" id="<?php echo esc_attr( self::get_form_id( $args->name ) ); ?>" name="<?php echo esc_attr( $args->name ); ?>" value="" class="<?php echo $args->required ? 'gem-required' : ''; ?>" data-label="<?php echo esc_attr( $args->display ); ?>" />
  290. <?php
  291. }
  292. /**
  293. * Displays the text field.
  294. *
  295. * @param array $args Settings field arguments.
  296. */
  297. public static function text_field( $args ) {
  298. $field_classes = array( 'gem-field' );
  299. // Is this field required?
  300. if ( $args->required ) {
  301. $field_classes[] = 'gem-required';
  302. }
  303. $field_classes = (array) apply_filters( 'gem_required_field_class', $field_classes, $args );
  304. ?>
  305. <label for="<?php echo esc_attr( self::get_form_id( $args->name ) ); ?>">
  306. <?php echo esc_html( $args->display ); ?>
  307. <?php if ( $args->required && apply_filters( 'gem_required_field_indicator', true, $args ) ) : ?>
  308. <span class="required">*</span>
  309. <?php endif; ?>
  310. </label>
  311. <input type="text" name="<?php echo esc_attr( $args->name ); ?>" id="<?php echo esc_attr( self::get_form_id( $args->name ) ); ?>" class="<?php echo esc_attr( join( ' ', $field_classes ) ); ?>" data-label="<?php echo esc_attr( $args->display ); ?>" />
  312. <?php
  313. }
  314. }