The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Using non-global phrase groups (problem)
Hi guys, I've been working on this for a few hours, but haven't come up with any result yet. The problem is displaying global phrases - no problem, but any custom phrase group - won't display.
I've looked in member.php which is also displaying my custom phrase group - but I can't see anything that is in there that isn't in my code. I've tried loads of different combinations and haven't got it to work. Consider this code placed at the top of a plugin which fires at login_verify_success: Code:
global $vbulletin, $vbphrase; $phrasegroups = array('cprofilefield', 'arcade'); print $vbphrase['field1_title']; print $vbphrase['field1_desc']; print $vbphrase['arcade_end']; print $vbphrase['accept']; Am I missing something obvious here? |
#2
|
||||
|
||||
You can only specify which phrase groups to fetch BEFORE global.php is included.
|
#3
|
|||
|
|||
Quote:
However, how does someone best approach this problem when working from a hook? Since global.php has been included already by the script which calls the hook. Or is it no problem to include global.php again inside the plugin? Normally we call global.php with a "require_once" statement? |
#4
|
||||
|
||||
I am looking for the same solution...
Just found it: PHP Code:
PHP Code:
|
#5
|
|||
|
|||
Thanks for that! I spent the entire day today sniffing through the various functions and trying to figure out a way to call the right functions to add a phrase group later in the execution. I didn't even think of looking for an earlier hook to append to the array BEFORE it gets processed.
Just in case anyone finds this thread later on, I've included an example below of what I did (added an additional product at the init_startup hook) : Code:
if (THIS_SCRIPT == 'login') { $phrasegroups[] = 'cprofilefield'; } |
#6
|
||||
|
||||
Exactly. Thank you for idea.
|
#7
|
||||
|
||||
BTW, don't forget to check admin pages against THIS_SCRIPT also if your hack is using them
|
#8
|
|||
|
|||
I've run into a bit of a problem again with this.
I'm running on the hook in cleanup.php (cron_script_cleanup). I have a phrase which I have defined as belonging to the scheduled tasks group. If I log into the admincp and manually run the scheduled task (which runs it as my login), then the phrase works. However, if I just leave the task to run by itself (running as unregistered) the phrase doesn't work. I tried making the phrase global, but this doesn't help either. Obviously these scheduled tasks normally run as unregistered, so I'd like to find a solution for this. Anyone have any ideas as to why this would be happening? |
#9
|
||||
|
||||
Have you created init_startup hook to load your phrase group? Cron script should execute this hook also when running as unregistered.
|
#10
|
|||
|
|||
Yes, see post #5. However, the cron task doesn't set its script name.
However, I don't believe this is the problem, because when I run the cron job in the admincp, where the job runs as me, the phrase works. Only when the job runs by itself (as unregistered) does the phrase not work. I'm guessing that somehow an unregistered cronjob has less rights, and doesn't get access to phrases? Ok, I've done some more testing and discovered what the problem is. basically /includes/cron/cleanup.php is the only cron job with a hook in it. However, this file needs to have: global $vbphrase; At the top, otherwise phrases are not available to this file, nor the hook. I could work around this by building my own cron file for what I am working on, but would have preferred to work without additional files. It seems a little strange when there is an entire phrase group for scheduled tasks, yet phrases aren't available in the only cron job with a hook Work-around solution to being unable to get phrases I found one way to get around this for situations where you can't get $vbphrase into your routine for whatever reason. I just decided to pull the phrase out of the database. Obviously this isn't good for something that is executing many times on every page, but for occassional use (like in a cron job) it should be no drama. Code:
$myphrase = pullphrase("the_name_of_my_phrase"); function pullphrase($phrasename, $language=-1) { global $db; return implode("", $db->query_first("SELECT text FROM " . TABLE_PREFIX . "phrase WHERE varname = '$phrasename' AND languageid = $language")); } I hope someone else who runs into the same kind of problems I did finds this and it makes life easier for them. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|