Skip to content

Instantly share code, notes, and snippets.

@jgarciaruiz
jgarciaruiz / check_user_can_access_content.php
Last active October 7, 2015 16:10
Personal extension that connects moodle with my wp plugin "Bookr". Allow access to any Moodle course if you have previously unlocked it in WordPress via Bookr. *Addon for Moodle, must be activated the extension that allows wp authentication (md5).
<?php
/*
//CÓDIGO A INSERTAR EN EL HEADER DEL THEME DE MOODLE
ftp://dominio.es//domains/dominio.es/public_html/tuaulavirtual/theme/essential/layout/includes/header.php
<!-- jvrdbug -->
<?php
include($_SERVER['DOCUMENT_ROOT'].'/tuaulavirtual/check_user_can_access_content.php');
//echo "<div style='display:none' id='jvrdbug'>".($_SERVER['DOCUMENT_ROOT'].'/tuaulavirtual/check_user_can_access_content.php')."</div>";
<?php
/**
* Template Name: Movie Reviews
**/
get_header();
?>
<?php
global $post;
$posts = get_posts( array( 'post_type' => 'movie-reviews' ) );
@jgarciaruiz
jgarciaruiz / makeClickableLinks.php
Created October 16, 2015 13:33
//php function to convert text url into links.
@jgarciaruiz
jgarciaruiz / jsflush.js
Last active October 22, 2015 12:42
JS function to prevent file caching, version randomizer
//fn to prevent file caching
function flushVersion(length) {
var glyphs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP1234567890";
var version = "";
for (var j = 0; j < length; j++) {
var i = Math.floor(Math.random() * glyphs.length);
version += glyphs.charAt(i);
}
return version;
}
<?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 / wp_plugin_load_time.php
Last active December 9, 2015 13:08
Disables plugins for API requests in order to speed up the API response times.
<?php
/*
Plugin Name: WP API Load Time Enhancement
*/
//http://codex.wordpress.org/Must_Use_Plugins
$listener_term = '/webservices/';
$current_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '';
// if $current_url contains $listener_term
@jgarciaruiz
jgarciaruiz / functions.php
Last active December 9, 2015 13:10
WP movie reviews functions.php
<?php
//create custom post type: movie review
function movie_reviews_init() {
$args = array(
'label' => 'Movie Reviews',
'public' => true,
'show_ui' => true,
'capability_type' => 'page',//post
'hierarchical' => false,
'rewrite' => array('slug' => 'movie-reviews'),
@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 / gist:df93e9cd025edc89e870
Last active December 9, 2015 13:11
js app fn test
var app = {
layout: {
init: function() {
app.loader.init();
console.info("1. app layout init");
var wwidth = window.innerWidth;
var wheight = window.innerHeight;
windowdata(wwidth,wheight);
}
@jgarciaruiz
jgarciaruiz / gist:0bde4a6725d024ced11f
Last active December 9, 2015 13:11
JS var with functions demo
var $test = $(".ricochet"),
multiply = function(x,y) {
console.log("multiply ok: " + x * y);
},
siberet = function(add2div){
$test.html("siberet ok");//write inside .ricochet
};
siberet( multiply(2,4) );//initialize everythin'