PDA

View Full Version : How do I set a $_REQUEST variable so that an included vB script will use it?


Spinball
01-07-2007, 12:02 PM
I am trying to display a thread (minus the header/footer and some other bits) in a webpage on the same server as my vB installation.
I have created a cut-down version of SHOWTHREAD template called SHOWTHREAD_inline.
I have made a copy of showthread.php to showthread_inline.php and changed it to use the SHOWTHREAD_inline template.
I have then included showthread_inline.php into my custom php script.

It works but just shows the 'no thread specified' error. I can't set the ID of the thread I want to display.
I have tried :
$_REQUEST['t'] = 123456;
include_once("path/to/showthread_inline.php");

but the value of t is not taken into the included code.

How do I do this, please?
Thanks

RedTyger
01-07-2007, 12:59 PM
if ($_REQUEST['t'] == '123456')
{
include_once("path/to/showthread_inline.php");
}


Should do the trick. Note the == instead of the = you had.

= means This is now the same as That.
== means This has the value of That.

Spinball
01-07-2007, 01:16 PM
Thanks for replying but you've got the wrong end of the stick.
What I need to know is how to have the showthread_inline.php script pick up on the value of the thread id.
Assigning $_REQUEST['t'] to it's value before including the code doesn't work.
THis is my test script:

chdir("/home/sites/avforums/public_html/forums");
$_REQUEST['t'] = 452805;
include("/home/sites/avforums/public_html/forums/showthread_inline.php");

which just displays the 'No Thread specified' error.
I have looked at some of the vB code to see where request variables are 'received' to get a clue on how to do this. I have looked in init.php and global.php but don't see any sign of such code.

(P.S.
= means This is now the same as That.
== means This has the value of That.

No offense but I've been programming computers for 25 years :))

RedTyger
01-07-2007, 01:30 PM
Oh I see. Request variables come from the URL itself. Look at the URL for this page, it'll either have a t (thread) or p (post) variable. Request is like POST or GET but with a few extras thrown in.

Spinball
01-07-2007, 01:52 PM
Oh I see. Request variables come from the URL itself. Look at the URL for this page, it'll either have a t (thread) or p (post) variable. Request is like POST or GET but with a few extras thrown in.
Yes I'm aware of all that. I'm trying to do something different.
As I stated in my first post, I'm trying to include a (only slightly modified) version of showthread.php within my own php script. I want to send it a specific thread id.

Paul M
01-07-2007, 02:05 PM
$threadid = 123;
include_once("path/to/showthread_inline.php");

Spinball
01-07-2007, 02:59 PM
Bingo!.
Who could possibly have thought it would be as blindingly simple as that!
Cheers, Paul.

Supplemental question.
Rather than using
eval('print_output("' . fetch_template('SHOWTHREAD_inline') . '");');
To output the page immediately, is there a quick way to assign it to a string for incorporation into my own web page?

Kirk Y
01-07-2007, 04:18 PM
eval('$var = "' . fetch_template('SHOWTHREAD_inline') . '";');

Spinball
01-07-2007, 05:10 PM
Awesome! Thanks - I'm nearly there.
Implementing into the website, now and I'm getting a problem because I'm including the showthread_inline.php script within a function. (I don't have any choice at this point).
I get an error:

Fatal error: Call to a member function on a non-object in /home/sites/avforums/public_html/forums/global.php on line 22
I don't get the same error when including it in the main code (rather than a function).
Is there any way I can include it within a function?
Many thanks

Paul M
01-07-2007, 05:41 PM
Add

global $vbulletin ;to the top of your function.

wIrEs
01-08-2007, 09:20 AM
i have a custom page that uses a custom template, the template uses a plugin to include a php file, the php file uses the option:

$vbulletin->options['my_options']

to retrieve a setting, i am trying to use this setting inside a php variable:

$cfg['conf']['avatars'] = $vbulletin->options['my_options'];

the problem is that the option is not inserted, how can i add options to php variables?

i tried adding

globals $vbulletin ;

at the top of the php file but it still does not work.

Another problem i have is that i dont know how to add functions to a custom template too retrieving those functions from a plugin.

Dismounted
01-09-2007, 09:25 AM
i tried adding

globals $vbulletin ;

at the top of the php file but it still does not work.

Another problem i have is that i dont know how to add functions to a custom template too retrieving those functions from a plugin.
It's
global $vbulletin;
not
globals $vbulletin ;
And you add it to the top of the FUNCTION, not the file.

wIrEs
01-10-2007, 01:59 AM
i sure did added it on the top of the file, that mistake it's because i wrote my post a lilllte bit too fast.., i have more variables inside it.

noppid
01-10-2007, 04:32 PM
As Paul states, if it's a function, put global $vbulletin in the function it self. Not at the top of the file the function is in.

If it's not a function, you won't need a global statement to access $vbulletin.

wIrEs
01-13-2007, 05:29 PM
thank you.

Spinball
02-04-2007, 07:59 AM
You've all been so helpful with this thread. I couldn't get it to work in the end because when the content was displayed, some variables are not set.
What I'm trying to achieve here is to display a certain thread on a non-vb page on a website on the same server.
Specifically we have a DVD reviews, and I want to display a specific discussion thread below each review.
Isn't this something which would make an awesome hack if released properly?
Are any of you guys interested?

Kirk Y
02-04-2007, 04:34 PM
I butchered something together for just such a task a few weeks back - it's not perfect, but it does work.

Go here and download vBExternal, it says it's for 3.5.0 Beta 1 - but don't worry, it doesn't make any modifications to your forum, it doesn't even have any Plugins. Upload those files to your server. https://vborg.vbsupport.ru/showthread.php?t=83005

Open up the vBExternal.php file and follow on...

Find:
// ---------------------------------------------------
// FUNCTION: output_UsersOnline
// DETAIL: Outputs All Users Online In The Forum
// ---------------------------------------------------

Add before:
// ---------------------------------------------------
// FUNCTION: output_Thread
// DETAIL: Outputs the first post from the specified thread
// ---------------------------------------------------

function output_Thread($t = "",$a=""){
global $db, $Data, $vbulletin;

// Define Forum To Pull From
$Thread = ($t)? intval($t): '';

if(!$Thread){
RunError("No specified thread to pull from.");
}

// Load Template
$Template = LoadTemplate("_thread.html");

// Collect Data
$NewestNews = $db->query("
select t.*,p.pagetext
from ".TABLE_PREFIX."thread t
left join ".TABLE_PREFIX."post p on(p.postid=t.firstpostid)
where t.threadid = $Thread
");


$parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());

while($News = $db->fetch_array($NewestNews)){
$Data .= ParseTemplate($Template,
array(
'threadid' => $News['threadid'],
'threadname' => $News['title'],
'postuserid' => $News['postuserid'],
'postusername' => $News['postusername'],
'post' => $parser->do_parse(substr($News['pagetext'], 0, strrpos(substr($News['pagetext'], 0, $a), ' ')) . construct_phrase($vbphrase['read_more_news'], $vbulletin->options['bburl'], $sql['threadid'], $session['sessionurl'])),
'comments' => vb_number_format($News['replycount']),
)
);
}
doOutput();
}

Then you need to create a new HTML document in the vBExternal folder, name it _thread.html and fill it with the following contents:
{post}...
<br /><span class="readmore" style="float:right;"><a href='{url}/showthread.php?t={threadid}' class="readmore" style='text-decoration:none;'><strong>[Read More]</strong></a></span>

Then wherever you want to display the first post of a thread, use this:
<?php
output_Thread(2504,1500);
?>

2504 is the ThreadID and 1500 is the Amount of Characters to Display.
Don't forget to CHDIR the file you're placing the code in.

Spinball
02-04-2007, 06:49 PM
Thanks acidburn0520.
How difficult would it be to display the entire thread (with login info, reply buttons etc) as it would appear on the normal forum but without the header, footer and nav bar?

Kirk Y
02-04-2007, 07:02 PM
Well the Reply Buttons would be easy, as you'd just need the ThreadID -- and there's already a modification that lets you put a Login on a non-vb page.