function google_authorship_preprocess_username in Google Authorship 7.2
Same name and namespace in other branches
- 7 google_authorship.module \google_authorship_preprocess_username()
Implements template_preprocess_username().
Alters the 'name' variable to be a link to a Google+ profile and sets the "rel='author'" parameter on the generate URL.
File
- ./
google_authorship.module, line 57 - A module to display Google+ profile pictures of node authors in Google search results.
Code
function google_authorship_preprocess_username(&$variables) {
// Checks if Metatag is being used instead of the default behavior
if (variable_get('google_authorship_use_metatag')) {
return;
}
$node = menu_get_object('node');
$bundles = variable_get('google_authorship_bundles', array());
// Checks if the loaded page is a node page. Checks that authorship information should be added for the node content type
if (empty($node) || !in_array($node->type, $bundles)) {
return;
}
// Checks whether author is a comment author.
$is_not_comment = !isset($variables['account']->comment_body);
// Checks to see if the author's Google+ ID is set, and if so, sets a variable
// for the id.
$is_id_set = $google_id = google_authorship_get_google_id($variables['uid']);
// Checks conditions set above and if it passes, alters the link path of the
// author.
if ($node && $is_not_comment && $is_id_set) {
if (variable_get('google_authorship_use_head')) {
$element = array(
'#tag' => 'link',
'#attributes' => array(
'href' => GOOGLE_AUTHORSHIP_PREFIX . $google_id,
'rel' => 'author',
),
);
if (variable_get('google_authorship_use_user')) {
$element['#attributes']['href'] = $GLOBALS['base_url'] . '/' . $variables['link_path'];
}
drupal_add_html_head($element, 'google_authorship_head_link');
}
else {
$variables['link_path'] = GOOGLE_AUTHORSHIP_PREFIX . $google_id . '?rel=author';
}
}
}