vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   How do I set a $_REQUEST variable so that an included vB script will use it? (https://vborg.vbsupport.ru/showthread.php?t=135776)

Spinball 01-07-2007 12:02 PM

How do I set a $_REQUEST variable so that an included vB script will use it?
 
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 :
PHP Code:

$_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

Code:

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:
PHP Code:

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.
Quote:

= 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

Quote:

Originally Posted by RedTyger (Post 1152606)
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

PHP Code:

$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
PHP Code:

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

Code:

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:

Quote:

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

PHP Code:

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:

PHP Code:

$vbulletin->options['my_options'

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

PHP Code:

$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

PHP Code:

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

Quote:

Originally Posted by wIrEs (Post 1153442)
i tried adding

PHP Code:

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
PHP Code:

global $vbulletin

not
PHP Code:

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:
Code:

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

Add before:
Code:

        // ---------------------------------------------------
        // 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:
Code:

{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:
Code:

<?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.


All times are GMT. The time now is 08:11 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01338 seconds
  • Memory Usage 1,786KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_code_printable
  • (11)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (19)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete