Skip to content

Instantly share code, notes, and snippets.

View wernerkrauss's full-sized avatar

Werner Krauß wernerkrauss

View GitHub Profile
@wernerkrauss
wernerkrauss / DomPDFHelper.php
Created April 15, 2021 06:43
Silversttripe DOMPDF Image helper
<?php
namespace Netwerkstatt\Helper;
use SilverStripe\View\TemplateGlobalProvider;
class DomPDFHelper implements TemplateGlobalProvider
{
/**
* @return array
@wernerkrauss
wernerkrauss / BlogNews.php
Last active February 25, 2020 06:46
Migration from firesphere's news module (SilverStripe 3) to Silverstripe 4 and Blog module
<?php
namespace Netwerkstatt\NewsToBlogMigration\Extension;
use SilverStripe\ORM\DataExtension;
/**
* Class BlogNews
* @package Netwerkstatt\NewsToBlogMigration\Extension
@wernerkrauss
wernerkrauss / CleanupContent.php
Last active March 20, 2018 13:30
Method to cleanup SilverStripe $Content from old installations on-the-fly using HTMLPurifyer
<?php
/**
* cleans up $Content using HTMLPurifyer
*
* @return \SilverStripe\ORM\FieldType\DBHTMLText
*/
public function getContent()
{
$content = $this->dbObject('Content');
<?php
/**
* Class NetwerkstattDataObjectCMSPermissionExtension
*
* @property ImageGalleryAlbum|ImageGalleryItem|BookingDotComAccommodation|HomePageCategory|HomePageElement|Tag|Webcam|TomasFeatureGroup|TomasService|TomasServiceGroup|TomasServiceProvider|NetwerkstattDataObjectCMSPermissionExtension $owner
*/
class NetwerkstattDataObjectCMSPermissionExtension extends DataExtension implements PermissionProvider
{
@wernerkrauss
wernerkrauss / inline-svg-function.scss
Last active January 17, 2018 17:52 — forked from JacobDB/inline-svg-function.scss
Inline SVG function [SASS]
// Replace letters
@function str-replace($string, $search, $replace: '') {
$index: str-index($string, $search);
@if $index {
@return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
}
@return $string;
}
@wernerkrauss
wernerkrauss / MySortableAdmin.php
Created May 3, 2017 07:43
a ModelAdmin with sortable gridfield (if the managed model has a field "SortOrder")
<?php
class MySortableAdmin extends ModelAdmin
{
private static $managed_models = [
'MySortableDataObject'
];
private static $url_segment = "sorable-demo";
private static $menu_title = "Sort stuff";
@wernerkrauss
wernerkrauss / gist:8ef7b7e576a23458151c6cfffb920129
Created December 6, 2016 10:02
SilverStripe Fluent Problem (Row size too large)
private static $create_table_options = array(
'MySQLDatabase' => 'ENGINE=InnoDB ROW_FORMAT=COMPRESSED'
);
@wernerkrauss
wernerkrauss / _config.php
Created November 30, 2016 13:31
redirect to main domain (e.g. from domain.com.host.com to domain.com)
if (Director::isLive()) {
$hostname = gethostname();
$http_host = $_SERVER['HTTP_HOST'];
if (strpos($http_host, $hostname) !== false) {
//redirect to original domain
$destURL = str_replace('.' . $hostname, '', $http_host);
$response = new SS_HTTPResponse();
@wernerkrauss
wernerkrauss / ss3-php7.patch
Created October 27, 2016 10:51
Silverstripe 3.2 PHP7 Patch
From 6d2a7ac089e1412cf6444fcff575c8780e93a6f9 Mon Sep 17 00:00:00 2001
From: Mark Guinn <mark@adaircreative.com>
Date: Tue, 15 Mar 2016 09:58:44 +0000
Subject: [PATCH 1/3] Applied 327/migrate
---
core/Diff.php | 21 +-
model/connect/DBSchemaManager.php | 4 +-
model/fieldtypes/Double.php | 2 +-
model/fieldtypes/Float.php | 2 +-
@wernerkrauss
wernerkrauss / SilverstripeDataObject.php
Last active May 25, 2016 06:34
Some PHPStorm / Intellij IDEA file templates for SilverStripe development
<?php
#parse("PHP File Header.php")
class ${NAME} extends DataObject {
private static \$db = array();
private static \$has_one = array();
private static \$has_many = array();