<commit_before><?php
//Custom functions

 
// Add in blog.envysion.com's (Hubspot) Posts sitemap to Yoast

// Yoast SEO, add own sub-sitemap
// works only after SEO -> XML Sitemaps -> Post Types (change something and back, some cache?)
function my_wpseo_sitemap_index() {
	$url = "http://blog.envysion.com/sitemap.xml";
	/*
	$response = wp_remote_get( $url );
	
	if( is_array($response) ) {
		$body = $response['body']; // use the content
		$headers = $response['headers'];	
	}
	*/
	
	// http://wordpress.stackexchange.com/a/8404
	/*
	date_default_timezone_set( get_option('timezone_string') );
	if($remotelastmod){
		$lastmod = $remotelastmod;
	}else{
		$lastmod = date( 'Y-m-d',strtotime("-2 days") );
	}
	*/
	$lastmod = date( 'Y-m-d',strtotime("-2 days") );
	$xml = '<sitemap>' . "\n";
	$xml .= '<loc>' . $url . '</loc>' . "\n";
	$xml .= '<lastmod>' .  $lastmod . '</lastmod>' . "\n";
	$xml .= '</sitemap>' . "\n";
	return $xml;
}
add_filter( 'wpseo_sitemap_index', 'my_wpseo_sitemap_index' );

 
/*Disable XML-RPC for security reasons */
add_filter('xmlrpc_enabled', '__return_false');

// Add about the author to wordpress feeds
function wpbeginner_postrss($content) {
	global $wp_query;
	$postid = $wp_query->post->ID;
	
	if(is_feed()) {
		//while the filter this hooks into will always add this, the is_feed check only runs this on feed content
		if(has_post_thumbnail($post->ID)) {
			$content = '<div>' . get_the_post_thumbnail($postid,'thumbnail') . '</div>' . $content;
		}
		$content = $content."<p>About ".get_the_author()."</p>";
		$is_guest = get_field('use_a_guest_author_for_this_post',$postid);
		
		if($is_guest):
			$bio = get_field('guest_author_bio',$postid);
		else:
			$bio = wpautop(get_the_author_meta('description'));
		endif;
		$content .= $bio;
	}else{
		$content = $content;
	}
	return $content;
}
add_filter('the_content', 'wpbeginner_postrss');


function add_cta_stuff_to_posts($content) {
	global $post;
	$cta = '';
	
	$cta_content = get_field('call-to-action_content',$post->ID);
	$cta_icon = get_field('call-to-action_icon',$post->ID);
	if($cta_content && !is_feed()):
		$cta .= "<div class='postcta'>".wpautop($cta_content)."</div>";
		if($cta_icon):
			$cta .= "<style>div.postcta:before{content:'".rtrim(str_replace("&#x","\\", $cta_icon->unicode),";")."';}</style>";
		endif;
		$content = $content . $cta;
		return $content;
	else:
		return $content;
	endif;
}
add_filter('the_content', 'add_cta_stuff_to_posts',1);


	
// Resources Get_Posts Function
function get_resource( $post_type, $taxonomy_term = false, $posts_per_page = 10 ) {

	$base_args = array(
		'posts_per_page'   => $posts_per_page,
		'category'         => '',
		'post_type'        => $post_type,
		'post_status'      => 'publish'
	);

	if ( $taxonomy_term ) {
		$additional_args = array(
			'tax_query' => array(
				array(
					'taxonomy' => 'industry',
					'field' => 'slug',
					'terms' => $taxonomy_term
				)
			)
		);
	} else {
		$additional_args = array();
	}

	$args = array_merge( $base_args, $additional_args );

	return get_posts( $args );
}
 
//IFrame Shortcode
add_shortcode( 'iframe' , 'mycustom_shortcode_iframe' );
function mycustom_shortcode_iframe($args, $content) {
    $keys = array("src", "width", "height", "scrolling", "marginwidth", "marginheight", "frameborder", "style");
    $arguments = mycustom_extract_shortcode_arguments($args, $keys);
    return '<iframe ' . $arguments . '></iframe>';
}

function mycustom_extract_shortcode_arguments($args, $keys) {
    $result = "";
    foreach ($keys as $key) {
        if (isset($args[$key])) {
            $result .= $key . '="' . $args[$key] . '" ';
        }
    }
    return $result;
}



function output_jobvite_iframe(){
	$return = '<!-- BEGIN JOBVITE CODE -->
    <iframe id="jobviteframe" src="http://hire.jobvite.com/CompanyJobs/Jobs.aspx?c=qv1aVfwl&jvresize=http://envysion.com/FrameResize.html" width="100%" height="500px" scrolling="no" frameborder="0" allowtransparency="true">Sorry, iframes are not supported.</iframe>
    <script type="text/javascript">
          var l = location.href;
          var args = "";
          var k = "";
          var iStart = l.indexOf("?jvk=");
          if (iStart == -1) iStart = l.indexOf("&jvk=");
          if (iStart != -1) {
                iStart += 5;
                var iEnd = l.indexOf("&", iStart);
                if (iEnd == -1) iEnd = l.length;
                k = l.substring(iStart, iEnd);
          }
          iStart = l.indexOf("?jvi=");
          if (iStart == -1) iStart = l.indexOf("&jvi=");
          if (iStart != -1) {
                iStart += 5;
                var iEnd = l.indexOf("&", iStart);
                if (iEnd == -1) iEnd = l.length;
                args += "&j=" + l.substring(iStart, iEnd);
                if (!k.length) args += "&k=Job";
                var iStart = l.indexOf("?jvs=");
                if (iStart == -1) iStart = l.indexOf("&jvs=");
                if (iStart != -1){
                      iStart += 5;
                      var iEnd = l.indexOf("&", iStart);
                      if (iEnd == -1) iEnd = l.length;
                      args += "&s=" + l.substring(iStart, iEnd);
                }
          }
          if (k.length) args += "&k=" + k;
          if (args.length) document.getElementById("jobviteframe").src += args;
          function resizeFrame(height, scrollToTop) {
                if (scrollToTop) window.scrollTo(0, 0);
                var oFrame = document.getElementById("jobviteframe");
                if (oFrame) oFrame.height = height;
          }
    </script>
    <!--END JOBVITE CODE -->';
	
	return $return;
}

add_shortcode( 'jobvite' , 'output_jobvite_iframe' );


function output_hubspot_form(){
$return ='
<!--[if lte IE 8]>
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2-legacy.js"></script>
<![endif]-->
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
<script>
  hbspt.forms.create({ 
    sfdcCampaignId: "701400000011X5NAAU",<commit_msg>New jobvite code<commit_after><?php
//Custom functions

 
// Add in blog.envysion.com's (Hubspot) Posts sitemap to Yoast

// Yoast SEO, add own sub-sitemap
// works only after SEO -> XML Sitemaps -> Post Types (change something and back, some cache?)
function my_wpseo_sitemap_index() {
	$url = "http://blog.envysion.com/sitemap.xml";
	/*
	$response = wp_remote_get( $url );
	
	if( is_array($response) ) {
		$body = $response['body']; // use the content
		$headers = $response['headers'];	
	}
	*/
	
	// http://wordpress.stackexchange.com/a/8404
	/*
	date_default_timezone_set( get_option('timezone_string') );
	if($remotelastmod){
		$lastmod = $remotelastmod;
	}else{
		$lastmod = date( 'Y-m-d',strtotime("-2 days") );
	}
	*/
	$lastmod = date( 'Y-m-d',strtotime("-2 days") );
	$xml = '<sitemap>' . "\n";
	$xml .= '<loc>' . $url . '</loc>' . "\n";
	$xml .= '<lastmod>' .  $lastmod . '</lastmod>' . "\n";
	$xml .= '</sitemap>' . "\n";
	return $xml;
}
add_filter( 'wpseo_sitemap_index', 'my_wpseo_sitemap_index' );

 
/*Disable XML-RPC for security reasons */
add_filter('xmlrpc_enabled', '__return_false');

// Add about the author to wordpress feeds
function wpbeginner_postrss($content) {
	global $wp_query;
	$postid = $wp_query->post->ID;
	
	if(is_feed()) {
		//while the filter this hooks into will always add this, the is_feed check only runs this on feed content
		if(has_post_thumbnail($post->ID)) {
			$content = '<div>' . get_the_post_thumbnail($postid,'thumbnail') . '</div>' . $content;
		}
		$content = $content."<p>About ".get_the_author()."</p>";
		$is_guest = get_field('use_a_guest_author_for_this_post',$postid);
		
		if($is_guest):
			$bio = get_field('guest_author_bio',$postid);
		else:
			$bio = wpautop(get_the_author_meta('description'));
		endif;
		$content .= $bio;
	}else{
		$content = $content;
	}
	return $content;
}
add_filter('the_content', 'wpbeginner_postrss');


function add_cta_stuff_to_posts($content) {
	global $post;
	$cta = '';
	
	$cta_content = get_field('call-to-action_content',$post->ID);
	$cta_icon = get_field('call-to-action_icon',$post->ID);
	if($cta_content && !is_feed()):
		$cta .= "<div class='postcta'>".wpautop($cta_content)."</div>";
		if($cta_icon):
			$cta .= "<style>div.postcta:before{content:'".rtrim(str_replace("&#x","\\", $cta_icon->unicode),";")."';}</style>";
		endif;
		$content = $content . $cta;
		return $content;
	else:
		return $content;
	endif;
}
add_filter('the_content', 'add_cta_stuff_to_posts',1);


	
// Resources Get_Posts Function
function get_resource( $post_type, $taxonomy_term = false, $posts_per_page = 10 ) {

	$base_args = array(
		'posts_per_page'   => $posts_per_page,
		'category'         => '',
		'post_type'        => $post_type,
		'post_status'      => 'publish'
	);

	if ( $taxonomy_term ) {
		$additional_args = array(
			'tax_query' => array(
				array(
					'taxonomy' => 'industry',
					'field' => 'slug',
					'terms' => $taxonomy_term
				)
			)
		);
	} else {
		$additional_args = array();
	}

	$args = array_merge( $base_args, $additional_args );

	return get_posts( $args );
}
 
//IFrame Shortcode
add_shortcode( 'iframe' , 'mycustom_shortcode_iframe' );
function mycustom_shortcode_iframe($args, $content) {
    $keys = array("src", "width", "height", "scrolling", "marginwidth", "marginheight", "frameborder", "style");
    $arguments = mycustom_extract_shortcode_arguments($args, $keys);
    return '<iframe ' . $arguments . '></iframe>';
}

function mycustom_extract_shortcode_arguments($args, $keys) {
    $result = "";
    foreach ($keys as $key) {
        if (isset($args[$key])) {
            $result .= $key . '="' . $args[$key] . '" ';
        }
    }
    return $result;
}



function output_jobvite_iframe(){
	$return = '<!-- BEGIN JOBVITE CODE -->
  <div class="jv-careersite" data-careersite="envysion"></div>

  <script src="https://jobs.jobvite.com/__assets__/scripts/careersite/public/iframe.js"></script>
  
  <script>Jobvite = { careersite: "envysion" };</script>

  <script src="https://jobs.jobvite.com/__assets__/scripts/careersite/public/redirect.js"> </script>
    <!-- old jobvite code
    <iframe id="jobviteframe" src="http://hire.jobvite.com/CompanyJobs/Jobs.aspx?c=qv1aVfwl&jvresize=http://envysion.com/FrameResize.html" width="100%" height="500px" scrolling="no" frameborder="0" allowtransparency="true">Sorry, iframes are not supported.</iframe>
    <script type="text/javascript">
          var l = location.href;
          var args = "";
          var k = "";
          var iStart = l.indexOf("?jvk=");
          if (iStart == -1) iStart = l.indexOf("&jvk=");
          if (iStart != -1) {
                iStart += 5;
                var iEnd = l.indexOf("&", iStart);
                if (iEnd == -1) iEnd = l.length;
                k = l.substring(iStart, iEnd);
          }
          iStart = l.indexOf("?jvi=");
          if (iStart == -1) iStart = l.indexOf("&jvi=");
          if (iStart != -1) {
                iStart += 5;
                var iEnd = l.indexOf("&", iStart);
                if (iEnd == -1) iEnd = l.length;
                args += "&j=" + l.substring(iStart, iEnd);
                if (!k.length) args += "&k=Job";
                var iStart = l.indexOf("?jvs=");
                if (iStart == -1) iStart = l.indexOf("&jvs=");
                if (iStart != -1){
                      iStart += 5;
                      var iEnd = l.indexOf("&", iStart);
                      if (iEnd == -1) iEnd = l.length;
                      args += "&s=" + l.substring(iStart, iEnd);
                }
          }
          if (k.length) args += "&k=" + k;
          if (args.length) document.getElementById("jobviteframe").src += args;
          function resizeFrame(height, scrollToTop) {
                if (scrollToTop) window.scrollTo(0, 0);
                var oFrame = document.getElementById("jobviteframe");
                if (oFrame) oFrame.height = height;
          }
    </script>-->
    <!--END JOBVITE CODE -->';
	
	return $return;
}

add_shortcode( 'jobvite' , 'output_jobvite_iframe' );


function output_hubspot_form(){
$return ='
<!--[if lte IE 8]>
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2-legacy.js"></script>
<![endif]-->
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
<script>
  hbspt.forms.create({ 
    sfdcCampaignId: "701400000011X5NAAU",
{'fraction_non_alphanumeric': 0.18623351559987134, 'fraction_numerical': 0.00788034737857832, 'mean_word_length': 2.8963032581453634, 'pattern_counts': {'":': 0, '<': 72, '<?xml version=': 0, '>': 102, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, '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': '453701', 'n_tokens_mistral': 4749, 'n_tokens_neox': 4427, 'n_words': 854}