Skip to content

Instantly share code, notes, and snippets.

View rafasashi's full-sized avatar
👍
Happy

Raphaël Dartigues rafasashi

👍
Happy
View GitHub Profile
@rafasashi
rafasashi / lazyload-get-the-post-thumbnail.php
Last active November 26, 2016 11:00 — forked from menslow/lazyload-get-the-post-thumbnail.php
Rewrite of the WordPress "get_the_post_thumbnail" for compatibility with jQuery LazyLoad plugin
<php
// Rewrite of "get_the_post_thumbnail" for compatibility with jQuery LazyLoad plugin
function my_get_the_post_lazyload_thumbnail( $post_id = false, $size = 'full' ) {
if ( $post_id ) {
// Get the id of the attachment
$attachment_id = get_post_thumbnail_id( $post_id );
if ( $attachment_id ) {
$src = wp_get_attachment_image_src( $attachment_id, $size );
if ($src) {
$img = get_the_post_thumbnail( $post_id, $size, array(
@rafasashi
rafasashi / curl_multi_exec_functions.php
Created July 3, 2016 18:20
Implementation of curl_multi_exec for parallel processing
function custom_curl_multi_exec($mh, &$running){
do{
$rv = curl_multi_exec($mh, $running);
}
while ($rv === CURLM_CALL_MULTI_PERFORM);
@rafasashi
rafasashi / ip_in_range.php
Created June 23, 2016 12:27 — forked from tott/ip_in_range.php
php check if IP is in given network range
/**
* Check if a given ip is in a network
* @param string $ip IP to check in IPV4 format eg. 127.0.0.1
* @param string $range IP/CIDR netmask eg. 127.0.0.0/24, also 127.0.0.1 is accepted and /32 assumed
* @return boolean true if the ip is in this range / false if not.
*/
function ip_in_range( $ip, $range ) {
if ( strpos( $range, '/' ) == false ) {
$range .= '/32';
}
@rafasashi
rafasashi / Readme.md
Created June 14, 2016 23:24 — forked from atomotic/Readme.md
Internet Archive Save Page Now
@rafasashi
rafasashi / bootbox-dialog-v4-all.js
Created November 3, 2015 18:25 — forked from makeusabrew/bootbox-dialog-v4-all.js
An attempt to demonstrate as many bootbox.dialog options as sanely possible in a single-file gist.
bootbox.dialog({
/**
* @required String|Element
*/
message: "I am a custom dialog",
/**
* @optional String|Element
* adds a header to the dialog and places this text in an h4
*/
@rafasashi
rafasashi / Migrate SPIP 2 to Wordpress with SQL.md
Last active September 29, 2015 14:35 — forked from angezanetti/FromSPIPtoWordpress.sql
Migrate SPIP 2 and 3 to Wordpress with MySQL

##Imports terms

REPLACE INTO wp_terms(term_id, name, slug, term_group)
SELECT    id_rubrique, titre, CONCAT("rub",id_rubrique), 1 FROM spip_rubriques;

Update urls

UPDATE wp_terms, spip_urls
SET slug = spip_urls.url

WHERE spip_urls.id_objet = term_id

@rafasashi
rafasashi / README.md
Last active August 29, 2015 14:25
Parse a CSS file with PHP

##Handles

  • child selector >
  • base64 images
  • input[type="button"]:hover
  • @media queries

##Example

$css_contents = file_get_contents($url);

@rafasashi
rafasashi / strip_single_tag.php
Last active November 28, 2019 03:44
strip a single html tag
function strip_single_tag($str,$tag=''){
if(is_array($tag)){
foreach($tag as $t){
$str=strip_single_tag($str,$t);
}
}
else{
<?php
if (!isset($_SESSION['user'])) {
require_once( COMPONENTS . "/user/class.user.php" );
$_SESSION['user'] = $_SERVER['PHP_AUTH_USER'];
$_SESSION['lang'] = 'en';
$_SESSION['theme'] = 'default';
$_SESSION['project'] = '/var/www';
$User = new User();
@rafasashi
rafasashi / How to review and run an external php script safely.markdown
Last active August 29, 2015 14:23
How to review and run an external php script safely?
  1. fetch the original script but never change it directly
  2. parse the php script using token_get_all() and token_name()
  3. replace every sensitive functions by a wrape_function_name to control the behavore
  4. rebuild the script and store the mirror script somewhere
  5. use getcwd() to store the current directory and chdir() to reset it to the original location so the static resources will be dowloaded from the origine
  6. execute the mirror script
  7. use chdir() to restore the previous directory location