perl: warning: Please check that your locale settings
The fix (change to whatever language or version of english you’re using eg en_GB):
apt-get install language-pack-en-base
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
dpkg-reconfigure locales
If you get the following warning below for apt-get or dpkg in ubuntu:
perl: warning: Please check that your locale settings ubuntu
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = “en_US.UTF-8″,
LC_ALL = “en_US.UTF-8″,
LANG = “en_US.UTF-8″
are supported and installed on your system.
perl: warning: Falling back to the standard locale (“C”).
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Taxonomy Terms Display for Drupal 6
Recently there have been two projects that both required segmenting of taxonomy terms/categories in different ways. Below are a couple different solutions I've put into sites to control the output of terms.
The first example is overriding all taxonomy and terms. This snippet was found at another site, but has been modified to suit our projects needs. Put this code in your themes template.php file. Below this snippet is how to implement them via your node.tpl.php file.
<?php
function yourtheme_preprocess_node(&$vars, $hook) {
global $user;
if ($vars['node']->taxonomy) {
foreach ($vars['node']->taxonomy as $term) {
$vocabulary[$term->vid]['taxonomy_term_'. $term->tid] = array(
'title' => $term->name,
'href' => taxonomy_term_path($term),
'attributes' => array(
'rel' => 'tag',
'title' => strip_tags($term->description),
),
);
}
ksort($vocabulary, SORT_NUMERIC);
unset($vars['terms']);
foreach ($vocabulary as $vid => $terms) {
$name = taxonomy_vocabulary_load($vid)->name;
$lname = taxonomy_vocabulary_load($vid)->name;
$lname = strtolower($lname);
$terms = theme('links', $terms, array('id' => $lname, 'class' => 'links inline'));
$vars['terms'] .= '<div class="vocabulary taxonomy_vid_';
$vars['terms'] .= $vid;
$vars['terms'] .= '">';
$vars['terms'] .= $name;
$vars['terms'] .= ': ';
$vars['terms'] .= $terms;
$vars['terms'] .= '</div>';
}
$vars['cat'] = theme('links', $vocabulary[1], array('class'=>'links inline'));
$vars['disorder'] = theme('links', $vocabulary[2], array('class'=>'links inline'));
$vars['gene']= theme('links', $vocabulary[3], array('class'=>'links inline'));
$vars['tat']= theme('links', $vocabulary[4], array('class'=>'links inline'));
$vars['cpt']= theme('links', $vocabulary[5], array('class'=>'links inline'));
}
}
?>You can use this by default with the value:
<?php if (count($taxonomy)): ?>
<div class="taxonomy"><?php echo $terms; ?></div>
<?php endif; ?>
Or you can use the defined variable based off your term ids specified:
<?php if (count($cpt)): ?>
<div class="vocabulary">CPT: <?php print $cpt; ?></div>
<?php endif; ?>
The other option I decided to use was to create my own function. This worked great on a site that had unique term pages (apache solr), so I used this function to display my blog terms (without the blog categories).
<?php
function themename_get_terms_by_vocabulary($node, $vid, $label = 0) {
$terms = taxonomy_node_get_terms_by_vocabulary($node, $vid);
if ($terms) {
$links = array();
if ($label != 0) {
$output = '<div class="term vid-' .$vid .'">' .$label .': ';
} else {
$vocabulary = taxonomy_vocabulary_load($vid);
$output .= '<div class="term vid-' .$vid .'">' .$vocabulary->name .': ';
}
foreach ($terms as $term) {
$links[] = l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description)));
}
$output .= implode(', ', $links);
$output .= '</div>';
}
return $output;
}
?>And then on my node-blog.tpl.php page, instead of using print $terms, I can use:
<?php if (count($taxonomy)): ?>
<div class="taxonomy">
<?php print themename_get_terms_by_vocabulary($node, 3); ?>
<?php print themename_get_terms_by_vocabulary($node, 3, "tags"); // adds additional class values ?>
</div>
<?php endif; ?>
Well I hope you found this tutorial/snippet of code helpful.
Using Jquery to get URL parameters and values
In this post, I would like to share a little jQuery code snippet that makes getting URL parameters and their values more convenient.
Recently, while working on one of my projects, I needed to read and get parameter values from URL string of the current page that was constructed and sent by PHP script. I came across this short and sweet JavaScript code snippet by Roshambo that does just that.
// Read a page's GET URL variables and return them as an associative array.
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
The function returns an array/object with your URL parameters and their values. For example, consider we have the following URL:
http://www.example.com/?me=myValue&name2=SomeOtherValue
Calling getUrlVars() function would return you the following array:
{
"me" : "myValue",
"name2" : "SomeOtherValue"
}
To get a value of first parameter you would do this:
var first = getUrlVars()["me"];
// To get the second parameter
var second = getUrlVars()["name2"];
To make the script syntax to look more jQuery like syntax I rewrote it as an extension for jQuery:
$.extend({
getUrlVars: function(){
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
},
getUrlVar: function(name){
return $.getUrlVars()[name];
}
});
Now you can use it in the following way:
// Get object of URL parameters
var allVars = $.getUrlVars();
// Getting URL var by its nam
var byName = $.getUrlVar('name');
Drupal and how to send email on form submit
Found these snippets of code on another blog, but thought they might help the followers of this blog. There are 3 functions. First is the submit handlers, then submit handler function, and finally mail hook.
<?php
function CUSTOM_form_alter(&$form, $form_state, $form_id) {
// test for comment form
if ($form_id == 'comment_form') {
// add an additional submit handler
$form['#submit'][] = '_CUSTOM_comment_form_submit';
}
}
?><?php
function _CUSTOM_comment_form_submit($form, &$form_state) {
// create an array of parameters
$params = array(
// NOTE: I tried using l() here,
// but links don't work very well in text emails
// this link will send me back to the node with an anchor to the comment
'commentLink' => 'http://' . $_SERVER['HTTP_HOST'] . base_path() .
$form_state['redirect'][0] . '#' . $form_state['redirect'][2]
);
// call mail function and send email
drupal_mail('CUSTOM', 'comment_submitted',
variable_get('site_mail','CUSTOMEMAIL'), language_default(), $params);
}
?><?php
function CUSTOM_mail($key, &$message, $params) {
$language = $message['language'];
switch($key) {
case 'comment_submitted':
// create an array of variables from the parameters argument
$variables = array(
'!commentLink' => $params['commentLink'],
);
// define subject and body
$message['subject'] = t("A comment has been submitted");
$message['body'] = t("!commentLink", $variables, $language->language);
break;
}
}
?>User Segmentation in Google Analytics with Drupal
Here are some notes to add user segmentation to Drupal and Google Analytics:
Find every user by role:
<?php
(^|,)(.*?)(:|,)
<strong>Find a particular user role:</strong>
<code>
(^|,)(authenticated user)(:|,)
(^|,)(administrator)(:|,)
(^|,)(editor)(:|,)
(^|,)(purchaser)(:|,)
?>Find all user profile values:
<?php
:(.*?)$
:(.*?):(.*?):(.*?)$
?>Find a particular user profile value:
<?php
:(.*?):(Iowa):(.*?)$
:(Iowa City):(Iowa):(.*?)$
?>Personally Identifiable Information:
You may not track certain user data.
- Full name (if not common)
- National identification number
- IP address (in some cases)
- Vehicle registration plate number
- Driver's license number
- Face, fingerprints, or handwriting
- Credit card numbers
- Digital identity
- Birthday
- Birth Place
http://en.wikipedia.org/wiki/Personally_identifiable_information