Skip to content

Instantly share code, notes, and snippets.

View carwin's full-sized avatar
🍔
cheeseburger

Carwin Young carwin

🍔
cheeseburger
  • Missouri
View GitHub Profile
@carwin
carwin / d6_uc_cart_form_alter.php
Created September 6, 2012 01:09
Drupal 6: Use hook_form_alter() to remove the "Remove" button on Ubercart's cart form
<?php
function modulename_form_alter(&$form, $form_state, $form_id) {
switch ( $form_id ) {
case 'uc_cart_view_form':
/*
* This is how you can remove the "remove"
* button for each item.
*/
foreach($form['items'] as $k => $v ) {
if(is_integer($k) && isset($v['remove'])) {
@carwin
carwin / d7_webform_simplenews_conditional_subscription.php
Created September 6, 2012 01:39
Drupal 7: hook_webform_submission_presave() to subscribe a user to a Simplenews newsletter with a conditional component.
<?php
/*
* Implementation of hook_webform_submission_presave()
*
* For a particular Webform node, use the submitted
* value of a component to determine whether or not
* the submitter will be subscribed to a Simplenews
* newsletter.
*
* Subscribe the user to the Simplenews newsletter
@carwin
carwin / weathergist.php
Created September 6, 2012 01:46
PHP: Use Yahoo's Weather API, cURL, and SimpleXML to get current weather conditions given a WOEID.
<?php
/*
* This gist utilizes Yahoo's Weather API to snag the current
* weather conditions for any country given it's WOEID.
*
* - by Carwin Young
*/
/* Set up some location WOEIDs */
$Cambodia = 1020985; /* Phnom Pneh */
@carwin
carwin / d7_out_of_stock_remove_addtocart.php
Created September 7, 2012 07:07
Drupal 7: Ubercart - Change the value of "Add to cart" when a product is already in a user's cart, or the product is out of stock.
<?php
// Get the "Add to cart" array ready for rendering.
$add_to_cart = array(
'#theme' => 'uc_product_add_to_cart',
'#form' => drupal_get_form('uc_product_add_to_cart_form_' . $node->nid, $node),
);
/*
* Check the database to see the Stock availability of the product.
*/
if(uc_stock_is_active($node->model)){
@carwin
carwin / d7_uc_extra_checkout_pane.php
Created September 7, 2012 17:37
Drupal 7: (UNTESTED) Add an extra pane to Ubercart's checkout form / review.
<?php
function yourmodule_custom_form($form, &$form_state, $term) {
/* Note: rather than passing a $term var, you could use arg(2) from the url */
drupal_set_title('Your Label: ' . ucwords($term));
// or
drupal_set_title('Your Label: ' . str_replace('%20',' ', arg(2)));
/* Make life easier: */
$school = ucwords($term);
@carwin
carwin / icons
Created September 8, 2012 09:28
A list of neat characters I don't want to forget about.
☎ - &#9742; &#x260e;
☂ - &#9730; &#x2602;
☑ - &#9745; &#x2611;
☒ - &#9746; &#x2612;
☐ - &#9744; &#x2610;
☁ - &#9729; &#x2601;
⌘ - &#8984; &#x2318;
♻ - &#9851; &#x267b;
@carwin
carwin / d7_theme_jquery_usage.js
Created September 12, 2012 17:43
Drupal 7: Proper implementation of jQuery in a Drupal theme.
(function ($) {
Drupal.behaviors.themename = {
attach: function(context, settings) {
// Add a hover class to nav items.
$('.mainnav nav a')
.hover(
function() {
$(this).addClass('hover');
},
function() {
@carwin
carwin / d7_html5_menus.php
Created September 13, 2012 17:26
Drupal 7: Change structure of all menus from pattern [ ul > li > a ] to a valid html5 pattern [ nav > a ]
<?php
/*
* Replace all menu tree <ul> elements with <nav>.
*/
function foo_menu_tree(&$variables) {
return '<nav>' . $variables['tree'] . '</nav>';
}
/*
* Removes <li> from all menu links, leaving only <a>s.
*/
@carwin
carwin / node.tpl.php
Created September 14, 2012 11:55
Drupal 7: Remove the link on a user-picture entirely and render a region in node.tpl.php
/*
* Render the new user picture
*/
<?php print '<div class="user-picture"><img src="' . $user_picture . '" /></div>'; ?>
/*
* Render the now-available 'below_content' region
* under the content or wherever you want.
*/
<div class="content"<?php print $content_attributes; ?>>
@carwin
carwin / drupal_lighttpd_conf
Created September 19, 2012 16:47
Lighttpd Configuration for Drupal
##
## Variables
##
var.log_root = "/var/log/lighttpd"
var.server_root = "/var/www"
var.state_dir = "/var/run"
var.home_dir = "/var/lib/lighttpd"
var.conf_dir = "/etc/lighttpd"
var.vhosts_dir = server_root + "/vhosts"