Skip to content

Instantly share code, notes, and snippets.

<?php
//secure-submit-functions.php
// Strips nasty tags from code..
function cleanEvilTags($data) {
$data = preg_replace("/javascript/i", "j&#097;v&#097;script",$data);
$data = preg_replace("/alert/i", "&#097;lert",$data);
$data = preg_replace("/about:/i", "&#097;bout:",$data);
$data = preg_replace("/onmouseover/i", "&#111;nmouseover",$data);
$data = preg_replace("/onclick/i", "&#111;nclick",$data);
$data = preg_replace("/onload/i", "&#111;nload",$data);
@jgarciaruiz
jgarciaruiz / normalize_filename.php
Last active December 9, 2015 13:11
Normalize file name, clear white spaces and special chars
<?php
function normalize_filename($string) {
$extension = substr(strrchr($string,'.'),1);
// delete extension
$string = preg_replace('/\.[^.]+$/','',$string);
//utf8_encode($string);
$a = array(' ','À','Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö','Ø','Ù','Ú','Û','Ü','Ý','ß','à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î','ï','ñ','ò','ó','ô','õ','ö','ø','ù','ú','�»','ü','ý','ÿ','Ā','ā','Ă','ă','Ą','ą','Ć','ć','Ĉ','ĉ','Ċ','ċ','Č','č','Ď','ď','Đ','đ','Ē','ē','Ĕ','ĕ','Ė','ė','Ę','ę','Ě','ě','Ĝ','ĝ','Ğ','ğ','Ġ','ġ','Ģ','ģ','Ĥ','ĥ','Ħ','ħ','Ĩ','ĩ','Ī','ī','Ĭ','ĭ','Į','į','İ','ı','IJ','ij','Ĵ','ĵ','Ķ','ķ','Ĺ','ĺ','�»','ļ','Ľ','ľ','Ŀ','ŀ','Ł','ł','Ń','ń','Ņ','ņ','Ň','ň','ʼn','Ō','ō','Ŏ','ŏ','Ő','ő','Œ','œ','Ŕ','ŕ','Ŗ','ŗ','Ř','ř','Ś','ś','Ŝ','ŝ','Ş','ş','Š','š','Ţ','ţ','Ť','ť','Ŧ','ŧ','Ũ','ũ','Ū','ū','Ŭ','ŭ','Ů','ů','Ű','ű','Ų','ų','Ŵ','ŵ','Ŷ','ŷ','Ÿ','Ź','ź','�»','ż','Ž','ž','ſ','ƒ','Ơ','ơ','Ư','ư','Ǻ','�»','Ǽ','ǽ','Ǿ','ǿ');
$b = array('-','A','A','A','A','A','A'
@jgarciaruiz
jgarciaruiz / modal-share.js
Created December 16, 2015 14:27
Add the class social-button to the links you want to open on a modal window.
function modalPopup(url, width, height) {
var left = (screen.width / 2) - (width / 2),
top = (screen.height / 2) - (height / 2);
window.open(
url,
"",
"menubar=no,toolbar=no,resizable=yes,scrollbars=yes,width=" + width + ",height=" + height + ",top=" + top + ",left=" + left
);
}
$(".social-button").on("click", function(e) {
function checkPalindrome(thestr) {
var reverseStr = thestr.split('').reverse().join('');
if (thestr == reverseStr){
return "yay";
}else{
return "nope"
}
}
//checkPalindrome("aba");
@jgarciaruiz
jgarciaruiz / js-apply-example.js
Last active December 29, 2015 20:53
Using apply function to find out the maximum/minimum value in an array
var numbers = [342, 16, 8, 345, 23, 436, 75];
highestVal(numbers);//436
lowestVal(numbers);//8
function highestVal(array){
var highestN = Math.max.apply(Math, array)
return highestN;
}
@jgarciaruiz
jgarciaruiz / class.yith-wc-coupon-email-system-premium
Last active January 26, 2016 12:40
Add bday field to register form using WP plugin yith-woocommerce-coupon-email-system-premium: lines 104-105
<?php
/**
* This file belongs to the YIT Plugin Framework.
*
* This source file is subject to the GNU GENERAL PUBLIC LICENSE (GPL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.gnu.org/licenses/gpl-3.0.txt
*/
@jgarciaruiz
jgarciaruiz / add2cartViaCoupon.php
Created February 4, 2016 17:17
WooCommerce add product to cart if coupon code matches existing coupon
//Adding a hidden product to cart with applied coupon woocommerce/wordpress
//a modified version of this:http://docs.woothemes.com/document/automatically-add-product-to-cart-on-visit/
add_action( 'init', 'add_product_to_cart' );
<?php
function add_product_to_cart() {
if ( ! is_admin() ) {
global $woocommerce;
$product_id = 1211;
$found = false;
//@ http://jsfromhell.com/array/shuffle
shuffle = function(v){
for(var j, x, i = v.length; i; j = parseInt(Math.random() * i), x = v[--i], v[i] = v[j], v[j] = x);
return v;
};
//example:
var a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
shuffle(a);
@jgarciaruiz
jgarciaruiz / remove_whitespaces_regex.js
Last active February 10, 2016 10:55
Remove leading and trailing white spaces from html string. [Polyfill]
//// http://stackoverflow.com/questions/10032024/how-to-remove-leading-and-trailing-white-spaces-from-a-given-html-string
//Running the following code before any other code will create trim() if it's not natively available.
if(!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g,'');
};
}
@jgarciaruiz
jgarciaruiz / functions.php
Created February 16, 2016 09:20
Add custom code to specific wp page snippet
function custom_code(){
if ( is_page( 102 )) {
?>
<!-- TRACKING CODE OR WHATEVER -->
<?php
}
}
add_action('wp_footer', 'custom_code');