Skip to content

Instantly share code, notes, and snippets.

View cam8001's full-sized avatar
💭
lol no

Cameron Tod cam8001

💭
lol no
  • Amazon Web Services
  • Wellington, New Zealand
  • 18:45 (UTC +12:00)
View GitHub Profile
@cam8001
cam8001 / gist:1700086
Created January 29, 2012 18:45
Building a drupal query
$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 April 15, 2019 19:02
Feature revert library function
<?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 September 12, 2012 11:19
Find mismatched closing tags in php files
#!/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 October 10, 2012 17:12
Removing conf vars from site.conf.php (or whatever)
# 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 October 25, 2012 23:14
backtrace of _drupal_log_error notice
<?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 November 1, 2012 01:00
Bookmarklet to make Drupal.org issue micro-branch or patch name
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 October 12, 2015 07:38
How to implement a custom field formatter
<?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 November 5, 2012 10:41
Drupal 6 syntax for theme_imagecache
<?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 November 9, 2012 15:02
Hook node view implementation
/**
* 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,
@cam8001
cam8001 / gist:4079725
Created November 15, 2012 16:53
sites.txt
13emerueuniversal.fr
13thstreet.de
13thstreet.pl
13thstreetuniversal.com.au
13thstreetuniversal.nl
calle13universal.es
divauniversal.asia
divauniversal.ro
divauniversal.ru
scifiuniversal.pl