Skip to content

Instantly share code, notes, and snippets.

View jonom's full-sized avatar

Jono Menz jonom

View GitHub Profile
@jonom
jonom / PageController.php
Last active May 21, 2024 06:59
Silverstripe partial caching methods
<?php
use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\Control\Director;
use SilverStripe\Core\Environment;
/**
* Below are some methods that can be added to PageController for use in partial caching blocks.
* Example: <% cached $EnvCacheKey, $ClassCacheKey('SilverStripe\CMS\Model\SiteTree') unless $DontCache %>
*/
@jonom
jonom / UniqueURLSegmentExtension.php
Created January 30, 2020 19:23
Unique URL Segment extension
<?php
class UniqueURLSegmentExtension extends DataExtension
{
private static $db = array(
'URLSegment' => 'Varchar(255)',
);
public function onBeforeWrite()
{
@jonom
jonom / DownloadCloudwaysLocalBackups.sh
Created October 4, 2019 03:30
CloudWays - bash script to download local backups for all applications on a server
#!/bin/bash
# CloudWays - Download local backups for all applications
# =======================================================
# * Local backups must be enabled and available. See https://support.cloudways.com/how-to-download-a-full-backup/
# * Add your machine's SSH key to your server so this script needs no input.
# * Backups will be saved inside a new folder with today's date within your nominated backup directory. (This might not be the date the backup was taken.)
# * Only tested on Digital Ocean VPS so far.
# Configuration
@jonom
jonom / ss-bookmarklets.html
Created October 14, 2016 18:39
SilverStripe developer bookmarklets
<h3>Drag these links in to a folder on your bookmarks bar for easy access</h3>
<p>
<a href="javascript:void(function(){popDestination = (baseTag = document.getElementsByTagName('base')[0]) ? baseTag.getAttribute('href') + 'dev/' : window.location.protocol + '//' + window.location.host + '/dev/'; window.open(popDestination);})();">
SS:Dev</a><br />
<a href="javascript:void(function(){popDestination = (baseTag = document.getElementsByTagName('base')[0]) ? baseTag.getAttribute('href') + 'dev/build/?flush=all' : window.location.protocol + '//' + window.location.host + '/dev/build/?flush=all'; window.open(popDestination);})();">
SS:Build</a><br />
<a href="javascript:void(function(){popDestination = (baseTag = document.getElementsByTagName('base')[0]) ? baseTag.getAttribute('href') + 'admin/' : window.location.protocol + '//' + window.location.host + '/admin/'; window.open(popDestination);})();">
SS:CMS</a><br />
<a href="javascript:window.location.search = 'flush=all'">
SS:Flush</a><br />
@jonom
jonom / TextRaw2P.php
Last active December 10, 2015 20:38
SilverStripe TextRaw2P extension. Converts raw text to html and replaces double line breaks with paragraphs.
<?php
/**
* TextRaw2P class.
* Apply this extension to the Text class to access $YourText.Raw2P in templates.
*
*/
class TextRaw2P extends DataExtension {
private static $casting = array(
@jonom
jonom / HelloPage.php
Last active August 29, 2015 14:23
SilverStripe code competition entry
<?php
/**
* Hello Page.
* Landing page for users when they log in to the website
* @author jonom
*/
class HelloPage_controller extends Page_controller {
/**
* Restrict access to logged in users at a minimum
@jonom
jonom / MaxWidthHeightImageExtension.php
Last active August 29, 2015 14:21
SilverStripe crop image to maximum width or height
<?php
class MaxWidthHeightImageExtension extends DataExtension {
/**
* Crop an image if it exceeds a certain height.
* Use in templates e.g. $Image.SetWidth(200).MaxHeight(200)
*
* @param integer $maxHeight Max height of image
* @return Image
@jonom
jonom / BalancedImageExtension.php
Created May 19, 2015 17:18
SilverStripe Balanced Image
<?php
class BalancedImageExtension extends DataExtension {
/**
* Creates a scaled image that fits within a given container and does not exceed a specified area (square space).
* Useful for ensuring a series of images of various dimensions (especially logos) have approximately the same visual weight.
* Use in templates with $BalancedImage
*
* @param integer $containerWidth Max width of image