Skip to content

Instantly share code, notes, and snippets.

@opi
opi / gist:1437730
Created December 6, 2011 10:39
HTML Link element with rel="alternate" for multilingual Drupal website
<?php
/**
* More info : http://www.google.com/support/webmasters/bin/answer.py?answer=189077&hl=en
*/
/**
* Implements hook_preprocess_page()
*/
function mymodule_preprocess_page(&$vars) {
global $language;
@opi
opi / gist:1582649
Created January 9, 2012 11:56
Drupal: Front theme on error 403 (Access denied)
<?php
// To enable this, set 403 path to 'error-403' on admin/settings/error-reporting
// or do variable_set('site_403', 'error-403'); in a hook_update_N, in your .install file.
function mymodule_menu() {
return array(
'error-403' => array(
'title' => "Access denied",
'page callback' => 'mymodule_error_403',
@opi
opi / Drupal 6 Update block cache
Created January 18, 2012 09:39
Drupal 6 Update block cache
<?php
function mymodule_update_N() {
$return = array();
$blocks = mymodule_block('list');
foreach($blocks as $delta => $block) {
$cache = ($block['cache']) ? $block['cache'] : BLOCK_CACHE_PER_ROLE;
$return[] = update_sql('UPDATE {blocks} SET cache = '.$cache.' WHERE module = "mymodule" AND delta = "'.$delta.'" ');
@opi
opi / gist:1885165
Created February 22, 2012 13:23
D6: Alter cck multiple value field. Not really sure this is the good way.
<?php
/**
* Implementation of hook_form_alter().
*/
function mymodule_form_alter(&$form, $form_state, $form_id) {
// Appelé la 1ere fois, sur node/add/mycontenttype
if($form_id == 'mycontenttype_node_form') {
@opi
opi / gist:1979024
Created March 5, 2012 16:04
Deny acces to txt files on drupal (CHANGELOG.txt, ...) (by @GoZOo)
Les fichiers TXT ne doivent pas être lisibles. Ajouter au .htaccess :
<Files *\.txt>
order allow,deny
deny from all
</Files>
<Files robots\.txt>
order allow,deny
allow from all
</Files>
@opi
opi / Drupal (6) login & logout issue
Created March 19, 2012 17:30
Drupal (6) login & logout issue
/**
* Implements hook_init().
*/
function mymodule_init() {
// Override Drupal default header.
// See http://www.journeymm.com/blogs/drupal/drupal-loginlogout-caching-problem
// and http://sriramk.com/blog/2007/06/firefox-and-ie-deal-with-no-cache.html
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", FALSE);
}
@opi
opi / gist:2217692
Created March 27, 2012 16:28
Drupal6 - Webform - Add custom data to result table and export
<?php
// Add custom data to submission
function mymodule_webform_submission_load(&$submissions) {
foreach ($submissions as $sid => $submission) {
$submissions[$sid]->data['mydata']['value'][] = $mydata;
}
}
// Alter registry to override theme_webform_results_table
@opi
opi / Disqus Javascript Callback
Created March 29, 2012 08:12
Disqus Javascript Callback
// In a js file
disqus_config = function() {
this.callbacks.afterRender.push(function() { /* your code */ });
this.callbacks.onNewComment.push(function() { /* your code */ });
/* Available callbacks are afterRender, onInit, onNewComment, onPaginate, onReady, preData, preInit, preReset */
}
@opi
opi / gist:2429422
Created April 20, 2012 15:04
function.css.less
.rounded(@radius: 0) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
border-radius: @radius;
}
.border-radius(@topright: 0; @bottomright: 0; @bottomleft: 0; @topleft: 0) {
-webkit-border-top-right-radius: @topright;
-webkit-border-bottom-right-radius: @bottomright;
-webkit-border-bottom-left-radius: @bottomleft;
-webkit-border-top-left-radius: @topleft;
@opi
opi / EnlargeYourClick.js
Created May 9, 2012 18:24
Enlarge Your Click
$.fn.enlargeYourClick = function(selector){
$(selector).click(function(e){
// don't handle if user click on a link, or if he click with mouse wheel
if (e.target.tagName != "A" && e.button != 1) {
var dest = $(this).find('a:first').attr('href');
if (dest) {window.location = dest};
}
});
}