Skip to content

Instantly share code, notes, and snippets.

View cesarmiquel's full-sized avatar

Cesar Miquel cesarmiquel

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / README.md
Last active December 27, 2015 20:39 — forked from JoelBesada/README.md
Make Drupal issue queue information box sticky
@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 / gist:8091980
Last active January 1, 2016 04:29
Blue / Orange color palette. Result can be previewed here: http://jsfiddle.net/FS9S8/1/embedded/result/
<div class="container">
<div class="box" style="background-color:#04263c"></div>
<div class="box" style="background-color:#042e3c"></div>
<div class="box" style="background-color:#043644"></div>
<div class="box" style="background-color:#044254"></div>
<div class="box" style="background-color:#045264"></div>
<div class="box" style="background-color:#045664"></div>
<div class="box" style="background-color:#042e44"></div>
<div class="box" style="background-color:#043a4c"></div>
<div class="box" style="background-color:#043e4c"></div>
@cesarmiquel
cesarmiquel / create-palette.php
Created December 23, 2013 05:15
Create a color palette from an image.
<?php
$img = imagecreatefrompng ( '/tmp/image.png' );
$palette = build_palette($img, 20, 20);
$unique_colors = array();
foreach($palette as $row) {
foreach($row as $col) {
$rgb = sprintf('%02x%02x%02x', $col['r'], $col['g'], $col['b']);
if (!isset($unique_colors[$rgb])) {
@cesarmiquel
cesarmiquel / create-node.php
Last active January 2, 2016 02:39
Create a Drupal node with path
<?php
// Create a node by code
$newNode = new stdClass();
$newNode->type = 'page';
node_object_prepare($newNode);
$newNode->title = 'This is the title of the new node';
$newNode->status = 1;
$newNode->comment = 1;