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 / 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 / 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 / gulpfile.js
Created December 14, 2018 14:13
Gulp 4 Configuration File
// Alphasite Build Tool
// Verion: 2.0
// Author: [email protected]
//
// 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 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 / 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 / welcomeMessage.plugin.php
Last active December 12, 2018 17:17 — 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
<?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 December 12, 2018 17:16
Log the output of a placeholder or snippet to the MODX error log. Useful for checking what a placeholder actually outputs...
<?php
/*
logOutput snippet for MODX
Use like this:
[[!logOutput? &input=`[[+placeholder]]`]] or
*/
if (empty($input)) {
@jonleverrier
jonleverrier / getFormSteps.snippet.php
Last active December 12, 2018 17:18
getFormSteps for the MODX Formalicious form builder by Sterc. This utility snippet displays all the step titles for a given form ID.
<?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 December 12, 2018 17:19
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.
<?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.
*