Skip to content

Instantly share code, notes, and snippets.

@hansspiess
hansspiess / .htaccess
Created August 10, 2012 19:47
.htaccess: Localhost / Live Server Switch
RewriteBase /
# Copy HTTP Authorization header value to HTTP_AUTOHRIZATION server variable for use by script
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# On live server, rewrite requests for URL-paths which do not resolve to specific
# physically-existing filetypes to my script, excluding the script's URL-path itself.
RewriteCond %{HTTP_HOST} !^localhost$
RewriteCond $1 !^index\.php
RewriteCond %{REQUEST_FILENAME} !-f
@hansspiess
hansspiess / functions.php
Created August 17, 2012 14:28
Wordpress: Add custom Class to Contact Form 7 <form> tag
<?php
add_filter( 'wpcf7_form_class_attr', 'custom_custom_form_class_attr' );
function custom_custom_form_class_attr( $class ) {
$class .= ' nice';
return $class;
}
?>
@hansspiess
hansspiess / terminal.sh
Last active May 2, 2020 16:44
Create .htaccess files for standard joomla install to secure folders
# Inside the root directory of the Joomla 3 instance, run these commands to add .htaccess files
# to joomla directories (except ./administrator) that prevent direct access to them.
# Also see https://www.joomla-security.de/dateien-verzeichnisse/htaccess-einstellungen.html
# Generally block access from outside
echo "<Files "*.*">
Deny from all
</Files>" > ./bin/.htaccess; cp -i ./bin/.htaccess ./cache/.htaccess; cp -i ./bin/.htaccess ./cli/.htaccess; cp -i ./bin/.htaccess ./includes/.htaccess; cp -i ./bin/.htaccess ./language/.htaccess; cp -i ./bin/.htaccess ./layouts/.htaccess; cp -i ./bin/.htaccess ./libraries/.htaccess; cp -i ./bin/.htaccess ./logs/.htaccess; cp -i ./bin/.htaccess ./tmp/.htaccess
# Block all except media files: First, create .htaccess file with
@hansspiess
hansspiess / .htaccess
Created May 1, 2020 16:39
Rewrite joomla article urls after turning on new routing system
# When changing joomla routing to not output article ids, google must be told where those articles are.
# Beware! This breaks if an article slug contains a number!
# https://docs.joomla.org/J3.x:New_Routing_System
RewriteRule category\/([a-z]*)\/(\d+)-([^/]*) https://www.site.example/category/$1/$3 [R=301,L]
@hansspiess
hansspiess / template-contact.php
Created October 3, 2013 19:42
Wordpress: Simple Contact Form
<?php
/*
Template Name: Kontakt
*/
?>
<?php /* other template code goes here... */ ?>
<?php
@hansspiess
hansspiess / .htaccess
Created June 28, 2019 00:44
Create a static copy of a phpwcms site
# Redirect Query String to Html file.
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} ([a-z0-9]+) [NC]
RewriteRule (.*) /%1.html? [R=301,L]
</IfModule>
@hansspiess
hansspiess / de-DE.override.ini
Last active November 20, 2018 07:01
Implement Icon Font with Joomla 2.5 pagination.php
;to be placed in ROOT/language/overrides/
JLIB_HTML_START="<i class=\"fa fa-fast-backward\"></i>"
JPREV="<i class=\"fa fa-backward\"></i>"
JNEXT="<i class=\"fa fa-forward\"></i>"
JLIB_HTML_END="<i class=\"fa fa-fast-forward\"></i>"
@hansspiess
hansspiess / node, nvm
Created June 26, 2018 12:22
update node on mac
# node version manager: list available versions
nvm ls
# nvm: see https://github.com/creationix/nvm
# node: get active version
node -v
# activate node version via nvm
nvm use 8
@hansspiess
hansspiess / hs_mailreplace.php
Created August 5, 2012 14:21
Php: Mask email address in string, using preg_replace_callback
<?php
function hs_mailreplace($str) {
return preg_replace_callback ('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})^',
create_function (
'$str',
'for ($i = 0; $i < strlen($str[0]); $i++) {
$result .= "&#" . ord(substr($str[0], $i, 1)) . ";";
};
@hansspiess
hansspiess / wp-tweaks.php
Last active December 14, 2017 03:00
wordpress tweaks
<?php
// remove wp generator
// https://css-tricks.com/snippets/wordpress/remove-wp-generator-meta-tag/
remove_action('wp_head', 'wp_generator');
// disable emojis
// http://wordpress.stackexchange.com/questions/185577/disable-emojicons-introduced-with-wp-4-2
function wpt_disable_emojis() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );