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

Reply
 
Thread Tools Display Modes
  #11  
Old 04-16-2012, 09:34 AM
basketmen's Avatar
basketmen basketmen is offline
 
Join Date: Nov 2006
Posts: 446
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Dear kh99, i am sorry, so is it like this

Quote:
if ($_POST['do'] == 'updateprofile')
{
$vbulletin->input->clean_gpc('p', 'userfield', TYPE_ARRAY);

$fieldcontentbefore = array(
'aaa',
'ccc'
);

$fieldcontentafter = array(
'bbb',
'ddd'
);


$vbulletin->input->clean_gpc('p', 'userfield', TYPE_ARRAY); = str_replace($fieldcontentbefore, $fieldcontentafter, $vbulletin->input->clean_gpc('p', 'userfield', TYPE_ARRAY);


or this one


Quote:
if ($_POST['do'] == 'updateprofile')
{
$vbulletin->input->clean_gpc('p', 'userfield', TYPE_ARRAY);

$fieldcontentbefore = array(
'aaa',
'ccc'
);

$fieldcontentafter = array(
'bbb',
'ddd'
);


$vbulletin->input->clean_gpc('p', 'userfield', TYPE_ARRAY) = str_replace($fieldcontentbefore, $fieldcontentafter, $vbulletin->input->clean_gpc('p', 'userfield', TYPE_ARRAY));
}
}



i tried both got error message like this

Parse error: syntax error, unexpected '=' in /home/username/public_html/profile.php(156) : eval()'d code on line 22
Reply With Quote
  #12  
Old 04-16-2012, 10:55 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No, just the one change, like this:

Code:
if ($_POST['do'] == 'updateprofile')
{
	$vbulletin->input->clean_gpc('p', 'userfield', TYPE_ARRAY);

	$fieldcontentbefore = array(
		'aaa',
		'ccc'
	);

	$fieldcontentafter = array(
		'bbb',
		'ddd'
	);


	$vbulletin->GPC['userfield']['fieldX'] = str_replace($fieldcontentbefore, $fieldcontentafter, $vbulletin->GPC['userfield']['fieldX']);
}

Where you replace the 2 occurrences of 'fieldX' with the real field name that you want to change.


Quote:
Originally Posted by Simon Lloyd View Post
It wouldn't be $field1 but rather ['field1'] so the id of the field you are trying to manipulate
Right. Or else you'd need to set $field to something like:

Code:
$fields = array('field4', 'field7', 'field8');
foreach ($fields AS $field)
{
    	$vbulletin->GPC['userfield'][$field] = str_replace($fieldcontentbefore, $fieldcontentafter, $vbulletin->GPC['userfield'][$field]);
}
Reply With Quote
  #13  
Old 04-16-2012, 05:53 PM
basketmen's Avatar
basketmen basketmen is offline
 
Join Date: Nov 2006
Posts: 446
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Dear kh99, thank you for explaining it again, but its looks like still not working




Quote:
if ($_POST['do'] == 'updateprofile')
{
$vbulletin->input->clean_gpc('p', 'userfield', TYPE_ARRAY);

$fieldcontentbefore = array(
'aaa',
'ccc'
);

$fieldcontentafter = array(
'bbb',
'ddd'
);


$vbulletin->GPC['field1'] = str_replace($fieldcontentbefore, $fieldcontentafter, $vbulletin->GPC['field1']);
}


is it working in your vbulletin test? if needed i can give a vb3 test site access
Reply With Quote
  #14  
Old 04-16-2012, 06:16 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, I have a vb3 test site, but I haven't actually tried this code. But now I see that I've misled you again with another mistake. The last line should be:

Code:
$vbulletin->GPC['userfield']['field1'] = str_replace($fieldcontentbefore, $fieldcontentafter, $vbulletin->GPC['userfield']['field1']);

ETA: ...and that seems to work for me. I used 'field4' (Occupation) and when I edited my details and put in "aaa" it was set to "bbb".

Also, that will obviously only work if the entire sting matches. If you want substrings, I think this should work:

Code:
if ($_POST['do'] == 'updateprofile')
{
$vbulletin->input->clean_gpc('p', 'userfield', TYPE_ARRAY);

$fieldcontentbefore = array(
'/aaa/',
'/ccc/'
);

$fieldcontentafter = array(
'bbb',
'ddd'
);


$vbulletin->GPC['userfield']['field1'] = preg_replace($fieldcontentbefore, $fieldcontentafter, preg_quote($vbulletin->GPC['userfield']['field1'], '/'));
}

Note the before array needs '/' before and after the string to be matched.
Reply With Quote
  #15  
Old 04-17-2012, 10:53 AM
basketmen's Avatar
basketmen basketmen is offline
 
Join Date: Nov 2006
Posts: 446
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Gorgeus!! many thanks kh99!!


i recommend release a mod for it

we already have global replacement variable

we already have replacement in postbit

and this one is replacement in profile field
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 07:31 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.04709 seconds
  • Memory Usage 2,209KB
  • 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
  • (4)bbcode_code
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (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_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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete