Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 03-17-2016, 05:05 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default yet another replace issue php, img to div

so i have been playing with this for a couple days, and i still cant get it. im trying to replace the avatar img in postbit to be a div instead.

this is the line to be changed:
Code:
<img src="$post[avatarurl]" $post[avwidth] $post[avheight] alt="<phrase 1="$post[username]">$vbphrase[xs_avatar]</phrase>" border="0" />
im hooking into postbit_display_complete

some methods i have used with no results:
PHP Code:
$search '<img src="$post[avatarurl]" $post[avwidth] $post[avheight] alt="<phrase 1="$post[username]">$vbphrase[xs_avatar]</phrase>" border="0" />';
$replace '<div id="drcltrav" style="background-color:'.$color.';"><span>'.strtoupper($drcltrav_lgth).'</span></div>';
$vbulletin->templatecache['postbit'] = str_replace($search$replace$vbulletin->templatecache['postbit']);
$show['avatar'] = true
using for my search:
PHP Code:
$search '<img src="' $post[avatarurl] . '" ' $post[avwidth] . ' ' $post[avheight] . 'alt="<phrase 1="' $post[username] . '">' $vbphrase[xs_avatar] . '</phrase>" border="0" />'
this method seemed the most promising since it wouldnt matter if the site has a custom template:
PHP Code:
$pattern '/<img src="'.$post['avatarurl'].'"(.*?)>/';
$replacement '<div id="myDiv">content</div>';

echo 
preg_replace($pattern$replacement$vbulletin->templatecache['postbit']); 
and they're about 50 other ways I have tried this. the ONLY time i get a result is when i use
PHP Code:
$post['avatarurl'] = '" class="someClass'
but i dont just want to add a class to it i want to replace it completely
Reply With Quote
  #2  
Old 03-17-2016, 06:26 PM
squidsk's Avatar
squidsk squidsk is offline
 
Join Date: Nov 2010
Posts: 969
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Your playing around with regular expressions so you need to escape every non-standard character otherwise they all have particular meanings for the regular expression engine other than their plain text characters.

So your search string would need to be something like:

Code:
'\<img src=\"\$post\[avatarurl\]\" \$post\[avwidth\] \$post\[avheight\] alt=\"\<phrase 1=\"\$post\[username\]\"\>\$vbphrase\[xs_avatar\]\<\/phrase\>\" border=\"0\" \/\>'
The easiest way to test is to use an online preg_replace tester to see if you patterns work or not.
Reply With Quote
Благодарность от:
MarkFL
  #3  
Old 03-17-2016, 06:48 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by squidsk View Post
Your playing around with regular expressions so you need to escape every non-standard character otherwise they all have particular meanings for the regular expression engine other than their plain text characters.

So your search string would need to be something like:

Code:
'\<img src=\"\$post\[avatarurl\]\" \$post\[avwidth\] \$post\[avheight\] alt=\"\<phrase 1=\"\$post\[username\]\"\>\$vbphrase\[xs_avatar\]\<\/phrase\>\" border=\"0\" \/\>'
The easiest way to test is to use an online preg_replace tester to see if you patterns work or not.
so what would i have to escape if i were using
PHP Code:
$pattern '/<img src="'.$post['avatarurl'].'"(.*?)>/'
$replacement '<div id="myDiv">content</div>'
i tried a tester but it threw me errors no matter what i did =/
Reply With Quote
  #4  
Old 03-17-2016, 08:44 PM
squidsk's Avatar
squidsk squidsk is offline
 
Join Date: Nov 2010
Posts: 969
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try <img src\="\$post\[avatarurl\]".*/> as the pattern.
Reply With Quote
  #5  
Old 03-17-2016, 09:50 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$pattern '<img src\="\$post\[avatarurl\]".*/>';  
$replacement '<div id="myDiv">content</div>'
echo 
preg_replace($pattern$replacement$vbulletin->templatecache['postbit']); 
no luck =(
Reply With Quote
  #6  
Old 03-17-2016, 10:38 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try the pattern:

PHP Code:
$pattern '/<img src\="\$post\[avatarurl\]".*?\/>/'
Reply With Quote
  #7  
Old 03-17-2016, 11:41 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

again nothing, lol this is becoming such a headache for such a little task =(

--------------- Added [DATE]1458277099[/DATE] at [TIME]1458277099[/TIME] ---------------

just for popped in my head so i tried.

postbit_display_complete
Code:
$search = 'img';
$replace = 'a';

$vbulletin->templatecache['postbit'] = preg_replace($search, $replace, $vbulletin->templatecache['postbit']);
seems like that should do something.... like replace all the images with links, but all it does is cause an infinite load -_-

--------------- Added [DATE]1458322966[/DATE] at [TIME]1458322966[/TIME] ---------------

seems postbit isnt cached in the hook i was using

using
Code:
$vbulletin->templatecache['postbit'] = str_replace('<img src=\"$post[avatarurl]', 'SHIT', $vbulletin->templatecache['postbit']);
in global gave me results. although i need some help to get the "whatever comes after doesnt matter" combination, been playing with it for hours and cant get it =/

example in red:
Code:
str_replace('<img src=\"$post[avatarurl]'\"*/>, ......
so everything in the img tag gets replaced.
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 03:07 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.06822 seconds
  • Memory Usage 2,246KB
  • 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
  • (6)bbcode_code
  • (7)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (1)post_thanks_box_bit
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete