Skip to content

Instantly share code, notes, and snippets.

<?php
namespace modules;
use Craft;
use craft\controllers\EntriesController;
use craft\controllers\UsersController;
use yii\base\ActionEvent;
use yii\base\Event;
use yii\base\Module;
use yii\web\ForbiddenHttpException;
@croxton
croxton / .env.php
Last active March 20, 2019 19:23
Craft 3 live previews across different root (or sub) domains
<?php
// In general.php define an alias:
'aliases' => [
'@baseUrl' => getenv('CRAFTENV_BASE_URL')
],
// In the CP, set the Base URL for each site to @baseUrl/
// When previewing, the CP will therefore always use the hostname the editor logged into as the base url for the preview
// (that happens with 'new' entries anyway regardless of base url, but existing entries use base url).
@nfourtythree
nfourtythree / Password Protect Serverpilot App.md
Last active December 10, 2020 17:20
Password Protect Serverpilot App

How to password protect your Serverpilot app

This is a quick (rough) guide on how to protect a Serverpilot pilot app with auth basic

1. SSH into your Serverpilot Server

2. Create a htpasswd file in your app

@nfourtythree
nfourtythree / How To Disable Strict SQL Mode in MySQL 5.7.MD
Last active April 29, 2021 09:45
Serverpilot - Disable Strict SQL Mode in MySQL 5.7

How To Disable Strict SQL Mode in MySQL 5.7

I wrote a quick script for those that provision servers often enough.

To get this to work take the following steps

  1. Log into your server as root
  2. Get script wget https://gist.githubusercontent.com/nfourtythree/90fb8ef5eeafdf478f522720314c60bd/raw/disable-strict-mode.sh
  3. Make is executable chmod +x disable-strict-mode.sh
  4. Run the script ./disable-strict-mode.sh
@khalwat
khalwat / crontab_helper
Last active April 20, 2018 23:39
Never struggle with editing your crontab again; put this in the beginning of each of your crontabs
This is now part of craft-scripts:
https://github.com/nystudio107/craft-scripts
@joshangell
joshangell / MyPluginController.php
Last active February 1, 2016 14:07
Content migration in Craft example.
<?php
namespace Craft;
class MyPluginController extends BaseController
{
// This lets anyone run the controller actions we specify, useful for CRON etc
protected $allowAnonymous = array('actionMigrate');
/**
@andrewfairlie
andrewfairlie / goodfeedback.md
Last active November 9, 2015 14:03
Good Feedback
<?php
# Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
# http://creativecommons.org/publicdomain/zero/1.0/
function postToMedium($data=array()) {
$user_id = "XXXX";
$accessToken = "XXXX";
public function modifyEntrySources(&$sources, $context)
{
if ($context === 'index') {
foreach ($sources as &$source) {
if (!isset($source['label'])) {
continue;
}
$total = craft()->elements->getTotalElements($source['criteria']);
$source['label'] .= ' ('. $total .')';
}