* @copyright Narno.com * @todo inegration in node content, forum, profile, etc. */ define(GRAVATAR_URL, 'http://www.gravatar.com/avatar.php?gravatar_id=%s'); define(GRAVATAR_MAX_SIZE, 80); /** * Implementation of hook_help(). * Displays helpful descriptions and hints on necessary pages. */ function gravatar_help($section) { switch ($section) { case 'admin/user/gravatar': $output = '

'. t("The Gravatar module display the user's Gravatar in comments.") .'

'; $output .= ''; return $output; break; } } /** * Implementation of hook_menu(). */ function gravatar_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array( 'path' => 'admin/user/gravatar', 'title' => t('Gravatar'), 'description' => t('Gravatar settings.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('gravatar_admin_settings'), 'access' => user_access('administer site configuration'), 'type' => MENU_NORMAL_ITEM ); } return $items; } /** * admin settings for the Gravatar module */ function gravatar_admin_settings() { $modules_path = drupal_get_path('module', 'gravatar'); $form = array(); $form['gravatar_prepend'] = array( '#type' => 'fieldset', '#title' => t('How to insert the Gravatar picture in comment ?') ); $form['gravatar_prepend']['gravatar_prepend'] = array( '#type' => 'radios', '#default_value' => variable_get('gravatar_prepend', TRUE), '#options' => array( TRUE => t('Prepend the Gravatar picture to the comment'), FALSE => t('Leave it up to the theme to add (only if the theme support Gravatar)') ) ); $form['gravatar_rating'] = array( '#type' => 'fieldset', '#title' => t('Authorized rated') ); $form['gravatar_rating']['gravatar_rating'] = array( '#type' => 'radios', '#default_value' => variable_get('gravatar_rating', ''), '#options' => array( 'G' => theme('image', $modules_path . '/rating/g.gif', 'G', 'G', '', FALSE) . ' ' . t('rated Gravatars are suitable for display on all websites with any audience type'), 'PG' => theme('image', $modules_path . '/rating/pg.gif', 'PG', 'PG', '', FALSE) . ' ' . t('rated Gravatars contain may contain rude gestures, provocatively dressed individuals, the lesser swear words, or mild violence'), 'R' => theme('image', $modules_path . '/rating/r.gif', 'R', 'R', '', FALSE) . ' ' . t('rated Gravatars may contain such things as harsh profanity, intense violence, nudity, or hard drug use'), 'X' => theme('image', $modules_path . '/rating/x.gif', 'X', 'X', '', FALSE) . ' ' . t('rated Gravatars may contain hardcore sexual imagery or extremely disturbing violence'), '' => t('None') ) ); if (variable_get('user_pictures', 0)) { $user_picture_default = variable_get('user_picture_default', ''); $user_picture_dimensions = variable_get('user_picture_dimensions', '85x85'); $gravatar_pictures = ''; $gravatar_pictures .= '

'. t("You can modify this settings on users settings page.", array('@link' => '/admin/user/settings')) .'

'; $form['gravatar_pictures'] = array( '#type' => 'fieldset', '#title' => t('Pictures settings'), '#description' => $gravatar_pictures ); } $form['gravatar_advanced'] = array( '#type' => 'fieldset', '#title' => t('Advanced options') ); $form['gravatar_advanced']['gravatar_url'] = array( '#type' => 'textfield', '#title' => t('Gravatar URL'), '#default_value' => variable_get('gravatar_url', GRAVATAR_URL), '#description' => t("If you are not sure don't modify this !") ); return system_settings_form($form); } /** * Implementation of hook_comment(). */ function gravatar_comment(&$comment, $op) { $comment_account = user_load(array('uid' => $comment->uid)); // allowed to use gravatar (for ananymous and users) and enabled (for users) if (($comment_account->uid == 0) && user_access('use gravatar', $comment_accoun) || (($comment_account->uid != 0) && (user_access('use gravatar', $comment_account) && $comment_account->gravatar_enabled))) { switch ($op) { case 'view': // hack for authenticated users if ($comment_account->uid != 0) { $comment->mail = $comment_account->mail; } // check email address if (!empty($comment->mail)) { // Gravatar url $grav_url = gravatar_build_url($comment->mail); // set Gravatar for template $comment->gravatar = theme('gravatar', $grav_url, $comment->name, $comment->homepage); // if theme dosen't support Gravatar, insert picture in comment text if (variable_get('gravatar_prepend', TRUE)) { $comment->comment = $comment->gravatar . $comment->comment; } } break; case 'form': $comment['mail']['#description'] .= '
'. t('If you have a Gravatar account, used to display your avatar.', array('@gravatar-website' => url('http://www.gravatar.com'))) .''; return $comment; break; } } } /** * Implementation of hook_user() */ function gravatar_user($op, &$edit, &$account, $category = NULL) { if (user_access('use gravatar')) { switch ($op) { case 'form': if ($category == 'account') { $form['gravatar'] = array( '#type' => 'fieldset', '#title' => t('Gravatar settings') ); $grav_url = gravatar_build_url($account->mail); $form['gravatar']['gravatar_enabled'] = array( '#type' => 'checkbox', '#title' => t('Use my Gravatar in comments') . theme('gravatar', $grav_url), '#default_value' => $edit['gravatar_enabled'], '#description' => t('If checked, display your Gravatar (You can see it at the right).') ); } return $form; break; /* case 'view': // set gravatar for users's profile (in Drupal 6 templating ?) $account->gravatar = theme('gravatar', $grav_url, $account->name); echo '
', print_r($account), '
'; break; */ } } } // print Gravatar function theme_gravatar($grav_url, $name='', $homepage='') { $alt = t("@user's picture", array('@user' => $name ? $name : variable_get('anonymous', t('Anonymous')))); $picture = theme('image', $grav_url, $alt, $alt, '', FALSE); if (!empty($homepage)) { $picture = l($picture, $homepage, array('title' => t('View user website.')), NULL, NULL, FALSE, TRUE); } $output = "\n
" . $picture . "
\n"; return $output; } // build the Gravatar URL from e-mail function gravatar_build_url($email) { $grav_url = ''; // Gravatar url $grav_url = sprintf(variable_get('gravatar_url', GRAVATAR_URL), md5($email)); // default picture $default = variable_get('user_picture_default', ''); if (!empty($default)) { $grav_url .= "&default=" . urlencode(url($default)); } // rating $rating = variable_get('gravatar_rating', ''); if (!empty($rating)) { $grav_url .= "&rating=" . $rating; } // set the maximum Gravatar sized // get the maximum allowed user picture dimensions from user settings list($maxwidth, $maxheight) = explode('x', variable_get('user_picture_dimensions', '85x85')); if (!empty($maxwidth) && (integer)$maxwidth <= GRAVATAR_MAX_SIZE) { $grav_url .= "&size=" . $maxwidth; } return $grav_url; } /** * Implementation of hook_perm(). * Defines a few access roles utilized in this module. */ function gravatar_perm() { return array('use gravatar'); } ?>