Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
fe2a1e85
Commit
fe2a1e85
authored
9 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
avatar: Add "Built-In" avatar source with random images
parent
8d883887
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
assets/default/css/theme.css
+4
-0
4 additions, 0 deletions
assets/default/css/theme.css
avatar.php
+36
-0
36 additions, 0 deletions
avatar.php
include/class.avatar.php
+86
-5
86 additions, 5 deletions
include/class.avatar.php
include/class.http.php
+9
-4
9 additions, 4 deletions
include/class.http.php
with
135 additions
and
9 deletions
assets/default/css/theme.css
+
4
−
0
View file @
fe2a1e85
...
...
@@ -1067,6 +1067,10 @@ table.custom-data .headline {
img
.avatar
{
border-radius
:
inherit
;
}
.avatar
>
img
.avatar
{
width
:
100%
;
height
:
100%
;
}
.thread-entry
.header
{
padding
:
8px
0.9em
;
border
:
1px
solid
#ccc
;
...
...
This diff is collapsed.
Click to expand it.
avatar.php
0 → 100644
+
36
−
0
View file @
fe2a1e85
<?php
/*********************************************************************
file.php
File download facilitator for clients
Peter Rotich <peter@osticket.com>
Jared Hancock <jared@osticket.com>
Copyright (c) 2006-2014 osTicket
http://www.osticket.com
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
require
(
'client.inc.php'
);
if
(
!
isset
(
$_GET
[
'uid'
])
||
!
isset
(
$_GET
[
'mode'
]))
Http
::
response
(
400
,
'`uid` and `mode` parameters are required'
);
require_once
INCLUDE_DIR
.
'class.avatar.php'
;
try
{
$ra
=
new
RandomAvatar
(
$_GET
[
'mode'
]);
$avatar
=
$ra
->
makeAvatar
(
$_GET
[
'uid'
]);
Http
::
response
(
200
,
false
,
'image/png'
,
false
);
Http
::
cacheable
(
$_GET
[
'uid'
],
false
,
86400
);
imagepng
(
$avatar
,
null
,
1
);
imagedestroy
(
$avatar
);
exit
;
}
catch
(
InvalidArgumentException
$ex
)
{
Http
::
response
(
422
,
'No such avatar image set'
);
}
This diff is collapsed.
Click to expand it.
include/class.avatar.php
+
86
−
5
View file @
fe2a1e85
...
...
@@ -23,12 +23,25 @@ abstract class Avatar {
}
abstract
function
getUrl
(
$size
);
abstract
function
__toString
();
function
getImageTag
(
$size
=
null
)
{
return
'<img class="avatar" alt="'
.
__
(
'Avatar'
)
.
'" src="'
.
$this
->
getUrl
(
$size
)
.
'" />'
;
}
function
__toString
()
{
return
$this
->
getImageTag
();
}
}
abstract
class
AvatarSource
{
static
$id
;
static
$name
;
var
$mode
;
function
__construct
(
$mode
=
null
)
{
if
(
isset
(
$mode
))
$this
->
mode
=
$mode
;
}
function
getName
()
{
return
__
(
static
::
$name
);
...
...
@@ -124,12 +137,80 @@ extends Avatar {
$url
.
=
"?s=
$size
&d=
{
$this
->
d
}
"
;
return
$url
;
}
}
function
getImageTag
(
$size
=
null
)
{
return
'<img class="avatar" alt="'
.
__
(
'Avatar'
)
.
'" src="'
.
$this
->
getUrl
(
$size
)
.
'" />'
;
class
LocalAvatarSource
extends
AvatarSource
{
static
$id
=
'local'
;
static
$name
=
/* @trans */
'Built-In'
;
var
$mode
=
'ateam'
;
static
function
getModes
()
{
return
array
(
'ateam'
=>
__
(
"Oscar's A-Team"
),
);
}
function
__toString
()
{
return
$this
->
getImageTag
();
function
getAvatar
(
$user
)
{
return
new
LocalAvatar
(
$user
,
$this
->
mode
);
}
}
AvatarSource
::
register
(
'LocalAvatarSource'
);
class
LocalAvatar
extends
Avatar
{
var
$mode
;
function
__construct
(
$user
,
$mode
)
{
parent
::
__construct
(
$user
);
$this
->
mode
=
$mode
;
}
function
getUrl
(
$size
)
{
if
(
false
&&
(
$file
=
$this
->
user
->
getAvatarFile
()))
return
$file
->
getDownloadUrl
();
// Generate a random string of 0-6 chars for the avatar signature
$uid
=
md5
(
strtolower
(
$this
->
user
->
getEmail
()));
return
'avatar.php?'
.
Http
::
build_query
(
array
(
'uid'
=>
$uid
,
'mode'
=>
$this
->
mode
));
}
static
function
serveRandomAvatar
(
$uid
,
$mode
)
{
}
}
class
RandomAvatar
{
var
$mode
;
static
$sprites
=
array
(
'ateam'
=>
array
(
'file'
=>
'images/avatar-sprite-ateam.png'
,
'grid'
=>
96
,
),
);
function
__construct
(
$mode
)
{
$this
->
mode
=
$mode
;
}
function
makeAvatar
(
$uid
)
{
$sprite
=
self
::
$sprites
[
$this
->
mode
];
$source
=
imagecreatefrompng
(
ROOT_DIR
.
$sprite
[
'file'
]);
$grid
=
$sprite
[
'grid'
];
$avatar
=
imagecreatetruecolor
(
$grid
,
$grid
);
$width
=
imagesx
(
$source
)
/
$grid
;
$height
=
imagesy
(
$source
)
/
$grid
;
// Start with a white matte
$white
=
imagecolorallocate
(
$avatar
,
255
,
255
,
255
);
imagefill
(
$avatar
,
0
,
0
,
$white
);
for
(
$i
=
0
,
$k
=
$height
-
1
;
$i
<
$k
;
$i
++
)
{
$idx
=
hexdec
(
$uid
[
$i
])
%
$width
;
imagecopy
(
$avatar
,
$source
,
0
,
0
,
$idx
*
$grid
,
$i
*
$grid
,
$grid
,
$grid
);
}
return
$avatar
;
}
}
This diff is collapsed.
Click to expand it.
include/class.http.php
+
9
−
4
View file @
fe2a1e85
...
...
@@ -37,10 +37,15 @@ class Http {
header
(
'HTTP/1.1 '
.
Http
::
header_code_verbose
(
$code
));
header
(
'Status: '
.
Http
::
header_code_verbose
(
$code
)
.
"
\r\n
"
);
header
(
"Connection: Close
\r\n
"
);
header
(
"Content-Type:
$contentType
; charset=
$charset
\r\n
"
);
header
(
'Content-Length: '
.
strlen
(
$content
)
.
"
\r\n\r\n
"
);
print
$content
;
exit
;
$ct
=
"Content-Type:
$contentType
"
;
if
(
$charset
)
$ct
.
=
"; charset=
$charset
"
;
header
(
$ct
);
if
(
$content
)
{
header
(
'Content-Length: '
.
strlen
(
$content
)
.
"
\r\n\r\n
"
);
print
$content
;
exit
;
}
}
function
redirect
(
$url
,
$delay
=
0
,
$msg
=
''
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment