make the fetching of the default profile photo hookable, and document the hook
This commit is contained in:
parent
3bf0a27e45
commit
eff2e6c795
@ -60,19 +60,32 @@ class Photo extends \Zotlabs\Web\Controller {
|
||||
|
||||
$uid = $person;
|
||||
|
||||
$r = q("SELECT * FROM photo WHERE imgscale = %d AND uid = %d AND photo_usage = %d LIMIT 1",
|
||||
intval($resolution),
|
||||
intval($uid),
|
||||
intval(PHOTO_PROFILE)
|
||||
);
|
||||
if($r) {
|
||||
$data = dbunescbin($r[0]['content']);
|
||||
$mimetype = $r[0]['mimetype'];
|
||||
$d = [ 'imgscale' => $resolution, 'channel_id' => $uid, 'default' => $default, 'data' => '', 'mimetype' => '' ];
|
||||
call_hooks('get_profile_photo',$d);
|
||||
|
||||
$resolution = $d['resolution'];
|
||||
$uid = $d['channel_id'];
|
||||
$default = $d['default'];
|
||||
$data = $d['data'];
|
||||
$mimetype = $d['mimetype'];
|
||||
|
||||
if(! $data) {
|
||||
$r = q("SELECT * FROM photo WHERE imgscale = %d AND uid = %d AND photo_usage = %d LIMIT 1",
|
||||
intval($resolution),
|
||||
intval($uid),
|
||||
intval(PHOTO_PROFILE)
|
||||
);
|
||||
if($r) {
|
||||
$data = dbunescbin($r[0]['content']);
|
||||
$mimetype = $r[0]['mimetype'];
|
||||
}
|
||||
if(intval($r[0]['os_storage']))
|
||||
$data = file_get_contents($data);
|
||||
}
|
||||
if(intval($r[0]['os_storage']))
|
||||
$data = file_get_contents($data);
|
||||
if(! isset($data)) {
|
||||
if(! $data) {
|
||||
$data = file_get_contents($default);
|
||||
}
|
||||
if(! $mimetype) {
|
||||
$mimetype = 'image/png';
|
||||
}
|
||||
}
|
||||
@ -88,6 +101,7 @@ class Photo extends \Zotlabs\Web\Controller {
|
||||
Project link: https://github.com/Retina-Images/Retina-Images
|
||||
License link: http://creativecommons.org/licenses/by/3.0/
|
||||
*/
|
||||
|
||||
$cookie_value = false;
|
||||
if (isset($_COOKIE['devicePixelRatio'])) {
|
||||
$cookie_value = intval($_COOKIE['devicePixelRatio']);
|
||||
@ -114,15 +128,15 @@ class Photo extends \Zotlabs\Web\Controller {
|
||||
}
|
||||
|
||||
// If using resolution 1, make sure it exists before proceeding:
|
||||
if ($resolution == 1)
|
||||
{
|
||||
if($resolution == 1) {
|
||||
$r = q("SELECT uid FROM photo WHERE resource_id = '%s' AND imgscale = %d LIMIT 1",
|
||||
dbesc($photo),
|
||||
intval($resolution)
|
||||
);
|
||||
if (!($r))
|
||||
);
|
||||
if(! $r) {
|
||||
$resolution = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$r = q("SELECT uid FROM photo WHERE resource_id = '%s' AND imgscale = %d LIMIT 1",
|
||||
dbesc($photo),
|
||||
|
18
doc/hook/get_profile_photo.bb
Normal file
18
doc/hook/get_profile_photo.bb
Normal file
@ -0,0 +1,18 @@
|
||||
[h2]get_profile_photo[/h2]
|
||||
|
||||
Called when fetching the content of the default profile photo for a local channel in mod_photo.
|
||||
|
||||
|
||||
Hook arguments:
|
||||
|
||||
'imgscale' => integer resolution requested (4, 5, or 6)
|
||||
'channel_id' => channel_id of requested profile photo
|
||||
'default' => filename of default profile photo of this imgscale
|
||||
'data' => empty string
|
||||
'mimetype' => empty string
|
||||
|
||||
|
||||
If 'data' is set, this data will be used instead of the data obtained from the database search for the profile photo.
|
||||
If 'mimetype' is set, this mimetype will be used instead of the mimetype obtained from the database or the default profile photo mimetype.
|
||||
|
||||
|
@ -236,6 +236,9 @@ Hooks allow plugins/addons to "hook into" the code at many points and alter the
|
||||
[zrl=[baseurl]/help/hook/get_features]get_features[/zrl]
|
||||
Called when get_features() is called
|
||||
|
||||
[zrl=[baseurl]/help/hook/get_profile_photo]get_profile_photo[/zrl]
|
||||
Called when local profile photo content is fetched in mod_photo
|
||||
|
||||
[zrl=[baseurl]/help/hook/get_role_perms]get_role_perms[/zrl]
|
||||
Called when get_role_perms() is called to obtain permissions for named permission roles
|
||||
|
||||
|
Reference in New Issue
Block a user