Skip to content

Instantly share code, notes, and snippets.

View wilr's full-sized avatar

Will Rossiter wilr

View GitHub Profile
@wilr
wilr / export.sql
Created February 8, 2011 02:12
Generates a list of all the suburbs and regions (with lat/lngs in NZ). Uses a timeout interval to prevent issues with the google geocoder. If you're too lazy to wait for that script to run, the SQL is attached below. I accept no responsibility for the acc
# ************************************************************
# Sequel Pro SQL dump
# Version 3348
#
# http://www.sequelpro.com/
# http://code.google.com/p/sequel-pro/
#
# Host: localhost (MySQL 5.1.54)
# Generation Time: 2011-07-10 19:08:36 +1200
# ************************************************************
@wilr
wilr / composer-script.php
Last active November 14, 2022 07:46
Auto PHP Linting
<?php
// This script will copy a pre-commit hook from this repo to a developers local git
// The pre-commit hook will be run whenever a developer runs "git commit"
// This script will run after running composer install, via the "post-install-cmd" in composer.json
//
$gitHookFilename = '.git/hooks/pre-commit';
$shellHookFilename = 'pre-commit.sh';
if (file_exists($gitHookFilename)) {
unlink($gitHookFilename);
@wilr
wilr / event.tracking.js
Created August 26, 2011 03:54
Simple jQuery Helper for wrapping GA event tracking
(function($) {
/*
A simple helper plugin for wrapping Google Analytic event tracking
into sites through jQuery and HTML5 data attributes.
This assumes that you have used the standard configuration provided
by google for setting up Google Analytics and used the _gaq var for
storing the tracker.
Can track focus, activate, hover and click input methods but not key
@wilr
wilr / SubsiteAwareRedirectExtension.php
Created September 14, 2022 07:27
A Silverstripe DataExtension which adds subsite support to the redirectedurls module.
<?php
use SilverStripe\Forms\FieldList;
use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\DataQuery;
use SilverStripe\ORM\Queries\SQLSelect;
use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Subsites\State\SubsiteState;
class SubsiteAwareRedirectExtension extends DataExtension
@wilr
wilr / Project.php
Created December 7, 2021 21:23
Example of how to do searchable_fields with a many_many relation
<?php
use SilverStripe\ORM\DataObject;
use SilverStripe\Forms\DropdownField;
use SilverStripe\ORM\Filters\ExactMatchFilter;
class Project extends DataObject
{
private static $db = [
'Title' => 'Varchar(200)',
@wilr
wilr / GridFieldPrintLicencesButton.php
Last active December 7, 2020 22:46
GridField action button (for the whole list)
<?php
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Extensible;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\Security\Security;
@wilr
wilr / GridFieldRestrictedRiderAction.php
Created December 7, 2020 22:43
Custom GridField row action example
<?php
use SilverStripe\Control\Controller;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\ValidationException;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridField_FormAction;
use SilverStripe\Forms\GridField\GridField_ColumnProvider;
use SilverStripe\Forms\GridField\GridField_ActionProvider;
use SilverStripe\Forms\GridField\GridField_ActionMenuItem;
@wilr
wilr / PostmarkMailTransport.php
Last active August 3, 2020 03:34
Postmark Mailing in Silverstripe 4.5
<?php
use Psr\Log\LoggerInterface;
use SilverStripe\Control\Email\Email;
use SilverStripe\Control\Director;
use SilverStripe\Core\Environment;
use SilverStripe\Core\Injector\Injector;
class PostmarkMailTransport extends \Postmark\Transport
{
@wilr
wilr / SecureControllerExtension.php
Last active February 10, 2020 23:08
Secure Silverstripe Controller Extension
<?php
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTP;
use SilverStripe\Security\Member;
use SilverStripe\Core\Extension;
/**
* Implements Content-Security-Policy and other security headers on the
* controllers.
@wilr
wilr / CustomIndex.diff
Created May 14, 2019 22:06
solr-issues-silverstripe
--- a/app/src/Search/CustomerSolrIndex.php
+++ b/app/src/Search/CustomerSolrIndex.php
@@ -9,10 +9,14 @@ use SilverStripe\Control\Director;
*/
class CustomerSolrIndex extends GazetteSolrIndex
{
+ private static $casting = [
+ 'FieldDefinitions' => 'HTMLFragment',
+ 'CopyFieldDefinitions' => 'HTMLFragment'
+ ];