vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   query_first_slave() error when trying to use vBulletin API outside of vBulletin (https://vborg.vbsupport.ru/showthread.php?t=187371)

nvitremi 08-06-2008 02:22 PM

query_first_slave() error when trying to use vBulletin API outside of vBulletin
 
Hi,

Since the past two days, the only thing I'm trying to do with vBulletin is to display a login form or a user information box (when the user is logged in) on every pages of the site, including those not in vBulletin. That's it -- nothing fancy. I do not need or want full integration capabilities -- just display a user information box or a login box whether the user is logged in or not.

I followed a tutorial I found on this site and tried to make a page outside of vBulletin's directory and still use vBulletin's API. Even though I followed the instructions to the letter, I can't make a page outside vBulletin. I get the following error message:

Quote:

Call to a member function query_first_slave() on a non-object in /var/nvisionit/projects/precisionnutrition/www-newcms/forum/includes/functions.php on line 1303
Is there anything I can do to make this thing work once and for all?

Any help will be appreciated. Thanks in advance!

Lynne 08-06-2008 02:46 PM

You should post the code so people can see it.

nvitremi 08-06-2008 03:01 PM

Here it is:

Code:

<?php
// https://vborg.vbsupport.ru/showthread.php?t=98009

// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// ##################### DEFINE IMPORTANT CONSTANTS #######################
// change the line below to the actual filename without ".php" extention.
// the reason for using actual filename without extention as a value of this constant is to ensure uniqueness of the value throughout every PHP file of any given vBulletin installation.

define('THIS_SCRIPT', 'test');

// #################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array(
        // change the lines below to the list of actual templates used in the script
        'pn_test',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ########################## REQUIRE BACK-END ############################
$forumdir = $pnsite->getConfig('forumdir');
chdir($forumdir);
require_once('./global.php');
// I checked the "forumdir" above and the path is correct
// since the file "global.php" gets loaded.

// #################### HARD CODE JAVASCRIPT PATHS ########################
$headinclude = str_replace('clientscript', $vbulletin->options['bburl'] . '/clientscript', $headinclude);

// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################

$navbits = array();
// change the line below to contain whatever you want to show in the navbar (title of your custom page)
$navbits[$parent] = 'Test Page';

$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
print_output($navbar);

// change the line below to contain the name of the actual main output template used in your script
eval('print_output("' . fetch_template('pn_test') . '");');

I also cleared all my cookies for the site, thus I'm no longer logged in. I get different errors in this case:

Quote:

Warning: array_keys() [function.array-keys]: The first argument should be an array in [path]/includes/functions.php on line 4088

Warning: Invalid argument supplied for foreach() in [path]/includes/functions.php on line 4088

( ! ) Fatal error: Call to a member function query_read_slave() on a non-object in /var/nvisionit/projects/precisionnutrition/www-newcms/forum/includes/functions.php on line 3093

Lynne 08-06-2008 03:22 PM

What are you spitting out though? I see you eval your template pn_test, but nothing is there to go into pn_test - perhaps post that template. Also, I hope you have a closing php tag at the end ("?>")? And, I don't think you need the line "print_output($navbar);"

nvitremi 08-06-2008 03:58 PM

I usually don't put closing tags when I only have PHP code in my file. See "Instruction separation" in PHP documentation.

Execution errs at "global.php". Anything after that is not executed.

--------------- Added [DATE]1218043772[/DATE] at [TIME]1218043772[/TIME] ---------------

I forgot to mention the custom template "pn_test" simply contains "TEST".

Lynne 08-06-2008 04:38 PM

Does it work if you do the following:
PHP Code:

// ########################## REQUIRE BACK-END ############################

chdir(/path/to/the/vbulltin/forums);
require_once(
'./global.php'); 


nvitremi 08-06-2008 04:43 PM

No. Still the same happens -- no different.

Paul M 08-06-2008 06:45 PM

What version of VB are you running ?

Lynne 08-06-2008 06:45 PM

Um, I just noticed something.... you didn't really create a template that only has the word "TEST" in it, did you? It needs to be html compliant. ie:
HTML Code:

$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<title>$vboptions[bbtitle]</title>
$headinclude
</head>
<body>
$header

$navbar

<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
    <td class="tcat" colspan="2">Title</td>
</tr>
<tr>
    <td class="alt1" colspan="2">Text</td>
</tr>
</table>

$footer
</body>
</html>

Also, as I said, be sure to remove the print_output line.

Marco van Herwaarden 08-07-2008 08:10 AM

I really don't see how the following can work:
PHP Code:

// ########################## REQUIRE BACK-END ############################
$forumdir $pnsite->getConfig('forumdir');
chdir($forumdir);
require_once(
'./global.php'); 

$pnsite is not even defined at this point.


All times are GMT. The time now is 06:30 AM.

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.02072 seconds
  • Memory Usage 1,749KB
  • 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
  • (1)bbcode_code_printable
  • (1)bbcode_html_printable
  • (2)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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