Skip to content

Instantly share code, notes, and snippets.

View Langmans's full-sized avatar

Langmans Langmans

  • Netherlands
  • 05:20 (UTC +02:00)
View GitHub Profile
@Langmans
Langmans / cache.htaccess
Last active February 26, 2019 09:45 — forked from jcanfield/cache.htaccess
.htaccess caching rules
<IfModule mod_mime.c>
# Text
AddType text/css .css
AddType application/x-javascript .js
AddType text/html .html .htm
AddType text/richtext .rtf .rtx
AddType text/plain .txt
AddType text/xml .xml
@Langmans
Langmans / functions.php
Created February 6, 2019 16:15
timber: set the search query to the loaded page on the 404 page so you can extend search.twig in 404.twig.
<?php
add_filter( 'timber/context/404', function ( array $context ) {
global $wp;
$url = urldecode( $wp->request );
$context['referer'] = wp_get_referer();
$context['url'] = site_url( $url );
<?php
$fh_read = fopen('alldb.sql', 'r');
$fh_write = null;
$dbname = null;
while ($line = fgets($fh_read)) {
if (preg_match('@-- Current Database: `([^`]+)`@', $line, $m)) {
if ($fh_write) {
echo 'Closing ', $dbname, '<br>';
<?php
function cafileCheck()
{
if(!__DEBUGGING__)
{
return;
}
$cert_locations = openssl_get_cert_locations();
if(is_file($cert_locations['default_cert_file']))
@Langmans
Langmans / DMG\ServiceProvider\GoogleAnalyticsProvider.php
Created January 15, 2019 13:01
google analytics provider (gtag) for silex 1.x
<?php
namespace DMG\ServiceProvider;
use Silex\Application;
use Silex\ServiceProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
@Langmans
Langmans / get_loaded_theme_file.php
Created November 26, 2018 10:00
gets the loaded php file within a wordpress theme
<?php
function get_loaded_theme_files() {
$sdir = realpath( get_stylesheet_directory() ) . DIRECTORY_SEPARATOR;
$tdir = realpath( get_template_directory() ) . DIRECTORY_SEPARATOR;
return array_filter( get_included_files(), function ( $file ) use ( $sdir, $tdir ) {
$r = realpath( $file );
$d = dirname( $r ) . DIRECTORY_SEPARATOR;
@Langmans
Langmans / .htaccess
Last active February 28, 2019 10:02
.htaccess dynamic environment for slim framework (development, testing, acceptance, production) var based on hostname and current env
# env based
SetEnvIf SLIM_MODE ^(development|testing|acceptation|production)$ SLIM_MODE_FROM_ENV=$0
SetEnvIfNoCase Request_URI /projects/ SLIM_MODE_FROM_REQUEST=testing SLIM_MODE_RULE_6=1
SetEnvIfNoCase Host ^accepta(nce|tie|tion)\d*\. SLIM_MODE_FROM_REQUEST=acceptation SLIM_MODE_RULE_5=1
SetEnvIfNoCase Host ^(beta|test(ing)?)\d*\. SLIM_MODE_FROM_REQUEST=testing SLIM_MODE_RULE_4=1
SetEnvIfNoCase Host \.(dev|test(ing)?|local(host)?)$ SLIM_MODE_FROM_REQUEST=development SLIM_MODE_RULE_3=1
SetEnvIfNoCase Host ^localhost(:\d+)?$ SLIM_MODE_FROM_REQUEST=development SLIM_MODE_RULE_2=1
SetEnvIf SLIM_MODE_FROM_REQUEST ^$ SLIM_MODE_FROM_DOMAIN=none SLIM_MODE_RULE_1=1
<?php
class Menu extends \Timber\Menu {
public $MenuItemClass = 'MenuItem';
}
class MenuItem extends \Timber\MenuItem {
/** @var MenuItem */
public $parent;
<?php
// removes orphaned images
// as in no attachment record.
require __DIR__ . '/wp-load.php';
ob_implicit_flush( true );
set_time_limit( 0 );
/** @var \wpdb */
@Langmans
Langmans / article-teaser.php
Last active July 17, 2018 12:44
wordpress the_content with teaser (more tag), add to functions.php under wordpress theme
<?php
add_filter( 'the_content', function( $content ) {
$content = preg_replace_callback( "@(^.*)(<p>\s*(<span\s*id=\"more-\d+\">\s*</span>|<!--\s*more\s*-->)\s*</p>)@s", function ( $m ) {
return '<div class="article-teaser">' . $m[1] . '</div><!--/.article-teaser-->' . PHP_EOL . $m[2];
}, $content );
return $content;
});