dolibarr
18.0.6
Main Page
Related Pages
Topics
Classes
Files
File List
File Members
dolibarr_18.0
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'
)) {
28
define(
'NOREQUIRESOC'
,
'1'
);
29
}
30
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Not disabled cause need to do translations
31
if
(!defined(
'NOCSRFCHECK'
)) {
32
define(
'NOCSRFCHECK'
, 1);
33
}
34
if
(!defined(
'NOTOKENRENEWAL'
)) {
35
define(
'NOTOKENRENEWAL'
, 1);
36
}
37
if
(!defined(
'NOLOGIN'
)) {
38
define(
'NOLOGIN'
, 1);
39
}
40
if
(!defined(
'NOREQUIREMENU'
)) {
41
define(
'NOREQUIREMENU'
, 1);
42
}
43
if
(!defined(
'NOREQUIREHTML'
)) {
44
define(
'NOREQUIREHTML'
, 1);
45
}
46
if
(!defined(
'NOREQUIREAJAX'
)) {
47
define(
'NOREQUIREAJAX'
,
'1'
);
48
}
49
50
session_cache_limiter(
'public'
);
51
52
require_once
'../../main.inc.php'
;
53
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
if
(empty($dolibarr_nocache)) {
58
header(
'Cache-Control: max-age=10800, public, must-revalidate'
);
59
}
else
{
60
header(
'Cache-Control: no-cache'
);
61
}
62
63
?>
64
65
function
get_avatar_from_service(service, userid, size) {
66
// this return the url that redirects to the according user image/avatar/profile picture
67
// implemented services: google profiles, facebook, gravatar, twitter, tumblr, default fallback
68
// for google use get_avatar_from_service('google', profile-name or user-id , size-in-px )
69
// for facebook use get_avatar_from_service('facebook', vanity url or user-id , size-in-px or size-as-word )
70
// for gravatar use get_avatar_from_service('gravatar', md5 hash email@adress, size-in-px )
71
// for twitter use get_avatar_from_service('twitter', username, size-in-px or size-as-word )
72
// for tumblr use get_avatar_from_service('tumblr', blog-url, size-in-px )
73
// everything else will go to the fallback
74
// google and gravatar scale the avatar to any site, others will guided to the next best version
75
var url =
''
;
76
77
switch
(service) {
78
79
case
"google"
:
80
// see http://googlesystem.blogspot.com/2011/03/unedited-google-profile-pictures.html (couldn't find a better link)
81
// available sizes: all, google rescales for you
82
url =
"http://profiles.google.com/s2/photos/profile/"
+ userid +
"?sz="
+ size;
83
break
;
84
85
case
"facebook"
:
86
// see https://developers.facebook.com/docs/reference/api/
87
// available sizes: square (50x50), small (50xH) , normal (100xH), large (200xH)
88
var sizeparam =
''
;
89
if
(isNumberOrNot(size)) {
90
if
(size >= 200) {
91
sizeparam =
'large'
92
}
93
if
(size >= 100 && size < 200) {
94
sizeparam =
'normal'
95
}
96
if
(size >= 50 && size < 100) {
97
sizeparam =
'small'
98
}
99
if
(size < 50) {
100
sizeparam =
'square'
101
}
102
}
else
{
103
sizeparam = size;
104
}
105
url =
"https://graph.facebook.com/"
+ userid +
"/picture?type="
+ sizeparam;
106
break
;
107
108
case
"gravatar"
:
109
// see http://en.gravatar.com/site/implement/images/
110
// available sizes: all, gravatar rescales for you
111
url =
"http://www.gravatar.com/avatar/"
+ userid +
"?s="
+ size
112
break
;
113
114
case
"twitter"
:
115
// see https://dev.twitter.com/docs/api/1/get/users/profile_image/%3Ascreen_name
116
// available sizes: bigger (73x73), normal (48x48), mini (24x24), no param will give you full size
117
var sizeparam =
''
;
118
if
(isNumberOrNot(size)) {
119
if
(size >= 73) {
120
sizeparam =
'bigger'
121
}
122
if
(size >= 48 && size < 73) {
123
sizeparam =
'normal'
124
}
125
if
(size < 48) {
126
sizeparam =
'mini'
127
}
128
}
else
{
129
sizeparam = size;
130
}
131
132
url =
"http://api.twitter.com/1/users/profile_image?screen_name="
+ userid +
"&size="
+ sizeparam;
133
break
;
134
135
case
"tumblr"
:
136
// see http://www.tumblr.com/docs/en/api/v2#blog-avatar
137
//TODO do something smarter with the ranges
138
// available sizes: 16, 24, 30, 40, 48, 64, 96, 128, 512
139
var sizeparam =
''
;
140
if
(size >= 512) {
141
sizeparam = 512
142
}
143
if
(size >= 128 && size < 512) {
144
sizeparam = 128
145
}
146
if
(size >= 96 && size < 128) {
147
sizeparam = 96
148
}
149
if
(size >= 64 && size < 96) {
150
sizeparam = 64
151
}
152
if
(size >= 48 && size < 64) {
153
sizeparam = 48
154
}
155
if
(size >= 40 && size < 48) {
156
sizeparam = 40
157
}
158
if
(size >= 30 && size < 40) {
159
sizeparam = 30
160
}
161
if
(size >= 24 && size < 30) {
162
sizeparam = 24
163
}
164
if
(size < 24) {
165
sizeparam = 16
166
}
167
168
url =
"http://api.tumblr.com/v2/blog/"
+ userid +
"/avatar/"
+ sizeparam;
169
break
;
170
171
default
:
172
// http://www.iconfinder.com/icondetails/23741/128/avatar_devil_evil_green_monster_vampire_icon
173
// find your own
174
url =
"http://i.imgur.com/RLiDK.png"
;
// 48x48
175
}
176
177
178
return
url;
179
}
180
181
182
// helper methods
183
184
function
isNumberOrNot(n) {
185
// see http://stackoverflow.com/questions/18082/validate-numbers-in-javascript-isnumeric
186
return
!isNaN(parseFloat(n)) && isFinite(n);
187
}
188
189
// 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:1510
Generated on Sat Nov 2 2024 01:00:24 for
dolibarr
by Doxygen 1.11.0