Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
  #1  
Old 07-20-2012, 11:01 AM
Bundschuh Bundschuh is offline
 
Join Date: Mar 2012
Posts: 18
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Custom Field/Userfield in Subscription

Hi there,

does somebody knows a elegant way to use custom fields in the subscription mails?

I have to send Mails with the users real name like "Dear John, there are new replies ...."

In Lang & Phrases -> Email Body Text -> notify, there are only the variable $touser which doesn't contains any custom user fields.
$vbulletin->userinfo[field5] only give me the custom field of the user who has post the reply by whom the subscription notification was initiated.

Greetings for every advices
Bundschuh
Reply With Quote
  #2  
Old 07-20-2012, 11:21 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

There are two ways of doing that that I can see (I don't know if either would qualify as "elegant"): One would be to edit the file includes/functions_newpost.php and change the query that finds the users (around line 1186). You could add a JOIN of the userfield table, and add the fields you want to the fields being selected, then they should be available in $touser.

The other way would be to write a plugin using hook newpost_notification_message and write your own query to get the field. This way you're not modifying any files, but it would add 1 query per subscribed user every time someone posts.
Reply With Quote
  #3  
Old 07-20-2012, 01:44 PM
Bundschuh Bundschuh is offline
 
Join Date: Mar 2012
Posts: 18
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

These were also my first thoughts.
Using of hook location is more "elegant" than direct code modification.
But in this case, I thinks it's not the fastest solution.

I tried to get the custom field with
PHP Code:
$vbulletin->db->query_first('SELECT `field5` AS realname FROM `'.TABLE_PREFIX.'userfield` AS uf LEFT JOIN `'.TABLE_PREFIX.'user` AS u ON u.`userid` = uf.`userid` WHERE u.`userid` = ' $touser['userid']) 
but its pretty slow.
Also I can't simply str_replace the username in the template with the fetched custom field because the template will be rendered after the hook location .
So I have to use the loaded template in array $evalemail[$touser['languageid']] and write back my changes...
Reply With Quote
  #4  
Old 07-20-2012, 02:04 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Bundschuh View Post
TI tried to get the custom field with
PHP Code:
$vbulletin->db->query_first('SELECT `field5` AS realname FROM `'.TABLE_PREFIX.'userfield` AS uf LEFT JOIN `'.TABLE_PREFIX.'user` AS u ON u.`userid` = uf.`userid` WHERE u.`userid` = ' $touser['userid']) 
but its pretty slow.
If you have the userid and just want field5, you don't really need a join, just SELECT field5 FROM userfield WHERE userid = $touser['userid'].


Quote:
Also I can't simply str_replace the username in the template with the fetched custom field because the template will be rendered after the hook location .
So I have to use the loaded template in array $evalemail[$touser['languageid']] and write back my changes...
Hmm..yeah, that's a problem. I was thinking you were just going to edit the phrase and put in $touser['realname'] or something.
Reply With Quote
  #5  
Old 07-23-2012, 02:21 PM
Bundschuh Bundschuh is offline
 
Join Date: Mar 2012
Posts: 18
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
If you have the userid and just want field5, you don't really need a join, just SELECT field5 FROM userfield WHERE userid = $touser['userid'].
Yeah, that's right.

Quote:
Originally Posted by kh99 View Post
Hmm..yeah, that's a problem. I was thinking you were just going to edit the phrase and put in $touser['realname'] or something.
No I will do some more complex modifications based on different conditions. But I simply copied the Code from functions_newpost.php (around line 1178) which will eval the notify templates and fill the variables $message and $subject. Now I can parse it and change it for my needs.
PHP Code:
// copied from functions_newpost.php (line 1178) 
eval(
    
iif(empty($evalemail["$touser[languageid]"]),$evalemail["-1"],
        
$evalemail["$touser[languageid]"])
); 
For preventing override of these two variables I emptied the array holding the notify templates.
PHP Code:
$evalemail[$touser['languageid']] = null;
$evalemail['-1'] = null
Reply With Quote
Reply

Thread Tools
Display Modes

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 07:20 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.04011 seconds
  • Memory Usage 2,203KB
  • Queries Executed 13 (?)
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
  • (4)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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_postinfo_query
  • fetch_postinfo
  • 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