Skip to content

Instantly share code, notes, and snippets.

View janhebnes's full-sized avatar

Jan Hebnes janhebnes

View GitHub Profile
@janhebnes
janhebnes / gist:3550850
Created August 31, 2012 09:36
Sitecore CMS - Field level security validation for the SaveUI Pipeline so we could make sure no editor suddenly made changes to restricted languages versions of the same items.
public class EnsureLanguageWriteAccess
{
public int Limit
{
get;
set;
}
public void Process(Sitecore.Pipelines.Save.SaveArgs args)
{
@janhebnes
janhebnes / FallbackLanguageManager.cs
Created August 31, 2012 09:38
Sitecore CMS - Changes to the original Language Fallback module source for allowing fallback of layout deltas on a Shared layout fields - http://trac.sitecore.net/LanguageFallback/browser/Trunk/Sitecore.SharedSource.PartialLanguageFallback/Managers/Fallba
public static string ReadFallbackValue(Field field, Item item)
{
var fallbackItem = item.GetFallbackItem( MasterLanguage);
 
// makes 3 step renderings, currentitem -> fallback -> standard value
if (!TemplateManager.IsTemplate(item) && field.ID == Sitecore.FieldIDs.LayoutField && fallbackItem != null && fallbackItem.Versions.Count > 0 )
{
Field field1 = fallbackItem.Fields[field.ID];
if (!field1.ContainsStandardValue)
{
@janhebnes
janhebnes / gist:3550889
Created August 31, 2012 09:39
Sitecore does not implement hard validation on the language write access at field level, so to make sure a local editor would never be able to mingle with a language he did not have access to, we added the restriction code to the Item:Saving event queue p
public class EnsureLanguageWriteAccess
{
protected void OnItemSaving(object sender, EventArgs args)
{
Item item = Event.ExtractParameter(args, 0) as Item;
Error.AssertNotNull(item, "No item in parameters");
var itemlang = item.Database.GetItem(string.Format("/sitecore/system/Languages/{0}", item.Language));
if (itemlang != null && Sitecore.Security.AccessControl.AuthorizationManager.IsDenied(itemlang
, Sitecore.Security.AccessControl.AccessRight.LanguageWrite
@janhebnes
janhebnes / gist:3550905
Created August 31, 2012 09:41
Sitecore CMS - Event for handling changing the DataSources from path information to GUIDs to be inserted in the item:saving event prior to the save event
/// <summary>
/// The layout data sources are saved with a text path and not a guid.
/// </summary>
public class EnsureDataSourceIsGUID
{
public void OnItemSaving(object sender, EventArgs args)
{
Sitecore.Diagnostics.Log.Info("Running EnsureDataSourceIsGUID", this);
Item item = Event.ExtractParameter(args, 0) as Item;
@janhebnes
janhebnes / gist:3550920
Created August 31, 2012 09:43
Sitecore CMS - Handling Item copying where DataSources are referenced inside the copied structure, to inserted in the Item:Copied event queue.
/// <summary>
/// Class used to update Spot Context Data, when copying trees in Sitecore.
/// </summary>
public class LayoutDataSourceReferenceUpdater
{
#region Properties
/// <summary>
/// Gets or sets the new root Item (source item).
/// </summary>
@janhebnes
janhebnes / BuildTasks.TDSExcludeRulesValidator.cs
Created October 20, 2012 06:38
BuildTasks.TDSExcludeRulesValidator / MSBuild Task for monitoring the Exclude Rules in a Sitecore TDS Project file.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Xml;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
@janhebnes
janhebnes / gist:3946630
Created October 24, 2012 15:06
Sitecore CMS - SQL for Removing Non Image Blobs from a Sitecore Database Blob table
-- Large blob data in test/uat environments is just wastefull use of disk space
SP_SPACEUSED [Blobs]
-- FINDING ItemIds FOR RELEVANT FIELDS
-- File > Information > Extension Field
select * from Items where ID like 'C06867FE-9A43-4C7D-B739-48780492D06F'
-- File > Media > Blob Field
select * from Items where ID like '40E50ED9-BA07-4702-992E-A912738D32DC'
-- Examining the data location of the fields
@janhebnes
janhebnes / gist:3962756
Created October 27, 2012 02:44
Sitecore CMS - PageNotFound 404 handling using a Sitecore Item as ErrorPage
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Sitecore;
using Sitecore.Configuration;
using Sitecore.Diagnostics;
using Sitecore.Layouts;
using Sitecore.Pipelines.HttpRequest;
@janhebnes
janhebnes / gist:4001318
Created November 2, 2012 13:16
Sitecore CMS - GetContentEditorWarnings AvailableLanguageVersions Quick switch between versions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sitecore.Data.Items;
using Sitecore.Data.Managers;
using Sitecore.Globalization;
using Sitecore.Pipelines.GetContentEditorWarnings;
namespace SitecoreExtensions.Pipelines.GetContentEditorWarnings
@janhebnes
janhebnes / gist:6463709
Last active December 22, 2015 11:09
Parsing Web Browser Languages can be a pain here are some code snippets we use for getting the actual browser languages
// Try to match the local date format of the browser
var userLanguages = LanguageItem.GetRequestUserLanguages();
// Ignore if no language preferences
if (userLanguages != null)
{
var culture = CultureInfo.CreateSpecificCulture(userLanguages.First().IsoCode);
return Updated.ToString("d", culture);
}
return Updated.ToString("dd.MM.yyyy");