Footer.ps1

<#
    .SYNOPSIS
        Converts a simplified footer json file into an html footer.
    .DESCRIPTION
        Converts a simplified footer json file into an html footer.
    .LINK
        Nexus Innovations : http://www.nexusinno.com
#>


function global:ConvertFrom-SimplifiedFooter {
    [CmdletBinding()]
    Param (
        [ValidateScript({ Test-Path $_ -PathType Leaf })]
        [Parameter(Mandatory)]
        [string]$ValOpsFooterPath,

        [Parameter(Mandatory)]
        [string]$FooterPath
    )

    # Get simplified footer fields from json
    $simpleFooter = @{ }
    $footer = [string]::Empty
    try {
        $simpleFooter = Get-Content -Path $ValOpsFooterPath -Raw -Encoding UTF8 | ConvertFrom-Json
        $footer = Get-Content -Path $FooterPath -Raw -Encoding UTF8
    }
    catch {
        throw $_.Exception.Message
    }

    $footer = $footer -replace "{FIELD==CONTINENTA}", $simpleFooter.HeadOffice.Continent `
        -replace "{FIELD==STREETNUMBERA}", $simpleFooter.HeadOffice.CivicNumber `
        -replace "{FIELD==STREETNAMEA}", $simpleFooter.HeadOffice.StreetName `
        -replace "{FIELD==SUITENUMBERA}", $simpleFooter.HeadOffice.SuiteNumber `
        -replace "{FIELD==CITYA}", $simpleFooter.HeadOffice.City `
        -replace "{FIELD==PROVINCEA}", $simpleFooter.HeadOffice.Province `
        -replace "{FIELD==COUNTRYA}", $simpleFooter.HeadOffice.Country `
        -replace "{FIELD==POSTALCODEA}", $simpleFooter.HeadOffice.PostalCode `
        -replace "{FIELD==PHONENUMBERA}", $simpleFooter.HeadOffice.PhoneNumber `
        -replace "{FIELD==FACEBOOK}", $simpleFooter.SocialMedia.Facebook `
        -replace "{FIELD==TWITTER}", $simpleFooter.SocialMedia.Twitter `
        -replace "{FIELD==LINKEDIN}", $simpleFooter.SocialMedia.LinkedIn `
        -replace "{FIELD==YOUTUBE}", $simpleFooter.SocialMedia.YouTube
    
    if ($null -ne $simpleFooter.SecondaryOffice) {
        $footer = $footer -replace "{FIELD==CONTINENTB}", $simpleFooter.SecondaryOffice.Continent `
            -replace "{FIELD==STREETNUMBERB}", $simpleFooter.SecondaryOffice.CivicNumber `
            -replace "{FIELD==STREETNAMEB}", $simpleFooter.SecondaryOffice.StreetName `
            -replace "{FIELD==SUITENUMBERB}", $simpleFooter.SecondaryOffice.SuiteNumber `
            -replace "{FIELD==CITYB}", $simpleFooter.SecondaryOffice.City `
            -replace "{FIELD==PROVINCEB}", $simpleFooter.SecondaryOffice.Province `
            -replace "{FIELD==COUNTRYB}", $simpleFooter.SecondaryOffice.Country `
            -replace "{FIELD==POSTALCODEB}", $simpleFooter.SecondaryOffice.PostalCode `
            -replace "{FIELD==PHONENUMBERB}", $simpleFooter.SecondaryOffice.PhoneNumber `
            -replace "{ZONE==SecondaryOffice}", [string]::Empty `
            -replace "{ZONE==/SecondaryOffice}", [string]::Empty
    
    }
    else {
        $SecondaryOfficeBlock = $footer | Select-String '(?smi){ZONE==SecondaryOffice}[^!]+{ZONE==/SecondaryOffice}' -AllMatches | `
            ForEach-Object { $_.Matches } | `
            ForEach-Object { $_.Value }

        $footer = $footer -replace $SecondaryOfficeBlock, [string]::Empty
    }

    Set-Content -Path $FooterPath -Value $footer -Encoding UTF8
}