PageRenderTime 45ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/wordpress/wp-content/plugins/optin-monster-sidebar/themes/action-theme/save.php

https://github.com/kronda/kronda
PHP | 253 lines | 156 code | 51 blank | 46 comment | 52 complexity | 9e4c20117f4f3529617ee7c263d5d105 MD5 | raw file
  1. <?php
  2. /**
  3. * Saves the sidebar optin "Action Theme".
  4. *
  5. * @package OptinMonster
  6. * @since 1.0.0
  7. * @author Thomas Griffin <thomas@retyp.com>
  8. * @copyright Copyright (c) 2013, Thomas Griffin
  9. * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
  10. */
  11. /**
  12. * Save an optin theme.
  13. *
  14. * @package OptinMonster
  15. * @since 1.0.0
  16. */
  17. class optin_monster_save_sidebar_action_theme {
  18. /**
  19. * Prepare any base class properties.
  20. *
  21. * @since 1.0.0
  22. */
  23. public $type, $theme, $optin, $meta, $data;
  24. /**
  25. * Class constructor.
  26. *
  27. * @since 1.0.0
  28. */
  29. public function __construct( $type, $theme, $optin, $data ) {
  30. // Set class properties.
  31. global $optin_monster_account;
  32. $this->type = $type;
  33. $this->theme = $theme;
  34. $this->optin = $optin;
  35. $this->data = $data;
  36. $this->meta = get_post_meta( $this->optin, '_om_meta', true );
  37. $this->account = $optin_monster_account;
  38. }
  39. /**
  40. * Builds out the proper optin theme and styling.
  41. *
  42. * @since 1.0.0
  43. */
  44. public function save_optin() {
  45. // Save the meta for the optin.
  46. $this->meta['type'] = $this->type;
  47. $this->meta['theme'] = $this->theme;
  48. if ( empty( $this->meta['background']['content'] ) )
  49. $this->meta['background']['content'] = isset( $this->data['optin_content_bg'] ) ? esc_attr( $this->data['optin_content_bg'] ) : '';
  50. else
  51. $this->meta['background']['content'] = isset( $this->data['optin_content_bg'] ) ? esc_attr( $this->data['optin_content_bg'] ) : $this->meta['background']['content'];
  52. // Save the optin title.
  53. if ( empty( $this->meta['title']['text'] ) )
  54. $this->meta['title']['text'] = isset( $this->data['optin_title'] ) ? wp_kses_post( $this->data['optin_title'] ) : '';
  55. else
  56. $this->meta['title']['text'] = isset( $this->data['optin_title'] ) ? wp_kses_post( $this->data['optin_title'] ) : $this->meta['title']['text'];
  57. if ( empty( $this->meta['title']['color'] ) )
  58. $this->meta['title']['color'] = isset( $this->data['optin_title_color'] ) ? esc_attr( $this->data['optin_title_color'] ) : '';
  59. else
  60. $this->meta['title']['color'] = isset( $this->data['optin_title_color'] ) ? esc_attr( $this->data['optin_title_color'] ) : $this->meta['title']['color'];
  61. if ( empty( $this->meta['title']['font'] ) ) {
  62. $this->meta['title']['font'] = isset( $this->data['optin_title_font'] ) && 'Select your font...' !== $this->data['optin_title_font'] ? esc_attr( $this->data['optin_title_font'] ) : '';
  63. } else {
  64. $this->meta['title']['font'] = isset( $this->data['optin_title_font'] ) && 'Select your font...' !== $this->data['optin_title_font'] ? esc_attr( $this->data['optin_title_font'] ) : $this->meta['title']['font'];
  65. }
  66. if ( empty( $this->meta['title']['size'] ) )
  67. $this->meta['title']['size'] = isset( $this->data['optin_title_size'] ) ? esc_attr( $this->data['optin_title_size'] ) : '';
  68. else
  69. $this->meta['title']['size'] = isset( $this->data['optin_title_size'] ) ? esc_attr( $this->data['optin_title_size'] ) : $this->meta['title']['size'];
  70. // Save all meta related items.
  71. $this->save_meta( 'title' );
  72. // Save the optin tagline.
  73. if ( empty( $this->meta['tagline']['text'] ) )
  74. $this->meta['tagline']['text'] = isset( $this->data['optin_tagline'] ) ? wp_kses_post( $this->data['optin_tagline'] ) : '';
  75. else
  76. $this->meta['tagline']['text'] = isset( $this->data['optin_tagline'] ) ? wp_kses_post( $this->data['optin_tagline'] ) : $this->meta['tagline']['text'];
  77. if ( empty( $this->meta['tagline']['color'] ) )
  78. $this->meta['tagline']['color'] = isset( $this->data['optin_tagline_color'] ) ? esc_attr( $this->data['optin_tagline_color'] ) : '';
  79. else
  80. $this->meta['tagline']['color'] = isset( $this->data['optin_tagline_color'] ) ? esc_attr( $this->data['optin_tagline_color'] ) : $this->meta['tagline']['color'];
  81. if ( empty( $this->meta['tagline']['font'] ) ) {
  82. $this->meta['tagline']['font'] = isset( $this->data['optin_tagline_font'] ) && 'Select your font...' !== $this->data['optin_tagline_font'] ? esc_attr( $this->data['optin_tagline_font'] ) : '';
  83. } else {
  84. $this->meta['tagline']['font'] = isset( $this->data['optin_tagline_font'] ) && 'Select your font...' !== $this->data['optin_tagline_font'] ? esc_attr( $this->data['optin_tagline_font'] ) : $this->meta['tagline']['font'];
  85. }
  86. if ( empty( $this->meta['tagline']['size'] ) )
  87. $this->meta['tagline']['size'] = isset( $this->data['optin_tagline_size'] ) ? esc_attr( $this->data['optin_tagline_size'] ) : '';
  88. else
  89. $this->meta['tagline']['size'] = isset( $this->data['optin_tagline_size'] ) ? esc_attr( $this->data['optin_tagline_size'] ) : $this->meta['tagline']['size'];
  90. // Save all meta related items.
  91. $this->save_meta( 'tagline' );
  92. // Save the optin name input field.
  93. if ( isset( $this->data['optin_name_show'] ) )
  94. $this->meta['name']['show'] = true;
  95. else
  96. $this->meta['name']['show'] = false;
  97. if ( empty( $this->meta['name']['placeholder'] ) )
  98. $this->meta['name']['placeholder'] = isset( $this->data['optin_name_placeholder'] ) ? strip_tags( esc_attr( $this->data['optin_name_placeholder'] ) ) : '';
  99. else
  100. $this->meta['name']['placeholder'] = isset( $this->data['optin_name_placeholder'] ) ? strip_tags( esc_attr( $this->data['optin_name_placeholder'] ) ) : $this->meta['name']['placeholder'];
  101. if ( empty( $this->meta['name']['color'] ) )
  102. $this->meta['name']['color'] = isset( $this->data['optin_name_color'] ) ? esc_attr( $this->data['optin_name_color'] ) : '';
  103. else
  104. $this->meta['name']['color'] = isset( $this->data['optin_name_color'] ) ? esc_attr( $this->data['optin_name_color'] ) : $this->meta['name']['color'];
  105. if ( empty( $this->meta['name']['font'] ) ) {
  106. $this->meta['name']['font'] = isset( $this->data['optin_name_font'] ) && 'Select your font...' !== $this->data['optin_name_font'] ? esc_attr( $this->data['optin_name_font'] ) : '';
  107. } else {
  108. $this->meta['name']['font'] = isset( $this->data['optin_name_font'] ) && 'Select your font...' !== $this->data['optin_name_font'] ? esc_attr( $this->data['optin_name_font'] ) : $this->meta['name']['font'];
  109. }
  110. if ( empty( $this->meta['name']['size'] ) )
  111. $this->meta['name']['size'] = isset( $this->data['optin_name_size'] ) ? esc_attr( $this->data['optin_name_size'] ) : '';
  112. else
  113. $this->meta['name']['size'] = isset( $this->data['optin_name_size'] ) ? esc_attr( $this->data['optin_name_size'] ) : $this->meta['name']['size'];
  114. // Save all meta related items.
  115. $this->save_meta( 'name' );
  116. // Save the optin email input field.
  117. if ( empty( $this->meta['email']['placeholder'] ) )
  118. $this->meta['email']['placeholder'] = isset( $this->data['optin_email_placeholder'] ) ? strip_tags( esc_attr( $this->data['optin_email_placeholder'] ) ) : '';
  119. else
  120. $this->meta['email']['placeholder'] = isset( $this->data['optin_email_placeholder'] ) ? strip_tags( esc_attr( $this->data['optin_email_placeholder'] ) ) : $this->meta['email']['placeholder'];
  121. if ( empty( $this->meta['email']['color'] ) )
  122. $this->meta['email']['color'] = isset( $this->data['optin_email_color'] ) ? esc_attr( $this->data['optin_email_color'] ) : '';
  123. else
  124. $this->meta['email']['color'] = isset( $this->data['optin_email_color'] ) ? esc_attr( $this->data['optin_email_color'] ) : $this->meta['email']['color'];
  125. if ( empty( $this->meta['email']['font'] ) ) {
  126. $this->meta['email']['font'] = isset( $this->data['optin_email_font'] ) && 'Select your font...' !== $this->data['optin_email_font'] ? esc_attr( $this->data['optin_email_font'] ) : '';
  127. } else {
  128. $this->meta['email']['font'] = isset( $this->data['optin_email_font'] ) && 'Select your font...' !== $this->data['optin_email_font'] ? esc_attr( $this->data['optin_email_font'] ) : $this->meta['email']['font'];
  129. }
  130. if ( empty( $this->meta['email']['size'] ) )
  131. $this->meta['email']['size'] = isset( $this->data['optin_email_size'] ) ? esc_attr( $this->data['optin_email_size'] ) : '';
  132. else
  133. $this->meta['email']['size'] = isset( $this->data['optin_email_size'] ) ? esc_attr( $this->data['optin_email_size'] ) : $this->meta['email']['size'];
  134. // Save all meta related items.
  135. $this->save_meta( 'email' );
  136. // Save the optin submit field.
  137. if ( empty( $this->meta['submit']['placeholder'] ) )
  138. $this->meta['submit']['placeholder'] = isset( $this->data['optin_submit_placeholder'] ) ? strip_tags( esc_attr( $this->data['optin_submit_placeholder'] ) ) : '';
  139. else
  140. $this->meta['submit']['placeholder'] = isset( $this->data['optin_submit_placeholder'] ) ? strip_tags( esc_attr( $this->data['optin_submit_placeholder'] ) ) : $this->meta['submit']['placeholder'];
  141. if ( empty( $this->meta['submit']['field_color'] ) )
  142. $this->meta['submit']['field_color'] = isset( $this->data['optin_submit_field_color'] ) ? esc_attr( $this->data['optin_submit_field_color'] ) : '';
  143. else
  144. $this->meta['submit']['field_color'] = isset( $this->data['optin_submit_field_color'] ) ? esc_attr( $this->data['optin_submit_field_color'] ) : $this->meta['submit']['field_color'];
  145. if ( empty( $this->meta['submit']['bg_color'] ) )
  146. $this->meta['submit']['bg_color'] = isset( $this->data['optin_submit_bg_color'] ) ? esc_attr( $this->data['optin_submit_bg_color'] ) : '';
  147. else
  148. $this->meta['submit']['bg_color'] = isset( $this->data['optin_submit_bg_color'] ) ? esc_attr( $this->data['optin_submit_bg_color'] ) : $this->meta['submit']['bg_color'];
  149. if ( empty( $this->meta['submit']['font'] ) ) {
  150. $this->meta['submit']['font'] = isset( $this->data['optin_submit_font'] ) && 'Select your font...' !== $this->data['optin_submit_font'] ? esc_attr( $this->data['optin_submit_font'] ) : '';
  151. } else {
  152. $this->meta['submit']['font'] = isset( $this->data['optin_submit_font'] ) && 'Select your font...' !== $this->data['optin_submit_font'] ? esc_attr( $this->data['optin_submit_font'] ) : $this->meta['submit']['font'];
  153. }
  154. if ( empty( $this->meta['submit']['size'] ) )
  155. $this->meta['submit']['size'] = isset( $this->data['optin_submit_size'] ) ? esc_attr( $this->data['optin_submit_size'] ) : '';
  156. else
  157. $this->meta['submit']['size'] = isset( $this->data['optin_submit_size'] ) ? esc_attr( $this->data['optin_submit_size'] ) : $this->meta['submit']['size'];
  158. // Save all meta related items.
  159. $this->save_meta( 'submit' );
  160. // Build all of the fonts together.
  161. $this->meta['fonts'] = array( $this->meta['title']['font'], $this->meta['name']['font'], $this->meta['email']['font'], $this->meta['submit']['font'] );
  162. $this->meta['fonts'] = array_filter( $this->meta['fonts'] );
  163. $this->meta['fonts'] = array_unique( $this->meta['fonts'] );
  164. // Remove any non-Google related fonts.
  165. foreach ( $this->meta['fonts'] as $i => $font )
  166. if ( ! in_array( $font, $this->account->get_available_fonts( false ) ) )
  167. unset( $this->meta['fonts'][$i] );
  168. // If there is any custom CSS, save that now.
  169. if ( isset( $this->data['optin_custom_css'] ) )
  170. $this->meta['custom_css'] = trim( esc_html( $this->data['optin_custom_css'] ) );
  171. // Finally update the post meta.
  172. update_post_meta( $this->optin, '_om_meta', $this->meta );
  173. }
  174. public function get_field( $field, $subfield = '' ) {
  175. if ( ! empty( $subfield ) )
  176. return isset( $this->meta[$field][$subfield] ) ? $this->meta[$field][$subfield] : '';
  177. else
  178. return isset( $this->meta[$field] ) ? $this->meta[$field] : '';
  179. }
  180. public function save_meta( $field ) {
  181. if ( 'email' == $field || 'name' == $field || 'submit' == $field )
  182. $meta_field = $field . '_placeholder';
  183. else
  184. $meta_field = $field;
  185. if ( ! isset( $this->meta[$field]['meta']['font_weight'] ) )
  186. $this->meta[$field]['meta']['font_weight'] = isset( $this->data['optin_' . $meta_field . '_font-weight'] ) ? esc_attr( $this->data['optin_' . $meta_field . '_font-weight'] ) : 'normal';
  187. else
  188. $this->meta[$field]['meta']['font_weight'] = isset( $this->data['optin_' . $meta_field . '_font-weight'] ) ? esc_attr( $this->data['optin_' . $meta_field . '_font-weight'] ) : $this->meta[$field]['meta']['font_weight'];
  189. if ( ! isset( $this->meta[$field]['meta']['font_style'] ) )
  190. $this->meta[$field]['meta']['font_style'] = isset( $this->data['optin_' . $meta_field . '_font-style'] ) ? esc_attr( $this->data['optin_' . $meta_field . '_font-style'] ) : 'normal';
  191. else
  192. $this->meta[$field]['meta']['font_style'] = isset( $this->data['optin_' . $meta_field . '_font-style'] ) ? esc_attr( $this->data['optin_' . $meta_field . '_font-style'] ) : $this->meta[$field]['meta']['font_style'];
  193. if ( ! isset( $this->meta[$field]['meta']['text_decoration'] ) )
  194. $this->meta[$field]['meta']['text_decoration'] = isset( $this->data['optin_' . $meta_field . '_text-decoration'] ) ? esc_attr( $this->data['optin_' . $meta_field . '_text-decoration'] ) : 'none';
  195. else
  196. $this->meta[$field]['meta']['text_decoration'] = isset( $this->data['optin_' . $meta_field . '_text-decoration'] ) ? esc_attr( $this->data['optin_' . $meta_field . '_text-decoration'] ) : $this->meta[$field]['meta']['text_decoration'];
  197. if ( ! isset( $this->meta[$field]['meta']['text_align'] ) )
  198. $this->meta[$field]['meta']['text_align'] = isset( $this->data['optin_' . $meta_field . '_text-align'] ) ? esc_attr( $this->data['optin_' . $meta_field . '_text-align'] ) : (( 'submit' == $field ) ? 'center' : 'left' );
  199. else
  200. $this->meta[$field]['meta']['text_align'] = isset( $this->data['optin_' . $meta_field . '_text-align'] ) ? esc_attr( $this->data['optin_' . $meta_field . '_text-align'] ) : $this->meta[$field]['meta']['text_align'];
  201. }
  202. }