<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet [ 
<!ENTITY nbsp "&#160;"> 
<!ENTITY mdash "&#8212;">
]>

<!-- 
	Social Media Meta Tags Core Skeleton - 10/09/2018

	XSL that helps schools output social meta tags to there pages and have the ability to overwrite wheen needed
-->

<xsl:stylesheet version="3.0"
				xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
				xmlns:xs="http://www.w3.org/2001/XMLSchema"
				xmlns:ou="http://omniupdate.com/XSL/Variables"
				xmlns:ouc="http://omniupdate.com/XSL/Variables"
				exclude-result-prefixes="xs ou ouc">
	
	<!-- xsl param to enable social meta tag output onto the pages -->
	<xsl:param name="enable-social-meta-tag-output" select="false()" />
	
	<!-- template for the social meta tags output -->
	<xsl:template name="full-social-meta-tag-output">
		<xsl:variable name="output" select="$enable-social-meta-tag-output" />
		<xsl:if test="$output">
			<xsl:call-template name="open-graph-tag-output" />
			<xsl:call-template name="twitter-card-tag-output" />
		</xsl:if>
	</xsl:template>
	
	<!-- ############ open graph directory variables ############ -->
	<!-- directory variable for the og image -->
	<xsl:param name="ou:og-image" />
	<!-- directory variable for the og image description -->
	<xsl:param name="ou:og-image-alt" />
	<!-- directory variable for the og site name -->
	<xsl:param name="ou:og-site-name" />
	<!-- directory variable for the fb app id, this is optional but when defined will give analytics back to your facebook account -->
	<xsl:param name="ou:fb-app-id" />
	<!-- directory variable for declaring the type of content, as seen here https://developers.facebook.com/docs/reference/opengraph#object-type -->
	<xsl:param name="ou:og-type" />
	<!-- ############ open graph directory variables ############ -->
	
	<!-- override the open graph type -->
	<xsl:param name="override-og-type" />
	<!-- the final open graph type -->
	<xsl:variable name="final-og-type">
		<xsl:call-template name="final-social-output">
			<xsl:with-param name="check-output" select="$override-og-type" />
			<xsl:with-param name="default-output" select="$ou:og-type"/>
		</xsl:call-template>
	</xsl:variable>
	
	<!-- override the open graph image -->
	<xsl:param name="override-og-image" />
	<!-- the final open graph image -->
	<xsl:variable name="final-og-image">
		<xsl:call-template name="final-social-output">
			<xsl:with-param name="check-output" select="$override-og-image" />
			<xsl:with-param name="default-output" select="$ou:og-image"/>
		</xsl:call-template>
	</xsl:variable>
	
	<!-- override the open graph description -->
	<xsl:param name="override-og-title" />
	<!-- the final open graph description -->
	<xsl:variable name="final-og-title">
		<xsl:call-template name="final-social-output">
			<xsl:with-param name="check-output" select="$override-og-title" />
			<xsl:with-param name="default-output" select="$page-title"/>
		</xsl:call-template>
	</xsl:variable>
	
	<!-- override the open graph description -->
	<xsl:param name="override-og-description" />
	<!-- the final open graph description -->
	<xsl:variable name="final-og-description">
		<xsl:call-template name="final-social-output">
			<xsl:with-param name="check-output" select="$override-og-description" />
			<xsl:with-param name="default-output" select="/document/ouc:properties/meta[@name='Description' or @name='description'][1]/@content"/>
		</xsl:call-template>
	</xsl:variable>
	
	<!-- override the og image alt -->
	<xsl:param name="override-og-image-alt" />
	<!-- the final open graph image -->
	<xsl:variable name="final-og-image-alt">
		<xsl:call-template name="final-social-output">
			<xsl:with-param name="check-output" select="$override-og-image-alt" />
			<xsl:with-param name="default-output" select="$ou:og-image-alt"/>
		</xsl:call-template>
	</xsl:variable>
	
	<!-- facebook opengraph meta tag output -->
	<xsl:template name="open-graph-tag-output">
		<xsl:if test="$final-og-image !=''"><meta property="og:image" content="{$final-og-image}"/></xsl:if>
		<xsl:if test="$final-og-image-alt !=''"><meta property="og:image:alt" content="{$final-og-image-alt}"/></xsl:if>
		<meta property="og:title" content="{$final-og-title}"/>
		<meta property="og:url" content="{$page-pub-path}"/>
		<meta property="og:description" content="{$final-og-description}" />
		<xsl:if test="$ou:og-site-name !=''"><meta property="og:site_name" content="{$ou:og-site-name}"/></xsl:if>
		<meta property="og:type" content="{$final-og-type}"/>
		<xsl:if test="$ou:fb-app-id !=''"><meta property="fb:app_id" content="{$ou:fb-app-id}" /></xsl:if>
		<meta property="og:updated_time" content="{current-dateTime()}" />
	</xsl:template>
	
	<!-- ############ twitter card directory variables ############ -->
	<!-- the twitter handle of who created the content for the twitter card -->
	<xsl:param name="ou:twitter-creator" />
	<!-- the site of the content for the twitter card -->
	<xsl:param name="ou:twitter-site" />
	<!-- the image of the content for the twitter card, needs to be less than 5 mb -->
	<xsl:param name="ou:twitter-card-image" />
	<!-- the image description for the twitter card, needs to be less than 420 characters -->
	<xsl:param name="ou:twitter-card-image-alt" />
	<!-- twitter card type, options are summary or summary_large_image -->
	<xsl:param name="ou:twitter-card-type" />
	<!-- ############ twitter card directory variables ############ -->
	
	<!-- override the twitter card title -->
	<xsl:param name="override-twitter-card-title" />
	<!-- the final twitter card title needs to be less than 70 characters -->
	<xsl:variable name="final-twitter-card-title">
		<xsl:call-template name="final-social-output">
			<xsl:with-param name="check-output" select="$override-twitter-card-title" />
			<xsl:with-param name="default-output" select="$page-title"/>
		</xsl:call-template>
	</xsl:variable>
	
	<!-- override the twitter card description -->
	<xsl:param name="override-twitter-card-description" />
	<!-- the final twitter card description, needs to be less than 200 characters -->
	<xsl:variable name="final-twitter-card-description">
		<xsl:call-template name="final-social-output">
			<xsl:with-param name="check-output" select="$override-twitter-card-description" />
			<xsl:with-param name="default-output" select="/document/ouc:properties/meta[@name='Description' or @name='description'][1]/@content"/>
		</xsl:call-template>
	</xsl:variable>
	
	<!-- override the twitter image -->
	<xsl:param name="override-twitter-card-image" />
	<!-- the final twitter image -->
	<xsl:variable name="final-twitter-card-image">
		<xsl:call-template name="final-social-output">
			<xsl:with-param name="check-output" select="$override-twitter-card-image" />
			<xsl:with-param name="default-output" select="$ou:twitter-card-image"/>
		</xsl:call-template>
	</xsl:variable>
	
	<!-- override the twitter image -->
	<xsl:param name="override-twitter-card-creator" />
	<!-- the final twitter image -->
	<xsl:variable name="final-twitter-card-creator">
		<xsl:call-template name="final-social-output">
			<xsl:with-param name="check-output" select="$override-twitter-card-creator" />
			<xsl:with-param name="default-output" select="$ou:twitter-creator"/>
		</xsl:call-template>
	</xsl:variable>
	
	<!-- override the twitter image -->
	<xsl:param name="override-twitter-card-site" />
	<!-- the final twitter image -->
	<xsl:variable name="final-twitter-card-site">
		<xsl:call-template name="final-social-output">
			<xsl:with-param name="check-output" select="$override-twitter-card-site" />
			<xsl:with-param name="default-output" select="$ou:twitter-site"/>
		</xsl:call-template>
	</xsl:variable>
	
	<!-- override the twitter image alt -->
	<xsl:param name="override-twitter-card-image-alt" />
	<!-- the finaltwitter image alt -->
	<xsl:variable name="final-twitter-card-image-alt">
		<xsl:call-template name="final-social-output">
			<xsl:with-param name="check-output" select="$override-twitter-card-image-alt" />
			<xsl:with-param name="default-output" select="$ou:twitter-card-image-alt"/>
		</xsl:call-template>
	</xsl:variable>
	
	<!-- override the card type options: summary or summary_large_image -->
	<xsl:param name="override-twitter-card-type" select="'summary_large_image'"/>
	<!-- the final twitter card type -->
	<xsl:variable name="final-twitter-card-type">
		<xsl:call-template name="final-social-output">
			<xsl:with-param name="check-output" select="$override-twitter-card-type" />
			<xsl:with-param name="default-output" select="$ou:twitter-card-type"/>
		</xsl:call-template>
	</xsl:variable>

	<!-- twitter card meta tag output -->
	<xsl:template name="twitter-card-tag-output">
		<meta name="twitter:card" content="summary_large_image"/>
		<meta name="twitter:url" content="{$page-pub-path}"/>
		<meta name="twitter:title" content="{substring($final-twitter-card-title, 1, 70)}"/>
		<meta name="twitter:description" content="{substring($final-twitter-card-description, 1, 200)}"/>
		<xsl:if test="$final-twitter-card-image !=''"><meta name="twitter:image" content="{$final-twitter-card-image}" /></xsl:if>
		<xsl:if test="$final-twitter-card-image-alt !=''"><meta name="twitter:image:alt" content="{substring($final-twitter-card-image-alt, 1, 420)}" /></xsl:if>
		<xsl:if test="$final-twitter-card-creator !=''"><meta name="twitter:creator" content="{$final-twitter-card-creator}"/></xsl:if>
		<xsl:if test="$final-twitter-card-site !=''"><meta name="twitter:site" content="{$final-twitter-card-site}"/></xsl:if>
	</xsl:template>
	
	<!-- template to help with social meta tag output -->
	<xsl:template name="final-social-output">
		<xsl:param name="check-output" />
		<xsl:param name="default-output" />
		<xsl:value-of select="if ($check-output = '') then $default-output else $check-output" />
	</xsl:template>

</xsl:stylesheet>