Skip to content

Instantly share code, notes, and snippets.

Avatar

Jon Leverrier jonleverrier

View GitHub Profile
@jonleverrier
jonleverrier / module.php
Last active Apr 30, 2020
A way of setting the Content Security Policy header in Craft CMS
View module.php
<?php
// https://jonleverrier.com/notes/weeknote-2
// - If the request is not from the control panel
// - If the request is not from the console
// - If a user is not logged in (for debug toolbar in the front-end)
if (
!Craft::$app->request->isCpRequest &&
!Craft::$app->request->isConsoleRequest &&
!Craft::$app->getUser()->getIdentity()
)
@jonleverrier
jonleverrier / sitemap.twig
Last active Jan 27, 2019
Craft CMS 3 XML Sitemap Example
View sitemap.twig
{#
Craft CMS 3 Sitemap Example
This sitemap example presumes you have some custom fields setup. These are:
- contentShowInSitemap
- contentSitemapChangeFreq
- contentSitemapPriority
#}
{#
Sitemap Configuration
@jonleverrier
jonleverrier / gulpfile.js
Created Dec 14, 2018
Gulp 4 Configuration File
View gulpfile.js
// Alphasite Build Tool
// Verion: 2.0
// Author: jon@youandme.digital
//
// Built and tested on:
// - Node: v.10.14.1
// - NPM: v.6.4.1
// - Gulp: v.4.0
// load required npm plugins (from a-z)
@jonleverrier
jonleverrier / getAsset.snippet.php
Last active Dec 14, 2018
This MODX snippet retrieves CSS and JS files from your local file system, which is handy when you are adding a revision suffix to your build files.
View getAsset.snippet.php
<?php
/**
* getAsset
* v.0.0.2
*
* This snippet retrieves CSS and JS files from your local file system,
* which is handy when you are adding a revision suffix to your build files.
* For example: 's.min.cdbbec54.js' or 'c.min.543e2b40.css'.
*
* The script attempts to serve and look for the latest file in
@jonleverrier
jonleverrier / criticalCSS.snippet.php
Last active Dec 14, 2018
Critical CSS snippet for MODX
View criticalCSS.snippet.php
<?php
/**
* Critical CSS
* v.0.0.3
*
* This snippet helps you manage and serve your critical CSS in MODX.
* It does not generate critical CSS (ccss) for you.
*
* Why use ccss when we have http/2?
* Serving ccss when using http/2 still optimises First Contentful Paint,
@jonleverrier
jonleverrier / welcomeMessage.plugin.php
Last active Dec 12, 2018 — forked from rtripault/plugin.php
Sample plugin to display the welcome screen to any new member login for the first time in MODX Revolution manager
View welcomeMessage.plugin.php
<?php
/**
* A sample plugin to display the "welcome message" to all users, login for the first time in Revo manager
*
* @var modX $modx
* @var array $scriptProperties
* @var modPlugin $this
*
* @see modPlugin::process()
*
@jonleverrier
jonleverrier / logOutput.snippet.php
Last active Dec 12, 2018
Log the output of a placeholder or snippet to the MODX error log. Useful for checking what a placeholder actually outputs...
View logOutput.snippet.php
<?php
/*
logOutput snippet for MODX
Use like this:
[[!logOutput? &input=`[[+placeholder]]`]] or
*/
if (empty($input)) {
@jonleverrier
jonleverrier / getFormSteps.snippet.php
Last active Dec 12, 2018
getFormSteps for the MODX Formalicious form builder by Sterc. This utility snippet displays all the step titles for a given form ID.
View getFormSteps.snippet.php
<?php
/**
* getFromSteps v.1.0
* An unoffical utility snippet for Formalicious by Sterc
*
* This utility snippet outputs all the steps for a multistep form
* based on a given form ID
*
* Usage:
* Put the snippet in your &stepTpl and call the snippet like this:
@jonleverrier
jonleverrier / pdfcrowd.plugin.php
Last active Dec 12, 2018
PDF Crowd MODX Plugin. Using the API from PDF Crowd, this plugin will convert a MODX resource in to PDF format and then save it to your web server in a specified location.
View pdfcrowd.plugin.php
<?php
/**
* PDF Crowd MODX Plugin
*
* Using the API from PDF Crowd, this plugin will convert a MODX resource in to
* PDF format and then save it to your web server in a specified location.
*
* The plugin is setup to trigger witin a certain MODX context.
* For example, a "pdf" context.
*
@jonleverrier
jonleverrier / getImgSizeFromUrl.snippet.php
Last active Dec 12, 2018
getImgSizeFromUrl snippet for MODX. Retrieves the height and width of an image from a remote url.
View getImgSizeFromUrl.snippet.php
<?php
/**
* getImgSizeFromUrl snippet for MODX
* Retrieves the height and width of an image from a remote url
*
* example usage: [[!getImgSizeFromUrl? &url='https://path/to/myimg.jpg' &tpl=`myTpl`]]
* placeholders to use in the myTpl chunk are [[+height]]] and [[+width]]
*
* @author Jon Leverrier (jon@youandmedigital.com)
* @version 1.0
You can’t perform that action at this time.