PageRenderTime 23ms CodeModel.GetById 13ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

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