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