From 939ce5e44c049b0897899c8c7a79544068d2e3b3 Mon Sep 17 00:00:00 2001 From: marcus Date: Wed, 8 Oct 2008 11:27:00 +0000 Subject: Closes #301: Profile icons now use getIcon() API. Overrides now possible: For themes to override, create a plugin hook listening to 'entity:icon:url' and object 'user'. In the hook return a different url. To replace default user icons in a plugin one might create a hook: function profile_usericon_hook($hook, $entity_type, $returnvalue, $params) { if ((!$returnvalue) && ($params['entity'] instanceof ElggUser)) { // return your default graphic here. } } And set it to priority 900 (lower priority than the code that displays a pretty icon for users but higher than the default object display code in entities.php) git-svn-id: https://code.elgg.org/elgg/trunk@2221 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/profile/start.php | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) (limited to 'mod/profile/start.php') diff --git a/mod/profile/start.php b/mod/profile/start.php index ff9d142a5..811bffbbd 100644 --- a/mod/profile/start.php +++ b/mod/profile/start.php @@ -65,7 +65,10 @@ if (isadminloggedin()) { extend_view('profile/menu/links','profile/menu/adminwrapper',10000); - } + } + + // Now override icons + register_plugin_hook('entity:icon:url', 'user', 'profile_usericon_hook'); } /** @@ -127,6 +130,48 @@ function profile_url($user) { global $CONFIG; return $CONFIG->wwwroot . "pg/profile/" . $user->username; + } + + /** + * This hooks into the getIcon API and provides nice user icons for users where possible. + * + * @param unknown_type $hook + * @param unknown_type $entity_type + * @param unknown_type $returnvalue + * @param unknown_type $params + * @return unknown + */ + function profile_usericon_hook($hook, $entity_type, $returnvalue, $params) + { + global $CONFIG; + + if ((!$returnvalue) && ($hook == 'entity:icon:url') && ($params['entity'] instanceof ElggUser)) + { + $entity = $params['entity']; + $type = $entity->type; + $subtype = get_subtype_from_id($entity->subtype); + $viewtype = $params['viewtype']; + $size = $params['size']; + $username = $entity->username; + + if ($icontime = $entity->icontime) { + $icontime = "{$icontime}"; + } else { + $icontime = "default"; + } + + + $filehandler = new ElggFile(); + $filehandler->owner_guid = $entity->getGUID(); + $filehandler->setFilename("profile/" . $username . $size . ".jpg"); + + if ($filehandler->open("read")) { + $url = $CONFIG->url . "pg/icon/$username/$size/$icontime.jpg"; + + + return $url; + } + } } // Make sure the profile initialisation function is called on initialisation @@ -136,7 +181,9 @@ global $CONFIG; register_action("profile/edit",false,$CONFIG->pluginspath . "profile/actions/edit.php"); register_action("profile/iconupload",false,$CONFIG->pluginspath . "profile/actions/iconupload.php"); - register_action("profile/cropicon",false,$CONFIG->pluginspath . "profile/actions/cropicon.php"); + register_action("profile/cropicon",false,$CONFIG->pluginspath . "profile/actions/cropicon.php"); + + // Define widgets for use in this context use_widgets('profile'); -- cgit v1.2.3