-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgravatar-support-in-drupal.html
More file actions
144 lines (137 loc) · 6.22 KB
/
gravatar-support-in-drupal.html
File metadata and controls
144 lines (137 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>Dreams of thought</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/theme/styles.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="/theme/slicknav.css">
<script src="/theme/jquery.slicknav.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.2/html5shiv.js"></script>
<![endif]-->
<script>
$(function(){
$('#menu').slicknav({'label':''});
});
</script>
<link rel="icon" href="/theme/favicon.ico" sizes="16x16 32x32 48x48 64x64" type="image/vnd.microsoft.icon">
<link rel="apple-touch-icon" sizes="114x114" href="/theme/apple-touch-icon-precomposed.png">
<link rel="apple-touch-icon" sizes="152x152" href="/theme/favicon152.png">
<link rel="apple-touch-icon" sizes="196x196" href="/theme/favicon196.png">
</head>
<body>
<div id="wrapper">
<header>
<nav class="byline"><ul id="menu">
</ul></nav><!-- /#menu -->
<div class="downloads">
<a href="#" class="fa fa-Twitter"></a>
<a href="#" class="fa fa-Github"></a>
</div>
<hgroup>
<h1>Gravatar support in Drupal</h1>
<footer class="article-footer">
<address class="vcard author">
By <a class="url fn" href="./author/admin.html">admin</a>
</address>
<abbr class="published" title="2009-11-04T19:22:00+05:30">
on 04.11.2009
</abbr>
</footer><!-- /.post-info -->
</hgroup>
<meta name="tags" contents="drupal" />
<meta name="tags" contents="gravatar" />
</header>
<section id="content" class="body article">
<div class="entry-content">
<p>If you've been using Wordpress you probably know about Gravatar.
Gravatar is an abbreviation for "Globally Recognized Avatar". It's a
service which provides an avatar across sites. While Gravatar support is
built-in in Wordpress, it requires an external module to be installed in
Drupal. Recently I had to use the module in a Drupal 5 instance.</p>
<p>The module provides a gravatar only for comments. You can have the
module insert the gravatar into the comment body itself or have it
provide a field in the comment object ($comment->gravatar) which can be
used by the theme. It does this by using the hook_comment() .</p>
<p>In our case though, we needed it to show the gravatar instead of the
user picture if the user had not uploaded any. This was very easy to do.
The key function here is _gravatar_get_gravatar(). You can provide it
any or all of these parameters - mail, default, size or rating. Mail is
the email id of the user. Gravatar can supply a unique generated avatar
in case the email id you send them is not that of a registered Gravatar
user. This can be of many types - identicon, wavatar or monsterid. Which
of these are what you want, is specified in the default parameter. The
size is of course, the size. The gravatars uploaded come with a rating -
G, PG, R or X. You can specify a maximum rating with the rating
parameter. You can read more about the <a class="reference external" href="http://en.gravatar.com/site/implement/url">gravatar
parameters</a>.</p>
<p>You can pass whichever of these parameters you want to
_gravatar_get_gravatar() and it will return to you the url of the
gravatar. Now pass this to the theme_gravatar() function in the
gravatar module.</p>
<div class="line-block">
<div class="line">$picture = theme('gravatar',$gravatar_url,$username,$url);[/sourcecode]</div>
<div class="line">You have to do all of this in the theme_user_picture function of
your theme. If your theme is something like -</div>
<div class="line">function THEMENAME_user_picture($account) {</div>
<div class="line">if (variable_get('user_pictures', 0)) {</div>
<div class="line">if ($account->picture && file_exists($account->picture)) {</div>
<div class="line">$picture = file_create_url($account->picture);</div>
<div class="line">}</div>
<div class="line">else if (variable_get('user_picture_default', '')) {</div>
<div class="line">$picture = variable_get('user_picture_default', '');</div>
<div class="line">}</div>
</div>
<div class="line-block">
<div class="line">You could change it to something like -</div>
<div class="line"><br /></div>
<div class="line">function THEMENAME_user_picture($account) {</div>
<div class="line-block">
<div class="line">if (variable_get('user_pictures', 0)) {</div>
<div class="line">if ($account->picture && file_exists($account->picture)) {</div>
<div class="line">$picture = file_create_url($account->picture);</div>
</div>
<div class="line">}</div>
<div class="line">else if (user_access('use gravatar', $account) &&
(!user_access('disable own gravatar', $account) ||
!isset($account->gravatar) || $account->gravatar)) {</div>
<div class="line">$picture = _gravatar_get_gravatar(array('mail' =>
$account->mail));</div>
<div class="line">return theme('gravatar',$picture,$account->name,'');</div>
<div class="line">}</div>
<div class="line">else if (variable_get('user_picture_default', '')) {</div>
<div class="line">$picture = variable_get('user_picture_default', '');</div>
<div class="line">}</div>
<div class="line">You could even rewrite the default theme_gravatar provided by the
gravatar module with your own THEMENAME_gravatar theme function.</div>
</div>
</div><!-- /.entry-content -->
<div class="article-share-tags">
<div class="end-article-tags">
<i class="fa fa-tags"></i>
<a href="./tag/drupal.html">drupal</a>
<a href="./tag/gravatar.html">gravatar</a>
</div>
<div class='article-share'>
share -
</div>
</div>
</section>
<div class="neighbors">
</div>
<footer>
<a href="./pages/about.html" >About</a>
<div class="right-footer">
<a href="./categories.html" >Categories</a>
<a href="./tags.html" >Tags</a>
</div>
</footer>
</body>
</html>