Skip to content

Instantly share code, notes, and snippets.

View felipelavinz's full-sized avatar

Felipe Lavín Z. felipelavinz

View GitHub Profile
<?php
$row = 1;
$per_loop = 0;
$loop = 1;
$headers = array();
$files = array();
if (($handle = fopen("datos.csv", "r")) !== FALSE){
while (($data = fgetcsv($handle, 0, ";")) !== FALSE) {
if ( $row === 1 ) $headers = $data;
@felipelavinz
felipelavinz / i18n_update.sh
Created August 13, 2013 14:49
Actualizar un catálogo de traducciones
# instalar las herramientas de traducción de GNU.
# en Ubuntu están en el paquete gettext, en otras distribuciones puede tener otro nombre
sudo apt-get install gettext
# acceder a la carpeta donde están los archivos del proyecto
cd /var/www/proyecto/htdocs/wp-content/plugins/mi-plugin/
# actualizar la plantilla de traducciones
php /var/www/i18n/makepot.php wp-plugin . l10n/dominio_de_traduccion.pot
@felipelavinz
felipelavinz / i18n-tools.sh
Last active December 21, 2015 00:39
Herramientas de localización de WordPress
# Acceder al directorio donde vamos a obtener el repositorio
cd /var/www
# Copiar los contenidos del repositorio al directorio i18n
svn checkout http://svn.automattic.com/wordpress-i18n/tools/trunk/ i18n/
# Acceder al directorio donde están los archivos que queremos traducir
cd /var/www/proyecto/htdocs/wp-content/plugins/mi-plugin
# Crear la carpeta donde se van a almacenar las traducciones
@felipelavinz
felipelavinz / l10n.php
Created August 12, 2013 22:38
Ejemplos de funciones de localización en WordPress
<?php
/**
* Para textos que pueden estar en singular o plural: _n( $singular, $plural, $numero, $dominio_de_traduccion )
* printf() permite intercalar la variable con el número en el mensaje a traducir
*/
printf( _n( 'Hay %d usuario activo.', 'Hay %d usuarios activos.', $count, 'dominio_de_traduccion' ), $count );
/**
* Desambiguación por contexto
@felipelavinz
felipelavinz / EntriesOptions.php
Last active December 20, 2015 10:48
Create Entries Options using an ArrayIterator
<?php
class EntriesOptions extends ArrayIterator{
private $query;
private $cur_post;
public function __construct( $query_params = array(), $flags = array() ){
$args = wp_parse_args( $query_params, array(
'post_status' => 'publish',
'orderby' => 'title',
'order' => 'ASC',
@felipelavinz
felipelavinz / brute-thumbnails.php
Created July 19, 2013 04:18
Create image thumbnails with PHP and Imagick
<?php
$abs_start = microtime(true);
$path = __DIR__;
$Directory = new RecursiveDirectoryIterator('.');
$img_extensions = array('jpg', 'jpeg', 'gif', 'png');
@felipelavinz
felipelavinz / .htaccess
Created July 6, 2013 17:45
.htaccess default wordpress multisite en subdirectorio
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
#!/bin/bash
# Daniel Verner
# CarrotPlant LLC
# 2011
# Backup each mysql databases into a different file, rather than one big file
# Optionally files can be gzipped (dbname.gz)
#
# Usage: dump_all_databases [ -u username -o output_dir -z ]
#
# -u username to connect mysql server
@felipelavinz
felipelavinz / respuesta-api-senado.xml
Created April 3, 2013 22:59
Respuesta del API del Senado de Chile para trámites de un proyecto de ley... esto era lo que escupía cuando funcionaba
<?xml version="1.0" encoding="UTF-8"?>
<proyectos>
<proyecto>
<descripcion>
<boletin>8575-05</boletin>
<titulo>Ley de Presupuestos del sector público para el año 2013.</titulo>
<fecha_ingreso>01/10/2012</fecha_ingreso>
<iniciativa>Mensaje</iniciativa>
<camara_origen>C.Diputados</camara_origen>
<urgencia_actual>Discusión inmediata</urgencia_actual>
@felipelavinz
felipelavinz / fancybox_cover_embeds.js
Created March 19, 2013 19:13
Cover embed objects when using a lightbox image. It works by creating an iframe behind the lightbox div, with the same dimensions as that.
jQuery(document).ready(function($){
$('.lightbox-img').fancybox({
cyclic: true,
index: 0,
onStart: function(){
},
onComplete: function(){
var wrap = $('#fancybox-wrap'),
outer = $('#fancybox-outer'),
width = outer.width(),