steveosoule
11/10/2014 - 10:25 PM

Miva Dynamic SEO

Miva Dynamic SEO

<mvt:comment><!-- Loop over all of the breadcrumbs starting with current category; working up the hierarchy --></mvt:comment>
<mvt:assign name="l.counter" value="miva_array_elements(l.settings:breadcrumbs:links)" />
<mvt:while expr="l.counter GT 0">
	<mvt:assign name="l.settings:cats" value="l.settings:breadcrumbs:links[l.counter]" />

	<mvt:item name="customfields" param="Read_Category_Code( l.settings:cats:code, '', l.settings:fields )" />

	<mvt:foreach iterator="field" array="fields">

		<mvt:comment><!-- Save templates --></mvt:comment>
		<mvt:if expr="'seo-template_' CIN l.settings:field:code AND l.settings:field:value">
			<mvt:assign name="l.template_code" value="gettoken( l.settings:field:code, '_', 2 )" />
			<mvt:if expr="NOT ( miva_array_find( l.template_code, l.settings:seo:template_codes, 1 ) )">
				<mvt:assign name="l.insert" value="miva_array_insert( l.settings:seo:template_codes, l.template_code, -1 )" />
				<mvt:assign name="l.insert" value="miva_array_insert( l.settings:seo:template_values, l.settings:field:value, -1 )" />
				<mvt:assign name="g.seo_template_index" value="g.seo_template_index + 1" />
			</mvt:if>
		</mvt:if>

		<mvt:comment><!-- Save variables --></mvt:comment>
		<mvt:if expr="'seo-variable_' CIN l.settings:field:code AND l.settings:field:value">
			<mvt:assign name="l.variable_code" value="gettoken( l.settings:field:code, '_', 2 )" />
			<mvt:if expr="NOT ( miva_array_find( l.variable_code, l.settings:seo:variable_codes, 1 ) )">
				<mvt:assign name="l.insert" value="miva_array_insert( l.settings:seo:variable_codes, l.variable_code, -1 )" />
				<mvt:assign name="l.insert" value="miva_array_insert( l.settings:seo:variable_values, l.settings:field:value, -1 )" />
			</mvt:if>
		</mvt:if>

	</mvt:foreach>

	<mvt:comment><!-- Save category name --></mvt:comment>
	<mvt:if expr="l.counter EQ miva_array_elements(l.settings:breadcrumbs:links) AND NOT ( miva_array_find( 'category', l.settings:seo:variable_codes, 1 ) )">
		<mvt:assign name="l.insert" value="miva_array_insert( l.settings:seo:variable_codes, 'category', -1 )" />
		<mvt:assign name="l.insert" value="miva_array_insert( l.settings:seo:variable_values, l.settings:category:name, -1 )" />
	</mvt:if>

	<mvt:assign name="l.counter" value="l.counter - 1" />

</mvt:while>

<mvt:comment><!-- Add empty variables to list --></mvt:comment>
<mvt:foreach iterator="field" array="fields">
	<mvt:if expr="'seo-variable_' CIN l.settings:field:code">
		<mvt:assign name="l.variable_code" value="gettoken( l.settings:field:code, '_', 2 )" />
		<mvt:if expr="NOT ( miva_array_find( l.variable_code, l.settings:seo:variable_codes, 1 ) )">
			<mvt:assign name="l.insert" value="miva_array_insert( l.settings:seo:variable_codes, l.variable_code, -1 )" />
			<mvt:assign name="l.insert" value="miva_array_insert( l.settings:seo:variable_values, '', -1 )" />
		</mvt:if>
	</mvt:if>
</mvt:foreach>

<mvt:comment><!-- Prevent duplicate keywords --></mvt:comment>
<mvt:foreach iterator="value" array="seo:variable_values">
	<mvt:foreach iterator="value2" array="seo:variable_values">
		<mvt:if expr="l.settings:value NE l.settings:value2 AND l.settings:value IN l.settings:value2">
			<mvt:assign name="l.settings:value2" value="trim(glosub( l.settings:value2, l.settings:value, '' ))" />
		</mvt:if>
	</mvt:foreach>
</mvt:foreach>

<mvt:comment><!-- Populate Templates with variable values --></mvt:comment>
<mvt:assign name="l.template_counter" value="0" />
<mvt:foreach iterator="template_value" array="seo:template_values">
	<mvt:assign name="l.template_counter" value="l.template_counter + 1" />

	<mvt:assign name="l.variable_counter" value="0" />
	<mvt:foreach iterator="code" array="seo:variable_codes">
		<mvt:assign name="l.variable_counter" value="l.variable_counter + 1" />
		<mvt:assign name="l.settings:search" value="'{{ ' $ l.settings:code $ ' }}'" />
		<mvt:assign name="l.settings:replacement" value="l.settings:seo:variable_values[l.variable_counter]" />
		<mvt:assign name="l.settings:template_value" value="glosub( l.settings:template_value, l.settings:search, l.settings:replacement )" />
	</mvt:foreach>

	<mvt:assign name="l.settings:template_value" value="encodeattribute(glosub(glosub(glosub(trim(l.settings:template_value), ' .', '.'), ' ,', ','), ' !', '!'))" />

	<mvt:if expr="l.settings:seo:content">
		<mvt:assign name="l.settings:seo:content" value="l.settings:seo:content $ ','" />
	</mvt:if>
	<mvt:assign name="l.settings:seo:content" value="l.settings:seo:content $ ':' $ l.settings:seo:template_codes[l.template_counter] $ '=' $ l.settings:template_value" />
</mvt:foreach>

<mvt:assign name="l.settings:seo" value="miva_array_deserialize( l.settings:seo:content )" />