Skip to content

Instantly share code, notes, and snippets.

@Megafry
Megafry / FormController.php
Created March 6, 2024 11:48
Formie import/export for console
<?php
namespace modules\ExtendFormie\console\controllers;
use Throwable;
use verbb\formie\helpers\ImportExportHelper;
use yii\console\Controller;
use yii\console\ExitCode;
use yii\helpers\Console;
@Megafry
Megafry / gist:8da833eb5ebd1e0b3be3dfa1554043af
Created October 26, 2021 13:47
Regex xml to xlf (TYPO3)
## Default (locallang.xml to locallang.xlf)
## search
<label index="(.*?)">(.*?)</label>
## replace
<trans-unit id="$1">\n\t<source>$2</source>\n</trans-unit>
## langauge (locallang.xml to de.locallang.xlf)
## search
<label index="(.*?)">(.*?)</label>
## replace
@Megafry
Megafry / G201.typoscript
Last active November 17, 2021 14:16
TYPO3: add warning text to all external links with regex
page.10.stdWrap.replacement {
10 {
search = #(<a.*?target="_blank".*?>)(.*?)(</a>)#i
replace {
wrap2 = ${1}${2} |${3}
noTrimWrap = |<span class="show-for-sr"> |</span>|
data = LLL:EXT:...locallang.xlf:link_open_in_new_windows
}
useRegExp = 1
}
@Megafry
Megafry / setClassRand.js
Created October 20, 2020 09:50
Adds the given class to 1 element from the selection and return it:
// extend jQuery:
$.fn.setClassRand = function(cssClass) {
return this.eq( Math.floor( Math.random() * this.length ) ).addClass(cssClass);
};
//usage:
//add the class "teaser__video--active" and play it:
var video = $(".teaser__video").setClassRand("teaser__video--active");
if (video.length) {
video[0].play();
@Megafry
Megafry / parseFunc.typoscript
Created September 23, 2020 11:29
TypoScript to extend TYPO3 lib.parseFunc by adding the file-extention as data attribute without userFunc.
lib.parseFunc {
tags.a.typolink {
ATagParams.stdWrap.cObject = FILES
ATagParams.stdWrap.cObject {
stdWrap.if {
isPositive.data = parameters:href
isPositive.stdWrap.replacement {
10 {
search = t3://file?uid=
replace =
@Megafry
Megafry / parseFunc.typoscript
Last active November 5, 2020 13:46
TypoScript to extend TYPO3 parseFunc, adding the file-extention and size to all link
lib.parseFunc {
tags.a.typolink {
#add text in the A-Tag
ATagBeforeWrap = 1
wrap.cObject = FILES
wrap.cObject {
#get file ID
files.stdWrap {
data = parameters:href
stdWrap.replacement {
@Megafry
Megafry / .htaccess
Created May 14, 2020 08:38
Favicon redirect
RewriteEngine On
RewriteCond %{HTTP_HOST} webpage2\.com$ [NC]
RewriteRule ^favicon\.ico$ /webpage2_favicon.ico [L,NC]
@Megafry
Megafry / FizzBuzz.js
Last active March 21, 2020 11:32
FizzBuzz challenge
const numberOfLoops = 100
const numbersToReplace = [ [3,'Fizz'], [5,'Buzz'] ]
for(i=1;i<=numberOfLoops;i++){
r = numbersToReplace.filter( replacement => !(i % replacement[0]))
console.log( r.length ? r.map(result => result[1]).join('') : i )
}
@Megafry
Megafry / cmd.php
Created October 11, 2018 10:21
cmd.php
<html lang="de">
<head>
<meta charset="utf-8">
<title>cmd box by Megafry</title>
<style>
body {
background-color: rgba(0, 0, 0, 0.5);
color: #fff;
}
* {
@Megafry
Megafry / sys_file_reference.php
Created June 2, 2017 07:56
TYPO3 7.X overwrit default crop aspect ratio's for sys_file_reference
<?php
defined('TYPO3_MODE') or die();
$GLOBALS['TCA']['sys_file_reference']['columns']['crop']['config']['ratios'] = array(
'1.7777777777777777' => '16:9',
'1.3333333333333333' => '4:3',
'1' => '1:1',
'2.380952381' => 'Slider',
'1.66666666666666666' => 'Slider Mobile',
'NaN' => 'Free',