Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
lol no

Cameron Tod cam8001

💭
lol no
  • Wellington, New Zealand
View GitHub Profile
@cam8001
cam8001 / gist:1700086
Created Jan 29, 2012
Building a drupal query
View gist:1700086
$arg = "%".drupal_get_path_alias($_GET['q'])."%";
echo $arg;
$query = db_select('url_alias', 't');
$query->fields('t');
$query->condition('t.alias', '$arg', 'LIKE');
$query->range(0, 1);
$result = $query->execute();
while ($record = $result->fetchAssoc()) {
print_r($record);
@cam8001
cam8001 / full_feature_revert.php
Last active Apr 15, 2019
Feature revert library function
View full_feature_revert.php
<?php
/**
* Completely reverts a feature based on the settings in its .info file.
*
* @param string $feature_module
* Name of feature/module to revert.
*/
function full_feature_revert($feature_module) {
$info = drupal_parse_info_file(drupal_get_path('module', $feature_module) . '/' . $feature_module . '.info');
@cam8001
cam8001 / php_closing_tags.sh
Created Sep 12, 2012
Find mismatched closing tags in php files
View php_closing_tags.sh
#!/bin/bash
# Find extra ?> tags in a PHP source tree.
# Much thanks to chx (drupal4hu.com) who gave me the regex!
ack '<\?php.*\?>(.(?!<\?php))+\?>' .
@cam8001
cam8001 / remove_conf_vars.sh
Created Oct 10, 2012
Removing conf vars from site.conf.php (or whatever)
View remove_conf_vars.sh
# Only works for vars that are expressed on one line, grep -A1 or a multilne pcregrep
# might be useful if you have longer var definitions.
# Check extant definitions
egrep "[$]conf\['related_videos_return'\]" --include site.conf.php .
# Blast em (note bsd/osx sed syntax, the first "" is not needed on gnu grep)
find . -type f -name site.conf.php -exec sed -i "" "/[$]conf\['related_videos_return'\]/d" {} \;
# Check them again, they are gone!
egrep "[$]conf\['related_videos_return'\]" --include site.conf.php .
@cam8001
cam8001 / gist:3956062
Created Oct 25, 2012
backtrace of _drupal_log_error notice
View gist:3956062
<?php
array(
0 =>
array (
'file' => '/Users/cam8001/Sites/drupal/core/includes/bootstrap.inc',
'line' => 2220,
'function' => '_drupal_log_error',
'args' =>
array (
@cam8001
cam8001 / patch_name_generator.js
Created Nov 1, 2012
Bookmarklet to make Drupal.org issue micro-branch or patch name
View patch_name_generator.js
javascript:alert(window.location.pathname.replace("/node/", '') + '-' + document.getElementsByTagName('h1')[0].innerHTML.replace(/'/g, '').replace(/[\s]/g, '-').toLowerCase());
@cam8001
cam8001 / field_formatter.module
Last active Oct 12, 2015
How to implement a custom field formatter
View field_formatter.module
<?php
/**
* @file
* Sets up a field formatter, which can run custom theming or whatever else for a field.
*
* Once you have implemented the formatter, choose it on the 'display options' for a node.
*/
/**
@cam8001
cam8001 / gist:4016570
Created Nov 5, 2012
Drupal 6 syntax for theme_imagecache
View gist:4016570
<?php
// The raw path to the image.
$path = $node->field_product_image[0]['filepath'];
// Let imagecache generate a different sized image using 'Product_large'
$large_path = imagecache_create_url('Product_large', $path);
// Render the original image and save the path to the large one in the tag.
// Your output will be something like:
// <img src="blah.jpg" large_img="large-blah.jpg" class='img-swap' />
theme('imagecache', $path, '', '', array('large_img' => $large_path, 'class' => 'img-swap'));
@cam8001
cam8001 / gist:4046187
Created Nov 9, 2012
Hook node view implementation
View gist:4046187
/**
* Implements hook_node_view().
*/
function superpoll_node_view($node, $view_mode, $langcode) {
// Provide a link back to the parent poll on superpoll options.
if ($node->type == 'superpoll_option' && $view_mode == 'full') {
$node->content['linkback_to_poll'] = array(
'#theme' => 'superpoll_option_header',
'#title' => $node->title,
View gist:4079725
13emerueuniversal.fr
13thstreet.de
13thstreet.pl
13thstreetuniversal.com.au
13thstreetuniversal.nl
calle13universal.es
divauniversal.asia
divauniversal.ro
divauniversal.ru
scifiuniversal.pl