Hauptmenü

Werkzeuge

Kategorien

Archiv

Gutenberg Block über die BlockID/PostID finden

Erstellt in Allgemein am 3. April 2021 vom Daschmi

Mit folgender Funktion habe ich sensible Einstellungen aus einem Gutenberg Block ausgelesen, ohne diese über das Frontend übertragen zu müssen.

/**
 * Sucht einen Block anhand der blockId
 *
 * @param array $arBlocks
 * @param string $block_id
 *
 * @return false|array
 */
$search_block = function(array $arBlocks, string $block_id) use (&$search_block) {

    foreach ($arBlocks as $block) {

        if (($block['attrs']['blockId']??'') === $block_id) {

            return $block;

        }

        $sub = $search_block(($block['innerBlocks']??[]), $block_id);

        if ($sub !== false) return $sub;

    }

    return false;

};

$post = get_post($post_id);
$arBlocks = parse_blocks($post->post_content);

$block = $search_block($arBlocks, $blockId);

OpenStreetmap Karte mit OpenLayer ohne Zoom mit dem Scrollrad

Erstellt in Allgemein am 3. Februar 2021 vom Daschmi

Wenn man eine Karte von OpenStreetmap mit OpenLayer integriert, kann das Zoomen mit dem Mausrad stören. Abhilfe schafft eine Option brei den interactions:

interactions: ol.interaction.defaults( { mouseWheelZoom:false } 

Beispiel:

let map = new ol.Map({
    layers: [
        new ol.layer.Tile({
            source: new ol.source.OSM()
        }),
        new ol.layer.Vector({

        })
    ],
    view: new ol.View({
        center: ol.proj.fromLonLat([long, lat]),
        zoom: 16
    }),
    interactions: ol.interaction.defaults( { mouseWheelZoom:false } ),
    target: 'm1_map'
});

TextWithRotation und tFPDF / UTF8

Erstellt in Allgemein am 14. Januar 2021 vom Daschmi

Nutzt man die Erweiterung von FPDF für TextRotation (http://www.fpdf.org/en/script/script2.php) funktioniert diese nicht direkt mit tFPDF (http://www.fpdf.org/en/script/script92.php) und UTF8 Fonts. Folgende kleine Anpassung in der Funktion TextWithRotation löst das Problem:

function TextWithRotationUTF($x, $y, $txt, $txt_angle, $font_angle = 0) {

    $font_angle += 90 + $txt_angle;
    $txt_angle *= M_PI / 180;
    $font_angle *= M_PI / 180;

    $txt_dx = cos($txt_angle);
    $txt_dy = sin($txt_angle);
    $font_dx = cos($font_angle);
    $font_dy = sin($font_angle);

    if ($this->unifontSubset) {

        $txt2 = '('.$this->_escape($this->UTF8ToUTF16BE($txt, false)).')';
        foreach ($this->UTF8StringToArray($txt) as $uni)
        $this->CurrentFont['subset'][$uni] = $uni;

    } else {

        $txt2 = '('.$this->_escape($txt).')';

    }

    $s = sprintf('BT %.2f %.2f %.2f %.2f %.2f %.2f Tm %s Tj ET',
            $txt_dx, $txt_dy, $font_dx, $font_dy,
            $x*$this->k, ($this->h-$y)*$this->k, $txt2);

    if ($this->ColorFlag) $s = 'q '.$this->TextColor.' '.$s.' Q';

    $this->_out($s);

}

SCSS Mixin Helper für IE11 Flex Gap Support

Erstellt in Stylesheet CSS/SCSS am 11. Dezember 2020 vom Daschmi

Wer das Property gap für Flex Elemente nutzt (oder genutzt hat) und den Internet Explorer 11 noch unterstützen muss, kann mit folgenden SCSS Mixins einfach das gleiche Verhalten erzeugen.

@mixin ie11gapfixrow($gap) {
  & > * { margin-right:#{$gap}; &:last-child { margin-right:0; } }
}
@mixin ie11gapfixcolumn($gap) {
  & > * { margin-bottom:#{$gap}; &:last-child { margin-bottom:0; } }
}

Angewendet wird es dann einfach innrehalb SCSS Anweisungen

#catnav { display:flex; justify-content:flex-start; /*gap:1rem;*/ 
  @include ie11gapfixrow(1rem);
}

MD5 Hash rekursiv aus Verzeichnis ermitteln

Erstellt in PHP am 5. November 2020 vom Daschmi

Um mit PHP den MD5 Hash eines Verzeichnisses zu ermitteln kann folgende Funktion verwendet werden.

abstract class Md5Tool {

    public static function md5_dir(string $path): string {

        if (is_dir($path)) {

            foreach (scandir($path) as $entry) {
                
                if (!in_array($entry, ['.', '..'])) $arMd5[] = self::md5_dir($path.$entry);
                                    
            }
            
            return md5(implode('', $arMd5));
            
        } else {
            
            return md5_file($path);
            
        } 

    }
    
}

echo Md5Tool::md5_dir('/');