Skip to content

Instantly share code, notes, and snippets.

View fluxdigital's full-sized avatar

Adam Seabridge fluxdigital

View GitHub Profile
<#
### Displays a 'Draft Site' message in Experience Editor ###
.Description
The $text variable below should be edited as required.
#>
$title = "Displaying Draft Site"
$text = "You are viewing the draft (Master DB) version of the site."
$icon = @{$true="Office/32x32/information.png";$false="Applications/16x16/warning.png"}[$SitecoreVersion.Major -gt 7]
<#
### Moves all SXA Draft Sites to Top of list so they load on the CM before the non-Draft sites ###
.Description
Before running this script open the SXA Site Manager from the Powershell Toolbox to ensure all sites are up to date.
All Draft sites will be moved to the top of this field: "/sitecore/system/Settings/Foundation/Experience Accelerator/Multisite/Management/Sites"
#>
$sxaSitesList = Get-Item -Path "master:/sitecore/system/Settings/Foundation/Experience Accelerator/Multisite/Management/Sites"
$orderField = $sxaSitesList.Fields["Order"].Value;
<#
### Context Menu script to creates a single SXA Draft Site - for use on the CM Instance ###
.Description
Should be created in the Content Menu section, e.g: /sitecore/system/Modules/PowerShell/Script Library/{YOUR SCRIPT LIBRARY}/Content Editor/Context Menu
Duplicates the existing Site Grouping item and adds 'DRAFT' to the name.
Sets the environment to 'Draft' and database to 'master' also sets the target hostname to the current CM instance Url.
Moves the new Draft site to the top of the list so it is loaded before the non-Draft site.
#>
Import-Function -Name "Get-CmUrl"
Import-Function -Name "Move-Preview-Site-To-Top"
<#
### Creates Draft Sites for all existing Sites - for use on the CM Instance ###
.Description
For each site -> Duplicates the existing Site Grouping item and adds 'DRAFT' to the name.
Sets the environment to 'Draft' and database to 'master' also sets the target hostname to the current CM instance Url.
#>
$rootItem = Get-Item -Path "/sitecore/content"
$sxaSites = Get-ChildItem -Path "/sitecore/content/Sites"
$successCount = 0
@fluxdigital
fluxdigital / Strip-Invalid-HTML-Tags-SPE-Script.ps1
Last active February 17, 2022 21:33
Remove script tags from RTE fields using SPE. Can easily be updated to remove any HTML tag required.
function Strip-InvalidTags($item, $fieldName){
write-host "checking: $($item.Name) for matching tags..."
if($item.Fields[$fieldName]){
$html = $item.Fields[$fieldName].value
$htmlDocument = New-Object -TypeName HtmlAgilityPack.HtmlDocument
$htmlDocument.LoadHtml($html)
$scriptNodes = $htmlDocument.DocumentNode.SelectNodes("//script") #you can change this to any tag or duplicate this for multiple nodes as needed
<configuration
name="Foundation.SiteCron"
description="SiteCron definition items"
dependencies="Foundation.Serialization"
patch:after="configuration[@name='Foundation.Serialization']"
extends="Helix.Foundation">
<predicate type="Unicorn.Predicates.SerializationPresetPredicate, Unicorn" singleInstance="true">
<include name="ModulesTemplatesSitecron" database="master" path="/sitecore/templates/Modules/Sitecron" />
<include name="SystemSitecron" database="master" path="/sitecore/system/Modules/Sitecron">
<exclude childrenOfPath="OOTB/SiteCron Execution Reports" />
class AddTableRows : WebEdit
{
private string RowsToAdd { get; set; }
public override void Execute(CommandContext context)
{
Assert.ArgumentNotNull((object)context, nameof(context));
ItemUri queryString = ItemUri.ParseQueryString();
if (queryString != (ItemUri)null)
{
Item obj = Database.GetItem(queryString);
public interface ITable : ISitecoreItem
{
bool HasHeaderRow { get; set; }
bool HasFooterRow { get; set; }
IEnumerable<ITableRow> TableRows { get; set; }
}
public interface ITableRow : ISitecoreItem
{
IEnumerable<ITableCell> TableCells { get; set; }
@inherits MyWebsite.Models.ITable
@{
var tableRowsToSkip = 0;
if (DataSource.HasHeaderRow)
{
tableRowsToSkip = 1;
}
var tableRowsToRemove = 1;
if (DataSource.HasFooterRow && DataSource.HasHeaderRow)
@fluxdigital
fluxdigital / Last-Run-Log.cs
Last active June 25, 2021 00:00
Logging to the SiteCron Last Run Log
public void Execute(IJobExecutionContext context)
{
//get details of Job
JobDataMap dataMap = context.JobDetail.JobDataMap;
string itemId = dataMap.GetString(SitecronConstants.FieldNames.ItemID);
Database masterDb = Sitecore.Configuration.Factory.GetDatabase("master");
Item jobItem = masterDb.GetItem(new ID(itemId));
try
{