diff options
-rw-r--r-- | Zotlabs/Module/Photo.php | 48 | ||||
-rw-r--r-- | doc/hook/get_profile_photo.bb | 18 | ||||
-rw-r--r-- | doc/hooklist.bb | 3 |
3 files changed, 52 insertions, 17 deletions
diff --git a/Zotlabs/Module/Photo.php b/Zotlabs/Module/Photo.php index a16206299..d37ae07ac 100644 --- a/Zotlabs/Module/Photo.php +++ b/Zotlabs/Module/Photo.php @@ -59,20 +59,33 @@ 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), diff --git a/doc/hook/get_profile_photo.bb b/doc/hook/get_profile_photo.bb new file mode 100644 index 000000000..ab07179ae --- /dev/null +++ b/doc/hook/get_profile_photo.bb @@ -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. + + diff --git a/doc/hooklist.bb b/doc/hooklist.bb index 858a7d021..e48fbee7c 100644 --- a/doc/hooklist.bb +++ b/doc/hooklist.bb @@ -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 |