Skip to main content
Topic: MWSP: Member's Website & Signature Permission (Read 2188 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

MWSP: Member's Website & Signature Permission


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. ;)

 


#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.

Re: [WIP] AMWSP - Add Member's Website And Signature Permission Mod

Reply #1
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.

Code: [Select]
		'signature' => array(
'type' => 'callback',
'callback_func' => 'signature_modify',
'permission' => 'profile_extra',
'enabled' => substr($modSettings['signature_settings'], 0, 1) == 1,
'preload' => 'profileLoadSignatureData',
'input_validate' => 'profileValidateSignature',
),

Code: [Select]
		'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?

Code: [Select]
			'website' => array(
'title' => $profile['website_title'],
'url' => $profile['website_url'],
),

And this one too. I missed it.
Code: [Select]
'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.

Re: [WIP] AMWSP - Add Member's Website And Signature Permission Mod

Reply #2
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.

Re: [WIP] MWSP - Member's Website & Signature Permission Mod

Reply #3
Manually, this is how I add these three code in Load.php.

Code: [Select]
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:

Code: [Select]
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:
Code: [Select]
	'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:

Code: [Select]
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.

Re: [WIP] MWSP - Member's Website & Signature Permission Mod

Reply #4
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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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'] = '';
}
Bugs creator.
Features destroyer.
Template killer.

Re: [WIP] MWSP - Member's Website & Signature Permission Mod

Reply #5
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.

Re: [WIP] MWSP - Member's Website & Signature Permission Mod

Reply #6
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?
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.

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.  :'(
It's in $context, just globalize that and add to the array.

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
Well, when you deal with permissions, admin are special (as anyone with the permission to do something).
Bugs creator.
Features destroyer.
Template killer.

Re: [WIP] MWSP - Member's Website & Signature Permission Mod

Reply #7
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?
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.
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.

Re: [WIP] MWSP - Member's Website & Signature Permission Mod

Reply #8
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:

Code: [Select]
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.

Re: [ADDON] MWSP - Member's Website & Signature Permission

Reply #9
OP a.k.a. Opening Post has been updated with the final package attached to it.

Re: [ADDON] MWSP - Member's Website & Signature Permission

Reply #10
As to $context, I think I get it. Will try -1 group to be excluded. Will report soon.
Actually, what I wanted to say is that you can just do:
Code: [Select]
global $context;

$context['non_guest_permissions'][] = 'add_website';
$context['non_guest_permissions'][] = 'add_signature';
Bugs creator.
Features destroyer.
Template killer.

Re: [ADDON] MWSP - Member's Website & Signature Permission

Reply #11
Thank you @emanuele. Though mine is working without errors, I guess that would be the proper way of doing it.

Re: [ADDON] MWSP - Member's Website & Signature Permission

Reply #12
OT question: what browser are you using?
Bugs creator.
Features destroyer.
Template killer.

Re: [ADDON] MWSP - Member's Website & Signature Permission

Reply #13
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.

Re: [ADDON] MWSP - Member's Website & Signature Permission

Reply #14

Updated...

#Change Logs

@Version 1.0.1
- Cleaning up some code.
- Restructuring addon's directory and location.