changed user icon delivery - still lacking etags/if-none-match handling

This commit is contained in:
hyung-hwan 2015-02-04 07:40:32 +00:00
parent 0198854319
commit cce5c5be47
7 changed files with 87 additions and 5 deletions

View File

@ -235,6 +235,65 @@ class User extends Controller
$this->load->view ($this->VIEW_SETTINGS, $data);
}
}
function icon ($userid = '')
{
// TODO: ETag, If-None-Match???
$userid_len = strlen($userid);
if ($userid_len > 0)
{
$userid = $this->converter->HexToAscii ($userid);
$userid_len = strlen($userid);
}
if ($userid_len > 0)
{
$icon_path = CODEPOT_USERICON_DIR . '/' . $userid . '.png';
$icon_size = @filesize ($icon_path);
if (@file_exists($icon_path) === TRUE &&
($icon_size = @filesize($icon_path)) !== FALSE &&
@getimagesize($icon_path) !== FALSE)
{
header ("Content-Type: image/png");
header ("Content-Length: $icon_size");
@readfile ($icon_path);
return $icon_size;
}
}
$img = imagecreate (50, 50);
$bgcolor = imagecolorallocate($img, 250, 255, 250);
imagefill ($img, 0, 0, $bgcolor);
if ($userid_len > 0)
{
$fgcolor = imagecolorallocate($img, 0, 0, 0);
$font_size = 4;
$font_width = imagefontwidth(5);
$font_height = imagefontheight(5);
$img_width = imagesx($img);
$y = 2;
$k = 1;
for ($i = 0; $i < $userid_len; $i++)
{
$x = $k * $font_width;
if ($x > $img_width - $font_width)
{
$k = 1;
$y += $font_height + 2;
$x = $k * $font_width;
}
$k++;
imagechar ($img, $font_size, $x, $y, $userid[$i], $fgcolor);
}
}
header ("Content-Type: image/png");
imagepng ($img);
imagedestroy ($img);
}
}
?>

View File

@ -15,3 +15,15 @@ if ( ! function_exists('base_url_make'))
}
}
if ( ! function_exists('codepot_merge_path'))
{
function codepot_merge_path($base, $path)
{
if (substr($base, -1) == '/')
{
for ($i = 0; substr($path, $i, 1) == '/'; $i++);
return $base . substr($path, $i);
}
else return $base . $path;
}
}

View File

@ -308,11 +308,11 @@ if (FALSE) // don't want to delete code for the original diff view.
else
{
$http_user_agent = $_SERVER['HTTP_USER_AGENT'];
$is_msie = (stristr($http_user_agent, 'MSIE') != FALSE &&
stristr($http_user_agent, 'Opera') == FALSE);
$is_msie = (stristr($http_user_agent, 'MSIE') !== FALSE &&
stristr($http_user_agent, 'Opera') === FALSE);
if (!$is_msie)
{
$is_msie = (preg_match ("/^Mozilla.+\(Windows.+\) like Gecko$/", $http_user_agent) != FALSE);
$is_msie = (preg_match ("/^Mozilla.+\(Windows.+\) like Gecko$/", $http_user_agent) !== FALSE);
}
print '<div style="width: 100%; overflow: hidden;" id="code_diff_mainarea_result_fullview">';

View File

@ -83,10 +83,10 @@ $this->load->view (
<?php
$xfullpath = $this->converter->AsciiToHex (($fullpath == '')? '.': $fullpath);
$graph_url = site_url() . "/code/graph/commits-by-users/{$project->id}/{$xfullpath}";
$graph_url = codepot_merge_path (site_url(), "/code/graph/commits-by-users/{$project->id}/{$xfullpath}");
print "<img src='{$graph_url}' />";
$graph_url = site_url() . "/code/graph/commit-share-by-users/{$project->id}/{$xfullpath}";
$graph_url = codepot_merge_path (site_url(), "/code/graph/commit-share-by-users/{$project->id}/{$xfullpath}");
print "<img src='{$graph_url}' />";
?>

View File

@ -98,6 +98,7 @@ $this->load->view (
$m = $members[$i];
if ($m == '') continue;
/*
$icon_src = '';
if (array_key_exists($m, $icons))
{
@ -115,6 +116,9 @@ $this->load->view (
}
print "<li>{$icon_src}{$m}</li>";
*/
$user_icon_url = codepot_merge_path (site_url(), '/user/icon/' . $this->converter->AsciiToHex($m));
print "<li><img src='{$user_icon_url}' class='user_icon_img' />{$m}</li>";
}
?>
</ul>

View File

@ -11,6 +11,7 @@ function show_taskbar ($con, $login)
$title = (isset($login['email']) && $login['email'] != '')?
('title=' . htmlspecialchars($login['email'])): '';
/*
// attempt to load the user icon regardless of its upload state.
// if it has not been uploaded, it won't be found.
// check a file system may be faster than checking the database.
@ -26,6 +27,9 @@ function show_taskbar ($con, $login)
);
}
print $icon_src;
*/
$user_icon_url = codepot_merge_path (site_url(), '/user/icon/' . $con->converter->AsciiToHex($login['id']));
print "<img src='{$user_icon_url}' class='user_icon_img' />";
print anchor ('user/home', htmlspecialchars($login['id']), $title);

View File

@ -68,6 +68,7 @@ body {
.content .taskbar .boxb .user_icon_img {
height: 2em; /* as large as line-height of taskbar */
width: auto;
vertical-align: middle;
}
@ -493,9 +494,11 @@ pre.prettyprint li.L9 { background: #eee }
.content .sidebar .box .user_icon_img {
height: 2em;
width: auto;
vertical-align: middle;
padding-top: 1px;
padding-bottom: 1px;
padding-right: 1px;
}
.content .sidebar .boxtitle {