/shared/shortcodes/preview.php

https://github.com/deltafactory/landing-pages · PHP · 215 lines · 203 code · 8 blank · 4 comment · 2 complexity · 66e7a6b3dc270c73638faaec7cbba55c MD5 · raw file

  1. <?php
  2. /* Include Wordpress
  3. * --------------------------------------------------------------------------- */
  4. if (defined('ABSPATH')) {
  5. require_once( ABSPATH . 'wp-load.php' );
  6. } else {
  7. $absolute_path = __FILE__;
  8. $path_to_file = explode( 'wp-content', $absolute_path );
  9. $path_to_wp = $path_to_file[0];
  10. require_once( $path_to_wp . '/wp-load.php' );
  11. }
  12. /* Get Shortcodes
  13. * --------------------------------------------------------------------------- */
  14. $broekn = "divider_options=%22%3Ca%20href=%22http://glocal.dev/wp-admin/edit.php?post_type=inbound-forms%22%3ELeads%3C/a%3E%22";
  15. $test = "http://glocal.dev/wp-content/plugins/leads/shared/shortcodes/preview.php?post=1544&sc=[inbound_form%20id=%221544%22%20name=%22New%20Icon%20Form%22%20redirect=%22http://fontawesome.io/%22%20notify=%22ccc%22%20layout=%22vertical%22%20font_size=%2216%22%20%20labels=%22top%22%20icon=%22check-circle-o%22%20submit=%22Submit%22%20width=%22%22]
  16. [inbound_field%20label=%22First%20Name%22%20type=%22divider%22%20description=%22%22%20required=%220%22%20dropdown=%22%22%20radio=%22%22%20%20checkbox=%22%22%20placeholder=%22%22%20html=%22%22%20dynamic=%22%22%20map_to=%22%22%20
  17. divider_options=%22%3Ca%20href=%22%22%3ETest%3C/a%3E%22]
  18. [/inbound_form]";
  19. $html_test = "divider_options=%22&lt;h3&gt;Hi&lt;/h3&gt;%22";
  20. $html_test2 = "divider_options=%22<h3>Hi</h3>%22";
  21. $extra_content = "";
  22. $html_test = preg_replace("/%22/", "'", $html_test);
  23. $test = html_entity_decode( trim( $html_test2 ) );
  24. //echo $test;
  25. $shortcode = html_entity_decode( trim( $_GET['sc'] ) );
  26. // SET CORRECT FILE PATHS FOR SCRIPTS
  27. if ( defined( 'WPL_URL' )) {
  28. $final_path = WPL_URL . "/";
  29. } else if (defined( 'LANDINGPAGES_URLPATH' )){
  30. $final_path = LANDINGPAGES_URLPATH;
  31. } else if (defined( 'WP_CTA_URLPATH' )){
  32. $final_path = WP_CTA_URLPATH;
  33. } else {
  34. $final_path = preg_replace("/\/shared\/shortcodes\//", "/", INBOUND_FORMS);
  35. }
  36. /* HTML MATCHES */
  37. // $test = 'html="&lt;span%20class="test"&gt;tes&lt;/span&gt;"';
  38. // preg_match_all('%\[inbound_form_test\s*(?:(layout)\s*=\s*(.*?))?\](.*?)\[/inbound_form_test\]%', $shortcode, $matches);
  39. // preg_match_all('/'.$varname.'\s*?=\s*?(.*)\s*?(;|$)/msU',$shortcode,$matches);
  40. $horiz = "";
  41. if (preg_match("/horizontal/i", $shortcode)) {
  42. $horiz = "<h2 title='Open preview in new tab' class='open_new_tab'>Horizontal Previews detected.<br>Click to Preview Horizontal shortcode in new tab</h2>";
  43. }
  44. $shortcode = str_replace('\"', '"', $shortcode);
  45. $shortcode = str_replace('&lt;', '<', $shortcode);
  46. $shortcode = str_replace('&gt;', '>', $shortcode);
  47. $shortcode = str_replace('{{child}}', '', $shortcode);
  48. $shortcode = str_replace('label=""', 'label="Default"', $shortcode);
  49. //$field_name_fallback = ($field_name === "") ? 'fallback_name' : '0';
  50. ?>
  51. <!DOCTYPE HTML>
  52. <html lang="en">
  53. <head>
  54. <link rel="stylesheet" type="text/css" href="../shortcodes/css/frontend-render.css" media="all" />
  55. <?php // FIX THESE AND ROLL SHARE TRACKING INTO SHARED
  56. wp_enqueue_script( 'jquery' );
  57. wp_enqueue_script('jquery-cookie', $final_path . 'shared/assets/global/js/jquery.cookie.js', array( 'jquery' ));
  58. wp_register_script('jquery-total-storage',$final_path . 'shared/assets/global/js/jquery.total-storage.min.js', array( 'jquery' ));
  59. wp_enqueue_script( 'store-lead-ajax' , $final_path . 'shared/assets/frontend/js/store.lead.ajax.js', array( 'jquery','jquery-cookie', 'jquery-total-storage'));
  60. wp_enqueue_script( 'funnel-tracking' , $final_path . 'shared/assets/frontend/js/page-tracking.js', array( 'jquery','jquery-cookie','jquery-total-storage'));
  61. wp_localize_script( 'store-lead-ajax' , 'inbound_ajax', array( 'admin_url' => admin_url( 'admin-ajax.php' ), 'post_id' => '100000000', 'post_type' => 'page'));
  62. $time = current_time( 'timestamp', 0 ); // Current wordpress time from settings
  63. $wordpress_date_time = date("Y-m-d G:i:s T", $time);
  64. wp_localize_script( 'funnel-tracking' , 'wplft', array( 'post_id' => '100000000', 'ip_address' => $_SERVER['REMOTE_ADDR'], 'wp_lead_data' => null, 'admin_url' => admin_url( 'admin-ajax.php' ), 'track_time' => $wordpress_date_time));
  65. wp_dequeue_script('form-population');
  66. wp_head();
  67. ?>
  68. <style type="text/css">
  69. html {margin: 0 !important;}
  70. body {padding: 30px 15px;
  71. background:#fff;
  72. padding-top: 5px;}
  73. .bottom-insert-button {
  74. position: fixed;
  75. bottom: 5px;
  76. left: 10%;
  77. text-align: center;
  78. margin: auto;
  79. width: 80%;
  80. display: inline-block;
  81. text-decoration: none;
  82. font-size: 17px;
  83. line-height: 23px;
  84. height: 24px;
  85. margin: 0;
  86. padding: 0 10px 1px;
  87. cursor: pointer;
  88. border-width: 1px;
  89. border-style: solid;
  90. -webkit-border-radius: 3px;
  91. -webkit-appearance: none;
  92. border-radius: 3px;
  93. white-space: nowrap;
  94. -webkit-box-sizing: border-box;
  95. -moz-box-sizing: border-box;
  96. box-sizing: border-box;
  97. background-color: #21759B;
  98. background-image: -webkit-gradient(linear,left top,left bottom,from(#2A95C5),to(#21759B));
  99. background-image: -webkit-linear-gradient(top,#2A95C5,#21759B);
  100. background-image: -moz-linear-gradient(top,#2a95c5,#21759b);
  101. background-image: -ms-linear-gradient(top,#2a95c5,#21759b);
  102. background-image: -o-linear-gradient(top,#2a95c5,#21759b);
  103. background-image: linear-gradient(to bottom,#2A95C5,#21759B);
  104. border-color: #21759B;
  105. border-bottom-color: #1E6A8D;
  106. -webkit-box-shadow: inset 0 1px 0 rgba(120, 200, 230, 0.5);
  107. box-shadow: inset 0 1px 0 rgba(120, 200, 230, 0.5);
  108. color: #FFF;
  109. text-decoration: none;
  110. text-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
  111. }
  112. .disclaimer {
  113. top: 0px;
  114. display: inline-block;
  115. margin-bottom: 20px;
  116. font-size: 11px;
  117. display: none;
  118. }
  119. .open_new_tab {
  120. color: #2465D8;
  121. margin-bottom: 15px;
  122. cursor: pointer;
  123. font-size: 12px;
  124. text-align: center;
  125. margin-top: 0px;
  126. display: none;
  127. }
  128. #close-preview-window {
  129. float: right;
  130. display: none;
  131. }
  132. <?php if (preg_match("/social_share/i", $shortcode)) {
  133. echo "body {
  134. padding: 10px 0px !important;
  135. padding-left: 5px !important;
  136. }";
  137. $extra_content = "<p>This is dummy text and not part of the shortcode. This is dummy text and not part of the shortcode. This is dummy text and not part of the shortcode. This is dummy text and not part of the shortcode. This is dummy text and not part of the shortcode. This is dummy text and not part of the shortcode. This is dummy text and not part of the shortcode. This is dummy text and not part of the shortcode. This is dummy text and not part of the shortcode.</p>";
  138. }?>
  139. </style>
  140. </head>
  141. <body>
  142. <div id="close-preview-window"><a href="javascript:window.close()" class="close_window">close window</a></div>
  143. <?php //echo "Shortcode: <textarea style='width:100%; height:50px;'>". $shortcode ."</textarea><br><br>"; ?>
  144. <?php echo $horiz;
  145. if ($horiz != ""){ ?>
  146. <script type="text/javascript">
  147. function OpenInNewTab(url) {
  148. var win=window.open(url, '_blank');
  149. win.focus();
  150. }
  151. jQuery(document).ready(function($) {
  152. var this_link = window.location.href;
  153. jQuery("body").on('click', '.open_new_tab', function () {
  154. OpenInNewTab(this_link);
  155. });
  156. if ( window.self === window.top ) {
  157. jQuery("#close-preview-window").show();
  158. } else {
  159. jQuery(".open_new_tab").show();
  160. jQuery(".disclaimer").show();
  161. }
  162. });
  163. </script>
  164. <?php }
  165. ?>
  166. <?php
  167. echo do_shortcode( $shortcode ) . $extra_content; ?>
  168. <?php // echo "<br>". $shortcode; ?>
  169. <?php wp_footer();?>
  170. <script>
  171. (function () {
  172. if ( !window.jQuery ) {
  173. var s = document.createElement('script');
  174. s.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js');
  175. document.body.appendChild(s);
  176. //console.log('jquery loaded!');
  177. }
  178. // document.body.innerHTML = document.body.innerHTML.replace( /ERROR: AffiliateID invalid/g, ""); // remove text
  179. })();
  180. jQuery(document).ready(function($) {
  181. jQuery("body").on('click', '.inbound-button.inbound-special-class', function (e) {
  182. e.preventDefault();
  183. var current_link = $(this).attr('href');
  184. var link_text = (current_link != "" ? "Linked to " + current_link : ". Please Enter a URL in the button options");
  185. alert('Sweet button! Link disabled in preview window ' + link_text);
  186. });
  187. });
  188. </script>
  189. </body>
  190. </html>