Skip to content

Instantly share code, notes, and snippets.

View flowtwo's full-sized avatar

Christian Laugesen flowtwo

View GitHub Profile
@flowtwo
flowtwo / validate-cpr.php
Created March 21, 2017 10:05
Validate Danish CPR
// Validate CPR-nr.
function is_cpr_valid($cpr) {
$cleaned = preg_replace("/[^0-9]/", "", $cpr);
if (strlen($cleaned) != 10) {
return FALSE;
}
$valid_dates = Array('010165', '010166', '010170', '010180', '010187', '010190');
@flowtwo
flowtwo / validate-cpr.js
Created March 21, 2017 10:04
Validate Danish CPR
// Validate CPR-nr.
function is_cpr_valid(cpr) {
var res = cpr.replace(/[^0-9]/ig, "");
if (res.length != 10) {
return false;
}
var validDates = ['010165', '010166', '010170', '010180', '010187', '010190'];
@flowtwo
flowtwo / curl.php
Last active February 9, 2018 22:57
ClickDimensions Programmatic Form Capture via PHP cURL
// Define constants
$cd_url = 'https://analytics-eu.clickdimensions.com/forms/h/foobar'; // copy from ClickDimensions
$cd_accountkey = 'foo'; // copy from ClickDimensions
$cd_domain = 'bar'; // copy from ClickDimensions
// Build fields (array) to ClickDimensions, matching keys and values
$fields = array(
'FirstName' => 'John', // retrieve from posted form
'LastName' => 'Doe', // retrieve from posted form
'Email' => 'john@doe.com', // retrieve from posted form
<div id="fund" class="fund"></div>
<script type="text/javascript">
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = "https://onlinefundraising.dk/js/3.5/iframe.js";
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
function OFfit() {
if (window.iFrameResize) {
/*
* Force download of documents due to bug in version 1.9.4
* Open bg-group-documents/include/filters.php and replace line 117-131 with this:
*/
$file_name = basename( $doc_path );
switch( strtolower( substr( strrchr( $file_name, '.' ), 1 ) ) ) {
case 'pdf' : $mime = 'application/pdf'; break;
case 'zip' : $mime = 'application/zip'; break;
case 'jpeg': $mime = 'image/jpg'; break;
@flowtwo
flowtwo / count-download
Last active December 23, 2019 22:23
Count downloads of files from the WordPress Media Library
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $download_base_dir;
$download_base_dir = dirname(__FILE__);
global $download_prefix;
$download_prefix = 'download_';
function gr_download_init() {
@flowtwo
flowtwo / Indlejringskode til eksempel
Created September 17, 2014 18:28
Indlejring af OnlineFundraising.dk
<div id="fund"></div><script type="text/javascript">window.onload=function(){var e=window.location.search.substring(1),n="https://onlinefundraising.dk/showcase/?"+e,t=document.getElementById("fund").offsetWidth,d=document.createElement("iframe");d.frameBorder=0,d.width=t,d.height="1450px",d.id="fundraising",d.frameborder="0",d.scrolling="no",d.setAttribute("src",n),document.getElementById("fund").appendChild(d)};</script>
@flowtwo
flowtwo / wpdb.sql
Last active February 1, 2017 08:58
Renaming existing WordPress tables for security reasons
/* STEP 1 */
RENAME table `wp_commentmeta` TO `prefix_commentmeta`;
RENAME table `wp_comments` TO `prefix_comments`;
RENAME table `wp_icl_content_status` TO `prefix_icl_content_status`;
RENAME table `wp_icl_core_status` TO `prefix_icl_core_status`;
RENAME table `wp_icl_flags` TO `prefix_icl_flags`;
RENAME table `wp_icl_languages` TO `prefix_icl_languages`;
RENAME table `wp_icl_languages_translations` TO `prefix_icl_languages_translations`;
RENAME table `wp_icl_locale_map` TO `prefix_icl_locale_map`;
RENAME table `wp_icl_message_status` TO `prefix_icl_message_status`;
@flowtwo
flowtwo / jQuery - External links
Created October 11, 2013 18:46
This makes sure external links are opened in new window and applies UTM parametres for statistics.
@flowtwo
flowtwo / WP - Get language
Created October 11, 2013 18:41
This checks browser language and returns its prefix.
/**
* Browser language
*/
if ( !function_exists('gr_language') ) {
function gr_language() {
$lang = substr( $_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2 );
echo $lang;
}
}