Nenhuma Descrição

easy-modal-v2.php 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <?php
  2. /**
  3. * Function
  4. *
  5. * @package POPMAKE_EMODAL
  6. * @subpackage Functions/Import
  7. * @copyright Copyright (c) 2019, Code Atlantic LLC
  8. * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
  9. * @since 1.0
  10. */
  11. // Exit if accessed directly
  12. if ( ! defined( 'ABSPATH' ) ) {
  13. exit;
  14. }
  15. /**
  16. * Import
  17. *
  18. * Runs on plugin install by setting up the post types, custom taxonomies,
  19. * flushing rewrite rules also creates the plugin and populates the settings
  20. * fields for those plugin pages. After successful install, the user is
  21. * redirected to the POPMAKE_EMODAL Welcome screen.
  22. *
  23. * @since 1.0
  24. * @global $wpdb
  25. * @global $popmake_options
  26. * @global $wp_version
  27. * @return void
  28. */
  29. function popmake_emodal_v2_import() {
  30. global $wpdb, $popmake_options, $wp_version, $popmake_tools_page;
  31. require_once POPMAKE_DIR . 'includes/importer/easy-modal-v2/functions.php';
  32. if ( ! class_exists( 'EModal_Model' ) ) {
  33. require_once POPMAKE_DIR . '/includes/importer/easy-modal-v2/model.php';
  34. }
  35. if ( ! class_exists( 'EModal_Model_Modal' ) ) {
  36. require_once POPMAKE_DIR . '/includes/importer/easy-modal-v2/model/modal.php';
  37. }
  38. if ( ! class_exists( 'EModal_Model_Theme' ) ) {
  39. require_once POPMAKE_DIR . '/includes/importer/easy-modal-v2/model/theme.php';
  40. }
  41. if ( ! class_exists( 'EModal_Model_Theme_Meta' ) ) {
  42. require_once POPMAKE_DIR . '/includes/importer/easy-modal-v2/model/theme/meta.php';
  43. }
  44. if ( ! class_exists( 'EModal_Model_Modal_Meta' ) ) {
  45. require_once POPMAKE_DIR . '/includes/importer/easy-modal-v2/model/modal/meta.php';
  46. }
  47. $themes = get_all_modal_themes( '1 = 1' );
  48. $theme_id_map = array();
  49. foreach ( $themes as $Theme ) {
  50. $theme = $Theme->as_array();
  51. $meta = $theme['meta'];
  52. $theme_meta = apply_filters( 'popmake_emodal_import_theme_meta', array(
  53. 'popup_theme_defaults_set' => true,
  54. 'popup_theme_overlay_background_color' => $meta['overlay']['background']['color'],
  55. 'popup_theme_overlay_background_opacity' => $meta['overlay']['background']['opacity'],
  56. 'popup_theme_container_padding' => $meta['container']['padding'],
  57. 'popup_theme_container_background_color' => $meta['container']['background']['color'],
  58. 'popup_theme_container_background_opacity' => $meta['container']['background']['opacity'],
  59. 'popup_theme_container_border_radius' => $meta['container']['border']['radius'],
  60. 'popup_theme_container_border_style' => $meta['container']['border']['style'],
  61. 'popup_theme_container_border_color' => $meta['container']['border']['color'],
  62. 'popup_theme_container_border_width' => $meta['container']['border']['width'],
  63. 'popup_theme_container_boxshadow_inset' => $meta['container']['boxshadow']['inset'],
  64. 'popup_theme_container_boxshadow_horizontal' => $meta['container']['boxshadow']['horizontal'],
  65. 'popup_theme_container_boxshadow_vertical' => $meta['container']['boxshadow']['vertical'],
  66. 'popup_theme_container_boxshadow_blur' => $meta['container']['boxshadow']['blur'],
  67. 'popup_theme_container_boxshadow_spread' => $meta['container']['boxshadow']['spread'],
  68. 'popup_theme_container_boxshadow_color' => $meta['container']['boxshadow']['color'],
  69. 'popup_theme_container_boxshadow_opacity' => $meta['container']['boxshadow']['opacity'],
  70. 'popup_theme_title_font_color' => $meta['title']['font']['color'],
  71. 'popup_theme_title_line_height' => $meta['title']['font']['size'],
  72. 'popup_theme_title_font_size' => $meta['title']['font']['size'],
  73. 'popup_theme_title_font_family' => $meta['title']['font']['family'],
  74. 'popup_theme_title_font_weight' => $meta['title']['font']['weight'],
  75. 'popup_theme_title_font_style' => $meta['title']['font']['style'],
  76. 'popup_theme_title_text_align' => $meta['title']['text']['align'],
  77. 'popup_theme_title_textshadow_horizontal' => $meta['title']['textshadow']['horizontal'],
  78. 'popup_theme_title_textshadow_vertical' => $meta['title']['textshadow']['vertical'],
  79. 'popup_theme_title_textshadow_blur' => $meta['title']['textshadow']['blur'],
  80. 'popup_theme_title_textshadow_color' => $meta['title']['textshadow']['color'],
  81. 'popup_theme_title_textshadow_opacity' => $meta['title']['textshadow']['opacity'],
  82. 'popup_theme_content_font_color' => $meta['content']['font']['color'],
  83. 'popup_theme_content_font_family' => $meta['content']['font']['family'],
  84. 'popup_theme_content_font_weight' => $meta['content']['font']['weight'],
  85. 'popup_theme_content_font_style' => $meta['content']['font']['style'],
  86. 'popup_theme_close_text' => $meta['close']['text'],
  87. 'popup_theme_close_padding' => $meta['close']['padding'],
  88. 'popup_theme_close_location' => $meta['close']['location'],
  89. 'popup_theme_close_position_top' => $meta['close']['position']['top'],
  90. 'popup_theme_close_position_left' => $meta['close']['position']['left'],
  91. 'popup_theme_close_position_bottom' => $meta['close']['position']['bottom'],
  92. 'popup_theme_close_position_right' => $meta['close']['position']['right'],
  93. 'popup_theme_close_line_height' => $meta['close']['font']['size'],
  94. 'popup_theme_close_font_color' => $meta['close']['font']['color'],
  95. 'popup_theme_close_font_size' => $meta['close']['font']['size'],
  96. 'popup_theme_close_font_family' => $meta['close']['font']['family'],
  97. 'popup_theme_close_font_weight' => $meta['close']['font']['weight'],
  98. 'popup_theme_close_font_style' => $meta['close']['font']['style'],
  99. 'popup_theme_close_background_color' => $meta['close']['background']['color'],
  100. 'popup_theme_close_background_opacity' => $meta['close']['background']['opacity'],
  101. 'popup_theme_close_border_radius' => $meta['close']['border']['radius'],
  102. 'popup_theme_close_border_style' => $meta['close']['border']['style'],
  103. 'popup_theme_close_border_color' => $meta['close']['border']['color'],
  104. 'popup_theme_close_border_width' => $meta['close']['border']['width'],
  105. 'popup_theme_close_boxshadow_inset' => $meta['close']['boxshadow']['inset'],
  106. 'popup_theme_close_boxshadow_horizontal' => $meta['close']['boxshadow']['horizontal'],
  107. 'popup_theme_close_boxshadow_vertical' => $meta['close']['boxshadow']['vertical'],
  108. 'popup_theme_close_boxshadow_blur' => $meta['close']['boxshadow']['blur'],
  109. 'popup_theme_close_boxshadow_spread' => $meta['close']['boxshadow']['spread'],
  110. 'popup_theme_close_boxshadow_color' => $meta['close']['boxshadow']['color'],
  111. 'popup_theme_close_boxshadow_opacity' => $meta['close']['boxshadow']['opacity'],
  112. 'popup_theme_close_textshadow_horizontal' => $meta['close']['textshadow']['horizontal'],
  113. 'popup_theme_close_textshadow_vertical' => $meta['close']['textshadow']['vertical'],
  114. 'popup_theme_close_textshadow_blur' => $meta['close']['textshadow']['blur'],
  115. 'popup_theme_close_textshadow_color' => $meta['close']['textshadow']['color'],
  116. 'popup_theme_close_textshadow_opacity' => $meta['close']['textshadow']['opacity'],
  117. ), $Theme );
  118. $new_theme_id = wp_insert_post(
  119. array(
  120. 'post_title' => $theme['name'],
  121. 'post_status' => $theme['is_trash'] ? 'trash' : 'publish',
  122. 'post_author' => get_current_user_id(),
  123. 'post_type' => 'popup_theme',
  124. 'comment_status' => 'closed'
  125. )
  126. );
  127. foreach ( $theme_meta as $meta_key => $meta_value ) {
  128. update_post_meta( $new_theme_id, $meta_key, $meta_value );
  129. }
  130. update_post_meta( $new_theme_id, 'popup_theme_old_easy_modal_id', $theme['id'] );
  131. $theme_id_map[ $theme['id'] ] = $new_theme_id;
  132. }
  133. if ( count( $themes ) == 1 ) {
  134. update_post_meta( $new_theme_id, 'popup_theme_defaults_set', true );
  135. update_option( 'popmake_default_theme', $new_theme_id );
  136. }
  137. $modals = get_all_modals( '1 = 1' );
  138. //echo '<pre>'; var_export(popmake_popup_meta_fields()); echo '</pre>';
  139. foreach ( $modals as $Modal ) {
  140. $modal = $Modal->as_array();
  141. $meta = $modal['meta'];
  142. $modal_meta = apply_filters( 'popmake_emodal_import_modal_meta', array(
  143. 'popup_old_easy_modal_id' => $modal['id'],
  144. 'popup_defaults_set' => true,
  145. 'popup_theme' => isset( $theme_id_map[ $theme['id'] ] ) ? $theme_id_map[ $theme['id'] ] : null,
  146. 'popup_title' => $modal['title'],
  147. 'popup_display_scrollable_content' => null,
  148. 'popup_display_overlay_disabled' => $meta['display']['overlay_disabled'],
  149. 'popup_display_size' => $meta['display']['size'],
  150. 'popup_display_responsive_min_width' => '',
  151. 'popup_display_responsive_min_width_unit' => 'px',
  152. 'popup_display_responsive_max_width' => '',
  153. 'popup_display_responsive_max_width_unit' => 'px',
  154. 'popup_display_custom_width' => $meta['display']['custom_width'],
  155. 'popup_display_custom_width_unit' => $meta['display']['custom_width_unit'],
  156. 'popup_display_custom_height' => $meta['display']['custom_height'],
  157. 'popup_display_custom_height_unit' => $meta['display']['custom_height_unit'],
  158. 'popup_display_custom_height_auto' => $meta['display']['custom_height_auto'],
  159. 'popup_display_location' => $meta['display']['location'],
  160. 'popup_display_position_top' => $meta['display']['position']['top'],
  161. 'popup_display_position_left' => $meta['display']['position']['left'],
  162. 'popup_display_position_bottom' => $meta['display']['position']['bottom'],
  163. 'popup_display_position_right' => $meta['display']['position']['right'],
  164. 'popup_display_position_fixed' => $meta['display']['position']['fixed'],
  165. 'popup_display_animation_type' => $meta['display']['animation']['type'],
  166. 'popup_display_animation_speed' => $meta['display']['animation']['speed'],
  167. 'popup_display_animation_origin' => $meta['display']['animation']['origin'],
  168. 'popup_close_overlay_click' => $meta['close']['overlay_click'],
  169. 'popup_close_esc_press' => $meta['close']['esc_press'],
  170. 'popup_close_f4_press' => null,
  171. ), $Modal );
  172. if ( $modal['is_sitewide'] == 1 ) {
  173. $modal_meta['popup_targeting_condition_on_entire_site'] = true;
  174. }
  175. $new_modal_id = wp_insert_post(
  176. array(
  177. 'post_title' => $modal['name'],
  178. 'post_status' => $modal['is_trash'] ? 'trash' : 'publish',
  179. 'post_content' => $modal['content'],
  180. 'post_author' => get_current_user_id(),
  181. 'post_type' => 'popup',
  182. 'comment_status' => 'closed'
  183. )
  184. );
  185. foreach ( $modal_meta as $meta_key => $meta_value ) {
  186. update_post_meta( $new_modal_id, $meta_key, $meta_value );
  187. }
  188. }
  189. }
  190. function popmake_emodal_init() {
  191. if ( pum_get_option( 'enable_easy_modal_compatibility_mode' ) ) {
  192. if ( ! shortcode_exists( 'modal' ) ) {
  193. add_shortcode( 'modal', 'popmake_emodal_shortcode_modal' );
  194. }
  195. add_filter( 'pum_popup_data_attr', 'popmake_emodal_get_the_popup_data_attr', 10, 2 );
  196. add_filter( 'popmake_shortcode_popup_default_atts', 'popmake_emodal_shortcode_popup_default_atts', 10, 2 );
  197. add_filter( 'popmake_shortcode_data_attr', 'popmake_emodal_shortcode_data_attr', 10, 2 );
  198. add_filter( 'pum_popup_is_loadable', 'popmake_emodal_popup_is_loadable', 20, 2 );
  199. }
  200. }
  201. add_action( 'init', 'popmake_emodal_init' );
  202. function popmake_emodal_popup_is_loadable( $return, $popup_id ) {
  203. global $post;
  204. if ( empty( $post ) || ! isset( $post->ID ) ) {
  205. return $return;
  206. }
  207. $easy_modal_id = get_post_meta( $popup_id, 'popup_old_easy_modal_id', true );
  208. $post_modals = get_post_meta( $post->ID, 'easy-modal_post_modals', true );
  209. if ( ! $easy_modal_id || empty( $post_modals ) || ! in_array( $easy_modal_id, $post_modals ) ) {
  210. return $return;
  211. }
  212. return true;
  213. }
  214. function popmake_emodal_get_the_popup_data_attr( $data_attr, $popup_id ) {
  215. $easy_modal_id = get_post_meta( $popup_id, 'popup_old_easy_modal_id', true );
  216. if ( ! $easy_modal_id ) {
  217. return $data_attr;
  218. }
  219. return array_merge( $data_attr, array(
  220. 'old_easy_modal_id' => $easy_modal_id
  221. ) );
  222. }
  223. function popmake_emodal_shortcode_modal( $atts, $content = null ) {
  224. $atts = shortcode_atts(
  225. apply_filters( 'emodal_shortcode_modal_default_atts', array(
  226. 'id' => "",
  227. 'theme_id' => null,
  228. 'title' => null,
  229. 'overlay_disabled' => null,
  230. 'size' => null,
  231. 'width' => null,
  232. 'widthUnit' => null,
  233. 'height' => null,
  234. 'heightUnit' => null,
  235. 'location' => null,
  236. 'positionTop' => null,
  237. 'positionLeft' => null,
  238. 'positionBottom' => null,
  239. 'positionRight' => null,
  240. 'positionFixed' => null,
  241. 'animation' => null,
  242. 'animationSpeed' => null,
  243. 'animationOrigin' => null,
  244. 'overlayClose' => null,
  245. 'escClose' => null,
  246. // Deprecated
  247. 'theme' => null,
  248. 'duration' => null,
  249. 'direction' => null,
  250. 'overlayEscClose' => null,
  251. ) ),
  252. apply_filters( 'emodal_shortcode_modal_atts', $atts )
  253. );
  254. $new_shortcode_atts = array(
  255. 'id' => $atts['id'],
  256. 'emodal_id' => $atts['id'],
  257. 'theme_id' => $atts['theme_id'],
  258. 'title' => $atts['title'],
  259. 'overlay_disabled' => $atts['overlay_disabled'],
  260. 'size' => $atts['size'],
  261. 'width' => $atts['width'],
  262. 'width_unit' => $atts['widthUnit'],
  263. 'height' => $atts['height'],
  264. 'height_unit' => $atts['heightUnit'],
  265. 'location' => $atts['location'],
  266. 'position_top' => $atts['positionTop'],
  267. 'position_left' => $atts['positionLeft'],
  268. 'position_bottom' => $atts['positionBottom'],
  269. 'position_right' => $atts['positionRight'],
  270. 'position_fixed' => $atts['positionFixed'],
  271. 'animation_type' => $atts['animation'],
  272. 'animation_speed' => $atts['animationSpeed'],
  273. 'animation_origin' => $atts['animationOrigin'],
  274. 'overlay_click' => $atts['overlayClose'],
  275. 'esc_press' => $atts['escClose']
  276. );
  277. $shortcode = '[popup ';
  278. foreach ( $new_shortcode_atts as $attr => $val ) {
  279. if ( $val && ! empty( $val ) ) {
  280. $shortcode .= $attr . '="' . $val . '" ';
  281. }
  282. }
  283. $shortcode .= ']' . $content . '[/popup]';
  284. return do_shortcode( $shortcode );
  285. }
  286. function popmake_emodal_shortcode_popup_default_atts( $default_atts = array() ) {
  287. return array_merge( $default_atts, array(
  288. 'emodal_id' => null,
  289. ) );
  290. }
  291. function popmake_emodal_shortcode_data_attr( $data, $attr ) {
  292. if ( ! empty( $attr['emodal_id'] ) ) {
  293. $data['old_easy_modal_id'] = $attr['emodal_id'];
  294. }
  295. return $data;
  296. }