PDA

View Full Version : Additional Re-Direct Option


Arrogant-One
11-13-2010, 07:38 PM
Firstly, let me say I made an honest and lengthy attempt to do this myself before bothering my fellow vB owners.

The Goal

I have a vB forum catering to chess players. Obviously tournaments are played and announced regularly, although the Calendar feature gets ignored big time.

What I would like to have is, when a member posts a new thread about their upcoming chess tournament, an option like the Post a Poll Option.

As everyone is aware the poll option firstly posts the members post as post #1 of the new thread, and then it re-directs them to the create your poll page.

I'm after pretty much the same thing, except once they have posted their first post in the new thread, I want them redirected to the Ranged Calendar entry page -

http://www.ozchess.com.au/calendar.php?do=add&c=1

As the Additional Options are often ignored, I was hoping this could be a button alongside the Submit New Thread and Preview Post buttons when someone is posting a new thread. Maybe the button could be called New Thread + Calendar Entry.

Is there anyone who could please tell me how I can achieve this?

kh99
11-13-2010, 08:23 PM
In template newthread you can add your button like this: find the existing buttons by searching for submit_new_thread and add
<input type="submit" class="button" name="calendar" value="New Thread + Calendar Entry" accesskey="c" tabindex="1" />

(you can make a phrase for it if you want)


Then add a plugin to get the value if that button is pushed: hook location newthread_post_start, code:
$newthread['calendar'] = $vbulletin->input->clean_gpc('p', 'calendar', TYPE_STR);


One more plugin to redirect to the calendar, hook location newthread_post_complete, code:
if ($newthread['calendar'])
{
$vbulletin->url = 'calendar.php?' . $vbulletin->session->vars['sessionurl'] . "do=add&c=1";
if ($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads'])
{
eval(print_standard_redirect('redirect_postthanks' , true, true));
}
else
{
eval(print_standard_redirect('redirect_postthanks_ nopermission', true, true));
}
}

If you want you might want to make another phrase that says "Thanks for posting, now you're going to the calendar" or something like that (although I find you don't often really see that page anyway). BTW, I don't know if you really need the check for permissions here, but I just copied the code for submitting a poll).

The only thing about this is that after filling in the calendar entry it won't take you back to your thread, but maybe that's OK (or maybe you can work that part out).

Arrogant-One
11-14-2010, 05:54 AM
Thank you dude! :)

You are a legend. Thanks again.

Arrogant-One
11-26-2010, 07:10 AM
The above didn't work unfortunately :(

kh99
11-26-2010, 08:49 AM
Well, I did test it before posting, but it's possible that your setup is different somehow, or maybe I misunderstood what you wanted. Does it not work at all, or what does it do?

kh99
11-28-2010, 10:44 PM
I made the above changes into the attached product file you can import, and I also added phrases.

Shanj
11-29-2010, 01:56 PM
kh9 this looks like good work I think it's the kind of thing quite a few will want.

What I need is to make all new posts in a selected forum redirect to a certain URL once they have posted.
Not as a user option, as 100% always.
I need to put it on several forums but it is always the same URL destination.

Is that possible?

kh99
11-29-2010, 02:40 PM
Yes, you could just copy the code that's under the hook location into a plugin so you can change it. In other words, make a new plugin using hook location newthread_post_complete with this code:

if ($newpost['postpoll']) // user selected poll
{
$vbulletin->url = 'poll.php?' . $vbulletin->session->vars['sessionurl'] . "t=$newpost[threadid]&polloptions=$newpost[polloptions]";
if ($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads'])
{
eval(print_standard_redirect('redirect_postthanks' , true, true));
}
else
{
eval(print_standard_redirect('redirect_postthanks_ nopermission', true, true));
}
}
else if ($newpost['visible']) // normal submit
{
if ($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads'])
{
// user has permission to see thread (this is probably the "normal" case)
$vbulletin->url = 'showthread.php?' . $vbulletin->session->vars['sessionurl'] . "p=$newpost[postid]#post$newpost[postid]";
eval(print_standard_redirect('redirect_postthanks' ));
}
else
{
// user can't see thread
$vbulletin->url = 'forumdisplay.php?' . $vbulletin->session->vars['sessionurl'] . "f=$foruminfo[forumid]";
eval(print_standard_redirect('redirect_postthanks_ nopermission', true, true));
}
}
else
{
// Thread waiting for moderation
$vbulletin->url = 'forumdisplay.php?' . $vbulletin->session->vars['sessionurl'] . "f=$foruminfo[forumid]";
eval(print_standard_redirect('redirect_postthanks_ moderate', true, true));
}

Then change the "$vbulletin->url =" lines as needed. You probably don't want to change the redirect to poll.php, so if the user is adding a poll you'd have to do something more complicated to get it to redirect after adding the poll. But you could change the other 3 $vbulletin->url lines to get it to redirect somewhere else, for instance:

$vbulletin->url = "http://www.foo.com";

I hope that makes sense. I guess it would be nice to have acp options to set the url, but this will work.

Shanj
11-29-2010, 04:33 PM
kr9 I get the outline but I'll need to ask you more questions. Hope that's OK.
Right now I don't see how to make this apply to a selected forum only.

kh99
11-29-2010, 04:56 PM
Oh..sorry, I missed that part. you could do something like this:

if (in_array($foruminfo['forumid'], array(1, 2, 3))) // list your forum ids in place of 1, 2, 3...
$redirect_url = "http://www.foo.com"; // url to redirect to

if ($newpost['postpoll']) // user selected poll
{
$vbulletin->url = 'poll.php?' . $vbulletin->session->vars['sessionurl'] . "t=$newpost[threadid]&polloptions=$newpost[polloptions]";
if ($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads'])
{
eval(print_standard_redirect('redirect_postthanks' , true, true));
}
else
{
eval(print_standard_redirect('redirect_postthanks_ nopermission', true, true));
}
}
else if ($newpost['visible']) // normal submit
{
if ($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads'])
{
// user has permission to see thread (this is probably the "normal" case)
if (!empty($redirect_url))
$vbulletin->url = $redirect_url;
else
$vbulletin->url = 'showthread.php?' . $vbulletin->session->vars['sessionurl'] . "p=$newpost[postid]#post$newpost[postid]";
eval(print_standard_redirect('redirect_postthanks' ));
}
else
{
// user can't see thread
if (!empty($redirect_url))
$vbulletin->url = $redirect_url;
else
$vbulletin->url = 'forumdisplay.php?' . $vbulletin->session->vars['sessionurl'] . "f=$foruminfo[forumid]";
eval(print_standard_redirect('redirect_postthanks_ nopermission', true, true));
}
}
else
{
// Thread waiting for moderation
if (!empty($redirect_url))
$vbulletin->url = $redirect_url;
else
$vbulletin->url = 'forumdisplay.php?' . $vbulletin->session->vars['sessionurl'] . "f=$foruminfo[forumid]";
eval(print_standard_redirect('redirect_postthanks_ moderate', true, true));
}


If you wanted you could have different forums redirect to different URLs by adding "else if" to that first if statement.

--------------- Added 1291058521 at 1291058521 ---------------

Sorry, the above had a mistake that I (hopefully) fixed.

Shanj
11-29-2010, 05:33 PM
Thank you!

For me it involves the same URL but it's great you put the IF ELSE in because that'll cover other people wanting that.

Now I need to be told where to PUT all that lovely code!

I guess a specific template for new posts but I'd be grateful to be told where to insert it.

kh99
11-29-2010, 05:36 PM
Create a new plugin, select hook location "newthread_post_complete", make up a title (so you'll remember what it is later), and paste the above in the code box. Click on the "Yes" radio button at the bottom and save.

ETA: If you want to understand more about adding a plugin you can read about it here: http://www.vbulletin.com/docs/html/main/add_plugin