Skip to content

Instantly share code, notes, and snippets.

@jonleverrier
jonleverrier / dropbox-php-auth.md
Created October 26, 2023 15:40 — forked from marcus-at-localhost/dropbox-php-auth.md
Dropbox API V2: PHP Authentication Process

Effective September 2021, Dropbox will be deprecating long-lived access tokens.

This GIST generally describes how to authenticate requests to Dropbox API v2, for anyone working on a server-side PHP Dropbox implementation.

It's important to understand three types of codes you'll encounter:

  1. Access Code - this is a one-time code that represents user-granted app access.
  2. Access Token - this is short-lived token that provides access to Dropbox API endpoints.
  3. Refresh Token - this is a long-lived token that allows you to fetch a fresh Access Token.
@jonleverrier
jonleverrier / gulpfile.js
Created December 14, 2018 14:13
Gulp 4 Configuration File
// 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 / module.php
Last active December 21, 2022 13:44
A way of setting the Content Security Policy header in Craft CMS
<?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 / cbContentEditor.php
Last active December 30, 2021 22:49
This MODX plugin hides certain Content Blocks buttons from a specific MODX user group. It also disables the drag and drop functionality, so that you can provide some users with a more locked down version of Content Blocks.
<?php
/**
* Content Blocks cbContentEditor Plugin
*
* This plugin hides certain CB buttons from certain MODX user groups
* and disables the drag and drop functionality, so that you can provide
* some clients with a more locked down version of CB.
*
* I would suggest setting up CB templates and defaults in the CB component manager,
* so that predefined layouts are loaded automatically when a new resource is created.
@jonleverrier
jonleverrier / sitemap.twig
Last active October 15, 2020 14:02
Craft CMS 3 XML Sitemap Example
{#
Craft CMS 3 Sitemap Example
This sitemap example presumes you have some custom fields setup. These are:
- contentShowInSitemap
- contentSitemapChangeFreq
- contentSitemapPriority
#}
{#
Sitemap Configuration
@jonleverrier
jonleverrier / criticalCSS.snippet.php
Last active December 14, 2018 14:04
Critical CSS snippet for MODX
<?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 / getAsset.snippet.php
Last active December 14, 2018 12:38
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.
<?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 / isAdmin.snippet.php
Last active December 12, 2018 17:21
isAdmin snippet for MODX. returns the value 1 if the user is an administrator
<?php
/**
* isAdmin snippet
* returns the value 1 if the user is an administrator
*
* example usage: [[!isAdmin:is=`1`:then=`i'm an admin`:else=`i'm just a content editor`]]
*
* @author Jon Leverrier (jon@youandmedigital.com)
* @version 1.0
* @since 10th December 2017
@jonleverrier
jonleverrier / isAnon.snippet.php
Last active December 12, 2018 17:21
isAnon snippet for MODx. Returns the value 1 if the user is anonymous (not logged into the manager)
<?php
/**
* isAnon snippet
* returns the value 1 if the user is anonymous (not logged into the manager)
*
* example usage: [[!isAnon:is=`1`:then=``:else=`i'm not logged in`]]
*
* @author Jon Leverrier (jon@youandmedigital.com)
* @version 1.0
* @since 10th December 2017
@jonleverrier
jonleverrier / getResourceThumbnails.snippet.php
Last active December 12, 2018 17:20
getResourceThumbnails snippet for MODX. Searches inside the tv_posttype field and pulls out the images for use in open graph tags. If the resource is a "default" resource, it will display the default Open Graph image from ClientConfig.
<?php
/**
* getResourceThumbnails snippet
* Searches inside the tv_posttype field, and pulls out images
* for use in Open Graph tags.
* If the resource is a default resource, it displays the default
* Open Graph image from ClientConfig
*
*
* @author Jon Leverrier (jon@youandmedigital.com)