Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gravatar support for images #546

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion include/photo_handler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ public static function getDataURL($type, $id)
}
}

public static function hasPhotoData($type, $id) {
$db = $GLOBALS['db'];
$SQL = $obj = NULL;
if ($type == 'person') {
$obj = $GLOBALS['system']->getDBObject('person', (int)$id);
if ($obj) $SQL = 'SELECT COUNT(photodata) FROM person_photo WHERE personid = '.$obj->id;
}
if ($obj) {
$res = $GLOBALS['db']->queryOne($SQL);
if ($res) {
return $res;
}
}
}

public static function getPhotoData($type, $id)
{
$db = $GLOBALS['db'];
Expand Down Expand Up @@ -147,4 +162,4 @@ public static function getPhotoData($type, $id)
}
}

}
}
13 changes: 13 additions & 0 deletions resources/less/jethro.less.php
Original file line number Diff line number Diff line change
Expand Up @@ -851,12 +851,25 @@
float: left;
margin-right: 15px;
}
.person-photo-with-gravatar-div {
float: left;
position: relative;
}
img.person-photo {
width: 200px;
float: left;
border-radius: 5px;
border: 1px solid @jethroDarkest;
}
img.person-photo-gravatar {
width: 200px;
float: left;
border-radius: 5px;
border: 1px solid @jethroDarkest;
position: absolute;
top: 0;
left: 0;
}
.details-box {
box-sizing: border-box;
-webkit-box-sizing: border-box;
Expand Down
18 changes: 15 additions & 3 deletions templates/view_family.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,21 @@
<div class="family-member">
<?php
if ($GLOBALS['system']->featureEnabled('PHOTOS')) {
?>
<img src="?call=photo&personid=<?php echo $personid; ?>" />
<?php
if (Photo_Handler::hasPhotoData('person', $personid)) {
?>
<img src="?call=photo&personid=<?php echo $personid; ?>" />
<?php
} else {
$gravatarURL = "https://www.gravatar.com/avatar/" .
md5( strtolower( trim( $dummy->getValue('email') ) ) ) .
"?d=blank" . "&s=70";
?>
<div class="person-photo-with-gravatar-div">
<img width="70" src="?call=photo&personid=<?php echo $personid; ?>"/>
<img width="70" src="<?php echo $gravatarURL ?>" style="position: absolute; top: 0; right: 0;"/>
</div>
<?php
}
}
?>
<label>
Expand Down
31 changes: 26 additions & 5 deletions templates/view_person.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@
/**************** BASIC DETAILS TAB *************/

printf($panel_header, 'basic', _('Basic Details'), 'active');
if ($GLOBALS['system']->featureEnabled('PHOTOS')) {

}
?>
<div class="person-details">

Expand Down Expand Up @@ -199,18 +202,36 @@

<?php
if ($accordion && $GLOBALS['system']->featureEnabled('PHOTOS')) {
?>
<img class="person-photo" src="?call=photo&personid=<?php echo (int)$person->id; ?>" />
<?php
if (Photo_Handler::hasPhotoData('person', $person->id)) {
?>
<img class="person-photo" alt="has photo" src="?call=photo&personid=<?php echo (int)$person->id; ?>" />
<?php
} else {
?>
<img class="person-photo" alt="no photo" src="?call=photo&personid=<?php echo (int)$person->id; ?>" />
<?php
}
}
?>
</div>

<?php
if (!$accordion && $GLOBALS['system']->featureEnabled('PHOTOS')) {
?>
if (Photo_Handler::hasPhotoData('person', $person->id)) {
?>
<img class="person-photo" width="<?php echo Photo_Handler::MAX_PHOTO_WIDTH; ?>" src="?call=photo&personid=<?php echo (int)$person->id; ?>" />
<?php
<?php
} else {
$gravatarURL = "https://www.gravatar.com/avatar/" .
md5( strtolower( trim( $person->getValue('email') ) ) ) .
"?d=blank" . "&s=" . Photo_Handler::MAX_PHOTO_WIDTH;
?>
<div class="person-photo-with-gravatar-div">
<img class="person-photo" width="<?php echo Photo_Handler::MAX_PHOTO_WIDTH; ?>" height="<?php echo Photo_Handler::MAX_PHOTO_WIDTH; ?>" src="?call=photo&personid=<?php echo (int)$person->id; ?>"/>
<img class="person-photo-gravatar" width="<?php echo Photo_Handler::MAX_PHOTO_WIDTH; ?>" src="<?php echo $gravatarURL ?>"/>
</div>
<?php
}
}
?>
<br class="clearfix" />
Expand Down