dolibarr
24.0.0-beta
Main Page
Related Pages
Topics
Classes
Files
File List
File Members
dolibarr_dev
htdocs
core
js
lib_gravatar.js.php
Go to the documentation of this file.
1
<?php
2
/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 3 of the License, or
8
* (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17
* or see https://www.gnu.org/
18
*/
19
26
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language
27
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1');
28
if
(!defined(
'NOREQUIRESOC'
)) {
29
define(
'NOREQUIRESOC'
,
'1'
);
30
}
31
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Not disabled cause need to do translations
32
if
(!defined(
'NOCSRFCHECK'
)) {
33
define(
'NOCSRFCHECK'
, 1);
34
}
35
if
(!defined(
'NOTOKENRENEWAL'
)) {
36
define(
'NOTOKENRENEWAL'
, 1);
37
}
38
if
(!defined(
'NOLOGIN'
)) {
39
define(
'NOLOGIN'
, 1);
40
}
41
if
(!defined(
'NOREQUIREMENU'
)) {
42
define(
'NOREQUIREMENU'
, 1);
43
}
44
if
(!defined(
'NOREQUIREHTML'
)) {
45
define(
'NOREQUIREHTML'
, 1);
46
}
47
if
(!defined(
'NOREQUIREAJAX'
)) {
48
define(
'NOREQUIREAJAX'
,
'1'
);
49
}
50
51
session_cache_limiter(
'public'
);
52
53
require_once
'../../main.inc.php'
;
54
// Define javascript type
55
top_httphead
(
'text/javascript; charset=UTF-8'
);
56
// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
57
header(
'Cache-Control: max-age=10800, public, must-revalidate'
);
58
59
?>
60
61
function
get_avatar_from_service(service, userid, size) {
62
// this return the url that redirects to the according user image/avatar/profile picture
63
// implemented services: google profiles, facebook, gravatar, twitter, tumblr, default fallback
64
// for google use get_avatar_from_service('google', profile-name or user-id , size-in-px )
65
// for facebook use get_avatar_from_service('facebook', vanity url or user-id , size-in-px or size-as-word )
66
// for gravatar use get_avatar_from_service('gravatar', md5 hash email@address, size-in-px )
67
// for twitter use get_avatar_from_service('twitter', username, size-in-px or size-as-word )
68
// for tumblr use get_avatar_from_service('tumblr', blog-url, size-in-px )
69
// everything else will go to the fallback
70
// google and gravatar scale the avatar to any site, others will guided to the next best version
71
var url =
''
;
72
73
switch
(service) {
74
75
case
"google"
:
76
// see http://googlesystem.blogspot.com/2011/03/unedited-google-profile-pictures.html (couldn't find a better link)
77
// available sizes: all, google rescales for you
78
url =
"http://profiles.google.com/s2/photos/profile/"
+ userid +
"?sz="
+ size;
79
break
;
80
81
case
"facebook"
:
82
// see https://developers.facebook.com/docs/reference/api/
83
// available sizes: square (50x50), small (50xH) , normal (100xH), large (200xH)
84
var sizeparam =
''
;
85
if
(isNumberOrNot(size)) {
86
if
(size >= 200) {
87
sizeparam =
'large'
88
}
89
if
(size >= 100 && size < 200) {
90
sizeparam =
'normal'
91
}
92
if
(size >= 50 && size < 100) {
93
sizeparam =
'small'
94
}
95
if
(size < 50) {
96
sizeparam =
'square'
97
}
98
}
else
{
99
sizeparam = size;
100
}
101
url =
"https://graph.facebook.com/"
+ userid +
"/picture?type="
+ sizeparam;
102
break
;
103
104
case
"gravatar"
:
105
// see http://en.gravatar.com/site/implement/images/
106
// available sizes: all, gravatar rescales for you
107
url =
"http://www.gravatar.com/avatar/"
+ userid +
"?s="
+ size
108
break
;
109
110
case
"twitter"
:
111
// see https://dev.twitter.com/docs/api/1/get/users/profile_image/%3Ascreen_name
112
// available sizes: bigger (73x73), normal (48x48), mini (24x24), no param will give you full size
113
var sizeparam =
''
;
114
if
(isNumberOrNot(size)) {
115
if
(size >= 73) {
116
sizeparam =
'bigger'
117
}
118
if
(size >= 48 && size < 73) {
119
sizeparam =
'normal'
120
}
121
if
(size < 48) {
122
sizeparam =
'mini'
123
}
124
}
else
{
125
sizeparam = size;
126
}
127
128
url =
"http://api.twitter.com/1/users/profile_image?screen_name="
+ userid +
"&size="
+ sizeparam;
129
break
;
130
131
case
"tumblr"
:
132
// see http://www.tumblr.com/docs/en/api/v2#blog-avatar
133
//TODO do something smarter with the ranges
134
// available sizes: 16, 24, 30, 40, 48, 64, 96, 128, 512
135
var sizeparam =
''
;
136
if
(size >= 512) {
137
sizeparam = 512
138
}
139
if
(size >= 128 && size < 512) {
140
sizeparam = 128
141
}
142
if
(size >= 96 && size < 128) {
143
sizeparam = 96
144
}
145
if
(size >= 64 && size < 96) {
146
sizeparam = 64
147
}
148
if
(size >= 48 && size < 64) {
149
sizeparam = 48
150
}
151
if
(size >= 40 && size < 48) {
152
sizeparam = 40
153
}
154
if
(size >= 30 && size < 40) {
155
sizeparam = 30
156
}
157
if
(size >= 24 && size < 30) {
158
sizeparam = 24
159
}
160
if
(size < 24) {
161
sizeparam = 16
162
}
163
164
url =
"http://api.tumblr.com/v2/blog/"
+ userid +
"/avatar/"
+ sizeparam;
165
break
;
166
167
default
:
168
// http://www.iconfinder.com/icondetails/23741/128/avatar_devil_evil_green_monster_vampire_icon
169
// find your own
170
url =
"http://i.imgur.com/RLiDK.png"
;
// 48x48
171
}
172
173
174
return
url;
175
}
176
177
178
// helper methods
179
180
function
isNumberOrNot(n) {
181
// see http://stackoverflow.com/questions/18082/validate-numbers-in-javascript-isnumeric
182
return
!isNaN(parseFloat(n)) && isFinite(n);
183
}
184
185
// End of lib_gravatar.js.php
top_httphead
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition
main.inc.php:1512
Generated on Mon Jun 22 2026 21:04:40 for
dolibarr
by Doxygen 1.11.0