Skip to content

Instantly share code, notes, and snippets.

@derralf
derralf / gist:f93545f76d8eb96f2bd0
Created March 5, 2015 13:21
Silverstripe Magic Links: Make sure "http://" exists at the start of the URL, if it doesn't have http:// or https://
public function onBeforeWrite() {
// Magic Links: Make sure "http://" exists at the start of the URL, if it doesn't have http:// or https://
// replace "$this->ExternaLink" for your needs
if ($link = $this->ExternalLink) {
$this->ExternalLink = (substr($link, 0, 7) == 'http://' || substr($link, 0, 8) == 'https://') ? $link : 'http://' . $link;
}
parent::onBeforeWrite();
@derralf
derralf / HTML5Modernizr für ältere Typo3 Versionen
Created March 13, 2012 09:40
HTML5 <html>'s conditional classes (see Html5 Boilerplate) with modernizr for older Typo3 Versions
config.xmlprologue = none
# HTML5 f. css3pie benötigt - hatte bei box-shadow (ältere IE? nicht sicher...) z.T. Abstand zwischen Schatten und Objekt
config.doctype (
<!doctype html>
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!-- Consider adding an manifest.appcache: h5bp.com/d/Offline -->
<!--[if gt IE 8]><!-->
@derralf
derralf / translated untranslated DataObjects
Created March 13, 2012 18:25
Silverstripe - translated untranslated DataObjects
SomeClass.php
class SomeClass extends DataObject {
static $db = array (
'Title_de_DE' => 'Text',
'Title_en_US' => 'Text'
);
...
...
// return Title (or other field) for current locale
@derralf
derralf / ObfuscateEmailExtension.php
Created May 11, 2016 09:23
Silverstripe simple E-Mail Obfuscation
<?php
/**
* Add E-Mail Obfuscation to Dataobjects (and thus also for Pages).
* Activate:
* save this file to mysite/code or mysite/extensions
* and:
* in _config.php: DataObject::add_extension('DataObject', 'ObfuscateEmailExtension');
* or in config.yml: DataObject: extensions: - ObfuscateEmailExtension
@derralf
derralf / mysite.yml
Last active August 9, 2018 12:08
silverstripe config yml: override array/map instead of merging
Different YAML maps/arrays for the same obeject/element are usually merged.
In the below example the value "5px" would usually be merged with the first defined map.
if you want to override maps/array you can first reset it by setting it to null.
Verschiedene YAML-Maps/Arrays für das gleiche Objekt/Element werden in der Regel zusammengeführt.
Im folgenden Beispiel wird der Wert "5px" normalerweise mit der ersten definierten Map zusammengeführt.
Wenn man Map/Array überschreiben will, kann man es zunächst zurücksetzen, indem man es auf Null setzt.
#### /vendor/My/Extension/_config/config.yml
@derralf
derralf / BootstrapLinkingModeExtension.php
Last active January 24, 2019 09:23
Silverstripe - BootstrapLinkingMode: Add "active" class to LinkingMode for Bootstrap Menus
<?php
namespace App\Extension;
use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\DataExtension;
/**
* Simple class to add "active" class to $LinkingMode (does not replace `current` class) for Bootstrap Menus
@derralf
derralf / BBEdit-TextWrangler-grep.txt
Last active February 26, 2019 09:06
BBEdit und Textwrangler Text ersetzen
ersetze erste 5 Zeichen je Zeile (grep)
finde: ^.....
ersetze durch:
entferne leere Zeilen (grep)
finde: \r+
ersetze durch: \r
entferne komplette Zeile mit einem bestimmten Zeichen (hier ") (grep)
finde: .*".*
@derralf
derralf / elementalownsreset.yml
Created July 3, 2019 10:42
silverstripe-elemental: break cascading publishing / owns
# ==================================================================================
# Do not automatically publish all the individual elements when publishing the page
# Allow published and unpublished items on a page
#
# see:
# Disable Cascade-publishing of Element in ElementalArea
# https://github.com/dnadesign/silverstripe-elemental/issues/681
# or:
# QUESTION - On Page save&publish, it publishes all elements...
# https://github.com/dnadesign/silverstripe-elemental/issues/205
@derralf
derralf / _config_TinyMCEConfig.php
Last active January 21, 2020 15:55
TinyMCEConfig / HtmlEditorConfig > style_formats (Silverstripe 4)
<?php
// place this in /app/config.php
use SilverStripe\Forms\HTMLEditor\TinyMCEConfig;
@derralf
derralf / Spotlight Mojave index Markdown.md
Created May 5, 2020 15:09
Unter macOS 10.14 Mojave Spotlight das indizieren von Markdown-Dateien (.md) beibringen

Spotlight Mojave index Markdown

Unter macOS 10.14 Mojave Spotlight das indizieren von Markdown-Dateien (.md) beibringen.

# kopiere RichText.mdimporter
cp -r /System/Library/Spotlight/RichText.mdimporter ~/

# benenne um in Markdown.mdimporter
mv ~/RichText.mdimporter Markdown.mdimporter