Skip to content

Instantly share code, notes, and snippets.

View fluxdigital's full-sized avatar

Adam Seabridge fluxdigital

View GitHub Profile
@fluxdigital
fluxdigital / add experience editor button to rendering
Created August 20, 2020 00:27
add-experience-editor-button-to-rendering.ps1
#add button to custom experience editor button to all matching components
$componentsPath = Get-ChildItem -Path "/sitecore/layout/Renderings/Shared/Test"
$multiListFieldName = "Page Editor Buttons"
$buttonIdToAdd = "{26A25CDD-E49D-4846-BA07-17D85C6DA950}"
Write-Host "Getting Components..."
foreach($component in $componentsPath){
#check if there is no datasource
if($component.Fields["Datasource Location"].Value -ne ""){
@fluxdigital
fluxdigital / add-captcha-to-wffm-forms.ps1
Last active October 9, 2020 16:35
adds a captcha to any form within a folder that doesn't have a captcha already
#add captcha to any form that doesn't have one already
$formsRootPath = "master:/sitecore/content/Wbsite1/forms/test"
$wffmFormTemplateId = "{FFB1DA32-2764-47DB-83B0-95B843546A7E}"
$wffmFieldTemplateId = "{C9E1BF85-800A-4247-A3A3-C3F5DFBFD6AA}"
$captchaFieldTemplateId = "{7FB270BE-FEFC-49C3-8CB4-947878C099E5}"
$captchaFieldName = "I'm not a Robot"
$captchFieldSortOrder = 1000
$updatedCount = 0
Write-Host "Getting List of Forms to add Captchas to from: $($formsRootPath)..."
@fluxdigital
fluxdigital / add-new-item-with-forced-id.ps1
Last active January 8, 2021 00:01
Add a New Item with an Specific ID
New-Item -Path "master:\content\home" -Name "Item With Forced ID" -ItemType "Sample/Sample Item" -ForceId "777f5e27-bbb2-462b-a3bc-8e170e84649d"
# Create Package & Set Properties
$package = new-package "Test Pages & Components";
$package.Sources.Clear();
$package.Metadata.Author = "aseabridge";
$package.Metadata.Publisher = "Flux Digital";
$package.Metadata.Version = "1.0";
$package.Metadata.Readme = 'This package contains number of test pages and components';
Write-Host "Creating Test Pages & Components Package..."
@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
{
@inherits MyWebsite.Models.ITable
@{
var tableRowsToSkip = 0;
if (DataSource.HasHeaderRow)
{
tableRowsToSkip = 1;
}
var tableRowsToRemove = 1;
if (DataSource.HasFooterRow && DataSource.HasHeaderRow)
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; }
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);
<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" />
@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