Change poster ID or post as another user

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
Flerex
Registered User
Posts: 57
Joined: Sun Oct 14, 2012 8:35 pm
Location: Galicia, Spain
Name: Flerex
Contact:

Change poster ID or post as another user

Post by Flerex » Sun Jul 01, 2018 5:42 pm

Hello!

I was trying to add a new feature to my extension that would allow users to reply to posts as another user and change some of their posts' ownership when I stumbled upon an implementation problem. I tried to find a way to accomplish this in phpBB but I couldn't find anything. I did some research and came to the following conclusion:

The submit_post function in includes/function_posting.php has a $data array parameter with poster_id but it is not used to post as that user. This makes it pointless to wait for the core.posting_modify_submit_post_before event as there's no way to change the poster before the post is actually published.

There exists a change_post function under includes/mcp/mcp_post.php that's part of the MCP's feature to change the poster of a given post. Unfortunatelly, this function is not accessible from within the post creation and edit interface because it's only included in includes/mcp/mcp_main.php.

This function would allow me to accomplish what I want by doing extra queries (not ideal but would do the trick) after the post is already published using the core.posting_modify_submit_post_after event.

What should I do? Is it okay if I just include the file containing this function in the posting interface (from withing my extension, of course) or should I implement this functionality (copy & paste it)? Am I missing something? Is there any other way to do this? Maybe an easier way?

Thanks for your attention.

User avatar
david63
Jr. Extension Validator
Posts: 14559
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Change poster ID or post as another user

Post by david63 » Sun Jul 01, 2018 6:07 pm

That is a built in Moderator function - you should be able to follow it from there
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
3Di
Registered User
Posts: 12753
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Change poster ID or post as another user

Post by 3Di » Sun Jul 01, 2018 6:13 pm

Code: Select all

		if (!function_exists('change_poster'))
		{
			include($this->root_path . 'includes/mcp/mcp_post.' . $this->php_ext);
		}
Usage: change_poster($post_info, $userdata);

Lurk at the native code in order to provide the 2 arrays of data necessary.
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

User avatar
Flerex
Registered User
Posts: 57
Joined: Sun Oct 14, 2012 8:35 pm
Location: Galicia, Spain
Name: Flerex
Contact:

Re: Change poster ID or post as another user

Post by Flerex » Sun Jul 01, 2018 6:24 pm

Yeah, I already know that. I was mostly asking if it is a good practice to include this file from withing my extension, but I suppose it is.

Thank you guys.

User avatar
3Di
Registered User
Posts: 12753
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Change poster ID or post as another user

Post by 3Di » Sun Jul 01, 2018 6:30 pm

That's the same if you include submit_post() or submit_pm() or any other stuff.

You said you want the users to be able to change some of their posts' ownership too, that's a sensitive operation which I suggest to use the above inclusion/function, if it were only to post a reply with another username/ID (like a Bot) then I do have another solution which doesn't use that approach at all and takes care of the last_post() stuffs (forums etc..) in a elegant way.. by my opinion eheh..
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

User avatar
Flerex
Registered User
Posts: 57
Joined: Sun Oct 14, 2012 8:35 pm
Location: Galicia, Spain
Name: Flerex
Contact:

Re: Change poster ID or post as another user

Post by Flerex » Sun Jul 01, 2018 6:36 pm

Mmmm. Is there any difference between changing the ownership of a post and it's poster ID? I said ownership meaning the poster id. I would like to see your approach if you don't mind.

User avatar
3Di
Registered User
Posts: 12753
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Change poster ID or post as another user

Post by 3Di » Sun Jul 01, 2018 6:56 pm

It's a bit complicated to explain, let's see..
Flerex wrote:
Sun Jul 01, 2018 5:42 pm
I was trying to add a new feature to my extension that would allow users to reply to posts as another user
Flerex wrote:
Sun Jul 01, 2018 5:42 pm
The submit_post function in includes/function_posting.php has a $data array parameter with poster_id but it is not used to post as that user. This makes it pointless to wait for the core.posting_modify_submit_post_before event as there's no way to change the poster before the post is actually published.
You should just use core.submit_post_modify_sql_data
https://github.com/phpBB-Studio/DateTop ... #L473-L509

in combo with submit_post() (reply mode)
https://github.com/phpBB-Studio/DateTop ... #L576-L643

Note the three lines added to submit_post() previously instantiated within the listener
https://github.com/phpBB-Studio/DateTop ... #L637-L639

Now in the controller we are sending (posting) a reply with another user/bot (which have their settings in ACP)
https://github.com/phpBB-Studio/DateTop ... r.php#L654

To take care of the last_post() thinghy, here is what we did..
https://github.com/phpBB-Studio/DateTop ... #L656-L699

Hope that helps, you can surely go ahead and in case.. ask.
Last edited by 3Di on Tue Jul 03, 2018 7:52 pm, edited 1 time in total.
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

User avatar
Flerex
Registered User
Posts: 57
Joined: Sun Oct 14, 2012 8:35 pm
Location: Galicia, Spain
Name: Flerex
Contact:

Re: Change poster ID or post as another user

Post by Flerex » Mon Jul 02, 2018 3:31 pm

I decided to go with the “include” way because the code is getting to complex and I don't want to also have to wonder about with all that implementation. Thank you tho!

User avatar
3Di
Registered User
Posts: 12753
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Change poster ID or post as another user

Post by 3Di » Mon Jul 02, 2018 6:18 pm

No probs, that's for the posterity too.

In the meantime, I have found a glitch.. I forgot to include the forum's parents. :P
I will update the post with the fix as soon as I have time. Currently I am under a pile of code so to speak.
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

User avatar
3Di
Registered User
Posts: 12753
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Change poster ID or post as another user

Post by 3Di » Tue Jul 03, 2018 2:16 pm

3Di wrote:
Mon Jul 02, 2018 6:18 pm
I have found a glitch.. I forgot to include the forum's parents. :P
To add to the above list of snippets, perma-link edited.

The last post() thinghy has been fully covered now.
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: No registered users and 5 guests