Skip to content

Instantly share code, notes, and snippets.

View cesarmiquel's full-sized avatar

Cesar Miquel cesarmiquel

View GitHub Profile
@cesarmiquel
cesarmiquel / add_terms.php
Created November 20, 2013 17:23
Add term tree into a taxonomy
<?php
// Structure to use
$terms = array(
array('name' => 'Technical', 'weight' => 1, 'parent' => 0),
array('name' => 'Operations', 'weight' => 6, 'parent' => 0),
array('name' => 'Customer Relationship', 'weight' => 7, 'parent' => 0),
array('name' => 'Talent & Culture', 'weight' => 11, 'parent' => 0),
array('name' => 'Finance', 'weight' => 12, 'parent' => 0),
array('name' => 'Dev', 'weight' => 0, 'parent' => 'Technical'),
@cesarmiquel
cesarmiquel / README.md
Last active December 27, 2015 20:39 — forked from JoelBesada/README.md
Make Drupal issue queue information box sticky
@cesarmiquel
cesarmiquel / unpublish-nodes.php
Last active December 27, 2015 00:29
Unpublish drupal content
<?php
// Select all nodes of type article created by anonymous and admin
$result = db_select('node', 'n')
->fields('n', array('nid'))
->condition('type', 'article')
->condition('uid', array(0,1), 'IN')
->execute();
// go through results and unpublish each article.
@cesarmiquel
cesarmiquel / add-table-prefix.php
Last active December 25, 2015 22:19
Change the prefix to all Drupal tables.
<?php
// ------------------------------------------------------------------------------------------
// This simple script adds the specified table prefix to all tables in the current DB.
// It is used if you want to add a prefix to all tables once the DB has been created.
//
// WARNING: Do not run on a DB which already uses prefixes to separate different databases.
//
// To run copy this script to the docroot of your Drupal installation and then do:
//
@cesarmiquel
cesarmiquel / thumbails.php
Created March 1, 2013 04:11
Go through all document content-types (should be PDFs), generate a thumbnail of the first page of the PDF and save the thumbnail in a field of the document.
<?php
// Select all nodes of type Document
$result = db_select('node', 'n')
->fields('n', array('nid'))
->condition('type', 'document')
->execute();
// create thumbnail and attach it
foreach($result as $row) {
@cesarmiquel
cesarmiquel / remap-csv.php
Created February 13, 2013 03:17
Read a CSV, process it and output a CSV
<?php
if (count($argv) != 3) {
die('Usage: php remap-csv.php <infile> <outfile>');
}
// in / out files are $argv[1] and $argv[2]
$in = fopen($argv[1], "r");
$out = fopen($argv[2], "w");
@cesarmiquel
cesarmiquel / edl_flowplayer.module
Created January 27, 2013 05:36
This simple Drupal module renders a URL with the flowplayer (http://flowplayer.org/) Javscript library. It requires having the Drupal flowplayer module.
<?php
/**
* Implements hook_field_formatter_info().
*/
function edl_flowplayer_field_formatter_info() {
return array(
// the key must be unique, so it's best to prefix with your module's name.
'edl_flowplayer_flowplayer' => array(
// the label is is what is displayed in the select box in the UI.
@cesarmiquel
cesarmiquel / drupal_module_snippets.php
Last active December 10, 2015 06:28
This are drupal snippets I constantly use in my modules. Replace xxxxx with module name.
<?php
/**
* Implements hook_menu().
*/
function xxxxx_menu() {
$items['path'] = array(
'title' => '[Title]',
'access callback' => TRUE,
'page callback' => 'xxxxx_render_page',
#!/bin/bash -x
#
# Script que actualiza el codigo en el ambiente a donde se hace push
#
#
# The "post-receive" script is run after receive-pack has accepted a pack
# and the repository has been updated. It is passed arguments in through
# stdin in the form
# <oldrev> <newrev> <refname>
# For example:
@cesarmiquel
cesarmiquel / stylesheet.html
Created November 22, 2012 23:17
HTML Stylesheet
<html>
<head>
<title>Titulo</title>
</head>
<body><p>Titulo</p>
<h1>This is an h1 header</h1>
<h2>This is an h2 header</h2>
<h3>This is an h3 header</h3>
<h4>This is an h4 header</h4>
<h5>This is an h5 header</h5>