MWSP: Member's Website & Signature Permission
- For ElkArte 1.0.x and 1.1 Beta x.
- Fully hook, no file modification.
1. Please do your own backup though every installation is backed up automatically.
2. By default, forum members are usually allowed to have their own signatures and websites (links and names).
3. All these are shown at display (post), personal message, profile summary, message list etc (are there any more?).
4. Some of these are annoying and forum admins or owners dislike this, (or they want to charge some payment for them :P).
5. Using this mod added permission, forum admins / owners can decide which groups are allowed to have these option available.
6. This mod should automatically stop displaying all members' signatures and websites until permission is assigned.
7. Admin groups shall always have the privilege to have both options and can see previously set members' signatures and websites.
8. You can test it in all lower ElkArte 1.0.x version too as IMO it should work just fine. ;)
9. Special thanks to emanuele in making this a fully hook version.
Thank you for using/testing it.
Yours friendly,
Abu Fahim Ismail.
BSD License. Feel free to modify accordingly but keep original and current authors' link(s) if it is in there somewhere. ;)
(http://validator.w3.org/images/valid_icons/valid-xhtml10) (http://jigsaw.w3.org/css-validator/images/vcss)
#Change Logs
@Version 1.0.3
- Make it work for 1.1 Beta 3.
@Version 1.0.2
- Restructuring addon's directory and location again.
@Version 1.0.1
- Cleaning up some code.
- Restructuring addon's directory and location.
@Version 1.0.0
- Initial fully hook release.
I have created two mods for SMF 2.0 (one is actually by Joker :P ) and am hoping to create the same in single addon here using hook technique. Any help, tips, guides will be much appreciated. I am looking at permission hook in ManagePermissions.subs.php and Profile.subs.php.
In SMF 2.0, I also hack into Load.php but there may be other ways to achieve the same here. The purpose of hacking into Load.php is to ensure that website url is considered empty if the permission has not been assigned to the membergroup but they must be able to see member's website and signature from the group allowed to have website and signature.
These two permissions will be a separate permission so the admin can choose whether they can have both or just any one of them.
The following code in Profile.subs.php will need to be unset or something before setting the new one.
'signature' => array(
'type' => 'callback',
'callback_func' => 'signature_modify',
'permission' => 'profile_extra',
'enabled' => substr($modSettings['signature_settings'], 0, 1) == 1,
'preload' => 'profileLoadSignatureData',
'input_validate' => 'profileValidateSignature',
),
'website_title' => array(
'type' => 'text',
'label' => $txt['website_title'],
'subtext' => $txt['include_website_url'],
'size' => 50,
'permission' => 'profile_extra',
'link_with' => 'website',
),
'website_url' => array(
'type' => 'url',
'label' => $txt['website_url'],
'subtext' => $txt['complete_url'],
'size' => 50,
'permission' => 'profile_extra',
// Fix the URL...
'input_validate' => create_function('&$value', '
if (strlen(trim($value)) > 0 && strpos($value, \'://\') === false)
$value = \'http://\' . $value;
if (strlen($value) < 8 || (substr($value, 0, 7) !== \'http://\' && substr($value, 0, 8) !== \'https://\'))
$value = \'\';
return true;
'),
'link_with' => 'website',
While this one, in Load.php, I dont know what to do with it yet. Manual modification is my original way. May be unset too?
'website' => array(
'title' => $profile['website_title'],
'url' => $profile['website_url'],
),
And this one too. I missed it.
'signature' => $profile['signature'],
And add some permission in using ManagePermissions.php. Let's see how this goes.
Edited. Add left out code to change in this add on.
I managed to package and test it quite fast with ElkArte hook system. ;)
But it is not perfected yet. I cannot get the permissionhelp to show for both website and signature though their names are well appearing. Plus, I haven't test the functionalities, just tested the installation and it look in permission page. Lol.
Those who wishes to test, I attached the testing package here.
I will update again soon.
Edited - Package removed as fully working version is already attached in OP.
Manually, this is how I add these three code in Load.php.
require_once(SUBSDIR . '/Members.subs.php');
// If the set isn't minimal then load the monstrous array
'url' => (allowedTo('add_signature') || in_array($user, membersAllowedTo('add_website')) ? $profile['website_url'] : ''),
'signature' => (allowedTo('add_signature') || in_array($user, membersAllowedTo('add_signature')) ? $profile['signature'] : ''),
And it still works in ElkArte. Currently, I am trying this on:
function MWSP_redefine_member_contexts(&$user)
{
require_once(SUBSDIR . '/Members.subs.php');
if (isset($user['website']['url']))
unset($user['website']['url']);
$user['website']['url'] = (allowedTo('add_signature') || in_array($user, membersAllowedTo('add_website')) ? $profile['website_url'] : '');
if (isset($user['signature']))
unset($user['signature']);
$user['signature'] = (allowedTo('add_signature') || in_array($user, membersAllowedTo('add_signature')) ? $profile['signature'] : '');
}
The hook is:
'integrate_member_context' => 'MWSP_redefine_member_contexts|SOURCEDIR/addons/MWSP.subs.php',
But it doesn't work. Any ideas why and how to overcome this? ::)
For the permission, I am using these code:
function MWSP_add_user_permissions(&$permissionGroups, &$permissionList)
{
require_once(SUBSDIR . '/Members.subs.php');
// Load language(s)
loadLanguage('MWSP');
// Add permission(s)
$permissionList['membergroup']['add_website'] = array(false, 'profile', 'add_website');
$permissionList['membergroup']['add_signature'] = array(false, 'profile', 'add_signature');
}
The permissionname text is loaded fine. Permission can also be checked and unchecked fine. But the permissionhelp text is not loaded. Make me a bit confused. Will test some more and update.
Latest package is attached.
Meanwhile, please feel free to give comments and feedbacks.
Edited - Package removed as fully working version is already attached in OP.
The $user passed by integrate_member_context is not an array, but an id_member, that can be used to access the user that the function is loading through $memberContext, so something like this:
function MWSP_redefine_member_contexts(&$user)
{
global $memberContext;
require_once(SUBSDIR . '/Members.subs.php');
if (isset($memberContext[$user]['website']['url']))
unset($memberContext[$user]['website']['url']);
$memberContext[$user]['website']['url'] = (allowedTo('add_signature') || in_array($user, membersAllowedTo('add_website')) ? $profile['website_url'] : '');
if (isset($memberContext[$user]['signature']))
unset($user['signature']);
$memberContext[$user]['signature'] = (allowedTo('add_signature') || in_array($user, membersAllowedTo('add_signature')) ? $memberContext[$user]['signature'] : '');
}
Also, $profile is not available in the function you created, it's something available only in loadMemberContext unless you "grab" it globalizing $user_profile and assigning it explicitly like this:
function MWSP_redefine_member_contexts(&$user)
{
global $memberContext, $user_profile;
$profile = $user_profile[$user];
but I feel this is not necessary if I understood properly what you want to obtain, this should work as well:
function MWSP_redefine_member_contexts(&$user)
{
global $memberContext;
require_once(SUBSDIR . '/Members.subs.php');
if (!allowedTo('add_signature') && !in_array($user, membersAllowedTo('add_website'))
$memberContext[$user]['website']['url'] = '';
if (!allowedTo('add_signature') && !in_array($user, membersAllowedTo('add_signature'))
$memberContext[$user]['signature'] = '';
}
Thank you very much
@emanuele. Like always, you are the saver. The key problem that prolong the test was &$user. It is just $user without &. Removing that makes all tests go smoother. Major problems stated above have been eliminated.
Few minor problems to highlight is that:
1. permissionhelp_ is not respected by ElkArte when loaded from (&$permissionGroups, &$permissionList). >:( I need to go around by calling just text from integrate_pre_load. Is there any other way?
2. How to add the permission to non_guest list. It shows in guest permission page. There is no hook that I can find to stop it, not yet. :'(
3. Admin can still see user's previously set signature or website. (This is ok actually and can be deal with in the future). :D
Latest package is attached here until I have time to update the OP.
Edited - Package removed as fully working version is already attached in OP.
I can't see how use loadLanguage in pre_load is any different from calling it at the beginning of MWSP_add_user_permissions if that is the problem.
It's in $context, just globalize that and add to the array.
Well, when you deal with permissions, admin are special (as anyone with the permission to do something).
May be you can look into it. It doesn't fully work when it is called from MWSP_add_user_permission. As stated earlier, permissionname work just fine but not permissionhelp. May be an ElkArte bug?
As to $context, I think I get it. Will try -1 group to be excluded. Will report soon.
Finish updating the mod with the exception of minor problem #1.
#2 is resolved by globalizing $context and changing the original code to the following code:
function MWSP_add_user_permissions(&$permissionGroups, &$permissionList)
{
global $context;
// Load language(s)
loadLanguage('MWSP');
// Add permission(s)
if (isset($context['group']['id']) && $context['group']['id'] != -1) {
$permissionList['membergroup']['add_website'] = array(false, 'profile', 'add_website');
$permissionList['membergroup']['add_signature'] = array(false, 'profile', 'add_signature');
}
}
As mentioned earlier #3 is not truly a problem. As stated by
@emanuele, as it is based on permission, admin will always have the privilege of seeing and accessing what others cannot.
I will update the OP and attach the final package mod soonest.
OP a.k.a. Opening Post has been updated with the final package attached to it.
Actually, what I wanted to say is that you can just do:
global $context;
$context['non_guest_permissions'][] = 'add_website';
$context['non_guest_permissions'][] = 'add_signature';
Thank you @emanuele. Though mine is working without errors, I guess that would be the proper way of doing it.
OT question: what browser are you using?
Most of the time I am using chrome for browsing and testing. Firefox is used only to test other user/membergroup. I rarely use IE and Safari.
Updated...
#Change Logs
@Version 1.0.1
- Cleaning up some code.
- Restructuring addon's directory and location.
#Change Logs
@Version 1.0.2
- Restructuring addon's directory and location again.
#Change Logs
@Version 1.0.3
- Make it work for 1.1 Beta 3.
Just tested and works fine with 1.1 RC2. Thanks
@ahrasis
Thank you for testing it on 1.1 RC2.
@ahrasis will be possible to add a feature to disable signatures to guests?
thank you in advance
It shouldn't be that hard. Let me revisit this addon and relevant code first.
Edited: I think this addon is mainly about permission, while what you want
@radu81, may not need a permission to achieve it. A very lazy simpler approach is to add a code where if user is a guest, add css that hide the signature. Other way, stop signature from loading for guest.
Well, I am not so good about the other way though I can try but
@emanuele or @Spuds may know how to create them better. The first approach is definitely easy to do for now.
I think is better to wait for a response here https://www.elkarte.net/community/index.php?topic=4838 ... who knows, probably we'll see it into the core of elkarte ;)
It seems like you have it solved already. If it is not made a feature, you can still use the same code via an addon rather than using a modification like that, since the Load.php will, most most of the time, be replaced in a full update / upgrade.
I already solve it, thanks for your attention.