Skip to content

Instantly share code, notes, and snippets.

View evandonovan's full-sized 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
<?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()
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
<?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)
/**
* 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
<?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
<?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
<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
<?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
<?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;
@evandonovan
evandonovan / user-profile.tpl.php
Created May 19, 2010 22:42
user-profile.tpl.php with embedded view
<?php
// $Id: user-profile.tpl.php,v 1.2.2.1 2008/10/15 13:52:04 dries Exp $
/**
* @file user-profile.tpl.php
* Default theme implementation to present all user profile data.
*
* This template is used when viewing a registered member's profile page,
* e.g., example.com/user/123. 123 being the users ID.
*