vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   Custom Field/Userfield in Subscription (https://vborg.vbsupport.ru/showthread.php?t=285753)

Bundschuh 07-20-2012 11:01 AM

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

kh99 07-20-2012 11:21 AM

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.

Bundschuh 07-20-2012 01:44 PM

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...

kh99 07-20-2012 02:04 PM

Quote:

Originally Posted by Bundschuh (Post 2349837)
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.

Bundschuh 07-23-2012 02:21 PM

Quote:

Originally Posted by kh99 (Post 2349843)
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 (Post 2349843)
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



All times are GMT. The time now is 04:25 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.01499 seconds
  • Memory Usage 1,738KB
  • 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
  • (4)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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