vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Errors when including global.php (https://vborg.vbsupport.ru/showthread.php?t=91514)

Xia 07-02-2005 12:45 PM

Errors when including global.php
 
I want to implement an external user registration functionality.

I use this code to include global.php

chdir('../forum');
require_once('./global.php');

However, upon doing this I receive these errors:

Notice: Undefined variable: errfile in /home/wa/public_html/forum/includes/functions_log_error.php on line 136

Warning: array_keys(): The first argument should be an array in /includes/functions.php on line 3090

Notice: Undefined variable: errfile in /home/wa/public_html/forum/includes/functions_log_error.php on line 136

Warning: Invalid argument supplied for foreach() in /includes/functions.php on line 3090

Fatal error: Call to a member function on a non-object in /home/wa/public_html/forum/includes/functions.php on line 2379

functions.php line 2379 =
$temps = $vbulletin->db->query_read("
SELECT title, template
FROM " . TABLE_PREFIX . "template
WHERE templateid IN (" . implode(',', $templateids) . ")
");

functions.php line 3090 =
foreach(array_keys($vbulletin->forumcache) AS $forumid)
{
foreach($membergroupids AS $usergroupid)
{
$user['forumpermissions']["$forumid"] |= $vbulletin->forumcache["$forumid"]['permissions']["$usergroupid"];
}
}

Anyone know what is wrong and why?

Marco van Herwaarden 07-02-2005 12:53 PM

You will find 4 arrays defined in each vB file, before the call to global.php. Just define those 4 arrays.

Xia 07-02-2005 01:04 PM

Thanks for your quick reply,

I added the 4 arrays but the errors still remain.

Here is the new code:

PHP Code:

echo "creating arrays..";
        
//define('THIS_SCRIPT', 'index');
        
$phrasegroups = array('holiday');
        
$specialtemplates = array(
            
'userstats',
            
'birthdaycache',
            
'maxloggedin',
            
'iconcache',
            
'eventcache',
            
'mailqueue'
        
);
        
$globaltemplates = array(
            
'FORUMHOME',
            
'forumhome_event',
            
'forumhome_forumbit_level1_nopost',
            
'forumhome_forumbit_level1_post',
            
'forumhome_forumbit_level2_nopost',
            
'forumhome_forumbit_level2_post',
            
'forumhome_lastpostby',
            
'forumhome_loggedinuser',
            
'forumhome_moderator',
            
'forumhome_pmloggedin',
            
'forumhome_subforumbit_nopost',
            
'forumhome_subforumbit_post',
            
'forumhome_subforumseparator_nopost',
            
'forumhome_subforumseparator_post'
        
);
        
$actiontemplates = array();
        
chdir('../forum');
        echo 
"requiring..";
        require_once(
'./global.php');
        echo 
"required..";
        
        
$user =& datamanager_init('User'$vbulletinERRTYPE_ARRAY);
        
        echo 
"created.."


Cloudrunner 07-02-2005 01:07 PM

Quote:

Originally Posted by Xia
Thanks for your quick reply,

I added the 4 arrays but the errors still remain.

Here is the new code:

PHP Code:

echo "creating arrays..";
        
//define('THIS_SCRIPT', 'index');
        
$phrasegroups = array('holiday');
        
$specialtemplates = array(
            
'userstats',
            
'birthdaycache',
            
'maxloggedin',
            
'iconcache',
            
'eventcache',
            
'mailqueue'
        
);
        
$globaltemplates = array(
            
'FORUMHOME',
            
'forumhome_event',
            
'forumhome_forumbit_level1_nopost',
            
'forumhome_forumbit_level1_post',
            
'forumhome_forumbit_level2_nopost',
            
'forumhome_forumbit_level2_post',
            
'forumhome_lastpostby',
            
'forumhome_loggedinuser',
            
'forumhome_moderator',
            
'forumhome_pmloggedin',
            
'forumhome_subforumbit_nopost',
            
'forumhome_subforumbit_post',
            
'forumhome_subforumseparator_nopost',
            
'forumhome_subforumseparator_post'
        
);
        
$actiontemplates = array();
        
chdir('../forum');
        echo 
"requiring..";
        require_once(
'./global.php');
        echo 
"required..";
        
        
$user =& datamanager_init('User'$vbulletinERRTYPE_ARRAY);
        
        echo 
"created.."


in your chdir statement, declare the full filepath (ie. /home/yourdomain/public_html/forum) to the forum directory...then after you have done the work that requires the vb files, chdir back to the directory that the file is in that you are working with. That should remove the global errors.

Xia 07-02-2005 01:15 PM

Hello,

I changed the code snippet to this:

PHP Code:

        chdir('/home/wa/public_html/forum');
        echo 
"requiring..";
        require_once(
'./global.php');
        
chdir('/home/wa/public_html/common');
        echo 
"required.."

Alas, the errors remain even with this change. Any other ideas? Thanks

Could it be that the arrays required cannot be accessed by global.php because they are created in a function inside a class? (local scope) Just guessing here..

PSEUDO :

Code:

class Registration
  function insert
    define arrays;
    chdir;
    include global.php;

Update: Well, it definately works if I do not put it in a class or function, however this is the way my framework works and there is no way around it.

Is it possible to still have access to global.php inside a class or function?

Update2: If there isn't, is it still possible to play with the datamanager?

This is what I need global.php for:

PHP Code:

        $user =& datamanager_init('User'$vbulletinERRTYPE_ARRAY);
        
$user->set('username'$parameters['username']);
        
$user->set('email'$parameters['email']);
        
$user->set('password'$parameters['password']);

        if (
$user->errors) {
            
$this->errors =& $user->errors;
            
$this->reportInputError('register');
            die();
        } 
            
        
$userID $user->save(); 

Thanks

For anyone wanting to test: This does not work :

PHP Code:

<?php
function test() {
        
chdir('/home/wa/public_html/forum/');
        
$phrasegroups = array('holiday');
        
$specialtemplates = array(
            
'userstats',
            
'birthdaycache',
            
'maxloggedin',
            
'iconcache',
            
'eventcache',
            
'mailqueue'
        
);
        
$globaltemplates = array(
            
'FORUMHOME',
            
'forumhome_event',
            
'forumhome_forumbit_level1_nopost',
            
'forumhome_forumbit_level1_post',
            
'forumhome_forumbit_level2_nopost',
            
'forumhome_forumbit_level2_post',
            
'forumhome_lastpostby',
            
'forumhome_loggedinuser',
            
'forumhome_moderator',
            
'forumhome_pmloggedin',
            
'forumhome_subforumbit_nopost',
            
'forumhome_subforumbit_post',
            
'forumhome_subforumseparator_nopost',
            
'forumhome_subforumseparator_post'
        
);
        
$actiontemplates = array();
        require_once(
'./global.php');
        }

test();
        
?>

Errors as already said:

Code:

Warning: array_keys(): The first argument should be an array in /includes/functions.php on line 3090

Warning: Invalid argument supplied for foreach() in /includes/functions.php on line 3090

Fatal error: Call to a member function on a non-object in /home/wa/public_html/forum/includes/functions.php on line 2379

Fatal error: Call to a member function on a non-object in /home/wa/public_html/forum/includes/functions.php on line 4198

What to do?

Cloudrunner 07-02-2005 06:22 PM

Global the variables...

PHP Code:

<?php
function test(){
    global 
$phrasegroups$specialtemplates$globaltemplatesactiontemplates;

    
$phrasegroups = array('holiday');
    
$specialtemplates = array(
        
'userstats',
        
'birthdaycache',
        
'maxloggedin'
        
'iconcache'
        
'eventcache'
        
'mailqueue');
    
$globaltemplates = array(
        
'FORUMHOME'
        
'forumhome_event'
        
'forumhome_forumbit_level1_nopost'
         
'forumhome_forumbit_level1_post'
        
'forumhome_forumbit_level2_nopost'
        
'forumhome_forumbit_level2_post'
        
'forumhome_lastpostby'
        
'forumhome_loggedinuser'
        
'forumhome_moderator'
        
'forumhome_pmloggedin'
        
'forumhome_subforumbit_nopost'
        
'forumhome_subforumbit_post'
        
'forumhome_subforumseparator_nopost'
        
'forumhome_subforumseparator_post');
     
$actiontemplates = array(); 
     
chdir('/home/wa/public_html/forum');
     require_once(
'./global.php');
     
chdir('/home/wa/public_html/common');
}

test();
?>


Xia 07-03-2005 09:36 AM

Hi,

Just tried it, errors remain the same. Any other ideas?

Thanks

Paul M 07-03-2005 12:09 PM

As a side note, do you actually need all those templates you are declaring, or did you just copy the code from somewhere ?

Xia 07-03-2005 01:13 PM

No i don't need them, I just copied it from index.php. Can they just be empty arrays?

Marco van Herwaarden 07-03-2005 01:15 PM

Like i said in my first reply, just define them.

Xia 07-03-2005 03:39 PM

Ok, so I have changed the code to :

PHP Code:

<?php
function test() {
    global 
$phrasegroups;
    global 
$specialtemplates;
    global 
$globaltemplates;
    global 
$actiontemplates;

    
chdir('/home/wa/public_html/forum/');
    
$phrasegroups = array();
    
$specialtemplates = array();
    
$globaltemplates = array();
    
$actiontemplates = array();
    require_once(
'./global.php');
}

test();
?>

But it still doesn't work :(

Xia 07-04-2005 06:01 PM

anyone ? :s

Xia 07-06-2005 11:03 AM

No replies, does this mean it's impossible to do??

merk 07-06-2005 12:05 PM

it just means noone has a solution to fix your problem.


Now that I've read your requirements, no. you will not be able to do this to use it inside a class.

It is still possible, and since you're already mucking around with classes i dont see why you'd need help to copy the data_managers init function to make it work.

you will need to reproduce init.php's behaviour to initialise any variables the datamanager requires.

Xia 07-07-2005 06:21 AM

I'll look into that, thanks!

Btw, is there also a login function in that class or anywhere else which I can easily use from outside Vb? That would be very nice.

merk 07-07-2005 06:23 AM

im not sure. if there is one itll be in /includes/.

johnobandalong 03-15-2006 12:19 AM

I'm having this problem too. Did anybody find a solution? How do other people integrate vbulletin with their application?

kolita 04-14-2006 10:44 PM

Hi Xia,

(Hope is not too late.. well, it will serve someone else if it's too late for you :))

Here's the code to get an instance of vbulletins' registry object (a.k.a $vbulletin).

I've placed toghether a couple pieces from various threads here in vb.org (including some of them from this same one, and from https://vborg.vbsupport.ru/showthread.php?t=112388)

You can place the function as a method in your class and call it statically like:
PHP Code:

$vbInstance = &yourClass::_getVbulletinRegistryInstance() 

(remember to use '=&', not just '=' here :))

I've successfully tested this and used a datamanager, and it worked perfectly (created thread and post correctly :-D)

This follows a singleton pattern, so you'll never overwrite the instance, even if the instance was created by vB itself.

PHP Code:

function &_getVbulletinRegistryInstance() {
    
define('SKIP_SESSIONCREATE'1);
    
define('DIE_QUIETLY'1);
    
define('THIS_SCRIPT''vbSupport');
    
$GLOBALS['phrasegroups'] = array();
    
$GLOBALS['specialtemplates'] = array();
    
$GLOBALS['globaltemplates'] = array();
    
$GLOBALS['actiontemplates'] = array();

    
$cwd getcwd();
    
chdir($_SERVER['DOCUMENT_ROOT'].'/forum'); 

    if (!isset(
$GLOBALS['vbulletin'])) {
        include_once(
'./includes/init.php');
        
$GLOBALS['vbulletin'] = &$vbulletin;
    }
    
chdir($cwd);

    return 
$GLOBALS['vbulletin'];


regards!

Markus

Hammon 05-10-2006 12:27 PM

Quote:

Why isn't it possible to create a session? I would like to display the username on an external website if a user is logged in in the forum.
No one has the answer? I'm interested me too.

bradsears 05-18-2006 03:51 PM

I'm struggling with this as well. Please help.


All times are GMT. The time now is 05:02 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.01273 seconds
  • Memory Usage 1,849KB
  • 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
  • (2)bbcode_code_printable
  • (9)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (20)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