Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / Composer auf Hetzner Shared Hosting Level 19
Last active November 23, 2023 10:32
Composer auf Hetzner Shared Hosting Level 19
mkdir ~/bin
mkdir ~/bin/composer
cd ~/bin/composer
wget https://getcomposer.org/composer.phar
echo "# composer alias" >> ~/.bashrc
echo "alias composer='php -d allow_url_fopen=on ~/bin/composer/composer.phar'" >> ~/.bashrc
echo "alias php='/usr/bin/php56'" >> ~/.bashrc
source ~/.bashrc
composer -h
@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 / 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 / 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 / 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]><!-->