Skip to content

Instantly share code, notes, and snippets.

Avatar

Evan Donovan evandonovan

View GitHub Profile
@evandonovan
evandonovan / geocode_update.module
Created April 3, 2010 05:19
auto-updates geocodes using Google geocoder from location.module
View geocode_update.module
<?php
// geocode_update.module
/**
* Implementation of hook_cron()
*
* Loads all the locations on the site which have invalid latitude/longitude,
* then uses the Google geocoder to update the latitude/longitude, if possible.
*/
function geocode_update_cron() {
@evandonovan
evandonovan / um_common_form-alter.php
Created April 3, 2010 15:09
example of various uses of hook_form_alter()
View um_common_form-alter.php
function um_common_form_alter(&$form, $form_state, $form_id) {
// hide split teaser on node forms
if (isset($form['#node']) && $form_id == $form['#node']->type .'_node_form') {
$form['body_field']['teaser_include'] = array(
'#type' => 'value',
'#value' => TRUE,
);
}
// user login block changes
elseif(($form_id == 'user_login_block')) {
@evandonovan
evandonovan / taxonomy_token.module.php
Created April 28, 2010 15:38
taxonomy_token.module
View taxonomy_token.module.php
<?php
// $Id
define(MODULE_DESCRIPTION, 'Provides tokens that will contain text when a taxonomy term is present. For use with taxonomy module.');
/**
* Implements hook_help()
*
*/
function taxonomy_token_help($path, $arg) {
@evandonovan
evandonovan / email_validate.php
Created May 13, 2010 03:57
code to validate email addresses (via MX address & PHP mail well-formedness rules)
View email_validate.php
/**
* Implements hook_user().
* Does advanced email validation.
*/
function revolven_user($op, &$edit, &$account, $category = NULL) {
if($op == "validate") {
if($error = adv_email_validate($edit['mail'])) {
form_set_error('mail', $error);
}
}
@evandonovan
evandonovan / find_element()
Created May 14, 2010 14:24 — forked from wimleers/find_element()
Wim Leers' recursive code - find form elements of given type
View find_element()
<?php
function find_element($form, $element_type) {
if (isset($form['#type']) && $form['#type'] == $element_type) {
return $form;
}
else {
foreach (element_children($form) as $name) {
if (is_array($form[$name])) {
$element = find_element($form[$name], $element_type);
if ($element !== FALSE) {
@evandonovan
evandonovan / gmap_plugin_style_gmap-with_remote_callback.php
Created May 15, 2010 00:50
gmap plugin style with remote callback
View gmap_plugin_style_gmap-with_remote_callback.php
<?php
// $Id: gmap_plugin_style_gmap.inc,v 1.7 2009/02/05 21:51:53 bdragon Exp $
/**
* @file
* GMap style plugin.
*/
/**
* Style plugin to render a map.
@evandonovan
evandonovan / find_hook_implementations.php
Created May 17, 2010 18:45
find implementations of a given hook in Drupal
View find_hook_implementations.php
<ol>
<?php
foreach(module_implements("block") as $module) {
print "<li>" . $module . "</li>";
}
?>
</ol>
@evandonovan
evandonovan / marker-popup_code.php
Created May 17, 2010 22:01
gmap marker popup via AHAH code
View marker-popup_code.php
<?php
// following is excerpted from um_common.module:
// service area vid
define("SERVICE_AREA_VID", 32);
/**
* Implements hook_menu()
* Creates Gmap rendering callbacks for popups.
@evandonovan
evandonovan / url_outbound_alter_example.php
Created May 18, 2010 03:13
url_outbound_alter set absolute domain
View url_outbound_alter_example.php
<?php
/**
* Implements hook_url_outbound_alter() - from URL Alter module
*/
function YOURMODULE_url_outbound_alter(&$path, &$options, $original_path) {
// Rewrite paths for rices4peru.com
if ($_SERVER['HTTP_HOST'] == "www.rices4peru.com") {
$options['absolute'] = TRUE;
View taxonomy_node_list_terms_by_vocabulary.php
<?php
// convenience theming function for taxonomy lists -- ead 6.10.10
function taxonomy_node_list_terms_by_vocabulary($nid, $voc_id, $link = FALSE, $ul = FALSE) {
/* loads a "dummy" node in order to use taxonomy_node_get_terms_by_vocabulary()
to get an array of taxonomy terms */
$node = new stdClass();
$node->vid = db_result(db_query("SELECT MAX(vid) FROM {node_revisions} WHERE nid = %d", $nid));
$terms = taxonomy_node_get_terms_by_vocabulary($node, $voc_id);
if(!isset($terms) || !is_array($terms) || empty($terms)) { return ''; }