Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
facd4cbe
Commit
facd4cbe
authored
13 years ago
by
Bart Visscher
Browse files
Options
Downloads
Patches
Plain Diff
Contacts: Cleanup photo and thumbnail code
parent
3eff161b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/contacts/photo.php
+30
-73
30 additions, 73 deletions
apps/contacts/photo.php
apps/contacts/thumbnail.php
+39
-32
39 additions, 32 deletions
apps/contacts/thumbnail.php
with
69 additions
and
105 deletions
apps/contacts/photo.php
+
30
−
73
View file @
facd4cbe
<?php
/**
* ownCloud - Addressbook
*
* @author Jakob Sack
* @copyright 2011 Jakob Sack mail@jakobsack.de
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
* Copyright (c) 2011, 2012 Bart Visscher <bartv@thisnet.nl>
* Copyright (c) 2011 Jakob Sack mail@jakobsack.de
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
// Init owncloud
...
...
@@ -29,67 +17,36 @@ $id = $_GET['id'];
if
(
isset
(
$GET
[
'refresh'
]))
{
header
(
"Cache-Control: no-cache, no-store, must-revalidate"
);
}
$l10n
=
new
OC_L10N
(
'contacts'
);
$cont
en
t
=
OC_Contacts_App
::
getContactVCard
(
$id
);
$cont
ac
t
=
OC_Contacts_App
::
getContactVCard
(
$id
);
$image
=
new
OC_Image
();
// invalid vcard
if
(
is_null
(
$content
)){
$image
->
loadFromFile
(
'img/person_large.png'
);
header
(
'Content-Type: '
.
$image
->
mimeType
());
$image
();
//echo $l10n->t('This card is not RFC compatible.');
exit
();
if
(
is_null
(
$contact
))
{
OC_Log
::
write
(
'contacts'
,
'photo.php. The VCard for ID '
.
$id
.
' is not RFC compatible'
,
OC_Log
::
ERROR
);
}
else
{
// Photo :-)
foreach
(
$content
->
children
as
$child
){
if
(
$child
->
name
==
'PHOTO'
){
$mime
=
'image/jpeg'
;
foreach
(
$child
->
parameters
as
$parameter
){
if
(
$parameter
->
name
==
'TYPE'
){
$mime
=
$parameter
->
value
;
}
}
if
(
$image
->
loadFromBase64
(
$child
->
value
))
{
if
(
$image
->
width
()
>
200
||
$image
->
height
()
>
200
)
{
$image
->
resize
(
200
);
}
header
(
'Content-Type: '
.
$mime
);
$image
();
exit
();
}
else
{
$image
->
loadFromFile
(
'img/person_large.png'
);
header
(
'Content-Type: '
.
$image
->
mimeType
());
$image
();
}
//$photo = base64_decode($child->value);
//header('Content-Type: '.$mime);
//header('Content-Length: ' . strlen($photo));
//echo $photo;
//exit();
if
(
$image
->
loadFromBase64
(
$contact
->
getAsString
(
'PHOTO'
)))
{
// OK
header
(
'ETag: '
.
md5
(
$contact
->
getAsString
(
'PHOTO'
)));
}
}
}
$image
->
loadFromFile
(
'img/person_large.png'
);
header
(
'Content-Type: '
.
$image
->
mimeType
());
$image
();
/*
else
// Logo :-/
foreach($content->children as $child){
if($child->name == 'PHOTO'){
$mime = 'image/jpeg';
foreach($child->parameters as $parameter){
if($parameter->name == 'TYPE'){
$mime = $parameter->value;
if
(
$image
->
loadFromBase64
(
$contact
->
getAsString
(
'LOGO'
)))
{
// OK
header
(
'ETag: '
.
md5
(
$contact
->
getAsString
(
'LOGO'
)));
}
if
(
$image
->
valid
())
{
$max_size
=
200
;
if
(
$image
->
width
()
>
$max_size
||
$image
->
height
()
>
$max_size
)
{
$image
->
resize
(
$max_size
);
}
$photo = base64_decode($child->value());
header('Content-Type: '.$mime);
header('Content-Length: ' . strlen($photo));
echo $photo;
exit();
}
}
*/
if
(
!
$image
->
valid
())
{
// Not found :-(
//echo $l10n->t('This card does not contain a photo.');
$image
->
loadFromFile
(
'img/person_large.png'
);
}
header
(
'Content-Type: '
.
$image
->
mimeType
());
$image
->
show
();
//echo OC_Contacts_App::$l10n->t('This card does not contain a photo.');
This diff is collapsed.
Click to expand it.
apps/contacts/thumbnail.php
+
39
−
32
View file @
facd4cbe
...
...
@@ -29,15 +29,11 @@ OC_Util::checkAppEnabled('contacts');
function
getStandardImage
(){
$date
=
new
DateTime
(
'now'
);
$date
->
add
(
new
DateInterval
(
'P10D'
));
header
(
'Expires: '
.
$date
->
format
(
DateTime
::
RFC
850
));
header
(
'Expires: '
.
$date
->
format
(
DateTime
::
RFC
2822
));
header
(
'Cache-Control: cache'
);
header
(
'Pragma: cache'
);
header
(
"HTTP/1.1 307 Temporary Redirect"
);
header
(
'Location: '
.
OC_Helper
::
imagePath
(
'contacts'
,
'person.png'
));
exit
();
// $src_img = imagecreatefrompng('img/person.png');
// header('Content-Type: image/png');
// imagepng($src_img);
// imagedestroy($src_img);
}
if
(
!
function_exists
(
'imagecreatefromjpeg'
))
{
...
...
@@ -50,10 +46,10 @@ $id = $_GET['id'];
$l10n
=
new
OC_L10N
(
'contacts'
);
$cont
en
t
=
OC_Contacts_App
::
getContactVCard
(
$id
);
$cont
ac
t
=
OC_Contacts_App
::
getContactVCard
(
$id
);
// invalid vcard
if
(
is_null
(
$cont
en
t
)){
if
(
is_null
(
$cont
ac
t
)){
OC_Log
::
write
(
'contacts'
,
'thumbnail.php. The VCard for ID '
.
$id
.
' is not RFC compatible'
,
OC_Log
::
ERROR
);
getStandardImage
();
exit
();
...
...
@@ -62,34 +58,45 @@ if( is_null($content)){
$thumbnail_size
=
23
;
// Find the photo from VCard.
foreach
(
$content
->
children
as
$child
){
if
(
$child
->
name
==
'PHOTO'
){
$image
=
new
OC_Image
();
if
(
$image
->
loadFromBase64
(
$child
->
value
))
{
$photo
=
$contact
->
getAsString
(
'PHOTO'
);
$etag
=
md5
(
$photo
);
$rev_string
=
$contact
->
getAsString
(
'REV'
);
if
(
$rev_string
)
{
$rev
=
DateTime
::
createFromFormat
(
DateTime
::
W3C
,
$rev_string
);
$last_modified_time
=
$rev
->
format
(
DateTime
::
RFC2822
);
}
else
{
$last_modified_time
=
null
;
}
header
(
'Cache-Control: cache'
);
header
(
'Pragma: cache'
);
if
(
$rev_string
)
{
header
(
'Last-Modified: '
.
$last_modified_time
);
}
header
(
'ETag: '
.
$etag
);
if
(
@
trim
(
$_SERVER
[
'HTTP_IF_MODIFIED_SINCE'
])
==
$last_modified_time
||
@
trim
(
$_SERVER
[
'HTTP_IF_NONE_MATCH'
])
==
$etag
)
{
header
(
'HTTP/1.1 304 Not Modified'
);
exit
;
}
if
(
$image
->
loadFromBase64
(
$photo
))
{
if
(
$image
->
centerCrop
())
{
if
(
$image
->
resize
(
$thumbnail_size
))
{
header
(
'ETag: '
.
md5
(
$child
->
value
));
if
(
!
$image
())
{
OC_Log
::
write
(
'contacts'
,
'thumbnail.php. Couldn\'t display thumbnail for ID '
.
$id
,
OC_Log
::
ERROR
);
getStandardImage
();
if
(
$image
->
show
())
{
exit
();
}
else
{
OC_Log
::
write
(
'contacts'
,
'thumbnail.php. Couldn\'t display thumbnail for ID '
.
$id
,
OC_Log
::
ERROR
);
}
}
else
{
OC_Log
::
write
(
'contacts'
,
'thumbnail.php. Couldn\'t resize thumbnail for ID '
.
$id
,
OC_Log
::
ERROR
);
getStandardImage
();
exit
();
}
}
else
{
OC_Log
::
write
(
'contacts'
,
'thumbnail.php. Couldn\'t crop thumbnail for ID '
.
$id
,
OC_Log
::
ERROR
);
getStandardImage
();
exit
();
}
}
else
{
OC_Log
::
write
(
'contacts'
,
'thumbnail.php. Couldn\'t load image string for ID '
.
$id
,
OC_Log
::
ERROR
);
getStandardImage
();
exit
();
}
exit
();
}
}
getStandardImage
();
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