<commit_before><?php
/**
 * @package Frontend
 */
class Wbounce_Frontend {

	function __construct() {
		add_action( 'wp_head', array( $this, 'custom_css') );
		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
		add_action( 'wp_footer', array( $this, 'wp_footer'), 0, WBOUNCE_OPTION_KEY.'-functions' );
		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style') );
		include_once( WBOUNCE_PATH . 'frontend/class-shortcodes.php' );
	}

	/**
	 * Create modal
	 */
	function create_modal_content() { ?>
		<div id="wbounce-modal" class="wbounce-modal underlay" style="display:none">
			<div id="wbounce-modal-sub" class="wbounce-modal-sub modal">
				<?php 
					$general_template = get_option(WBOUNCE_OPTION_KEY.'_template_engine');
					$template = get_post_meta(get_the_ID(), WBOUNCE_OPTION_KEY.'_template', true);
					$override = get_post_meta(get_the_ID(), WBOUNCE_OPTION_KEY.'_override', true);

					if ($template == 'all' && $override != '' && $general_template != 'disabled') {
						echo $override;
					}
					else if (stripslashes(get_option(WBOUNCE_OPTION_KEY.'_content')) != '' && $general_template != 'disabled') {
						echo do_shortcode( stripslashes(get_option(WBOUNCE_OPTION_KEY.'_content')) );
					}
					else {
						$this->create_modal_content_default();
					}
				?>
			</div>
		</div>
	<?php }

	function create_modal_content_default() {
		$content_default = '
			<div class="modal-title">
	          <h3>Do you love this plugin as much as I do?</h3>
	        </div>

	        <div class="modal-body" style="text-align:center">

	        	<p><a href="http://kevinw.de/" target="_blank"><img src="http://www.gravatar.com/avatar/9d876cfd1fed468f71c84d26ca0e9e33?d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536&s=100" style="-webkit-border-radius:50%;-moz-border-radius:50%;border-radius:50%;"></a></p>
				<p><a href="http://kevinw.de/wbounce" target="_blank" style="color:#009000;font-size:20px"><h4>wBounce by <NAME></h4></a></p>
				<p style="font-size:15px">I\'m the developer of this plugin. Feel free to contact and follow me <a href="https://twitter.com/kevinweber" title="<NAME> on Twitter" target="_blank" style="color:#4099FF">on Twitter</a>. And subscribe to my list for WordPress enthusiasts:</p>

				<div id="mc_embed_signup">
				<form action="//kevinw.us2.list-manage.com/subscribe/post?u=f65d804ad274b9c8812b59b4d&amp;id=39ca44d8d3" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
					<div class="mc-field-group updated">
						<input type="email" value="Enter your email address" name="EMAIL" class="required email" id="mce-EMAIL" onclick="this.focus();this.select()" onfocus="if(this.value == \'\') { this.value = this.defaultValue; }" onblur="if(this.value == \'\') { this.value = this.defaultValue; }">
						<input type="hidden" name="GROUPS" id="GROUPS" value="Signup via Plugin (frontend)" />
						<input style="background-color:#009000" type="submit" value="Click to subscribe" name="subscribe" id="mc-embedded-subscribe" class="button">
					</div>
					<div id="mce-responses" class="clear">
						<div class="response" id="mce-error-response" style="display:none"></div>
						<div class="response" id="mce-success-response" style="display:none"></div>
					</div>
				    <div style="position: absolute; left: -5000px;"><input type="text" name="b_f65d804ad274b9c8812b59b4d_39ca44d8d3" tabindex="-1" value=""></div>
				</form>
				</div>

	        </div>
		';
		echo apply_filters( WBOUNCE_OPTION_KEY.'_create_modal_content_default', $content_default );
	}

	/**
	 * Add Code to Footer
	 */
	function wp_footer() {
		if ($this->test_if_status_is_off()) return;

		$this->create_modal_content();
		$this->load_footer_script();
	}


	function load_footer_script() { ?>
		<script>
		(function ( $ ) {
			var fired = false;	// Set "fired" to true as soon as the popup is fired
			var cookieName = 'wBounce';
			var aggressive = '<?php echo $this->test_if_aggressive(); ?>';

			$(document).ready(function() {
				if (typeof ouibounce !== 'undefined' && $.isFunction(ouibounce)) {
			      var _ouibounce = ouibounce(document.getElementById('wbounce-modal'), {
			      	<?php
			      	// Echo options that require a string input
			      	$option_str = array(
			      		'cookieExpire',	// Cookie expiration
			      		'cookieDomain', // Cookie domain
			      	);	
		      		foreach ($option_str as $str) {
		      			$this->echo_option_str( $str );
		      		}

			      	// Echo options that require an integer input
			      	$option_int = array(
			      		'timer', // Timer (Set a min time before wBounce fires)
			      		'sensitivity',	// Sensitivity
			      	);	
		      		foreach ($option_int as $int) {
		      			$this->echo_option_int( $int );
		      		}

		      		// Aggressive Mode
		      		if ( $this->test_if_aggressive() ) {
		      			echo 'aggressive:true,';
			      	}

		      		// Cookie per page (sitewide cookie)
		      		if ( get_option(WBOUNCE_OPTION_KEY.'_sitewide') != '1' ) {
			      		echo 'sitewide:true,';
			      	}

		      		// Hesitation
		      		if ( $this->test_if_given_str('hesitation') ) {
		      			echo 'delay:'.$this->get_option('hesitation').',';
		      		}

			      	// Custom cookie name
			      	echo "cookieName:cookieName,";

		      		// Callback
		      		echo
		      		"callback:function(){".
		      			"fired = true;".	// Set fired to "true" when popup is fired
		      			$this->analytics_action('fired').
		      		"}"	

		      		// Delay/Intelligent timer
		      		// ...
			      	?>
			      });

				};

		      $('body').on('click', function() {
		        $('#wbounce-modal').hide();
		        <?php echo $this->analytics_action('hidden_outside'); ?>
		      });

		      $('#wbounce-modal .modal-close').on('click', function() {
		        $('#wbounce-modal').hide();
		        <?php echo $this->analytics_action('hidden_close'); ?>
		      });

		      $('#wbounce-modal .modal-footer').on('click', function() {
		        $('#wbounce-modal').hide();
		        <?php echo $this->analytics_action('hidden_footer'); ?>
		      });

		      $('#wbounce-modal-sub').on('click', function(e) {
		        e.stopPropagation();
		      });

/*
 * AUTOFIRE JS
 */
var autoFire = null;
<?php
if ( $this->test_if_given_str('autoFire') ) {
	echo 'autoFire = '.$this->get_option('autoFire').';';
}
?>

function isInteger(x) {
	return (typeof x === 'number') && (x % 1 === 0);
}
function handleAutoFire( delay ) {
	if ( (_ouibounce.checkCookieValue( cookieName, 'true') && !aggressive ) || fired === true ) return;
	setTimeout( _ouibounce._fireAndCallback, delay );
}
if ( isInteger(autoFire) && autoFire !== null ) {
  handleAutoFire( autoFire );
}
/*** /AUTOFIRE JS ***/
			});

		})(jQuery);
		</script>
	<?php }

	function get_option( $optionname ) {
		return get_option(WBOUNCE_OPTION_KEY.'_'.$optionname);
	}
	function test_if_given_str( $optionname ) {
		return ( get_option(WBOUNCE_OPTION_KEY.'_'.$optionname) != "" ) ? true : false;
	}
	function echo_option_str( $optionname ) {
  		if ( $this->test_if_given_str(strtolower($optionname)) ) {
  			echo $optionname.':\''.$this->get_option(strtolower($optionname)).'\',';
  		}
	}
	function echo_option_int( $optionname ) {
  		if ( $this->test_if_given_str(strtolower($optionname)) ) {
  			echo $optionname.':'.$this->get_option($optionname).',';<commit_msg>Improved jQuery ready function<commit_after><?php
/**
 * @package Frontend
 */
class Wbounce_Frontend {

	function __construct() {
		add_action( 'wp_head', array( $this, 'custom_css') );
		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
		add_action( 'wp_footer', array( $this, 'wp_footer'), 0, WBOUNCE_OPTION_KEY.'-functions' );
		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style') );
		include_once( WBOUNCE_PATH . 'frontend/class-shortcodes.php' );
	}

	/**
	 * Create modal
	 */
	function create_modal_content() { ?>
		<div id="wbounce-modal" class="wbounce-modal underlay" style="display:none">
			<div id="wbounce-modal-sub" class="wbounce-modal-sub modal">
				<?php 
					$general_template = get_option(WBOUNCE_OPTION_KEY.'_template_engine');
					$template = get_post_meta(get_the_ID(), WBOUNCE_OPTION_KEY.'_template', true);
					$override = get_post_meta(get_the_ID(), WBOUNCE_OPTION_KEY.'_override', true);

					if ($template == 'all' && $override != '' && $general_template != 'disabled') {
						echo $override;
					}
					else if (stripslashes(get_option(WBOUNCE_OPTION_KEY.'_content')) != '' && $general_template != 'disabled') {
						echo do_shortcode( stripslashes(get_option(WBOUNCE_OPTION_KEY.'_content')) );
					}
					else {
						$this->create_modal_content_default();
					}
				?>
			</div>
		</div>
	<?php }

	function create_modal_content_default() {
		$content_default = '
			<div class="modal-title">
	          <h3>Do you love this plugin as much as I do?</h3>
	        </div>

	        <div class="modal-body" style="text-align:center">

	        	<p><a href="http://kevinw.de/" target="_blank"><img src="http://www.gravatar.com/avatar/9d876cfd1fed468f71c84d26ca0e9e33?d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536&s=100" style="-webkit-border-radius:50%;-moz-border-radius:50%;border-radius:50%;"></a></p>
				<p><a href="http://kevinw.de/wbounce" target="_blank" style="color:#009000;font-size:20px"><h4>wBounce by <NAME></h4></a></p>
				<p style="font-size:15px">I\'m the developer of this plugin. Feel free to contact and follow me <a href="https://twitter.com/kevinweber" title="<NAME> on Twitter" target="_blank" style="color:#4099FF">on Twitter</a>. And subscribe to my list for WordPress enthusiasts:</p>

				<div id="mc_embed_signup">
				<form action="//kevinw.us2.list-manage.com/subscribe/post?u=f65d804ad274b9c8812b59b4d&amp;id=39ca44d8d3" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
					<div class="mc-field-group updated">
						<input type="email" value="Enter your email address" name="EMAIL" class="required email" id="mce-EMAIL" onclick="this.focus();this.select()" onfocus="if(this.value == \'\') { this.value = this.defaultValue; }" onblur="if(this.value == \'\') { this.value = this.defaultValue; }">
						<input type="hidden" name="GROUPS" id="GROUPS" value="Signup via Plugin (frontend)" />
						<input style="background-color:#009000" type="submit" value="Click to subscribe" name="subscribe" id="mc-embedded-subscribe" class="button">
					</div>
					<div id="mce-responses" class="clear">
						<div class="response" id="mce-error-response" style="display:none"></div>
						<div class="response" id="mce-success-response" style="display:none"></div>
					</div>
				    <div style="position: absolute; left: -5000px;"><input type="text" name="b_f65d804ad274b9c8812b59b4d_39ca44d8d3" tabindex="-1" value=""></div>
				</form>
				</div>

	        </div>
		';
		echo apply_filters( WBOUNCE_OPTION_KEY.'_create_modal_content_default', $content_default );
	}

	/**
	 * Add Code to Footer
	 */
	function wp_footer() {
		if ($this->test_if_status_is_off()) return;

		$this->create_modal_content();
		$this->load_footer_script();
	}


	function load_footer_script() { ?>
		<script>
		(function ( $ ) {
			$(function() {
				var fired = false;	// Set "fired" to true as soon as the popup is fired
				var cookieName = 'wBounce';
				var aggressive = '<?php echo $this->test_if_aggressive(); ?>';

				if (typeof ouibounce !== 'undefined' && $.isFunction(ouibounce)) {
			      var _ouibounce = ouibounce(document.getElementById('wbounce-modal'), {
			      	<?php
			      	// Echo options that require a string input
			      	$option_str = array(
			      		'cookieExpire',	// Cookie expiration
			      		'cookieDomain', // Cookie domain
			      	);	
		      		foreach ($option_str as $str) {
		      			$this->echo_option_str( $str );
		      		}

			      	// Echo options that require an integer input
			      	$option_int = array(
			      		'timer', // Timer (Set a min time before wBounce fires)
			      		'sensitivity',	// Sensitivity
			      	);	
		      		foreach ($option_int as $int) {
		      			$this->echo_option_int( $int );
		      		}

		      		// Aggressive Mode
		      		if ( $this->test_if_aggressive() ) {
		      			echo 'aggressive:true,';
			      	}

		      		// Cookie per page (sitewide cookie)
		      		if ( get_option(WBOUNCE_OPTION_KEY.'_sitewide') != '1' ) {
			      		echo 'sitewide:true,';
			      	}

		      		// Hesitation
		      		if ( $this->test_if_given_str('hesitation') ) {
		      			echo 'delay:'.$this->get_option('hesitation').',';
		      		}

			      	// Custom cookie name
			      	echo "cookieName:cookieName,";

		      		// Callback
		      		echo
		      		"callback:function(){".
		      			"fired = true;".	// Set fired to "true" when popup is fired
		      			$this->analytics_action('fired').
		      		"}"	

		      		// Delay/Intelligent timer
		      		// ...
			      	?>
			      });

				};

				$('body').on('click', function() {
					$('#wbounce-modal').hide();
					<?php echo $this->analytics_action('hidden_outside'); ?>
				});

				$('#wbounce-modal .modal-close').on('click', function() {
					$('#wbounce-modal').hide();
					<?php echo $this->analytics_action('hidden_close'); ?>
				});

				$('#wbounce-modal .modal-footer').on('click', function() {
					$('#wbounce-modal').hide();
					<?php echo $this->analytics_action('hidden_footer'); ?>
				});

				$('#wbounce-modal-sub').on('click', function(e) {
					e.stopPropagation();
				});

				/*
				 * AUTOFIRE JS
				 */
				var autoFire = null;
				<?php
				if ( $this->test_if_given_str('autoFire') ) {
					echo 'autoFire = '.$this->get_option('autoFire').';';
				}
				?>

				function isInteger(x) {
					return (typeof x === 'number') && (x % 1 === 0);
				}
				function handleAutoFire( delay ) {
					if ( (_ouibounce.checkCookieValue( cookieName, 'true') && !aggressive ) || fired === true ) return;
					setTimeout( _ouibounce._fireAndCallback, delay );
				}
				if ( isInteger(autoFire) && autoFire !== null ) {
				  handleAutoFire( autoFire );
				}
				/*** /AUTOFIRE JS ***/
			});
		})(jQuery);
		</script>
	<?php }

	function get_option( $optionname ) {
		return get_option(WBOUNCE_OPTION_KEY.'_'.$optionname);
	}
	function test_if_given_str( $optionname ) {
		return ( get_option(WBOUNCE_OPTION_KEY.'_'.$optionname) != "" ) ? true : false;
	}
	function echo_option_str( $optionname ) {
  		if ( $this->test_if_given_str(strtolower($optionname)) ) {
  			echo $optionname.':\''.$this->get_option(strtolower($optionname)).'\',';
  		}
	}
	function echo_option_int( $optionname ) {
  		if ( $this->test_if_given_str(strtolower($optionname)) ) {
  			echo $optionname.':'.$this->get_option($optionname).',';
{'fraction_non_alphanumeric': 0.1751673360107095, 'fraction_numerical': 0.017536813922356093, 'mean_word_length': 3.1641583054626534, 'pattern_counts': {'":': 0, '<': 117, '<?xml version=': 0, '>': 155, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2331767', 'n_tokens_mistral': 6052, 'n_tokens_neox': 5091, 'n_words': 888}