View Full Version : Allow all members to edit first post of a thread if it has certain prefix
I would like to make it so that any member of my forum can edit the first post of a thread if it had a specific prefix.
EG: When a member posts a thread, they can choose a prefix called "editable", which then allows any member of the forum to edit that post.
So like, on my gaming forum, if I have a thread dedicated to one console, the first post can be used to keep track of all the latest news. I want to be able to use it as an index type of thing where users can add links to news articles etc with a few other ideas floating around in my head.
I tried doing it for ages but couldn't get it to work. What I did was ducplicate the "editpost.php" file and called the duplicate "editable.php". I tried adding some conditonals for the prefix but I'm not exactly very good at php so I couldn't figure out how to edit the permissions while fitting the conditional in :p
Thanks!
BirdOPrey5
03-03-2012, 05:26 PM
This idea grabs my attention- I have some ideas I may play around with. No promises or estimate though so if someone else wants to do this feel free to jump in.
Simon Lloyd
03-04-2012, 10:09 AM
Here's my first shot at it, i haven't tested tested it minimally on test forum, so you can be the guinea pig :)
BOP5, feel free to take this and edit change it to make it work if it doesn't, i just saw this post and knew i could knock something out that may help :)
BirdOPrey5
03-04-2012, 10:55 AM
Here's my first shot at it, i haven't tested tested it minimally on test forum, so you can be the guinea pig :)
BOP5, feel free to take this and edit change it to make it work if it doesn't, i just saw this post and knew i could knock something out that may help :)
Thanks but I don't think that is what he is looking for. This will allow the original author to edit the first post indefinitely...
He wants to allow ALL users to be able to edit the first post- almost like a "Wiki"
My thought was to mark a thread as a "Wiki Thread" and if it was marked as a "Wiki Thread" go ahead and show the "Edit" button to everyone and then allow everyone to edit it.
In my testing so far however editpost.php does not have the hooks necessary to bypass the permissions- so what I'm trying to figure out is if I can intercept the permissions themselves somewhere to give everyone permission to edit a wiki-thread.
Unfortunately making a copy of editpost.php without the permission checks isn't working either... It's actually very very weird behavior- it seems to update the post cache but somewhere along the line another permission check must fail and it doesn't update the post... so it looks like it works but a little later when I come back all the "edits" I thought I did had been "magically" undone... so that is definitely not the avenue to pursue IMO.
The key to this is going to be if I can do a test for when vBulletin builds its permissions and override them when on a wiki-thread ($thread['iswiki'] == 1 for example).
Simon Lloyd
03-04-2012, 11:00 AM
From my effort you could just remove the $this->registry->userinfo['userid'] == $post['userid'], the post is then always editable by anyone in the selected groups in vboptions only if the post has the prefix, isn't that how it would work?
Simon Lloyd
03-04-2012, 11:07 AM
Just checked it and it seems to work :)
BirdOPrey5
03-04-2012, 11:11 AM
Your mod will show the edit link, no problem... but if you actually try to edit a post as a different/non-mod user you will get a permission error because editpost.php checks for permission to edit the post before doing anything else.
Simon Lloyd
03-04-2012, 11:59 AM
I did try on my test forum as editing as different user, the edit window opened fine (i didnt edit though, maybe i should check that too :))
BirdOPrey5
03-04-2012, 12:01 PM
Yeah, it's when you try to save the edit the permissions kick in.
Simon Lloyd
03-04-2012, 04:21 PM
Yes i see, when i get home i'm going to mess with GETting the users usergroupid and save it as a variable, change their usergroup to say moderator at postdata_presave then back to their original at postdata_postsave i know thats 3 queries but it's hardly going to happen very often, i'll have to see what time i've got when i get home.
Thanks for the replies guys, I actually managed to do it a week or so ago (forgot to update here since I've been busy and working on a games wiki section (http://www.nintendolounge.com/forum/forumdisplay.php?f=31) which will also end up using this, so I kinda forgot about this thread :o)
Basically, what I did, was duplicate editpost.php, and called it wikiedit.php. Then, from the wikiedit.php file I removed all of this;
// ############################### start permissions checking ###############################
if ($_REQUEST['do'] == 'deletepost')
{
// is post being deleted? if so check delete specific permissions
if (!can_moderate($threadinfo['forumid'], 'candeleteposts'))
{
if (!$threadinfo['open'])
{
$vbulletin->url = 'showthread.php?' . $vbulletin->session->vars['sessionurl'] . "t=$postinfo[threadid]";
eval(print_standard_redirect('redirect_threadclose d'));
}
if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['candeletepost']))
{
print_no_permission();
}
else
{
if ($vbulletin->userinfo['userid'] != $postinfo['userid'])
{
// check user owns this post since they failed the Mod Delete permission check for this forum
print_no_permission();
}
}
}
}
else
{
// otherwise, post is being edited
if (!can_moderate($threadinfo['forumid'], 'caneditposts'))
{ // check for moderator
if (!$threadinfo['open'])
{
$vbulletin->url = 'showthread.php?' . $vbulletin->session->vars['sessionurl'] . "t=$threadinfo[threadid]";
eval(standard_error(fetch_error('threadclosed')));
}
if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['caneditpost']))
{
print_no_permission();
}
else
{
if ($vbulletin->userinfo['userid'] != $postinfo['userid'])
{
// check user owns this post
print_no_permission();
}
else
{
// check for time limits
if ($postinfo['dateline'] < (TIMENOW - ($vbulletin->options['edittimelimit'] * 60)) AND $vbulletin->options['edittimelimit'] != 0)
{
eval(standard_error(fetch_error('edittimelimit', $vbulletin->options['edittimelimit'], $vbulletin->options['contactuslink'])));
}
}
}
}
}
and then from lines 91-97, I replaced this;
// get permissions info
$_permsgetter_ = 'edit post';
$forumperms = fetch_permissions($threadinfo['forumid']);
if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads']) OR (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewothers']) AND ($threadinfo['postuserid'] != $vbulletin->userinfo['userid'] OR $vbulletin->userinfo['userid'] == 0)))
{
print_no_permission();
}
with this;
// get permissions info
if ($threadinfo['prefixid'] != wiki OR is_member_of($vbulletin->userinfo, 4, 1, 3, 8, 2) OR ($threadinfo['firstpostid'] != $postinfo['postid']))
{
print_no_permission();
}
I did have it do that any member could edit the first post, but decided to only allow it to people with over 15 posts (which is obviously what the is_member_of($vbulletin->userinfo, 4, 1, 3, 8, 2) bit is for)
I'm sure there's a better way of doing it, but I'm just happy I managed to get it working :p
You can see the thread at the bottom of this page comes up as a "WikiEdit" post - http://www.nintendolounge.com/forum/forumdisplay.php?f=6&order=desc&page=3
BirdOPrey5
03-09-2012, 10:14 AM
very cool. Great idea to put a notice with new edit link in it... Solves the issue I was having with quick edit permissions and looks great on your forum. :up:
Paul M
03-09-2012, 12:48 PM
Removing the delete permission checks is very unwise.
BirdOPrey5
03-09-2012, 01:18 PM
If the entire if ($_REQUEST['do'] == 'deletepost') is removed how could anyone delete a post even if they tried?
Paul M
03-09-2012, 01:25 PM
It isnt removed, thats just the permission check. The delete code is way further down.
very cool. Great idea to put a notice with new edit link in it... Solves the issue I was having with quick edit permissions and looks great on your forum. :up:
Thanks! :)
It isnt removed, thats just the permission check. The delete code is way further down.
Ah, I thought I had disabled the ability to delete it, but I hadn't seen the code at the bottom. I see it now;
// ############################### start delete post ###############################
if ($_POST['do'] == 'deletepost')
{
$vbulletin->input->clean_array_gpc('p', array(
'deletepost' => TYPE_STR,
'reason' => TYPE_STR,
'keepattachments' => TYPE_BOOL,
));
($hook = vBulletinHook::fetch_hook('editpost_delete_start') ) ? eval($hook) : false;
if (!can_moderate($threadinfo['forumid'], 'candeleteposts'))
{ // Keep attachments for non moderator deletes (post owner)
$vbulletin->GPC['keepattachments'] = true;
}
if ($vbulletin->GPC['deletepost'] != '')
{
//get first post in thread
$getfirst = $db->query_first_slave("
SELECT postid, dateline
FROM " . TABLE_PREFIX . "post
WHERE threadid = $postinfo[threadid]
ORDER BY dateline
LIMIT 1
");
if ($getfirst['postid'] == $postinfo['postid'])
{
// delete thread
if ($forumperms & $vbulletin->bf_ugp_forumpermissions['candeletethread'] OR can_moderate($threadinfo['forumid'], 'canmanagethreads'))
{
if ($vbulletin->GPC['deletepost'] == 'remove' AND can_moderate($threadinfo['forumid'], 'canremoveposts'))
{
$removaltype = true;
}
else
{
$removaltype = false;
}
$threadman =& datamanager_init('Thread', $vbulletin, ERRTYPE_STANDARD, 'threadpost');
$threadman->set_existing($threadinfo);
$threadman->delete($foruminfo['countposts'], $removaltype, array('userid' => $vbulletin->userinfo['userid'], 'username' => $vbulletin->userinfo['username'], 'reason' => $vbulletin->GPC['reason'], 'keepattachments' => $vbulletin->GPC['keepattachments']));
unset($threadman);
if ($foruminfo['lastthreadid'] != $threadinfo['threadid'])
{
// just decrement the reply and thread counter for the forum
$forumdm =& datamanager_init('Forum', $vbulletin, ERRTYPE_SILENT);
$forumdm->set_existing($foruminfo);
$forumdm->set('threadcount', 'threadcount - 1', false);
$forumdm->set('replycount', 'replycount - 1', false);
$forumdm->save();
unset($forumdm);
}
else
{
// this thread is the one being displayed as the thread with the last post...
// so get a new thread to display.
build_forum_counters($threadinfo['forumid']);
}
($hook = vBulletinHook::fetch_hook('editpost_delete_complet e')) ? eval($hook) : false;
$vbulletin->url = 'forumdisplay.php?' . $vbulletin->session->vars['sessionurl'] . "f=$threadinfo[forumid]";
eval(print_standard_redirect('redirect_deletethrea d'));
}
else
{
print_no_permission();
}
}
else
{
//delete just this post
if ($vbulletin->GPC['deletepost'] == 'remove' AND can_moderate($threadinfo['forumid'], 'canremoveposts'))
{
$removaltype = true;
}
else
{
$removaltype = false;
}
$postman =& datamanager_init('Post', $vbulletin, ERRTYPE_SILENT, 'threadpost');
$postman->set_existing($postinfo);
$postman->delete($foruminfo['countposts'], $threadinfo['threadid'], $removaltype, array('userid' => $vbulletin->userinfo['userid'], 'username' => $vbulletin->userinfo['username'], 'reason' => $vbulletin->GPC['reason'], 'keepattachments' => $vbulletin->GPC['keepattachments']));
unset($postman);
build_thread_counters($threadinfo['threadid']);
if ($foruminfo['lastthreadid'] != $threadinfo['threadid'])
{
// just decrement the reply counter
$forumdm =& datamanager_init('Forum', $vbulletin, ERRTYPE_SILENT);
$forumdm->set_existing($foruminfo);
$forumdm->set('replycount', 'replycount - 1', false);
$forumdm->save();
unset($forumdm);
}
else
{
// this thread is the one being displayed as the thread with the last post...
// need to get the lastpost datestamp and lastposter name from the thread.
build_forum_counters($threadinfo['forumid']);
}
($hook = vBulletinHook::fetch_hook('editpost_delete_complet e')) ? eval($hook) : false;
$url = unhtmlspecialchars($vbulletin->url);
if (preg_match('/\?([^#]*)(#.*)?$/s', $url, $match))
{
parse_str($match[1], $parts);
if ($parts['postid'] == $postinfo['postid'] OR $parts['p'] == $postinfo['postid'])
{
// we've deleted the post that we came into this thread from
// blank the redirect as it will be set below
$vbulletin->url = '';
}
}
else if ($removaltype OR !can_moderate($threadinfo['forumid'], 'candeleteposts'))
{
// hard deleted or not moderating -> redirect back to the thread
$vbulletin->url = '';
}
if (!stristr($vbulletin->url, 'showthread.php')) // no referring url?
{
$vbulletin->url = 'showthread.php?' . $vbulletin->session->vars['sessionurl'] . 't=' . $threadinfo['threadid'];
}
eval(print_standard_redirect('redirect_deletepost' ));
}
}
else
{
($hook = vBulletinHook::fetch_hook('editpost_delete_complet e')) ? eval($hook) : false;
$vbulletin->url = 'showthread.php?' . $vbulletin->session->vars['sessionurl'] . "p=$postinfo[postid]#post$postinfo[postid]";
eval(print_standard_redirect('redirect_nodelete')) ;
}
}
Is it ok to just delete that then?
BirdOPrey5
03-09-2012, 08:43 PM
I would think it is safer to delete it than leave it. ;)
Hehe yeah :p Well I've deleted it now. Just thought there might be a safer way to disable it in the code or something, feels a bit weird deleting so much :p
Niak_Judge
03-14-2012, 07:16 PM
Hello,
is this possible in vb 4 ?
Would be great :) !
BirdOPrey5
03-15-2012, 03:33 AM
It is possible using the same basic procedures... a lot of file edits... I am working on trying to make this into a mod for VB4... no promises...
dougdirac
07-30-2012, 02:24 PM
Any progress on this? I need this very much for my forum. vB4, though.
InfoNirvana
08-01-2012, 12:40 AM
Any progress on this? I need this very much for my forum. vB4, though.
http://www.qapla.com/mods/showthread.php/309-Wiki-Posts-for-VB4-by-BOP5-BETA
27RUS
12-12-2013, 03:10 PM
for vb 4.2 add in editpost.php
// check for time limits $post['postcount']==1
if ($postinfo['dateline'] < (TIMENOW - ($vbulletin->options['edittimelimit'] * 60)) AND $vbulletin->options['edittimelimit'] != 0 AND $threadinfo['firstpostid'] != $postinfo['postid'])
sub_ubi
04-05-2014, 09:36 PM
This is great, thank you BOP.
vbresults
04-06-2014, 05:02 AM
I've coded a mod to edit threads owned by someone else mainly for the purpose of making the thread wiki-like (which includes edit history/revisions and rollback support), and this is doable with zero file edits.
Banana
06-06-2015, 08:36 AM
I've coded a mod to edit threads owned by someone else mainly for the purpose of making the thread wiki-like (which includes edit history/revisions and rollback support), and this is doable with zero file edits.
Hi - how can I get hold of this mod to look at? Thanks in advance.
BirdOPrey5
06-06-2015, 08:51 AM
Hi - how can I get hold of this mod to look at? Thanks in advance.
The member is not active on this site. If you google his username you should be able to find his website, you may be able to contact him there.
Banana
06-06-2015, 09:02 AM
Thanks.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.