Skip to content

Instantly share code, notes, and snippets.

View cafuego's full-sized avatar
😢

Peter Lieverdink cafuego

😢
View GitHub Profile
<?php
$count = 50000;
if(module_exists("devel"))
dpm("The count before increment:" . $count);
if ($node = menu_get_object('node')) {
if ($node->type == 'webform') {
$count = db_result(db_query('SELECT count(*) FROM {webform_submissions} WHERE nid = %d', $node->nid));
@cafuego
cafuego / gist:2951849
Created June 19, 2012 01:42
wysiwyg_fields
<p>&lt;wysiwyg_field wf_field="field_page_image" wf_deltas="1" wf_formatter="uom_image_floater" contenteditable="false" wf_settings-image_style="thumbnail" wf_settings-image_link="" wf_settings-image_float="right"&gt;<img class="image-float-right" title="Babel" src="http://languages.dev/sites/default/files/styles/thumbnail/public/about-us_1.jpg" alt="Babel" width="100" height="73" align="right" />Globally engage an expanded array of bandwidth for interdependent results. Phosfluorescently deliver maintainable channels through value-added data. Professionally drive synergistic infrastructures without high-quality quality vectors...
<div id="blurb" style="clear: both; margin: 0px 100px 0px 100px;">
<div id="portuguese" class="text" style="
float: left;
width: 30%;
margin-right: 5%;
padding-bottom: 5%;
">
<p>Drupal é uma plataforma open source de gerenciamento de conteúdo alimentar milhões de sites e aplicações. Ele é construído, usado, e apoiado por uma comunidade ativa e diversificada de pessoas ao redor do mundo.
</p>
@cafuego
cafuego / gist:2993779
Created June 26, 2012 06:32
static flag to avoid loop
wibble_node_presave($node) {
if (node->type == 'whatever') {
static $edit_flag;
if (reference_has_changed && empty($edit_flag)) {
$edit_flag = TRUE;
$reference = node_load($node->reference_field[0]['nid']);
$reference->reference_field[0]['nid'] = node->nid;
node_save($reference);
}
}
@cafuego
cafuego / gist:3074521
Created July 9, 2012 06:22
Drupal 7 Views Grid Preprocessor
<?php
/**
* Implements hook_preprocess_views_view_grid().
*
* Our own implementation removes the complete.css grid class names from
* the views grid and uses different ones instead.
*
* Specifically: col-N => view-col-N
*/
function phptemplate_preprocess_views_view_grid(&$vars) {
// Better yet, sue the language as defined in the entity. $entity->language?
foreach ($GLOBALS['user']->field_product_brand[LANGUAGE_NONE] as $term) {
if ($entity->field_product_brand[LANGUAGE_NONE][0]['tid'] == $term['tid'])
return $term['tid'];
}
}
return NULL;
-- Query 1: Use sensiblised day and time, also check if rollover is required.
SET @TIME=DATE_FORMAT(CONVERT_TZ(NOW(), 'UTC', 'Australia/Melbourne'), '%T'), @DOW=DAYOFWEEK(CONVERT_TZ(NOW(), 'UTC', 'Australia/Melbourne')), @FIRST=(SELECT programstarttime FROM wp_programgrid_programs WHERE dayofweek=DAYNAME(CONVERT_TZ(NOW(), 'UTC', 'Australia/Melbourne')) AND IsFirstProgramForDay=1), @LAST=(SELECT programstarttime FROM wp_programgrid_programs WHERE dayofweek=DAYNAME(CONVERT_TZ(NOW(), 'UTC', 'Australia/Melbourne')) ORDER BY programstarttime DESC LIMIT 1);
-- Query 2: Query the shit out of the data using our vars.
(select *, case dayofweek
when 'Sunday' then 1
when 'Monday' then 2
when 'Tuesday' then 3
when 'Wednesday' then 4
when 'Thursday' then 5
#!/usr/bin/php
<?php
// define('FORMAT', 'jS F Y');
// define('FORMAT', 'YYYY/mm/dd MMM M m mmm ddd j S EEEE');
define('FORMAT', 'dd');
define('LOCALE', 'nl_NL.UTF-8');
$alpha = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z');
/**
@cafuego
cafuego / gist:3998475
Created November 2, 2012 03:08
urlamafication
<?php
$text = "Whatever stuff with URLs in it.";
$protocols = array('http', 'https', 'ftp');
$protocols = implode(':(?://)?|', $protocols) . ':(?://)?';
// Prepare domain name pattern.
// The ICANN seems to be on track towards accepting more diverse top level
// domains, so this pattern has been "future-proofed" to allow for TLDs
// of length 2-64.
@cafuego
cafuego / gist:4192641
Created December 3, 2012 04:10
check serialized data
<?php
// Add yer string!
$data = '';
define('PATTERN', '/s:(\d+):"(.*?)";([Obis]):((\d+):)?([^;]+);/');
// Care not for arrays.
$blob = preg_replace('/a:\d+:{/', "\n", $data);
// Can't cope with objects.