Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-18-2007, 09:45 PM
mfyvie mfyvie is offline
 
Join Date: Mar 2007
Location: Zurich, Switzerland
Posts: 336
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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'];
I've double checked that all the variable names are correct, but the only output I get is from the final print statement - as this is a global phrase.

Am I missing something obvious here?
Reply With Quote
  #2  
Old 06-19-2007, 07:30 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You can only specify which phrase groups to fetch BEFORE global.php is included.
Reply With Quote
  #3  
Old 06-19-2007, 07:37 AM
mfyvie mfyvie is offline
 
Join Date: Mar 2007
Location: Zurich, Switzerland
Posts: 336
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dismounted View Post
You can only specify which phrase groups to fetch BEFORE global.php is included.
Thanks - I just discovered that while writing a little test file (running directly from a shell script) about 2 minutes ago

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?
Reply With Quote
  #4  
Old 06-19-2007, 02:33 PM
FractalizeR's Avatar
FractalizeR FractalizeR is offline
 
Join Date: Oct 2005
Location: Russia, Moscow
Posts: 368
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am looking for the same solution...

Just found it:

PHP Code:
- <plugin active="1">
  <
title>Mod Auto-PM :: Include Phrase Groups</title
  <
hookname>init_startup</hookname
- <
phpcode>
- <![
CDATA$phrasegroups[] = 'autopm_title';
$phrasegroups[] = 'autopm_text';
  ]]> 
  </
phpcode>
  </
plugin
So, just create init_startup hook and write only there:
PHP Code:
$phrasegroups[] = '<your_phrase_group_name>'
Reply With Quote
  #5  
Old 06-19-2007, 03:20 PM
mfyvie mfyvie is offline
 
Join Date: Mar 2007
Location: Zurich, Switzerland
Posts: 336
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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';
}
Note that mod autoPM probably isn't the best example to follow since these phrase groups will be loaded on ALL pages. I limited mine to only appear where I needed it, that is in login.php.
Reply With Quote
  #6  
Old 06-21-2007, 02:22 PM
FractalizeR's Avatar
FractalizeR FractalizeR is offline
 
Join Date: Oct 2005
Location: Russia, Moscow
Posts: 368
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Exactly. Thank you for idea.
Reply With Quote
  #7  
Old 06-22-2007, 08:44 PM
FractalizeR's Avatar
FractalizeR FractalizeR is offline
 
Join Date: Oct 2005
Location: Russia, Moscow
Posts: 368
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

BTW, don't forget to check admin pages against THIS_SCRIPT also if your hack is using them
Reply With Quote
  #8  
Old 06-28-2007, 11:55 PM
mfyvie mfyvie is offline
 
Join Date: Mar 2007
Location: Zurich, Switzerland
Posts: 336
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #9  
Old 06-29-2007, 09:59 AM
FractalizeR's Avatar
FractalizeR FractalizeR is offline
 
Join Date: Oct 2005
Location: Russia, Moscow
Posts: 368
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Have you created init_startup hook to load your phrase group? Cron script should execute this hook also when running as unregistered.
Reply With Quote
  #10  
Old 06-29-2007, 10:02 AM
mfyvie mfyvie is offline
 
Join Date: Mar 2007
Location: Zurich, Switzerland
Posts: 336
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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"));
}
This could be easily modified to load up an entire phrase group with a single query.

I hope someone else who runs into the same kind of problems I did finds this and it makes life easier for them.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:16 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07786 seconds
  • Memory Usage 2,259KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (2)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete