Skip to content

Instantly share code, notes, and snippets.

View smdooley's full-sized avatar

Sean Dooley smdooley

View GitHub Profile
@smdooley
smdooley / AuthorFilter.cs
Created May 25, 2023 09:33
Extending Umbraco Content Delivery API
using Umbraco.Cms.Core.DeliveryApi;
namespace UmbracoPlayground.UI.Application.Filters
{
public class AuthorFilter : IFilterHandler
{
private const string FilterType = "author:";
public FilterOption BuildFilterOption(string filter)
{
using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
namespace Project.Core.Extensions
{
public static class EnumExtensions
{
public static string GetEnumDescription(this Enum value)
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web;
public static class EnumerableExtensions {
public static bool HasAny<T> (this IEnumerable<T> items) => items != null && items.Any();
public static bool IsNullOrEmpty<T>(this IEnumerable<T> items)
@smdooley
smdooley / XPathQueryExamples.md
Created January 19, 2023 10:34
Various XPath query examples for Umbraco Multinode Treepicker

Umbraco Multinode Treepicker

Available placeholders

  • $current Current page or closest found ancestor
  • $parent Parent page or closest found ancestor
  • $root Root of the content tree
  • $site Ancestor node at level 1

Examples

@smdooley
smdooley / UrlHelper.cs
Created January 11, 2023 10:56
UrlHelper class to validate URL
using System.Text.RegularExpressions;
using Umbraco.Extensions;
namespace Concept.Core.Helpers
{
public static class UrlHelper
{
private const string URL_SCHEME_PATTERN = @"^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$";
private const string URL_RELATIVE_PATTERN = @"^\/([\w-]+.)+[\w-]+(\/[\w- ])?\S$";
@smdooley
smdooley / BlockListNotification.cs
Last active January 11, 2023 12:53
Using Umbraco notifications with a Block List Editor
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models.Blocks;
using Umbraco.Cms.Core.Notifications;
namespace Concept.Core.NotificationHandlers
{
public class ContentPublishing : INotificationHandler<ContentPublishingNotification>
{
public void Handle(ContentPublishingNotification notification)
{
@smdooley
smdooley / UmbracoHtmlHelperExtensions.cs
Created January 11, 2023 10:52
Umbraco related HTML helper extension methods
using System.Text;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Umbraco.Cms.Core.Models;
using Umbraco.Extensions;
namespace Concept.Core.Extensions
{
public static class HtmlHelperExtensions
@smdooley
smdooley / TableMarkupHelper.cs
Last active January 11, 2023 10:55
Helper class to dynamically update table HTML markup
using HtmlAgilityPack;
namespace Concept.Core.Helpers
{
public static class TableMarkupHelper
{
public static ApplyHtmlStyleGuidelines(string text)
{
HtmlDocument htmlDocument = new HtmlDocument();
htmlDocument.LoadHtml(text);
// https://github.com/photonstorm/phaser3-examples/blob/master/public/src/game%20objects/graphics/health%20bars%20demo.js
import Phaser from "phaser";
export default class HealthBar extends Phaser.GameObjects.Container {
constructor(scene, x, y) {
super(scene, x, y);
this.bar = new Phaser.GameObjects.Graphics(scene);
@smdooley
smdooley / jquery.ua-events.js
Created May 16, 2022 09:03
Google Analytics events for all a tags
jQuery(document).ready(function ($) {
var filetypes = /\.(zip|exe|pdf|doc*|xls*|ppt*|mp3)$/i;
var baseHref = '';
if (jQuery('base').attr('href') != undefined) {
baseHref = jQuery('base').attr('href');
$('a').each(function() {
var href = $(this).attr('href');
if (href && (href.match(/^https?\:/i)) && (!href.match(document.domain))) {
$(this).click(function() {
var extLink = href.replace(/^https?\:\/\//i, '');