Skip to content

Instantly share code, notes, and snippets.

View wernerkrauss's full-sized avatar

Werner Krauß wernerkrauss

View GitHub Profile
@wernerkrauss
wernerkrauss / DataObjectSummaryExtension.php
Last active December 20, 2015 12:29
Decorator for DataObject for retrieving $summary_fields in templates.
<?php
/**
* Class DataObjectSummaryExtension
* @author Werner Krauß <[email protected]>
*/
class DataObjectSummaryExtension extends DataExtension {
/**
@wernerkrauss
wernerkrauss / user.xml
Created August 23, 2013 14:53
PHPStorm Livetemplate for surrounding a text inside Silverstripe templates with <%t 'mytext' %>
<?xml version="1.0" encoding="UTF-8"?>
<templateSet group="user">
<template name="t" value="&lt;%t $filename$.$code$ '$SELECTION$' %&gt;" description="surrounds the current selection with translation tag" toReformat="true" toShortenFQNames="true">
<variable name="filename" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="code" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="SELECTION" expression="" defaultValue="" alwaysStopAt="false" />
<context>
<option name="HTML_TEXT" value="true" />
<option name="HTML" value="false" />
<option name="XSL_TEXT" value="false" />
jQuery(function($) {
$('form[data-async]').on('submit', function(event) {
var $form = $(this);
var $target = $($form.attr('data-target'));
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize(),
@wernerkrauss
wernerkrauss / gist:6540191
Created September 12, 2013 16:17
Silverstripe: open RedirectorPage's external link in a new tab or window
<a href="$Link"<% if $RedirectionType == 'External' %>target="_blank"<% end_if %>>$MenuTitle.XML</a>
@wernerkrauss
wernerkrauss / Page.php
Created September 10, 2014 19:04
CDN rewrite in Page_Controller
<?php
class Page_Controller extends ContentController
{
private static $cdn_domain = 'cdn.mysite.com';
private static $cdn_rewrite = false;
public function handleRequest(SS_HTTPRequest $request, DataModel $model = null)
{
@wernerkrauss
wernerkrauss / post-merge
Last active April 18, 2016 10:08
git post-merge hook for silverstripe installs.
#!/bin/bash
echo "running git post receive hook..."
DIR=$(git rev-parse --show-toplevel)
composer.phar install --no-dev -o
echo "running dev/build"
sudo -u www-data php $DIR/framework/cli-script.php dev/build flush=1
@wernerkrauss
wernerkrauss / MyDataObject.php
Last active August 29, 2015 14:10
Permission check for a DataObject.
class MyDataObject extends DataObject implements PermissionProvider {
/**
...
*/
/**
* Return a map of permission codes to add to the dropdown shown in the Security section of the CMS.
* array(
* 'VIEW_SITE' => 'View the site',
* );
*/
@wernerkrauss
wernerkrauss / GalleryPic.php
Created December 3, 2014 11:58
PageGallery extension
<?php
/**
* Class GalleryPic
* @todo: sync Copyright if Image has a db field for it
*/
class GalleryPic extends DataObject
{
private static $db = array(
'Title' => 'Text',
@wernerkrauss
wernerkrauss / GalleryPic.php
Created June 4, 2015 14:15
Silverstripe GalleryPic Dataobject with Shortcodable interface
<?php
/**
* Class GalleryPic
* @todo: sync Copyright if Image has a db field for it
*/
class GalleryPic extends DataObject implements Shortcodable
{
private static $db = array(
'Title' => 'Text',
@wernerkrauss
wernerkrauss / gist:f72f1214ce27e3acba2a
Created June 17, 2015 13:58
sass / foundation snippet to get a responsive two column table.
.responsive-twocolumn-table {
width: 100%;
th {
display: none;
}
td {
width: 100%;
display: block;
&:first-child {
font-weight: bold;