ElkArte Community

Extending Elk => Addons => Topic started by: ahrasis on December 20, 2014, 09:21:35 am

Title: MWSP: Member's Website & Signature Permission
Post by: ahrasis on December 20, 2014, 09:21:35 am

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.
Title: Re: [WIP] AMWSP - Add Member's Website And Signature Permission Mod
Post by: ahrasis on December 20, 2014, 09:23:07 am
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.
Title: Re: [WIP] AMWSP - Add Member's Website And Signature Permission Mod
Post by: ahrasis on December 20, 2014, 10:19:28 am
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.
Title: Re: [WIP] MWSP - Member's Website & Signature Permission Mod
Post by: ahrasis on December 20, 2014, 11:32:55 am
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.
Title: Re: [WIP] MWSP - Member's Website & Signature Permission Mod
Post by: emanuele on December 20, 2014, 11:47:52 am
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'] = '';
}
Title: Re: [WIP] MWSP - Member's Website & Signature Permission Mod
Post by: ahrasis on December 20, 2014, 01:26:05 pm
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.
Title: Re: [WIP] MWSP - Member's Website & Signature Permission Mod
Post by: emanuele on December 20, 2014, 02:40:59 pm
Quote from: ahrasis – 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.

Quote from: ahrasis – 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.

Quote from: ahrasis – 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).
Title: Re: [WIP] MWSP - Member's Website & Signature Permission Mod
Post by: ahrasis on December 20, 2014, 10:10:33 pm
Quote from: emanuele –
Quote from: ahrasis – 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.
Title: Re: [WIP] MWSP - Member's Website & Signature Permission Mod
Post by: ahrasis on December 20, 2014, 10:50:27 pm
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.
Title: Re: [ADDON] MWSP - Member's Website & Signature Permission
Post by: ahrasis on December 20, 2014, 11:22:36 pm
OP a.k.a. Opening Post has been updated with the final package attached to it.
Title: Re: [ADDON] MWSP - Member's Website & Signature Permission
Post by: emanuele on December 21, 2014, 04:33:28 am
Quote from: ahrasis – 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';
Title: Re: [ADDON] MWSP - Member's Website & Signature Permission
Post by: ahrasis on December 21, 2014, 07:01:34 am
Thank you @emanuele. Though mine is working without errors, I guess that would be the proper way of doing it.
Title: Re: [ADDON] MWSP - Member's Website & Signature Permission
Post by: emanuele on December 21, 2014, 07:33:41 am
OT question: what browser are you using?
Title: Re: [ADDON] MWSP - Member's Website & Signature Permission
Post by: ahrasis on December 21, 2014, 08:14:39 am
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.
Title: Re: [ADDON] MWSP - Member's Website & Signature Permission
Post by: ahrasis on July 26, 2016, 09:31:36 am

Updated...

#Change Logs

@Version 1.0.1
- Cleaning up some code.
- Restructuring addon's directory and location.
Title: Re: [ADDON] MWSP - Member's Website & Signature Permission
Post by: ahrasis on August 11, 2016, 04:41:46 am
#Change Logs

@Version 1.0.2
- Restructuring addon's directory and location again.
Title: Re: MWSP: Member's Website & Signature Permission
Post by: ahrasis on November 01, 2016, 01:27:36 pm
#Change Logs

@Version 1.0.3
- Make it work for 1.1 Beta 3.
Title: Re: MWSP: Member's Website & Signature Permission
Post by: radu81 on September 21, 2017, 03:29:41 am
Just tested and works fine with 1.1 RC2. Thanks @ahrasis‍ 
Title: Re: MWSP: Member's Website & Signature Permission
Post by: ahrasis on September 21, 2017, 03:51:13 am
Thank you for testing it on 1.1 RC2.
Title: Re: MWSP: Member's Website & Signature Permission
Post by: radu81 on January 03, 2018, 02:26:15 pm
@ahrasis‍ will be possible to add a feature to disable signatures to guests?
thank you in advance
Title: Re: MWSP: Member's Website & Signature Permission
Post by: ahrasis on January 03, 2018, 08:20:42 pm
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.
Title: Re: MWSP: Member's Website & Signature Permission
Post by: radu81 on January 03, 2018, 08:48:19 pm
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 ;)
Title: Re: MWSP: Member's Website & Signature Permission
Post by: ahrasis on January 03, 2018, 10:18:42 pm
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.[1]
You can use a patch file to avoid that.
Title: Re: MWSP: Member's Website & Signature Permission
Post by: radu81 on January 04, 2018, 06:07:18 am
I already solve it, thanks for your attention.